

	/* context switch frame is as follows:
	 * lr
	 * r11
	 * r10
	 * r9
	 * r8
	 * r7
	 * r6
	 * r5
	 * r4
	 * spsr
	 * ulr
	 * usp
	 */
/* arm_context_switch(addr_t *old_sp, addr_t new_sp) */
	.global arm_context_switch
arm_context_switch:
	/* save all the usual registers + spsr */
	mrs	r3, spsr
	stmfd	sp!, { r3-r11, r14 }
	
	/* save some of the user registers */
	sub	r2, sp, $8           /* can't use sp in user mode ldm/stm */
	stmia	r2, { r13, r14 }^

	/* save old sp */
	str	r2, [r0] 

	/* load new user regs */
	ldmia	r1, { r13, r14 }^
	add	r1, r1, $8

	/* load new regs */
	ldmfd	r1!, { r3-r11, r14 }
	mov	sp, r1              /* restore sp */
	msr	spsr_all, r3	    /* restore spsr */
	bx	lr
