Index: /branches/arm/lisp-kernel/arm-spentry.s
===================================================================
--- /branches/arm/lisp-kernel/arm-spentry.s	(revision 13803)
+++ /branches/arm/lisp-kernel/arm-spentry.s	(revision 13804)
@@ -1752,25 +1752,28 @@
         __(unbox_fixnum(imm1,arg_z))
         __(dnode_align(imm1,imm1,0))
-        __(add imm1,imm1,#macptr.size+node_size)
+        __(add imm1,imm1,#node_size)
         __(add imm0,imm1,#node_size)
+        __(cmp imm0,#stack_alloc_limit)
+        __(mov temp0,sp)
+        __(bhs 1f)
         __(mov imm1,imm1,lsl #num_subtag_bits)
         __(orr imm1,imm1,#subtag_u8_vector)
-        __(cmp imm0,#stack_alloc_limit)
-        __(bhs 1f)
         __(stack_allocate_ivector(imm1,imm0))
+        __(add temp1,sp,#dnode_size)
         __(movc16(imm1,make_header(macptr.element_count,subtag_macptr)))
-        __(str imm1,[sp,#dnode_size])
+        __(str imm1,[sp,#-macptr.size]!)
+        __(add arg_z,sp,#fulltag_misc)
+        __(str temp1,[arg_z,#macptr.address])
         __(mov imm0,#0)
-        __(str imm0,[sp,#dnode_size+macptr.type-fulltag_misc])
-        __(str imm0,[sp,#dnode_size+macptr.domain-fulltag_misc])
-        __(add imm0,sp,#macptr.size+dnode_size)
-        __(str imm0,[sp,#dnode_size+macptr.address-fulltag_misc])
-        __(add arg_z,sp,#dnode_size+fulltag_misc)
+        __(mov imm1,#stack_alloc_marker)
+        __(str imm0,[arg_z,#macptr.type])
+        __(str imm0,[arg_z,#macptr.domain])
+        __(stmdb sp!,{imm1,temp0})
         __(bx lr)
 
         /* Too big. Heap cons a gcable macptr  */
 1:
-        __(mov imm1,#subtag_u8_vector)
-        __(str imm1,[sp,#-dnode_size]!)
+        __(mov imm1,#stack_alloc_marker)
+        __(stmdb sp!,{imm1,temp0})
         __(set_nargs(1))
         __(ref_nrs_symbol(fname,new_gcable_ptr,imm0))
@@ -1781,21 +1784,28 @@
         __(unbox_fixnum(imm1,arg_z))
         __(dnode_align(imm1,imm1,0))
-        __(add imm1,imm1,#macptr.size+node_size)
+        __(add imm1,imm1,#node_size)
         __(add imm0,imm1,#node_size)
+        __(cmp imm0,#stack_alloc_limit)
+        __(mov temp0,sp)
+        __(bhs 1f)
         __(mov imm1,imm1,lsl #num_subtag_bits)
         __(orr imm1,imm1,#subtag_u8_vector)
-        __(cmp imm0,#stack_alloc_limit)
-        __(bhs 1f)
-        __(stack_allocate_zeroed_ivector(imm1,imm0))
+        __(stack_allocate_ivector(imm1,imm0))
+        __(add temp1,sp,#dnode_size)
         __(movc16(imm1,make_header(macptr.element_count,subtag_macptr)))
-        __(str imm1,[sp,#dnode_size])
-        __(add imm0,sp,#macptr.size+dnode_size)
-        __(str imm0,[sp,#dnode_size+macptr.address-fulltag_misc])
-        __(add arg_z,sp,#dnode_size+fulltag_misc)
-        __(bx lr)
+        __(str imm1,[sp,#-macptr.size]!)
+        __(add arg_z,sp,#fulltag_misc)
+        __(str temp1,[arg_z,#macptr.address])
+        __(mov imm0,#0)
+        __(mov imm1,#stack_alloc_marker)
+        __(str imm0,[arg_z,#macptr.type])
+        __(str imm0,[arg_z,#macptr.domain])
+        __(stmdb sp!,{imm1,temp0})
+        __(bx lr)
+	
         /* Too big. Heap cons a gcable macptr  */
 1:
-        __(mov imm1,#subtag_u8_vector)
-        __(str imm1,[sp,#-dnode_size]!)
+        __(mov imm1,#stack_alloc_marker)
+        __(stmdb sp!,{imm1,temp0})
         __(mov arg_y,arg_z) /* save block size  */
         __(mov arg_z,#nil_value) /* clear-p arg to %new-gcable-ptr  */
@@ -1970,6 +1980,6 @@
         __(cmp imm0,#subtag_bignum)
         __(uuo_error_reg_not_xtype(ne,arg_z,xtype_integer))
-        __(getvheader(imm0,arg_z))
-        __(header_length(imm0,imm0)) /* boxed length = scaled size  */
+        __(getvheader(imm1,arg_z))
+        __(header_length(imm0,imm1)) /* boxed length = scaled size  */
         __(add imm0,imm0,#misc_data_offset-4) /* bias, less 1 element  */
         __(ldr imm0,[arg_z,imm0])
@@ -2728,5 +2738,5 @@
         __(vpush1(imm1))
 3:      __(subs imm0,imm0,#1)
-        __(bge 2f)
+        __(bge 2b)
         /* Save nargs and temp1 so that we can use them in the loop(s) */
         __(stmdb vsp!,{imm2,temp1})
@@ -2763,6 +2773,6 @@
 local_label(current_key_allow_other_keys_handled):
         __(getvheader(imm0,temp1))
-        __(header_length(imm0,imm0))
-        __(add imm0,imm0,#misc_data_offset)
+        __(header_length(arg_x,imm0))
+        __(add imm0,arg_x,#misc_data_offset)
         __(b local_label(defined_keyword_compare_test))
 local_label(defined_keyword_compare_loop):      
@@ -2780,12 +2790,12 @@
 local_label(defined_keyword_found):     
         __(sub imm0,temp0,imm0,lsl #1)
-        __(ldr arg_x,[imm0,#-4])
+        __(ldr arg_x,[imm0,#-8])
         __(cmp arg_x,#nil_value) /* seen this keyword yet ? */
         __(bne local_label(nextkeyvalpairnext))
         __(add arg_x,arg_x,#t_offset)
-        __(str arg_x,[imm0,#-4])
+        __(str arg_x,[imm0,#-8])
         __(add temp1,sp,#8)
         __(ldr temp1,[temp1,imm2])
-        __(str temp1,[imm0,#0])
+        __(str temp1,[imm0,#-4])
 local_label(nextkeyvalpairnext):
         __(add imm2,imm2,#8)
@@ -2966,9 +2976,13 @@
         __(str temp0,[rcontext,#tcr.last_lisp_frame])
         __(mov temp0,rcontext)
+        __(test_fixnum(arg_z))
+        __(moveq imm1,arg_z,asr #fixnumshift)
+        __(ldrne imm1,[arg_z,#misc_data_offset])
         __(mov imm0,#TCR_STATE_FOREIGN)
         __(str imm0,[rcontext,#tcr.valence])
+        __(mov r4,imm1)
         __(add sp,sp,#dnode_size)
         __(ldmia sp!,{r0,r1,r2,r3})
-        __(blx arg_z)           /* fix this */
+        __(blx r4) 
         __(mov temp1,#0)
         __(mov temp2,#0)
@@ -3112,6 +3126,6 @@
 local_label(not_aok):   
         __(getvheader(imm0,keyvect_reg))
-        __(header_length(imm0,imm0))
-        __(add imm0,imm0,#misc_data_offset)
+        __(header_length(arg_y,imm0))
+        __(add imm0,arg_y,#misc_data_offset)
         __(b local_label(match_key_test))
 local_label(match_key_loop):    
@@ -4051,5 +4065,5 @@
         __(str arg_y,[rcontext,#tcr.xframe])
         __(beq local_label(_nthrow1v_dont_unbind))
-        __(do_unbind_to(imm0,temp1,arg_x,arg_y))
+        __(do_unbind_to(imm1,temp1,arg_x,arg_y))
 local_label(_nthrow1v_dont_unbind):
         __(ldr temp1,[temp0,#catch_frame.catch_tag])
@@ -4058,42 +4072,35 @@
         /* A catch frame.  If the last one, restore context from there.  */
         __(cmp temp2,#0)
-        __(ldreq vsp,[sp,#lisp_frame.savevsp])
+        __(ldreq vsp,[sp,#catch_frame.size+lisp_frame.savevsp])
         __(add sp,sp,#catch_frame.size+lisp_frame.size)
         __(b local_label(_nthrow1v_nextframe))
 local_label(_nthrow1v_do_unwind):
-pushdef(`__',`
-        .word 0
-        ')        
         /* This is harder, but not as hard (not as much BLTing) as the  */
         /* multiple-value case.  */
         /* Save our caller's LR and FN in the csp frame created by the unwind-  */
         /* protect.  (Clever, eh ?)  */
-
-        __(la tsp,-(tsp_frame.fixed_overhead+fulltag_misc)(temp0))
-        __(unlink(tsp))
-        __(ldr loc_pc,[sp,#lisp_frame.savelr])
-        __(ldr nfn,[sp,#lisp_frame.savefn])
-        __(mtctr loc_pc)  /* cleanup code address.  */
-        __(str(fn,lisp_frame.savefn(sp)))
-        __(mflr loc_pc)
+        __(add sp,sp,#catch_frame.size)
+        /* swp is deprecated on ARMv6+.  It's not useful as a basis
+           for synchronization, but that's not why we're using it here. */
+        __(mov imm1,#0)
+        __(mov temp0,sp)
+        __(mov imm0,#3<<num_subtag_bits)
+        __(orr imm0,imm0,#subtag_simple_vector)
+        __(stmdb sp!,{imm0,imm1,arg_z,temp2})
+        __(add imm0,temp0,#lisp_frame.savelr)
+        __(swp lr,lr,[imm0])
+        __(ldr nfn,[temp0,#lisp_frame.savefn])
+        __(str fn,[temp0,#lisp_frame.savefn])
+        __(ldr vsp,[temp0,#lisp_frame.savevsp])
         __(mov fn,nfn)
-        __(str(loc_pc,lisp_frame.savelr(sp)))
-        __(TSP_Alloc_Fixed_Boxed(2*node_size)) /* tsp overhead, value, throw count  */
-        __(str(arg_z,tsp_frame.data_offset(tsp)))
-        __(str(temp2,tsp_frame.data_offset+node_size(tsp)))
-        __(ldr vsp,[sp,#lisp_frame.savevsp])
-        __(str(rzero,tcr.unwinding(rcontext)))
-        __(bctrl)
+        __(str imm1,[rcontext,#tcr.unwinding])
+        __(blx lr)
         __(mov imm1,#1)
-        __(ldr arg_z,[tsp,#tsp_frame.data_offset])
-        __(str(imm1,tcr.unwinding(rcontext)))
-        __(ldr temp2,[tsp,#tsp_frame.data_offset+node_size])
-        __(ldr fn,[sp,#lisp_frame.savefn])
-        __(ldr loc_pc,[sp,#lisp_frame.savelr])
-        __(discard_lisp_frame())
-        __(mtlr loc_pc)
-        __(unlink(tsp))
+        __(ldr arg_z,[sp,#8])
+        __(str imm1,[rcontext,#tcr.unwinding])
+        __(ldr temp2,[sp,#12])
+        __(add sp,sp,#4*node_size)
+        __(restore_lisp_frame(imm0))
         __(b local_label(_nthrow1v_nextframe))
-popdef(`__')        
 local_label(_nthrow1v_done):
         __(mov imm0,#0)
