Index: /branches/arm/lisp-kernel/arm-constants.h
===================================================================
--- /branches/arm/lisp-kernel/arm-constants.h	(revision 13670)
+++ /branches/arm/lisp-kernel/arm-constants.h	(revision 13671)
@@ -18,17 +18,17 @@
 #include "constants.h"
 
-#define arg_z 0
-#define arg_y 1
-#define arg_x 2
-#define temp0 3
-#define temp1 4
-#define temp2 5
-#define fn    6
-#define rcontext 7
+#define fn 0
+#define vsp 1
+#define arg_z 2
+#define arg_y 3
+#define arg_x 4
+#define temp0 5
+#define temp1 6
+#define temp2 7
 #define imm0 8
 #define imm1 9
 #define imm2 10
-#define allocptr 11
-#define vsp 12
+#define rcontext 11
+#define allocptr 12
 #define sp 13
 #define lr 14
Index: /branches/arm/lisp-kernel/arm-constants.s
===================================================================
--- /branches/arm/lisp-kernel/arm-constants.s	(revision 13670)
+++ /branches/arm/lisp-kernel/arm-constants.s	(revision 13671)
@@ -43,21 +43,28 @@
 
 /* registers.  These assignments may not be viable. */
-define(`arg_z',`r0')
-define(`arg_y',`r1')
-define(`arg_x',`r2')
-define(`temp0',`r3')
-define(`temp1',`r4')
-define(`temp2',`r5')
-define(`fn',`r6')
-define(`rcontext',`r7')
-define(`imm0',`r8')
+/* 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(`allocptr',`r11')
-define(`vsp',`r12')
+define(`rcontext',`r11')
+define(`allocptr',`r12')
 define(`sp',`r13')
 define(`lr',`r14')
 define(`pc',`r15')
 
+nargregs = 3
+                
 define(`fname',`temp1')
 define(`nfn',`temp2')
@@ -70,5 +77,7 @@
 ne = 1
 cs = 2
+hs = cs        
 cc = 3
+lo = cc        
 mi = 4
 pl = 5
@@ -159,5 +168,5 @@
 /* set in the result. */
 
-t_offset = (8+(8-fulltag_nil)+fulltag_misc)
+t_offset = ((dnode_size-fulltag_nil)+fulltag_misc)
 t_value = nil_value+t_offset
 
@@ -298,9 +307,6 @@
 	 _node(link)		/* backpointer to previous catch frame */
 	 _node(mvflag)		/* 0 if single-valued catch, fixnum 1 otherwise */
-	 _node(csp)		/* pointer to lisp_frame on csp */
 	 _node(db_link)		/* head of special-binding chain */
-	 _field(regs,8*node_size)	/* save7-save0 */
 	 _node(xframe)		/* exception frame chain */
-	 _node(tsp_segment)	/* maybe someday; padding for now */
 	_endstructf
 
@@ -350,11 +356,34 @@
         _ends
 
+/* Indices in %builtin-functions% */
+_builtin_plus = 0	/* +-2 */
+_builtin_minus = 1	/* --2 */
+_builtin_times = 2	/* *-2 */
+_builtin_div = 3	/* /-2 */
+_builtin_eq = 4		/* =-2 */
+_builtin_ne = 5		/* /-2 */
+_builtin_gt = 6		/* >-2 */
+_builtin_ge = 7		/* >=-2 */
+_builtin_lt = 8		/* <-2 */
+_builtin_le = 9		/* <=-2 */
+_builtin_eql = 10	/* eql */
+_builtin_length = 11	/* length */
+_builtin_seqtype = 12	/* sequence-type */
+_builtin_assq = 13	/* assq */
+_builtin_memq = 14	/* memq */
+_builtin_logbitp = 15	/* logbitp */
+_builtin_logior = 16	/* logior-2 */
+_builtin_logand = 17	/* logand-2 */
+_builtin_ash = 18	/* ash */
+_builtin_negate = 19	/* %negate */
+_builtin_logxor = 20	/* logxor-2 */
+_builtin_aref1 = 21	/* %aref1 */
+_builtin_aset1 = 22	/* %aset1 */
 
 
 symbol_extra = symbol.size-fulltag_misc
 	
-	_struct(nrs,nil_value-fulltag_nil)
-	 _struct_pad(fulltag_nil)
-	 _field(nilptr,16-fulltag_nil)
+	_struct(nrs,0)
+	 _struct_pad(dnode_size-fulltag_nil)
 
 	 _struct_pad(fulltag_misc)
@@ -649,5 +678,60 @@
 define(`RESERVATION_DISCHARGE',0x2004)
 
-lisp_globals_limit = (0x3010+(LOWMEM_BIAS))
+lisp_globals_limit = fulltag_nil
+
+num_lisp_globals = 49		 /* MUST UPDATE THIS !!! */
+	
+	_struct(lisp_globals,lisp_globals_limit-(num_lisp_globals*node_size))
+	 _node(weakvll)                 /* all populations as of last GC */
+	 _node(initial_tcr)	        /* initial thread tcr */
+	 _node(image_name)	        /* --image-name argument */
+	 _node(BADfpscr_save_high)      /* high word of FP reg used to save FPSCR */
+	 _node(unwind_resume)           /* _Unwind_Resume */
+	 _node(batch_flag)	        /* -b */
+	 _node(host_platform)	        /* for runtime platform-specific stuff */
+	 _node(argv)			/* address of argv`0' */
+	 _node(ref_base)		        /* start of oldest pointer-bearing area */
+	 _node(tenured_area) 		/* the tenured_area */
+	 _node(oldest_ephemeral) 	/* dword address of oldest ephemeral object or 0 */
+	 _node(lisp_exit_hook)		/* install foreign exception_handling */
+	 _node(lisp_return_hook)	/* install lisp exception_handling */
+	 _node(double_float_one) 	/* high half of 1.0d0 */
+	 _node(short_float_zero) 	/* low half of 1.0d0 */
+	 _node(objc2_end_catch)         /* objc_end_catch() */
+	 _node(metering_info) 		/* address of lisp_metering global */
+	 _node(in_gc) 			/* non-zero when GC active */
+	 _node(lexpr_return1v) 		/* simpler when &lexpr called for single value. */
+	 _node(lexpr_return) 		/* magic &lexpr return code. */
+	 _node(all_areas) 		/* doubly-linked list of all memory areas */
+	 _node(kernel_path) 		/* real executable name */
+	 _node(objc2_begin_catch) 	/* objc_begin_catch */
+	 _node(stack_size) 		/* from command-line */
+	 _node(statically_linked)	/* non-zero if -static */
+	 _node(heap_end)                /* end of lisp heap */
+	 _node(heap_start)              /* start of lisp heap */
+	 _node(gcable_pointers)         /* linked-list of weak macptrs. */
+	 _node(gc_num)                  /* fixnum: GC call count. */
+	 _node(fwdnum)                  /* fixnum: GC "forwarder" call count. */
+	 _node(altivec_present)         /* non-zero when AltiVec available */
+	 _node(oldspace_dnode_count) 	/* dynamic dnodes older than g0 start */
+	 _node(refbits) 		/* EGC refbits */
+	 _node(gc_inhibit_count)
+	 _node(intflag) 		/* sigint pending */
+	 _node(BAD_block_tag_counter) 	/* counter for (immediate) block tag */
+	 _node(deleted_static_pairs) 		
+	 _node(exception_lock)
+	 _node(area_lock)
+	 _node(tcr_key) 		/* tsd key for per-thread tcr */
+	 _node(ret1val_addr) 		/* address of "dynamic" subprims magic values return addr */
+	 _node(subprims_base) 		/* address of dynamic subprims jump table */
+	 _node(saveR13)			/* probably don't really need this */
+	 _node(saveTOC)                 /* where the 68K emulator stores the  emulated regs */
+	 _node(objc_2_personality)      /* exception "personality routine" address for ObjC 2.0 */ 
+	 _node(kernel_imports) 		/* some things we need imported for us */
+	 _node(interrupt_signal)	/* signal used by PROCESS-INTERRUPT */
+	 _node(tcr_count) 		/* tcr_id for next tcr */
+	 _node(get_tcr) 		/* address of get_tcr() */
+	_ends
+                
         
 INTERRUPT_LEVEL_BINDING_INDEX = fixnumone
Index: /branches/arm/lisp-kernel/arm-macros.s
===================================================================
--- /branches/arm/lisp-kernel/arm-macros.s	(revision 13670)
+++ /branches/arm/lisp-kernel/arm-macros.s	(revision 13671)
@@ -14,6 +14,4 @@
 /*   http://opensource.franz.com/preamble.html */
 
-/* The assembler has to do the arithmetic here:	 the expression */
-/*   may not be evaluable by m4. */
 
 
@@ -26,14 +24,31 @@
 ')
 
+define(`make_header',`(($1<<num_subtag_bits)|($2&subtag_mask))')
+        
+/* Load a 16-bit constant into $1, 8 bits at a time. */
+define(`movc16',`
+        __(mov $1,#$2&0xff)
+        __(orr $1,$1,#$2&~0xff)
+        ')
+        
+define(`test_fixnum',`
+        __(tst $1,#fixnummask)
+        ')
+	
+define(`test_two_fixnums',`
+        __(orr $3,$1,$2)
+        __(test_fixnum($3))
+        ')
+        	
 define(`extract_fulltag',`
-        __(and $1,$1,#((1<<ntagbits)-1))
+        __(and $1,$2,#fulltagmask)
         ')
 
 define(`extract_lisptag',`
-        __(and $1,$1,#((1<<nlisptagbits)-1))
+        __(and $1,$2,#tagmask)
         ')
 
 define(`extract_lisptag_',`
-        __(ands $1,$1,#((1<<nlisptagbits)-1))
+        __(ands $1,$1,#tagmask)
         ')
 
@@ -53,10 +68,10 @@
 define(`extract_typecode',`
         __(extract_lisptag($1,$2))
-        __(cmp $1,#fulltag_misc)
+        __(cmp $1,#tag_misc)
         __(ldrbeq $1,[$2,#misc_subtag_offset])
         ')
 
 define(`box_fixnum',`
-        __(mov #1,$2, lsl #fixnumshift)
+        __(mov $1,$2, lsl #fixnumshift)
 	')
 
@@ -96,5 +111,5 @@
 	
 define(`set_nargs',`
-	__(lwi(nargs,($1)<<fixnumshift))
+	__(mov nargs,#($1)<<fixnumshift)
 	')
 	
@@ -105,5 +120,5 @@
 
 define(`vref32',`
-        __(ldr #1,[$2,#misc_data_offset+(($3)<<2)])
+        __(ldr $1,[$2,#misc_data_offset+(($3)<<2)])
 	')
         
@@ -126,8 +141,8 @@
 	/* "Length" is fixnum element count */
 define(`header_length',`
-        mov $1,#-1<<fixnumshift
-        and $1,$1,$2,lsr #num_subtag_bits-fixnumshift
-        ')
-')        
+        __(mov $1,#-1<<fixnumshift)
+        __(and $1,$1,$2,lsr #num_subtag_bits-fixnumshift)
+        ')
+
 
 
@@ -139,10 +154,12 @@
 	
 define(`ref_global',`
-	__(ldr($1,lisp_globals.$2(0)))
+        __(mov $1,#nil_value)
+	__(ldr $1,[$1,#lisp_globals.$2])
 ')
 
 
 define(`ref_nrs_value',`
-	__(ldr($1,((nrs.$2)+(symbol.vcell))(0)))
+        __(mov $1,#nil_value)
+	__(ldr $1,[$1,#((nrs.$2)+(symbol.vcell))])
 ')
 	
@@ -179,32 +196,31 @@
 define(`vpush_argregs',`
 	new_macro_labels()
-	__(cmplri(cr0,nargs,0))
-	__(cmplri(cr1,nargs,node_size*2))
-	__(beq cr0,macro_label(done))
-	__(blt cr1,macro_label(z))
-	__(beq cr1,macro_label(yz))
-	__(vpush(arg_x))
-macro_label(yz):
-	__(vpush(arg_y))
-macro_label(z):
-	__(vpush(arg_z))
+        __(cmp nargs,#0)
+        __(beq macro_label(done))
+        __(cmp nargs,#node_size*2)
+        __(strhi arg_x,[vsp,#-node_size]!)
+        __(strhs arg_y,[vsp,#-node_size]!)
+        __(str arg_z,[vsp,#-node_size]!)
 macro_label(done):
 ')
 
-define(`create_lisp_frame',`
-	__(stru(sp,-lisp_frame.size(sp)))
-')
-
-                
+
+/* $1 = sp copy for instruction restriction, $2 = value for lisp_frame.savevsp */                
 define(`build_lisp_frame',`
-	create_lisp_frame()
-	__(str(ifelse($1,`',fn,$1),lisp_frame.savefn(sp)))
-	__(str(ifelse($2,`',loc_pc,$2),lisp_frame.savelr(sp)))
-	__(str(ifelse($3,`',vsp,$3),lisp_frame.savevsp(sp)))
-')
-
-        	
+        __(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 */
+define(`restore_lisp_frame',`
+        __(ldm sp!,{fn,vsp,$1,lr})
+        ')
+
+define(`return_lisp_frame',`
+        __(ldm sp!,{fn,vsp,$1,pc})
+        ')
+        
 define(`discard_lisp_frame',`
-	__(la sp,lisp_frame.size(sp))
+	__(add sp,sp,#lisp_frame.size)
 	')
 	
@@ -229,5 +245,6 @@
 define(`trap_unless_lisptag_equal',`
 	__(extract_lisptag($3,$1))
-	__(trnei($3,$2))
+        __(cmp $3,#$2)
+	__(uuo_error_reg_not_lisptag(ne,$3,$2))
 ')
 
@@ -279,41 +296,26 @@
         __(uuo_error_not_callable(ne,nfn))
 
-')	
+')
+
 
 define(`mkcatch',`
-	__(mflr loc_pc)
-	__(ldr(imm0,tcr.catch_top(rcontext)))
-	__(lwz imm1,0(loc_pc)) /* a forward branch to the catch/unwind cleanup */
-	__(rlwinm imm1,imm1,0,6,29)	/* extract LI */
-	__(add loc_pc,loc_pc,imm1)
-	__(build_lisp_frame(fn,loc_pc,vsp))
-	__(sub loc_pc,loc_pc,imm1)
-	__(la loc_pc,4(loc_pc))	/* skip over the forward branch */
-	__(mtlr loc_pc)
-	__(lwi(imm4,(catch_frame.element_count<<num_subtag_bits)|subtag_catch_frame))
-	__(ldr(imm3,tcr.xframe(rcontext)))
-	__(ldr(imm1,tcr.db_link(rcontext)))
-	__(TSP_Alloc_Fixed_Unboxed(catch_frame.size))
-	__(la nargs,tsp_frame.data_offset+fulltag_misc(tsp))
-        __(str(imm4,catch_frame.header(nargs)))
-	__(str(arg_z,catch_frame.catch_tag(nargs)))
-	__(str(imm0,catch_frame.link(nargs)))
-	__(str(imm2,catch_frame.mvflag(nargs)))
-	__(str(sp,catch_frame.csp(nargs)))
-	__(str(imm1,catch_frame.db_link(nargs)))
-        __(str(first_nvr,catch_frame.regs+0*node_size(nargs)))
-        __(str(second_nvr,catch_frame.regs+1*node_size(nargs)))
-        __(str(third_nvr,catch_frame.regs+2*node_size(nargs)))
-        __(str(fourth_nvr,catch_frame.regs+3*node_size(nargs)))
-        __(str(fifth_nvr,catch_frame.regs+4*node_size(nargs)))
-        __(str(sixth_nvr,catch_frame.regs+5*node_size(nargs)))
-        __(str(seventh_nvr,catch_frame.regs+6*node_size(nargs)))
-        __(str(eighth_nvr,catch_frame.regs+7*node_size(nargs)))
-	__(str(imm3,catch_frame.xframe(nargs)))
-	__(str(rzero,catch_frame.tsp_segment(nargs)))
-	__(Set_TSP_Frame_Boxed())
-	__(str(nargs,tcr.catch_top(rcontext)))
-        __(li nargs,0)
-
+	__(build_lisp_frame(imm0))
+        __(movc16(imm0,make_header(catch_frame.element_count,subtag_u32_vector)))
+        __(str imm0,[sp,#-((catch_frame.element_count+1)*node_size)]!)
+        __(mov imm0,#0)
+        __(str imm0,[sp,#catch_frame.catch_tag+fulltag_misc])
+        __(ldr imm0,[rcontext,#tcr.catch_top])
+        __(str imm0,[sp,#catch_frame.link+fulltag_misc])
+        __(ldr imm0,[rcontext,#tcr.db_link])
+        __(str imm0,[sp,#catch_frame.db_link+fulltag_misc])
+        __(ldr imm0,[rcontext,#tcr.xframe])
+        __(str imm0,[sp,#catch_frame.xframe+fulltag_misc])
+        __(add imm0,sp,#fulltag_misc)
+        __(str imm2,[imm0,#catch_frame.mvflag])
+        __(mov imm2,#subtag_catch_frame)
+        __(strb imm2,[imm0,#misc_subtag_offset])
+        __(str arg_z,[imm0,#catch_frame.catch_tag])
+        __(str imm0,[rcontext,#tcr.catch_top])
+        __(add lr,lr,#4)
 ')	
 
@@ -335,6 +337,6 @@
 
 define(`Cons',`
+        __(add allocptr,allocptr,#-cons.size+fulltag_cons)
         __(ldr allocbase,[rcontext,#tcr.save_allocbase])
-        __(add allocptr,allocptr,#-cons.size+fulltag_cons)
         __(cmp allocptr,allocbase)
         __(uuo_alloc_trap(lo))
@@ -382,8 +384,10 @@
 /*  Parameters $1, $2 as above; $3 = physical size constant. */
 define(`Misc_Alloc_Fixed',`
-	__(la allocptr,(-$3)+fulltag_misc(allocptr))
-        __(alloc_trap())
-	__(str($2,misc_header_offset(allocptr)))
-	__(mr $1,allocptr)
+        __(add allocptr,allocptr,#(-$3)+fulltag_misc)
+        __(ldr allocbase,[rcontext,#tcr.save_allocbase])
+        __(cmp allocptr,allocbase)
+        __(uuo_alloc_trap(lo))
+	__(str $2,[allocptr,#misc_header_offset])
+	__(mov $1,allocptr)
 	__(clear_alloc_tag())
 ')
@@ -514,4 +518,4 @@
 
 define(`suspend_now',`
-	__(uuo_suspend_now())
-')
+	__(uuo_suspend_now(al))
+')
