18a23fdecSChristophe Leroy /* SPDX-License-Identifier: GPL-2.0 */ 28a23fdecSChristophe Leroy #ifndef __HEAD_32_H__ 38a23fdecSChristophe Leroy #define __HEAD_32_H__ 48a23fdecSChristophe Leroy 58a23fdecSChristophe Leroy #include <asm/ptrace.h> /* for STACK_FRAME_REGS_MARKER */ 68a23fdecSChristophe Leroy 78a23fdecSChristophe Leroy /* 88a23fdecSChristophe Leroy * Exception entry code. This code runs with address translation 98a23fdecSChristophe Leroy * turned off, i.e. using physical addresses. 108a23fdecSChristophe Leroy * We assume sprg3 has the physical address of the current 118a23fdecSChristophe Leroy * task's thread_struct. 128a23fdecSChristophe Leroy */ 13719e7e21SChristophe Leroy .macro EXCEPTION_PROLOG trapno name handle_dar_dsisr=0 1402847487SChristophe Leroy EXCEPTION_PROLOG_0 handle_dar_dsisr=\handle_dar_dsisr 151f1c4d01SChristophe Leroy EXCEPTION_PROLOG_1 16719e7e21SChristophe Leroy EXCEPTION_PROLOG_2 \trapno \name handle_dar_dsisr=\handle_dar_dsisr 171f1c4d01SChristophe Leroy .endm 181f1c4d01SChristophe Leroy 1902847487SChristophe Leroy .macro EXCEPTION_PROLOG_0 handle_dar_dsisr=0 208a23fdecSChristophe Leroy mtspr SPRN_SPRG_SCRATCH0,r10 218a23fdecSChristophe Leroy mtspr SPRN_SPRG_SCRATCH1,r11 2202847487SChristophe Leroy mfspr r10, SPRN_SPRG_THREAD 2302847487SChristophe Leroy .if \handle_dar_dsisr 240512aaddSChristophe Leroy #ifdef CONFIG_40x 250512aaddSChristophe Leroy mfspr r11, SPRN_DEAR 260512aaddSChristophe Leroy #else 2702847487SChristophe Leroy mfspr r11, SPRN_DAR 280512aaddSChristophe Leroy #endif 2902847487SChristophe Leroy stw r11, DAR(r10) 300512aaddSChristophe Leroy #ifdef CONFIG_40x 310512aaddSChristophe Leroy mfspr r11, SPRN_ESR 320512aaddSChristophe Leroy #else 3302847487SChristophe Leroy mfspr r11, SPRN_DSISR 340512aaddSChristophe Leroy #endif 3502847487SChristophe Leroy stw r11, DSISR(r10) 3602847487SChristophe Leroy .endif 3702847487SChristophe Leroy mfspr r11, SPRN_SRR0 3802847487SChristophe Leroy stw r11, SRR0(r10) 395ae8fabcSChristophe Leroy mfspr r11, SPRN_SRR1 /* check whether user or kernel */ 4002847487SChristophe Leroy stw r11, SRR1(r10) 418a23fdecSChristophe Leroy mfcr r10 425ae8fabcSChristophe Leroy andi. r11, r11, MSR_PR 438a23fdecSChristophe Leroy .endm 448a23fdecSChristophe Leroy 457aa8dd67SChristophe Leroy .macro EXCEPTION_PROLOG_1 46d2e00603SChristophe Leroy mtspr SPRN_SPRG_SCRATCH2,r1 47da7bb43aSChristophe Leroy subi r1, r1, INT_FRAME_SIZE /* use r1 if kernel */ 48da7bb43aSChristophe Leroy beq 1f 49da7bb43aSChristophe Leroy mfspr r1,SPRN_SPRG_THREAD 50da7bb43aSChristophe Leroy lwz r1,TASK_STACK-THREAD(r1) 51da7bb43aSChristophe Leroy addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE 526285f9cfSChristophe Leroy 1: 537aa8dd67SChristophe Leroy #ifdef CONFIG_VMAP_STACK 543642eb21SChristophe Leroy mtcrf 0x3f, r1 555b5e5bc5SChristophe Leroy bt 32 - THREAD_ALIGN_SHIFT, vmap_stack_overflow 563978eb78SChristophe Leroy #endif 578a23fdecSChristophe Leroy .endm 588a23fdecSChristophe Leroy 59719e7e21SChristophe Leroy .macro EXCEPTION_PROLOG_2 trapno name handle_dar_dsisr=0 605b1c9a0dSChristophe Leroy #ifdef CONFIG_PPC_8xx 615b1c9a0dSChristophe Leroy .if \handle_dar_dsisr 625b1c9a0dSChristophe Leroy li r11, RPN_PATTERN 635b1c9a0dSChristophe Leroy mtspr SPRN_DAR, r11 /* Tag DAR, to be used in DTLB Error */ 645b1c9a0dSChristophe Leroy .endif 655b1c9a0dSChristophe Leroy #endif 669b6150fbSChristophe Leroy LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~MSR_RI) /* re-enable MMU */ 679b6150fbSChristophe Leroy mtspr SPRN_SRR1, r11 689b6150fbSChristophe Leroy lis r11, 1f@h 699b6150fbSChristophe Leroy ori r11, r11, 1f@l 709b6150fbSChristophe Leroy mtspr SPRN_SRR0, r11 71d2e00603SChristophe Leroy mfspr r11, SPRN_SPRG_SCRATCH2 729b6150fbSChristophe Leroy rfi 73dc13b889SChristophe Leroy 74dc13b889SChristophe Leroy .text 758f844c06SChristophe Leroy \name\()_virt: 769b6150fbSChristophe Leroy 1: 77da7bb43aSChristophe Leroy stw r11,GPR1(r1) 78da7bb43aSChristophe Leroy stw r11,0(r1) 79da7bb43aSChristophe Leroy mr r11, r1 80d2e00603SChristophe Leroy stw r10,_CCR(r11) /* save registers */ 818a23fdecSChristophe Leroy stw r12,GPR12(r11) 828a23fdecSChristophe Leroy stw r9,GPR9(r11) 83d2e00603SChristophe Leroy mfspr r10,SPRN_SPRG_SCRATCH0 848a23fdecSChristophe Leroy mfspr r12,SPRN_SPRG_SCRATCH1 85d2e00603SChristophe Leroy stw r10,GPR10(r11) 868a23fdecSChristophe Leroy stw r12,GPR11(r11) 878a23fdecSChristophe Leroy mflr r10 888a23fdecSChristophe Leroy stw r10,_LINK(r11) 8902847487SChristophe Leroy mfspr r12, SPRN_SPRG_THREAD 9002847487SChristophe Leroy tovirt(r12, r12) 9102847487SChristophe Leroy .if \handle_dar_dsisr 9202847487SChristophe Leroy lwz r10, DAR(r12) 9302847487SChristophe Leroy stw r10, _DAR(r11) 9402847487SChristophe Leroy lwz r10, DSISR(r12) 9502847487SChristophe Leroy stw r10, _DSISR(r11) 9602847487SChristophe Leroy .endif 9702847487SChristophe Leroy lwz r9, SRR1(r12) 9802847487SChristophe Leroy lwz r12, SRR0(r12) 9990f204b9SChristophe Leroy #ifdef CONFIG_40x 10090f204b9SChristophe Leroy rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ 101e464d92bSChristophe Leroy #elif defined(CONFIG_PPC_8xx) 102e464d92bSChristophe Leroy mtspr SPRN_EID, r2 /* Set MSR_RI */ 10390f204b9SChristophe Leroy #else 1049b6150fbSChristophe Leroy li r10, MSR_KERNEL /* can take exceptions */ 10539bccfd1SChristophe Leroy mtmsr r10 /* (except for mach check in rtas) */ 10690f204b9SChristophe Leroy #endif 107a3055978SChristophe Leroy COMMON_EXCEPTION_PROLOG_END \trapno 108a3055978SChristophe Leroy _ASM_NOKPROBE_SYMBOL(\name\()_virt) 109a3055978SChristophe Leroy .endm 110a3055978SChristophe Leroy 111a3055978SChristophe Leroy .macro COMMON_EXCEPTION_PROLOG_END trapno 112a3055978SChristophe Leroy stw r0,GPR0(r1) 1138a23fdecSChristophe Leroy lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ 1148a23fdecSChristophe Leroy addi r10,r10,STACK_FRAME_REGS_MARKER@l 115a3055978SChristophe Leroy stw r10,8(r1) 116719e7e21SChristophe Leroy li r10, \trapno 117a3055978SChristophe Leroy stw r10,_TRAP(r1) 118a3055978SChristophe Leroy SAVE_4GPRS(3, r1) 119a3055978SChristophe Leroy SAVE_2GPRS(7, r1) 12016db5436SChristophe Leroy SAVE_NVGPRS(r1) 12116db5436SChristophe Leroy stw r2,GPR2(r1) 12216db5436SChristophe Leroy stw r12,_NIP(r1) 12316db5436SChristophe Leroy stw r9,_MSR(r1) 12416db5436SChristophe Leroy mfctr r10 12516db5436SChristophe Leroy mfspr r2,SPRN_SPRG_THREAD 12616db5436SChristophe Leroy stw r10,_CTR(r1) 12716db5436SChristophe Leroy tovirt(r2, r2) 12816db5436SChristophe Leroy mfspr r10,SPRN_XER 12916db5436SChristophe Leroy addi r2, r2, -THREAD 13016db5436SChristophe Leroy stw r10,_XER(r1) 13116db5436SChristophe Leroy addi r3,r1,STACK_FRAME_OVERHEAD 1328a23fdecSChristophe Leroy .endm 1338a23fdecSChristophe Leroy 134bce4c26aSChristophe Leroy .macro prepare_transfer_to_handler 135a2b3e09aSChristophe Leroy #ifdef CONFIG_PPC_BOOK3S_32 136*b5efec00SChristophe Leroy andi. r12,r9,MSR_PR 137*b5efec00SChristophe Leroy bne 777f 138bce4c26aSChristophe Leroy bl prepare_transfer_to_handler 139*b5efec00SChristophe Leroy 777: 140a2b3e09aSChristophe Leroy #endif 141bce4c26aSChristophe Leroy .endm 142bce4c26aSChristophe Leroy 143b86fb888SChristophe Leroy .macro SYSCALL_ENTRY trapno 1449e270862SChristophe Leroy mfspr r9, SPRN_SRR1 1452c59e510SChristophe Leroy mfspr r10, SPRN_SRR0 1462c59e510SChristophe Leroy LOAD_REG_IMMEDIATE(r11, MSR_KERNEL) /* can take exceptions */ 1472c59e510SChristophe Leroy lis r12, 1f@h 1482c59e510SChristophe Leroy ori r12, r12, 1f@l 1492c59e510SChristophe Leroy mtspr SPRN_SRR1, r11 1502c59e510SChristophe Leroy mtspr SPRN_SRR0, r12 1512c59e510SChristophe Leroy mfspr r12,SPRN_SPRG_THREAD 152d5c24398SChristophe Leroy mr r11, r1 153d5c24398SChristophe Leroy lwz r1,TASK_STACK-THREAD(r12) 1542c59e510SChristophe Leroy tovirt(r12, r12) 155d5c24398SChristophe Leroy addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE 15676249ddcSChristophe Leroy rfi 15776249ddcSChristophe Leroy 1: 158d5c24398SChristophe Leroy stw r11,GPR1(r1) 159d5c24398SChristophe Leroy stw r11,0(r1) 160d5c24398SChristophe Leroy mr r11, r1 1612c59e510SChristophe Leroy stw r10,_NIP(r11) 1629e270862SChristophe Leroy mflr r10 1639e270862SChristophe Leroy stw r10, _LINK(r11) 164c06f0affSChristophe Leroy mfcr r10 165c06f0affSChristophe Leroy rlwinm r10,r10,0,4,2 /* Clear SO bit in CR */ 166c06f0affSChristophe Leroy stw r10,_CCR(r11) /* save registers */ 167b86fb888SChristophe Leroy #ifdef CONFIG_40x 168b86fb888SChristophe Leroy rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ 169b86fb888SChristophe Leroy #endif 170b86fb888SChristophe Leroy lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ 171b86fb888SChristophe Leroy stw r2,GPR2(r11) 172b86fb888SChristophe Leroy addi r10,r10,STACK_FRAME_REGS_MARKER@l 173b86fb888SChristophe Leroy stw r9,_MSR(r11) 174fbcee2ebSChristophe Leroy li r2, \trapno 175b86fb888SChristophe Leroy stw r10,8(r11) 176b86fb888SChristophe Leroy stw r2,_TRAP(r11) 177b86fb888SChristophe Leroy SAVE_GPR(0, r11) 178b86fb888SChristophe Leroy SAVE_4GPRS(3, r11) 179b86fb888SChristophe Leroy SAVE_2GPRS(7, r11) 180b86fb888SChristophe Leroy addi r2,r12,-THREAD 18176249ddcSChristophe Leroy b transfer_to_syscall /* jump to handler */ 182b86fb888SChristophe Leroy .endm 183b86fb888SChristophe Leroy 1848a23fdecSChristophe Leroy /* 1858a23fdecSChristophe Leroy * Note: code which follows this uses cr0.eq (set if from kernel), 1868a23fdecSChristophe Leroy * r11, r12 (SRR0), and r9 (SRR1). 1878a23fdecSChristophe Leroy * 1888a23fdecSChristophe Leroy * Note2: once we have set r1 we are in a position to take exceptions 1898a23fdecSChristophe Leroy * again, and we could thus set MSR:RI at that point. 1908a23fdecSChristophe Leroy */ 1918a23fdecSChristophe Leroy 1928a23fdecSChristophe Leroy /* 1938a23fdecSChristophe Leroy * Exception vectors. 1948a23fdecSChristophe Leroy */ 1958a23fdecSChristophe Leroy #ifdef CONFIG_PPC_BOOK3S 1968a23fdecSChristophe Leroy #define START_EXCEPTION(n, label) \ 197dc13b889SChristophe Leroy __HEAD; \ 1988a23fdecSChristophe Leroy . = n; \ 1998a23fdecSChristophe Leroy DO_KVM n; \ 2008a23fdecSChristophe Leroy label: 2018a23fdecSChristophe Leroy 2028a23fdecSChristophe Leroy #else 2038a23fdecSChristophe Leroy #define START_EXCEPTION(n, label) \ 204dc13b889SChristophe Leroy __HEAD; \ 2058a23fdecSChristophe Leroy . = n; \ 2068a23fdecSChristophe Leroy label: 2078a23fdecSChristophe Leroy 2088a23fdecSChristophe Leroy #endif 2098a23fdecSChristophe Leroy 210acc142b6SChristophe Leroy #define EXCEPTION(n, label, hdlr) \ 2118a23fdecSChristophe Leroy START_EXCEPTION(n, label) \ 212719e7e21SChristophe Leroy EXCEPTION_PROLOG n label; \ 2134c0104a8SChristophe Leroy prepare_transfer_to_handler; \ 2140f2793e3SChristophe Leroy bl hdlr; \ 2154c0104a8SChristophe Leroy b interrupt_return 2168a23fdecSChristophe Leroy 2173978eb78SChristophe Leroy .macro vmap_stack_overflow_exception 218dc13b889SChristophe Leroy __HEAD 2195b5e5bc5SChristophe Leroy vmap_stack_overflow: 2203978eb78SChristophe Leroy #ifdef CONFIG_SMP 221da7bb43aSChristophe Leroy mfspr r1, SPRN_SPRG_THREAD 222da7bb43aSChristophe Leroy lwz r1, TASK_CPU - THREAD(r1) 223da7bb43aSChristophe Leroy slwi r1, r1, 3 224da7bb43aSChristophe Leroy addis r1, r1, emergency_ctx@ha 2253978eb78SChristophe Leroy #else 226da7bb43aSChristophe Leroy lis r1, emergency_ctx@ha 2273978eb78SChristophe Leroy #endif 228da7bb43aSChristophe Leroy lwz r1, emergency_ctx@l(r1) 229a4719f5bSChristophe Leroy addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE 230719e7e21SChristophe Leroy EXCEPTION_PROLOG_2 0 vmap_stack_overflow 2314c0104a8SChristophe Leroy prepare_transfer_to_handler 2324c0104a8SChristophe Leroy bl stack_overflow_exception 2334c0104a8SChristophe Leroy b interrupt_return 2343978eb78SChristophe Leroy .endm 2353978eb78SChristophe Leroy 2368a23fdecSChristophe Leroy #endif /* __HEAD_32_H__ */ 237