Rev 1269 | Rev 1384 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
987 | decky | 1 | # |
2 | # Copyright (C) 2006 Martin 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 | |||
1277 | decky | 63 | subi sp, sp, 148 |
1004 | decky | 64 | stw r0, 0(sp) |
65 | stw r2, 4(sp) |
||
66 | stw r3, 8(sp) |
||
67 | stw r4, 12(sp) |
||
68 | stw r5, 16(sp) |
||
69 | stw r6, 20(sp) |
||
70 | stw r7, 24(sp) |
||
71 | stw r8, 28(sp) |
||
72 | stw r9, 32(sp) |
||
73 | stw r10, 36(sp) |
||
74 | stw r11, 40(sp) |
||
1267 | decky | 75 | stw r13, 44(sp) |
76 | stw r14, 48(sp) |
||
77 | stw r15, 52(sp) |
||
78 | stw r16, 56(sp) |
||
79 | stw r17, 60(sp) |
||
80 | stw r18, 64(sp) |
||
81 | stw r19, 68(sp) |
||
82 | stw r20, 72(sp) |
||
83 | stw r21, 76(sp) |
||
84 | stw r22, 80(sp) |
||
85 | stw r23, 84(sp) |
||
86 | stw r24, 88(sp) |
||
87 | stw r25, 92(sp) |
||
88 | stw r26, 96(sp) |
||
89 | stw r27, 100(sp) |
||
90 | stw r28, 104(sp) |
||
91 | stw r29, 108(sp) |
||
92 | stw r30, 112(sp) |
||
93 | stw r31, 116(sp) |
||
1004 | decky | 94 | |
1277 | decky | 95 | stw r12, 120(sp) |
1267 | decky | 96 | |
1277 | decky | 97 | mfsrr0 r12 |
98 | stw r12, 124(sp) |
||
1004 | decky | 99 | |
1277 | decky | 100 | mfsrr1 r12 |
101 | stw r12, 128(sp) |
||
1004 | decky | 102 | |
1277 | decky | 103 | mflr r12 |
1267 | decky | 104 | stw r12, 132(sp) |
1004 | decky | 105 | |
1277 | decky | 106 | mfctr r12 |
107 | stw r12, 136(sp) |
||
1004 | decky | 108 | |
1277 | decky | 109 | mfxer r12 |
110 | stw r12, 140(sp) |
||
111 | |||
112 | mfsprg1 r12 |
||
113 | stw r12, 144(sp) |
||
114 | |||
115 | mfsprg2 r12 |
||
116 | stw r12, 148(sp) |
||
1215 | decky | 117 | .endm |
1004 | decky | 118 | |
1277 | decky | 119 | .org 0x060 |
120 | jump_to_kernel: |
||
121 | lis r12, iret@ha |
||
122 | addi r12, r12, iret@l |
||
123 | mtlr r12 |
||
124 | |||
125 | mfmsr r12 |
||
126 | ori r12, r12, (msr_ir | msr_dr)@l |
||
127 | mtsrr1 r12 |
||
128 | |||
129 | addis sp, sp, 0x8000 |
||
130 | mr r4, sp |
||
131 | rfi |
||
132 | |||
133 | jump_to_kernel_syscall: |
||
134 | lis r12, syscall_handler@ha |
||
135 | addi r12, r12, syscall_handler@l |
||
136 | mtsrr0 r12 |
||
137 | |||
138 | lis r12, iret_syscall@ha |
||
139 | addi r12, r12, iret_syscall@l |
||
140 | mtlr r12 |
||
141 | |||
142 | mfmsr r12 |
||
143 | ori r12, r12, (msr_ir | msr_dr)@l |
||
144 | mtsrr1 r12 |
||
145 | |||
146 | addis sp, sp, 0x8000 |
||
147 | rfi |
||
148 | |||
1215 | decky | 149 | .org 0x100 |
150 | .global exc_system_reset |
||
151 | exc_system_reset: |
||
152 | b exc_system_reset |
||
153 | |||
154 | .org 0x200 |
||
155 | .global exc_machine_check |
||
156 | exc_machine_check: |
||
157 | b exc_machine_check |
||
158 | |||
159 | .org 0x300 |
||
160 | .global exc_data_storage |
||
161 | exc_data_storage: |
||
162 | CONTEXT_STORE |
||
1267 | decky | 163 | |
1277 | decky | 164 | lis r12, pht_refill@ha |
165 | addi r12, r12, pht_refill@l |
||
166 | mtsrr0 r12 |
||
1215 | decky | 167 | |
1269 | decky | 168 | li r3, 1 |
1277 | decky | 169 | b jump_to_kernel |
1215 | decky | 170 | |
171 | .org 0x400 |
||
172 | .global exc_instruction_storage |
||
173 | exc_instruction_storage: |
||
1267 | decky | 174 | CONTEXT_STORE |
175 | |||
1277 | decky | 176 | lis r12, pht_refill@ha |
177 | addi r12, r12, pht_refill@l |
||
178 | mtsrr0 r12 |
||
1267 | decky | 179 | |
1269 | decky | 180 | li r3, 0 |
1277 | decky | 181 | b jump_to_kernel |
1215 | decky | 182 | |
183 | .org 0x500 |
||
184 | .global exc_external |
||
185 | exc_external: |
||
186 | b exc_external |
||
187 | |||
188 | .org 0x600 |
||
189 | .global exc_alignment |
||
190 | exc_alignment: |
||
191 | b exc_alignment |
||
192 | |||
193 | .org 0x700 |
||
194 | .global exc_program |
||
195 | exc_program: |
||
196 | b exc_program |
||
197 | |||
198 | .org 0x800 |
||
199 | .global exc_fp_unavailable |
||
200 | exc_fp_unavailable: |
||
201 | b exc_fp_unavailable |
||
202 | |||
203 | .org 0x900 |
||
204 | .global exc_decrementer |
||
205 | exc_decrementer: |
||
206 | CONTEXT_STORE |
||
207 | |||
1277 | decky | 208 | lis r12, exc_dispatch@ha |
209 | addi r12, r12, exc_dispatch@l |
||
210 | mtsrr0 r12 |
||
1004 | decky | 211 | |
212 | li r3, 10 |
||
1277 | decky | 213 | b jump_to_kernel |
987 | decky | 214 | |
215 | .org 0xa00 |
||
216 | .global exc_reserved0 |
||
217 | exc_reserved0: |
||
218 | b exc_reserved0 |
||
219 | |||
220 | .org 0xb00 |
||
221 | .global exc_reserved1 |
||
222 | exc_reserved1: |
||
223 | b exc_reserved1 |
||
224 | |||
225 | .org 0xc00 |
||
226 | .global exc_syscall |
||
227 | exc_syscall: |
||
1277 | decky | 228 | CONTEXT_STORE |
229 | |||
230 | b jump_to_kernel_syscall |
||
987 | decky | 231 | |
232 | .org 0xd00 |
||
233 | .global exc_trace |
||
234 | exc_trace: |
||
235 | b exc_trace |