Add dual-license information.
[bertos.git] / kern / switch_dsp56k.c
1 /*!
2  * \file
3  * <!--
4  * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See devlib/README for information.
6  * -->
7  *
8  * \version $Id$
9  *
10  * \author Giovanni Bajo <rasky@develer.com>
11  *
12  * \brief DSP5680x task switching support
13  */
14
15 /*
16  * $Log$
17  * Revision 1.2  2004/06/03 11:27:09  bernie
18  * Add dual-license information.
19  *
20  * Revision 1.1  2004/05/23 17:27:00  bernie
21  * Import kern/ subdirectory.
22  *
23  */
24
25 void asm_switch_context(void ** new_sp/*R2*/, void ** save_sp/*R3*/);
26 asm void asm_switch_context(void ** new_sp, void ** save_sp)
27 {
28         lea   (SP)+
29         move  n,x:(SP)+
30         move  x0,x:(SP)+
31         move  y0,x:(SP)+
32         move  y1,x:(SP)+
33         move  a0,x:(SP)+
34         move  a1,x:(SP)+
35         move  a2,x:(SP)+
36         move  b0,x:(SP)+
37         move  b1,x:(SP)+
38         move  b2,x:(SP)+
39         move  r0,x:(SP)+
40         move  r1,x:(SP)+
41         move  r2,x:(SP)+
42         move  r3,x:(SP)+
43
44         move  omr,x:(SP)+
45         move  la,x:(SP)+
46         move  m01,x:(SP)+
47         move  lc,x:(SP)+
48
49         ;
50         ; save hardware stack
51         ;
52         move  hws,x:(SP)+
53         move  hws,x:(SP)+
54
55         ; From the manual:
56         ; The compiler uses page 0 address locations X: 0x0030 - 0x003F as register
57         ; variables. Frequently accessed local variables are assigned to the page 0
58         ; registers instead of to stack locations so that load and store instructions
59         ; are shortened. Addresses X: 0x0030 - 0x0037 (page 0 registers MR0-MR7) are
60         ; volatile registers and can be overwritten. The remaining registers (page 0
61         ; registers MR8-MR15) are treated as non-volatile and, if used by a routine,
62         ; must be saved on entry and restored on exit.
63         ;
64         ; So, register 0x30-0x37 are caller-save, while 0x38-0x3F are callee-save.
65         move  x:<$38,y1
66         move  y1,x:(SP)+
67         move  x:<$39,y1
68         move  y1,x:(SP)+
69         move  x:<$3A,y1
70         move  y1,x:(SP)+
71         move  x:<$3B,y1
72         move  y1,x:(SP)+
73         move  x:<$3C,y1
74         move  y1,x:(SP)+
75         move  x:<$3D,y1
76         move  y1,x:(SP)+
77         move  x:<$3E,y1
78         move  y1,x:(SP)+
79         move  x:<$3F,y1
80         move  y1,x:(SP)
81         
82         ; 
83         ; 28 words have been pushed on the stack.
84         nop
85         move SP, x:(R3)
86         nop
87         move x:(R2), SP
88         nop
89
90         pop   y1
91         move  y1,x:<$3F
92         pop   y1
93         move  y1,x:<$3E
94         pop   y1
95         move  y1,x:<$3D
96         pop   y1
97         move  y1,x:<$3C
98         pop   y1
99         move  y1,x:<$3B
100         pop   y1
101         move  y1,x:<$3A
102         pop   y1
103         move  y1,x:<$39
104         pop   y1
105         move  y1,x:<$38
106
107         ;
108         ; restore hardware stack
109         ;
110         move  hws,la  ; Clear HWS to ensure proper reload
111         move  hws,la
112         pop   HWS
113         pop   HWS
114         
115         ;
116         ; restore all saved registers
117         ;
118         pop   lc
119         pop   m01
120         pop   la
121         pop   omr
122
123         pop   r3
124         pop   r2
125         pop   r1
126         pop   r0
127         pop   b2
128         pop   b1
129         pop   b0
130         pop   a2
131         pop   a1
132         pop   a0
133
134         pop   y1
135         pop   y0
136         pop   x0
137
138         pop   n
139         
140         rts
141 }