Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef __HEAD_32_H__ |
| 3 | #define __HEAD_32_H__ |
| 4 | |
| 5 | #include <asm/ptrace.h> /* for STACK_FRAME_REGS_MARKER */ |
| 6 | |
| 7 | /* |
| 8 | * Exception entry code. This code runs with address translation |
| 9 | * turned off, i.e. using physical addresses. |
| 10 | * We assume sprg3 has the physical address of the current |
| 11 | * task's thread_struct. |
| 12 | */ |
Christophe Leroy | 719e7e2 | 2021-03-12 12:50:38 +0000 | [diff] [blame] | 13 | .macro EXCEPTION_PROLOG trapno name handle_dar_dsisr=0 |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 14 | EXCEPTION_PROLOG_0 handle_dar_dsisr=\handle_dar_dsisr |
Christophe Leroy | 1f1c4d0 | 2019-12-21 08:32:23 +0000 | [diff] [blame] | 15 | EXCEPTION_PROLOG_1 |
Christophe Leroy | 719e7e2 | 2021-03-12 12:50:38 +0000 | [diff] [blame] | 16 | EXCEPTION_PROLOG_2 \trapno \name handle_dar_dsisr=\handle_dar_dsisr |
Christophe Leroy | 1f1c4d0 | 2019-12-21 08:32:23 +0000 | [diff] [blame] | 17 | .endm |
| 18 | |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 19 | .macro EXCEPTION_PROLOG_0 handle_dar_dsisr=0 |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 20 | mtspr SPRN_SPRG_SCRATCH0,r10 |
| 21 | mtspr SPRN_SPRG_SCRATCH1,r11 |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 22 | mfspr r10, SPRN_SPRG_THREAD |
| 23 | .if \handle_dar_dsisr |
Christophe Leroy | 0512aad | 2021-03-12 12:50:16 +0000 | [diff] [blame] | 24 | #ifdef CONFIG_40x |
| 25 | mfspr r11, SPRN_DEAR |
| 26 | #else |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 27 | mfspr r11, SPRN_DAR |
Christophe Leroy | 0512aad | 2021-03-12 12:50:16 +0000 | [diff] [blame] | 28 | #endif |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 29 | stw r11, DAR(r10) |
Christophe Leroy | 0512aad | 2021-03-12 12:50:16 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_40x |
| 31 | mfspr r11, SPRN_ESR |
| 32 | #else |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 33 | mfspr r11, SPRN_DSISR |
Christophe Leroy | 0512aad | 2021-03-12 12:50:16 +0000 | [diff] [blame] | 34 | #endif |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 35 | stw r11, DSISR(r10) |
| 36 | .endif |
| 37 | mfspr r11, SPRN_SRR0 |
| 38 | stw r11, SRR0(r10) |
Christophe Leroy | 5ae8fab | 2019-12-21 08:32:25 +0000 | [diff] [blame] | 39 | mfspr r11, SPRN_SRR1 /* check whether user or kernel */ |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 40 | stw r11, SRR1(r10) |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 41 | mfcr r10 |
Christophe Leroy | 5ae8fab | 2019-12-21 08:32:25 +0000 | [diff] [blame] | 42 | andi. r11, r11, MSR_PR |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 43 | .endm |
| 44 | |
Christophe Leroy | 7aa8dd6 | 2021-03-12 12:50:22 +0000 | [diff] [blame] | 45 | .macro EXCEPTION_PROLOG_1 |
Christophe Leroy | d2e0060 | 2020-11-25 07:10:53 +0000 | [diff] [blame] | 46 | mtspr SPRN_SPRG_SCRATCH2,r1 |
Christophe Leroy | da7bb43 | 2020-09-07 13:42:10 +0000 | [diff] [blame] | 47 | subi r1, r1, INT_FRAME_SIZE /* use r1 if kernel */ |
| 48 | beq 1f |
| 49 | mfspr r1,SPRN_SPRG_THREAD |
| 50 | lwz r1,TASK_STACK-THREAD(r1) |
| 51 | addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE |
Christophe Leroy | 6285f9c | 2020-11-25 07:10:51 +0000 | [diff] [blame] | 52 | 1: |
Christophe Leroy | 7aa8dd6 | 2021-03-12 12:50:22 +0000 | [diff] [blame] | 53 | #ifdef CONFIG_VMAP_STACK |
Christophe Leroy | 3642eb2 | 2021-02-08 07:17:40 +0000 | [diff] [blame] | 54 | mtcrf 0x3f, r1 |
Christophe Leroy | 5b5e5bc | 2021-03-12 12:50:27 +0000 | [diff] [blame] | 55 | bt 32 - THREAD_ALIGN_SHIFT, vmap_stack_overflow |
Christophe Leroy | 3978eb7 | 2019-12-21 08:32:29 +0000 | [diff] [blame] | 56 | #endif |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 57 | .endm |
| 58 | |
Christophe Leroy | 719e7e2 | 2021-03-12 12:50:38 +0000 | [diff] [blame] | 59 | .macro EXCEPTION_PROLOG_2 trapno name handle_dar_dsisr=0 |
Christophe Leroy | 5b1c9a0 | 2021-03-12 12:50:23 +0000 | [diff] [blame] | 60 | #ifdef CONFIG_PPC_8xx |
| 61 | .if \handle_dar_dsisr |
| 62 | li r11, RPN_PATTERN |
| 63 | mtspr SPRN_DAR, r11 /* Tag DAR, to be used in DTLB Error */ |
| 64 | .endif |
| 65 | #endif |
Christophe Leroy | 9b6150f | 2021-03-12 12:50:24 +0000 | [diff] [blame] | 66 | LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~MSR_RI) /* re-enable MMU */ |
| 67 | mtspr SPRN_SRR1, r11 |
| 68 | lis r11, 1f@h |
| 69 | ori r11, r11, 1f@l |
| 70 | mtspr SPRN_SRR0, r11 |
Christophe Leroy | d2e0060 | 2020-11-25 07:10:53 +0000 | [diff] [blame] | 71 | mfspr r11, SPRN_SPRG_SCRATCH2 |
Christophe Leroy | 9b6150f | 2021-03-12 12:50:24 +0000 | [diff] [blame] | 72 | rfi |
Christophe Leroy | dc13b88 | 2021-03-12 12:50:29 +0000 | [diff] [blame] | 73 | |
| 74 | .text |
Christophe Leroy | 8f844c0 | 2021-03-12 12:50:30 +0000 | [diff] [blame] | 75 | \name\()_virt: |
Christophe Leroy | 9b6150f | 2021-03-12 12:50:24 +0000 | [diff] [blame] | 76 | 1: |
Christophe Leroy | da7bb43 | 2020-09-07 13:42:10 +0000 | [diff] [blame] | 77 | stw r11,GPR1(r1) |
| 78 | stw r11,0(r1) |
| 79 | mr r11, r1 |
Christophe Leroy | d2e0060 | 2020-11-25 07:10:53 +0000 | [diff] [blame] | 80 | stw r10,_CCR(r11) /* save registers */ |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 81 | stw r12,GPR12(r11) |
| 82 | stw r9,GPR9(r11) |
Christophe Leroy | d2e0060 | 2020-11-25 07:10:53 +0000 | [diff] [blame] | 83 | mfspr r10,SPRN_SPRG_SCRATCH0 |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 84 | mfspr r12,SPRN_SPRG_SCRATCH1 |
Christophe Leroy | d2e0060 | 2020-11-25 07:10:53 +0000 | [diff] [blame] | 85 | stw r10,GPR10(r11) |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 86 | stw r12,GPR11(r11) |
| 87 | mflr r10 |
| 88 | stw r10,_LINK(r11) |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 89 | mfspr r12, SPRN_SPRG_THREAD |
| 90 | tovirt(r12, r12) |
| 91 | .if \handle_dar_dsisr |
| 92 | lwz r10, DAR(r12) |
| 93 | stw r10, _DAR(r11) |
| 94 | lwz r10, DSISR(r12) |
| 95 | stw r10, _DSISR(r11) |
| 96 | .endif |
| 97 | lwz r9, SRR1(r12) |
| 98 | lwz r12, SRR0(r12) |
Christophe Leroy | 90f204b | 2019-04-30 12:38:56 +0000 | [diff] [blame] | 99 | #ifdef CONFIG_40x |
| 100 | rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ |
Christophe Leroy | e464d92 | 2021-03-12 12:50:20 +0000 | [diff] [blame] | 101 | #elif defined(CONFIG_PPC_8xx) |
| 102 | mtspr SPRN_EID, r2 /* Set MSR_RI */ |
Christophe Leroy | 90f204b | 2019-04-30 12:38:56 +0000 | [diff] [blame] | 103 | #else |
Christophe Leroy | 9b6150f | 2021-03-12 12:50:24 +0000 | [diff] [blame] | 104 | li r10, MSR_KERNEL /* can take exceptions */ |
Christophe Leroy | 39bccfd | 2019-12-21 08:32:22 +0000 | [diff] [blame] | 105 | mtmsr r10 /* (except for mach check in rtas) */ |
Christophe Leroy | 90f204b | 2019-04-30 12:38:56 +0000 | [diff] [blame] | 106 | #endif |
Christophe Leroy | a305597 | 2021-03-12 12:50:43 +0000 | [diff] [blame] | 107 | COMMON_EXCEPTION_PROLOG_END \trapno |
| 108 | _ASM_NOKPROBE_SYMBOL(\name\()_virt) |
| 109 | .endm |
| 110 | |
| 111 | .macro COMMON_EXCEPTION_PROLOG_END trapno |
| 112 | stw r0,GPR0(r1) |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 113 | lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ |
| 114 | addi r10,r10,STACK_FRAME_REGS_MARKER@l |
Christophe Leroy | a305597 | 2021-03-12 12:50:43 +0000 | [diff] [blame] | 115 | stw r10,8(r1) |
Christophe Leroy | 719e7e2 | 2021-03-12 12:50:38 +0000 | [diff] [blame] | 116 | li r10, \trapno |
Christophe Leroy | a305597 | 2021-03-12 12:50:43 +0000 | [diff] [blame] | 117 | stw r10,_TRAP(r1) |
| 118 | SAVE_4GPRS(3, r1) |
| 119 | SAVE_2GPRS(7, r1) |
Christophe Leroy | 16db543 | 2021-03-12 12:50:44 +0000 | [diff] [blame] | 120 | SAVE_NVGPRS(r1) |
| 121 | stw r2,GPR2(r1) |
| 122 | stw r12,_NIP(r1) |
| 123 | stw r9,_MSR(r1) |
| 124 | mfctr r10 |
| 125 | mfspr r2,SPRN_SPRG_THREAD |
| 126 | stw r10,_CTR(r1) |
| 127 | tovirt(r2, r2) |
| 128 | mfspr r10,SPRN_XER |
| 129 | addi r2, r2, -THREAD |
| 130 | stw r10,_XER(r1) |
| 131 | addi r3,r1,STACK_FRAME_OVERHEAD |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 132 | .endm |
| 133 | |
Christophe Leroy | bce4c26 | 2021-03-12 12:50:39 +0000 | [diff] [blame] | 134 | .macro prepare_transfer_to_handler |
Christophe Leroy | a2b3e09 | 2021-03-12 12:50:46 +0000 | [diff] [blame^] | 135 | #ifdef CONFIG_PPC_BOOK3S_32 |
Christophe Leroy | bce4c26 | 2021-03-12 12:50:39 +0000 | [diff] [blame] | 136 | bl prepare_transfer_to_handler |
Christophe Leroy | a2b3e09 | 2021-03-12 12:50:46 +0000 | [diff] [blame^] | 137 | #endif |
Christophe Leroy | bce4c26 | 2021-03-12 12:50:39 +0000 | [diff] [blame] | 138 | .endm |
| 139 | |
Christophe Leroy | b86fb88 | 2019-04-30 12:39:02 +0000 | [diff] [blame] | 140 | .macro SYSCALL_ENTRY trapno |
Christophe Leroy | 9e27086 | 2020-01-31 11:34:54 +0000 | [diff] [blame] | 141 | mfspr r9, SPRN_SRR1 |
Christophe Leroy | 2c59e51 | 2021-02-08 15:10:23 +0000 | [diff] [blame] | 142 | mfspr r10, SPRN_SRR0 |
Christophe Leroy | 2c59e51 | 2021-02-08 15:10:23 +0000 | [diff] [blame] | 143 | LOAD_REG_IMMEDIATE(r11, MSR_KERNEL) /* can take exceptions */ |
| 144 | lis r12, 1f@h |
| 145 | ori r12, r12, 1f@l |
| 146 | mtspr SPRN_SRR1, r11 |
| 147 | mtspr SPRN_SRR0, r12 |
| 148 | mfspr r12,SPRN_SPRG_THREAD |
Christophe Leroy | d5c2439 | 2020-12-21 06:18:03 +0000 | [diff] [blame] | 149 | mr r11, r1 |
| 150 | lwz r1,TASK_STACK-THREAD(r12) |
Christophe Leroy | 2c59e51 | 2021-02-08 15:10:23 +0000 | [diff] [blame] | 151 | tovirt(r12, r12) |
Christophe Leroy | d5c2439 | 2020-12-21 06:18:03 +0000 | [diff] [blame] | 152 | addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE |
Christophe Leroy | 76249dd | 2021-02-08 15:10:22 +0000 | [diff] [blame] | 153 | rfi |
| 154 | 1: |
Christophe Leroy | d5c2439 | 2020-12-21 06:18:03 +0000 | [diff] [blame] | 155 | stw r11,GPR1(r1) |
| 156 | stw r11,0(r1) |
| 157 | mr r11, r1 |
Christophe Leroy | 2c59e51 | 2021-02-08 15:10:23 +0000 | [diff] [blame] | 158 | stw r10,_NIP(r11) |
Christophe Leroy | 9e27086 | 2020-01-31 11:34:54 +0000 | [diff] [blame] | 159 | mflr r10 |
| 160 | stw r10, _LINK(r11) |
Christophe Leroy | c06f0af | 2020-01-31 11:34:55 +0000 | [diff] [blame] | 161 | mfcr r10 |
| 162 | rlwinm r10,r10,0,4,2 /* Clear SO bit in CR */ |
| 163 | stw r10,_CCR(r11) /* save registers */ |
Christophe Leroy | b86fb88 | 2019-04-30 12:39:02 +0000 | [diff] [blame] | 164 | #ifdef CONFIG_40x |
| 165 | rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ |
Christophe Leroy | b86fb88 | 2019-04-30 12:39:02 +0000 | [diff] [blame] | 166 | #endif |
| 167 | lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ |
| 168 | stw r2,GPR2(r11) |
| 169 | addi r10,r10,STACK_FRAME_REGS_MARKER@l |
| 170 | stw r9,_MSR(r11) |
Christophe Leroy | fbcee2e | 2021-02-08 15:10:32 +0000 | [diff] [blame] | 171 | li r2, \trapno |
Christophe Leroy | b86fb88 | 2019-04-30 12:39:02 +0000 | [diff] [blame] | 172 | stw r10,8(r11) |
| 173 | stw r2,_TRAP(r11) |
| 174 | SAVE_GPR(0, r11) |
| 175 | SAVE_4GPRS(3, r11) |
| 176 | SAVE_2GPRS(7, r11) |
Christophe Leroy | b86fb88 | 2019-04-30 12:39:02 +0000 | [diff] [blame] | 177 | addi r2,r12,-THREAD |
Christophe Leroy | 76249dd | 2021-02-08 15:10:22 +0000 | [diff] [blame] | 178 | b transfer_to_syscall /* jump to handler */ |
Christophe Leroy | b86fb88 | 2019-04-30 12:39:02 +0000 | [diff] [blame] | 179 | .endm |
| 180 | |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 181 | /* |
| 182 | * Note: code which follows this uses cr0.eq (set if from kernel), |
| 183 | * r11, r12 (SRR0), and r9 (SRR1). |
| 184 | * |
| 185 | * Note2: once we have set r1 we are in a position to take exceptions |
| 186 | * again, and we could thus set MSR:RI at that point. |
| 187 | */ |
| 188 | |
| 189 | /* |
| 190 | * Exception vectors. |
| 191 | */ |
| 192 | #ifdef CONFIG_PPC_BOOK3S |
| 193 | #define START_EXCEPTION(n, label) \ |
Christophe Leroy | dc13b88 | 2021-03-12 12:50:29 +0000 | [diff] [blame] | 194 | __HEAD; \ |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 195 | . = n; \ |
| 196 | DO_KVM n; \ |
| 197 | label: |
| 198 | |
| 199 | #else |
| 200 | #define START_EXCEPTION(n, label) \ |
Christophe Leroy | dc13b88 | 2021-03-12 12:50:29 +0000 | [diff] [blame] | 201 | __HEAD; \ |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 202 | . = n; \ |
| 203 | label: |
| 204 | |
| 205 | #endif |
| 206 | |
Christophe Leroy | acc142b | 2021-03-12 12:50:42 +0000 | [diff] [blame] | 207 | #define EXCEPTION(n, label, hdlr) \ |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 208 | START_EXCEPTION(n, label) \ |
Christophe Leroy | 719e7e2 | 2021-03-12 12:50:38 +0000 | [diff] [blame] | 209 | EXCEPTION_PROLOG n label; \ |
Christophe Leroy | 4c0104a | 2021-03-12 12:50:41 +0000 | [diff] [blame] | 210 | prepare_transfer_to_handler; \ |
| 211 | bl hdlr; \ |
| 212 | b interrupt_return |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 213 | |
Christophe Leroy | 3978eb7 | 2019-12-21 08:32:29 +0000 | [diff] [blame] | 214 | .macro vmap_stack_overflow_exception |
Christophe Leroy | dc13b88 | 2021-03-12 12:50:29 +0000 | [diff] [blame] | 215 | __HEAD |
Christophe Leroy | 5b5e5bc | 2021-03-12 12:50:27 +0000 | [diff] [blame] | 216 | vmap_stack_overflow: |
Christophe Leroy | 3978eb7 | 2019-12-21 08:32:29 +0000 | [diff] [blame] | 217 | #ifdef CONFIG_SMP |
Christophe Leroy | da7bb43 | 2020-09-07 13:42:10 +0000 | [diff] [blame] | 218 | mfspr r1, SPRN_SPRG_THREAD |
| 219 | lwz r1, TASK_CPU - THREAD(r1) |
| 220 | slwi r1, r1, 3 |
| 221 | addis r1, r1, emergency_ctx@ha |
Christophe Leroy | 3978eb7 | 2019-12-21 08:32:29 +0000 | [diff] [blame] | 222 | #else |
Christophe Leroy | da7bb43 | 2020-09-07 13:42:10 +0000 | [diff] [blame] | 223 | lis r1, emergency_ctx@ha |
Christophe Leroy | 3978eb7 | 2019-12-21 08:32:29 +0000 | [diff] [blame] | 224 | #endif |
Christophe Leroy | da7bb43 | 2020-09-07 13:42:10 +0000 | [diff] [blame] | 225 | lwz r1, emergency_ctx@l(r1) |
Christophe Leroy | a4719f5 | 2021-03-12 12:50:25 +0000 | [diff] [blame] | 226 | addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE |
Christophe Leroy | 719e7e2 | 2021-03-12 12:50:38 +0000 | [diff] [blame] | 227 | EXCEPTION_PROLOG_2 0 vmap_stack_overflow |
Christophe Leroy | 4c0104a | 2021-03-12 12:50:41 +0000 | [diff] [blame] | 228 | prepare_transfer_to_handler |
| 229 | bl stack_overflow_exception |
| 230 | b interrupt_return |
Christophe Leroy | 3978eb7 | 2019-12-21 08:32:29 +0000 | [diff] [blame] | 231 | .endm |
| 232 | |
Christophe Leroy | 8a23fdec | 2019-04-30 12:38:50 +0000 | [diff] [blame] | 233 | #endif /* __HEAD_32_H__ */ |