1 | /* |
---|
2 | * hal_witch.S - CPU context switch function for TSAR-MIPS32 |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH.is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH.is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | .section .switch , "ax" , @progbits |
---|
25 | |
---|
26 | .global hal_do_cpu_switch |
---|
27 | .global hal_do_cpu_save |
---|
28 | .global hal_do_cpu_restore |
---|
29 | |
---|
30 | .set noat |
---|
31 | .set noreorder |
---|
32 | |
---|
33 | #--------------------------------------------------------------------------------- |
---|
34 | # The hal_do_cpu_switch() function makes the following assumptions: |
---|
35 | # - register $4 contains a pointer on the old thread context. |
---|
36 | # - register $5 contains a pointer on the new thread context. |
---|
37 | #--------------------------------------------------------------------------------- |
---|
38 | hal_do_cpu_switch: |
---|
39 | |
---|
40 | /* save old thread context */ |
---|
41 | |
---|
42 | move $26, $4 /* $26 <= ctx_old */ |
---|
43 | |
---|
44 | mfc0 $27, $14 |
---|
45 | sw $27, 0*4($26) /* save c0_epc to slot 0 */ |
---|
46 | |
---|
47 | sw $1, 1*4($26) |
---|
48 | sw $2, 2*4($26) |
---|
49 | sw $3, 3*4($26) |
---|
50 | sw $4, 4*4($26) |
---|
51 | sw $5, 5*4($26) |
---|
52 | sw $6, 6*4($26) |
---|
53 | sw $7, 7*4($26) |
---|
54 | sw $8, 8*4($26) |
---|
55 | sw $9, 9*4($26) |
---|
56 | sw $10, 10*4($26) |
---|
57 | sw $11, 11*4($26) |
---|
58 | sw $12, 12*4($26) |
---|
59 | sw $13, 13*4($26) |
---|
60 | sw $14, 14*4($26) |
---|
61 | sw $15, 15*4($26) |
---|
62 | sw $16, 16*4($26) |
---|
63 | sw $17, 17*4($26) |
---|
64 | sw $18, 18*4($26) |
---|
65 | sw $19, 19*4($26) |
---|
66 | sw $20, 20*4($26) |
---|
67 | sw $21, 21*4($26) |
---|
68 | sw $22, 22*4($26) |
---|
69 | sw $23, 23*4($26) |
---|
70 | sw $24, 24*4($26) |
---|
71 | sw $25, 25*4($26) |
---|
72 | |
---|
73 | mfhi $27 |
---|
74 | sw $27, 26*4($26) /* save hi to slot 26 */ |
---|
75 | mflo $27 |
---|
76 | sw $27, 27*4($26) /* save lo to slot 27 */ |
---|
77 | |
---|
78 | sw $28, 28*4($26) |
---|
79 | sw $29, 29*4($26) |
---|
80 | sw $30, 30*4($26) |
---|
81 | sw $31, 31*4($26) |
---|
82 | |
---|
83 | mfc0 $27, $12 |
---|
84 | sw $27, 34*4($26) /* save c0_sr to slot 34 */ |
---|
85 | mfc0 $27, $4, 2 |
---|
86 | sw $27, 35*4($26) /* save c0_th to slot 35 */ |
---|
87 | |
---|
88 | mfc2 $27, $0 |
---|
89 | sw $27, 32*4($26) /* save c2_ptpr to slot 32 */ |
---|
90 | mfc2 $27, $1 |
---|
91 | sw $27, 33*4($26) /* save c2_mode to slot 33 */ |
---|
92 | |
---|
93 | sync |
---|
94 | |
---|
95 | /* restore new thread context */ |
---|
96 | |
---|
97 | move $26, $5 /* $26 <= ctx_new */ |
---|
98 | |
---|
99 | lw $27, 0*4($26) |
---|
100 | mtc0 $27, $14 /* restore C0_epc from slot 0 */ |
---|
101 | |
---|
102 | lw $1, 1*4($26) |
---|
103 | lw $2, 2*4($26) |
---|
104 | lw $3, 3*4($26) |
---|
105 | lw $4, 4*4($26) |
---|
106 | lw $5, 5*4($26) |
---|
107 | lw $6, 6*4($26) |
---|
108 | lw $7, 7*4($26) |
---|
109 | lw $8, 8*4($26) |
---|
110 | lw $9, 9*4($26) |
---|
111 | lw $10, 10*4($26) |
---|
112 | lw $11, 11*4($26) |
---|
113 | lw $12, 12*4($26) |
---|
114 | lw $13, 13*4($26) |
---|
115 | lw $14, 14*4($26) |
---|
116 | lw $15, 15*4($26) |
---|
117 | lw $16, 16*4($26) |
---|
118 | lw $17, 17*4($26) |
---|
119 | lw $18, 18*4($26) |
---|
120 | lw $19, 19*4($26) |
---|
121 | lw $20, 20*4($26) |
---|
122 | lw $21, 21*4($26) |
---|
123 | lw $22, 22*4($26) |
---|
124 | lw $23, 23*4($26) |
---|
125 | lw $24, 24*4($26) |
---|
126 | lw $25, 25*4($26) |
---|
127 | |
---|
128 | lw $27, 26*4($26) |
---|
129 | mthi $27 /* restore hi from slot 26 */ |
---|
130 | lw $27, 27*4($26) |
---|
131 | mtlo $27 /* restore lo from slot 27 */ |
---|
132 | |
---|
133 | lw $28, 28*4($26) |
---|
134 | lw $29, 29*4($26) |
---|
135 | lw $30, 30*4($26) |
---|
136 | lw $31, 31*4($26) /* restore ra from slot 31 */ |
---|
137 | |
---|
138 | lw $27, 32*4($26) |
---|
139 | mtc2 $27, $0 /* restore c2_ptpr from slot 32 */ |
---|
140 | |
---|
141 | lw $27, 35*4($26) |
---|
142 | mtc0 $27, $4, 2 /* restore c0_th from slot 35 */ |
---|
143 | |
---|
144 | lw $27, 33*4($26) |
---|
145 | lw $26, 34*4($26) |
---|
146 | |
---|
147 | mtc2 $27, $1 /* restore c2_mode from slot 33 */ |
---|
148 | mtc0 $26, $12 /* restore c0_sr from slot 34 */ |
---|
149 | |
---|
150 | jr $31 /* return to caller */ |
---|
151 | nop |
---|
152 | |
---|
153 | #--------------------------------------------------------------------------------- |
---|
154 | # The hal_do_cpu_save()function makes the following assumption: |
---|
155 | # - register $4 contains a pointer on the target thread context. |
---|
156 | #--------------------------------------------------------------------------------- |
---|
157 | hal_do_cpu_save: |
---|
158 | |
---|
159 | move $26, $4 /* $26 <= &context */ |
---|
160 | |
---|
161 | mfc0 $27, $14 |
---|
162 | sw $27, 0*4($26) /* save c0_epc to slot 0 */ |
---|
163 | |
---|
164 | sw $1, 1*4($26) |
---|
165 | sw $2, 2*4($26) |
---|
166 | sw $3, 3*4($26) |
---|
167 | sw $4, 4*4($26) |
---|
168 | sw $5, 5*4($26) |
---|
169 | sw $6, 6*4($26) |
---|
170 | sw $7, 7*4($26) |
---|
171 | sw $8, 8*4($26) |
---|
172 | sw $9, 9*4($26) |
---|
173 | sw $10, 10*4($26) |
---|
174 | sw $11, 11*4($26) |
---|
175 | sw $12, 12*4($26) |
---|
176 | sw $13, 13*4($26) |
---|
177 | sw $14, 14*4($26) |
---|
178 | sw $15, 15*4($26) |
---|
179 | sw $16, 16*4($26) |
---|
180 | sw $17, 17*4($26) |
---|
181 | sw $18, 18*4($26) |
---|
182 | sw $19, 19*4($26) |
---|
183 | sw $20, 20*4($26) |
---|
184 | sw $21, 21*4($26) |
---|
185 | sw $22, 22*4($26) |
---|
186 | sw $23, 23*4($26) |
---|
187 | sw $24, 24*4($26) |
---|
188 | sw $25, 25*4($26) |
---|
189 | |
---|
190 | mfhi $27 |
---|
191 | sw $27, 26*4($26) /* save hi to slot 26 */ |
---|
192 | mflo $27 |
---|
193 | sw $27, 27*4($26) /* save lo to slot 27 */ |
---|
194 | |
---|
195 | sw $28, 28*4($26) /* save gp to slot 28 */ |
---|
196 | sw $29, 29*4($26) /* save sp to slot 29 */ |
---|
197 | sw $30, 30*4($26) /* save s8 to slot 30 */ |
---|
198 | sw $31, 31*4($26) /* save ra to slot 31 */ |
---|
199 | |
---|
200 | mfc2 $27, $0 |
---|
201 | sw $27, 32*4($26) /* save c2_ptpr to slot 32 */ |
---|
202 | mfc2 $27, $1 |
---|
203 | sw $27, 33*4($26) /* save c2_mode to slot 33 */ |
---|
204 | mfc0 $27, $12 |
---|
205 | sw $27, 34*4($26) /* save c0_sr to slot 34 */ |
---|
206 | mfc0 $27, $4, 2 |
---|
207 | sw $27, 35*4($26) /* save c0_th to slot 35 */ |
---|
208 | |
---|
209 | sync |
---|
210 | |
---|
211 | jr $31 /* return to caller */ |
---|
212 | nop |
---|
213 | |
---|
214 | #--------------------------------------------------------------------------------- |
---|
215 | # The hal_do_cpu_restore()function makes the following assumption: |
---|
216 | # - register $4 contains a pointer on the target thread context. |
---|
217 | #--------------------------------------------------------------------------------- |
---|
218 | hal_do_cpu_restore: |
---|
219 | |
---|
220 | move $26, $4 /* $26 <= &context */ |
---|
221 | |
---|
222 | lw $27, 0*4($26) |
---|
223 | mtc0 $27, $14 /* restore C0_epc from slot 0 */ |
---|
224 | |
---|
225 | lw $1, 1*4($26) |
---|
226 | lw $2, 2*4($26) |
---|
227 | lw $3, 3*4($26) |
---|
228 | lw $4, 4*4($26) |
---|
229 | lw $5, 5*4($26) |
---|
230 | lw $6, 6*4($26) |
---|
231 | lw $7, 7*4($26) |
---|
232 | lw $8, 8*4($26) |
---|
233 | lw $9, 9*4($26) |
---|
234 | lw $10, 10*4($26) |
---|
235 | lw $11, 11*4($26) |
---|
236 | lw $12, 12*4($26) |
---|
237 | lw $13, 13*4($26) |
---|
238 | lw $14, 14*4($26) |
---|
239 | lw $15, 15*4($26) |
---|
240 | lw $16, 16*4($26) |
---|
241 | lw $17, 17*4($26) |
---|
242 | lw $18, 18*4($26) |
---|
243 | lw $19, 19*4($26) |
---|
244 | lw $20, 20*4($26) |
---|
245 | lw $21, 21*4($26) |
---|
246 | lw $22, 22*4($26) |
---|
247 | lw $23, 23*4($26) |
---|
248 | lw $24, 24*4($26) |
---|
249 | lw $25, 25*4($26) |
---|
250 | |
---|
251 | lw $27, 26*4($26) |
---|
252 | mthi $27 /* restore hi from slot 26 */ |
---|
253 | lw $27, 27*4($26) |
---|
254 | mtlo $27 /* restore lo from slot 27 */ |
---|
255 | |
---|
256 | lw $28, 28*4($26) |
---|
257 | lw $29, 29*4($26) |
---|
258 | lw $30, 30*4($26) |
---|
259 | lw $31, 31*4($26) /* restore ra from slot 31 */ |
---|
260 | |
---|
261 | lw $27, 32*4($26) |
---|
262 | mtc2 $27, $0 /* restore c2_ptpr from slot 32 */ |
---|
263 | |
---|
264 | lw $27, 35*4($26) |
---|
265 | mtc0 $27, $4, 2 /* restore c0_th from slot 35 */ |
---|
266 | |
---|
267 | lw $27, 33*4($26) |
---|
268 | lw $26, 34*4($26) |
---|
269 | |
---|
270 | mtc2 $27, $1 /* restore c2_mode from slot 33 */ |
---|
271 | mtc0 $26, $12 /* restore c0_sr from slot 34 */ |
---|
272 | |
---|
273 | jr $31 /* return to caller */ |
---|
274 | nop |
---|
275 | |
---|
276 | .set reorder |
---|
277 | .set at |
---|
278 | |
---|