Index: /branches/arm/lisp-kernel/arm-constants.s
===================================================================
--- /branches/arm/lisp-kernel/arm-constants.s	(revision 13679)
+++ /branches/arm/lisp-kernel/arm-constants.s	(revision 13680)
@@ -43,20 +43,16 @@
 
 /* registers.  These assignments may not be viable. */
-/* a lisp_frame contains the caller's fn, vsp (or an adjusted copy), */
-/*  a proxy for sp, and the lr. (we need to use a proxy for sp, since */
-/*   use of sp in the register list is deprecated and we generally save / */
-/*   restore lisp_frames on sp and use writeback to sp. */
-
-define(`fn',`r0')
-define(`vsp',`r1')
-define(`arg_z',`r2')
-define(`arg_y',`r3')
-define(`arg_x',`r4')
-define(`temp0',`r5')
-define(`temp1',`r6')
-define(`temp2',`r7')
-define(`imm0',`r8')             /* even, so ldrd/strd can use imm0/imm1 */
-define(`imm1',`r9')
-define(`imm2',`r10')
+
+define(`arg_z',`r0')
+define(`arg_y',`r1')
+define(`arg_x',`r2')
+define(`temp0',`r3')
+define(`temp1',`r4')
+define(`temp2',`r5')
+define(`imm0',`r6')             /* even, so ldrd/strd can use imm0/imm1 */
+define(`imm1',`r7')
+define(`imm2',`r9')
+define(`vsp',`r9')
+define(`fn',`r10')
 define(`rcontext',`r11')
 define(`allocptr',`r12')
@@ -128,5 +124,9 @@
 nil_value = (0x10000000+fulltag_nil)
 misc_bias = fulltag_misc
-cons_bias = tag_list        
+cons_bias = tag_list    
+        
+unsigned_byte_24_mask = 0xe0000003 /* bits that should be clear in a boxed */
+                                   /* (UNSIGNED-BYTE 24) */
+            
 
 /* Functions are of (conceptually) unlimited size. */
@@ -190,4 +190,5 @@
 		
 /*Immediate subtags. */
+        define_subtag(lisp_frame_marker,fulltag_imm,2) 
 	define_subtag(character,fulltag_imm,9)
 	define_subtag(unbound,fulltag_imm,6)
@@ -201,4 +202,7 @@
 illegal_marker = subtag_illegal
 no_thread_local_binding_marker = subtag_no_thread_local_binding
+lisp_frame_marker = subtag_lisp_frame_marker        
+	
+
 /*Numeric subtags. */
 
@@ -337,7 +341,7 @@
         	
 	_struct(lisp_frame,0)
+         _node(marker)
 	 _node(savefn) 
 	 _node(savevsp)	
-	 _node(savesp)	
 	 _node(savelr)	
 	_ends
@@ -676,5 +680,4 @@
 define(`TCR_STATE_EXCEPTION_RETURN',4)
 
-define(`RESERVATION_DISCHARGE',0x2004)
 
 lisp_globals_limit = fulltag_nil
@@ -750,5 +753,5 @@
 xtype_bit = 40                               
                                                
-                        
+stack_alloc_limit = 0x8000                        
                         
 INTERRUPT_LEVEL_BINDING_INDEX = fixnumone
Index: /branches/arm/lisp-kernel/arm-macros.s
===================================================================
--- /branches/arm/lisp-kernel/arm-macros.s	(revision 13679)
+++ /branches/arm/lisp-kernel/arm-macros.s	(revision 13680)
@@ -168,8 +168,7 @@
 ')
 
-/* This approach may not work if the symbol is too far from nil */        
 define(`ref_nrs_symbol',`
-        __(mov $1,#nil_value)
-        __(add $1,$1,#nrs.$2)
+        __(movc16($3,nrs.$2))
+        __(add $1,$3,#nil_value)
         ')
 	
@@ -216,17 +215,21 @@
 
 
-/* $1 = sp copy for instruction restriction, $2 = value for lisp_frame.savevsp */                
+/* $1 = arg/temp reg for lisp_frame_marker, $2 = value for lisp_frame.savevsp */                
 define(`build_lisp_frame',`
-        __(mov $1,sp)
-        __(stmdb sp!,{fn,ifelse($2,$2,vsp),$1,lr})
-')
-
-/* Have to use a temp (> vsp, < sp) to avoid having sp in the register list */
+        __(mov $1,#lisp_frame_marker)
+        __(stmdb sp!,{$1,ifelse($2,$2,vsp),fn,lr})
+')
+
+/* This has the odd side effect of loading lisp_frame_marker into
+   the arg/temp/imm reg $1.  I think that that's probably better
+   than adjusting sp and loading the other regs ; it'd be good
+   to say (at interrupt time) that there's either a lisp frame
+   on the stack or there isn't. */
 define(`restore_lisp_frame',`
-        __(ldm sp!,{fn,vsp,$1,lr})
+        __(ldm sp!,{$1,vsp,fn,lr})
         ')
 
 define(`return_lisp_frame',`
-        __(ldm sp!,{fn,vsp,$1,pc})
+        __(ldm sp!,{$1,vsp,fn,pc})
         ')
         
@@ -411,111 +414,23 @@
 ')
 
-
-/*  Zero $3 bytes worth of doublewords, starting at offset $2 relative */
-/* to the base register $1. */
-
-
-ifdef(`DARWIN',`
-	.macro zero_doublewords
-	.if $2
-	stfd fp_zero,$1($0)
-	zero_doublewords $0,$1+8,$2-8
-	.endif
-	.endmacro
-')
-
-ifdef(`LINUX',`
-	.macro zero_doublewords base,disp,nbytes
-	.if \nbytes
-	stfd fp_zero,\disp(\base)
-	zero_doublewords \base,\disp+8,\nbytes-8
-	.endif
-	.endm
-')	
-
-define(`Set_TSP_Frame_Unboxed',`
-	__(str(tsp,tsp_frame.type(tsp)))
-')
-
-define(`Set_TSP_Frame_Boxed',`
-	__(str(rzero,tsp_frame.type(tsp)))
-')
-		
-/* A newly allocated TSP frame is always "raw" (has non-zero type, indicating */
-/* that it doesn't contain tagged data. */
-
-define(`TSP_Alloc_Fixed_Unboxed',`
-	__(stru(tsp,-($1+tsp_frame.data_offset)(tsp)))
-	__(Set_TSP_Frame_Unboxed())
-')
-
-define(`TSP_Alloc_Fixed_Unboxed_Zeroed',`
-	__(TSP_Alloc_Fixed_Unboxed($1))
-	__(zero_doublewords tsp,tsp_frame.fixed_overhead,$1)
-')
-
-define(`TSP_Alloc_Fixed_Boxed',`
-	__(TSP_Alloc_Fixed_Unboxed_Zeroed($1))
-	__(Set_TSP_Frame_Boxed())
-')
-
-
-        
-	
-
-/* This assumes that the backpointer points  to the first byte beyond */
-/* each frame.  If we allow segmented tstacks, that constraint might */
-/* complicate  their implementation. */
-/* We don't need to know the size of the frame (positive or negative, */
-/* with or without header).  $1 and $2 are temp registers, $3 is an */
-/* optional CR field. */
-
-
-/* Handle the general case, where the frame might be empty */
-define(`Zero_TSP_Frame',`
-	__(new_macro_labels())
-	__(la $1,tsp_frame.size-8(tsp))
-	__(ldr($2,tsp_frame.backlink(tsp)))
-	__(la $2,-8($2))
-	__(b macro_label(zero_tsp_test))
-macro_label(zero_tsp_loop):
-	__(stfdu fp_zero,8($1))
-macro_label(zero_tsp_test):	
-	__(cmpr(ifelse($3,`',`cr0',$3),$1,$2))
-	__(bne ifelse($3,`',`cr0',$3),macro_label(zero_tsp_loop))
-')
-
-/* Save some branching when we know that the frame can't be empty.*/
-define(`Zero_TSP_Frame_nz',`
-	new_macro_labels()
-	__(la $1,tsp_frame.size-8(tsp))
-	__(ldr($2,tsp_frame.backlink(tsp)))
-	__(la $2,-8($2))
-macro_label(zero_tsp_loop):
-	__(stfdu fp_zero,8($1))
-	__(cmpr(ifelse($3,`',`cr0',$3),$1,$2))
-	__(bne ifelse($3,`',`cr0',$3),macro_label(zero_tsp_loop))
-')
-	
-/* $1 = 8-byte-aligned size, positive.  $2 (optiional) set */
-/* to negated size. */
-define(`TSP_Alloc_Var_Unboxed',`
-	__(neg ifelse($2,`',$1,$2),$1)
-	__(strux(tsp,tsp,ifelse($2,`',$1,$2)))
-	__(Set_TSP_Frame_Unboxed())
-')
-
-define(`TSP_Alloc_Var_Boxed',`
-	__(TSP_Alloc_Var_Unboxed($1))
-	__(Zero_TSP_Frame($1,$2))
-	__(Set_TSP_Frame_Boxed())
-')		
-
-
-define(`TSP_Alloc_Var_Boxed_nz',`
-	__(TSP_Alloc_Var_Unboxed($1))
-	__(Zero_TSP_Frame_nz($1,$2))
-	__(Set_TSP_Frame_Boxed())
-')		
+/* Stack-allocate an ivector and zero its contents; caller may
+   change subtag of header after it's zeroed. 
+   $1 = header (tagged as subtag_u32_vector until zeroed), $2 = dnode-
+   aligned size in bytes).  Both $1 and $2 are modified here. */
+define(`stack_allocate_zeroed_word_vector',`
+       new_macro_labels()
+        __(str $1,[sp,-$2]!)
+        __(mov $1,#0)
+        __(add $2,sp,$2)
+        __(b macro_label(test))
+macro_label(loop):      
+        __(str $1,[$2])
+macro_label(test):                      
+        __(sub $2,#dnode_size)
+        __(cmp $2,sp)
+        __(str $1,[$2,#node_size])
+        __(bne macro_label(loop))
+        ')
+   
 
 define(`check_enabled_pending_interrupt',`
Index: /branches/arm/lisp-kernel/arm-spentry.s
===================================================================
--- /branches/arm/lisp-kernel/arm-spentry.s	(revision 13679)
+++ /branches/arm/lisp-kernel/arm-spentry.s	(revision 13680)
@@ -185,5 +185,5 @@
 	
 _spentry(makeu64)
-	__(cmp imm1,0)
+	__(cmp imm1,#0)
 	__(beq _SPmakeu32)
 	__(blt 3f)
@@ -983,20 +983,10 @@
         __(mov arg_z,#nil_value)
 C(stkconslist_star):           
-        __(mov temp2,nargs,lsl 1)
+        __(mov temp2,nargs,lsl #1)
         __(add temp2,temp2,#node_size)
         __(mov imm0,temp2,lsl #num_subtag_bits-word_shift)
         __(orr imm0,imm0,#subtag_u32_vector)
-        __(add temp2,temp2,#node_size)
-        __(mov imm1,#0)
-        __(mov temp1,sp)
-        __(str imm0,[sp,-temp2]!)
-        __(add temp2,sp,#dnode_size)
-        __(str imm1,[sp,#node_size])
+        __(stack_allocate_zeroed_word_vector(imm0,temp2))
         __(mov imm0,#subtag_simple_vector)
-        __(b 2f)
-1:      __(str imm1,[temp1,#-node_size]!)
-        __(str imm1,[temp1,#-node_size]!)
-2:      __(cmp temp2,temp1)
-        __(bne 1b)
         __(strb imm0,[sp,#0])
         __(add imm1,sp,#dnode_size+fulltag_cons)
@@ -1024,15 +1014,6 @@
         __(mov imm0,nargs,lsl #num_subtag_bits-fixnumshift)
         __(orr imm0,imm0,#subtag_u32_vector)
-        __(mov temp1,sp)
-        __(str imm0,[sp,-imm1]!)
-        __(mov temp2,#0)
-        __(str temp0,[sp,#node_size])
-        __(add sp,temp0,#dnode_size)
+        __(stack_allocate_zeroed_word_vector(imm0,imm1))
         __(mov imm0,#subtag_simple_vector)
-        __(b 2f)
-1:      __(str temp2,[temp1,#-node_size]!)
-        __(str temp2,[temp1,#-node_size]!)
-2:      __(cmp temp1,temp0)
-        __(bne 1b)
         __(strb imm0,[sp,#0])
         __(add arg_z,sp,#fulltag_misc)
@@ -1132,53 +1113,54 @@
 dnl  
 	
-dnl /* Allocate a miscobj on the temp stack.  (Push a frame on the tsp and  */
-dnl /* heap-cons the object if there's no room on the tstack.)  */
-dnl _spentry(stack_misc_alloc)
-dnl   __(rlwinm. imm2,arg_y,32-fixnumshift,0,(8+fixnumshift)-1)
-dnl   __(unbox_fixnum(imm0,arg_z))
-dnl   __(extract_fulltag(imm1,imm0))
-dnl   __(bne- cr0,9f)
-dnl   __(cmpri(cr0,imm1,fulltag_nodeheader))
-dnl   __(mov imm3,imm0)
-dnl   __(cmplri(cr1,imm0,max_32_bit_ivector_subtag))
-dnl   __(rlwimi imm0,arg_y,num_subtag_bits-fixnum_shift,0,31-num_subtag_bits) /* imm0 now = header  */
-dnl   __(mov imm2,arg_y)
-dnl   __(beq cr0,1f) /* do probe if node object  */
-dnl           /* (fixnum element count = byte count).  */
-dnl   __(cmplri(cr0,imm3,max_16_bit_ivector_subtag))
-dnl   __(bng cr1,1f) /* do probe if 32-bit imm object  */
-dnl   __(cmplri(cr1,imm3,max_8_bit_ivector_subtag))
-dnl   __(srwi imm2,imm2,1)
-dnl   __(bgt cr0,3f)
-dnl   __(bgt cr1,1f)
-dnl   __(srwi imm2,imm2,1)
-dnl /* imm2 now = byte count.  Add 4 for header, 7 to align, then  */
-dnl /* clear low three bits.  */
-dnl 1:
-dnl          __(dnode_align(imm3,imm2,tsp_frame.fixed_overhead+node_size))
-dnl   __(cmplri(cr0,imm3,tstack_alloc_limit)) /* more than limit ?  */
-dnl   __(bgt- cr0,0f)
-dnl   __(TSP_Alloc_Var_Boxed_nz(imm3,imm4))
-dnl 
-dnl /* Slap the header on the vector, then return.  */
-dnl   __(str(imm0,tsp_frame.data_offset(tsp)))
-dnl   __(la arg_z,tsp_frame.data_offset+fulltag_misc(tsp))
-dnl   __(bx lr)
-dnl 9: 
-dnl 
-dnl 
-dnl 
-dnl /* Too large to safely fit on tstack.  Heap-cons the vector, but make  */
-dnl /* sure that there's an empty tsp frame to keep the compiler happy.  */
-dnl 0:
-dnl   __(TSP_Alloc_Fixed_Unboxed(0))
-dnl   __(b _SPmisc_alloc)
-dnl 3:
-dnl   __(cmplri(imm3,subtag_double_float_vector))
-dnl   __(slwi imm2,arg_y,1)
-dnl   __(beq 1b)
-dnl   __(addi imm2,arg_y,7<<fixnumshift)
-dnl   __(srwi imm2,imm2,fixnumshift+3)
-dnl   __(b 1b)
+/* Allocate a uvector on the  stack.  (Push a frame on the stack and  */
+/* heap-cons the object if there's no room on the stack.)  */
+_spentry(stack_misc_alloc)
+        __(tst arg_y,#unsigned_byte_24_mask)
+        __(uuo_error_reg_not_xtype(ne,arg_y,xtype_unsigned_byte_24))
+        __(unbox_fixnum(imm0,arg_z))
+        __(extract_fulltag(imm1,imm0))
+        __(cmp imm1,#fulltag_nodeheader)
+        __(bne 1f)
+        __(dnode_align(imm1,arg_y,node_size))
+        __(cmp imm1,#stack_alloc_limit)
+        __(bge 9f)
+        __(mov imm0,#subtag_u32_vector)
+        __(orr imm0,imm0,arg_y,lsl #num_subtag_bits-fixnumshift)
+        __(stack_allocate_zeroed_word_vector(imm0,imm1))
+        __(unbox_fixnum(imm0,arg_z))
+        __(strb imm0,[sp])
+        __(add arg_z,sp,#fulltag_misc)
+        __(bx lr)
+1:      __(mov imm0,arg_y,lsl #num_subtag_bits-fixnumshift)
+        __(orr imm0,imm0,arg_z,lsr #fixnumshift)
+        __(cmp arg_z,#max_32_bit_ivector_subtag<<fixnumshift)
+        __(movle imm1,arg_y)
+        __(ble 8f)
+        __(cmp arg_z,#max_8_bit_ivector_subtag<<fixnumshift)
+        __(movle imm1,arg_y,lsr #fixnumshift)
+        __(ble 8f)
+        __(cmp arg_z,#max_16_bit_ivector_subtag<<fixnumshift)
+        __(movle imm1,arg_y,lsr #1)
+        __(ble 8f)
+        __(cmp arg_z,#subtag_double_float)
+        __(moveq imm1,arg_y,lsl #1)
+        __(addeq imm1,imm1,#node_size)
+        __(addne imm1,arg_y,#7<<fixnumshift)
+        __(movne imm1,imm1,lsr#3+fixnumshift)
+8:      __(dnode_align(imm1,imm1,node_size))
+        __(cmp imm1,#stack_alloc_limit)
+        __(bhs 9f)
+        __(stack_allocate_zeroed_word_vector(imm0,imm1))
+        __(add arg_z,sp,#fulltag_misc)
+        __(bx lr)
+9: 
+
+/* Too large to safely fit on tstack.  Heap-cons the vector, but make  */
+/* sure that there's an empty tsp frame to keep the compiler happy.  */
+0:
+        __(movc16(imm0,make_header(1,subtag_u32_vector)))
+        __(mov imm1,#0)
+        __(stmdb sp!,{imm0,imm1})
+        __(b _SPmisc_alloc)
 
 
@@ -1263,5 +1245,5 @@
 dnl   __(srawi imm2,imm2,31)
 dnl   __(or imm2,imm2,imm1)
-dnl   __(addi imm1,imm1,fixnumone)
+dnl   __(addi imm1,imm1,#fixnumone)
 dnl   __(cmpr(cr0,imm1,imm0))
 dnl   __(subf imm2,nargs,imm2)
@@ -1517,5 +1499,5 @@
  
 _spentry(ksignalerr)
-        __(ref_nrs_symbol(fname,errdisp))
+        __(ref_nrs_symbol(fname,errdisp,imm0))
         __(jump_fname)
 
@@ -1658,192 +1640,167 @@
 dnl  __(mtctr loc_pc)
 dnl  __(bctr)
-dnl         
-dnl                 
-dnl /* Everything up to the last arg has been vpushed, nargs is set to  */
-dnl /* the (boxed) count of things already pushed.  */
-dnl /* On exit, arg_x, arg_y, arg_z, and nargs are set as per a normal  */
-dnl /* function call (this may require vpopping a few things.)  */
-dnl /* ppc2-invoke-fn assumes that temp1 is preserved here.  */
-dnl _spentry(spreadargz)
-dnl   __(extract_lisptag(imm1,arg_z))
-dnl   __(cmpri(cr1,imm1,tag_list))
-dnl  __(cmpri(cr0,arg_z,nil_value))
-dnl  __(mov imm0,#0)
-dnl  __(mov arg_y,arg_z)  /*  save in case of error  */
-dnl  __(beq cr0,2f)
-dnl 1:
-dnl  __(bne- cr1,3f)
-dnl  __(_car(arg_x,arg_z))
-dnl  __(_cdr(arg_z,arg_z))
-dnl  __(cmpri(cr0,arg_z,nil_value))
-dnl   __(extract_lisptag(imm1,arg_z))
-dnl   __(cmpri(cr1,imm1,tag_list))
-dnl  __(vpush1(arg_x))
-dnl  __(addi imm0,imm0,fixnum_one)
-dnl  __(bne cr0,1b)
-dnl 2:
-dnl  __(add. nargs,nargs,imm0)
-dnl  __(cmpri(cr2,nargs,2<<fixnumshift))
-dnl  __(beqlr- cr0)
-dnl  __(vpop(arg_z))
-dnl  __(bltlr cr2)
-dnl  __(vpop(arg_y))
-dnl  __(beqlr cr2)
-dnl  __(vpop(arg_x))
-dnl  __(bx lr)
-dnl         /*  Discard whatever's been vpushed already, complain.  */
-dnl 3: 
-dnl  __(add vsp,vsp,imm0)
-dnl  __(mov arg_z,arg_y)  /* recover original arg_z  */
-dnl  __(mov arg_y,#XNOSPREAD)
-dnl  __(set_nargs(2))
-dnl  __(b _SPksignalerr)
-dnl         
-dnl /* Tail-recursively funcall temp0.  */
-dnl /* Pretty much the same as the tcallsym* cases above.  */
-dnl _spentry(tfuncallgen)
-dnl  __(cmpri(cr0,nargs,nargregs<<fixnumshift))
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(mtlr loc_pc)
-dnl  __(ble cr0,2f)
-dnl  __(ldr imm0,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  /* can use nfn (= temp2) as a temporary  */
-dnl  __(subi imm1,nargs,nargregs<<fixnumshift)
-dnl  __(add imm1,imm1,vsp)
-dnl 1:
-dnl  __(ldru(temp2,-node_size(imm1)))
-dnl  __(cmpr(cr0,imm1,vsp))
-dnl  __(push(temp2,imm0))
-dnl  __(bne cr0,1b)
-dnl  __(mov vsp,imm0)
-dnl  __(do_funcall())
-dnl 2:
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  __(do_funcall())
-dnl 
-dnl 
-dnl /* Some args were vpushed.  Slide them down to the base of  */
-dnl /* the current frame, then do funcall.  */
-dnl _spentry(tfuncallslide)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr imm0,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  /* can use nfn (= temp2) as a temporary  */
-dnl  __(subi imm1,nargs,nargregs<<fixnumshift)
-dnl  __(add imm1,imm1,vsp)
-dnl  __(mtlr loc_pc)
-dnl 1:
-dnl  __(ldru(temp2,-node_size(imm1)))
-dnl  __(cmpr(cr0,imm1,vsp))
-dnl  __(push(temp2,imm0))
-dnl  __(bne cr0,1b)
-dnl  __(mov vsp,imm0)
-dnl  __(do_funcall())
-dnl 
-dnl /* No args were vpushed; recover saved context & do funcall  */
-dnl _spentry(tfuncallvsp)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp])
-dnl  __(mtlr loc_pc)
-dnl  __(discard_lisp_frame())
-dnl  __(do_funcall())
-dnl         
-dnl /* Tail-recursively call the (known symbol) in fname.  */
-dnl /* In the general case, we don't know if any args were  */
-dnl /* vpushed or not.  If so, we have to "slide" them down  */
-dnl /* to the base of the frame.  If not, we can just restore  */
-dnl /* vsp, lr, fn from the saved lisp frame on the control stack.  */
-dnl _spentry(tcallsymgen)
-dnl  __(cmpri(cr0,nargs,nargregs<<fixnumshift))
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(mtlr loc_pc)
-dnl  __(ble cr0,2f)
-dnl 
-dnl  __(ldr imm0,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  /* can use nfn (= temp2) as a temporary  */
-dnl  __(subi imm1,nargs,nargregs<<fixnumshift)
-dnl  __(add imm1,imm1,vsp)
-dnl 1:
-dnl  __(ldru(temp2,-node_size(imm1)))
-dnl  __(cmpr(cr0,imm1,vsp))
-dnl  __(push(temp2,imm0))
-dnl  __(bne cr0,1b)
-dnl  __(mov vsp,imm0)
-dnl  __(jump_fname)
-dnl  
-dnl 2:  
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  __(jump_fname)
-dnl  
-dnl  
-dnl /* Some args were vpushed.  Slide them down to the base of  */
-dnl /* the current frame, then do funcall.  */
-dnl _spentry(tcallsymslide)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr imm0,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  __(mtlr loc_pc)
-dnl  /* can use nfn (= temp2) as a temporary  */
-dnl  __(subi imm1,nargs,nargregs<<fixnumshift)
-dnl  __(add imm1,imm1,vsp)
-dnl 1:
-dnl  __(ldru(temp2,-node_size(imm1)))
-dnl  __(cmpr(cr0,imm1,vsp))
-dnl  __(push(temp2,imm0))
-dnl  __(bne cr0,1b)
-dnl  __(mov vsp,imm0)
-dnl  __(jump_fname)
-dnl 
-dnl /* No args were vpushed; recover saved context & call symbol  */
-dnl _spentry(tcallsymvsp)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  __(mtlr loc_pc)
-dnl  __(jump_fname)
-dnl  
-dnl /* Tail-recursively call the function in nfn.  */
-dnl /* Pretty much the same as the tcallsym* cases above.  */
-dnl _spentry(tcallnfngen)
-dnl  __(cmpri(cr0,nargs,nargregs<<fixnumshift))
-dnl  __(ble cr0,_SPtcallnfnvsp)
-dnl         __(b _SPtcallnfnslide)
-dnl 
-dnl /* Some args were vpushed.  Slide them down to the base of  */
-dnl /* the current frame, then do funcall.  */
-dnl _spentry(tcallnfnslide)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr imm0,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  __(mtlr loc_pc)
-dnl  /* Since we have a known function, can use fname as a temporary.  */
-dnl  __(subi imm1,nargs,nargregs<<fixnumshift)
-dnl  __(add imm1,imm1,vsp)
-dnl 1:
-dnl  __(ldru(fname,-node_size(imm1)))
-dnl  __(cmpr(cr0,imm1,vsp))
-dnl  __(push(fname,imm0))
-dnl  __(bne cr0,1b)
-dnl  __(mov vsp,imm0)
-dnl         __(jump_nfn())
-dnl         
-dnl _spentry(tcallnfnvsp)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  __(mtlr loc_pc)
-dnl         __(jump_nfn())
+
+
+/* Everything up to the last arg has been vpushed, nargs is set to  */
+/* the (boxed) count of things already pushed.  */
+/* On exit, arg_x, arg_y, arg_z, and nargs are set as per a normal  */
+/* function call (this may require vpopping a few things.)  */
+/* ppc2-invoke-fn assumes that temp1 is preserved here.  */
+_spentry(spreadargz)
+        __(extract_lisptag(imm1,arg_z))
+        __(cmp arg_z,#nil_value) 
+        __(mov imm0,#0)
+        __(mov arg_y,arg_z)  /*  save in case of error  */
+        __(beq 2f)
+1:
+        __(cmp imm1,#tag_list)
+        __(bne 3f)
+        __(_car(arg_x,arg_z))
+        __(_cdr(arg_z,arg_z))
+        __(cmp arg_z,#nil_value)
+        __(extract_lisptag(imm1,arg_z))
+        __(vpush1(arg_x))
+        __(add imm0,imm0,#fixnum_one)
+        __(bne 1b)
+2:
+        __(adds  nargs,nargs,imm0)
+        __(bxeq lr)
+        __(vpop_argregs_nz)
+        __(bx lr)
+	
+        /*  Discard whatever's been vpushed already, complain.  */
+3: 
+        __(add vsp,vsp,imm0)
+        __(mov arg_z,arg_y)  /* recover original arg_z  */
+        __(mov arg_y,#XNOSPREAD)
+        __(set_nargs(2))
+        __(b _SPksignalerr)
+
+/* Tail-recursively funcall temp0.  */
+/* Pretty much the same as the tcallsym* cases above.  */
+_spentry(tfuncallgen)
+        __(cmp nargs,#nargregs<<fixnumshift)
+        __(ldr lr,[sp,#lisp_frame.savelr])
+        __(ldr fn,[sp,#lisp_frame.savefn])
+        __(ble 2f)
+        __(ldr imm0,[sp,#lisp_frame.savevsp])
+        __(discard_lisp_frame())
+        /* can use temp0 as a temporary  */
+        __(sub imm1,nargs,#nargregs<<fixnumshift)
+        __(add imm1,imm1,vsp)
+1:
+        __(ldr temp0,[imm1,#-node_size]!)
+        __(cmp imm1,vsp)
+        __(push1(temp2,imm0))
+        __(bne 1b)
+        __(mov vsp,imm0)
+        __(funcall_nfn())
+2:
+        __(ldr vsp,[sp,#lisp_frame.savevsp])
+        __(discard_lisp_frame())
+        __(funcall_nfn())
+
+
+/* Some args were vpushed.  Slide them down to the base of  */
+/* the current frame, then do funcall.  */
+_spentry(tfuncallslide)
+        __(restore_lisp_frame(imm0))
+        /* can use temp0 as a temporary  */
+        __(sub imm1,nargs,#nargregs<<fixnumshift)
+        __(add imm1,imm1,vsp)
+1:
+        __(ldr temp0,[imm1,#-node_size]!)
+        __(cmp imm1,vsp)
+        __(push1(temp0,imm0))
+        __(bne 1b)
+        __(mov vsp,imm0)
+        __(funcall_nfn())
+
+/* No args were vpushed; recover saved context & do funcall  */
+_spentry(tfuncallvsp)
+        __(restore_lisp_frame(imm0))
+        __(funcall_nfn())
+
+/* Tail-recursively call the (known symbol) in fname.  */
+/* In the general case, we don't know if any args were  */
+/* vpushed or not.  If so, we have to "slide" them down  */
+/* to the base of the frame.  If not, we can just restore  */
+/* vsp, lr, fn from the saved lisp frame on the control stack.  */
+_spentry(tcallsymgen)
+        __(cmp nargs,#nargregs<<fixnumshift)
+        __(ldr lr,[sp,#lisp_frame.savelr])
+        __(ldr fn,[sp,#lisp_frame.savefn])
+        __(ble 2f)
+
+        __(ldr imm0,[sp,#lisp_frame.savevsp])
+        __(discard_lisp_frame())
+        /* can use nfn (= temp2) as a temporary  */
+        __(sub imm1,nargs,#nargregs<<fixnumshift)
+        __(add imm1,imm1,vsp)
+1:
+        __(ldr temp2,[imm1,#-node_size]!)
+        __(cmp imm1,vsp)
+        __(push1(temp2,imm0))
+        __(bne 1b)
+        __(mov vsp,imm0)
+        __(jump_fname)
+  
+2:  
+        __(ldr vsp,[sp,#lisp_frame.savevsp])
+        __(discard_lisp_frame())
+        __(jump_fname)
+
+
+/* Some args were vpushed.  Slide them down to the base of  */
+/* the current frame, then do funcall.  */
+_spentry(tcallsymslide)
+        __(ldr lr,[sp,#lisp_frame.savelr])
+        __(ldr fn,[sp,#lisp_frame.savefn])
+        __(ldr imm0,[sp,#lisp_frame.savevsp])
+        __(discard_lisp_frame())
+        /* can use nfn (= temp2) as a temporary  */
+        __(sub imm1,nargs,#nargregs<<fixnumshift)
+        __(add imm1,imm1,vsp)
+1:
+        __(ldr temp2,[imm1,#-node_size]!)
+        __(cmp imm1,vsp)
+        __(push1(temp2,imm0))
+        __(bne 1b)
+        __(mov vsp,imm0)
+        __(jump_fname)
+
+/* No args were vpushed; recover saved context & call symbol  */
+_spentry(tcallsymvsp)
+        __(restore_lisp_frame(imm0))
+        __(jump_fname)
+
+/* Tail-recursively call the function in nfn.  */
+/* Pretty much the same as the tcallsym* cases above.  */
+_spentry(tcallnfngen)
+        __(cmp nargs,#nargregs<<fixnumshift)
+        __(ble _SPtcallnfnvsp)
+        __(b _SPtcallnfnslide)
+ 
+/* Some args were vpushed.  Slide them down to the base of  */
+/* the current frame, then do funcall.  */
+_spentry(tcallnfnslide)
+        __(ldr lr,[sp,#lisp_frame.savelr])
+        __(ldr fn,[sp,#lisp_frame.savefn])
+        __(ldr imm0,[sp,#lisp_frame.savevsp])
+        __(discard_lisp_frame())
+        /* Since we have a known function, can use fname as a temporary.  */
+        __(sub imm1,nargs,#nargregs<<fixnumshift)
+        __(add imm1,imm1,vsp)
+1:
+        __(ldr fname,[imm1,#-node_size]!)
+        __(cmp imm1,vsp)
+        __(push1(fname,imm0))
+        __(bne 1b)
+        __(mov vsp,imm0)
+        __(jump_nfn())
+
+_spentry(tcallnfnvsp)
+        __(restore_lisp_frame(imm0))
+        __(jump_nfn())
 
 /* Reference index arg_z of a misc-tagged object (arg_y).  */
@@ -1877,76 +1834,5 @@
         __(bgt _SPsubtag_misc_ref)
         __(jump_builtin(_builtin_aref1,2))
-dnl          
-dnl  
-dnl /* Make a cons cell on the vstack.  Always push 3 words, 'cause we're   */
-dnl /* not sure how the vstack will be aligned.  */
-dnl _spentry(stkconsyz)
-dnl  __(mov imm0,#nil_value)
-dnl  __(vpush1(imm0))
-dnl  __(vpush1(imm0))
-dnl  __(vpush1(imm0))
-dnl  __(andi. imm0,vsp,1<<word_shift) /* (oddp vsp ?)  */
-dnl  __(beq cr0,1f)
-dnl  __(str(arg_y,node_size*2(vsp))) /* car  */
-dnl  __(str(arg_z,node_size(vsp))) /* cdr  */
-dnl  __(la arg_z,fulltag_cons+node_size(vsp))
-dnl  __(bx lr)
-dnl 1:
-dnl  __(str(arg_y,node_size(vsp))) /* car, again  */
-dnl  __(str(arg_z,0(vsp)))
-dnl  __(la arg_z,fulltag_cons(vsp))
-dnl  __(bx lr)
-dnl 
-dnl /* Make a stack-consed value cell.  Much like the case of */
-dnl /* stack-allocating a cons cell.  Imm0 points to the closed-over value */
-dnl /* (already vpushed).  Replace that locative with the vcell.  */
-dnl _spentry(stkvcell0)
-dnl  __(sub imm1,imm0,vsp) /* imm1 = delta from vsp to value cell loc  */
-dnl  __(mov arg_z,#nil_value)
-dnl  __(vpush1(arg_z))
-dnl  __(vpush1(arg_z))
-dnl  __(vpush1(arg_z))
-dnl  __(addi imm1,imm1,node_size*3)
-dnl  __(add imm0,vsp,imm1) /* in case stack overflowed  */
-dnl  __(andi. imm1,vsp,1<<word_shift) /* (oddp vsp) ?  */
-dnl  __(mov imm1,#value_cell_header)
-dnl  __(ldr arg_z,[imm0,#0])
-dnl  __(beq cr0,1f)
-dnl  __(str(arg_z,node_size*2(vsp)))
-dnl  __(str(imm1,node_size(vsp)))
-dnl  __(la arg_z,fulltag_misc+node_size(vsp))
-dnl  __(str(arg_z,0(imm0)))
-dnl  __(bx lr)
-dnl 1:
-dnl  __(str(arg_z,node_size(vsp)))
-dnl  __(str(imm1,0(vsp)))
-dnl  __(la arg_z,fulltag_misc(vsp))
-dnl  __(str(arg_z,0(imm0)))
-dnl  __(bx lr)
-dnl 
-dnl         
-dnl _spentry(stkvcellvsp)      
-dnl  __(mov arg_z,#nil_value)
-dnl  __(vpush1(arg_z))
-dnl  __(vpush1(arg_z))
-dnl  __(vpush1(arg_z))
-dnl  __(mov imm1,#node_size*3)
-dnl  __(add imm0,vsp,imm1) /* in case stack overflowed  */
-dnl  __(andi. imm1,vsp,1<<word_shift) /* (oddp vsp) ?  */
-dnl  __(mov imm1,#value_cell_header)
-dnl  __(ldr arg_z,[imm0,#0])
-dnl  __(beq cr0,1f)
-dnl  __(str(arg_z,node_size*2(vsp)))
-dnl  __(str(imm1,node_size(vsp)))
-dnl  __(la arg_z,fulltag_misc+node_size(vsp))
-dnl  __(str(arg_z,0(imm0)))
-dnl  __(bx lr)
-dnl 1:
-dnl  __(str(arg_z,node_size(vsp)))
-dnl  __(str(imm1,0(vsp)))
-dnl  __(la arg_z,fulltag_misc(vsp))
-dnl  __(str(arg_z,0(imm0)))
-dnl  __(bx lr)
-dnl 
+
 dnl /* Make a "raw" area on the temp stack, stack-cons a macptr to point to it,  */
 dnl /* and return the macptr.  Size (in bytes, boxed) is in arg_z on entry; macptr */
@@ -1998,46 +1884,46 @@
 dnl  __(mov fname,#nrs.new_gcable_ptr)
 dnl  __(jump_fname())
-dnl 
-dnl /* Make a list of length arg_y (boxed), initial-element arg_z (boxed) on  */
-dnl /* the tstack.  Return the list in arg_z.  */
-dnl _spentry(makestacklist)
-dnl  __(add imm0,arg_y,arg_y)
-dnl  __(cmplri(cr1,imm0,((tstack_alloc_limit+1)-cons.size)))
-dnl  __(addi imm0,imm0,tsp_frame.fixed_overhead)
-dnl  __(bge cr1,3f)
-dnl  __(TSP_Alloc_Var_Boxed(imm0,imm1))
-dnl  __(mov imm1,arg_y)
-dnl  __(cmpri(cr1,imm1,0))
-dnl  __(mov arg_y,arg_z)
-dnl  __(mov arg_z,#nil_value)
-dnl  __(ldr imm2,[tsp,#tsp_frame.backlink])
-dnl  __(la imm2,-tsp_frame.fixed_overhead+fulltag_cons(imm2))
-dnl  __(b 2f)
-dnl 1:
-dnl  __(subi imm1,imm1,fixnum1)
-dnl  __(cmpri(cr1,imm1,0))
-dnl  __(_rplacd(imm2,arg_z))
-dnl  __(_rplaca(imm2,arg_y))
-dnl  __(mov arg_z,imm2)
-dnl  __(subi imm2,imm2,cons.size)
-dnl 2:
-dnl  __(bne cr1,1b)
-dnl  __(bx lr)
-dnl 
-dnl 3:
-dnl  __(cmpri(cr1,arg_y,0))
-dnl  __(TSP_Alloc_Fixed_Boxed(0))  /* make the compiler happy  */
-dnl  __(mov imm1,arg_y) /* count  */
-dnl  __(mov arg_y,arg_z) /* initial value  */
-dnl  __(mov arg_z,#nil_value) /* result  */
-dnl  __(b 5f)
-dnl 4:
-dnl  __(subi imm1,imm1,fixnum1)
-dnl  __(cmpri(cr1,imm1,0))
-dnl  __(Cons(arg_z,arg_y,arg_z))
-dnl 5:
-dnl  __(bne cr1,4b)
-dnl  __(bx lr)
-dnl 
+
+/* Make a list of length arg_y (boxed), initial-element arg_z (boxed) on  */
+/* the tstack.  Return the list in arg_z.  */
+_spentry(makestacklist)
+        __(add imm0,arg_y,arg_y)
+        __(mov imm1,imm0,lsl #num_subtag_bits-fixnumshift)
+        __(add imm1,imm1,#4<<num_subtag_bits)
+        __(orr imm1,imm1,#subtag_u32_vector)
+        __(add imm0,imm0,#dnode_size)
+        __(cmp imm0,#stack_alloc_limit)
+        __(bge 4f)
+        __(stack_allocate_zeroed_word_vector(imm1,imm0))
+        __(mov imm0,#subtag_simple_vector)
+        __(strb imm0,[sp,#0])
+        __(add imm2,sp,#dnode_size+fulltag_cons)
+        __(movs imm1,arg_y)
+        __(mov arg_y,arg_z)
+        __(mov arg_z,#nil_value)
+        __(b 3f)
+2:
+        __(_rplacd(imm2,arg_z))
+        __(_rplaca(imm2,arg_y))
+        __(mov arg_z,imm2)
+        __(add imm2,imm2,#cons.size)
+        __(subs imm1,imm1,#fixnumone)
+3:
+        __(bne 2b)
+        __(bx lr)
+4:
+        __(movc16(imm0,make_header(1,subtag_u32_vector)))
+        __(str imm0,[sp,#-8]!)
+        __(movs imm1,arg_y) /* count  */
+        __(mov arg_y,arg_z) /* initial value  */
+        __(mov arg_z,#nil_value) /* result  */
+        __(b 6f)
+5:
+        __(Cons(arg_z,arg_y,arg_z))
+        __(subs imm1,imm1,#fixnumone)
+6:
+        __(bne 5b)
+        __(bx lr)
+
 dnl /* subtype (boxed) vpushed before initial values. (Had better be a  */
 dnl /* node header subtag.) Nargs set to count of things vpushed.  */
@@ -2075,6 +1961,4 @@
 /* the object's header (fulltag = fulltag_immheader or fulltag_nodeheader.)  */
 
-unsigned_byte_24_mask = 0xe0000003 /* bits that should be clear in a boxed */
-                                   /* (UNSIGNED-BYTE 24) */
 _spentry(misc_alloc)
         __(tst arg_y,#unsigned_byte_24_mask)
@@ -2422,5 +2306,5 @@
         __(add imm0,imm0,#misc_data_offset-4) /* bias, less 1 element  */
         __(ldr imm0,[arg_z,imm0])
-        __(cmp imm0,0)
+        __(cmp imm0,#0)
         __(movge imm0,#1)
         __(movlt imm0,#-1)
@@ -2428,25 +2312,27 @@
 
 
-dnl /* like misc_set, only pass the (boxed) subtag in temp0  */
-dnl _spentry(subtag_misc_set)
-dnl  __(trap_unless_fulltag_equal(arg_x,fulltag_misc,imm0))
-dnl  __(trap_unless_lisptag_equal(arg_y,tag_fixnum,imm0))
-dnl  __(vector_length(imm0,arg_x,imm1))
-dnl  __(trlge(arg_y,imm0))
-dnl  __(unbox_fixnum(imm1,temp0))
-dnl     __(b C(misc_set_common))
-
-
-dnl 
-dnl /* misc_set (vector index newval).  Pretty damned similar to  */
-dnl /* misc_ref, as one might imagine.  */
-dnl 
-dnl _spentry(misc_set)
-dnl  __(trap_unless_fulltag_equal(arg_x,fulltag_misc,imm0))
-dnl  __(trap_unless_lisptag_equal(arg_y,tag_fixnum,imm0))
-dnl  __(vector_length(imm0,arg_x,imm1))
-dnl  __(trlge(arg_y,imm0))
-dnl  __(extract_lowbyte(imm1,imm1))
-dnl         __(b C(misc_set_common))
+/* like misc_set, only pass the (boxed) subtag in temp0  */
+_spentry(subtag_misc_set)
+        __(trap_unless_fulltag_equal(arg_x,fulltag_misc,imm0))
+        __(trap_unless_fixnum(arg_y))
+        __(vector_length(imm0,arg_x,imm1))
+        __(cmp arg_y,imm0)
+        __(uuo_error_vector_bounds(hs,arg_y,arg_x))
+        __(unbox_fixnum(imm1,temp0))
+        __(b C(misc_set_common))
+
+
+
+/* misc_set (vector index newval).  Pretty damned similar to  */
+/* misc_ref, as one might imagine.  */
+
+_spentry(misc_set)
+        __(trap_unless_fulltag_equal(arg_x,fulltag_misc,imm0))
+        __(trap_unless_fixnum(arg_y))
+        __(vector_length(imm0,arg_x,imm1))
+        __(cmp arg_y,imm0)
+        __(uuo_error_vector_bounds(hs,arg_y,arg_x))
+        __(extract_lowbyte(imm1,imm1))
+        __(b C(misc_set_common))
 dnl         
 dnl /* "spread" the lexpr in arg_z.  */
@@ -2480,5 +2366,5 @@
 dnl 8:
 dnl  __(cmpri(cr3,imm0,4<<fixnumshift))
-dnl  __(subi imm0,imm0,fixnumone)
+dnl  __(subi imm0,imm0,#fixnumone)
 dnl  __(ldru(arg_z,-node_size(imm1)))
 dnl  __(vpush1(arg_z))
@@ -2597,97 +2483,58 @@
 dnl  __(bx lr)
 dnl         
-dnl         
-dnl /* Like misc_alloc (a LOT like it, since it does most of the work), but takes  */
-dnl /* an initial-value arg in arg_z, element_count in arg_x, subtag in arg_y.  */
-dnl /* Calls out to %init-misc, which does the rest of the work.  */
-dnl 
-dnl _spentry(misc_alloc_init)
-dnl  __(mflr loc_pc)
-dnl  __(build_lisp_frame(fn,loc_pc,vsp))
-dnl  __(mov fn,#0)
-dnl  __(mov temp0,arg_z)  /* initval  */
-dnl  __(mov arg_z,arg_y)  /* subtag  */
-dnl  __(mov arg_y,arg_x)  /* element-count  */
-dnl  __(bl _SPmisc_alloc)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(mtlr loc_pc)
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp]) 
-dnl  __(discard_lisp_frame())
-dnl  __(mov fname,#nrs.init_misc)
-dnl  __(set_nargs(2))
-dnl  __(mov arg_y,temp0)
-dnl  __(jump_fname())
-dnl 
-dnl /* As in stack_misc_alloc above, only with a non-default initial-value.  */
-dnl 
-dnl _spentry(stack_misc_alloc_init)
-dnl  __(mflr loc_pc)
-dnl  __(build_lisp_frame(fn,loc_pc,vsp))
-dnl  __(mov fn,#0)
-dnl  __(mov temp0,arg_z) /* initval  */
-dnl  __(mov arg_z,arg_y) /* subtag  */
-dnl  __(mov arg_y,arg_x) /* element-count  */
-dnl  __(bl _SPstack_misc_alloc)
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(mtlr loc_pc)
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp])
-dnl  __(discard_lisp_frame())
-dnl  __(mov fname,#nrs.init_misc)
-dnl  __(set_nargs(2))
-dnl  __(mov arg_y,temp0)
-dnl  __(jump_fname())
-dnl 
-dnl  
-dnl _spentry(callbuiltin)
-dnl  __(ref_nrs_value(fname,builtin_functions))
-dnl  __(la imm0,misc_data_offset(imm0))
-dnl  __(ldrx(fname,fname,imm0))
-dnl  __(jump_fname())
-dnl 
-dnl /* the value of the nilreg-relative symbol %builtin-functions% should be  */
-dnl /* a vector of symbols.  Call the symbol indexed by imm0 (boxed) and  */
-dnl /* return a single value.  */
-dnl 
-dnl _spentry(callbuiltin0)
-dnl  __(set_nargs(0))
-dnl  __(ref_nrs_value(fname,builtin_functions))
-dnl  __(la imm0,misc_data_offset(imm0))
-dnl  __(ldrx(fname,fname,imm0))
-dnl  __(jump_fname())
-dnl 
-dnl _spentry(callbuiltin1)
-dnl  __(ref_nrs_value(fname,builtin_functions))
-dnl  __(set_nargs(1))
-dnl  __(la imm0,misc_data_offset(imm0))
-dnl  __(ldrx(fname,fname,imm0))
-dnl  __(jump_fname())
-dnl 
-dnl _spentry(callbuiltin2)
-dnl  __(set_nargs(2))
-dnl  __(ref_nrs_value(fname,builtin_functions))
-dnl  __(la imm0,misc_data_offset(imm0))
-dnl  __(ldrx(fname,fname,imm0))
-dnl  __(jump_fname())
-dnl 
-dnl 
-dnl _spentry(callbuiltin3)
-dnl  __(set_nargs(3))
-dnl  __(ref_nrs_value(fname,builtin_functions))
-dnl  __(la imm0,misc_data_offset(imm0))
-dnl  __(ldrx(fname,fname,imm0))
-dnl  __(jump_fname())
-dnl  
-dnl 
-dnl _spentry(popj)
-dnl  .globl C(popj)
-dnl C(popj):
-dnl  __(ldr loc_pc,[sp,#lisp_frame.savelr])
-dnl  __(ldr vsp,[sp,#lisp_frame.savevsp])
-dnl  __(mtlr loc_pc)
-dnl  __(ldr fn,[sp,#lisp_frame.savefn])
-dnl  __(discard_lisp_frame())
-dnl  __(bx lr)
+
+/* Like misc_alloc (a LOT like it, since it does most of the work), but takes  */
+/* an initial-value arg in arg_z, element_count in arg_x, subtag in arg_y.  */
+/* Calls out to %init-misc, which does the rest of the work.  */
+
+_spentry(misc_alloc_init)
+        __(build_lisp_frame(imm0))
+        __(mov fn,#0)
+        __(mov temp2,arg_z)  /* initval  */
+        __(mov arg_z,arg_y)  /* subtag  */
+        __(mov arg_y,arg_x)  /* element-count  */
+        __(bl _SPmisc_alloc)
+        __(restore_lisp_frame(imm0))
+        __(ref_nrs_symbol(fname,init_misc,imm0))
+        __(set_nargs(2))
+        __(mov arg_y,temp2)
+        __(jump_fname())
+
+/* As in stack_misc_alloc above, only with a non-default initial-value.  */
+/* The funny part here is that we build a lisp frame, then push a vector
+/* on top of it.  Shuffle things around, carefully. */        
+                
+ 
+_spentry(stack_misc_alloc_init)
+        __(build_lisp_frame(imm0))
+        __(mov arg_x,sp)
+        __(mov fn,#0)
+        __(mov temp2,arg_z) /* initval  */
+        __(mov arg_z,arg_y) /* subtag  */
+        __(mov arg_y,arg_x) /* element-count  */
+        __(bl _SPstack_misc_alloc)
+        __(mov imm0,#0)
+        __(ldr lr,[arg_x,#lisp_frame.savelr])
+        __(ldr fn,[arg_x,#lisp_frame.savefn])
+        __(ldr vsp,[arg_x,#lisp_frame.savevsp])
+        __(ldr imm1,[sp])
+        __(add imm2,imm1,#lisp_frame.size)
+        __(str imm2,[sp])
+        __(str imm0,[arg_x,#lisp_frame.savelr])
+        __(str imm0,[arg_x,#lisp_frame.savefn])
+        __(str imm0,[arg_x,#lisp_frame.savevsp])
+        __(str imm0,[arg_x,#lisp_frame.marker])
+        __(str imm1,[sp,#lisp_frame.size]!)
+        __(add arg_z,arg_z,#lisp_frame.size)
+        __(ref_nrs_symbol(fname,init_misc,imm0))
+        __(set_nargs(2))
+        __(mov arg_y,temp2)
+        __(jump_fname())
+ 
+_spentry(popj)
+        .globl C(popj)
+C(popj):
+        __(return_lisp_frame(imm0))
+
 dnl 
 dnl _spentry(restorefullcontext)
@@ -2754,31 +2601,26 @@
 dnl  __(mov fn,#0)
 dnl  __(bx lr)
-dnl 
-dnl         
-dnl         
-dnl 
-dnl _spentry(builtin_div)
-dnl  __(jump_builtin(_builtin_div,2))
-dnl 
-dnl 
-dnl 
-dnl _spentry(builtin_eql)
-dnl         __(cmpr(cr1,arg_y,arg_z))
-dnl         __(extract_fulltag(imm2,arg_y))
-dnl         __(extract_fulltag(imm3,arg_z))
-dnl         __(beq cr1,1f)
-dnl         __(cmpri(cr1,imm2,fulltag_misc))
-dnl         __(cmpri(cr0,imm3,fulltag_misc))
-dnl         __(bne cr1,2f)
-dnl         __(extract_subtag(imm0,arg_y))
-dnl         __(bne cr0,2f)
-dnl         __(extract_subtag(imm1,arg_z))
-dnl         __(cmpr(cr0,imm0,imm1))
-dnl         __(bne cr0,2f)
-dnl  __(jump_builtin(_builtin_eql,2))
-dnl 1: __(mov arg_z,#t_value)
-dnl  __(bx lr)
-dnl 2: __(mov arg_z,#nil_value)
-dnl  __(bx lr)
+
+
+
+
+_spentry(builtin_div)
+        __(jump_builtin(_builtin_div,2))
+
+_spentry(builtin_eql)
+        __(cmp arg_y,arg_z)
+        __(beq 1f)
+        __(extract_fulltag(imm0,arg_y))
+        __(extract_fulltag(imm1,arg_z))
+        __(cmp imm0,imm1)
+        __(bne 2f)
+        __(cmp imm0,#fulltag_misc)
+        __(bne 2f)
+        __(jump_builtin(_builtin_eql,2))
+1:      __(mov arg_z,#nil_value)
+        __(add arg_z,arg_z,#t_offset)
+        __(bx lr)
+2:      __(mov arg_z,#nil_value)
+        __(bx lr)
 dnl         
 dnl _spentry(builtin_length)
@@ -2907,5 +2749,5 @@
         /* Shift right */
         __(unbox_fixnum(imm2,arg_z))
-        __(rsb imm2,imm2,0)
+        __(rsb imm2,imm2,#0)
         __(cmp imm2,#32)
         __(movge imm2,#31)
