Rev 3833 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3833 | Rev 3837 | ||
---|---|---|---|
1 | # |
1 | # |
2 | # Copyright (c) 2006 Martin Decky |
2 | # Copyright (c) 2006 Martin Decky |
3 | # All rights reserved. |
3 | # All rights reserved. |
4 | # |
4 | # |
5 | # Redistribution and use in source and binary forms, with or without |
5 | # Redistribution and use in source and binary forms, with or without |
6 | # modification, are permitted provided that the following conditions |
6 | # modification, are permitted provided that the following conditions |
7 | # are met: |
7 | # are met: |
8 | # |
8 | # |
9 | # - Redistributions of source code must retain the above copyright |
9 | # - Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. |
10 | # notice, this list of conditions and the following disclaimer. |
11 | # - Redistributions in binary form must reproduce the above copyright |
11 | # - Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the |
12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. |
13 | # documentation and/or other materials provided with the distribution. |
14 | # - The name of the author may not be used to endorse or promote products |
14 | # - The name of the author may not be used to endorse or promote products |
15 | # derived from this software without specific prior written permission. |
15 | # derived from this software without specific prior written permission. |
16 | # |
16 | # |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | # |
27 | # |
28 | 28 | ||
29 | #include <arch/asm/regname.h> |
29 | #include <arch/asm/regname.h> |
30 | #include <arch/mm/page.h> |
30 | #include <arch/mm/page.h> |
31 | 31 | ||
32 | .section K_UNMAPPED_TEXT_START, "ax" |
32 | .section K_UNMAPPED_TEXT_START, "ax" |
33 | 33 | ||
34 | .macro CONTEXT_STORE |
34 | .macro CONTEXT_STORE |
35 | 35 | ||
36 | # save R12 in SPRG1, backup CR in R12 |
36 | # save R12 in SPRG1, backup CR in R12 |
37 | # save SP in SPRG2 |
37 | # save SP in SPRG2 |
38 | 38 | ||
39 | mtsprg1 r12 |
39 | mtsprg1 r12 |
40 | mfcr r12 |
40 | mfcr r12 |
41 | mtsprg2 sp |
41 | mtsprg2 sp |
42 | 42 | ||
43 | # check whether SP is in kernel |
43 | # check whether SP is in kernel |
44 | 44 | ||
45 | andis. sp, sp, 0x8000 |
45 | andis. sp, sp, 0x8000 |
46 | bne 1f |
46 | bne 1f |
47 | 47 | ||
48 | # stack is in user-space |
48 | # stack is in user-space |
49 | 49 | ||
50 | mfsprg0 sp |
50 | mfsprg0 sp |
51 | 51 | ||
52 | b 2f |
52 | b 2f |
53 | 53 | ||
54 | 1: |
54 | 1: |
55 | 55 | ||
56 | # stack is in kernel |
56 | # stack is in kernel |
57 | 57 | ||
58 | mfsprg2 sp |
58 | mfsprg2 sp |
59 | subis sp, sp, 0x8000 |
59 | subis sp, sp, 0x8000 |
60 | 60 | ||
61 | 2: |
61 | 2: |
62 | 62 | ||
63 | subi sp, sp, 164 |
63 | subi sp, sp, 164 |
64 | stw r0, 8(sp) |
64 | stw r0, 8(sp) |
65 | stw r2, 12(sp) |
65 | stw r2, 12(sp) |
66 | stw r3, 16(sp) |
66 | stw r3, 16(sp) |
67 | stw r4, 20(sp) |
67 | stw r4, 20(sp) |
68 | stw r5, 24(sp) |
68 | stw r5, 24(sp) |
69 | stw r6, 28(sp) |
69 | stw r6, 28(sp) |
70 | stw r7, 32(sp) |
70 | stw r7, 32(sp) |
71 | stw r8, 36(sp) |
71 | stw r8, 36(sp) |
72 | stw r9, 40(sp) |
72 | stw r9, 40(sp) |
73 | stw r10, 44(sp) |
73 | stw r10, 44(sp) |
74 | stw r11, 48(sp) |
74 | stw r11, 48(sp) |
75 | stw r13, 52(sp) |
75 | stw r13, 52(sp) |
76 | stw r14, 56(sp) |
76 | stw r14, 56(sp) |
77 | stw r15, 60(sp) |
77 | stw r15, 60(sp) |
78 | stw r16, 64(sp) |
78 | stw r16, 64(sp) |
79 | stw r17, 68(sp) |
79 | stw r17, 68(sp) |
80 | stw r18, 72(sp) |
80 | stw r18, 72(sp) |
81 | stw r19, 76(sp) |
81 | stw r19, 76(sp) |
82 | stw r20, 80(sp) |
82 | stw r20, 80(sp) |
83 | stw r21, 84(sp) |
83 | stw r21, 84(sp) |
84 | stw r22, 88(sp) |
84 | stw r22, 88(sp) |
85 | stw r23, 92(sp) |
85 | stw r23, 92(sp) |
86 | stw r24, 96(sp) |
86 | stw r24, 96(sp) |
87 | stw r25, 100(sp) |
87 | stw r25, 100(sp) |
88 | stw r26, 104(sp) |
88 | stw r26, 104(sp) |
89 | stw r27, 108(sp) |
89 | stw r27, 108(sp) |
90 | stw r28, 112(sp) |
90 | stw r28, 112(sp) |
91 | stw r29, 116(sp) |
91 | stw r29, 116(sp) |
92 | stw r30, 120(sp) |
92 | stw r30, 120(sp) |
93 | stw r31, 124(sp) |
93 | stw r31, 124(sp) |
94 | 94 | ||
95 | stw r12, 128(sp) |
95 | stw r12, 128(sp) |
96 | 96 | ||
97 | mfsrr0 r12 |
97 | mfsrr0 r12 |
98 | stw r12, 132(sp) |
98 | stw r12, 132(sp) |
99 | 99 | ||
100 | mfsrr1 r12 |
100 | mfsrr1 r12 |
101 | stw r12, 136(sp) |
101 | stw r12, 136(sp) |
102 | 102 | ||
103 | mflr r12 |
103 | mflr r12 |
104 | stw r12, 140(sp) |
104 | stw r12, 140(sp) |
105 | 105 | ||
106 | mfctr r12 |
106 | mfctr r12 |
107 | stw r12, 144(sp) |
107 | stw r12, 144(sp) |
108 | 108 | ||
109 | mfxer r12 |
109 | mfxer r12 |
110 | stw r12, 148(sp) |
110 | stw r12, 148(sp) |
111 | 111 | ||
112 | mfdar r12 |
112 | mfdar r12 |
113 | stw r12, 152(sp) |
113 | stw r12, 152(sp) |
114 | 114 | ||
115 | mfsprg1 r12 |
115 | mfsprg1 r12 |
116 | stw r12, 156(sp) |
116 | stw r12, 156(sp) |
117 | 117 | ||
118 | mfsprg2 r12 |
118 | mfsprg2 r12 |
119 | stw r12, 160(sp) |
119 | stw r12, 160(sp) |
120 | .endm |
120 | .endm |
121 | 121 | ||
122 | .org 0x100 |
122 | .org 0x100 |
123 | .global exc_system_reset |
123 | .global exc_system_reset |
124 | exc_system_reset: |
124 | exc_system_reset: |
125 | CONTEXT_STORE |
125 | CONTEXT_STORE |
126 | 126 | ||
127 | li r3, 0 |
127 | li r3, 0 |
128 | b jump_to_kernel |
128 | b jump_to_kernel |
129 | 129 | ||
130 | .org 0x200 |
130 | .org 0x200 |
131 | .global exc_machine_check |
131 | .global exc_machine_check |
132 | exc_machine_check: |
132 | exc_machine_check: |
133 | CONTEXT_STORE |
133 | CONTEXT_STORE |
134 | 134 | ||
135 | li r3, 1 |
135 | li r3, 1 |
136 | b jump_to_kernel |
136 | b jump_to_kernel |
137 | 137 | ||
138 | .org 0x300 |
138 | .org 0x300 |
139 | .global exc_data_storage |
139 | .global exc_data_storage |
140 | exc_data_storage: |
140 | exc_data_storage: |
141 | CONTEXT_STORE |
141 | CONTEXT_STORE |
142 | 142 | ||
143 | b data_storage |
143 | b data_storage |
144 | 144 | ||
145 | .org 0x400 |
145 | .org 0x400 |
146 | .global exc_instruction_storage |
146 | .global exc_instruction_storage |
147 | exc_instruction_storage: |
147 | exc_instruction_storage: |
148 | CONTEXT_STORE |
148 | CONTEXT_STORE |
149 | 149 | ||
150 | b instruction_storage |
150 | b instruction_storage |
151 | 151 | ||
152 | .org 0x500 |
152 | .org 0x500 |
153 | .global exc_external |
153 | .global exc_external |
154 | exc_external: |
154 | exc_external: |
155 | CONTEXT_STORE |
155 | CONTEXT_STORE |
156 | 156 | ||
157 | li r3, 4 |
157 | li r3, 4 |
158 | b jump_to_kernel |
158 | b jump_to_kernel |
159 | 159 | ||
160 | .org 0x600 |
160 | .org 0x600 |
161 | .global exc_alignment |
161 | .global exc_alignment |
162 | exc_alignment: |
162 | exc_alignment: |
163 | CONTEXT_STORE |
163 | CONTEXT_STORE |
164 | 164 | ||
165 | li r3, 5 |
165 | li r3, 5 |
166 | b jump_to_kernel |
166 | b jump_to_kernel |
167 | 167 | ||
168 | .org 0x700 |
168 | .org 0x700 |
169 | .global exc_program |
169 | .global exc_program |
170 | exc_program: |
170 | exc_program: |
171 | CONTEXT_STORE |
171 | CONTEXT_STORE |
172 | 172 | ||
173 | li r3, 6 |
173 | li r3, 6 |
174 | b jump_to_kernel |
174 | b jump_to_kernel |
175 | 175 | ||
176 | .org 0x800 |
176 | .org 0x800 |
177 | .global exc_fp_unavailable |
177 | .global exc_fp_unavailable |
178 | exc_fp_unavailable: |
178 | exc_fp_unavailable: |
179 | CONTEXT_STORE |
179 | CONTEXT_STORE |
180 | 180 | ||
181 | li r3, 7 |
181 | li r3, 7 |
182 | b jump_to_kernel |
182 | b jump_to_kernel |
183 | 183 | ||
184 | .org 0x900 |
184 | .org 0x900 |
185 | .global exc_decrementer |
185 | .global exc_decrementer |
186 | exc_decrementer: |
186 | exc_decrementer: |
187 | CONTEXT_STORE |
187 | CONTEXT_STORE |
188 | 188 | ||
189 | li r3, 8 |
189 | li r3, 8 |
190 | b jump_to_kernel |
190 | b jump_to_kernel |
191 | 191 | ||
192 | .org 0xa00 |
192 | .org 0xa00 |
193 | .global exc_reserved0 |
193 | .global exc_reserved0 |
194 | exc_reserved0: |
194 | exc_reserved0: |
195 | CONTEXT_STORE |
195 | CONTEXT_STORE |
196 | 196 | ||
197 | li r3, 9 |
197 | li r3, 9 |
198 | b jump_to_kernel |
198 | b jump_to_kernel |
199 | 199 | ||
200 | .org 0xb00 |
200 | .org 0xb00 |
201 | .global exc_reserved1 |
201 | .global exc_reserved1 |
202 | exc_reserved1: |
202 | exc_reserved1: |
203 | CONTEXT_STORE |
203 | CONTEXT_STORE |
204 | 204 | ||
205 | li r3, 10 |
205 | li r3, 10 |
206 | b jump_to_kernel |
206 | b jump_to_kernel |
207 | 207 | ||
208 | .org 0xc00 |
208 | .org 0xc00 |
209 | .global exc_syscall |
209 | .global exc_syscall |
210 | exc_syscall: |
210 | exc_syscall: |
211 | CONTEXT_STORE |
211 | CONTEXT_STORE |
212 | 212 | ||
213 | b jump_to_kernel_syscall |
213 | b jump_to_kernel_syscall |
214 | 214 | ||
215 | .org 0xd00 |
215 | .org 0xd00 |
216 | .global exc_trace |
216 | .global exc_trace |
217 | exc_trace: |
217 | exc_trace: |
218 | CONTEXT_STORE |
218 | CONTEXT_STORE |
219 | 219 | ||
220 | li r3, 12 |
220 | li r3, 12 |
221 | b jump_to_kernel |
221 | b jump_to_kernel |
222 | 222 | ||
223 | .org 0x4000 |
223 | .org 0x4000 |
224 | data_storage: |
224 | data_storage: |
225 | li r3, 2 |
225 | li r3, 2 |
226 | mr r4, sp |
226 | mr r4, sp |
227 | addi r4, r4, 8 |
227 | addi r4, r4, 8 |
228 | bl pht_real_refill |
228 | bl pht_refill_real |
229 | 229 | ||
230 | cmpwi r3, 0 |
230 | cmpwi r3, 0 |
231 | bne iret_real |
231 | bne iret_real |
232 | 232 | ||
233 | li r3, 2 |
233 | li r3, 2 |
234 | b jump_to_kernel |
234 | b jump_to_kernel |
235 | 235 | ||
236 | instruction_storage: |
236 | instruction_storage: |
237 | li r3, 3 |
237 | li r3, 3 |
238 | mr r4, sp |
238 | mr r4, sp |
239 | addi r4, r4, 8 |
239 | addi r4, r4, 8 |
240 | bl pht_real_refill |
240 | bl pht_refill_real |
241 | 241 | ||
242 | cmpwi r3, 0 |
242 | cmpwi r3, 0 |
243 | bne iret_real |
243 | bne iret_real |
244 | 244 | ||
245 | li r3, 3 |
245 | li r3, 3 |
246 | b jump_to_kernel |
246 | b jump_to_kernel |
247 | 247 | ||
248 | jump_to_kernel: |
248 | jump_to_kernel: |
249 | lis r12, iret@ha |
249 | lis r12, iret@ha |
250 | addi r12, r12, iret@l |
250 | addi r12, r12, iret@l |
251 | mtlr r12 |
251 | mtlr r12 |
252 | 252 | ||
253 | lis r12, exc_dispatch@ha |
253 | lis r12, exc_dispatch@ha |
254 | addi r12, r12, exc_dispatch@l |
254 | addi r12, r12, exc_dispatch@l |
255 | mtsrr0 r12 |
255 | mtsrr0 r12 |
256 | 256 | ||
257 | mfmsr r12 |
257 | mfmsr r12 |
258 | ori r12, r12, (msr_ir | msr_dr)@l |
258 | ori r12, r12, (msr_ir | msr_dr)@l |
259 | mtsrr1 r12 |
259 | mtsrr1 r12 |
260 | 260 | ||
261 | addis sp, sp, 0x8000 |
261 | addis sp, sp, 0x8000 |
262 | mr r4, sp |
262 | mr r4, sp |
263 | addi r4, r4, 8 |
263 | addi r4, r4, 8 |
264 | 264 | ||
265 | rfi |
265 | rfi |
266 | 266 | ||
267 | jump_to_kernel_syscall: |
267 | jump_to_kernel_syscall: |
268 | lis r12, syscall_handler@ha |
268 | lis r12, syscall_handler@ha |
269 | addi r12, r12, syscall_handler@l |
269 | addi r12, r12, syscall_handler@l |
270 | mtsrr0 r12 |
270 | mtsrr0 r12 |
271 | 271 | ||
272 | lis r12, iret_syscall@ha |
272 | lis r12, iret_syscall@ha |
273 | addi r12, r12, iret_syscall@l |
273 | addi r12, r12, iret_syscall@l |
274 | mtlr r12 |
274 | mtlr r12 |
275 | 275 | ||
276 | mfmsr r12 |
276 | mfmsr r12 |
277 | ori r12, r12, (msr_ir | msr_dr)@l |
277 | ori r12, r12, (msr_ir | msr_dr)@l |
278 | mtsrr1 r12 |
278 | mtsrr1 r12 |
279 | 279 | ||
280 | addis sp, sp, 0x8000 |
280 | addis sp, sp, 0x8000 |
281 | rfi |
281 | rfi |
282 | 282 | ||
283 | iret_real: |
283 | iret_real: |
284 | - | ||
285 | lwz r0, 8(sp) |
284 | lwz r0, 8(sp) |
286 | lwz r2, 12(sp) |
285 | lwz r2, 12(sp) |
287 | lwz r3, 16(sp) |
286 | lwz r3, 16(sp) |
288 | lwz r4, 20(sp) |
287 | lwz r4, 20(sp) |
289 | lwz r5, 24(sp) |
288 | lwz r5, 24(sp) |
290 | lwz r6, 28(sp) |
289 | lwz r6, 28(sp) |
291 | lwz r7, 32(sp) |
290 | lwz r7, 32(sp) |
292 | lwz r8, 36(sp) |
291 | lwz r8, 36(sp) |
293 | lwz r9, 40(sp) |
292 | lwz r9, 40(sp) |
294 | lwz r10, 44(sp) |
293 | lwz r10, 44(sp) |
295 | lwz r11, 48(sp) |
294 | lwz r11, 48(sp) |
296 | lwz r13, 52(sp) |
295 | lwz r13, 52(sp) |
297 | lwz r14, 56(sp) |
296 | lwz r14, 56(sp) |
298 | lwz r15, 60(sp) |
297 | lwz r15, 60(sp) |
299 | lwz r16, 64(sp) |
298 | lwz r16, 64(sp) |
300 | lwz r17, 68(sp) |
299 | lwz r17, 68(sp) |
301 | lwz r18, 72(sp) |
300 | lwz r18, 72(sp) |
302 | lwz r19, 76(sp) |
301 | lwz r19, 76(sp) |
303 | lwz r20, 80(sp) |
302 | lwz r20, 80(sp) |
304 | lwz r21, 84(sp) |
303 | lwz r21, 84(sp) |
305 | lwz r22, 88(sp) |
304 | lwz r22, 88(sp) |
306 | lwz r23, 92(sp) |
305 | lwz r23, 92(sp) |
307 | lwz r24, 96(sp) |
306 | lwz r24, 96(sp) |
308 | lwz r25, 100(sp) |
307 | lwz r25, 100(sp) |
309 | lwz r26, 104(sp) |
308 | lwz r26, 104(sp) |
310 | lwz r27, 108(sp) |
309 | lwz r27, 108(sp) |
311 | lwz r28, 112(sp) |
310 | lwz r28, 112(sp) |
312 | lwz r29, 116(sp) |
311 | lwz r29, 116(sp) |
313 | lwz r30, 120(sp) |
312 | lwz r30, 120(sp) |
314 | lwz r31, 124(sp) |
313 | lwz r31, 124(sp) |
315 | 314 | ||
316 | lwz r12, 128(sp) |
315 | lwz r12, 128(sp) |
317 | mtcr r12 |
316 | mtcr r12 |
318 | 317 | ||
319 | lwz r12, 132(sp) |
318 | lwz r12, 132(sp) |
320 | mtsrr0 r12 |
319 | mtsrr0 r12 |
321 | 320 | ||
322 | lwz r12, 136(sp) |
321 | lwz r12, 136(sp) |
323 | mtsrr1 r12 |
322 | mtsrr1 r12 |
324 | 323 | ||
325 | lwz r12, 140(sp) |
324 | lwz r12, 140(sp) |
326 | mtlr r12 |
325 | mtlr r12 |
327 | 326 | ||
328 | lwz r12, 144(sp) |
327 | lwz r12, 144(sp) |
329 | mtctr r12 |
328 | mtctr r12 |
330 | 329 | ||
331 | lwz r12, 148(sp) |
330 | lwz r12, 148(sp) |
332 | mtxer r12 |
331 | mtxer r12 |
333 | 332 | ||
334 | lwz r12, 156(sp) |
333 | lwz r12, 156(sp) |
335 | lwz sp, 160(sp) |
334 | lwz sp, 160(sp) |
336 | 335 | ||
337 | rfi |
336 | rfi |
338 | 337 | ||
339 | 338 | ||
340 |
|
339 |
|
341 | 340 | ||
342 | 341 | ||
343 | 342 |