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,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 */\
40 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
46 * Exception prolog for critical exceptions. This is a little different
47 * from the normal exception prolog above since a critical exception
48 * can potentially occur at any point during normal exception processing.
49 * Thus we cannot use the same SPRG registers as the normal prolog above.
50 * Instead we use a couple of words of memory at low physical addresses.
51 * This is OK since we don't support SMP on these processors. For Book E
52 * processors, we also have a reserved register (SPRG2) that is only used
53 * in critical exceptions so we can free up a GPR to use as the base for
54 * indirect access to the critical exception save area. This is necessary
55 * since the MMU is always on and the save area is offset from KERNELBASE.
57 #define CRITICAL_EXCEPTION_PROLOG \
58 mtspr SPRG2,r8; /* SPRG2 only used in criticals */ \
59 lis r8,crit_save@ha; \
60 stw r10,crit_r10@l(r8); \
61 stw r11,crit_r11@l(r8); \
63 stw r10,crit_sprg0@l(r8); \
65 stw r10,crit_sprg1@l(r8); \
67 stw r10,crit_sprg4@l(r8); \
69 stw r10,crit_sprg5@l(r8); \
71 stw r10,crit_sprg7@l(r8); \
73 stw r10,crit_pid@l(r8); \
75 stw r10,crit_srr0@l(r8); \
77 stw r10,crit_srr1@l(r8); \
78 mfspr r8,SPRG2; /* SPRG2 only used in criticals */ \
79 mfcr r10; /* save CR in r10 for now */\
80 mfspr r11,SPRN_CSRR1; /* check whether user or kernel */\
81 andi. r11,r11,MSR_PR; \
82 lis r11,critical_stack_top@h; \
83 ori r11,r11,critical_stack_top@l; \
85 /* COMING FROM USER MODE */ \
86 mfspr r11,SPRG3; /* if from user, start at top of */\
87 lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
88 addi r11,r11,THREAD_SIZE; \
89 1: subi r11,r11,INT_FRAME_SIZE; /* Allocate an exception frame */\
90 stw r10,_CCR(r11); /* save various registers */\
95 mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
96 stw r12,_DEAR(r11); /* since they may have had stuff */\
97 mfspr r9,SPRN_ESR; /* in them at the point where the */\
98 stw r9,_ESR(r11); /* exception was taken */\
104 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
106 SAVE_4GPRS(3, r11); \
110 * Exception prolog for machine check exceptions. This is similar to
111 * the critical exception prolog, except that machine check exceptions
112 * have their own save area. For Book E processors, we also have a
113 * reserved register (SPRG6) that is only used in machine check exceptions
114 * so we can free up a GPR to use as the base for indirect access to the
115 * machine check exception save area. This is necessary since the MMU
116 * is always on and the save area is offset from KERNELBASE.
118 #define MCHECK_EXCEPTION_PROLOG \
119 mtspr SPRG6W,r8; /* SPRG6 used in machine checks */ \
120 lis r8,mcheck_save@ha; \
121 stw r10,mcheck_r10@l(r8); \
122 stw r11,mcheck_r11@l(r8); \
124 stw r10,mcheck_sprg0@l(r8); \
126 stw r10,mcheck_sprg1@l(r8); \
128 stw r10,mcheck_sprg4@l(r8); \
130 stw r10,mcheck_sprg5@l(r8); \
132 stw r10,mcheck_sprg7@l(r8); \
133 mfspr r10,SPRN_PID; \
134 stw r10,mcheck_pid@l(r8); \
136 stw r10,mcheck_srr0@l(r8); \
138 stw r10,mcheck_srr1@l(r8); \
140 stw r10,mcheck_csrr0@l(r8); \
142 stw r10,mcheck_csrr1@l(r8); \
143 mfspr r8,SPRG6R; /* SPRG6 used in machine checks */ \
144 mfcr r10; /* save CR in r10 for now */\
145 mfspr r11,SPRN_MCSRR1; /* check whether user or kernel */\
146 andi. r11,r11,MSR_PR; \
147 lis r11,mcheck_stack_top@h; \
148 ori r11,r11,mcheck_stack_top@l; \
150 /* COMING FROM USER MODE */ \
151 mfspr r11,SPRG3; /* if from user, start at top of */\
152 lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
153 addi r11,r11,THREAD_SIZE; \
154 1: subi r11,r11,INT_FRAME_SIZE; /* Allocate an exception frame */\
155 stw r10,_CCR(r11); /* save various registers */\
156 stw r12,GPR12(r11); \
159 stw r10,_LINK(r11); \
160 mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
161 stw r12,_DEAR(r11); /* since they may have had stuff */\
162 mfspr r9,SPRN_ESR; /* in them at the point where the */\
163 stw r9,_ESR(r11); /* exception was taken */\
169 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
171 SAVE_4GPRS(3, r11); \
177 #define START_EXCEPTION(label) \
181 #define FINISH_EXCEPTION(func) \
182 bl transfer_to_handler_full; \
184 .long ret_from_except_full
186 #define EXCEPTION(n, label, hdlr, xfer) \
187 START_EXCEPTION(label); \
188 NORMAL_EXCEPTION_PROLOG; \
189 addi r3,r1,STACK_FRAME_OVERHEAD; \
192 #define CRITICAL_EXCEPTION(n, label, hdlr) \
193 START_EXCEPTION(label); \
194 CRITICAL_EXCEPTION_PROLOG; \
195 addi r3,r1,STACK_FRAME_OVERHEAD; \
196 EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
197 NOCOPY, transfer_to_handler_full, \
198 ret_from_except_full)
200 #define MCHECK_EXCEPTION(n, label, hdlr) \
201 START_EXCEPTION(label); \
202 MCHECK_EXCEPTION_PROLOG; \
205 addi r3,r1,STACK_FRAME_OVERHEAD; \
206 EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
207 NOCOPY, mcheck_transfer_to_handler, \
210 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \
220 #define COPY_EE(d, s) rlwimi d,s,0,16,16
223 #define EXC_XFER_STD(n, hdlr) \
224 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \
225 ret_from_except_full)
227 #define EXC_XFER_LITE(n, hdlr) \
228 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
231 #define EXC_XFER_EE(n, hdlr) \
232 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \
233 ret_from_except_full)
235 #define EXC_XFER_EE_LITE(n, hdlr) \
236 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
240 /* Check for a single step debug exception while in an exception
241 * handler before state has been saved. This is to catch the case
242 * where an instruction that we are trying to single step causes
243 * an exception (eg ITLB/DTLB miss) and thus the first instruction of
244 * the exception handler generates a single step debug exception.
246 * If we get a debug trap on the first instruction of an exception handler,
247 * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
248 * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
249 * The exception handler was handling a non-critical interrupt, so it will
250 * save (and later restore) the MSR via SPRN_CSRR1, which will still have
251 * the MSR_DE bit set.
253 #define DEBUG_EXCEPTION \
254 START_EXCEPTION(Debug); \
255 CRITICAL_EXCEPTION_PROLOG; \
258 * If there is a single step or branch-taken exception in an \
259 * exception entry sequence, it was probably meant to apply to \
260 * the code where the exception occurred (since exception entry \
261 * doesn't turn off DE automatically). We simulate the effect \
262 * of turning off DE on entry to an exception handler by turning \
263 * off DE in the CSRR1 value and clearing the debug status. \
265 mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
266 andis. r10,r10,DBSR_IC@h; \
269 lis r10,KERNELBASE@h; /* check if exception in vectors */ \
270 ori r10,r10,KERNELBASE@l; \
272 blt+ 2f; /* addr below exception vectors */ \
275 ori r10,r10,Debug@l; \
277 bgt+ 2f; /* addr above exception vectors */ \
279 /* here it looks like we got an inappropriate debug exception. */ \
280 1: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CSRR1 value */ \
281 lis r10,DBSR_IC@h; /* clear the IC event */ \
282 mtspr SPRN_DBSR,r10; \
283 /* restore state and get out */ \
291 lwz r12,GPR12(r11); \
292 mtspr SPRG2,r8; /* SPRG2 only used in criticals */ \
293 lis r8,crit_save@ha; \
294 lwz r10,crit_r10@l(r8); \
295 lwz r11,crit_r11@l(r8); \
301 /* continue normal handling for a critical exception... */ \
302 2: mfspr r4,SPRN_DBSR; \
303 addi r3,r1,STACK_FRAME_OVERHEAD; \
304 EXC_XFER_TEMPLATE(DebugException, 0x2002, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)
306 #define INSTRUCTION_STORAGE_EXCEPTION \
307 START_EXCEPTION(InstructionStorage) \
308 NORMAL_EXCEPTION_PROLOG; \
309 mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
311 mr r4,r12; /* Pass SRR0 as arg2 */ \
312 li r5,0; /* Pass zero as arg3 */ \
313 EXC_XFER_EE_LITE(0x0400, handle_page_fault)
315 #define ALIGNMENT_EXCEPTION \
316 START_EXCEPTION(Alignment) \
317 NORMAL_EXCEPTION_PROLOG; \
318 mfspr r4,SPRN_DEAR; /* Grab the DEAR and save it */ \
320 addi r3,r1,STACK_FRAME_OVERHEAD; \
321 EXC_XFER_EE(0x0600, AlignmentException)
323 #define PROGRAM_EXCEPTION \
324 START_EXCEPTION(Program) \
325 NORMAL_EXCEPTION_PROLOG; \
326 mfspr r4,SPRN_ESR; /* Grab the ESR and save it */ \
328 addi r3,r1,STACK_FRAME_OVERHEAD; \
329 EXC_XFER_STD(0x0700, ProgramCheckException)
331 #define DECREMENTER_EXCEPTION \
332 START_EXCEPTION(Decrementer) \
333 NORMAL_EXCEPTION_PROLOG; \
334 lis r0,TSR_DIS@h; /* Setup the DEC interrupt mask */ \
335 mtspr SPRN_TSR,r0; /* Clear the DEC interrupt */ \
336 addi r3,r1,STACK_FRAME_OVERHEAD; \
337 EXC_XFER_LITE(0x0900, timer_interrupt)
339 #endif /* __HEAD_BOOKE_H__ */