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>
22 # include <linux/kgdb.h>
24 # define CHK_DEBUGGER_TRAP() \
26 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
28 # define CHK_DEBUGGER_TRAP_MAYBE() \
31 CHK_DEBUGGER_TRAP(); \
34 # define CHK_DEBUGGER_TRAP() do { } while (0)
35 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
39 #ifdef CONFIG_DEBUG_VERBOSE
40 #define verbose_printk(fmt, arg...) \
43 #define verbose_printk(fmt, arg...) \
44 ({ if (0) printk(fmt, ##arg); 0; })
47 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
49 #ifdef CONFIG_DEBUG_MMRS_MODULE
50 EXPORT_SYMBOL(last_seqstat
);
54 /* Initiate the event table handler */
55 void __init
trap_init(void)
58 bfin_write_EVT3(trap
);
62 static int kernel_mode_regs(struct pt_regs
*regs
)
64 return regs
->ipend
& 0xffc0;
67 asmlinkage notrace
void trap_c(struct pt_regs
*fp
)
69 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
72 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
75 unsigned int cpu
= raw_smp_processor_id();
76 const char *strerror
= NULL
;
79 unsigned long trapnr
= fp
->seqstat
& SEQSTAT_EXCAUSE
;
82 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
83 last_seqstat
= (u32
)fp
->seqstat
;
86 /* Important - be very careful dereferncing pointers - will lead to
87 * double faults if the stack has become corrupt
90 /* 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
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); */
98 /* send the appropriate signal to the user program */
101 /* This table works in conjuction with the one in ./mach-common/entry.S
102 * 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
109 /* 0x00 - Linux Syscall, getting here is an error */
110 /* 0x01 - userspace gdb breakpoint, handled here */
112 info
.si_code
= TRAP_ILLTRAP
;
114 CHK_DEBUGGER_TRAP_MAYBE();
115 /* Check if this is a breakpoint in kernel space */
116 if (kernel_mode_regs(fp
))
120 /* 0x03 - User Defined, userspace stack overflow */
122 info
.si_code
= SEGV_STACKFLOW
;
124 strerror
= KERN_NOTICE
EXC_0x03(KERN_NOTICE
);
125 CHK_DEBUGGER_TRAP_MAYBE();
127 /* 0x02 - KGDB initial connection and break signal trap */
130 info
.si_code
= TRAP_ILLTRAP
;
135 /* 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 */
147 /* If we got here, it is most likely that someone was trying to use a
148 * custom exception handler, and it is not actually installed properly
150 case VEC_EXCPT04
... VEC_EXCPT15
:
151 info
.si_code
= ILL_ILLPARAOP
;
153 strerror
= KERN_NOTICE
EXC_0x04(KERN_NOTICE
);
154 CHK_DEBUGGER_TRAP_MAYBE();
156 /* 0x10 HW Single step, handled here */
158 info
.si_code
= TRAP_STEP
;
160 CHK_DEBUGGER_TRAP_MAYBE();
161 /* Check if this is a single step in kernel space */
162 if (kernel_mode_regs(fp
))
166 /* 0x11 - Trace Buffer Full, handled here */
168 info
.si_code
= TRAP_TRACEFLOW
;
170 strerror
= KERN_NOTICE
EXC_0x11(KERN_NOTICE
);
171 CHK_DEBUGGER_TRAP_MAYBE();
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 */
191 if (kernel_mode_regs(fp
)) {
192 switch (report_bug(fp
->pc
, fp
)) {
193 case BUG_TRAP_TYPE_NONE
:
195 case BUG_TRAP_TYPE_WARN
:
196 dump_bfin_trace_buffer();
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
207 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
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
213 if (!kernel_mode_regs(fp
) && get_instruction(&opcode
, (unsigned short *)fp
->pc
)) {
214 if (execute_pseudodbg_assert(fp
, opcode
))
216 if (execute_pseudodbg(fp
, opcode
))
220 info
.si_code
= ILL_ILLOPC
;
222 strerror
= KERN_NOTICE
EXC_0x21(KERN_NOTICE
);
223 CHK_DEBUGGER_TRAP_MAYBE();
225 /* 0x22 - Illegal Instruction Combination, handled here */
227 info
.si_code
= ILL_ILLPARAOP
;
229 strerror
= KERN_NOTICE
EXC_0x22(KERN_NOTICE
);
230 CHK_DEBUGGER_TRAP_MAYBE();
232 /* 0x23 - Data CPLB protection violation, handled here */
234 info
.si_code
= ILL_CPLB_VI
;
236 strerror
= KERN_NOTICE
EXC_0x23(KERN_NOTICE
);
237 CHK_DEBUGGER_TRAP_MAYBE();
239 /* 0x24 - Data access misaligned, handled here */
241 info
.si_code
= BUS_ADRALN
;
243 strerror
= KERN_NOTICE
EXC_0x24(KERN_NOTICE
);
244 CHK_DEBUGGER_TRAP_MAYBE();
246 /* 0x25 - Unrecoverable Event, handled here */
248 info
.si_code
= ILL_ILLEXCPT
;
250 strerror
= KERN_NOTICE
EXC_0x25(KERN_NOTICE
);
251 CHK_DEBUGGER_TRAP_MAYBE();
253 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
254 error case is handled here */
256 info
.si_code
= BUS_ADRALN
;
258 strerror
= KERN_NOTICE
EXC_0x26(KERN_NOTICE
);
260 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
262 info
.si_code
= ILL_CPLB_MULHIT
;
264 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
265 if (cpu_pda
[cpu
].dcplb_fault_addr
< FIXED_CODE_START
)
266 strerror
= KERN_NOTICE
"NULL pointer access\n";
269 strerror
= KERN_NOTICE
EXC_0x27(KERN_NOTICE
);
270 CHK_DEBUGGER_TRAP_MAYBE();
272 /* 0x28 - Emulation Watchpoint, handled here */
274 info
.si_code
= TRAP_WATCHPT
;
276 pr_debug(EXC_0x28(KERN_DEBUG
));
277 CHK_DEBUGGER_TRAP_MAYBE();
278 /* Check if this is a watchpoint in kernel space */
279 if (kernel_mode_regs(fp
))
284 /* 0x29 - Instruction fetch access error (535 only) */
285 case VEC_ISTRU_VL
: /* ADSP-BF535 only (MH) */
286 info
.si_code
= BUS_OPFETCH
;
288 strerror
= KERN_NOTICE
"BF535: VEC_ISTRU_VL\n";
289 CHK_DEBUGGER_TRAP_MAYBE();
292 /* 0x29 - Reserved, Caught by default */
294 /* 0x2A - Instruction fetch misaligned, handled here */
296 info
.si_code
= BUS_ADRALN
;
298 strerror
= KERN_NOTICE
EXC_0x2A(KERN_NOTICE
);
299 CHK_DEBUGGER_TRAP_MAYBE();
301 /* 0x2B - Instruction CPLB protection violation, handled here */
303 info
.si_code
= ILL_CPLB_VI
;
305 strerror
= KERN_NOTICE
EXC_0x2B(KERN_NOTICE
);
306 CHK_DEBUGGER_TRAP_MAYBE();
308 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
310 info
.si_code
= ILL_CPLB_MISS
;
312 strerror
= KERN_NOTICE
EXC_0x2C(KERN_NOTICE
);
314 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
315 case VEC_CPLB_I_MHIT
:
316 info
.si_code
= ILL_CPLB_MULHIT
;
318 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
319 if (cpu_pda
[cpu
].icplb_fault_addr
< FIXED_CODE_START
)
320 strerror
= KERN_NOTICE
"Jump to NULL address\n";
323 strerror
= KERN_NOTICE
EXC_0x2D(KERN_NOTICE
);
324 CHK_DEBUGGER_TRAP_MAYBE();
326 /* 0x2E - Illegal use of Supervisor Resource, handled here */
328 info
.si_code
= ILL_PRVOPC
;
330 strerror
= KERN_NOTICE
EXC_0x2E(KERN_NOTICE
);
331 CHK_DEBUGGER_TRAP_MAYBE();
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 */
351 info
.si_code
= BUS_ADRALN
;
353 switch (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) {
354 /* System MMR Error */
355 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR
):
356 info
.si_code
= BUS_ADRALN
;
358 strerror
= KERN_NOTICE
HWC_x2(KERN_NOTICE
);
360 /* External Memory Addressing Error */
361 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR
):
362 if (ANOMALY_05000310
) {
363 static unsigned long anomaly_rets
;
365 if ((fp
->pc
>= (L1_CODE_START
+ L1_CODE_LENGTH
- 512)) &&
366 (fp
->pc
< (L1_CODE_START
+ L1_CODE_LENGTH
))) {
368 * A false hardware error will happen while fetching at
369 * the L1 instruction SRAM boundary. Ignore it.
371 anomaly_rets
= fp
->rets
;
373 } else if (fp
->rets
== anomaly_rets
) {
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.
380 } else if ((fp
->rets
>= (L1_CODE_START
+ L1_CODE_LENGTH
- 512)) &&
381 (fp
->rets
< (L1_CODE_START
+ L1_CODE_LENGTH
))) {
383 * If boundary code calls a function, at the entry point,
384 * a new false hardware error maybe happen based on tests.
392 info
.si_code
= BUS_ADRERR
;
394 strerror
= KERN_NOTICE
HWC_x3(KERN_NOTICE
);
396 /* Performance Monitor Overflow */
397 case (SEQSTAT_HWERRCAUSE_PERF_FLOW
):
398 strerror
= KERN_NOTICE
HWC_x12(KERN_NOTICE
);
400 /* RAISE 5 instruction */
401 case (SEQSTAT_HWERRCAUSE_RAISE_5
):
402 printk(KERN_NOTICE
HWC_x18(KERN_NOTICE
));
404 default: /* Reserved */
405 printk(KERN_NOTICE
HWC_default(KERN_NOTICE
));
408 CHK_DEBUGGER_TRAP_MAYBE();
411 * We should be handling all known exception types above,
412 * if we get here we hit a reserved one, so panic
415 info
.si_code
= ILL_ILLPARAOP
;
417 verbose_printk(KERN_EMERG
"Caught Unhandled Exception, code = %08lx\n",
418 (fp
->seqstat
& SEQSTAT_EXCAUSE
));
419 CHK_DEBUGGER_TRAP_MAYBE();
425 /* If the fault was caused by a kernel thread, or interrupt handler
426 * we will kernel panic, so the system reboots.
428 if (kernel_mode_regs(fp
) || (current
&& !current
->mm
)) {
430 oops_in_progress
= 1;
433 if (sig
!= SIGTRAP
) {
435 verbose_printk(strerror
);
437 dump_bfin_process(fp
);
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
)
444 verbose_printk(KERN_NOTICE
"No trace since you do not have "
445 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
448 dump_bfin_trace_buffer();
450 if (oops_in_progress
) {
451 /* Dump the current kernel stack */
452 verbose_printk(KERN_NOTICE
"Kernel Stack\n");
453 show_stack(current
, NULL
);
455 #ifndef CONFIG_ACCESS_CHECK
456 verbose_printk(KERN_EMERG
"Please turn on "
457 "CONFIG_ACCESS_CHECK\n");
459 panic("Kernel exception");
461 #ifdef CONFIG_DEBUG_VERBOSE
462 unsigned long *stack
;
463 /* Dump the user space stack */
464 stack
= (unsigned long *)rdusp();
465 verbose_printk(KERN_NOTICE
"Userspace Stack\n");
466 show_stack(NULL
, stack
);
472 if (!ipipe_trap_notify(fp
->seqstat
& 0x3f, fp
))
482 info
.si_addr
= (void __user
*)cpu_pda
[cpu
].dcplb_fault_addr
;
485 info
.si_addr
= (void __user
*)fp
->pc
;
488 force_sig_info(sig
, &info
, current
);
491 if ((ANOMALY_05000461
&& trapnr
== VEC_HWERR
&& !access_ok(VERIFY_READ
, fp
->pc
, 8)) ||
492 (ANOMALY_05000281
&& trapnr
== VEC_HWERR
) ||
493 (ANOMALY_05000189
&& (trapnr
== VEC_CPLB_I_VL
|| trapnr
== VEC_CPLB_VL
)))
494 fp
->pc
= SAFE_USER_INSTRUCTION
;
497 trace_buffer_restore(j
);
500 asmlinkage
void double_fault_c(struct pt_regs
*fp
)
502 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
504 trace_buffer_save(j
);
508 oops_in_progress
= 1;
509 #ifdef CONFIG_DEBUG_VERBOSE
510 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();
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
);
523 decode_address(buf
, fp
->retx
);
524 printk(KERN_NOTICE
"The instruction at %s caused a double exception\n", buf
);
528 dump_bfin_process(fp
);
531 dump_bfin_trace_buffer();
534 panic("Double Fault - unrecoverable event");
539 void panic_cplb_error(int cplb_panic
, struct pt_regs
*fp
)
541 switch (cplb_panic
) {
542 case CPLB_NO_UNLOCKED
:
543 printk(KERN_EMERG
"All CPLBs are locked\n");
547 case CPLB_NO_ADDR_MATCH
:
549 case CPLB_UNKNOWN_ERR
:
550 printk(KERN_EMERG
"Unknown CPLB Exception\n");
554 oops_in_progress
= 1;
556 dump_bfin_process(fp
);
560 panic("Unrecoverable event");
564 int is_valid_bugaddr(unsigned long addr
)
568 if (!get_instruction(&opcode
, (unsigned short *)addr
))
571 return opcode
== BFIN_BUG_OPCODE
;
576 #ifndef CONFIG_DEBUG_VERBOSE
577 void show_regs(struct pt_regs
*fp
)