Index: /branches/ia32/lisp-kernel/x86-macros.s
===================================================================
--- /branches/ia32/lisp-kernel/x86-macros.s	(revision 8068)
+++ /branches/ia32/lisp-kernel/x86-macros.s	(revision 8069)
@@ -41,5 +41,5 @@
 
 define([box_fixnum],[
-        imulq [$]fixnumone,$1,$2
+        imul [$]fixnumone,$1,$2
 ])	
 
@@ -47,7 +47,15 @@
 /* box_fixnum, with no effect on flags */
 define([box_fixnum_no_flags],[
-        leaq (,$1,8),$2
-])
-                                
+        lea (,$1,fixnumone),$2
+])
+
+ifdef([X8632],[
+define([save_node_regs],[
+	push %arg_z
+	push %arg_y
+	push %temp0
+	push %temp1
+	push %fn
+])],[
 define([save_node_regs],[
 	push %arg_z
@@ -63,9 +71,17 @@
 	push %ra0
 	push %fn
-])
+])])
 
 /* This needs to be done before we transition back to the lisp stack  */
 /* from the foreign stack.   */
-		
+
+ifdef([X8632],[
+define([zero_node_regs],[
+	xor %fn,%fn
+	mov %fn,%temp1
+	mov %fn,%temp0
+	mov %fn,%arg_y
+	mov %fn,%arg_z
+])],[
 define([zero_node_regs],[
 	xor %fn,%fn
@@ -81,5 +97,14 @@
 	mov %fn,%arg_y
 	mov %fn,arg_z
-])	
+])])
+
+ifdef([X8632],[
+define([restore_node_regs],[
+	pop %fn
+	pop %temp1
+	pop %temp0
+	pop %arg_y
+	pop %arg_z
+])],[
 define([restore_node_regs],[
 	pop %fn
@@ -95,5 +120,5 @@
 	pop %arg_y
 	pop %arg_z
-])	
+])])
 
 /* Zero $3 bytes worth of dnodes, starting at offset $2 relative  */
@@ -104,5 +129,9 @@
 	.macro zero_dnodes
 	.if $2
+	ifdef([X8632],[
+	movsd %fpzero,$1($0)
+	],[
 	movapd %fpzero,$1($0)
+	])
 	zero_dnodes $0,$1+dnode_size,$2-dnode_size
 	.endif
@@ -111,5 +140,9 @@
 	.macro zero_dnodes base,disp,nbytes
 	.ifgt \nbytes
+	ifdef([X8632],[
+	movsd %fpzero,\disp(\base)
+	],[
 	movapd %fpzero,\disp(\base)
+	])
 	zero_dnodes \base,"\disp+dnode_size","\nbytes-dnode_size"
 	.endif
@@ -120,5 +153,16 @@
 /* Allocate $1+dnode_size zeroed bytes on the tstack, using $2 as a temp  */
 /* reg.  */
-	
+
+ifdef([X8632],[
+define([TSP_Alloc_Fixed],[
+	define([TSP_Alloc_Size],[((($1+node_size) & ~(dnode_size-1))+dnode_size)])
+	subl [$]TSP_Alloc_Size,%rcontext:tcr.next_tsp
+        movd %rcontext:tcr.save_tsp,%stack_temp
+        movl %rcontext:tcr.next_tsp,$2
+	zero_dnodes $2,0,TSP_Alloc_Size
+	movd %stack_temp,($2)
+        movl $2,%rcontext:tcr.save_tsp
+	undefine([TSP_Alloc_Size])
+])],[
 define([TSP_Alloc_Fixed],[
 	define([TSP_Alloc_Size],[((($1+node_size) & ~(dnode_size-1))+dnode_size)])
@@ -130,9 +174,28 @@
         movq $2,%rcontext:tcr.save_tsp
 	undefine([TSP_Alloc_Size])
-])
+])])
 
 /* $1 = size (dnode-aligned, including tsp overhead, $2 scratch.  */
 /* Modifies both $1 and $2; on exit, $2 = new_tsp+tsp_overhead, $1 = old tsp  */
-	
+
+ifdef([X8632],[
+define([TSP_Alloc_Var],[
+	new_macro_labels()
+        subl $1,%rcontext:tcr.next_tsp
+        movd %rcontext:tcr.save_tsp,%stack_temp
+        movl %rcontext:tcr.next_tsp,$2
+	jmp macro_label(test)
+macro_label(loop):
+	movapd %fpzero,0($2)
+	addl $dnode_size,$2
+macro_label(test):	
+	subl $dnode_size,$1
+	jge macro_label(loop)
+        movl %rcontext:tcr.next_tsp,$2
+	movd %stack_temp,$1
+	movl $1,($2)
+        movl $2,%rcontext:tcr.save_tsp
+	addl $dnode_size,$2
+])],[
 define([TSP_Alloc_Var],[
 	new_macro_labels()
@@ -152,16 +215,39 @@
         movq $2,%rcontext:tcr.save_tsp
 	addq $dnode_size,$2
-])
-	
-	
-
+])])
+	
+	
+ifdef([X8632],[
+define([Allocate_Catch_Frame],[
+	TSP_Alloc_Fixed(catch_frame.size,$1)
+	movl [$](catch_frame.element_count<<subtag_shift)|subtag_catch_frame,dnode_size($1)
+	addl [$]dnode_size+fulltag_misc,$1
+])],[
 define([Allocate_Catch_Frame],[
 	TSP_Alloc_Fixed(catch_frame.size,$1)
 	movq [$](catch_frame.element_count<<subtag_shift)|subtag_catch_frame,dnode_size($1)
 	addq [$]dnode_size+fulltag_misc,$1
-])
+])])
 
 /* %arg_z = tag,  %xfn = pc, $1 = mvflag 	  */
-	
+
+ifdef([X8632],[
+define([Make_Catch],[
+	Allocate_Catch_Frame(%imm0)
+	movd %rcontext:tcr.catch_top,%mm0
+	movd %rcontext:tcr.db_link,%mm1
+	movq %arg_z,catch_frame.catch_tag(%imm0)
+	movd %mm0,catch_frame.link(%imm0)
+	movq [$]$1,catch_frame.mvflag(%imm0)
+	movd %rcontext:tcr.xframe,%mm0
+	movq %esp,catch_frame.esp(%imm0)
+	movq %ebp,catch_frame.ebp(%imm0)
+        movd %rcontext:tcr.foreign_sp,%stack_temp
+	movd %mm1,catch_frame.db_link(%imm0)
+	movd %imm0,catch_frame.xframe(%imm0)
+	movd %stack_temp,catch_frame.foreign_sp(%imm0)
+	movl %xfn,catch_frame.pc(%imm0)
+	movd %imm0,%rcontext:tcr.catch_top
+])],[
 define([Make_Catch],[
 	Allocate_Catch_Frame(%imm2)
@@ -184,6 +270,25 @@
 	movq %xfn,catch_frame.pc(%imm2)
 	movq %imm2,%rcontext:tcr.catch_top
-])	
-
+])])	
+
+ifdef([X8632],[
+define([nMake_Catch],[
+	Allocate_Catch_Frame(%imm0)
+	movd %rcontext:tcr.catch_top,%mm0
+	movd %rcontext:tcr.db_link,%mm1
+	movl %arg_z,catch_frame.catch_tag(%imm0)
+	movd %mm0,catch_frame.link(%imm0)
+	movl %esp,catch_frame.esp(%imm0)
+	addl $node_size,catch_frame.esp(%imm0)
+	movl [$]$1,catch_frame.mvflag(%imm0)
+	movd %rcontext:tcr.xframe,%mm0
+	movl %ebp,catch_frame.ebp(%imm0)
+        movd %rcontext:tcr.foreign_sp,%stack_temp
+	movd %mm1,catch_frame.db_link(%imm0)
+	movd %mm0,catch_frame.xframe(%imm0)
+	movd %stack_temp,catch_frame.foreign_sp(%imm0)
+	movl %xfn,catch_frame.pc(%imm0)
+	movl %imm0,%rcontext:tcr.catch_top
+])],[	
 define([nMake_Catch],[
 	Allocate_Catch_Frame(%imm2)
@@ -207,5 +312,5 @@
 	movq %xfn,catch_frame.pc(%imm2)
 	movq %imm2,%rcontext:tcr.catch_top
-])	
+])])	
         	
 	
@@ -242,16 +347,37 @@
 ])
 
-/* The header has to be in %imm0, and the physical size in bytes has  */
-/*  to be in %imm1. We bash %imm1.   */
-
+ifdef([X8632],[
+/* Header in %mm0, size in bytes in %imm0.  We bash %imm0. */
+define([Misc_Alloc],[
+	sub [$]fulltag_misc,%imm0
+	Misc_Alloc_Internal($1)
+])],[
+/* Header in %imm0, size in bytes in %imm1.  We bash %imm1. */
 define([Misc_Alloc],[
 	subq [$]fulltag_misc,%imm1
 	Misc_Alloc_Internal($1)
-])
-
-define([Misc_Alloc_Internal],[			
+])])
+
+
 /* Here Be Monsters: we have to treat some/all of this instruction   */
 /* sequence atomically, as soon as tcr.save_allocptr becomes tagged.  */
                 
+ifdef([X8632],[
+define([Misc_Alloc_Internal],[                  
+        new_macro_labels()
+        subl %imm0,%rcontext:tcr.save_allocptr      /* decrement allocptr */
+        movl %rcontext:tcr.save_allocptr,%allocptr  /* load into temp0 */
+        cmpl %rcontext:tcr.save_allocbase,%allocptr /* above allocbase? */
+        jg macro_label(no_trap)			    /* yes, skip trap */
+        uuo_alloc()				    /* uh, don't skip trap */
+macro_label(no_trap):   
+        movd %mm0,misc_header_offset(%allocptr)		/* write header */
+        andb $~fulltagmask,%rcontext:tcr.save_allocptr	/* untag allocptr */
+/* Now that tcr.save_allocptr is untagged, it's easier to be interrupted   */
+        ifelse($1,[],[],[
+         mov %allocptr,$1
+        ])
+])],[	
+define([Misc_Alloc_Internal],[			
 	new_macro_labels()
 	subq %imm1,%rcontext:tcr.save_allocptr
@@ -267,10 +393,15 @@
 	 mov %allocptr,$1
 	])
-])
-	
+])])
+
+ifdef([X8632],[
 define([Misc_Alloc_Fixed],[
-	movq [$]$2-fulltag_misc,%imm1
+	mov [$]$2-fulltag_misc,%imm0
 	Misc_Alloc_Internal($1)
-])					
+])],[
+define([Misc_Alloc_Fixed],[
+	mov [$]$2-fulltag_misc,%imm1
+	Misc_Alloc_Internal($1)
+])])					
 
 define([vrefr],[
@@ -279,5 +410,5 @@
 
 define([jump_fn],[
-	jmpq *%fn
+	jmp *%fn
 ])
 			
@@ -296,21 +427,27 @@
 
 define([_car],[
-	movq cons.car($1),$2
+	mov cons.car($1),$2
 ])	
 
 define([_rplaca],[
-	movq $2,cons.car($1)
+	mov $2,cons.car($1)
 ])	
 		
 define([_cdr],[
-	movq cons.cdr($1),$2
+	mov cons.cdr($1),$2
 ])
 
 define([_rplacd],[
-	movq $2,cons.cdr($1)
+	mov $2,cons.cdr($1)
 ])	
 		
 	
-	
+ifdef([X8632],[
+define([tra],[
+        .p2align 3
+	.long 0
+	.byte 0
+$1:	
+])],[
 define([tra],[
         .p2align 3
@@ -321,6 +458,27 @@
 	])
 $1:	
-])
-				
+])])
+
+ifdef([X8632],[
+define([do_funcall],[
+	new_macro_labels()
+	movl %imm0,%temp1 /* preserve nargs */
+	extract_fulltag(%temp0,%imm0)
+	cmpb $fulltag_misc,%imm0_b
+	movl %temp1,%imm0
+	jne macro_label(bad)
+	cmpb $subtag_function,misc_subtag_offset(%temp0)
+	jne macro_label(maybe_symbol)
+	mov %temp0,%fn
+	jmp *%fn
+macro_label(maybe_symbol):
+	cmpb $subtag_symbol,misc_subtag_offset(%temp0)
+	jne macro_label(bad)
+	/* %fname == %temp0 */
+	mov symbol.fcell(%fname),%fn
+	jmp *%fn
+macro_label(bad):
+	__(uuo_error_not_callable)
+])],[
 define([do_funcall],[
 	new_macro_labels()
@@ -335,8 +493,8 @@
 macro_label(bad):		
 	__(uuo_error_not_callable)
-])
+])])
 
 define([getvheader],[
-        movq misc_header_offset($1),$2
+        mov misc_header_offset($1),$2
 ])
 
@@ -344,5 +502,5 @@
 /*    both be immediate registers   */
 define([header_size],[
-        movq $1,$2
+        mov $1,$2
         shr $num_subtag_bits,$2
 ])
@@ -350,6 +508,6 @@
 /* $2 (length) is fixnum element-count.   */
 define([header_length],[
-        movq $~255,$2
-        andq $1,$2
+        mov $~255,$2
+        and $1,$2
         shr $num_subtag_bits-fixnumshift,$2
 ])
@@ -363,6 +521,6 @@
 /* $1 = vector, $2 = dest   */
 define([vector_length],[                                 
-        movq $~255,$2
-        andq misc_header_offset($1),$2
+        mov $~255,$2
+        and misc_header_offset($1),$2
         shr $num_subtag_bits-fixnumshift,$2
 ])
@@ -392,7 +550,11 @@
 ])
 
+ifdef([X8632],[
+define([compare_reg_to_nil],[
+	cmp $nil_value,$1
+])],[
 define([compare_reg_to_nil],[
 	cmpb $fulltag_nil,$1_b
-])		
+])])
 	
 define([extract_lisptag],[
@@ -413,5 +575,5 @@
 define([extract_typecode],[
 	new_macro_labels()
-	movzbl $1_b,$2_l
+	mov $1,$2
 	andb $tagmask,$2_b
 	cmpb $tag_misc,$2_b
@@ -423,9 +585,20 @@
 /* dnode_align(src,delta,dest)  */
 
-        define([dnode_align],[
+define([dnode_align],[
         lea ($2+(dnode_size-1))($1),$3
 	andb $~(dnode_size-1),$3_b
 ])
-	
+
+ifdef([X8632],[
+define([push_argregs],[
+	new_macro_labels()
+	cmpw [$]1*node_size,%nargs
+	jb macro_label(done)
+	je macro_label(z)
+	push %arg_y
+macro_label(z):
+	push %arg_z
+macro_label(done):
+])],[
 define([push_argregs],[
 	new_macro_labels()
@@ -441,5 +614,5 @@
 	push %arg_z
 macro_label(done):
-])	
+])])	
 
 
@@ -448,16 +621,22 @@
 
 define([discard_temp_frame],[
-	movq %rcontext:tcr.save_tsp,$1
-	movq ($1),$1
-        movq $1,%rcontext:tcr.save_tsp
-        movq $1,%rcontext:tcr.next_tsp
-
-])	
-
+	mov %rcontext:tcr.save_tsp,$1
+	mov ($1),$1
+        mov $1,%rcontext:tcr.save_tsp
+        mov $1,%rcontext:tcr.next_tsp
+
+])	
+
+ifdef([X8632],[	
+define([check_pending_enabled_interrupt],[
+	btrl [$]31,%rcontext:tcr.interrupt_pending
+	jnc,pt $1
+	interrupt_now()
+])],[
 define([check_pending_enabled_interrupt],[
 	btrq [$]63,%rcontext:tcr.interrupt_pending
 	jnc,pt $1
 	interrupt_now()
-])
+])])
 	
 /* $1 = scratch register, used to access tcr.tlb_pointer.  An interrupt  */
@@ -468,6 +647,6 @@
 define([check_pending_interrupt],[
 	new_macro_labels()
-	movq %rcontext:tcr.tlb_pointer,$1
-	cmpq [$]0,INTERRUPT_LEVEL_BINDING_INDEX($1)
+	mov %rcontext:tcr.tlb_pointer,$1
+	cmp [$]0,INTERRUPT_LEVEL_BINDING_INDEX($1)
 	js,pt macro_label(done)
 	check_pending_enabled_interrupt(macro_label(done))
@@ -513,4 +692,25 @@
          ret
 ])
-                                
-        
+
+ifdef([X8632],[
+define([regnum],[ifelse($1, [eax], [0],
+       $1, [ecx], [1],
+       $1, [edx], [2],
+       $1, [ebx], [3],
+       $1, [esp], [4],
+       $1, [ebp], [5],
+       $1, [esi], [6],
+       $1, [edi], [7])dnl
+])
+
+define([mark_as_node], [
+	xorl %$1, %$1
+        orb [$](1<<regnum($1)), %rcontext:tcr.node_regs_mask
+])
+
+define([mark_as_imm],[
+        andb [$]~(1<<regnum($1)), %rcontext:tcr.node_regs_mask
+])
+
+])
+
