Index: /branches/ia32/level-0/X86/X8632/x8632-utils.lisp
===================================================================
--- /branches/ia32/level-0/X86/X8632/x8632-utils.lisp	(revision 8077)
+++ /branches/ia32/level-0/X86/X8632/x8632-utils.lisp	(revision 8077)
@@ -0,0 +1,142 @@
+(in-package "CCL")
+
+(defx8632lapfunction %address-of ((arg arg_z))
+  ;; %address-of a fixnum is a fixnum, just for spite.
+  ;; %address-of anything else is the address of that thing as an integer.
+  (testb ($ x8632::fixnummask) (%b arg))
+  (je @done)
+  (movl (% arg) (% imm0))
+  (jmp-subprim .SPmakeu32)
+  @done
+  (single-value-return))
+
+;;; "areas" are fixnum-tagged and, for the most part, so are their
+;;; contents.
+
+;;; The nilreg-relative global all-areas is a doubly-linked-list header
+;;; that describes nothing.  Its successor describes the current/active
+;;; dynamic heap.  Return a fixnum which "points to" that area, after
+;;; ensuring that the "active" pointers associated with the current thread's
+;;; stacks are correct.
+
+(defx8632lapfunction %normalize-areas ()
+  (let ((address temp0)
+        (temp temp1))
+
+    ; update active pointer for tsp area.
+    (movl (@ (% :rcontext) x8632::tcr.ts-area) (% address))
+    (movl (@ (% :rcontext) x8632::tcr.save-tsp) (% temp))
+    (movl (% temp) (@ x8632::area.active (% address)))
+    
+    ;; Update active pointer for vsp area.
+    (movl (@ (% :rcontext) x8632::tcr.vs-area) (% address))
+    (movl (% esp) (@ x8632::area.active (% address)))
+
+    (ref-global all-areas arg_z)
+    (movl (@ x8632::area.succ (% arg_z)) (% arg_z))
+
+    (single-value-return)))
+
+(defx8632lapfunction %active-dynamic-area ()
+  (ref-global all-areas arg_z)
+  (movl (@ x8632::area.succ (% arg_z)) (% arg_z))
+  (single-value-return))
+
+(defx8632lapfunction %object-in-stack-area-p ((object arg_y) (area arg_z))
+  (rcmp (% object) (@ x8632::area.active (% area)))
+  (movl ($ nil) (% temp0))
+  (movl ($ t) (% imm0))
+  (jb @done)
+  (rcmp (% object) (@ x8632::area.high (% area)))
+  (cmovbl (% imm0) (% temp0))
+  @done
+  (movl (% temp0) (% arg_z))
+  (single-value-return))
+
+(defx8632lapfunction %object-in-heap-area-p ((object arg_y) (area arg_z))
+  (rcmp (% object) (@ x8632::area.low (% area)))
+  (movl ($ nil) (% temp0))
+  (movl ($ t) (% imm0))
+  (jb @done)
+  (rcmp (% object) (@ x8632::area.active (% area)))
+  (cmovbl (% imm0) (% temp0))
+  @done
+  (movl (% temp0) (% arg_z))
+  (single-value-return))
+
+
+
+
+(defx8632lapfunction use-lisp-heap-gc-threshold ()
+  "Try to grow or shrink lisp's heap space, so that the free space is (approximately) equal to the current heap threshold. Return NIL"
+  (check-nargs 0) 
+  (movl ($ arch::gc-trap-function-use-lisp-heap-threshold) (% imm0))
+  (uuo-gc-trap)
+  (movl ($ x8632::nil-value) (%l arg_z))
+  (single-value-return))
+
+;;; offset is a fixnum, one of the x8632::kernel-import-xxx constants.
+;;; Returns that kernel import, a fixnum.
+(defx8632lapfunction %kernel-import ((offset arg_z))
+  (mark-as-imm temp0)
+  (let ((imm1 temp0))
+    (ref-global kernel-imports imm1)
+    (unbox-fixnum arg_z imm0)
+    (movl (@ (% imm1) (% imm0)) (% imm0))
+    (box-fixnum imm0 arg_z))
+  (mark-as-node temp0)
+  (single-value-return))
+
+(defx8632lapfunction %get-unboxed-ptr ((macptr arg_z))
+  (macptr-ptr arg_z imm0)
+  (movl (@ (% imm0)) (% arg_z))
+  (single-value-return))
+
+(defx8632lapfunction %revive-macptr ((p arg_z))
+  (movb ($ x8632::subtag-macptr) (@ x8632::misc-subtag-offset (% p)))
+  (single-value-return))
+
+(defx86lapfunction %macptr-type ((p arg_z))
+  (check-nargs 1)
+  (trap-unless-typecode= p x8632::subtag-macptr)
+  (svref p x8632::macptr.type-cell imm0)
+  (box-fixnum imm0 arg_z)
+  (single-value-return))
+  
+(defx86lapfunction %macptr-domain ((p arg_z))
+  (check-nargs 1)
+  (trap-unless-typecode= p x8632::subtag-macptr)
+  (svref p x8632::macptr.domain-cell imm0)
+  (box-fixnum imm0 arg_z)
+  (single-value-return))
+
+(defx8632lapfunction %set-macptr-type ((p arg_y) (new arg_z))
+  (check-nargs 2)
+  (trap-unless-typecode= p x8632::subtag-macptr)
+  (unbox-fixnum new imm0)
+  (svset p x8632::macptr.type-cell imm0)
+  (single-value-return))
+
+(defx8632lapfunction %set-macptr-domain ((p arg_y) (new arg_z))
+  (check-nargs 2)
+  (trap-unless-typecode= p x8632::subtag-macptr)
+  (unbox-fixnum new imm0)
+  (svset p x8632::macptr.domain-cell imm0)
+  (single-value-return))
+
+;;; N.B. nargs is the same register as imm0
+(defx8632lapfunction true ()
+  (movzwl (% nargs) (% imm0))
+  (subl ($ '2) (% imm0))
+  (leal (@ '2 (% esp) (% imm0)) (% imm0))
+  (cmoval (% imm0) (% esp))
+  (movl ($ x8632::t-value) (% arg_z))
+  (single-value-return))
+
+(defx8632lapfunction false ()
+  (movzwl (% nargs) (% imm0))
+  (subl ($ '2) (% imm0))
+  (leal (@ '2 (% esp) (% imm0)) (% imm0))
+  (cmoval (% imm0) (% esp))
+  (movl ($ x8632::nil-value) (% arg_z))
+  (single-value-return))
