blob: 655f25d139a74ee93e409477789f848f0f5062e3 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz2a12c462010-03-11 16:24:18 +00002 * Main exception handling logic.
3 *
4 * Copyright 2004-2010 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07005 *
Robin Getz96f10502009-09-24 14:11:24 +00006 * Licensed under the GPL-2 or later
Bryan Wu1394f032007-05-06 14:50:22 -07007 */
8
Mike Frysinger70f12562009-06-07 17:18:25 -04009#include <linux/bug.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080010#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -070011#include <linux/module.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080012#include <asm/traps.h>
Mike Frysingerf4585a02008-10-13 14:45:21 +080013#include <asm/cplb.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080014#include <asm/blackfin.h>
15#include <asm/irq_handler.h>
Robin Getzd8f66c82007-12-24 15:27:56 +080016#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080017#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080018#include <asm/fixed_code.h>
Robin Getz6ce3e9c2010-03-16 14:40:17 +000019#include <asm/pseudo_instructions.h>
Bryan Wu1394f032007-05-06 14:50:22 -070020
21#ifdef CONFIG_KGDB
Bryan Wu1394f032007-05-06 14:50:22 -070022# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080023
24# define CHK_DEBUGGER_TRAP() \
25 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080026 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080027 } while (0)
28# define CHK_DEBUGGER_TRAP_MAYBE() \
29 do { \
30 if (kgdb_connected) \
31 CHK_DEBUGGER_TRAP(); \
32 } while (0)
33#else
34# define CHK_DEBUGGER_TRAP() do { } while (0)
35# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070036#endif
37
Robin Getz9f06c382008-10-10 18:13:21 +080038
Robin Getz4ee1c452008-10-28 11:36:11 +080039#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +080040#define verbose_printk(fmt, arg...) \
41 printk(fmt, ##arg)
42#else
43#define verbose_printk(fmt, arg...) \
44 ({ if (0) printk(fmt, ##arg); 0; })
45#endif
46
Robin Getz81f7f452009-06-03 18:58:26 +000047#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
48u32 last_seqstat;
49#ifdef CONFIG_DEBUG_MMRS_MODULE
50EXPORT_SYMBOL(last_seqstat);
51#endif
52#endif
53
Bryan Wu1394f032007-05-06 14:50:22 -070054/* Initiate the event table handler */
55void __init trap_init(void)
56{
57 CSYNC();
58 bfin_write_EVT3(trap);
59 CSYNC();
60}
61
Mike Frysinger82bd1d72009-06-07 17:08:28 -040062static int kernel_mode_regs(struct pt_regs *regs)
63{
64 return regs->ipend & 0xffc0;
65}
66
Yi Lic4baebf2009-08-12 23:05:35 +000067asmlinkage notrace void trap_c(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -070068{
Robin Getz518039b2007-07-25 11:03:28 +080069#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
70 int j;
71#endif
Robin Getz6ce3e9c2010-03-16 14:40:17 +000072#ifdef CONFIG_BFIN_PSEUDODBG_INSNS
73 int opcode;
74#endif
Yi Lib6dbde22009-08-20 04:17:47 +000075 unsigned int cpu = raw_smp_processor_id();
Mike Frysinger82bd1d72009-06-07 17:08:28 -040076 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +080077 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -070078 siginfo_t info;
79 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
80
Bryan Wu1394f032007-05-06 14:50:22 -070081 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +000082#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
83 last_seqstat = (u32)fp->seqstat;
84#endif
Bryan Wu1394f032007-05-06 14:50:22 -070085
Robin Getz226eb1e2007-10-29 17:59:07 +080086 /* Important - be very careful dereferncing pointers - will lead to
87 * double faults if the stack has become corrupt
88 */
89
Bryan Wu1394f032007-05-06 14:50:22 -070090 /* trap_c() will be called for exceptions. During exceptions
91 * processing, the pc value should be set with retx value.
92 * With this change we can cleanup some code in signal.c- TODO
93 */
94 fp->orig_pc = fp->retx;
95 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
96 trapnr, fp->ipend, fp->pc, fp->retx); */
97
98 /* send the appropriate signal to the user program */
99 switch (trapnr) {
100
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300101 /* This table works in conjunction with the one in ./mach-common/entry.S
Bryan Wu1394f032007-05-06 14:50:22 -0700102 * Some exceptions are handled there (in assembly, in exception space)
103 * Some are handled here, (in C, in interrupt space)
104 * Some, like CPLB, are handled in both, where the normal path is
105 * handled in assembly/exception space, and the error path is handled
106 * here
107 */
108
109 /* 0x00 - Linux Syscall, getting here is an error */
110 /* 0x01 - userspace gdb breakpoint, handled here */
111 case VEC_EXCPT01:
112 info.si_code = TRAP_ILLTRAP;
113 sig = SIGTRAP;
114 CHK_DEBUGGER_TRAP_MAYBE();
115 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400116 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400117 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700118 else
119 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800120 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700121 case VEC_EXCPT03:
122 info.si_code = SEGV_STACKFLOW;
123 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400124 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800125 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700126 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800127 /* 0x02 - KGDB initial connection and break signal trap */
128 case VEC_EXCPT02:
129#ifdef CONFIG_KGDB
130 info.si_code = TRAP_ILLTRAP;
131 sig = SIGTRAP;
132 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400133 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800134#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800135 /* 0x04 - User Defined */
136 /* 0x05 - User Defined */
137 /* 0x06 - User Defined */
138 /* 0x07 - User Defined */
139 /* 0x08 - User Defined */
140 /* 0x09 - User Defined */
141 /* 0x0A - User Defined */
142 /* 0x0B - User Defined */
143 /* 0x0C - User Defined */
144 /* 0x0D - User Defined */
145 /* 0x0E - User Defined */
146 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800147 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800148 * custom exception handler, and it is not actually installed properly
149 */
150 case VEC_EXCPT04 ... VEC_EXCPT15:
151 info.si_code = ILL_ILLPARAOP;
152 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400153 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800154 CHK_DEBUGGER_TRAP_MAYBE();
155 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700156 /* 0x10 HW Single step, handled here */
157 case VEC_STEP:
158 info.si_code = TRAP_STEP;
159 sig = SIGTRAP;
160 CHK_DEBUGGER_TRAP_MAYBE();
161 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400162 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400163 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700164 else
165 break;
166 /* 0x11 - Trace Buffer Full, handled here */
167 case VEC_OVFLOW:
168 info.si_code = TRAP_TRACEFLOW;
169 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400170 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800171 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700172 break;
173 /* 0x12 - Reserved, Caught by default */
174 /* 0x13 - Reserved, Caught by default */
175 /* 0x14 - Reserved, Caught by default */
176 /* 0x15 - Reserved, Caught by default */
177 /* 0x16 - Reserved, Caught by default */
178 /* 0x17 - Reserved, Caught by default */
179 /* 0x18 - Reserved, Caught by default */
180 /* 0x19 - Reserved, Caught by default */
181 /* 0x1A - Reserved, Caught by default */
182 /* 0x1B - Reserved, Caught by default */
183 /* 0x1C - Reserved, Caught by default */
184 /* 0x1D - Reserved, Caught by default */
185 /* 0x1E - Reserved, Caught by default */
186 /* 0x1F - Reserved, Caught by default */
187 /* 0x20 - Reserved, Caught by default */
188 /* 0x21 - Undefined Instruction, handled here */
189 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400190#ifdef CONFIG_BUG
191 if (kernel_mode_regs(fp)) {
192 switch (report_bug(fp->pc, fp)) {
193 case BUG_TRAP_TYPE_NONE:
194 break;
195 case BUG_TRAP_TYPE_WARN:
196 dump_bfin_trace_buffer();
197 fp->pc += 2;
198 goto traps_done;
199 case BUG_TRAP_TYPE_BUG:
200 /* call to panic() will dump trace, and it is
201 * off at this point, so it won't be clobbered
202 */
203 panic("BUG()");
204 }
205 }
206#endif
Robin Getz6ce3e9c2010-03-16 14:40:17 +0000207#ifdef CONFIG_BFIN_PSEUDODBG_INSNS
208 /*
209 * Support for the fake instructions, if the instruction fails,
210 * then just execute a illegal opcode failure (like normal).
211 * Don't support these instructions inside the kernel
212 */
213 if (!kernel_mode_regs(fp) && get_instruction(&opcode, (unsigned short *)fp->pc)) {
214 if (execute_pseudodbg_assert(fp, opcode))
215 goto traps_done;
Robin Getzdc89d972010-03-28 12:50:53 +0000216 if (execute_pseudodbg(fp, opcode))
217 goto traps_done;
Robin Getz6ce3e9c2010-03-16 14:40:17 +0000218 }
219#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700220 info.si_code = ILL_ILLOPC;
221 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400222 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800223 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700224 break;
225 /* 0x22 - Illegal Instruction Combination, handled here */
226 case VEC_ILGAL_I:
227 info.si_code = ILL_ILLPARAOP;
228 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400229 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800230 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700231 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800232 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700233 case VEC_CPLB_VL:
234 info.si_code = ILL_CPLB_VI;
Graf Yang36b84122009-07-21 02:26:57 +0000235 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400236 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800237 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700238 break;
239 /* 0x24 - Data access misaligned, handled here */
240 case VEC_MISALI_D:
241 info.si_code = BUS_ADRALN;
242 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400243 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800244 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700245 break;
246 /* 0x25 - Unrecoverable Event, handled here */
247 case VEC_UNCOV:
248 info.si_code = ILL_ILLEXCPT;
249 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400250 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800251 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700252 break;
253 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
254 error case is handled here */
255 case VEC_CPLB_M:
256 info.si_code = BUS_ADRALN;
257 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400258 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700259 break;
260 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
261 case VEC_CPLB_MHIT:
262 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700263 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800264#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800265 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400266 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800267 else
Bryan Wu1394f032007-05-06 14:50:22 -0700268#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400269 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800270 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700271 break;
272 /* 0x28 - Emulation Watchpoint, handled here */
273 case VEC_WATCH:
274 info.si_code = TRAP_WATCHPT;
275 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800276 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700277 CHK_DEBUGGER_TRAP_MAYBE();
278 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400279 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400280 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700281 else
282 break;
283#ifdef CONFIG_BF535
284 /* 0x29 - Instruction fetch access error (535 only) */
285 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
286 info.si_code = BUS_OPFETCH;
287 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400288 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800289 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700290 break;
291#else
292 /* 0x29 - Reserved, Caught by default */
293#endif
294 /* 0x2A - Instruction fetch misaligned, handled here */
295 case VEC_MISALI_I:
296 info.si_code = BUS_ADRALN;
297 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400298 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800299 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700300 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800301 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700302 case VEC_CPLB_I_VL:
303 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800304 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400305 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800306 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700307 break;
308 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
309 case VEC_CPLB_I_M:
310 info.si_code = ILL_CPLB_MISS;
311 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400312 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700313 break;
314 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
315 case VEC_CPLB_I_MHIT:
316 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700317 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800318#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800319 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400320 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800321 else
Bryan Wu1394f032007-05-06 14:50:22 -0700322#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400323 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800324 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700325 break;
326 /* 0x2E - Illegal use of Supervisor Resource, handled here */
327 case VEC_ILL_RES:
328 info.si_code = ILL_PRVOPC;
329 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400330 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800331 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700332 break;
333 /* 0x2F - Reserved, Caught by default */
334 /* 0x30 - Reserved, Caught by default */
335 /* 0x31 - Reserved, Caught by default */
336 /* 0x32 - Reserved, Caught by default */
337 /* 0x33 - Reserved, Caught by default */
338 /* 0x34 - Reserved, Caught by default */
339 /* 0x35 - Reserved, Caught by default */
340 /* 0x36 - Reserved, Caught by default */
341 /* 0x37 - Reserved, Caught by default */
342 /* 0x38 - Reserved, Caught by default */
343 /* 0x39 - Reserved, Caught by default */
344 /* 0x3A - Reserved, Caught by default */
345 /* 0x3B - Reserved, Caught by default */
346 /* 0x3C - Reserved, Caught by default */
347 /* 0x3D - Reserved, Caught by default */
348 /* 0x3E - Reserved, Caught by default */
349 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800350 case VEC_HWERR:
351 info.si_code = BUS_ADRALN;
352 sig = SIGBUS;
353 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
354 /* System MMR Error */
355 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
356 info.si_code = BUS_ADRALN;
357 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400358 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800359 break;
360 /* External Memory Addressing Error */
361 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
Barry Songa00b4fe2009-11-27 09:18:21 +0000362 if (ANOMALY_05000310) {
363 static unsigned long anomaly_rets;
364
365 if ((fp->pc >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
366 (fp->pc < (L1_CODE_START + L1_CODE_LENGTH))) {
367 /*
368 * A false hardware error will happen while fetching at
369 * the L1 instruction SRAM boundary. Ignore it.
370 */
371 anomaly_rets = fp->rets;
372 goto traps_done;
373 } else if (fp->rets == anomaly_rets) {
374 /*
375 * While boundary code returns to a function, at the ret
376 * point, a new false hardware error might occur too based
377 * on tests. Ignore it too.
378 */
379 goto traps_done;
380 } else if ((fp->rets >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
381 (fp->rets < (L1_CODE_START + L1_CODE_LENGTH))) {
382 /*
383 * If boundary code calls a function, at the entry point,
384 * a new false hardware error maybe happen based on tests.
385 * Ignore it too.
386 */
387 goto traps_done;
388 } else
389 anomaly_rets = 0;
390 }
391
Robin Getz13fe24f2008-01-27 15:38:56 +0800392 info.si_code = BUS_ADRERR;
393 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400394 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800395 break;
396 /* Performance Monitor Overflow */
397 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400398 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800399 break;
400 /* RAISE 5 instruction */
401 case (SEQSTAT_HWERRCAUSE_RAISE_5):
402 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
403 break;
404 default: /* Reserved */
405 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
406 break;
407 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800408 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800409 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800410 /*
411 * We should be handling all known exception types above,
412 * if we get here we hit a reserved one, so panic
413 */
Bryan Wu1394f032007-05-06 14:50:22 -0700414 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800415 info.si_code = ILL_ILLPARAOP;
416 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800417 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700418 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800419 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700420 break;
421 }
422
Robin Getz226eb1e2007-10-29 17:59:07 +0800423 BUG_ON(sig == 0);
424
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400425 /* If the fault was caused by a kernel thread, or interrupt handler
426 * we will kernel panic, so the system reboots.
427 */
428 if (kernel_mode_regs(fp) || (current && !current->mm)) {
429 console_verbose();
430 oops_in_progress = 1;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400431 }
432
Robin Getz226eb1e2007-10-29 17:59:07 +0800433 if (sig != SIGTRAP) {
Mike Frysinger15627bd2009-06-23 11:21:34 +0000434 if (strerror)
435 verbose_printk(strerror);
436
Mike Frysinger49dce912007-11-21 16:46:49 +0800437 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800438 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800439 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800440
441 /* Print out the trace buffer if it makes sense */
442#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
443 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800444 verbose_printk(KERN_NOTICE "No trace since you do not have "
Joe Perchesad361c92009-07-06 13:05:40 -0700445 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800446 else
447#endif
448 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800449
Robin Getz226eb1e2007-10-29 17:59:07 +0800450 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800451 /* Dump the current kernel stack */
Joe Perchesad361c92009-07-06 13:05:40 -0700452 verbose_printk(KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800453 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800454 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800455#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800456 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800457 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800458#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700459 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800460 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800461#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800462 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800463 /* Dump the user space stack */
464 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800465 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800466 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800467#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800468 }
Bryan Wu1394f032007-05-06 14:50:22 -0700469 }
Robin Getzfb322912007-11-21 16:38:05 +0800470
Yi Li6a01f232009-01-07 23:14:39 +0800471#ifdef CONFIG_IPIPE
472 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
473#endif
474 {
475 info.si_signo = sig;
476 info.si_errno = 0;
Barry Song5e8d3212010-01-19 11:01:08 +0000477 switch (trapnr) {
478 case VEC_CPLB_VL:
479 case VEC_MISALI_D:
480 case VEC_CPLB_M:
481 case VEC_CPLB_MHIT:
482 info.si_addr = (void __user *)cpu_pda[cpu].dcplb_fault_addr;
483 break;
484 default:
485 info.si_addr = (void __user *)fp->pc;
486 break;
487 }
Yi Li6a01f232009-01-07 23:14:39 +0800488 force_sig_info(sig, &info, current);
489 }
Bryan Wu1394f032007-05-06 14:50:22 -0700490
Robin Getz0e4edcf2009-06-22 20:23:48 +0000491 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
Robin Getzf574a762009-07-09 15:11:52 +0000492 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
493 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
Robin Getz0acad8d2009-05-11 18:55:16 +0000494 fp->pc = SAFE_USER_INSTRUCTION;
495
Mike Frysinger6510a202009-06-07 15:07:25 -0400496 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700497 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700498}
499
Robin Getz2a12c462010-03-11 16:24:18 +0000500asmlinkage void double_fault_c(struct pt_regs *fp)
Robin Getzf09630b2008-07-26 19:45:46 +0800501{
Robin Getz518039b2007-07-25 11:03:28 +0800502#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Robin Getz2a12c462010-03-11 16:24:18 +0000503 int j;
504 trace_buffer_save(j);
Robin Getz518039b2007-07-25 11:03:28 +0800505#endif
506
Robin Getz2a12c462010-03-11 16:24:18 +0000507 console_verbose();
508 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800509#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz2a12c462010-03-11 16:24:18 +0000510 printk(KERN_EMERG "Double Fault\n");
511#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
512 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
513 unsigned int cpu = raw_smp_processor_id();
514 char buf[150];
515 decode_address(buf, cpu_pda[cpu].retx_doublefault);
516 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
517 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
518 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
519 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
520 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
521 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +0800522
Robin Getz2a12c462010-03-11 16:24:18 +0000523 decode_address(buf, fp->retx);
524 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +0800525 } else
Robin Getz9f06c382008-10-10 18:13:21 +0800526#endif
Robin Getz2a12c462010-03-11 16:24:18 +0000527 {
528 dump_bfin_process(fp);
529 dump_bfin_mem(fp);
530 show_regs(fp);
531 dump_bfin_trace_buffer();
532 }
533#endif
534 panic("Double Fault - unrecoverable event");
535
Mike Frysinger49dce912007-11-21 16:46:49 +0800536}
537
Mike Frysinger1ffe6642007-08-05 17:14:04 +0800538
Bryan Wu1394f032007-05-06 14:50:22 -0700539void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
540{
541 switch (cplb_panic) {
542 case CPLB_NO_UNLOCKED:
543 printk(KERN_EMERG "All CPLBs are locked\n");
544 break;
545 case CPLB_PROT_VIOL:
546 return;
547 case CPLB_NO_ADDR_MATCH:
548 return;
549 case CPLB_UNKNOWN_ERR:
550 printk(KERN_EMERG "Unknown CPLB Exception\n");
551 break;
552 }
553
Robin Getz226eb1e2007-10-29 17:59:07 +0800554 oops_in_progress = 1;
555
Mike Frysinger49dce912007-11-21 16:46:49 +0800556 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800557 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800558 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -0700559 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000560 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -0700561}
Robin Getz2a12c462010-03-11 16:24:18 +0000562
563#ifdef CONFIG_BUG
564int is_valid_bugaddr(unsigned long addr)
565{
Robin Getz9a95e2f2010-03-15 17:42:07 +0000566 unsigned int opcode;
Robin Getz2a12c462010-03-11 16:24:18 +0000567
568 if (!get_instruction(&opcode, (unsigned short *)addr))
569 return 0;
570
571 return opcode == BFIN_BUG_OPCODE;
572}
573#endif
Robin Getzd28cff42010-03-11 19:26:38 +0000574
575/* stub this out */
576#ifndef CONFIG_DEBUG_VERBOSE
577void show_regs(struct pt_regs *fp)
578{
579
580}
581#endif