blob: 891cc39f7eec4f909b8e625dcba08892613a20a4 [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>
Bryan Wu1394f032007-05-06 14:50:22 -070019
20#ifdef CONFIG_KGDB
Bryan Wu1394f032007-05-06 14:50:22 -070021# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080022
23# define CHK_DEBUGGER_TRAP() \
24 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080025 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080026 } while (0)
27# define CHK_DEBUGGER_TRAP_MAYBE() \
28 do { \
29 if (kgdb_connected) \
30 CHK_DEBUGGER_TRAP(); \
31 } while (0)
32#else
33# define CHK_DEBUGGER_TRAP() do { } while (0)
34# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070035#endif
36
Robin Getz9f06c382008-10-10 18:13:21 +080037
Robin Getz4ee1c452008-10-28 11:36:11 +080038#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +080039#define verbose_printk(fmt, arg...) \
40 printk(fmt, ##arg)
41#else
42#define verbose_printk(fmt, arg...) \
43 ({ if (0) printk(fmt, ##arg); 0; })
44#endif
45
Robin Getz81f7f452009-06-03 18:58:26 +000046#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
47u32 last_seqstat;
48#ifdef CONFIG_DEBUG_MMRS_MODULE
49EXPORT_SYMBOL(last_seqstat);
50#endif
51#endif
52
Bryan Wu1394f032007-05-06 14:50:22 -070053/* Initiate the event table handler */
54void __init trap_init(void)
55{
56 CSYNC();
57 bfin_write_EVT3(trap);
58 CSYNC();
59}
60
Mike Frysinger82bd1d72009-06-07 17:08:28 -040061static int kernel_mode_regs(struct pt_regs *regs)
62{
63 return regs->ipend & 0xffc0;
64}
65
Yi Lic4baebf2009-08-12 23:05:35 +000066asmlinkage notrace void trap_c(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -070067{
Robin Getz518039b2007-07-25 11:03:28 +080068#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
69 int j;
70#endif
Yi Lib6dbde22009-08-20 04:17:47 +000071 unsigned int cpu = raw_smp_processor_id();
Mike Frysinger82bd1d72009-06-07 17:08:28 -040072 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +080073 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -070074 siginfo_t info;
75 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
76
Bryan Wu1394f032007-05-06 14:50:22 -070077 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +000078#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
79 last_seqstat = (u32)fp->seqstat;
80#endif
Bryan Wu1394f032007-05-06 14:50:22 -070081
Robin Getz226eb1e2007-10-29 17:59:07 +080082 /* Important - be very careful dereferncing pointers - will lead to
83 * double faults if the stack has become corrupt
84 */
85
Bryan Wu1394f032007-05-06 14:50:22 -070086 /* trap_c() will be called for exceptions. During exceptions
87 * processing, the pc value should be set with retx value.
88 * With this change we can cleanup some code in signal.c- TODO
89 */
90 fp->orig_pc = fp->retx;
91 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
92 trapnr, fp->ipend, fp->pc, fp->retx); */
93
94 /* send the appropriate signal to the user program */
95 switch (trapnr) {
96
97 /* This table works in conjuction with the one in ./mach-common/entry.S
98 * Some exceptions are handled there (in assembly, in exception space)
99 * Some are handled here, (in C, in interrupt space)
100 * Some, like CPLB, are handled in both, where the normal path is
101 * handled in assembly/exception space, and the error path is handled
102 * here
103 */
104
105 /* 0x00 - Linux Syscall, getting here is an error */
106 /* 0x01 - userspace gdb breakpoint, handled here */
107 case VEC_EXCPT01:
108 info.si_code = TRAP_ILLTRAP;
109 sig = SIGTRAP;
110 CHK_DEBUGGER_TRAP_MAYBE();
111 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400112 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400113 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700114 else
115 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800116 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700117 case VEC_EXCPT03:
118 info.si_code = SEGV_STACKFLOW;
119 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400120 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800121 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700122 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800123 /* 0x02 - KGDB initial connection and break signal trap */
124 case VEC_EXCPT02:
125#ifdef CONFIG_KGDB
126 info.si_code = TRAP_ILLTRAP;
127 sig = SIGTRAP;
128 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400129 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800130#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800131 /* 0x04 - User Defined */
132 /* 0x05 - User Defined */
133 /* 0x06 - User Defined */
134 /* 0x07 - User Defined */
135 /* 0x08 - User Defined */
136 /* 0x09 - User Defined */
137 /* 0x0A - User Defined */
138 /* 0x0B - User Defined */
139 /* 0x0C - User Defined */
140 /* 0x0D - User Defined */
141 /* 0x0E - User Defined */
142 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800143 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800144 * custom exception handler, and it is not actually installed properly
145 */
146 case VEC_EXCPT04 ... VEC_EXCPT15:
147 info.si_code = ILL_ILLPARAOP;
148 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400149 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800150 CHK_DEBUGGER_TRAP_MAYBE();
151 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700152 /* 0x10 HW Single step, handled here */
153 case VEC_STEP:
154 info.si_code = TRAP_STEP;
155 sig = SIGTRAP;
156 CHK_DEBUGGER_TRAP_MAYBE();
157 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400158 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400159 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700160 else
161 break;
162 /* 0x11 - Trace Buffer Full, handled here */
163 case VEC_OVFLOW:
164 info.si_code = TRAP_TRACEFLOW;
165 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400166 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800167 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700168 break;
169 /* 0x12 - Reserved, Caught by default */
170 /* 0x13 - Reserved, Caught by default */
171 /* 0x14 - Reserved, Caught by default */
172 /* 0x15 - Reserved, Caught by default */
173 /* 0x16 - Reserved, Caught by default */
174 /* 0x17 - Reserved, Caught by default */
175 /* 0x18 - Reserved, Caught by default */
176 /* 0x19 - Reserved, Caught by default */
177 /* 0x1A - Reserved, Caught by default */
178 /* 0x1B - Reserved, Caught by default */
179 /* 0x1C - Reserved, Caught by default */
180 /* 0x1D - Reserved, Caught by default */
181 /* 0x1E - Reserved, Caught by default */
182 /* 0x1F - Reserved, Caught by default */
183 /* 0x20 - Reserved, Caught by default */
184 /* 0x21 - Undefined Instruction, handled here */
185 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400186#ifdef CONFIG_BUG
187 if (kernel_mode_regs(fp)) {
188 switch (report_bug(fp->pc, fp)) {
189 case BUG_TRAP_TYPE_NONE:
190 break;
191 case BUG_TRAP_TYPE_WARN:
192 dump_bfin_trace_buffer();
193 fp->pc += 2;
194 goto traps_done;
195 case BUG_TRAP_TYPE_BUG:
196 /* call to panic() will dump trace, and it is
197 * off at this point, so it won't be clobbered
198 */
199 panic("BUG()");
200 }
201 }
202#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700203 info.si_code = ILL_ILLOPC;
204 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400205 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800206 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700207 break;
208 /* 0x22 - Illegal Instruction Combination, handled here */
209 case VEC_ILGAL_I:
210 info.si_code = ILL_ILLPARAOP;
211 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400212 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800213 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700214 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800215 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700216 case VEC_CPLB_VL:
217 info.si_code = ILL_CPLB_VI;
Graf Yang36b84122009-07-21 02:26:57 +0000218 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400219 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800220 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700221 break;
222 /* 0x24 - Data access misaligned, handled here */
223 case VEC_MISALI_D:
224 info.si_code = BUS_ADRALN;
225 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400226 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800227 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700228 break;
229 /* 0x25 - Unrecoverable Event, handled here */
230 case VEC_UNCOV:
231 info.si_code = ILL_ILLEXCPT;
232 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400233 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800234 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700235 break;
236 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
237 error case is handled here */
238 case VEC_CPLB_M:
239 info.si_code = BUS_ADRALN;
240 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400241 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700242 break;
243 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
244 case VEC_CPLB_MHIT:
245 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700246 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800247#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800248 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400249 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800250 else
Bryan Wu1394f032007-05-06 14:50:22 -0700251#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400252 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800253 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700254 break;
255 /* 0x28 - Emulation Watchpoint, handled here */
256 case VEC_WATCH:
257 info.si_code = TRAP_WATCHPT;
258 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800259 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700260 CHK_DEBUGGER_TRAP_MAYBE();
261 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400262 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400263 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700264 else
265 break;
266#ifdef CONFIG_BF535
267 /* 0x29 - Instruction fetch access error (535 only) */
268 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
269 info.si_code = BUS_OPFETCH;
270 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400271 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800272 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700273 break;
274#else
275 /* 0x29 - Reserved, Caught by default */
276#endif
277 /* 0x2A - Instruction fetch misaligned, handled here */
278 case VEC_MISALI_I:
279 info.si_code = BUS_ADRALN;
280 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400281 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800282 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700283 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800284 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700285 case VEC_CPLB_I_VL:
286 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800287 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400288 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800289 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700290 break;
291 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
292 case VEC_CPLB_I_M:
293 info.si_code = ILL_CPLB_MISS;
294 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400295 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700296 break;
297 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
298 case VEC_CPLB_I_MHIT:
299 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700300 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800301#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800302 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400303 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800304 else
Bryan Wu1394f032007-05-06 14:50:22 -0700305#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400306 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800307 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700308 break;
309 /* 0x2E - Illegal use of Supervisor Resource, handled here */
310 case VEC_ILL_RES:
311 info.si_code = ILL_PRVOPC;
312 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400313 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800314 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700315 break;
316 /* 0x2F - Reserved, Caught by default */
317 /* 0x30 - Reserved, Caught by default */
318 /* 0x31 - Reserved, Caught by default */
319 /* 0x32 - Reserved, Caught by default */
320 /* 0x33 - Reserved, Caught by default */
321 /* 0x34 - Reserved, Caught by default */
322 /* 0x35 - Reserved, Caught by default */
323 /* 0x36 - Reserved, Caught by default */
324 /* 0x37 - Reserved, Caught by default */
325 /* 0x38 - Reserved, Caught by default */
326 /* 0x39 - Reserved, Caught by default */
327 /* 0x3A - Reserved, Caught by default */
328 /* 0x3B - Reserved, Caught by default */
329 /* 0x3C - Reserved, Caught by default */
330 /* 0x3D - Reserved, Caught by default */
331 /* 0x3E - Reserved, Caught by default */
332 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800333 case VEC_HWERR:
334 info.si_code = BUS_ADRALN;
335 sig = SIGBUS;
336 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
337 /* System MMR Error */
338 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
339 info.si_code = BUS_ADRALN;
340 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400341 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800342 break;
343 /* External Memory Addressing Error */
344 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
Barry Songa00b4fe2009-11-27 09:18:21 +0000345 if (ANOMALY_05000310) {
346 static unsigned long anomaly_rets;
347
348 if ((fp->pc >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
349 (fp->pc < (L1_CODE_START + L1_CODE_LENGTH))) {
350 /*
351 * A false hardware error will happen while fetching at
352 * the L1 instruction SRAM boundary. Ignore it.
353 */
354 anomaly_rets = fp->rets;
355 goto traps_done;
356 } else if (fp->rets == anomaly_rets) {
357 /*
358 * While boundary code returns to a function, at the ret
359 * point, a new false hardware error might occur too based
360 * on tests. Ignore it too.
361 */
362 goto traps_done;
363 } else if ((fp->rets >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
364 (fp->rets < (L1_CODE_START + L1_CODE_LENGTH))) {
365 /*
366 * If boundary code calls a function, at the entry point,
367 * a new false hardware error maybe happen based on tests.
368 * Ignore it too.
369 */
370 goto traps_done;
371 } else
372 anomaly_rets = 0;
373 }
374
Robin Getz13fe24f2008-01-27 15:38:56 +0800375 info.si_code = BUS_ADRERR;
376 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400377 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800378 break;
379 /* Performance Monitor Overflow */
380 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400381 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800382 break;
383 /* RAISE 5 instruction */
384 case (SEQSTAT_HWERRCAUSE_RAISE_5):
385 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
386 break;
387 default: /* Reserved */
388 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
389 break;
390 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800391 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800392 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800393 /*
394 * We should be handling all known exception types above,
395 * if we get here we hit a reserved one, so panic
396 */
Bryan Wu1394f032007-05-06 14:50:22 -0700397 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800398 info.si_code = ILL_ILLPARAOP;
399 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800400 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700401 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800402 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700403 break;
404 }
405
Robin Getz226eb1e2007-10-29 17:59:07 +0800406 BUG_ON(sig == 0);
407
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400408 /* If the fault was caused by a kernel thread, or interrupt handler
409 * we will kernel panic, so the system reboots.
410 */
411 if (kernel_mode_regs(fp) || (current && !current->mm)) {
412 console_verbose();
413 oops_in_progress = 1;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400414 }
415
Robin Getz226eb1e2007-10-29 17:59:07 +0800416 if (sig != SIGTRAP) {
Mike Frysinger15627bd2009-06-23 11:21:34 +0000417 if (strerror)
418 verbose_printk(strerror);
419
Mike Frysinger49dce912007-11-21 16:46:49 +0800420 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800421 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800422 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800423
424 /* Print out the trace buffer if it makes sense */
425#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
426 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800427 verbose_printk(KERN_NOTICE "No trace since you do not have "
Joe Perchesad361c92009-07-06 13:05:40 -0700428 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800429 else
430#endif
431 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800432
Robin Getz226eb1e2007-10-29 17:59:07 +0800433 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800434 /* Dump the current kernel stack */
Joe Perchesad361c92009-07-06 13:05:40 -0700435 verbose_printk(KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800436 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800437 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800438#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800439 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800440 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800441#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700442 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800443 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800444#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800445 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800446 /* Dump the user space stack */
447 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800448 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800449 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800450#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800451 }
Bryan Wu1394f032007-05-06 14:50:22 -0700452 }
Robin Getzfb322912007-11-21 16:38:05 +0800453
Yi Li6a01f232009-01-07 23:14:39 +0800454#ifdef CONFIG_IPIPE
455 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
456#endif
457 {
458 info.si_signo = sig;
459 info.si_errno = 0;
Barry Song5e8d3212010-01-19 11:01:08 +0000460 switch (trapnr) {
461 case VEC_CPLB_VL:
462 case VEC_MISALI_D:
463 case VEC_CPLB_M:
464 case VEC_CPLB_MHIT:
465 info.si_addr = (void __user *)cpu_pda[cpu].dcplb_fault_addr;
466 break;
467 default:
468 info.si_addr = (void __user *)fp->pc;
469 break;
470 }
Yi Li6a01f232009-01-07 23:14:39 +0800471 force_sig_info(sig, &info, current);
472 }
Bryan Wu1394f032007-05-06 14:50:22 -0700473
Robin Getz0e4edcf2009-06-22 20:23:48 +0000474 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
Robin Getzf574a762009-07-09 15:11:52 +0000475 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
476 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
Robin Getz0acad8d2009-05-11 18:55:16 +0000477 fp->pc = SAFE_USER_INSTRUCTION;
478
Mike Frysinger6510a202009-06-07 15:07:25 -0400479 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700480 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700481}
482
Robin Getz2a12c462010-03-11 16:24:18 +0000483asmlinkage void double_fault_c(struct pt_regs *fp)
Robin Getzf09630b2008-07-26 19:45:46 +0800484{
Robin Getz518039b2007-07-25 11:03:28 +0800485#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Robin Getz2a12c462010-03-11 16:24:18 +0000486 int j;
487 trace_buffer_save(j);
Robin Getz518039b2007-07-25 11:03:28 +0800488#endif
489
Robin Getz2a12c462010-03-11 16:24:18 +0000490 console_verbose();
491 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800492#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz2a12c462010-03-11 16:24:18 +0000493 printk(KERN_EMERG "Double Fault\n");
494#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
495 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
496 unsigned int cpu = raw_smp_processor_id();
497 char buf[150];
498 decode_address(buf, cpu_pda[cpu].retx_doublefault);
499 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
500 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
501 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
502 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
503 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
504 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +0800505
Robin Getz2a12c462010-03-11 16:24:18 +0000506 decode_address(buf, fp->retx);
507 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +0800508 } else
Robin Getz9f06c382008-10-10 18:13:21 +0800509#endif
Robin Getz2a12c462010-03-11 16:24:18 +0000510 {
511 dump_bfin_process(fp);
512 dump_bfin_mem(fp);
513 show_regs(fp);
514 dump_bfin_trace_buffer();
515 }
516#endif
517 panic("Double Fault - unrecoverable event");
518
Mike Frysinger49dce912007-11-21 16:46:49 +0800519}
520
Mike Frysinger1ffe6642007-08-05 17:14:04 +0800521
Bryan Wu1394f032007-05-06 14:50:22 -0700522void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
523{
524 switch (cplb_panic) {
525 case CPLB_NO_UNLOCKED:
526 printk(KERN_EMERG "All CPLBs are locked\n");
527 break;
528 case CPLB_PROT_VIOL:
529 return;
530 case CPLB_NO_ADDR_MATCH:
531 return;
532 case CPLB_UNKNOWN_ERR:
533 printk(KERN_EMERG "Unknown CPLB Exception\n");
534 break;
535 }
536
Robin Getz226eb1e2007-10-29 17:59:07 +0800537 oops_in_progress = 1;
538
Mike Frysinger49dce912007-11-21 16:46:49 +0800539 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800540 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800541 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -0700542 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000543 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -0700544}
Robin Getz2a12c462010-03-11 16:24:18 +0000545
546#ifdef CONFIG_BUG
547int is_valid_bugaddr(unsigned long addr)
548{
549 unsigned short opcode;
550
551 if (!get_instruction(&opcode, (unsigned short *)addr))
552 return 0;
553
554 return opcode == BFIN_BUG_OPCODE;
555}
556#endif