blob: b6b5b01a173cb8030156c1113676306c409d3d3c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Becky Bruce63dafe52006-01-14 16:57:39 -06002#ifndef __HEAD_BOOKE_H__
3#define __HEAD_BOOKE_H__
4
Torez Smith471c70f2010-03-05 10:43:01 +00005#include <asm/ptrace.h> /* for STACK_FRAME_REGS_MARKER */
Scott Woodcfac5782011-12-20 15:34:40 +00006#include <asm/kvm_asm.h>
Scott Woodd30f6e42011-12-20 15:34:43 +00007#include <asm/kvm_booke_hv_asm.h>
Nathan Chancellor80027252023-04-06 10:51:30 -07008#include <asm/thread_info.h> /* for THREAD_SHIFT */
Scott Woodcfac5782011-12-20 15:34:40 +00009
Christophe Leroy1a4b7392019-04-30 12:39:03 +000010#ifdef __ASSEMBLY__
11
Becky Bruce63dafe52006-01-14 16:57:39 -060012/*
13 * Macros used for common Book-e exception handling
14 */
15
16#define SET_IVOR(vector_number, vector_label) \
17 li r26,vector_label@l; \
18 mtspr SPRN_IVOR##vector_number,r26; \
19 sync
20
Yuri Tikhonove1240122009-01-29 01:40:44 +000021#if (THREAD_SHIFT < 15)
22#define ALLOC_STACK_FRAME(reg, val) \
23 addi reg,reg,val
24#else
25#define ALLOC_STACK_FRAME(reg, val) \
26 addis reg,reg,val@ha; \
27 addi reg,reg,val@l
28#endif
29
Ashish Kalra1325a682011-04-22 16:48:27 -050030/*
31 * Macro used to get to thread save registers.
32 * Note that entries 0-3 are used for the prolog code, and the remaining
33 * entries are available for specific exception use in the event a handler
34 * requires more than 4 scratch registers.
35 */
36#define THREAD_NORMSAVE(offset) (THREAD_NORMSAVES + (offset * 4))
37
Christophe Leroy3e731852022-09-19 19:01:38 +020038#ifdef CONFIG_PPC_E500
Diana Craciun039daac2018-12-23 22:34:25 +020039#define BOOKE_CLEAR_BTB(reg) \
40START_BTB_FLUSH_SECTION \
41 BTB_FLUSH(reg) \
42END_BTB_FLUSH_SECTION
43#else
44#define BOOKE_CLEAR_BTB(reg)
45#endif
46
47
Christophe Leroy719e7e22021-03-12 12:50:38 +000048#define NORMAL_EXCEPTION_PROLOG(trapno, intno) \
Ashish Kalra1325a682011-04-22 16:48:27 -050049 mtspr SPRN_SPRG_WSCRATCH0, r10; /* save one register */ \
50 mfspr r10, SPRN_SPRG_THREAD; \
51 stw r11, THREAD_NORMSAVE(0)(r10); \
52 stw r13, THREAD_NORMSAVE(2)(r10); \
53 mfcr r13; /* save CR in r13 for now */\
Scott Woodd30f6e42011-12-20 15:34:43 +000054 mfspr r11, SPRN_SRR1; \
55 DO_KVM BOOKE_INTERRUPT_##intno SPRN_SRR1; \
56 andi. r11, r11, MSR_PR; /* check whether user or kernel */\
Christophe Leroy9b6150f2021-03-12 12:50:24 +000057 LOAD_REG_IMMEDIATE(r11, MSR_KERNEL); \
58 mtmsr r11; \
Ashish Kalra1325a682011-04-22 16:48:27 -050059 mr r11, r1; \
Becky Bruce63dafe52006-01-14 16:57:39 -060060 beq 1f; \
Diana Craciun039daac2018-12-23 22:34:25 +020061 BOOKE_CLEAR_BTB(r11) \
Ashish Kalra1325a682011-04-22 16:48:27 -050062 /* if from user, start at top of this thread's kernel stack */ \
Christophe Leroy8c1fc5a2019-01-31 10:08:54 +000063 lwz r11, TASK_STACK - THREAD(r10); \
Ashish Kalra1325a682011-04-22 16:48:27 -050064 ALLOC_STACK_FRAME(r11, THREAD_SIZE); \
651 : subi r11, r11, INT_FRAME_SIZE; /* Allocate exception frame */ \
66 stw r13, _CCR(r11); /* save various registers */ \
Becky Bruce63dafe52006-01-14 16:57:39 -060067 stw r12,GPR12(r11); \
68 stw r9,GPR9(r11); \
Ashish Kalra1325a682011-04-22 16:48:27 -050069 mfspr r13, SPRN_SPRG_RSCRATCH0; \
70 stw r13, GPR10(r11); \
71 lwz r12, THREAD_NORMSAVE(0)(r10); \
Becky Bruce63dafe52006-01-14 16:57:39 -060072 stw r12,GPR11(r11); \
Ashish Kalra1325a682011-04-22 16:48:27 -050073 lwz r13, THREAD_NORMSAVE(2)(r10); /* restore r13 */ \
Becky Bruce63dafe52006-01-14 16:57:39 -060074 mflr r10; \
75 stw r10,_LINK(r11); \
Becky Bruce63dafe52006-01-14 16:57:39 -060076 mfspr r12,SPRN_SRR0; \
Ashish Kalra1325a682011-04-22 16:48:27 -050077 stw r1, GPR1(r11); \
Becky Bruce63dafe52006-01-14 16:57:39 -060078 mfspr r9,SPRN_SRR1; \
Ashish Kalra1325a682011-04-22 16:48:27 -050079 stw r1, 0(r11); \
80 mr r1, r11; \
Becky Bruce63dafe52006-01-14 16:57:39 -060081 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
Christophe Leroya3055972021-03-12 12:50:43 +000082 COMMON_EXCEPTION_PROLOG_END trapno
83
84.macro COMMON_EXCEPTION_PROLOG_END trapno
85 stw r0,GPR0(r1)
86 lis r10, STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
87 addi r10, r10, STACK_FRAME_REGS_MARKER@l
Nicholas Piggind2e8ff92022-11-27 22:49:33 +100088 stw r10, STACK_INT_FRAME_MARKER(r1)
Christophe Leroya3055972021-03-12 12:50:43 +000089 li r10, \trapno
90 stw r10,_TRAP(r1)
Nicholas Pigginaebd1fb2021-10-22 16:13:22 +100091 SAVE_GPRS(3, 8, r1)
Christophe Leroy16db5432021-03-12 12:50:44 +000092 SAVE_NVGPRS(r1)
93 stw r2,GPR2(r1)
94 stw r12,_NIP(r1)
95 stw r9,_MSR(r1)
96 mfctr r10
97 mfspr r2,SPRN_SPRG_THREAD
98 stw r10,_CTR(r1)
99 tovirt(r2, r2)
100 mfspr r10,SPRN_XER
101 addi r2, r2, -THREAD
102 stw r10,_XER(r1)
Nicholas Pigginc03be0a2022-11-27 22:49:32 +1000103 addi r3,r1,STACK_INT_FRAME_REGS
Christophe Leroya3055972021-03-12 12:50:43 +0000104.endm
Becky Bruce63dafe52006-01-14 16:57:39 -0600105
Christophe Leroybce4c262021-03-12 12:50:39 +0000106.macro prepare_transfer_to_handler
Christophe Leroy688de012022-09-19 19:01:35 +0200107#ifdef CONFIG_PPC_E500
Christophe Leroyb5efec02021-03-12 12:50:47 +0000108 andi. r12,r9,MSR_PR
109 bne 777f
Christophe Leroybce4c262021-03-12 12:50:39 +0000110 bl prepare_transfer_to_handler
Christophe Leroyb5efec02021-03-12 12:50:47 +0000111777:
Christophe Leroya2b3e092021-03-12 12:50:46 +0000112#endif
Christophe Leroybce4c262021-03-12 12:50:39 +0000113.endm
114
Christophe Leroy82f6e262019-05-23 08:39:27 +0000115.macro SYSCALL_ENTRY trapno intno srr1
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000116 mfspr r10, SPRN_SPRG_THREAD
117#ifdef CONFIG_KVM_BOOKE_HV
118BEGIN_FTR_SECTION
119 mtspr SPRN_SPRG_WSCRATCH0, r10
120 stw r11, THREAD_NORMSAVE(0)(r10)
121 stw r13, THREAD_NORMSAVE(2)(r10)
122 mfcr r13 /* save CR in r13 for now */
123 mfspr r11, SPRN_SRR1
124 mtocrf 0x80, r11 /* check MSR[GS] without clobbering reg */
125 bf 3, 1975f
Christophe Leroy82f6e262019-05-23 08:39:27 +0000126 b kvmppc_handler_\intno\()_\srr1
Christophe Leroy1a4b7392019-04-30 12:39:03 +00001271975:
128 mr r12, r13
129 lwz r13, THREAD_NORMSAVE(2)(r10)
130FTR_SECTION_ELSE
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000131 mfcr r12
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000132ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
Christophe Leroya27755d2021-06-04 14:54:15 +0000133#else
134 mfcr r12
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000135#endif
Christophe Leroy9e270862020-01-31 11:34:54 +0000136 mfspr r9, SPRN_SRR1
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000137 BOOKE_CLEAR_BTB(r11)
Christophe Leroy275dcf22021-06-04 14:54:13 +0000138 mr r11, r1
139 lwz r1, TASK_STACK - THREAD(r10)
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000140 rlwinm r12,r12,0,4,2 /* Clear SO bit in CR */
Christophe Leroy275dcf22021-06-04 14:54:13 +0000141 ALLOC_STACK_FRAME(r1, THREAD_SIZE - INT_FRAME_SIZE)
142 stw r12, _CCR(r1)
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000143 mfspr r12,SPRN_SRR0
Christophe Leroy275dcf22021-06-04 14:54:13 +0000144 stw r12,_NIP(r1)
Christophe Leroy76249dd2021-02-08 15:10:22 +0000145 b transfer_to_syscall /* jump to handler */
Christophe Leroy1a4b7392019-04-30 12:39:03 +0000146.endm
147
Becky Bruce63dafe52006-01-14 16:57:39 -0600148/* To handle the additional exception priority levels on 40x and Book-E
Kumar Galabcf0b082008-04-30 03:49:55 -0500149 * processors we allocate a stack per additional priority level.
Becky Bruce63dafe52006-01-14 16:57:39 -0600150 *
151 * On 40x critical is the only additional level
152 * On 44x/e500 we have critical and machine check
Becky Bruce63dafe52006-01-14 16:57:39 -0600153 *
154 * Additionally we reserve a SPRG for each priority level so we can free up a
155 * GPR to use as the base for indirect access to the exception stacks. This
156 * is necessary since the MMU is always on, for Book-E parts, and the stacks
157 * are offset from KERNELBASE.
158 *
Kumar Galaeb0cd5fd2008-04-09 06:06:11 -0500159 * There is some space optimization to be had here if desired. However
160 * to allow for a common kernel with support for debug exceptions either
161 * going to critical or their own debug level we aren't currently
162 * providing configurations that micro-optimize space usage.
Becky Bruce63dafe52006-01-14 16:57:39 -0600163 */
Becky Bruce63dafe52006-01-14 16:57:39 -0600164
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000165#define MC_STACK_BASE mcheckirq_ctx
Kumar Galabcf0b082008-04-30 03:49:55 -0500166#define CRIT_STACK_BASE critirq_ctx
Becky Bruce63dafe52006-01-14 16:57:39 -0600167
Christophe Leroy39c8bf22020-11-17 05:07:58 +0000168/* only on e500mc */
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000169#define DBG_STACK_BASE dbgirq_ctx
Becky Bruce63dafe52006-01-14 16:57:39 -0600170
171#ifdef CONFIG_SMP
172#define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
173 mfspr r8,SPRN_PIR; \
Kumar Galabcf0b082008-04-30 03:49:55 -0500174 slwi r8,r8,2; \
175 addis r8,r8,level##_STACK_BASE@ha; \
176 lwz r8,level##_STACK_BASE@l(r8); \
Christophe Leroyb5cfc9c2021-07-07 05:55:07 +0000177 addi r8,r8,THREAD_SIZE - INT_FRAME_SIZE;
Becky Bruce63dafe52006-01-14 16:57:39 -0600178#else
179#define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
Kumar Galabcf0b082008-04-30 03:49:55 -0500180 lis r8,level##_STACK_BASE@ha; \
181 lwz r8,level##_STACK_BASE@l(r8); \
Christophe Leroyb5cfc9c2021-07-07 05:55:07 +0000182 addi r8,r8,THREAD_SIZE - INT_FRAME_SIZE;
Becky Bruce63dafe52006-01-14 16:57:39 -0600183#endif
184
185/*
186 * Exception prolog for critical/machine check exceptions. This is a
187 * little different from the normal exception prolog above since a
188 * critical/machine check exception can potentially occur at any point
189 * during normal exception processing. Thus we cannot use the same SPRG
190 * registers as the normal prolog above. Instead we use a portion of the
191 * critical/machine check exception stack at low physical addresses.
192 */
Christophe Leroy719e7e22021-03-12 12:50:38 +0000193#define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, trapno, intno, exc_level_srr0, exc_level_srr1) \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000194 mtspr SPRN_SPRG_WSCRATCH_##exc_level,r8; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600195 BOOKE_LOAD_EXC_LEVEL_STACK(exc_level);/* r8 points to the exc_level stack*/ \
Kumar Gala369e7572008-04-30 04:17:22 -0500196 stw r9,GPR9(r8); /* save various registers */\
197 mfcr r9; /* save CR in r9 for now */\
198 stw r10,GPR10(r8); \
199 stw r11,GPR11(r8); \
200 stw r9,_CCR(r8); /* save CR on stack */\
Scott Woodd30f6e42011-12-20 15:34:43 +0000201 mfspr r11,exc_level_srr1; /* check whether user or kernel */\
202 DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \
Diana Craciun039daac2018-12-23 22:34:25 +0200203 BOOKE_CLEAR_BTB(r10) \
Scott Woodd30f6e42011-12-20 15:34:43 +0000204 andi. r11,r11,MSR_PR; \
Christophe Leroy9b6150f2021-03-12 12:50:24 +0000205 LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)); \
206 mtmsr r11; \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000207 mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\
Christophe Leroy8c1fc5a2019-01-31 10:08:54 +0000208 lwz r11, TASK_STACK - THREAD(r11); /* this thread's kernel stack */\
Christophe Leroyb5cfc9c2021-07-07 05:55:07 +0000209 addi r11,r11,THREAD_SIZE - INT_FRAME_SIZE; /* allocate stack frame */\
Kumar Gala369e7572008-04-30 04:17:22 -0500210 beq 1f; \
211 /* COMING FROM USER MODE */ \
212 stw r9,_CCR(r11); /* save CR */\
213 lwz r10,GPR10(r8); /* copy regs from exception stack */\
214 lwz r9,GPR9(r8); \
215 stw r10,GPR10(r11); \
216 lwz r10,GPR11(r8); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600217 stw r9,GPR9(r11); \
Kumar Gala369e7572008-04-30 04:17:22 -0500218 stw r10,GPR11(r11); \
219 b 2f; \
220 /* COMING FROM PRIV MODE */ \
Christophe Leroyed1cd6d2019-01-31 10:08:58 +00002211: mr r11, r8; \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +00002222: mfspr r8,SPRN_SPRG_RSCRATCH_##exc_level; \
Kumar Gala369e7572008-04-30 04:17:22 -0500223 stw r12,GPR12(r11); /* save various registers */\
Becky Bruce63dafe52006-01-14 16:57:39 -0600224 mflr r10; \
225 stw r10,_LINK(r11); \
226 mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
227 stw r12,_DEAR(r11); /* since they may have had stuff */\
228 mfspr r9,SPRN_ESR; /* in them at the point where the */\
229 stw r9,_ESR(r11); /* exception was taken */\
230 mfspr r12,exc_level_srr0; \
231 stw r1,GPR1(r11); \
232 mfspr r9,exc_level_srr1; \
233 stw r1,0(r11); \
234 mr r1,r11; \
235 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
Christophe Leroya3055972021-03-12 12:50:43 +0000236 COMMON_EXCEPTION_PROLOG_END trapno
Becky Bruce63dafe52006-01-14 16:57:39 -0600237
Christophe Leroy32d2ca02021-03-12 12:50:31 +0000238#define SAVE_xSRR(xSRR) \
239 mfspr r0,SPRN_##xSRR##0; \
240 stw r0,_##xSRR##0(r1); \
241 mfspr r0,SPRN_##xSRR##1; \
242 stw r0,_##xSRR##1(r1)
243
244
245.macro SAVE_MMU_REGS
Christophe Leroyaa5f59d2022-09-19 19:01:39 +0200246#ifdef CONFIG_PPC_E500
Christophe Leroy32d2ca02021-03-12 12:50:31 +0000247 mfspr r0,SPRN_MAS0
248 stw r0,MAS0(r1)
249 mfspr r0,SPRN_MAS1
250 stw r0,MAS1(r1)
251 mfspr r0,SPRN_MAS2
252 stw r0,MAS2(r1)
253 mfspr r0,SPRN_MAS3
254 stw r0,MAS3(r1)
255 mfspr r0,SPRN_MAS6
256 stw r0,MAS6(r1)
257#ifdef CONFIG_PHYS_64BIT
258 mfspr r0,SPRN_MAS7
259 stw r0,MAS7(r1)
260#endif /* CONFIG_PHYS_64BIT */
Christophe Leroyaa5f59d2022-09-19 19:01:39 +0200261#endif /* CONFIG_PPC_E500 */
Christophe Leroy32d2ca02021-03-12 12:50:31 +0000262#ifdef CONFIG_44x
263 mfspr r0,SPRN_MMUCR
264 stw r0,MMUCR(r1)
265#endif
266.endm
267
Christophe Leroy719e7e22021-03-12 12:50:38 +0000268#define CRITICAL_EXCEPTION_PROLOG(trapno, intno) \
269 EXC_LEVEL_EXCEPTION_PROLOG(CRIT, trapno+2, intno, SPRN_CSRR0, SPRN_CSRR1)
270#define DEBUG_EXCEPTION_PROLOG(trapno) \
271 EXC_LEVEL_EXCEPTION_PROLOG(DBG, trapno+8, DEBUG, SPRN_DSRR0, SPRN_DSRR1)
272#define MCHECK_EXCEPTION_PROLOG(trapno) \
273 EXC_LEVEL_EXCEPTION_PROLOG(MC, trapno+4, MACHINE_CHECK, \
Scott Woodcfac5782011-12-20 15:34:40 +0000274 SPRN_MCSRR0, SPRN_MCSRR1)
Becky Bruce63dafe52006-01-14 16:57:39 -0600275
276/*
Scott Woodd30f6e42011-12-20 15:34:43 +0000277 * Guest Doorbell -- this is a bit odd in that uses GSRR0/1 despite
278 * being delivered to the host. This exception can only happen
279 * inside a KVM guest -- so we just handle up to the DO_KVM rather
280 * than try to fit this into one of the existing prolog macros.
281 */
282#define GUEST_DOORBELL_EXCEPTION \
283 START_EXCEPTION(GuestDoorbell); \
284 mtspr SPRN_SPRG_WSCRATCH0, r10; /* save one register */ \
285 mfspr r10, SPRN_SPRG_THREAD; \
286 stw r11, THREAD_NORMSAVE(0)(r10); \
287 mfspr r11, SPRN_SRR1; \
288 stw r13, THREAD_NORMSAVE(2)(r10); \
289 mfcr r13; /* save CR in r13 for now */\
290 DO_KVM BOOKE_INTERRUPT_GUEST_DBELL SPRN_GSRR1; \
291 trap
292
293/*
Becky Bruce63dafe52006-01-14 16:57:39 -0600294 * Exception vectors.
295 */
296#define START_EXCEPTION(label) \
297 .align 5; \
298label:
299
Christophe Leroyacc142b2021-03-12 12:50:42 +0000300#define EXCEPTION(n, intno, label, hdlr) \
Becky Bruce63dafe52006-01-14 16:57:39 -0600301 START_EXCEPTION(label); \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000302 NORMAL_EXCEPTION_PROLOG(n, intno); \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000303 prepare_transfer_to_handler; \
304 bl hdlr; \
305 b interrupt_return
Becky Bruce63dafe52006-01-14 16:57:39 -0600306
Scott Woodcfac5782011-12-20 15:34:40 +0000307#define CRITICAL_EXCEPTION(n, intno, label, hdlr) \
308 START_EXCEPTION(label); \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000309 CRITICAL_EXCEPTION_PROLOG(n, intno); \
Christophe Leroy32d2ca02021-03-12 12:50:31 +0000310 SAVE_MMU_REGS; \
311 SAVE_xSRR(SRR); \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000312 prepare_transfer_to_handler; \
313 bl hdlr; \
314 b ret_from_crit_exc
Becky Bruce63dafe52006-01-14 16:57:39 -0600315
316#define MCHECK_EXCEPTION(n, label, hdlr) \
317 START_EXCEPTION(label); \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000318 MCHECK_EXCEPTION_PROLOG(n); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600319 mfspr r5,SPRN_ESR; \
320 stw r5,_ESR(r11); \
Christophe Leroy32d2ca02021-03-12 12:50:31 +0000321 SAVE_xSRR(DSRR); \
322 SAVE_xSRR(CSRR); \
323 SAVE_MMU_REGS; \
324 SAVE_xSRR(SRR); \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000325 prepare_transfer_to_handler; \
Christophe Leroy0f2793e2021-03-12 12:50:32 +0000326 bl hdlr; \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000327 b ret_from_mcheck_exc
Becky Bruce63dafe52006-01-14 16:57:39 -0600328
Becky Bruce63dafe52006-01-14 16:57:39 -0600329/* Check for a single step debug exception while in an exception
330 * handler before state has been saved. This is to catch the case
331 * where an instruction that we are trying to single step causes
332 * an exception (eg ITLB/DTLB miss) and thus the first instruction of
333 * the exception handler generates a single step debug exception.
334 *
335 * If we get a debug trap on the first instruction of an exception handler,
336 * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
337 * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
338 * The exception handler was handling a non-critical interrupt, so it will
339 * save (and later restore) the MSR via SPRN_CSRR1, which will still have
340 * the MSR_DE bit set.
341 */
Kumar Galaeb0cd5fd2008-04-09 06:06:11 -0500342#define DEBUG_DEBUG_EXCEPTION \
343 START_EXCEPTION(DebugDebug); \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000344 DEBUG_EXCEPTION_PROLOG(2000); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600345 \
346 /* \
347 * If there is a single step or branch-taken exception in an \
348 * exception entry sequence, it was probably meant to apply to \
349 * the code where the exception occurred (since exception entry \
350 * doesn't turn off DE automatically). We simulate the effect \
351 * of turning off DE on entry to an exception handler by turning \
Kumar Galafec6a822008-06-11 13:07:26 -0500352 * off DE in the DSRR1 value and clearing the debug status. \
Becky Bruce63dafe52006-01-14 16:57:39 -0600353 */ \
354 mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000355 andis. r10,r10,(DBSR_IC|DBSR_BT)@h; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600356 beq+ 2f; \
357 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000358 lis r10,interrupt_base@h; /* check if exception in vectors */ \
359 ori r10,r10,interrupt_base@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600360 cmplw r12,r10; \
361 blt+ 2f; /* addr below exception vectors */ \
362 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000363 lis r10,interrupt_end@h; \
364 ori r10,r10,interrupt_end@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600365 cmplw r12,r10; \
366 bgt+ 2f; /* addr above exception vectors */ \
367 \
368 /* here it looks like we got an inappropriate debug exception. */ \
3691: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CDRR1 value */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000370 lis r10,(DBSR_IC|DBSR_BT)@h; /* clear the IC event */ \
Becky Bruce63dafe52006-01-14 16:57:39 -0600371 mtspr SPRN_DBSR,r10; \
372 /* restore state and get out */ \
373 lwz r10,_CCR(r11); \
374 lwz r0,GPR0(r11); \
375 lwz r1,GPR1(r11); \
376 mtcrf 0x80,r10; \
377 mtspr SPRN_DSRR0,r12; \
378 mtspr SPRN_DSRR1,r9; \
379 lwz r9,GPR9(r11); \
380 lwz r12,GPR12(r11); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000381 mtspr SPRN_SPRG_WSCRATCH_DBG,r8; \
382 BOOKE_LOAD_EXC_LEVEL_STACK(DBG); /* r8 points to the debug stack */ \
Kumar Gala369e7572008-04-30 04:17:22 -0500383 lwz r10,GPR10(r8); \
384 lwz r11,GPR11(r8); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000385 mfspr r8,SPRN_SPRG_RSCRATCH_DBG; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600386 \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000387 PPC_RFDI; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600388 b .; \
389 \
Kumar Galafec6a822008-06-11 13:07:26 -0500390 /* continue normal handling for a debug exception... */ \
Becky Bruce63dafe52006-01-14 16:57:39 -06003912: mfspr r4,SPRN_DBSR; \
Nicholas Piggin755d6642021-01-30 23:08:19 +1000392 stw r4,_ESR(r11); /* DebugException takes DBSR in _ESR */\
Christophe Leroy32d2ca02021-03-12 12:50:31 +0000393 SAVE_xSRR(CSRR); \
394 SAVE_MMU_REGS; \
395 SAVE_xSRR(SRR); \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000396 prepare_transfer_to_handler; \
397 bl DebugException; \
398 b ret_from_debug_exc
Kumar Galaeb0cd5fd2008-04-09 06:06:11 -0500399
400#define DEBUG_CRIT_EXCEPTION \
401 START_EXCEPTION(DebugCrit); \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000402 CRITICAL_EXCEPTION_PROLOG(2000,DEBUG); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600403 \
404 /* \
405 * If there is a single step or branch-taken exception in an \
406 * exception entry sequence, it was probably meant to apply to \
407 * the code where the exception occurred (since exception entry \
408 * doesn't turn off DE automatically). We simulate the effect \
409 * of turning off DE on entry to an exception handler by turning \
410 * off DE in the CSRR1 value and clearing the debug status. \
411 */ \
412 mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000413 andis. r10,r10,(DBSR_IC|DBSR_BT)@h; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600414 beq+ 2f; \
415 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000416 lis r10,interrupt_base@h; /* check if exception in vectors */ \
417 ori r10,r10,interrupt_base@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600418 cmplw r12,r10; \
419 blt+ 2f; /* addr below exception vectors */ \
420 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000421 lis r10,interrupt_end@h; \
422 ori r10,r10,interrupt_end@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600423 cmplw r12,r10; \
424 bgt+ 2f; /* addr above exception vectors */ \
425 \
426 /* here it looks like we got an inappropriate debug exception. */ \
4271: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CSRR1 value */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000428 lis r10,(DBSR_IC|DBSR_BT)@h; /* clear the IC event */ \
Becky Bruce63dafe52006-01-14 16:57:39 -0600429 mtspr SPRN_DBSR,r10; \
430 /* restore state and get out */ \
431 lwz r10,_CCR(r11); \
432 lwz r0,GPR0(r11); \
433 lwz r1,GPR1(r11); \
434 mtcrf 0x80,r10; \
435 mtspr SPRN_CSRR0,r12; \
436 mtspr SPRN_CSRR1,r9; \
437 lwz r9,GPR9(r11); \
438 lwz r12,GPR12(r11); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000439 mtspr SPRN_SPRG_WSCRATCH_CRIT,r8; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600440 BOOKE_LOAD_EXC_LEVEL_STACK(CRIT); /* r8 points to the debug stack */ \
Kumar Gala369e7572008-04-30 04:17:22 -0500441 lwz r10,GPR10(r8); \
442 lwz r11,GPR11(r8); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000443 mfspr r8,SPRN_SPRG_RSCRATCH_CRIT; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600444 \
445 rfci; \
446 b .; \
447 \
448 /* continue normal handling for a critical exception... */ \
4492: mfspr r4,SPRN_DBSR; \
Nicholas Piggin755d6642021-01-30 23:08:19 +1000450 stw r4,_ESR(r11); /* DebugException takes DBSR in _ESR */\
Christophe Leroy32d2ca02021-03-12 12:50:31 +0000451 SAVE_MMU_REGS; \
452 SAVE_xSRR(SRR); \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000453 prepare_transfer_to_handler; \
454 bl DebugException; \
455 b ret_from_crit_exc
Becky Bruce63dafe52006-01-14 16:57:39 -0600456
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000457#define DATA_STORAGE_EXCEPTION \
458 START_EXCEPTION(DataStorage) \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000459 NORMAL_EXCEPTION_PROLOG(0x300, DATA_STORAGE); \
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000460 mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
461 stw r5,_ESR(r11); \
462 mfspr r4,SPRN_DEAR; /* Grab the DEAR */ \
Christophe Leroy1ca9db52019-12-21 08:32:24 +0000463 stw r4, _DEAR(r11); \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000464 prepare_transfer_to_handler; \
465 bl do_page_fault; \
466 b interrupt_return
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000467
Nicholas Piggin81291382021-10-28 23:30:43 +1000468/*
469 * Instruction TLB Error interrupt handlers may call InstructionStorage
470 * directly without clearing ESR, so the ESR at this point may be left over
471 * from a prior interrupt.
472 *
473 * In any case, do_page_fault for BOOK3E does not use ESR and always expects
474 * dsisr to be 0. ESR_DST from a prior store in particular would confuse fault
475 * handling.
476 */
Becky Bruce63dafe52006-01-14 16:57:39 -0600477#define INSTRUCTION_STORAGE_EXCEPTION \
478 START_EXCEPTION(InstructionStorage) \
Nicholas Piggin81291382021-10-28 23:30:43 +1000479 NORMAL_EXCEPTION_PROLOG(0x400, INST_STORAGE); \
480 li r5,0; /* Store 0 in regs->esr (dsisr) */ \
Becky Bruce63dafe52006-01-14 16:57:39 -0600481 stw r5,_ESR(r11); \
Nicholas Piggin81291382021-10-28 23:30:43 +1000482 stw r12, _DEAR(r11); /* Set regs->dear (dar) to SRR0 */ \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000483 prepare_transfer_to_handler; \
484 bl do_page_fault; \
485 b interrupt_return
Becky Bruce63dafe52006-01-14 16:57:39 -0600486
487#define ALIGNMENT_EXCEPTION \
488 START_EXCEPTION(Alignment) \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000489 NORMAL_EXCEPTION_PROLOG(0x600, ALIGNMENT); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600490 mfspr r4,SPRN_DEAR; /* Grab the DEAR and save it */ \
491 stw r4,_DEAR(r11); \
Christophe Leroy8f6ff5b2021-03-12 12:50:40 +0000492 prepare_transfer_to_handler; \
493 bl alignment_exception; \
494 REST_NVGPRS(r1); \
495 b interrupt_return
Becky Bruce63dafe52006-01-14 16:57:39 -0600496
497#define PROGRAM_EXCEPTION \
498 START_EXCEPTION(Program) \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000499 NORMAL_EXCEPTION_PROLOG(0x700, PROGRAM); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600500 mfspr r4,SPRN_ESR; /* Grab the ESR and save it */ \
501 stw r4,_ESR(r11); \
Christophe Leroy8f6ff5b2021-03-12 12:50:40 +0000502 prepare_transfer_to_handler; \
503 bl program_check_exception; \
504 REST_NVGPRS(r1); \
505 b interrupt_return
Becky Bruce63dafe52006-01-14 16:57:39 -0600506
507#define DECREMENTER_EXCEPTION \
508 START_EXCEPTION(Decrementer) \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000509 NORMAL_EXCEPTION_PROLOG(0x900, DECREMENTER); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600510 lis r0,TSR_DIS@h; /* Setup the DEC interrupt mask */ \
511 mtspr SPRN_TSR,r0; /* Clear the DEC interrupt */ \
Christophe Leroy4c0104a2021-03-12 12:50:41 +0000512 prepare_transfer_to_handler; \
513 bl timer_interrupt; \
514 b interrupt_return
Becky Bruce63dafe52006-01-14 16:57:39 -0600515
516#define FP_UNAVAILABLE_EXCEPTION \
517 START_EXCEPTION(FloatingPointUnavailable) \
Christophe Leroy719e7e22021-03-12 12:50:38 +0000518 NORMAL_EXCEPTION_PROLOG(0x800, FP_UNAVAIL); \
Michael Neuling6f3d8e62008-06-25 14:07:18 +1000519 beq 1f; \
520 bl load_up_fpu; /* if from user, just load it up */ \
521 b fast_exception_return; \
Christophe Leroy4c0104a2021-03-12 12:50:41 +00005221: prepare_transfer_to_handler; \
523 bl kernel_fp_unavailable_exception; \
524 b interrupt_return
Becky Bruce63dafe52006-01-14 16:57:39 -0600525
Kumar Galafca622c2008-04-30 05:23:21 -0500526#endif /* __ASSEMBLY__ */
Becky Bruce63dafe52006-01-14 16:57:39 -0600527#endif /* __HEAD_BOOKE_H__ */