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 <linux/sched/signal.h>
13 #include <linux/sched/debug.h>
14 #include <asm/traps.h>
16 #include <asm/blackfin.h>
17 #include <asm/irq_handler.h>
18 #include <linux/irq.h>
19 #include <asm/trace.h>
20 #include <asm/fixed_code.h>
21 #include <asm/pseudo_instructions.h>
23 #include <asm/asm-offsets.h>
26 # include <linux/kgdb.h>
28 # define CHK_DEBUGGER_TRAP() \
30 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
32 # define CHK_DEBUGGER_TRAP_MAYBE() \
35 CHK_DEBUGGER_TRAP(); \
38 # define CHK_DEBUGGER_TRAP() do { } while (0)
39 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
43 #ifdef CONFIG_DEBUG_VERBOSE
44 #define verbose_printk(fmt, arg...) \
47 #define verbose_printk(fmt, arg...) \
48 ({ if (0) printk(fmt, ##arg); 0; })
51 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
53 #ifdef CONFIG_DEBUG_MMRS_MODULE
54 EXPORT_SYMBOL(last_seqstat);
58 /* Initiate the event table handler */
59 void __init trap_init(void)
62 bfin_write_EVT3(trap);
66 static int kernel_mode_regs(struct pt_regs *regs)
68 return regs->ipend & 0xffc0;
71 asmlinkage notrace void trap_c(struct pt_regs *fp)
73 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
76 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
79 unsigned int cpu = raw_smp_processor_id();
80 const char *strerror = NULL;
83 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
86 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
87 last_seqstat = (u32)fp->seqstat;
90 /* Important - be very careful dereferncing pointers - will lead to
91 * double faults if the stack has become corrupt
94 /* trap_c() will be called for exceptions. During exceptions
95 * processing, the pc value should be set with retx value.
96 * With this change we can cleanup some code in signal.c- TODO
98 fp->orig_pc = fp->retx;
99 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
100 trapnr, fp->ipend, fp->pc, fp->retx); */
102 /* send the appropriate signal to the user program */
105 /* This table works in conjunction with the one in ./mach-common/entry.S
106 * Some exceptions are handled there (in assembly, in exception space)
107 * Some are handled here, (in C, in interrupt space)
108 * Some, like CPLB, are handled in both, where the normal path is
109 * handled in assembly/exception space, and the error path is handled
113 /* 0x00 - Linux Syscall, getting here is an error */
114 /* 0x01 - userspace gdb breakpoint, handled here */
116 info.si_code = TRAP_ILLTRAP;
118 CHK_DEBUGGER_TRAP_MAYBE();
119 /* Check if this is a breakpoint in kernel space */
120 if (kernel_mode_regs(fp))
124 /* 0x03 - User Defined, userspace stack overflow */
126 info.si_code = SEGV_STACKFLOW;
128 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
129 CHK_DEBUGGER_TRAP_MAYBE();
131 /* 0x02 - KGDB initial connection and break signal trap */
134 info.si_code = TRAP_ILLTRAP;
139 /* 0x04 - User Defined */
140 /* 0x05 - User Defined */
141 /* 0x06 - User Defined */
142 /* 0x07 - User Defined */
143 /* 0x08 - User Defined */
144 /* 0x09 - User Defined */
145 /* 0x0A - User Defined */
146 /* 0x0B - User Defined */
147 /* 0x0C - User Defined */
148 /* 0x0D - User Defined */
149 /* 0x0E - User Defined */
150 /* 0x0F - User Defined */
151 /* If we got here, it is most likely that someone was trying to use a
152 * custom exception handler, and it is not actually installed properly
154 case VEC_EXCPT04 ... VEC_EXCPT15:
155 info.si_code = ILL_ILLPARAOP;
157 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
158 CHK_DEBUGGER_TRAP_MAYBE();
160 /* 0x10 HW Single step, handled here */
162 info.si_code = TRAP_STEP;
164 CHK_DEBUGGER_TRAP_MAYBE();
165 /* Check if this is a single step in kernel space */
166 if (kernel_mode_regs(fp))
170 /* 0x11 - Trace Buffer Full, handled here */
172 info.si_code = TRAP_TRACEFLOW;
174 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
175 CHK_DEBUGGER_TRAP_MAYBE();
177 /* 0x12 - Reserved, Caught by default */
178 /* 0x13 - Reserved, Caught by default */
179 /* 0x14 - Reserved, Caught by default */
180 /* 0x15 - Reserved, Caught by default */
181 /* 0x16 - Reserved, Caught by default */
182 /* 0x17 - Reserved, Caught by default */
183 /* 0x18 - Reserved, Caught by default */
184 /* 0x19 - Reserved, Caught by default */
185 /* 0x1A - Reserved, Caught by default */
186 /* 0x1B - Reserved, Caught by default */
187 /* 0x1C - Reserved, Caught by default */
188 /* 0x1D - Reserved, Caught by default */
189 /* 0x1E - Reserved, Caught by default */
190 /* 0x1F - Reserved, Caught by default */
191 /* 0x20 - Reserved, Caught by default */
192 /* 0x21 - Undefined Instruction, handled here */
195 if (kernel_mode_regs(fp)) {
196 switch (report_bug(fp->pc, fp)) {
197 case BUG_TRAP_TYPE_NONE:
199 case BUG_TRAP_TYPE_WARN:
200 dump_bfin_trace_buffer();
203 case BUG_TRAP_TYPE_BUG:
204 /* call to panic() will dump trace, and it is
205 * off at this point, so it won't be clobbered
211 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
213 * Support for the fake instructions, if the instruction fails,
214 * then just execute a illegal opcode failure (like normal).
215 * Don't support these instructions inside the kernel
217 if (!kernel_mode_regs(fp) && get_instruction(&opcode, (unsigned short *)fp->pc)) {
218 if (execute_pseudodbg_assert(fp, opcode))
220 if (execute_pseudodbg(fp, opcode))
224 info.si_code = ILL_ILLOPC;
226 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
227 CHK_DEBUGGER_TRAP_MAYBE();
229 /* 0x22 - Illegal Instruction Combination, handled here */
231 info.si_code = ILL_ILLPARAOP;
233 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
234 CHK_DEBUGGER_TRAP_MAYBE();
236 /* 0x23 - Data CPLB protection violation, handled here */
238 info.si_code = ILL_CPLB_VI;
240 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
241 CHK_DEBUGGER_TRAP_MAYBE();
243 /* 0x24 - Data access misaligned, handled here */
245 info.si_code = BUS_ADRALN;
247 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
248 CHK_DEBUGGER_TRAP_MAYBE();
250 /* 0x25 - Unrecoverable Event, handled here */
252 info.si_code = ILL_ILLEXCPT;
254 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
255 CHK_DEBUGGER_TRAP_MAYBE();
257 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
258 error case is handled here */
260 info.si_code = BUS_ADRALN;
262 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
264 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
266 info.si_code = ILL_CPLB_MULHIT;
268 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
269 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
270 strerror = KERN_NOTICE "NULL pointer access\n";
273 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
274 CHK_DEBUGGER_TRAP_MAYBE();
276 /* 0x28 - Emulation Watchpoint, handled here */
278 info.si_code = TRAP_WATCHPT;
280 pr_debug(EXC_0x28(KERN_DEBUG));
281 CHK_DEBUGGER_TRAP_MAYBE();
282 /* Check if this is a watchpoint in kernel space */
283 if (kernel_mode_regs(fp))
288 /* 0x29 - Instruction fetch access error (535 only) */
289 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
290 info.si_code = BUS_OPFETCH;
292 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
293 CHK_DEBUGGER_TRAP_MAYBE();
296 /* 0x29 - Reserved, Caught by default */
298 /* 0x2A - Instruction fetch misaligned, handled here */
300 info.si_code = BUS_ADRALN;
302 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
303 CHK_DEBUGGER_TRAP_MAYBE();
305 /* 0x2B - Instruction CPLB protection violation, handled here */
307 info.si_code = ILL_CPLB_VI;
309 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
310 CHK_DEBUGGER_TRAP_MAYBE();
312 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
314 info.si_code = ILL_CPLB_MISS;
316 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
318 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
319 case VEC_CPLB_I_MHIT:
320 info.si_code = ILL_CPLB_MULHIT;
322 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
323 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
324 strerror = KERN_NOTICE "Jump to NULL address\n";
327 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
328 CHK_DEBUGGER_TRAP_MAYBE();
330 /* 0x2E - Illegal use of Supervisor Resource, handled here */
332 info.si_code = ILL_PRVOPC;
334 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
335 CHK_DEBUGGER_TRAP_MAYBE();
337 /* 0x2F - Reserved, Caught by default */
338 /* 0x30 - Reserved, Caught by default */
339 /* 0x31 - Reserved, Caught by default */
340 /* 0x32 - Reserved, Caught by default */
341 /* 0x33 - Reserved, Caught by default */
342 /* 0x34 - Reserved, Caught by default */
343 /* 0x35 - Reserved, Caught by default */
344 /* 0x36 - Reserved, Caught by default */
345 /* 0x37 - Reserved, Caught by default */
346 /* 0x38 - Reserved, Caught by default */
347 /* 0x39 - Reserved, Caught by default */
348 /* 0x3A - Reserved, Caught by default */
349 /* 0x3B - Reserved, Caught by default */
350 /* 0x3C - Reserved, Caught by default */
351 /* 0x3D - Reserved, Caught by default */
352 /* 0x3E - Reserved, Caught by default */
353 /* 0x3F - Reserved, Caught by default */
355 info.si_code = BUS_ADRALN;
357 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
358 /* System MMR Error */
359 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
360 info.si_code = BUS_ADRALN;
362 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
364 /* External Memory Addressing Error */
365 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
366 if (ANOMALY_05000310) {
367 static unsigned long anomaly_rets;
369 if ((fp->pc >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
370 (fp->pc < (L1_CODE_START + L1_CODE_LENGTH))) {
372 * A false hardware error will happen while fetching at
373 * the L1 instruction SRAM boundary. Ignore it.
375 anomaly_rets = fp->rets;
377 } else if (fp->rets == anomaly_rets) {
379 * While boundary code returns to a function, at the ret
380 * point, a new false hardware error might occur too based
381 * on tests. Ignore it too.
384 } else if ((fp->rets >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
385 (fp->rets < (L1_CODE_START + L1_CODE_LENGTH))) {
387 * If boundary code calls a function, at the entry point,
388 * a new false hardware error maybe happen based on tests.
396 info.si_code = BUS_ADRERR;
398 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
400 /* Performance Monitor Overflow */
401 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
402 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
404 /* RAISE 5 instruction */
405 case (SEQSTAT_HWERRCAUSE_RAISE_5):
406 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
408 default: /* Reserved */
409 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
412 CHK_DEBUGGER_TRAP_MAYBE();
415 * We should be handling all known exception types above,
416 * if we get here we hit a reserved one, so panic
419 info.si_code = ILL_ILLPARAOP;
421 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
422 (fp->seqstat & SEQSTAT_EXCAUSE));
423 CHK_DEBUGGER_TRAP_MAYBE();
429 /* If the fault was caused by a kernel thread, or interrupt handler
430 * we will kernel panic, so the system reboots.
432 if (kernel_mode_regs(fp) || (current && !current->mm)) {
434 oops_in_progress = 1;
437 if (sig != SIGTRAP) {
439 verbose_printk(strerror);
441 dump_bfin_process(fp);
445 /* Print out the trace buffer if it makes sense */
446 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
447 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
448 verbose_printk(KERN_NOTICE "No trace since you do not have "
449 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
452 dump_bfin_trace_buffer();
454 if (oops_in_progress) {
455 /* Dump the current kernel stack */
456 verbose_printk(KERN_NOTICE "Kernel Stack\n");
457 show_stack(current, NULL);
459 #ifndef CONFIG_ACCESS_CHECK
460 verbose_printk(KERN_EMERG "Please turn on "
461 "CONFIG_ACCESS_CHECK\n");
463 panic("Kernel exception");
465 #ifdef CONFIG_DEBUG_VERBOSE
466 unsigned long *stack;
467 /* Dump the user space stack */
468 stack = (unsigned long *)rdusp();
469 verbose_printk(KERN_NOTICE "Userspace Stack\n");
470 show_stack(NULL, stack);
476 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
486 info.si_addr = (void __user *)cpu_pda[cpu].dcplb_fault_addr;
489 info.si_addr = (void __user *)fp->pc;
492 force_sig_info(sig, &info, current);
495 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
496 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
497 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
498 fp->pc = SAFE_USER_INSTRUCTION;
501 trace_buffer_restore(j);
504 asmlinkage void double_fault_c(struct pt_regs *fp)
506 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
508 trace_buffer_save(j);
512 oops_in_progress = 1;
513 #ifdef CONFIG_DEBUG_VERBOSE
514 printk(KERN_EMERG "Double Fault\n");
515 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
516 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
517 unsigned int cpu = raw_smp_processor_id();
519 decode_address(buf, cpu_pda[cpu].retx_doublefault);
520 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
521 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
522 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
523 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
524 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
525 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
527 decode_address(buf, fp->retx);
528 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
532 dump_bfin_process(fp);
535 dump_bfin_trace_buffer();
538 panic("Double Fault - unrecoverable event");
543 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
545 switch (cplb_panic) {
546 case CPLB_NO_UNLOCKED:
547 printk(KERN_EMERG "All CPLBs are locked\n");
551 case CPLB_NO_ADDR_MATCH:
553 case CPLB_UNKNOWN_ERR:
554 printk(KERN_EMERG "Unknown CPLB Exception\n");
558 oops_in_progress = 1;
560 dump_bfin_process(fp);
564 panic("Unrecoverable event");
568 int is_valid_bugaddr(unsigned long addr)
572 if (!get_instruction(&opcode, (unsigned short *)addr))
575 return opcode == BFIN_BUG_OPCODE;
580 #ifndef CONFIG_DEBUG_VERBOSE
581 void show_regs(struct pt_regs *fp)