1 #ifndef __HEAD_BOOKE_H__
2 #define __HEAD_BOOKE_H__
5 * Macros used for common Book-e exception handling
8 #define SET_IVOR(vector_number, vector_label) \
9 li r26,vector_label@l; \
10 mtspr SPRN_IVOR##vector_number,r26; \
13 #define NORMAL_EXCEPTION_PROLOG \
14 mtspr SPRN_SPRG0,r10; /* save two registers to work with */\
15 mtspr SPRN_SPRG1,r11; \
16 mtspr SPRN_SPRG4W,r1; \
17 mfcr r10; /* save CR in r10 for now */\
18 mfspr r11,SPRN_SRR1; /* check whether user or kernel */\
19 andi. r11,r11,MSR_PR; \
21 mfspr r1,SPRN_SPRG3; /* if from user, start at top of */\
22 lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\
23 addi r1,r1,THREAD_SIZE; \
24 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\
26 stw r10,_CCR(r11); /* save various registers */\
29 mfspr r10,SPRN_SPRG0; \
31 mfspr r12,SPRN_SPRG1; \
35 mfspr r10,SPRN_SPRG4R; \
36 mfspr r12,SPRN_SRR0; \
40 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
45 /* To handle the additional exception priority levels on 40x and Book-E
46 * processors we allocate a stack per additional priority level.
48 * On 40x critical is the only additional level
49 * On 44x/e500 we have critical and machine check
50 * On e200 we have critical and debug (machine check occurs via critical)
52 * Additionally we reserve a SPRG for each priority level so we can free up a
53 * GPR to use as the base for indirect access to the exception stacks. This
54 * is necessary since the MMU is always on, for Book-E parts, and the stacks
55 * are offset from KERNELBASE.
57 * There is some space optimization to be had here if desired. However
58 * to allow for a common kernel with support for debug exceptions either
59 * going to critical or their own debug level we aren't currently
60 * providing configurations that micro-optimize space usage.
63 /* CRIT_SPRG only used in critical exception handling */
64 #define CRIT_SPRG SPRN_SPRG2
65 /* MCHECK_SPRG only used in machine check exception handling */
66 #define MCHECK_SPRG SPRN_SPRG6W
68 #define MCHECK_STACK_BASE mcheckirq_ctx
69 #define CRIT_STACK_BASE critirq_ctx
71 /* only on e500mc/e200 */
72 #define DEBUG_STACK_BASE dbgirq_ctx
73 #ifdef CONFIG_PPC_E500MC
74 #define DEBUG_SPRG SPRN_SPRG9
76 #define DEBUG_SPRG SPRN_SPRG6W
79 #define EXC_LVL_FRAME_OVERHEAD (THREAD_SIZE - INT_FRAME_SIZE - EXC_LVL_SIZE)
82 #define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
85 addis r8,r8,level##_STACK_BASE@ha; \
86 lwz r8,level##_STACK_BASE@l(r8); \
87 addi r8,r8,EXC_LVL_FRAME_OVERHEAD;
89 #define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
90 lis r8,level##_STACK_BASE@ha; \
91 lwz r8,level##_STACK_BASE@l(r8); \
92 addi r8,r8,EXC_LVL_FRAME_OVERHEAD;
96 * Exception prolog for critical/machine check exceptions. This is a
97 * little different from the normal exception prolog above since a
98 * critical/machine check exception can potentially occur at any point
99 * during normal exception processing. Thus we cannot use the same SPRG
100 * registers as the normal prolog above. Instead we use a portion of the
101 * critical/machine check exception stack at low physical addresses.
103 #define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, exc_level_srr0, exc_level_srr1) \
104 mtspr exc_level##_SPRG,r8; \
105 BOOKE_LOAD_EXC_LEVEL_STACK(exc_level);/* r8 points to the exc_level stack*/ \
106 stw r9,GPR9(r8); /* save various registers */\
107 mfcr r9; /* save CR in r9 for now */\
110 stw r9,_CCR(r8); /* save CR on stack */\
111 mfspr r10,exc_level_srr1; /* check whether user or kernel */\
112 andi. r10,r10,MSR_PR; \
113 mfspr r11,SPRN_SPRG3; /* if from user, start at top of */\
114 lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
115 addi r11,r11,EXC_LVL_FRAME_OVERHEAD; /* allocate stack frame */\
117 /* COMING FROM USER MODE */ \
118 stw r9,_CCR(r11); /* save CR */\
119 lwz r10,GPR10(r8); /* copy regs from exception stack */\
121 stw r10,GPR10(r11); \
124 stw r10,GPR11(r11); \
126 /* COMING FROM PRIV MODE */ \
127 1: lwz r9,TI_FLAGS-EXC_LVL_FRAME_OVERHEAD(r11); \
128 lwz r10,TI_PREEMPT-EXC_LVL_FRAME_OVERHEAD(r11); \
129 stw r9,TI_FLAGS-EXC_LVL_FRAME_OVERHEAD(r8); \
130 stw r10,TI_PREEMPT-EXC_LVL_FRAME_OVERHEAD(r8); \
131 lwz r9,TI_TASK-EXC_LVL_FRAME_OVERHEAD(r11); \
132 stw r9,TI_TASK-EXC_LVL_FRAME_OVERHEAD(r8); \
134 2: mfspr r8,exc_level##_SPRG; \
135 stw r12,GPR12(r11); /* save various registers */\
137 stw r10,_LINK(r11); \
138 mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
139 stw r12,_DEAR(r11); /* since they may have had stuff */\
140 mfspr r9,SPRN_ESR; /* in them at the point where the */\
141 stw r9,_ESR(r11); /* exception was taken */\
142 mfspr r12,exc_level_srr0; \
144 mfspr r9,exc_level_srr1; \
147 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
149 SAVE_4GPRS(3, r11); \
152 #define CRITICAL_EXCEPTION_PROLOG \
153 EXC_LEVEL_EXCEPTION_PROLOG(CRIT, SPRN_CSRR0, SPRN_CSRR1)
154 #define DEBUG_EXCEPTION_PROLOG \
155 EXC_LEVEL_EXCEPTION_PROLOG(DEBUG, SPRN_DSRR0, SPRN_DSRR1)
156 #define MCHECK_EXCEPTION_PROLOG \
157 EXC_LEVEL_EXCEPTION_PROLOG(MCHECK, SPRN_MCSRR0, SPRN_MCSRR1)
162 #define START_EXCEPTION(label) \
166 #define FINISH_EXCEPTION(func) \
167 bl transfer_to_handler_full; \
169 .long ret_from_except_full
171 #define EXCEPTION(n, label, hdlr, xfer) \
172 START_EXCEPTION(label); \
173 NORMAL_EXCEPTION_PROLOG; \
174 addi r3,r1,STACK_FRAME_OVERHEAD; \
177 #define CRITICAL_EXCEPTION(n, label, hdlr) \
178 START_EXCEPTION(label); \
179 CRITICAL_EXCEPTION_PROLOG; \
180 addi r3,r1,STACK_FRAME_OVERHEAD; \
181 EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
182 NOCOPY, crit_transfer_to_handler, \
185 #define MCHECK_EXCEPTION(n, label, hdlr) \
186 START_EXCEPTION(label); \
187 MCHECK_EXCEPTION_PROLOG; \
190 addi r3,r1,STACK_FRAME_OVERHEAD; \
191 EXC_XFER_TEMPLATE(hdlr, n+4, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
192 NOCOPY, mcheck_transfer_to_handler, \
195 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \
197 stw r10,_TRAP(r11); \
205 #define COPY_EE(d, s) rlwimi d,s,0,16,16
208 #define EXC_XFER_STD(n, hdlr) \
209 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \
210 ret_from_except_full)
212 #define EXC_XFER_LITE(n, hdlr) \
213 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
216 #define EXC_XFER_EE(n, hdlr) \
217 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \
218 ret_from_except_full)
220 #define EXC_XFER_EE_LITE(n, hdlr) \
221 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
224 /* Check for a single step debug exception while in an exception
225 * handler before state has been saved. This is to catch the case
226 * where an instruction that we are trying to single step causes
227 * an exception (eg ITLB/DTLB miss) and thus the first instruction of
228 * the exception handler generates a single step debug exception.
230 * If we get a debug trap on the first instruction of an exception handler,
231 * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
232 * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
233 * The exception handler was handling a non-critical interrupt, so it will
234 * save (and later restore) the MSR via SPRN_CSRR1, which will still have
235 * the MSR_DE bit set.
237 #define DEBUG_DEBUG_EXCEPTION \
238 START_EXCEPTION(DebugDebug); \
239 DEBUG_EXCEPTION_PROLOG; \
242 * If there is a single step or branch-taken exception in an \
243 * exception entry sequence, it was probably meant to apply to \
244 * the code where the exception occurred (since exception entry \
245 * doesn't turn off DE automatically). We simulate the effect \
246 * of turning off DE on entry to an exception handler by turning \
247 * off DE in the DSRR1 value and clearing the debug status. \
249 mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
250 andis. r10,r10,DBSR_IC@h; \
253 lis r10,KERNELBASE@h; /* check if exception in vectors */ \
254 ori r10,r10,KERNELBASE@l; \
256 blt+ 2f; /* addr below exception vectors */ \
258 lis r10,DebugDebug@h; \
259 ori r10,r10,DebugDebug@l; \
261 bgt+ 2f; /* addr above exception vectors */ \
263 /* here it looks like we got an inappropriate debug exception. */ \
264 1: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CDRR1 value */ \
265 lis r10,DBSR_IC@h; /* clear the IC event */ \
266 mtspr SPRN_DBSR,r10; \
267 /* restore state and get out */ \
272 mtspr SPRN_DSRR0,r12; \
273 mtspr SPRN_DSRR1,r9; \
275 lwz r12,GPR12(r11); \
276 mtspr DEBUG_SPRG,r8; \
277 BOOKE_LOAD_EXC_LEVEL_STACK(DEBUG); /* r8 points to the debug stack */ \
280 mfspr r8,DEBUG_SPRG; \
285 /* continue normal handling for a debug exception... */ \
286 2: mfspr r4,SPRN_DBSR; \
287 addi r3,r1,STACK_FRAME_OVERHEAD; \
288 EXC_XFER_TEMPLATE(DebugException, 0x2008, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, debug_transfer_to_handler, ret_from_debug_exc)
290 #define DEBUG_CRIT_EXCEPTION \
291 START_EXCEPTION(DebugCrit); \
292 CRITICAL_EXCEPTION_PROLOG; \
295 * If there is a single step or branch-taken exception in an \
296 * exception entry sequence, it was probably meant to apply to \
297 * the code where the exception occurred (since exception entry \
298 * doesn't turn off DE automatically). We simulate the effect \
299 * of turning off DE on entry to an exception handler by turning \
300 * off DE in the CSRR1 value and clearing the debug status. \
302 mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
303 andis. r10,r10,DBSR_IC@h; \
306 lis r10,KERNELBASE@h; /* check if exception in vectors */ \
307 ori r10,r10,KERNELBASE@l; \
309 blt+ 2f; /* addr below exception vectors */ \
311 lis r10,DebugCrit@h; \
312 ori r10,r10,DebugCrit@l; \
314 bgt+ 2f; /* addr above exception vectors */ \
316 /* here it looks like we got an inappropriate debug exception. */ \
317 1: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CSRR1 value */ \
318 lis r10,DBSR_IC@h; /* clear the IC event */ \
319 mtspr SPRN_DBSR,r10; \
320 /* restore state and get out */ \
325 mtspr SPRN_CSRR0,r12; \
326 mtspr SPRN_CSRR1,r9; \
328 lwz r12,GPR12(r11); \
329 mtspr CRIT_SPRG,r8; \
330 BOOKE_LOAD_EXC_LEVEL_STACK(CRIT); /* r8 points to the debug stack */ \
333 mfspr r8,CRIT_SPRG; \
338 /* continue normal handling for a critical exception... */ \
339 2: mfspr r4,SPRN_DBSR; \
340 addi r3,r1,STACK_FRAME_OVERHEAD; \
341 EXC_XFER_TEMPLATE(DebugException, 0x2002, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)
343 #define DATA_STORAGE_EXCEPTION \
344 START_EXCEPTION(DataStorage) \
345 NORMAL_EXCEPTION_PROLOG; \
346 mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
348 mfspr r4,SPRN_DEAR; /* Grab the DEAR */ \
349 EXC_XFER_EE_LITE(0x0300, handle_page_fault)
351 #define INSTRUCTION_STORAGE_EXCEPTION \
352 START_EXCEPTION(InstructionStorage) \
353 NORMAL_EXCEPTION_PROLOG; \
354 mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
356 mr r4,r12; /* Pass SRR0 as arg2 */ \
357 li r5,0; /* Pass zero as arg3 */ \
358 EXC_XFER_EE_LITE(0x0400, handle_page_fault)
360 #define ALIGNMENT_EXCEPTION \
361 START_EXCEPTION(Alignment) \
362 NORMAL_EXCEPTION_PROLOG; \
363 mfspr r4,SPRN_DEAR; /* Grab the DEAR and save it */ \
365 addi r3,r1,STACK_FRAME_OVERHEAD; \
366 EXC_XFER_EE(0x0600, alignment_exception)
368 #define PROGRAM_EXCEPTION \
369 START_EXCEPTION(Program) \
370 NORMAL_EXCEPTION_PROLOG; \
371 mfspr r4,SPRN_ESR; /* Grab the ESR and save it */ \
373 addi r3,r1,STACK_FRAME_OVERHEAD; \
374 EXC_XFER_STD(0x0700, program_check_exception)
376 #define DECREMENTER_EXCEPTION \
377 START_EXCEPTION(Decrementer) \
378 NORMAL_EXCEPTION_PROLOG; \
379 lis r0,TSR_DIS@h; /* Setup the DEC interrupt mask */ \
380 mtspr SPRN_TSR,r0; /* Clear the DEC interrupt */ \
381 addi r3,r1,STACK_FRAME_OVERHEAD; \
382 EXC_XFER_LITE(0x0900, timer_interrupt)
384 #define FP_UNAVAILABLE_EXCEPTION \
385 START_EXCEPTION(FloatingPointUnavailable) \
386 NORMAL_EXCEPTION_PROLOG; \
388 bl load_up_fpu; /* if from user, just load it up */ \
389 b fast_exception_return; \
390 1: addi r3,r1,STACK_FRAME_OVERHEAD; \
391 EXC_XFER_EE_LITE(0x800, kernel_fp_unavailable_exception)
394 struct exception_regs {
407 unsigned long saved_ksp_limit;
410 /* ensure this structure is always sized to a multiple of the stack alignment */
411 #define STACK_EXC_LVL_FRAME_SIZE _ALIGN_UP(sizeof (struct exception_regs), 16)
413 #endif /* __ASSEMBLY__ */
414 #endif /* __HEAD_BOOKE_H__ */