Add DevLib license information.
[bertos.git] / kern / switch_avr.S
1 /*!
2  * \file
3  * <!--
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.
7  * -->
8  *
9  * \brief AVR context switch
10  *
11  * \version $Id$
12  *
13  * \author Bernardo Innocenti <bernie@develer.com>
14  * \author Stefano Fedrigo <aleph@develer.com>
15  */
16
17 #include <avr/io.h>
18
19 /* void asm_switch_context(void **new_sp, void **save_sp) */
20 .globl asm_switch_context
21 asm_switch_context:
22
23 ;       push    r0      caller-save
24 ;       push    r1      caller-save
25         push    r2
26         push    r3
27         push    r4
28         push    r5
29         push    r6
30         push    r7
31         push    r8
32         push    r9
33         push    r10
34         push    r11
35         push    r12
36         push    r13
37         push    r14
38         push    r15
39         push    r16
40         push    r17
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
51         push    r28
52         push    r29
53 ;       push    r30     caller-save
54 ;       push    r31     caller-save
55
56 ; First parameter (new_sp) is in r24:r25, second (save_sp) in r22:r23
57
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
62         st      X,r1
63         movw    r26,r24                 ; X = new_sp
64         ld      r0,X+
65         ld      r1,X
66         out     SPL-__SFR_OFFSET,r0     ; SP = *new_sp
67         out     SPH-__SFR_OFFSET,r1
68
69 ;       pop     r31     caller-save
70 ;       pop     r30     caller-save
71         pop     r29
72         pop     r28
73 ;       pop     r27     caller-save
74 ;       pop     r26     caller-save
75 ;       pop     r25     caller-save
76 ;       pop     r24     caller-save
77 ;       pop     r23     caller-save
78 ;       pop     r22     caller-save
79 ;       pop     r21     caller-save
80 ;       pop     r20     caller-save
81 ;       pop     r19     caller-save
82 ;       pop     r18     caller-save
83         pop     r17
84         pop     r16
85         pop     r15
86         pop     r14
87         pop     r13
88         pop     r12
89         pop     r11
90         pop     r10
91         pop     r9
92         pop     r8
93         pop     r7
94         pop     r6
95         pop     r5
96         pop     r4
97         pop     r3
98         pop     r2
99 ;       pop     r1      caller-save
100 ;       pop     r0      caller-save
101
102         ret