4 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999,2000,2001 Bernardo Innocenti <bernie@develer.com>
9 * \brief AVR context switch
13 * \author Bernardo Innocenti <bernie@develer.com>
14 * \author Stefano Fedrigo <aleph@develer.com>
19 /* void asm_switch_context(void **new_sp, void **save_sp) */
20 .globl asm_switch_context
41 ; push r18 caller-save
42 ; push r19 caller-save
43 ; push r20 caller-save
44 ; push r21 caller-save
45 ; push r22 caller-save
46 ; push r23 caller-save
47 ; push r24 caller-save
48 ; push r25 caller-save
49 ; push r26 caller-save
50 ; push r27 caller-save
53 ; push r30 caller-save
54 ; push r31 caller-save
56 ; First parameter (new_sp) is in r24:r25, second (save_sp) in r22:r23
58 in r0,SPL-__SFR_OFFSET ; r0:r1 = SP
59 in r1,SPH-__SFR_OFFSET
60 movw r26,r22 ; X = save_sp
61 st X+,r0 ; *save_sp = SP
63 movw r26,r24 ; X = new_sp
66 out SPL-__SFR_OFFSET,r0 ; SP = *new_sp
67 out SPH-__SFR_OFFSET,r1