[edc89bd0] | 1 | #
|
---|
[df4ed85] | 2 | # Copyright (c) 2006 Martin Decky
|
---|
[edc89bd0] | 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>
|
---|
[c0699467] | 30 | #include <arch/msr.h>
|
---|
[91d5ad6] | 31 | #include <arch/mm/page.h>
|
---|
[edc89bd0] | 32 |
|
---|
| 33 | .section K_UNMAPPED_TEXT_START, "ax"
|
---|
| 34 |
|
---|
[613bc54] | 35 | .macro CONTEXT_STORE
|
---|
[91d5ad6] | 36 |
|
---|
[ffe276f] | 37 | # save r12 in SPRG1, backup CR in r12
|
---|
[e34a141] | 38 | # save SP in SPRG2
|
---|
[ffe276f] | 39 |
|
---|
[e34a141] | 40 | mtsprg1 r12
|
---|
[762a824] | 41 | mfcr r12
|
---|
[e34a141] | 42 | mtsprg2 sp
|
---|
[762a824] | 43 |
|
---|
| 44 | # check whether SP is in kernel
|
---|
| 45 |
|
---|
| 46 | andis. sp, sp, 0x8000
|
---|
| 47 | bne 1f
|
---|
| 48 |
|
---|
| 49 | # stack is in user-space
|
---|
| 50 |
|
---|
| 51 | mfsprg0 sp
|
---|
| 52 |
|
---|
| 53 | b 2f
|
---|
[91d5ad6] | 54 |
|
---|
[762a824] | 55 | 1:
|
---|
| 56 |
|
---|
| 57 | # stack is in kernel
|
---|
| 58 |
|
---|
[e34a141] | 59 | mfsprg2 sp
|
---|
[762a824] | 60 | subis sp, sp, 0x8000
|
---|
| 61 |
|
---|
| 62 | 2:
|
---|
| 63 |
|
---|
[826c203] | 64 | subi sp, sp, 164
|
---|
[2e2d654] | 65 | stw r0, 8(sp)
|
---|
| 66 | stw r2, 12(sp)
|
---|
| 67 | stw r3, 16(sp)
|
---|
| 68 | stw r4, 20(sp)
|
---|
| 69 | stw r5, 24(sp)
|
---|
| 70 | stw r6, 28(sp)
|
---|
| 71 | stw r7, 32(sp)
|
---|
| 72 | stw r8, 36(sp)
|
---|
| 73 | stw r9, 40(sp)
|
---|
| 74 | stw r10, 44(sp)
|
---|
| 75 | stw r11, 48(sp)
|
---|
| 76 | stw r13, 52(sp)
|
---|
| 77 | stw r14, 56(sp)
|
---|
| 78 | stw r15, 60(sp)
|
---|
| 79 | stw r16, 64(sp)
|
---|
| 80 | stw r17, 68(sp)
|
---|
| 81 | stw r18, 72(sp)
|
---|
| 82 | stw r19, 76(sp)
|
---|
| 83 | stw r20, 80(sp)
|
---|
| 84 | stw r21, 84(sp)
|
---|
| 85 | stw r22, 88(sp)
|
---|
| 86 | stw r23, 92(sp)
|
---|
| 87 | stw r24, 96(sp)
|
---|
| 88 | stw r25, 100(sp)
|
---|
| 89 | stw r26, 104(sp)
|
---|
| 90 | stw r27, 108(sp)
|
---|
| 91 | stw r28, 112(sp)
|
---|
| 92 | stw r29, 116(sp)
|
---|
| 93 | stw r30, 120(sp)
|
---|
| 94 | stw r31, 124(sp)
|
---|
| 95 |
|
---|
| 96 | stw r12, 128(sp)
|
---|
[762a824] | 97 |
|
---|
[e34a141] | 98 | mfsrr0 r12
|
---|
[2e2d654] | 99 | stw r12, 132(sp)
|
---|
[91d5ad6] | 100 |
|
---|
[e34a141] | 101 | mfsrr1 r12
|
---|
[2e2d654] | 102 | stw r12, 136(sp)
|
---|
[91d5ad6] | 103 |
|
---|
[e34a141] | 104 | mflr r12
|
---|
[2e2d654] | 105 | stw r12, 140(sp)
|
---|
[91d5ad6] | 106 |
|
---|
[e34a141] | 107 | mfctr r12
|
---|
[2e2d654] | 108 | stw r12, 144(sp)
|
---|
[91d5ad6] | 109 |
|
---|
[e34a141] | 110 | mfxer r12
|
---|
[2e2d654] | 111 | stw r12, 148(sp)
|
---|
[e34a141] | 112 |
|
---|
[826c203] | 113 | mfdar r12
|
---|
[2e2d654] | 114 | stw r12, 152(sp)
|
---|
[e34a141] | 115 |
|
---|
[826c203] | 116 | mfsprg1 r12
|
---|
[2e2d654] | 117 | stw r12, 156(sp)
|
---|
[826c203] | 118 |
|
---|
| 119 | mfsprg2 r12
|
---|
| 120 | stw r12, 160(sp)
|
---|
[613bc54] | 121 | .endm
|
---|
| 122 |
|
---|
| 123 | .org 0x100
|
---|
| 124 | .global exc_system_reset
|
---|
| 125 | exc_system_reset:
|
---|
[c782434] | 126 | CONTEXT_STORE
|
---|
| 127 |
|
---|
| 128 | li r3, 0
|
---|
| 129 | b jump_to_kernel
|
---|
[613bc54] | 130 |
|
---|
| 131 | .org 0x200
|
---|
| 132 | .global exc_machine_check
|
---|
| 133 | exc_machine_check:
|
---|
[c782434] | 134 | CONTEXT_STORE
|
---|
| 135 |
|
---|
| 136 | li r3, 1
|
---|
| 137 | b jump_to_kernel
|
---|
[613bc54] | 138 |
|
---|
| 139 | .org 0x300
|
---|
| 140 | .global exc_data_storage
|
---|
| 141 | exc_data_storage:
|
---|
| 142 | CONTEXT_STORE
|
---|
[762a824] | 143 |
|
---|
[6c3106f] | 144 | li r3, 2
|
---|
| 145 | b jump_to_kernel
|
---|
[613bc54] | 146 |
|
---|
| 147 | .org 0x400
|
---|
| 148 | .global exc_instruction_storage
|
---|
| 149 | exc_instruction_storage:
|
---|
[762a824] | 150 | CONTEXT_STORE
|
---|
| 151 |
|
---|
[6c3106f] | 152 | li r3, 3
|
---|
| 153 | b jump_to_kernel
|
---|
[613bc54] | 154 |
|
---|
| 155 | .org 0x500
|
---|
| 156 | .global exc_external
|
---|
| 157 | exc_external:
|
---|
[982f0fe] | 158 | CONTEXT_STORE
|
---|
[c782434] | 159 |
|
---|
| 160 | li r3, 4
|
---|
[982f0fe] | 161 | b jump_to_kernel
|
---|
[613bc54] | 162 |
|
---|
| 163 | .org 0x600
|
---|
| 164 | .global exc_alignment
|
---|
| 165 | exc_alignment:
|
---|
[c782434] | 166 | CONTEXT_STORE
|
---|
| 167 |
|
---|
| 168 | li r3, 5
|
---|
| 169 | b jump_to_kernel
|
---|
[613bc54] | 170 |
|
---|
| 171 | .org 0x700
|
---|
| 172 | .global exc_program
|
---|
| 173 | exc_program:
|
---|
[c782434] | 174 | CONTEXT_STORE
|
---|
| 175 |
|
---|
| 176 | li r3, 6
|
---|
| 177 | b jump_to_kernel
|
---|
[613bc54] | 178 |
|
---|
| 179 | .org 0x800
|
---|
| 180 | .global exc_fp_unavailable
|
---|
| 181 | exc_fp_unavailable:
|
---|
[c782434] | 182 | CONTEXT_STORE
|
---|
| 183 |
|
---|
| 184 | li r3, 7
|
---|
| 185 | b jump_to_kernel
|
---|
[613bc54] | 186 |
|
---|
| 187 | .org 0x900
|
---|
| 188 | .global exc_decrementer
|
---|
| 189 | exc_decrementer:
|
---|
[a33c990] | 190 | CONTEXT_STORE
|
---|
[91d5ad6] | 191 |
|
---|
[c782434] | 192 | li r3, 8
|
---|
[e34a141] | 193 | b jump_to_kernel
|
---|
[edc89bd0] | 194 |
|
---|
| 195 | .org 0xa00
|
---|
| 196 | .global exc_reserved0
|
---|
| 197 | exc_reserved0:
|
---|
[c782434] | 198 | CONTEXT_STORE
|
---|
| 199 |
|
---|
| 200 | li r3, 9
|
---|
| 201 | b jump_to_kernel
|
---|
[edc89bd0] | 202 |
|
---|
| 203 | .org 0xb00
|
---|
| 204 | .global exc_reserved1
|
---|
| 205 | exc_reserved1:
|
---|
[c782434] | 206 | CONTEXT_STORE
|
---|
| 207 |
|
---|
| 208 | li r3, 10
|
---|
| 209 | b jump_to_kernel
|
---|
[edc89bd0] | 210 |
|
---|
| 211 | .org 0xc00
|
---|
| 212 | .global exc_syscall
|
---|
| 213 | exc_syscall:
|
---|
[0867321] | 214 | CONTEXT_STORE
|
---|
[e34a141] | 215 |
|
---|
| 216 | b jump_to_kernel_syscall
|
---|
[edc89bd0] | 217 |
|
---|
| 218 | .org 0xd00
|
---|
| 219 | .global exc_trace
|
---|
| 220 | exc_trace:
|
---|
[c782434] | 221 | CONTEXT_STORE
|
---|
| 222 |
|
---|
| 223 | li r3, 12
|
---|
| 224 | b jump_to_kernel
|
---|
[898d9f8] | 225 |
|
---|
[0867321] | 226 | .org 0x1000
|
---|
| 227 | .global exc_itlb_miss
|
---|
| 228 | exc_itlb_miss:
|
---|
| 229 | CONTEXT_STORE
|
---|
| 230 |
|
---|
[6c3106f] | 231 | li r3, 13
|
---|
| 232 | b jump_to_kernel
|
---|
[0867321] | 233 |
|
---|
| 234 | .org 0x1100
|
---|
| 235 | .global exc_dtlb_miss_load
|
---|
| 236 | exc_dtlb_miss_load:
|
---|
| 237 | CONTEXT_STORE
|
---|
| 238 |
|
---|
[6c3106f] | 239 | li r3, 14
|
---|
| 240 | b jump_to_kernel
|
---|
[0867321] | 241 |
|
---|
| 242 | .org 0x1200
|
---|
| 243 | .global exc_dtlb_miss_store
|
---|
| 244 | exc_dtlb_miss_store:
|
---|
| 245 | CONTEXT_STORE
|
---|
| 246 |
|
---|
[6c3106f] | 247 | li r3, 15
|
---|
[826c203] | 248 | b jump_to_kernel
|
---|
| 249 |
|
---|
[6c3106f] | 250 | .org 0x4000
|
---|
[898d9f8] | 251 | jump_to_kernel:
|
---|
| 252 | lis r12, iret@ha
|
---|
| 253 | addi r12, r12, iret@l
|
---|
| 254 | mtlr r12
|
---|
[fbb8b2b] | 255 |
|
---|
| 256 | lis r12, exc_dispatch@ha
|
---|
| 257 | addi r12, r12, exc_dispatch@l
|
---|
| 258 | mtsrr0 r12
|
---|
| 259 |
|
---|
[898d9f8] | 260 | mfmsr r12
|
---|
[ffe276f] | 261 | ori r12, r12, (MSR_IR | MSR_DR)@l
|
---|
[898d9f8] | 262 | mtsrr1 r12
|
---|
| 263 |
|
---|
| 264 | addis sp, sp, 0x8000
|
---|
| 265 | mr r4, sp
|
---|
| 266 | addi r4, r4, 8
|
---|
| 267 |
|
---|
| 268 | rfi
|
---|
| 269 |
|
---|
| 270 | jump_to_kernel_syscall:
|
---|
| 271 | lis r12, syscall_handler@ha
|
---|
| 272 | addi r12, r12, syscall_handler@l
|
---|
| 273 | mtsrr0 r12
|
---|
| 274 |
|
---|
| 275 | lis r12, iret_syscall@ha
|
---|
| 276 | addi r12, r12, iret_syscall@l
|
---|
| 277 | mtlr r12
|
---|
[fbb8b2b] | 278 |
|
---|
[898d9f8] | 279 | mfmsr r12
|
---|
[ffe276f] | 280 | ori r12, r12, (MSR_IR | MSR_DR)@l
|
---|
[898d9f8] | 281 | mtsrr1 r12
|
---|
| 282 |
|
---|
| 283 | addis sp, sp, 0x8000
|
---|
| 284 | rfi
|
---|