blob: 306e26c073a043b91d86f42c25075a2771760bf0 [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>
Scott Woodcfac5782011-12-20 15:34:40 +00008
Becky Bruce63dafe52006-01-14 16:57:39 -06009/*
10 * Macros used for common Book-e exception handling
11 */
12
13#define SET_IVOR(vector_number, vector_label) \
14 li r26,vector_label@l; \
15 mtspr SPRN_IVOR##vector_number,r26; \
16 sync
17
Yuri Tikhonove1240122009-01-29 01:40:44 +000018#if (THREAD_SHIFT < 15)
19#define ALLOC_STACK_FRAME(reg, val) \
20 addi reg,reg,val
21#else
22#define ALLOC_STACK_FRAME(reg, val) \
23 addis reg,reg,val@ha; \
24 addi reg,reg,val@l
25#endif
26
Ashish Kalra1325a682011-04-22 16:48:27 -050027/*
28 * Macro used to get to thread save registers.
29 * Note that entries 0-3 are used for the prolog code, and the remaining
30 * entries are available for specific exception use in the event a handler
31 * requires more than 4 scratch registers.
32 */
33#define THREAD_NORMSAVE(offset) (THREAD_NORMSAVES + (offset * 4))
34
Diana Craciun039daac2018-12-23 22:34:25 +020035#ifdef CONFIG_PPC_FSL_BOOK3E
36#define BOOKE_CLEAR_BTB(reg) \
37START_BTB_FLUSH_SECTION \
38 BTB_FLUSH(reg) \
39END_BTB_FLUSH_SECTION
40#else
41#define BOOKE_CLEAR_BTB(reg)
42#endif
43
44
Scott Woodcfac5782011-12-20 15:34:40 +000045#define NORMAL_EXCEPTION_PROLOG(intno) \
Ashish Kalra1325a682011-04-22 16:48:27 -050046 mtspr SPRN_SPRG_WSCRATCH0, r10; /* save one register */ \
47 mfspr r10, SPRN_SPRG_THREAD; \
48 stw r11, THREAD_NORMSAVE(0)(r10); \
49 stw r13, THREAD_NORMSAVE(2)(r10); \
50 mfcr r13; /* save CR in r13 for now */\
Scott Woodd30f6e42011-12-20 15:34:43 +000051 mfspr r11, SPRN_SRR1; \
52 DO_KVM BOOKE_INTERRUPT_##intno SPRN_SRR1; \
53 andi. r11, r11, MSR_PR; /* check whether user or kernel */\
Ashish Kalra1325a682011-04-22 16:48:27 -050054 mr r11, r1; \
Becky Bruce63dafe52006-01-14 16:57:39 -060055 beq 1f; \
Diana Craciun039daac2018-12-23 22:34:25 +020056 BOOKE_CLEAR_BTB(r11) \
Ashish Kalra1325a682011-04-22 16:48:27 -050057 /* if from user, start at top of this thread's kernel stack */ \
58 lwz r11, THREAD_INFO-THREAD(r10); \
59 ALLOC_STACK_FRAME(r11, THREAD_SIZE); \
601 : subi r11, r11, INT_FRAME_SIZE; /* Allocate exception frame */ \
61 stw r13, _CCR(r11); /* save various registers */ \
Becky Bruce63dafe52006-01-14 16:57:39 -060062 stw r12,GPR12(r11); \
63 stw r9,GPR9(r11); \
Ashish Kalra1325a682011-04-22 16:48:27 -050064 mfspr r13, SPRN_SPRG_RSCRATCH0; \
65 stw r13, GPR10(r11); \
66 lwz r12, THREAD_NORMSAVE(0)(r10); \
Becky Bruce63dafe52006-01-14 16:57:39 -060067 stw r12,GPR11(r11); \
Ashish Kalra1325a682011-04-22 16:48:27 -050068 lwz r13, THREAD_NORMSAVE(2)(r10); /* restore r13 */ \
Becky Bruce63dafe52006-01-14 16:57:39 -060069 mflr r10; \
70 stw r10,_LINK(r11); \
Becky Bruce63dafe52006-01-14 16:57:39 -060071 mfspr r12,SPRN_SRR0; \
Ashish Kalra1325a682011-04-22 16:48:27 -050072 stw r1, GPR1(r11); \
Becky Bruce63dafe52006-01-14 16:57:39 -060073 mfspr r9,SPRN_SRR1; \
Ashish Kalra1325a682011-04-22 16:48:27 -050074 stw r1, 0(r11); \
75 mr r1, r11; \
Becky Bruce63dafe52006-01-14 16:57:39 -060076 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
77 stw r0,GPR0(r11); \
Torez Smith471c70f2010-03-05 10:43:01 +000078 lis r10, STACK_FRAME_REGS_MARKER@ha;/* exception frame marker */ \
79 addi r10, r10, STACK_FRAME_REGS_MARKER@l; \
80 stw r10, 8(r11); \
Becky Bruce63dafe52006-01-14 16:57:39 -060081 SAVE_4GPRS(3, r11); \
82 SAVE_2GPRS(7, r11)
83
84/* To handle the additional exception priority levels on 40x and Book-E
Kumar Galabcf0b082008-04-30 03:49:55 -050085 * processors we allocate a stack per additional priority level.
Becky Bruce63dafe52006-01-14 16:57:39 -060086 *
87 * On 40x critical is the only additional level
88 * On 44x/e500 we have critical and machine check
89 * On e200 we have critical and debug (machine check occurs via critical)
90 *
91 * Additionally we reserve a SPRG for each priority level so we can free up a
92 * GPR to use as the base for indirect access to the exception stacks. This
93 * is necessary since the MMU is always on, for Book-E parts, and the stacks
94 * are offset from KERNELBASE.
95 *
Kumar Galaeb0cd5fd2008-04-09 06:06:11 -050096 * There is some space optimization to be had here if desired. However
97 * to allow for a common kernel with support for debug exceptions either
98 * going to critical or their own debug level we aren't currently
99 * providing configurations that micro-optimize space usage.
Becky Bruce63dafe52006-01-14 16:57:39 -0600100 */
Becky Bruce63dafe52006-01-14 16:57:39 -0600101
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000102#define MC_STACK_BASE mcheckirq_ctx
Kumar Galabcf0b082008-04-30 03:49:55 -0500103#define CRIT_STACK_BASE critirq_ctx
Becky Bruce63dafe52006-01-14 16:57:39 -0600104
Kumar Gala3dfa8772008-06-16 09:41:32 -0500105/* only on e500mc/e200 */
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000106#define DBG_STACK_BASE dbgirq_ctx
Becky Bruce63dafe52006-01-14 16:57:39 -0600107
Kumar Galafca622c2008-04-30 05:23:21 -0500108#define EXC_LVL_FRAME_OVERHEAD (THREAD_SIZE - INT_FRAME_SIZE - EXC_LVL_SIZE)
Kumar Gala369e7572008-04-30 04:17:22 -0500109
Becky Bruce63dafe52006-01-14 16:57:39 -0600110#ifdef CONFIG_SMP
111#define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
112 mfspr r8,SPRN_PIR; \
Kumar Galabcf0b082008-04-30 03:49:55 -0500113 slwi r8,r8,2; \
114 addis r8,r8,level##_STACK_BASE@ha; \
115 lwz r8,level##_STACK_BASE@l(r8); \
Kumar Gala369e7572008-04-30 04:17:22 -0500116 addi r8,r8,EXC_LVL_FRAME_OVERHEAD;
Becky Bruce63dafe52006-01-14 16:57:39 -0600117#else
118#define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
Kumar Galabcf0b082008-04-30 03:49:55 -0500119 lis r8,level##_STACK_BASE@ha; \
120 lwz r8,level##_STACK_BASE@l(r8); \
Kumar Gala369e7572008-04-30 04:17:22 -0500121 addi r8,r8,EXC_LVL_FRAME_OVERHEAD;
Becky Bruce63dafe52006-01-14 16:57:39 -0600122#endif
123
124/*
125 * Exception prolog for critical/machine check exceptions. This is a
126 * little different from the normal exception prolog above since a
127 * critical/machine check exception can potentially occur at any point
128 * during normal exception processing. Thus we cannot use the same SPRG
129 * registers as the normal prolog above. Instead we use a portion of the
130 * critical/machine check exception stack at low physical addresses.
131 */
Scott Woodcfac5782011-12-20 15:34:40 +0000132#define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, intno, exc_level_srr0, exc_level_srr1) \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000133 mtspr SPRN_SPRG_WSCRATCH_##exc_level,r8; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600134 BOOKE_LOAD_EXC_LEVEL_STACK(exc_level);/* r8 points to the exc_level stack*/ \
Kumar Gala369e7572008-04-30 04:17:22 -0500135 stw r9,GPR9(r8); /* save various registers */\
136 mfcr r9; /* save CR in r9 for now */\
137 stw r10,GPR10(r8); \
138 stw r11,GPR11(r8); \
139 stw r9,_CCR(r8); /* save CR on stack */\
Scott Woodd30f6e42011-12-20 15:34:43 +0000140 mfspr r11,exc_level_srr1; /* check whether user or kernel */\
141 DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \
Diana Craciun039daac2018-12-23 22:34:25 +0200142 BOOKE_CLEAR_BTB(r10) \
Scott Woodd30f6e42011-12-20 15:34:43 +0000143 andi. r11,r11,MSR_PR; \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000144 mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\
Becky Bruce63dafe52006-01-14 16:57:39 -0600145 lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
Kumar Gala369e7572008-04-30 04:17:22 -0500146 addi r11,r11,EXC_LVL_FRAME_OVERHEAD; /* allocate stack frame */\
147 beq 1f; \
148 /* COMING FROM USER MODE */ \
149 stw r9,_CCR(r11); /* save CR */\
150 lwz r10,GPR10(r8); /* copy regs from exception stack */\
151 lwz r9,GPR9(r8); \
152 stw r10,GPR10(r11); \
153 lwz r10,GPR11(r8); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600154 stw r9,GPR9(r11); \
Kumar Gala369e7572008-04-30 04:17:22 -0500155 stw r10,GPR11(r11); \
156 b 2f; \
157 /* COMING FROM PRIV MODE */ \
1581: lwz r9,TI_FLAGS-EXC_LVL_FRAME_OVERHEAD(r11); \
159 lwz r10,TI_PREEMPT-EXC_LVL_FRAME_OVERHEAD(r11); \
160 stw r9,TI_FLAGS-EXC_LVL_FRAME_OVERHEAD(r8); \
161 stw r10,TI_PREEMPT-EXC_LVL_FRAME_OVERHEAD(r8); \
162 lwz r9,TI_TASK-EXC_LVL_FRAME_OVERHEAD(r11); \
163 stw r9,TI_TASK-EXC_LVL_FRAME_OVERHEAD(r8); \
164 mr r11,r8; \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +00001652: mfspr r8,SPRN_SPRG_RSCRATCH_##exc_level; \
Kumar Gala369e7572008-04-30 04:17:22 -0500166 stw r12,GPR12(r11); /* save various registers */\
Becky Bruce63dafe52006-01-14 16:57:39 -0600167 mflr r10; \
168 stw r10,_LINK(r11); \
169 mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
170 stw r12,_DEAR(r11); /* since they may have had stuff */\
171 mfspr r9,SPRN_ESR; /* in them at the point where the */\
172 stw r9,_ESR(r11); /* exception was taken */\
173 mfspr r12,exc_level_srr0; \
174 stw r1,GPR1(r11); \
175 mfspr r9,exc_level_srr1; \
176 stw r1,0(r11); \
177 mr r1,r11; \
178 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
179 stw r0,GPR0(r11); \
180 SAVE_4GPRS(3, r11); \
181 SAVE_2GPRS(7, r11)
182
Scott Woodcfac5782011-12-20 15:34:40 +0000183#define CRITICAL_EXCEPTION_PROLOG(intno) \
184 EXC_LEVEL_EXCEPTION_PROLOG(CRIT, intno, SPRN_CSRR0, SPRN_CSRR1)
Becky Bruce63dafe52006-01-14 16:57:39 -0600185#define DEBUG_EXCEPTION_PROLOG \
Scott Woodcfac5782011-12-20 15:34:40 +0000186 EXC_LEVEL_EXCEPTION_PROLOG(DBG, DEBUG, SPRN_DSRR0, SPRN_DSRR1)
Becky Bruce63dafe52006-01-14 16:57:39 -0600187#define MCHECK_EXCEPTION_PROLOG \
Scott Woodcfac5782011-12-20 15:34:40 +0000188 EXC_LEVEL_EXCEPTION_PROLOG(MC, MACHINE_CHECK, \
189 SPRN_MCSRR0, SPRN_MCSRR1)
Becky Bruce63dafe52006-01-14 16:57:39 -0600190
191/*
Scott Woodd30f6e42011-12-20 15:34:43 +0000192 * Guest Doorbell -- this is a bit odd in that uses GSRR0/1 despite
193 * being delivered to the host. This exception can only happen
194 * inside a KVM guest -- so we just handle up to the DO_KVM rather
195 * than try to fit this into one of the existing prolog macros.
196 */
197#define GUEST_DOORBELL_EXCEPTION \
198 START_EXCEPTION(GuestDoorbell); \
199 mtspr SPRN_SPRG_WSCRATCH0, r10; /* save one register */ \
200 mfspr r10, SPRN_SPRG_THREAD; \
201 stw r11, THREAD_NORMSAVE(0)(r10); \
202 mfspr r11, SPRN_SRR1; \
203 stw r13, THREAD_NORMSAVE(2)(r10); \
204 mfcr r13; /* save CR in r13 for now */\
205 DO_KVM BOOKE_INTERRUPT_GUEST_DBELL SPRN_GSRR1; \
206 trap
207
208/*
Becky Bruce63dafe52006-01-14 16:57:39 -0600209 * Exception vectors.
210 */
211#define START_EXCEPTION(label) \
212 .align 5; \
213label:
214
Scott Woodcfac5782011-12-20 15:34:40 +0000215#define EXCEPTION(n, intno, label, hdlr, xfer) \
Becky Bruce63dafe52006-01-14 16:57:39 -0600216 START_EXCEPTION(label); \
Scott Woodcfac5782011-12-20 15:34:40 +0000217 NORMAL_EXCEPTION_PROLOG(intno); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600218 addi r3,r1,STACK_FRAME_OVERHEAD; \
219 xfer(n, hdlr)
220
Scott Woodcfac5782011-12-20 15:34:40 +0000221#define CRITICAL_EXCEPTION(n, intno, label, hdlr) \
222 START_EXCEPTION(label); \
223 CRITICAL_EXCEPTION_PROLOG(intno); \
224 addi r3,r1,STACK_FRAME_OVERHEAD; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600225 EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
226 NOCOPY, crit_transfer_to_handler, \
227 ret_from_crit_exc)
228
229#define MCHECK_EXCEPTION(n, label, hdlr) \
230 START_EXCEPTION(label); \
231 MCHECK_EXCEPTION_PROLOG; \
232 mfspr r5,SPRN_ESR; \
233 stw r5,_ESR(r11); \
234 addi r3,r1,STACK_FRAME_OVERHEAD; \
Benjamin Herrenschmidt47c0bd12007-12-21 15:39:21 +1100235 EXC_XFER_TEMPLATE(hdlr, n+4, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
Becky Bruce63dafe52006-01-14 16:57:39 -0600236 NOCOPY, mcheck_transfer_to_handler, \
237 ret_from_mcheck_exc)
238
239#define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \
240 li r10,trap; \
241 stw r10,_TRAP(r11); \
242 lis r10,msr@h; \
243 ori r10,r10,msr@l; \
244 copyee(r10, r9); \
245 bl tfer; \
246 .long hdlr; \
247 .long ret
248
249#define COPY_EE(d, s) rlwimi d,s,0,16,16
250#define NOCOPY(d, s)
251
252#define EXC_XFER_STD(n, hdlr) \
253 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \
254 ret_from_except_full)
255
256#define EXC_XFER_LITE(n, hdlr) \
257 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
258 ret_from_except)
259
260#define EXC_XFER_EE(n, hdlr) \
261 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \
262 ret_from_except_full)
263
264#define EXC_XFER_EE_LITE(n, hdlr) \
265 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
266 ret_from_except)
267
268/* Check for a single step debug exception while in an exception
269 * handler before state has been saved. This is to catch the case
270 * where an instruction that we are trying to single step causes
271 * an exception (eg ITLB/DTLB miss) and thus the first instruction of
272 * the exception handler generates a single step debug exception.
273 *
274 * If we get a debug trap on the first instruction of an exception handler,
275 * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
276 * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
277 * The exception handler was handling a non-critical interrupt, so it will
278 * save (and later restore) the MSR via SPRN_CSRR1, which will still have
279 * the MSR_DE bit set.
280 */
Kumar Galaeb0cd5fd2008-04-09 06:06:11 -0500281#define DEBUG_DEBUG_EXCEPTION \
282 START_EXCEPTION(DebugDebug); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600283 DEBUG_EXCEPTION_PROLOG; \
284 \
285 /* \
286 * If there is a single step or branch-taken exception in an \
287 * exception entry sequence, it was probably meant to apply to \
288 * the code where the exception occurred (since exception entry \
289 * doesn't turn off DE automatically). We simulate the effect \
290 * of turning off DE on entry to an exception handler by turning \
Kumar Galafec6a822008-06-11 13:07:26 -0500291 * off DE in the DSRR1 value and clearing the debug status. \
Becky Bruce63dafe52006-01-14 16:57:39 -0600292 */ \
293 mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000294 andis. r10,r10,(DBSR_IC|DBSR_BT)@h; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600295 beq+ 2f; \
296 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000297 lis r10,interrupt_base@h; /* check if exception in vectors */ \
298 ori r10,r10,interrupt_base@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600299 cmplw r12,r10; \
300 blt+ 2f; /* addr below exception vectors */ \
301 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000302 lis r10,interrupt_end@h; \
303 ori r10,r10,interrupt_end@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600304 cmplw r12,r10; \
305 bgt+ 2f; /* addr above exception vectors */ \
306 \
307 /* here it looks like we got an inappropriate debug exception. */ \
3081: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CDRR1 value */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000309 lis r10,(DBSR_IC|DBSR_BT)@h; /* clear the IC event */ \
Becky Bruce63dafe52006-01-14 16:57:39 -0600310 mtspr SPRN_DBSR,r10; \
311 /* restore state and get out */ \
312 lwz r10,_CCR(r11); \
313 lwz r0,GPR0(r11); \
314 lwz r1,GPR1(r11); \
315 mtcrf 0x80,r10; \
316 mtspr SPRN_DSRR0,r12; \
317 mtspr SPRN_DSRR1,r9; \
318 lwz r9,GPR9(r11); \
319 lwz r12,GPR12(r11); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000320 mtspr SPRN_SPRG_WSCRATCH_DBG,r8; \
321 BOOKE_LOAD_EXC_LEVEL_STACK(DBG); /* r8 points to the debug stack */ \
Kumar Gala369e7572008-04-30 04:17:22 -0500322 lwz r10,GPR10(r8); \
323 lwz r11,GPR11(r8); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000324 mfspr r8,SPRN_SPRG_RSCRATCH_DBG; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600325 \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000326 PPC_RFDI; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600327 b .; \
328 \
Kumar Galafec6a822008-06-11 13:07:26 -0500329 /* continue normal handling for a debug exception... */ \
Becky Bruce63dafe52006-01-14 16:57:39 -06003302: mfspr r4,SPRN_DBSR; \
331 addi r3,r1,STACK_FRAME_OVERHEAD; \
Kumar Gala663276b2008-04-30 20:44:53 +1000332 EXC_XFER_TEMPLATE(DebugException, 0x2008, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, debug_transfer_to_handler, ret_from_debug_exc)
Kumar Galaeb0cd5fd2008-04-09 06:06:11 -0500333
334#define DEBUG_CRIT_EXCEPTION \
335 START_EXCEPTION(DebugCrit); \
Scott Woodcfac5782011-12-20 15:34:40 +0000336 CRITICAL_EXCEPTION_PROLOG(DEBUG); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600337 \
338 /* \
339 * If there is a single step or branch-taken exception in an \
340 * exception entry sequence, it was probably meant to apply to \
341 * the code where the exception occurred (since exception entry \
342 * doesn't turn off DE automatically). We simulate the effect \
343 * of turning off DE on entry to an exception handler by turning \
344 * off DE in the CSRR1 value and clearing the debug status. \
345 */ \
346 mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000347 andis. r10,r10,(DBSR_IC|DBSR_BT)@h; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600348 beq+ 2f; \
349 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000350 lis r10,interrupt_base@h; /* check if exception in vectors */ \
351 ori r10,r10,interrupt_base@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600352 cmplw r12,r10; \
353 blt+ 2f; /* addr below exception vectors */ \
354 \
Bharat Bhushanfc2a6cfe2013-04-29 22:18:11 +0000355 lis r10,interrupt_end@h; \
356 ori r10,r10,interrupt_end@l; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600357 cmplw r12,r10; \
358 bgt+ 2f; /* addr above exception vectors */ \
359 \
360 /* here it looks like we got an inappropriate debug exception. */ \
3611: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CSRR1 value */ \
Roland McGrathec097c82009-05-28 21:26:38 +0000362 lis r10,(DBSR_IC|DBSR_BT)@h; /* clear the IC event */ \
Becky Bruce63dafe52006-01-14 16:57:39 -0600363 mtspr SPRN_DBSR,r10; \
364 /* restore state and get out */ \
365 lwz r10,_CCR(r11); \
366 lwz r0,GPR0(r11); \
367 lwz r1,GPR1(r11); \
368 mtcrf 0x80,r10; \
369 mtspr SPRN_CSRR0,r12; \
370 mtspr SPRN_CSRR1,r9; \
371 lwz r9,GPR9(r11); \
372 lwz r12,GPR12(r11); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000373 mtspr SPRN_SPRG_WSCRATCH_CRIT,r8; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600374 BOOKE_LOAD_EXC_LEVEL_STACK(CRIT); /* r8 points to the debug stack */ \
Kumar Gala369e7572008-04-30 04:17:22 -0500375 lwz r10,GPR10(r8); \
376 lwz r11,GPR11(r8); \
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000377 mfspr r8,SPRN_SPRG_RSCRATCH_CRIT; \
Becky Bruce63dafe52006-01-14 16:57:39 -0600378 \
379 rfci; \
380 b .; \
381 \
382 /* continue normal handling for a critical exception... */ \
3832: mfspr r4,SPRN_DBSR; \
384 addi r3,r1,STACK_FRAME_OVERHEAD; \
385 EXC_XFER_TEMPLATE(DebugException, 0x2002, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)
Becky Bruce63dafe52006-01-14 16:57:39 -0600386
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000387#define DATA_STORAGE_EXCEPTION \
388 START_EXCEPTION(DataStorage) \
Scott Woodcfac5782011-12-20 15:34:40 +0000389 NORMAL_EXCEPTION_PROLOG(DATA_STORAGE); \
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000390 mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
391 stw r5,_ESR(r11); \
392 mfspr r4,SPRN_DEAR; /* Grab the DEAR */ \
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100393 EXC_XFER_LITE(0x0300, handle_page_fault)
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000394
Becky Bruce63dafe52006-01-14 16:57:39 -0600395#define INSTRUCTION_STORAGE_EXCEPTION \
396 START_EXCEPTION(InstructionStorage) \
Scott Woodcfac5782011-12-20 15:34:40 +0000397 NORMAL_EXCEPTION_PROLOG(INST_STORAGE); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600398 mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
399 stw r5,_ESR(r11); \
400 mr r4,r12; /* Pass SRR0 as arg2 */ \
401 li r5,0; /* Pass zero as arg3 */ \
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +1100402 EXC_XFER_LITE(0x0400, handle_page_fault)
Becky Bruce63dafe52006-01-14 16:57:39 -0600403
404#define ALIGNMENT_EXCEPTION \
405 START_EXCEPTION(Alignment) \
Scott Woodcfac5782011-12-20 15:34:40 +0000406 NORMAL_EXCEPTION_PROLOG(ALIGNMENT); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600407 mfspr r4,SPRN_DEAR; /* Grab the DEAR and save it */ \
408 stw r4,_DEAR(r11); \
409 addi r3,r1,STACK_FRAME_OVERHEAD; \
410 EXC_XFER_EE(0x0600, alignment_exception)
411
412#define PROGRAM_EXCEPTION \
413 START_EXCEPTION(Program) \
Scott Woodcfac5782011-12-20 15:34:40 +0000414 NORMAL_EXCEPTION_PROLOG(PROGRAM); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600415 mfspr r4,SPRN_ESR; /* Grab the ESR and save it */ \
416 stw r4,_ESR(r11); \
417 addi r3,r1,STACK_FRAME_OVERHEAD; \
418 EXC_XFER_STD(0x0700, program_check_exception)
419
420#define DECREMENTER_EXCEPTION \
421 START_EXCEPTION(Decrementer) \
Scott Woodcfac5782011-12-20 15:34:40 +0000422 NORMAL_EXCEPTION_PROLOG(DECREMENTER); \
Becky Bruce63dafe52006-01-14 16:57:39 -0600423 lis r0,TSR_DIS@h; /* Setup the DEC interrupt mask */ \
424 mtspr SPRN_TSR,r0; /* Clear the DEC interrupt */ \
425 addi r3,r1,STACK_FRAME_OVERHEAD; \
426 EXC_XFER_LITE(0x0900, timer_interrupt)
427
428#define FP_UNAVAILABLE_EXCEPTION \
429 START_EXCEPTION(FloatingPointUnavailable) \
Scott Woodcfac5782011-12-20 15:34:40 +0000430 NORMAL_EXCEPTION_PROLOG(FP_UNAVAIL); \
Michael Neuling6f3d8e62008-06-25 14:07:18 +1000431 beq 1f; \
432 bl load_up_fpu; /* if from user, just load it up */ \
433 b fast_exception_return; \
4341: addi r3,r1,STACK_FRAME_OVERHEAD; \
Becky Bruce66f2d022006-01-31 17:52:59 -0600435 EXC_XFER_EE_LITE(0x800, kernel_fp_unavailable_exception)
Becky Bruce63dafe52006-01-14 16:57:39 -0600436
Kumar Galafca622c2008-04-30 05:23:21 -0500437#ifndef __ASSEMBLY__
438struct exception_regs {
439 unsigned long mas0;
440 unsigned long mas1;
441 unsigned long mas2;
442 unsigned long mas3;
443 unsigned long mas6;
444 unsigned long mas7;
445 unsigned long srr0;
446 unsigned long srr1;
447 unsigned long csrr0;
448 unsigned long csrr1;
449 unsigned long dsrr0;
450 unsigned long dsrr1;
451 unsigned long saved_ksp_limit;
452};
453
454/* ensure this structure is always sized to a multiple of the stack alignment */
455#define STACK_EXC_LVL_FRAME_SIZE _ALIGN_UP(sizeof (struct exception_regs), 16)
456
457#endif /* __ASSEMBLY__ */
Becky Bruce63dafe52006-01-14 16:57:39 -0600458#endif /* __HEAD_BOOKE_H__ */