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>
21 # include <linux/kgdb.h>
23 # define CHK_DEBUGGER_TRAP() \
25 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
27 # define CHK_DEBUGGER_TRAP_MAYBE() \
30 CHK_DEBUGGER_TRAP(); \
33 # define CHK_DEBUGGER_TRAP() do { } while (0)
34 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
38 #ifdef CONFIG_DEBUG_VERBOSE
39 #define verbose_printk(fmt, arg...) \
42 #define verbose_printk(fmt, arg...) \
43 ({ if (0) printk(fmt, ##arg); 0; })
46 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
48 #ifdef CONFIG_DEBUG_MMRS_MODULE
49 EXPORT_SYMBOL(last_seqstat
);
53 /* Initiate the event table handler */
54 void __init
trap_init(void)
57 bfin_write_EVT3(trap
);
61 static int kernel_mode_regs(struct pt_regs
*regs
)
63 return regs
->ipend
& 0xffc0;
66 asmlinkage notrace
void trap_c(struct pt_regs
*fp
)
68 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
71 unsigned int cpu
= raw_smp_processor_id();
72 const char *strerror
= NULL
;
75 unsigned long trapnr
= fp
->seqstat
& SEQSTAT_EXCAUSE
;
78 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
79 last_seqstat
= (u32
)fp
->seqstat
;
82 /* Important - be very careful dereferncing pointers - will lead to
83 * double faults if the stack has become corrupt
86 /* 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
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); */
94 /* send the appropriate signal to the user program */
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
105 /* 0x00 - Linux Syscall, getting here is an error */
106 /* 0x01 - userspace gdb breakpoint, handled here */
108 info
.si_code
= TRAP_ILLTRAP
;
110 CHK_DEBUGGER_TRAP_MAYBE();
111 /* Check if this is a breakpoint in kernel space */
112 if (kernel_mode_regs(fp
))
116 /* 0x03 - User Defined, userspace stack overflow */
118 info
.si_code
= SEGV_STACKFLOW
;
120 strerror
= KERN_NOTICE
EXC_0x03(KERN_NOTICE
);
121 CHK_DEBUGGER_TRAP_MAYBE();
123 /* 0x02 - KGDB initial connection and break signal trap */
126 info
.si_code
= TRAP_ILLTRAP
;
131 /* 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 */
143 /* If we got here, it is most likely that someone was trying to use a
144 * custom exception handler, and it is not actually installed properly
146 case VEC_EXCPT04
... VEC_EXCPT15
:
147 info
.si_code
= ILL_ILLPARAOP
;
149 strerror
= KERN_NOTICE
EXC_0x04(KERN_NOTICE
);
150 CHK_DEBUGGER_TRAP_MAYBE();
152 /* 0x10 HW Single step, handled here */
154 info
.si_code
= TRAP_STEP
;
156 CHK_DEBUGGER_TRAP_MAYBE();
157 /* Check if this is a single step in kernel space */
158 if (kernel_mode_regs(fp
))
162 /* 0x11 - Trace Buffer Full, handled here */
164 info
.si_code
= TRAP_TRACEFLOW
;
166 strerror
= KERN_NOTICE
EXC_0x11(KERN_NOTICE
);
167 CHK_DEBUGGER_TRAP_MAYBE();
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 */
187 if (kernel_mode_regs(fp
)) {
188 switch (report_bug(fp
->pc
, fp
)) {
189 case BUG_TRAP_TYPE_NONE
:
191 case BUG_TRAP_TYPE_WARN
:
192 dump_bfin_trace_buffer();
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
203 info
.si_code
= ILL_ILLOPC
;
205 strerror
= KERN_NOTICE
EXC_0x21(KERN_NOTICE
);
206 CHK_DEBUGGER_TRAP_MAYBE();
208 /* 0x22 - Illegal Instruction Combination, handled here */
210 info
.si_code
= ILL_ILLPARAOP
;
212 strerror
= KERN_NOTICE
EXC_0x22(KERN_NOTICE
);
213 CHK_DEBUGGER_TRAP_MAYBE();
215 /* 0x23 - Data CPLB protection violation, handled here */
217 info
.si_code
= ILL_CPLB_VI
;
219 strerror
= KERN_NOTICE
EXC_0x23(KERN_NOTICE
);
220 CHK_DEBUGGER_TRAP_MAYBE();
222 /* 0x24 - Data access misaligned, handled here */
224 info
.si_code
= BUS_ADRALN
;
226 strerror
= KERN_NOTICE
EXC_0x24(KERN_NOTICE
);
227 CHK_DEBUGGER_TRAP_MAYBE();
229 /* 0x25 - Unrecoverable Event, handled here */
231 info
.si_code
= ILL_ILLEXCPT
;
233 strerror
= KERN_NOTICE
EXC_0x25(KERN_NOTICE
);
234 CHK_DEBUGGER_TRAP_MAYBE();
236 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
237 error case is handled here */
239 info
.si_code
= BUS_ADRALN
;
241 strerror
= KERN_NOTICE
EXC_0x26(KERN_NOTICE
);
243 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
245 info
.si_code
= ILL_CPLB_MULHIT
;
247 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
248 if (cpu_pda
[cpu
].dcplb_fault_addr
< FIXED_CODE_START
)
249 strerror
= KERN_NOTICE
"NULL pointer access\n";
252 strerror
= KERN_NOTICE
EXC_0x27(KERN_NOTICE
);
253 CHK_DEBUGGER_TRAP_MAYBE();
255 /* 0x28 - Emulation Watchpoint, handled here */
257 info
.si_code
= TRAP_WATCHPT
;
259 pr_debug(EXC_0x28(KERN_DEBUG
));
260 CHK_DEBUGGER_TRAP_MAYBE();
261 /* Check if this is a watchpoint in kernel space */
262 if (kernel_mode_regs(fp
))
267 /* 0x29 - Instruction fetch access error (535 only) */
268 case VEC_ISTRU_VL
: /* ADSP-BF535 only (MH) */
269 info
.si_code
= BUS_OPFETCH
;
271 strerror
= KERN_NOTICE
"BF535: VEC_ISTRU_VL\n";
272 CHK_DEBUGGER_TRAP_MAYBE();
275 /* 0x29 - Reserved, Caught by default */
277 /* 0x2A - Instruction fetch misaligned, handled here */
279 info
.si_code
= BUS_ADRALN
;
281 strerror
= KERN_NOTICE
EXC_0x2A(KERN_NOTICE
);
282 CHK_DEBUGGER_TRAP_MAYBE();
284 /* 0x2B - Instruction CPLB protection violation, handled here */
286 info
.si_code
= ILL_CPLB_VI
;
288 strerror
= KERN_NOTICE
EXC_0x2B(KERN_NOTICE
);
289 CHK_DEBUGGER_TRAP_MAYBE();
291 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
293 info
.si_code
= ILL_CPLB_MISS
;
295 strerror
= KERN_NOTICE
EXC_0x2C(KERN_NOTICE
);
297 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
298 case VEC_CPLB_I_MHIT
:
299 info
.si_code
= ILL_CPLB_MULHIT
;
301 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
302 if (cpu_pda
[cpu
].icplb_fault_addr
< FIXED_CODE_START
)
303 strerror
= KERN_NOTICE
"Jump to NULL address\n";
306 strerror
= KERN_NOTICE
EXC_0x2D(KERN_NOTICE
);
307 CHK_DEBUGGER_TRAP_MAYBE();
309 /* 0x2E - Illegal use of Supervisor Resource, handled here */
311 info
.si_code
= ILL_PRVOPC
;
313 strerror
= KERN_NOTICE
EXC_0x2E(KERN_NOTICE
);
314 CHK_DEBUGGER_TRAP_MAYBE();
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 */
334 info
.si_code
= BUS_ADRALN
;
336 switch (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) {
337 /* System MMR Error */
338 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR
):
339 info
.si_code
= BUS_ADRALN
;
341 strerror
= KERN_NOTICE
HWC_x2(KERN_NOTICE
);
343 /* External Memory Addressing Error */
344 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR
):
345 if (ANOMALY_05000310
) {
346 static unsigned long anomaly_rets
;
348 if ((fp
->pc
>= (L1_CODE_START
+ L1_CODE_LENGTH
- 512)) &&
349 (fp
->pc
< (L1_CODE_START
+ L1_CODE_LENGTH
))) {
351 * A false hardware error will happen while fetching at
352 * the L1 instruction SRAM boundary. Ignore it.
354 anomaly_rets
= fp
->rets
;
356 } else if (fp
->rets
== anomaly_rets
) {
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.
363 } else if ((fp
->rets
>= (L1_CODE_START
+ L1_CODE_LENGTH
- 512)) &&
364 (fp
->rets
< (L1_CODE_START
+ L1_CODE_LENGTH
))) {
366 * If boundary code calls a function, at the entry point,
367 * a new false hardware error maybe happen based on tests.
375 info
.si_code
= BUS_ADRERR
;
377 strerror
= KERN_NOTICE
HWC_x3(KERN_NOTICE
);
379 /* Performance Monitor Overflow */
380 case (SEQSTAT_HWERRCAUSE_PERF_FLOW
):
381 strerror
= KERN_NOTICE
HWC_x12(KERN_NOTICE
);
383 /* RAISE 5 instruction */
384 case (SEQSTAT_HWERRCAUSE_RAISE_5
):
385 printk(KERN_NOTICE
HWC_x18(KERN_NOTICE
));
387 default: /* Reserved */
388 printk(KERN_NOTICE
HWC_default(KERN_NOTICE
));
391 CHK_DEBUGGER_TRAP_MAYBE();
394 * We should be handling all known exception types above,
395 * if we get here we hit a reserved one, so panic
398 info
.si_code
= ILL_ILLPARAOP
;
400 verbose_printk(KERN_EMERG
"Caught Unhandled Exception, code = %08lx\n",
401 (fp
->seqstat
& SEQSTAT_EXCAUSE
));
402 CHK_DEBUGGER_TRAP_MAYBE();
408 /* If the fault was caused by a kernel thread, or interrupt handler
409 * we will kernel panic, so the system reboots.
411 if (kernel_mode_regs(fp
) || (current
&& !current
->mm
)) {
413 oops_in_progress
= 1;
416 if (sig
!= SIGTRAP
) {
418 verbose_printk(strerror
);
420 dump_bfin_process(fp
);
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
)
427 verbose_printk(KERN_NOTICE
"No trace since you do not have "
428 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
431 dump_bfin_trace_buffer();
433 if (oops_in_progress
) {
434 /* Dump the current kernel stack */
435 verbose_printk(KERN_NOTICE
"Kernel Stack\n");
436 show_stack(current
, NULL
);
438 #ifndef CONFIG_ACCESS_CHECK
439 verbose_printk(KERN_EMERG
"Please turn on "
440 "CONFIG_ACCESS_CHECK\n");
442 panic("Kernel exception");
444 #ifdef CONFIG_DEBUG_VERBOSE
445 unsigned long *stack
;
446 /* Dump the user space stack */
447 stack
= (unsigned long *)rdusp();
448 verbose_printk(KERN_NOTICE
"Userspace Stack\n");
449 show_stack(NULL
, stack
);
455 if (!ipipe_trap_notify(fp
->seqstat
& 0x3f, fp
))
465 info
.si_addr
= (void __user
*)cpu_pda
[cpu
].dcplb_fault_addr
;
468 info
.si_addr
= (void __user
*)fp
->pc
;
471 force_sig_info(sig
, &info
, current
);
474 if ((ANOMALY_05000461
&& trapnr
== VEC_HWERR
&& !access_ok(VERIFY_READ
, fp
->pc
, 8)) ||
475 (ANOMALY_05000281
&& trapnr
== VEC_HWERR
) ||
476 (ANOMALY_05000189
&& (trapnr
== VEC_CPLB_I_VL
|| trapnr
== VEC_CPLB_VL
)))
477 fp
->pc
= SAFE_USER_INSTRUCTION
;
480 trace_buffer_restore(j
);
483 asmlinkage
void double_fault_c(struct pt_regs
*fp
)
485 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
487 trace_buffer_save(j
);
491 oops_in_progress
= 1;
492 #ifdef CONFIG_DEBUG_VERBOSE
493 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();
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
);
506 decode_address(buf
, fp
->retx
);
507 printk(KERN_NOTICE
"The instruction at %s caused a double exception\n", buf
);
511 dump_bfin_process(fp
);
514 dump_bfin_trace_buffer();
517 panic("Double Fault - unrecoverable event");
522 void panic_cplb_error(int cplb_panic
, struct pt_regs
*fp
)
524 switch (cplb_panic
) {
525 case CPLB_NO_UNLOCKED
:
526 printk(KERN_EMERG
"All CPLBs are locked\n");
530 case CPLB_NO_ADDR_MATCH
:
532 case CPLB_UNKNOWN_ERR
:
533 printk(KERN_EMERG
"Unknown CPLB Exception\n");
537 oops_in_progress
= 1;
539 dump_bfin_process(fp
);
543 panic("Unrecoverable event");
547 int is_valid_bugaddr(unsigned long addr
)
549 unsigned short opcode
;
551 if (!get_instruction(&opcode
, (unsigned short *)addr
))
554 return opcode
== BFIN_BUG_OPCODE
;
559 #ifndef CONFIG_DEBUG_VERBOSE
560 void show_regs(struct pt_regs
*fp
)