[edc89bd0] | 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>
|
---|
[91d5ad6] | 30 | #include <arch/mm/page.h>
|
---|
[edc89bd0] | 31 |
|
---|
| 32 | .section K_UNMAPPED_TEXT_START, "ax"
|
---|
| 33 |
|
---|
[613bc54] | 34 | .macro CONTEXT_STORE
|
---|
[91d5ad6] | 35 |
|
---|
[e34a141] | 36 | # save R12 in SPRG1, backup CR in R12
|
---|
| 37 | # save SP in SPRG2
|
---|
[762a824] | 38 |
|
---|
[e34a141] | 39 | mtsprg1 r12
|
---|
[762a824] | 40 | mfcr r12
|
---|
[e34a141] | 41 | mtsprg2 sp
|
---|
[762a824] | 42 |
|
---|
| 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
|
---|
[91d5ad6] | 53 |
|
---|
[762a824] | 54 | 1:
|
---|
| 55 |
|
---|
| 56 | # stack is in kernel
|
---|
| 57 |
|
---|
[e34a141] | 58 | mfsprg2 sp
|
---|
[762a824] | 59 | subis sp, sp, 0x8000
|
---|
| 60 |
|
---|
| 61 | 2:
|
---|
| 62 |
|
---|
[2e2d654] | 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)
|
---|
| 94 |
|
---|
| 95 | stw r12, 128(sp)
|
---|
[762a824] | 96 |
|
---|
[e34a141] | 97 | mfsrr0 r12
|
---|
[2e2d654] | 98 | stw r12, 132(sp)
|
---|
[91d5ad6] | 99 |
|
---|
[e34a141] | 100 | mfsrr1 r12
|
---|
[2e2d654] | 101 | stw r12, 136(sp)
|
---|
[91d5ad6] | 102 |
|
---|
[e34a141] | 103 | mflr r12
|
---|
[2e2d654] | 104 | stw r12, 140(sp)
|
---|
[91d5ad6] | 105 |
|
---|
[e34a141] | 106 | mfctr r12
|
---|
[2e2d654] | 107 | stw r12, 144(sp)
|
---|
[91d5ad6] | 108 |
|
---|
[e34a141] | 109 | mfxer r12
|
---|
[2e2d654] | 110 | stw r12, 148(sp)
|
---|
[e34a141] | 111 |
|
---|
| 112 | mfsprg1 r12
|
---|
[2e2d654] | 113 | stw r12, 152(sp)
|
---|
[e34a141] | 114 |
|
---|
| 115 | mfsprg2 r12
|
---|
[2e2d654] | 116 | stw r12, 156(sp)
|
---|
[613bc54] | 117 | .endm
|
---|
| 118 |
|
---|
[e34a141] | 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
|
---|
[2e2d654] | 131 | addi r4, r4, 8
|
---|
| 132 |
|
---|
[e34a141] | 133 | rfi
|
---|
| 134 |
|
---|
| 135 | jump_to_kernel_syscall:
|
---|
| 136 | lis r12, syscall_handler@ha
|
---|
| 137 | addi r12, r12, syscall_handler@l
|
---|
| 138 | mtsrr0 r12
|
---|
| 139 |
|
---|
| 140 | lis r12, iret_syscall@ha
|
---|
| 141 | addi r12, r12, iret_syscall@l
|
---|
| 142 | mtlr r12
|
---|
| 143 |
|
---|
| 144 | mfmsr r12
|
---|
| 145 | ori r12, r12, (msr_ir | msr_dr)@l
|
---|
| 146 | mtsrr1 r12
|
---|
| 147 |
|
---|
| 148 | addis sp, sp, 0x8000
|
---|
| 149 | rfi
|
---|
| 150 |
|
---|
[613bc54] | 151 | .org 0x100
|
---|
| 152 | .global exc_system_reset
|
---|
| 153 | exc_system_reset:
|
---|
| 154 | b exc_system_reset
|
---|
| 155 |
|
---|
| 156 | .org 0x200
|
---|
| 157 | .global exc_machine_check
|
---|
| 158 | exc_machine_check:
|
---|
| 159 | b exc_machine_check
|
---|
| 160 |
|
---|
| 161 | .org 0x300
|
---|
| 162 | .global exc_data_storage
|
---|
| 163 | exc_data_storage:
|
---|
| 164 | CONTEXT_STORE
|
---|
[762a824] | 165 |
|
---|
[e34a141] | 166 | lis r12, pht_refill@ha
|
---|
| 167 | addi r12, r12, pht_refill@l
|
---|
| 168 | mtsrr0 r12
|
---|
[613bc54] | 169 |
|
---|
[9a68b34d] | 170 | li r3, 1
|
---|
[e34a141] | 171 | b jump_to_kernel
|
---|
[613bc54] | 172 |
|
---|
| 173 | .org 0x400
|
---|
| 174 | .global exc_instruction_storage
|
---|
| 175 | exc_instruction_storage:
|
---|
[762a824] | 176 | CONTEXT_STORE
|
---|
| 177 |
|
---|
[e34a141] | 178 | lis r12, pht_refill@ha
|
---|
| 179 | addi r12, r12, pht_refill@l
|
---|
| 180 | mtsrr0 r12
|
---|
[762a824] | 181 |
|
---|
[9a68b34d] | 182 | li r3, 0
|
---|
[e34a141] | 183 | b jump_to_kernel
|
---|
[613bc54] | 184 |
|
---|
| 185 | .org 0x500
|
---|
| 186 | .global exc_external
|
---|
| 187 | exc_external:
|
---|
| 188 | b exc_external
|
---|
| 189 |
|
---|
| 190 | .org 0x600
|
---|
| 191 | .global exc_alignment
|
---|
| 192 | exc_alignment:
|
---|
| 193 | b exc_alignment
|
---|
| 194 |
|
---|
| 195 | .org 0x700
|
---|
| 196 | .global exc_program
|
---|
| 197 | exc_program:
|
---|
| 198 | b exc_program
|
---|
| 199 |
|
---|
| 200 | .org 0x800
|
---|
| 201 | .global exc_fp_unavailable
|
---|
| 202 | exc_fp_unavailable:
|
---|
| 203 | b exc_fp_unavailable
|
---|
| 204 |
|
---|
| 205 | .org 0x900
|
---|
| 206 | .global exc_decrementer
|
---|
| 207 | exc_decrementer:
|
---|
[a33c990] | 208 | CONTEXT_STORE
|
---|
[91d5ad6] | 209 |
|
---|
[e34a141] | 210 | lis r12, exc_dispatch@ha
|
---|
| 211 | addi r12, r12, exc_dispatch@l
|
---|
| 212 | mtsrr0 r12
|
---|
[91d5ad6] | 213 |
|
---|
| 214 | li r3, 10
|
---|
[e34a141] | 215 | b jump_to_kernel
|
---|
[edc89bd0] | 216 |
|
---|
| 217 | .org 0xa00
|
---|
| 218 | .global exc_reserved0
|
---|
| 219 | exc_reserved0:
|
---|
| 220 | b exc_reserved0
|
---|
| 221 |
|
---|
| 222 | .org 0xb00
|
---|
| 223 | .global exc_reserved1
|
---|
| 224 | exc_reserved1:
|
---|
| 225 | b exc_reserved1
|
---|
| 226 |
|
---|
| 227 | .org 0xc00
|
---|
| 228 | .global exc_syscall
|
---|
| 229 | exc_syscall:
|
---|
[e34a141] | 230 | CONTEXT_STORE
|
---|
| 231 |
|
---|
| 232 | b jump_to_kernel_syscall
|
---|
[edc89bd0] | 233 |
|
---|
| 234 | .org 0xd00
|
---|
| 235 | .global exc_trace
|
---|
| 236 | exc_trace:
|
---|
| 237 | b exc_trace
|
---|