[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)
|
---|
[3ab2d1e] | 121 |
|
---|
| 122 | li r12, 0
|
---|
| 123 | stw r12, 0(sp)
|
---|
[613bc54] | 124 | .endm
|
---|
| 125 |
|
---|
| 126 | .org 0x100
|
---|
| 127 | .global exc_system_reset
|
---|
| 128 | exc_system_reset:
|
---|
[c782434] | 129 | CONTEXT_STORE
|
---|
| 130 |
|
---|
| 131 | li r3, 0
|
---|
| 132 | b jump_to_kernel
|
---|
[613bc54] | 133 |
|
---|
| 134 | .org 0x200
|
---|
| 135 | .global exc_machine_check
|
---|
| 136 | exc_machine_check:
|
---|
[c782434] | 137 | CONTEXT_STORE
|
---|
| 138 |
|
---|
| 139 | li r3, 1
|
---|
| 140 | b jump_to_kernel
|
---|
[613bc54] | 141 |
|
---|
| 142 | .org 0x300
|
---|
| 143 | .global exc_data_storage
|
---|
| 144 | exc_data_storage:
|
---|
| 145 | CONTEXT_STORE
|
---|
[762a824] | 146 |
|
---|
[6c3106f] | 147 | li r3, 2
|
---|
| 148 | b jump_to_kernel
|
---|
[613bc54] | 149 |
|
---|
| 150 | .org 0x400
|
---|
| 151 | .global exc_instruction_storage
|
---|
| 152 | exc_instruction_storage:
|
---|
[762a824] | 153 | CONTEXT_STORE
|
---|
| 154 |
|
---|
[6c3106f] | 155 | li r3, 3
|
---|
| 156 | b jump_to_kernel
|
---|
[613bc54] | 157 |
|
---|
| 158 | .org 0x500
|
---|
| 159 | .global exc_external
|
---|
| 160 | exc_external:
|
---|
[982f0fe] | 161 | CONTEXT_STORE
|
---|
[c782434] | 162 |
|
---|
| 163 | li r3, 4
|
---|
[982f0fe] | 164 | b jump_to_kernel
|
---|
[613bc54] | 165 |
|
---|
| 166 | .org 0x600
|
---|
| 167 | .global exc_alignment
|
---|
| 168 | exc_alignment:
|
---|
[c782434] | 169 | CONTEXT_STORE
|
---|
| 170 |
|
---|
| 171 | li r3, 5
|
---|
| 172 | b jump_to_kernel
|
---|
[613bc54] | 173 |
|
---|
| 174 | .org 0x700
|
---|
| 175 | .global exc_program
|
---|
| 176 | exc_program:
|
---|
[c782434] | 177 | CONTEXT_STORE
|
---|
| 178 |
|
---|
| 179 | li r3, 6
|
---|
| 180 | b jump_to_kernel
|
---|
[613bc54] | 181 |
|
---|
| 182 | .org 0x800
|
---|
| 183 | .global exc_fp_unavailable
|
---|
| 184 | exc_fp_unavailable:
|
---|
[c782434] | 185 | CONTEXT_STORE
|
---|
| 186 |
|
---|
| 187 | li r3, 7
|
---|
| 188 | b jump_to_kernel
|
---|
[613bc54] | 189 |
|
---|
| 190 | .org 0x900
|
---|
| 191 | .global exc_decrementer
|
---|
| 192 | exc_decrementer:
|
---|
[a33c990] | 193 | CONTEXT_STORE
|
---|
[91d5ad6] | 194 |
|
---|
[c782434] | 195 | li r3, 8
|
---|
[e34a141] | 196 | b jump_to_kernel
|
---|
[edc89bd0] | 197 |
|
---|
| 198 | .org 0xa00
|
---|
| 199 | .global exc_reserved0
|
---|
| 200 | exc_reserved0:
|
---|
[c782434] | 201 | CONTEXT_STORE
|
---|
| 202 |
|
---|
| 203 | li r3, 9
|
---|
| 204 | b jump_to_kernel
|
---|
[edc89bd0] | 205 |
|
---|
| 206 | .org 0xb00
|
---|
| 207 | .global exc_reserved1
|
---|
| 208 | exc_reserved1:
|
---|
[c782434] | 209 | CONTEXT_STORE
|
---|
| 210 |
|
---|
| 211 | li r3, 10
|
---|
| 212 | b jump_to_kernel
|
---|
[edc89bd0] | 213 |
|
---|
| 214 | .org 0xc00
|
---|
| 215 | .global exc_syscall
|
---|
| 216 | exc_syscall:
|
---|
[0867321] | 217 | CONTEXT_STORE
|
---|
[e34a141] | 218 |
|
---|
| 219 | b jump_to_kernel_syscall
|
---|
[edc89bd0] | 220 |
|
---|
| 221 | .org 0xd00
|
---|
| 222 | .global exc_trace
|
---|
| 223 | exc_trace:
|
---|
[c782434] | 224 | CONTEXT_STORE
|
---|
| 225 |
|
---|
| 226 | li r3, 12
|
---|
| 227 | b jump_to_kernel
|
---|
[898d9f8] | 228 |
|
---|
[0867321] | 229 | .org 0x1000
|
---|
| 230 | .global exc_itlb_miss
|
---|
| 231 | exc_itlb_miss:
|
---|
| 232 | CONTEXT_STORE
|
---|
| 233 |
|
---|
[6c3106f] | 234 | li r3, 13
|
---|
| 235 | b jump_to_kernel
|
---|
[0867321] | 236 |
|
---|
| 237 | .org 0x1100
|
---|
| 238 | .global exc_dtlb_miss_load
|
---|
| 239 | exc_dtlb_miss_load:
|
---|
| 240 | CONTEXT_STORE
|
---|
| 241 |
|
---|
[6c3106f] | 242 | li r3, 14
|
---|
| 243 | b jump_to_kernel
|
---|
[0867321] | 244 |
|
---|
| 245 | .org 0x1200
|
---|
| 246 | .global exc_dtlb_miss_store
|
---|
| 247 | exc_dtlb_miss_store:
|
---|
| 248 | CONTEXT_STORE
|
---|
| 249 |
|
---|
[6c3106f] | 250 | li r3, 15
|
---|
[826c203] | 251 | b jump_to_kernel
|
---|
| 252 |
|
---|
[6c3106f] | 253 | .org 0x4000
|
---|
[898d9f8] | 254 | jump_to_kernel:
|
---|
| 255 | lis r12, iret@ha
|
---|
| 256 | addi r12, r12, iret@l
|
---|
| 257 | mtlr r12
|
---|
[fbb8b2b] | 258 |
|
---|
| 259 | lis r12, exc_dispatch@ha
|
---|
| 260 | addi r12, r12, exc_dispatch@l
|
---|
| 261 | mtsrr0 r12
|
---|
| 262 |
|
---|
[df7f5cea] | 263 | mfsrr1 r5
|
---|
| 264 | andi. r5, r5, MSR_FP
|
---|
[898d9f8] | 265 | mfmsr r12
|
---|
[df7f5cea] | 266 | or r12, r12, r5 # Propagate MSR_FP from SRR1 to MSR
|
---|
[ffe276f] | 267 | ori r12, r12, (MSR_IR | MSR_DR)@l
|
---|
[898d9f8] | 268 | mtsrr1 r12
|
---|
| 269 |
|
---|
| 270 | addis sp, sp, 0x8000
|
---|
| 271 | mr r4, sp
|
---|
| 272 | addi r4, r4, 8
|
---|
| 273 |
|
---|
| 274 | rfi
|
---|
| 275 |
|
---|
| 276 | jump_to_kernel_syscall:
|
---|
| 277 | lis r12, syscall_handler@ha
|
---|
| 278 | addi r12, r12, syscall_handler@l
|
---|
| 279 | mtsrr0 r12
|
---|
| 280 |
|
---|
| 281 | lis r12, iret_syscall@ha
|
---|
| 282 | addi r12, r12, iret_syscall@l
|
---|
| 283 | mtlr r12
|
---|
[df7f5cea] | 284 |
|
---|
| 285 | mfsrr1 r0
|
---|
| 286 | andi. r0, r0, MSR_FP
|
---|
[898d9f8] | 287 | mfmsr r12
|
---|
[df7f5cea] | 288 | or r12, r12, r0 # Propagate MSR_FP from SRR1 to MSR
|
---|
[ffe276f] | 289 | ori r12, r12, (MSR_IR | MSR_DR)@l
|
---|
[898d9f8] | 290 | mtsrr1 r12
|
---|
| 291 |
|
---|
| 292 | addis sp, sp, 0x8000
|
---|
| 293 | rfi
|
---|