4 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999,2000,2001 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See devlib/README for information.
9 * \brief AVR context switch
13 * \author Bernardo Innocenti <bernie@develer.com>
14 * \author Stefano Fedrigo <aleph@develer.com>
20 * NOTE: At each change of this function affecting proc.c
21 * (i.e. arguments, data stored in the stack) bump up version
22 * number in asm_switch_version().
25 /* void asm_switch_context(void **new_sp, void **save_sp) */
26 .globl asm_switch_context
29 in r0,SREG-__SFR_OFFSET
49 ; push r18 caller-save
50 ; push r19 caller-save
51 ; push r20 caller-save
52 ; push r21 caller-save
53 ; push r22 caller-save
54 ; push r23 caller-save
55 ; push r24 caller-save
56 ; push r25 caller-save
57 ; push r26 caller-save
58 ; push r27 caller-save
61 ; push r30 caller-save
62 ; push r31 caller-save
64 ; First parameter (new_sp) is in r24:r25, second (save_sp) in r22:r23
66 in r0,SPL-__SFR_OFFSET ; r0:r1 = SP
67 in r1,SPH-__SFR_OFFSET
68 movw r26,r22 ; X = save_sp
69 st X+,r0 ; *save_sp = SP
71 movw r26,r24 ; X = new_sp
74 out SPL-__SFR_OFFSET,r0 ; SP = *new_sp
75 out SPH-__SFR_OFFSET,r1
110 out SREG-__SFR_OFFSET,r0
115 /* int asm_switch_version(void) */
116 .globl asm_switch_version