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