2 * Main exception handling logic.
4 * Copyright 2004-2010 Analog Devices Inc.
6 * Licensed under the GPL-2 or later
10 #include <linux/uaccess.h>
11 #include <linux/module.h>
12 #include <asm/traps.h>
14 #include <asm/blackfin.h>
15 #include <asm/irq_handler.h>
16 #include <linux/irq.h>
17 #include <asm/trace.h>
18 #include <asm/fixed_code.h>
19 #include <asm/pseudo_instructions.h>
21 #include <asm/asm-offsets.h>
24 # include <linux/kgdb.h>
26 # define CHK_DEBUGGER_TRAP() \
28 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
30 # define CHK_DEBUGGER_TRAP_MAYBE() \
33 CHK_DEBUGGER_TRAP(); \
36 # define CHK_DEBUGGER_TRAP() do { } while (0)
37 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
41 #ifdef CONFIG_DEBUG_VERBOSE
42 #define verbose_printk(fmt, arg...) \
45 #define verbose_printk(fmt, arg...) \
46 ({ if (0) printk(fmt, ##arg); 0; })
49 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
51 #ifdef CONFIG_DEBUG_MMRS_MODULE
52 EXPORT_SYMBOL(last_seqstat);
56 /* Initiate the event table handler */
57 void __init trap_init(void)
60 bfin_write_EVT3(trap);
64 static int kernel_mode_regs(struct pt_regs *regs)
66 return regs->ipend & 0xffc0;
69 asmlinkage notrace void trap_c(struct pt_regs *fp)
71 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
74 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
77 unsigned int cpu = raw_smp_processor_id();
78 const char *strerror = NULL;
81 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
84 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
85 last_seqstat = (u32)fp->seqstat;
88 /* Important - be very careful dereferncing pointers - will lead to
89 * double faults if the stack has become corrupt
92 /* trap_c() will be called for exceptions. During exceptions
93 * processing, the pc value should be set with retx value.
94 * With this change we can cleanup some code in signal.c- TODO
96 fp->orig_pc = fp->retx;
97 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
98 trapnr, fp->ipend, fp->pc, fp->retx); */
100 /* send the appropriate signal to the user program */
103 /* This table works in conjunction with the one in ./mach-common/entry.S
104 * Some exceptions are handled there (in assembly, in exception space)
105 * Some are handled here, (in C, in interrupt space)
106 * Some, like CPLB, are handled in both, where the normal path is
107 * handled in assembly/exception space, and the error path is handled
111 /* 0x00 - Linux Syscall, getting here is an error */
112 /* 0x01 - userspace gdb breakpoint, handled here */
114 info.si_code = TRAP_ILLTRAP;
116 CHK_DEBUGGER_TRAP_MAYBE();
117 /* Check if this is a breakpoint in kernel space */
118 if (kernel_mode_regs(fp))
122 /* 0x03 - User Defined, userspace stack overflow */
124 info.si_code = SEGV_STACKFLOW;
126 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
127 CHK_DEBUGGER_TRAP_MAYBE();
129 /* 0x02 - KGDB initial connection and break signal trap */
132 info.si_code = TRAP_ILLTRAP;
137 /* 0x04 - User Defined */
138 /* 0x05 - User Defined */
139 /* 0x06 - User Defined */
140 /* 0x07 - User Defined */
141 /* 0x08 - User Defined */
142 /* 0x09 - User Defined */
143 /* 0x0A - User Defined */
144 /* 0x0B - User Defined */
145 /* 0x0C - User Defined */
146 /* 0x0D - User Defined */
147 /* 0x0E - User Defined */
148 /* 0x0F - User Defined */
149 /* If we got here, it is most likely that someone was trying to use a
150 * custom exception handler, and it is not actually installed properly
152 case VEC_EXCPT04 ... VEC_EXCPT15:
153 info.si_code = ILL_ILLPARAOP;
155 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
156 CHK_DEBUGGER_TRAP_MAYBE();
158 /* 0x10 HW Single step, handled here */
160 info.si_code = TRAP_STEP;
162 CHK_DEBUGGER_TRAP_MAYBE();
163 /* Check if this is a single step in kernel space */
164 if (kernel_mode_regs(fp))
168 /* 0x11 - Trace Buffer Full, handled here */
170 info.si_code = TRAP_TRACEFLOW;
172 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
173 CHK_DEBUGGER_TRAP_MAYBE();
175 /* 0x12 - Reserved, Caught by default */
176 /* 0x13 - Reserved, Caught by default */
177 /* 0x14 - Reserved, Caught by default */
178 /* 0x15 - Reserved, Caught by default */
179 /* 0x16 - Reserved, Caught by default */
180 /* 0x17 - Reserved, Caught by default */
181 /* 0x18 - Reserved, Caught by default */
182 /* 0x19 - Reserved, Caught by default */
183 /* 0x1A - Reserved, Caught by default */
184 /* 0x1B - Reserved, Caught by default */
185 /* 0x1C - Reserved, Caught by default */
186 /* 0x1D - Reserved, Caught by default */
187 /* 0x1E - Reserved, Caught by default */
188 /* 0x1F - Reserved, Caught by default */
189 /* 0x20 - Reserved, Caught by default */
190 /* 0x21 - Undefined Instruction, handled here */
193 if (kernel_mode_regs(fp)) {
194 switch (report_bug(fp->pc, fp)) {
195 case BUG_TRAP_TYPE_NONE:
197 case BUG_TRAP_TYPE_WARN:
198 dump_bfin_trace_buffer();
201 case BUG_TRAP_TYPE_BUG:
202 /* call to panic() will dump trace, and it is
203 * off at this point, so it won't be clobbered
209 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
211 * Support for the fake instructions, if the instruction fails,
212 * then just execute a illegal opcode failure (like normal).
213 * Don't support these instructions inside the kernel
215 if (!kernel_mode_regs(fp) && get_instruction(&opcode, (unsigned short *)fp->pc)) {
216 if (execute_pseudodbg_assert(fp, opcode))
218 if (execute_pseudodbg(fp, opcode))
222 info.si_code = ILL_ILLOPC;
224 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
225 CHK_DEBUGGER_TRAP_MAYBE();
227 /* 0x22 - Illegal Instruction Combination, handled here */
229 info.si_code = ILL_ILLPARAOP;
231 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
232 CHK_DEBUGGER_TRAP_MAYBE();
234 /* 0x23 - Data CPLB protection violation, handled here */
236 info.si_code = ILL_CPLB_VI;
238 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
239 CHK_DEBUGGER_TRAP_MAYBE();
241 /* 0x24 - Data access misaligned, handled here */
243 info.si_code = BUS_ADRALN;
245 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
246 CHK_DEBUGGER_TRAP_MAYBE();
248 /* 0x25 - Unrecoverable Event, handled here */
250 info.si_code = ILL_ILLEXCPT;
252 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
253 CHK_DEBUGGER_TRAP_MAYBE();
255 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
256 error case is handled here */
258 info.si_code = BUS_ADRALN;
260 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
262 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
264 info.si_code = ILL_CPLB_MULHIT;
266 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
267 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
268 strerror = KERN_NOTICE "NULL pointer access\n";
271 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
272 CHK_DEBUGGER_TRAP_MAYBE();
274 /* 0x28 - Emulation Watchpoint, handled here */
276 info.si_code = TRAP_WATCHPT;
278 pr_debug(EXC_0x28(KERN_DEBUG));
279 CHK_DEBUGGER_TRAP_MAYBE();
280 /* Check if this is a watchpoint in kernel space */
281 if (kernel_mode_regs(fp))
286 /* 0x29 - Instruction fetch access error (535 only) */
287 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
288 info.si_code = BUS_OPFETCH;
290 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
291 CHK_DEBUGGER_TRAP_MAYBE();
294 /* 0x29 - Reserved, Caught by default */
296 /* 0x2A - Instruction fetch misaligned, handled here */
298 info.si_code = BUS_ADRALN;
300 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
301 CHK_DEBUGGER_TRAP_MAYBE();
303 /* 0x2B - Instruction CPLB protection violation, handled here */
305 info.si_code = ILL_CPLB_VI;
307 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
308 CHK_DEBUGGER_TRAP_MAYBE();
310 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
312 info.si_code = ILL_CPLB_MISS;
314 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
316 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
317 case VEC_CPLB_I_MHIT:
318 info.si_code = ILL_CPLB_MULHIT;
320 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
321 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
322 strerror = KERN_NOTICE "Jump to NULL address\n";
325 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
326 CHK_DEBUGGER_TRAP_MAYBE();
328 /* 0x2E - Illegal use of Supervisor Resource, handled here */
330 info.si_code = ILL_PRVOPC;
332 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
333 CHK_DEBUGGER_TRAP_MAYBE();
335 /* 0x2F - Reserved, Caught by default */
336 /* 0x30 - Reserved, Caught by default */
337 /* 0x31 - Reserved, Caught by default */
338 /* 0x32 - Reserved, Caught by default */
339 /* 0x33 - Reserved, Caught by default */
340 /* 0x34 - Reserved, Caught by default */
341 /* 0x35 - Reserved, Caught by default */
342 /* 0x36 - Reserved, Caught by default */
343 /* 0x37 - Reserved, Caught by default */
344 /* 0x38 - Reserved, Caught by default */
345 /* 0x39 - Reserved, Caught by default */
346 /* 0x3A - Reserved, Caught by default */
347 /* 0x3B - Reserved, Caught by default */
348 /* 0x3C - Reserved, Caught by default */
349 /* 0x3D - Reserved, Caught by default */
350 /* 0x3E - Reserved, Caught by default */
351 /* 0x3F - Reserved, Caught by default */
353 info.si_code = BUS_ADRALN;
355 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
356 /* System MMR Error */
357 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
358 info.si_code = BUS_ADRALN;
360 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
362 /* External Memory Addressing Error */
363 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
364 if (ANOMALY_05000310) {
365 static unsigned long anomaly_rets;
367 if ((fp->pc >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
368 (fp->pc < (L1_CODE_START + L1_CODE_LENGTH))) {
370 * A false hardware error will happen while fetching at
371 * the L1 instruction SRAM boundary. Ignore it.
373 anomaly_rets = fp->rets;
375 } else if (fp->rets == anomaly_rets) {
377 * While boundary code returns to a function, at the ret
378 * point, a new false hardware error might occur too based
379 * on tests. Ignore it too.
382 } else if ((fp->rets >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
383 (fp->rets < (L1_CODE_START + L1_CODE_LENGTH))) {
385 * If boundary code calls a function, at the entry point,
386 * a new false hardware error maybe happen based on tests.
394 info.si_code = BUS_ADRERR;
396 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
398 /* Performance Monitor Overflow */
399 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
400 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
402 /* RAISE 5 instruction */
403 case (SEQSTAT_HWERRCAUSE_RAISE_5):
404 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
406 default: /* Reserved */
407 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
410 CHK_DEBUGGER_TRAP_MAYBE();
413 * We should be handling all known exception types above,
414 * if we get here we hit a reserved one, so panic
417 info.si_code = ILL_ILLPARAOP;
419 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
420 (fp->seqstat & SEQSTAT_EXCAUSE));
421 CHK_DEBUGGER_TRAP_MAYBE();
427 /* If the fault was caused by a kernel thread, or interrupt handler
428 * we will kernel panic, so the system reboots.
430 if (kernel_mode_regs(fp) || (current && !current->mm)) {
432 oops_in_progress = 1;
435 if (sig != SIGTRAP) {
437 verbose_printk(strerror);
439 dump_bfin_process(fp);
443 /* Print out the trace buffer if it makes sense */
444 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
445 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
446 verbose_printk(KERN_NOTICE "No trace since you do not have "
447 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
450 dump_bfin_trace_buffer();
452 if (oops_in_progress) {
453 /* Dump the current kernel stack */
454 verbose_printk(KERN_NOTICE "Kernel Stack\n");
455 show_stack(current, NULL);
457 #ifndef CONFIG_ACCESS_CHECK
458 verbose_printk(KERN_EMERG "Please turn on "
459 "CONFIG_ACCESS_CHECK\n");
461 panic("Kernel exception");
463 #ifdef CONFIG_DEBUG_VERBOSE
464 unsigned long *stack;
465 /* Dump the user space stack */
466 stack = (unsigned long *)rdusp();
467 verbose_printk(KERN_NOTICE "Userspace Stack\n");
468 show_stack(NULL, stack);
474 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
484 info.si_addr = (void __user *)cpu_pda[cpu].dcplb_fault_addr;
487 info.si_addr = (void __user *)fp->pc;
490 force_sig_info(sig, &info, current);
493 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
494 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
495 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
496 fp->pc = SAFE_USER_INSTRUCTION;
499 trace_buffer_restore(j);
502 asmlinkage void double_fault_c(struct pt_regs *fp)
504 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
506 trace_buffer_save(j);
510 oops_in_progress = 1;
511 #ifdef CONFIG_DEBUG_VERBOSE
512 printk(KERN_EMERG "Double Fault\n");
513 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
514 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
515 unsigned int cpu = raw_smp_processor_id();
517 decode_address(buf, cpu_pda[cpu].retx_doublefault);
518 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
519 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
520 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
521 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
522 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
523 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
525 decode_address(buf, fp->retx);
526 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
530 dump_bfin_process(fp);
533 dump_bfin_trace_buffer();
536 panic("Double Fault - unrecoverable event");
541 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
543 switch (cplb_panic) {
544 case CPLB_NO_UNLOCKED:
545 printk(KERN_EMERG "All CPLBs are locked\n");
549 case CPLB_NO_ADDR_MATCH:
551 case CPLB_UNKNOWN_ERR:
552 printk(KERN_EMERG "Unknown CPLB Exception\n");
556 oops_in_progress = 1;
558 dump_bfin_process(fp);
562 panic("Unrecoverable event");
566 int is_valid_bugaddr(unsigned long addr)
570 if (!get_instruction(&opcode, (unsigned short *)addr))
573 return opcode == BFIN_BUG_OPCODE;
578 #ifndef CONFIG_DEBUG_VERBOSE
579 void show_regs(struct pt_regs *fp)