2 * File: arch/blackfin/kernel/traps.c
4 * Author: Hamish Macdonald
7 * Description: uses S/W interrupt 15 for the system calls
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/bug.h>
31 #include <linux/uaccess.h>
32 #include <linux/interrupt.h>
33 #include <linux/module.h>
34 #include <linux/kallsyms.h>
36 #include <linux/rbtree.h>
37 #include <asm/traps.h>
38 #include <asm/cacheflush.h>
41 #include <asm/blackfin.h>
42 #include <asm/irq_handler.h>
43 #include <linux/irq.h>
44 #include <asm/trace.h>
45 #include <asm/fixed_code.h>
48 # include <linux/kgdb.h>
50 # define CHK_DEBUGGER_TRAP() \
52 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
54 # define CHK_DEBUGGER_TRAP_MAYBE() \
57 CHK_DEBUGGER_TRAP(); \
60 # define CHK_DEBUGGER_TRAP() do { } while (0)
61 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
65 #ifdef CONFIG_DEBUG_VERBOSE
66 #define verbose_printk(fmt, arg...) \
69 #define verbose_printk(fmt, arg...) \
70 ({ if (0) printk(fmt, ##arg); 0; })
73 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
75 #ifdef CONFIG_DEBUG_MMRS_MODULE
76 EXPORT_SYMBOL(last_seqstat
);
80 /* Initiate the event table handler */
81 void __init
trap_init(void)
84 bfin_write_EVT3(trap
);
88 static void decode_address(char *buf
, unsigned long address
)
90 #ifdef CONFIG_DEBUG_VERBOSE
91 struct task_struct
*p
;
93 unsigned long flags
, offset
;
94 unsigned char in_atomic
= (bfin_read_IPEND() & 0x10) || in_atomic();
97 #ifdef CONFIG_KALLSYMS
98 unsigned long symsize
;
104 /* look up the address and see if we are in kernel space */
105 symname
= kallsyms_lookup(address
, &symsize
, &offset
, &modname
, namebuf
);
108 /* yeah! kernel space! */
110 modname
= delim
= "";
111 sprintf(buf
, "<0x%p> { %s%s%s%s + 0x%lx }",
112 (void *)address
, delim
, modname
, delim
, symname
,
113 (unsigned long)offset
);
119 /* Problem in fixed code section? */
120 if (address
>= FIXED_CODE_START
&& address
< FIXED_CODE_END
) {
121 sprintf(buf
, "<0x%p> /* Maybe fixed code section */", (void *)address
);
125 /* Problem somewhere before the kernel start address */
126 if (address
< CONFIG_BOOT_LOAD
) {
127 sprintf(buf
, "<0x%p> /* Maybe null pointer? */", (void *)address
);
131 /* looks like we're off in user-land, so let's walk all the
132 * mappings of all our processes and see if we can't be a whee
135 write_lock_irqsave(&tasklist_lock
, flags
);
136 for_each_process(p
) {
137 mm
= (in_atomic
? p
->mm
: get_task_mm(p
));
141 for (n
= rb_first(&mm
->mm_rb
); n
; n
= rb_next(n
)) {
142 struct vm_area_struct
*vma
;
144 vma
= rb_entry(n
, struct vm_area_struct
, vm_rb
);
146 if (address
>= vma
->vm_start
&& address
< vma
->vm_end
) {
148 char *name
= p
->comm
;
149 struct file
*file
= vma
->vm_file
;
152 char *d_name
= d_path(&file
->f_path
, _tmpbuf
,
158 /* FLAT does not have its text aligned to the start of
159 * the map while FDPIC ELF does ...
162 /* before we can check flat/fdpic, we need to
163 * make sure current is valid
165 if ((unsigned long)current
>= FIXED_CODE_START
&&
166 !((unsigned long)current
& 0x3)) {
168 (address
> current
->mm
->start_code
) &&
169 (address
< current
->mm
->end_code
))
170 offset
= address
- current
->mm
->start_code
;
172 offset
= (address
- vma
->vm_start
) +
173 (vma
->vm_pgoff
<< PAGE_SHIFT
);
175 sprintf(buf
, "<0x%p> [ %s + 0x%lx ]",
176 (void *)address
, name
, offset
);
178 sprintf(buf
, "<0x%p> [ %s vma:0x%lx-0x%lx]",
179 (void *)address
, name
,
180 vma
->vm_start
, vma
->vm_end
);
186 sprintf(buf
, "<0x%p> [ %s ] dynamic memory", (void *)address
, name
);
195 /* we were unable to find this address anywhere */
196 sprintf(buf
, "<0x%p> /* kernel dynamic memory */", (void *)address
);
199 write_unlock_irqrestore(&tasklist_lock
, flags
);
205 asmlinkage
void double_fault_c(struct pt_regs
*fp
)
207 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
209 trace_buffer_save(j
);
213 oops_in_progress
= 1;
214 #ifdef CONFIG_DEBUG_VERBOSE
215 printk(KERN_EMERG
"Double Fault\n");
216 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
217 if (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_UNCOV
) {
218 unsigned int cpu
= smp_processor_id();
220 decode_address(buf
, cpu_pda
[cpu
].retx
);
221 printk(KERN_EMERG
"While handling exception (EXCAUSE = 0x%x) at %s:\n",
222 (unsigned int)cpu_pda
[cpu
].seqstat
& SEQSTAT_EXCAUSE
, buf
);
223 decode_address(buf
, cpu_pda
[cpu
].dcplb_fault_addr
);
224 printk(KERN_NOTICE
" DCPLB_FAULT_ADDR: %s\n", buf
);
225 decode_address(buf
, cpu_pda
[cpu
].icplb_fault_addr
);
226 printk(KERN_NOTICE
" ICPLB_FAULT_ADDR: %s\n", buf
);
228 decode_address(buf
, fp
->retx
);
229 printk(KERN_NOTICE
"The instruction at %s caused a double exception\n", buf
);
233 dump_bfin_process(fp
);
236 dump_bfin_trace_buffer();
239 panic("Double Fault - unrecoverable event");
243 static int kernel_mode_regs(struct pt_regs
*regs
)
245 return regs
->ipend
& 0xffc0;
248 asmlinkage
void trap_c(struct pt_regs
*fp
)
250 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
253 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
254 unsigned int cpu
= smp_processor_id();
256 const char *strerror
= NULL
;
259 unsigned long trapnr
= fp
->seqstat
& SEQSTAT_EXCAUSE
;
261 trace_buffer_save(j
);
262 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
263 last_seqstat
= (u32
)fp
->seqstat
;
266 /* Important - be very careful dereferncing pointers - will lead to
267 * double faults if the stack has become corrupt
271 /* IPEND is skipped if KGDB isn't enabled (see entry code) */
272 fp
->ipend
= bfin_read_IPEND();
275 /* trap_c() will be called for exceptions. During exceptions
276 * processing, the pc value should be set with retx value.
277 * With this change we can cleanup some code in signal.c- TODO
279 fp
->orig_pc
= fp
->retx
;
280 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
281 trapnr, fp->ipend, fp->pc, fp->retx); */
283 /* send the appropriate signal to the user program */
286 /* This table works in conjuction with the one in ./mach-common/entry.S
287 * Some exceptions are handled there (in assembly, in exception space)
288 * Some are handled here, (in C, in interrupt space)
289 * Some, like CPLB, are handled in both, where the normal path is
290 * handled in assembly/exception space, and the error path is handled
294 /* 0x00 - Linux Syscall, getting here is an error */
295 /* 0x01 - userspace gdb breakpoint, handled here */
297 info
.si_code
= TRAP_ILLTRAP
;
299 CHK_DEBUGGER_TRAP_MAYBE();
300 /* Check if this is a breakpoint in kernel space */
301 if (kernel_mode_regs(fp
))
305 /* 0x03 - User Defined, userspace stack overflow */
307 info
.si_code
= SEGV_STACKFLOW
;
309 strerror
= KERN_NOTICE
EXC_0x03(KERN_NOTICE
);
310 CHK_DEBUGGER_TRAP_MAYBE();
312 /* 0x02 - KGDB initial connection and break signal trap */
315 info
.si_code
= TRAP_ILLTRAP
;
320 /* 0x04 - User Defined */
321 /* 0x05 - User Defined */
322 /* 0x06 - User Defined */
323 /* 0x07 - User Defined */
324 /* 0x08 - User Defined */
325 /* 0x09 - User Defined */
326 /* 0x0A - User Defined */
327 /* 0x0B - User Defined */
328 /* 0x0C - User Defined */
329 /* 0x0D - User Defined */
330 /* 0x0E - User Defined */
331 /* 0x0F - User Defined */
332 /* If we got here, it is most likely that someone was trying to use a
333 * custom exception handler, and it is not actually installed properly
335 case VEC_EXCPT04
... VEC_EXCPT15
:
336 info
.si_code
= ILL_ILLPARAOP
;
338 strerror
= KERN_NOTICE
EXC_0x04(KERN_NOTICE
);
339 CHK_DEBUGGER_TRAP_MAYBE();
341 /* 0x10 HW Single step, handled here */
343 info
.si_code
= TRAP_STEP
;
345 CHK_DEBUGGER_TRAP_MAYBE();
346 /* Check if this is a single step in kernel space */
347 if (kernel_mode_regs(fp
))
351 /* 0x11 - Trace Buffer Full, handled here */
353 info
.si_code
= TRAP_TRACEFLOW
;
355 strerror
= KERN_NOTICE
EXC_0x11(KERN_NOTICE
);
356 CHK_DEBUGGER_TRAP_MAYBE();
358 /* 0x12 - Reserved, Caught by default */
359 /* 0x13 - Reserved, Caught by default */
360 /* 0x14 - Reserved, Caught by default */
361 /* 0x15 - Reserved, Caught by default */
362 /* 0x16 - Reserved, Caught by default */
363 /* 0x17 - Reserved, Caught by default */
364 /* 0x18 - Reserved, Caught by default */
365 /* 0x19 - Reserved, Caught by default */
366 /* 0x1A - Reserved, Caught by default */
367 /* 0x1B - Reserved, Caught by default */
368 /* 0x1C - Reserved, Caught by default */
369 /* 0x1D - Reserved, Caught by default */
370 /* 0x1E - Reserved, Caught by default */
371 /* 0x1F - Reserved, Caught by default */
372 /* 0x20 - Reserved, Caught by default */
373 /* 0x21 - Undefined Instruction, handled here */
376 if (kernel_mode_regs(fp
)) {
377 switch (report_bug(fp
->pc
, fp
)) {
378 case BUG_TRAP_TYPE_NONE
:
380 case BUG_TRAP_TYPE_WARN
:
381 dump_bfin_trace_buffer();
384 case BUG_TRAP_TYPE_BUG
:
385 /* call to panic() will dump trace, and it is
386 * off at this point, so it won't be clobbered
392 info
.si_code
= ILL_ILLOPC
;
394 strerror
= KERN_NOTICE
EXC_0x21(KERN_NOTICE
);
395 CHK_DEBUGGER_TRAP_MAYBE();
397 /* 0x22 - Illegal Instruction Combination, handled here */
399 info
.si_code
= ILL_ILLPARAOP
;
401 strerror
= KERN_NOTICE
EXC_0x22(KERN_NOTICE
);
402 CHK_DEBUGGER_TRAP_MAYBE();
404 /* 0x23 - Data CPLB protection violation, handled here */
406 info
.si_code
= ILL_CPLB_VI
;
408 strerror
= KERN_NOTICE
EXC_0x23(KERN_NOTICE
);
409 CHK_DEBUGGER_TRAP_MAYBE();
411 /* 0x24 - Data access misaligned, handled here */
413 info
.si_code
= BUS_ADRALN
;
415 strerror
= KERN_NOTICE
EXC_0x24(KERN_NOTICE
);
416 CHK_DEBUGGER_TRAP_MAYBE();
418 /* 0x25 - Unrecoverable Event, handled here */
420 info
.si_code
= ILL_ILLEXCPT
;
422 strerror
= KERN_NOTICE
EXC_0x25(KERN_NOTICE
);
423 CHK_DEBUGGER_TRAP_MAYBE();
425 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
426 error case is handled here */
428 info
.si_code
= BUS_ADRALN
;
430 strerror
= KERN_NOTICE
EXC_0x26(KERN_NOTICE
);
432 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
434 info
.si_code
= ILL_CPLB_MULHIT
;
436 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
437 if (cpu_pda
[cpu
].dcplb_fault_addr
< FIXED_CODE_START
)
438 strerror
= KERN_NOTICE
"NULL pointer access\n";
441 strerror
= KERN_NOTICE
EXC_0x27(KERN_NOTICE
);
442 CHK_DEBUGGER_TRAP_MAYBE();
444 /* 0x28 - Emulation Watchpoint, handled here */
446 info
.si_code
= TRAP_WATCHPT
;
448 pr_debug(EXC_0x28(KERN_DEBUG
));
449 CHK_DEBUGGER_TRAP_MAYBE();
450 /* Check if this is a watchpoint in kernel space */
451 if (kernel_mode_regs(fp
))
456 /* 0x29 - Instruction fetch access error (535 only) */
457 case VEC_ISTRU_VL
: /* ADSP-BF535 only (MH) */
458 info
.si_code
= BUS_OPFETCH
;
460 strerror
= KERN_NOTICE
"BF535: VEC_ISTRU_VL\n";
461 CHK_DEBUGGER_TRAP_MAYBE();
464 /* 0x29 - Reserved, Caught by default */
466 /* 0x2A - Instruction fetch misaligned, handled here */
468 info
.si_code
= BUS_ADRALN
;
470 strerror
= KERN_NOTICE
EXC_0x2A(KERN_NOTICE
);
471 CHK_DEBUGGER_TRAP_MAYBE();
473 /* 0x2B - Instruction CPLB protection violation, handled here */
475 info
.si_code
= ILL_CPLB_VI
;
477 strerror
= KERN_NOTICE
EXC_0x2B(KERN_NOTICE
);
478 CHK_DEBUGGER_TRAP_MAYBE();
480 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
482 info
.si_code
= ILL_CPLB_MISS
;
484 strerror
= KERN_NOTICE
EXC_0x2C(KERN_NOTICE
);
486 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
487 case VEC_CPLB_I_MHIT
:
488 info
.si_code
= ILL_CPLB_MULHIT
;
490 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
491 if (cpu_pda
[cpu
].icplb_fault_addr
< FIXED_CODE_START
)
492 strerror
= KERN_NOTICE
"Jump to NULL address\n";
495 strerror
= KERN_NOTICE
EXC_0x2D(KERN_NOTICE
);
496 CHK_DEBUGGER_TRAP_MAYBE();
498 /* 0x2E - Illegal use of Supervisor Resource, handled here */
500 info
.si_code
= ILL_PRVOPC
;
502 strerror
= KERN_NOTICE
EXC_0x2E(KERN_NOTICE
);
503 CHK_DEBUGGER_TRAP_MAYBE();
505 /* 0x2F - Reserved, Caught by default */
506 /* 0x30 - Reserved, Caught by default */
507 /* 0x31 - Reserved, Caught by default */
508 /* 0x32 - Reserved, Caught by default */
509 /* 0x33 - Reserved, Caught by default */
510 /* 0x34 - Reserved, Caught by default */
511 /* 0x35 - Reserved, Caught by default */
512 /* 0x36 - Reserved, Caught by default */
513 /* 0x37 - Reserved, Caught by default */
514 /* 0x38 - Reserved, Caught by default */
515 /* 0x39 - Reserved, Caught by default */
516 /* 0x3A - Reserved, Caught by default */
517 /* 0x3B - Reserved, Caught by default */
518 /* 0x3C - Reserved, Caught by default */
519 /* 0x3D - Reserved, Caught by default */
520 /* 0x3E - Reserved, Caught by default */
521 /* 0x3F - Reserved, Caught by default */
523 info
.si_code
= BUS_ADRALN
;
525 switch (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) {
526 /* System MMR Error */
527 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR
):
528 info
.si_code
= BUS_ADRALN
;
530 strerror
= KERN_NOTICE
HWC_x2(KERN_NOTICE
);
532 /* External Memory Addressing Error */
533 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR
):
534 info
.si_code
= BUS_ADRERR
;
536 strerror
= KERN_NOTICE
HWC_x3(KERN_NOTICE
);
538 /* Performance Monitor Overflow */
539 case (SEQSTAT_HWERRCAUSE_PERF_FLOW
):
540 strerror
= KERN_NOTICE
HWC_x12(KERN_NOTICE
);
542 /* RAISE 5 instruction */
543 case (SEQSTAT_HWERRCAUSE_RAISE_5
):
544 printk(KERN_NOTICE
HWC_x18(KERN_NOTICE
));
546 default: /* Reserved */
547 printk(KERN_NOTICE
HWC_default(KERN_NOTICE
));
550 CHK_DEBUGGER_TRAP_MAYBE();
553 * We should be handling all known exception types above,
554 * if we get here we hit a reserved one, so panic
557 info
.si_code
= ILL_ILLPARAOP
;
559 verbose_printk(KERN_EMERG
"Caught Unhandled Exception, code = %08lx\n",
560 (fp
->seqstat
& SEQSTAT_EXCAUSE
));
561 CHK_DEBUGGER_TRAP_MAYBE();
567 /* If the fault was caused by a kernel thread, or interrupt handler
568 * we will kernel panic, so the system reboots.
570 if (kernel_mode_regs(fp
) || (current
&& !current
->mm
)) {
572 oops_in_progress
= 1;
575 if (sig
!= SIGTRAP
) {
577 verbose_printk(strerror
);
579 dump_bfin_process(fp
);
583 /* Print out the trace buffer if it makes sense */
584 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
585 if (trapnr
== VEC_CPLB_I_M
|| trapnr
== VEC_CPLB_M
)
586 verbose_printk(KERN_NOTICE
"No trace since you do not have "
587 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
590 dump_bfin_trace_buffer();
592 if (oops_in_progress
) {
593 /* Dump the current kernel stack */
594 verbose_printk(KERN_NOTICE
"Kernel Stack\n");
595 show_stack(current
, NULL
);
597 #ifndef CONFIG_ACCESS_CHECK
598 verbose_printk(KERN_EMERG
"Please turn on "
599 "CONFIG_ACCESS_CHECK\n");
601 panic("Kernel exception");
603 #ifdef CONFIG_DEBUG_VERBOSE
604 unsigned long *stack
;
605 /* Dump the user space stack */
606 stack
= (unsigned long *)rdusp();
607 verbose_printk(KERN_NOTICE
"Userspace Stack\n");
608 show_stack(NULL
, stack
);
614 if (!ipipe_trap_notify(fp
->seqstat
& 0x3f, fp
))
619 info
.si_addr
= (void __user
*)fp
->pc
;
620 force_sig_info(sig
, &info
, current
);
623 if ((ANOMALY_05000461
&& trapnr
== VEC_HWERR
&& !access_ok(VERIFY_READ
, fp
->pc
, 8)) ||
624 (ANOMALY_05000281
&& trapnr
== VEC_HWERR
) ||
625 (ANOMALY_05000189
&& (trapnr
== VEC_CPLB_I_VL
|| trapnr
== VEC_CPLB_VL
)))
626 fp
->pc
= SAFE_USER_INSTRUCTION
;
629 trace_buffer_restore(j
);
632 /* Typical exception handling routines */
634 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
637 * Similar to get_user, do some address checking, then dereference
638 * Return true on sucess, false on bad address
640 static bool get_instruction(unsigned short *val
, unsigned short *address
)
642 unsigned long addr
= (unsigned long)address
;
644 /* Check for odd addresses */
648 /* MMR region will never have instructions */
649 if (addr
>= SYSMMR_BASE
)
652 switch (bfin_mem_access_type(addr
, 2)) {
653 case BFIN_MEM_ACCESS_CORE
:
654 case BFIN_MEM_ACCESS_CORE_ONLY
:
657 case BFIN_MEM_ACCESS_DMA
:
658 dma_memcpy(val
, address
, 2);
660 case BFIN_MEM_ACCESS_ITEST
:
661 isram_memcpy(val
, address
, 2);
663 default: /* invalid access */
669 * decode the instruction if we are printing out the trace, as it
670 * makes things easier to follow, without running it through objdump
671 * These are the normal instructions which cause change of flow, which
672 * would be at the source of the trace buffer
674 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
675 static void decode_instruction(unsigned short *address
)
677 unsigned short opcode
;
679 if (get_instruction(&opcode
, address
)) {
680 if (opcode
== 0x0010)
681 verbose_printk("RTS");
682 else if (opcode
== 0x0011)
683 verbose_printk("RTI");
684 else if (opcode
== 0x0012)
685 verbose_printk("RTX");
686 else if (opcode
== 0x0013)
687 verbose_printk("RTN");
688 else if (opcode
== 0x0014)
689 verbose_printk("RTE");
690 else if (opcode
== 0x0025)
691 verbose_printk("EMUEXCPT");
692 else if (opcode
== 0x0040 && opcode
<= 0x0047)
693 verbose_printk("STI R%i", opcode
& 7);
694 else if (opcode
>= 0x0050 && opcode
<= 0x0057)
695 verbose_printk("JUMP (P%i)", opcode
& 7);
696 else if (opcode
>= 0x0060 && opcode
<= 0x0067)
697 verbose_printk("CALL (P%i)", opcode
& 7);
698 else if (opcode
>= 0x0070 && opcode
<= 0x0077)
699 verbose_printk("CALL (PC+P%i)", opcode
& 7);
700 else if (opcode
>= 0x0080 && opcode
<= 0x0087)
701 verbose_printk("JUMP (PC+P%i)", opcode
& 7);
702 else if (opcode
>= 0x0090 && opcode
<= 0x009F)
703 verbose_printk("RAISE 0x%x", opcode
& 0xF);
704 else if (opcode
>= 0x00A0 && opcode
<= 0x00AF)
705 verbose_printk("EXCPT 0x%x", opcode
& 0xF);
706 else if ((opcode
>= 0x1000 && opcode
<= 0x13FF) || (opcode
>= 0x1800 && opcode
<= 0x1BFF))
707 verbose_printk("IF !CC JUMP");
708 else if ((opcode
>= 0x1400 && opcode
<= 0x17ff) || (opcode
>= 0x1c00 && opcode
<= 0x1fff))
709 verbose_printk("IF CC JUMP");
710 else if (opcode
>= 0x2000 && opcode
<= 0x2fff)
711 verbose_printk("JUMP.S");
712 else if (opcode
>= 0xe080 && opcode
<= 0xe0ff)
713 verbose_printk("LSETUP");
714 else if (opcode
>= 0xe200 && opcode
<= 0xe2ff)
715 verbose_printk("JUMP.L");
716 else if (opcode
>= 0xe300 && opcode
<= 0xe3ff)
717 verbose_printk("CALL pcrel");
719 verbose_printk("0x%04x", opcode
);
725 void dump_bfin_trace_buffer(void)
727 #ifdef CONFIG_DEBUG_VERBOSE
728 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
731 unsigned short *addr
;
732 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
736 trace_buffer_save(tflags
);
738 printk(KERN_NOTICE
"Hardware Trace:\n");
740 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
741 printk(KERN_NOTICE
"WARNING: Expanded trace turned on - can not trace exceptions\n");
744 if (likely(bfin_read_TBUFSTAT() & TBUFCNT
)) {
745 for (; bfin_read_TBUFSTAT() & TBUFCNT
; i
++) {
746 decode_address(buf
, (unsigned long)bfin_read_TBUF());
747 printk(KERN_NOTICE
"%4i Target : %s\n", i
, buf
);
748 addr
= (unsigned short *)bfin_read_TBUF();
749 decode_address(buf
, (unsigned long)addr
);
750 printk(KERN_NOTICE
" Source : %s ", buf
);
751 decode_instruction(addr
);
756 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
757 if (trace_buff_offset
)
758 index
= trace_buff_offset
/ 4;
762 j
= (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN
) * 128;
764 decode_address(buf
, software_trace_buff
[index
]);
765 printk(KERN_NOTICE
"%4i Target : %s\n", i
, buf
);
769 decode_address(buf
, software_trace_buff
[index
]);
770 printk(KERN_NOTICE
" Source : %s ", buf
);
771 decode_instruction((unsigned short *)software_trace_buff
[index
]);
781 trace_buffer_restore(tflags
);
785 EXPORT_SYMBOL(dump_bfin_trace_buffer
);
788 int is_valid_bugaddr(unsigned long addr
)
790 unsigned short opcode
;
792 if (!get_instruction(&opcode
, (unsigned short *)addr
))
795 return opcode
== BFIN_BUG_OPCODE
;
800 * Checks to see if the address pointed to is either a
801 * 16-bit CALL instruction, or a 32-bit CALL instruction
803 static bool is_bfin_call(unsigned short *addr
)
805 unsigned short opcode
= 0, *ins_addr
;
806 ins_addr
= (unsigned short *)addr
;
808 if (!get_instruction(&opcode
, ins_addr
))
811 if ((opcode
>= 0x0060 && opcode
<= 0x0067) ||
812 (opcode
>= 0x0070 && opcode
<= 0x0077))
816 if (!get_instruction(&opcode
, ins_addr
))
819 if (opcode
>= 0xE300 && opcode
<= 0xE3FF)
826 void show_stack(struct task_struct
*task
, unsigned long *stack
)
829 unsigned int *addr
, *endstack
, *fp
= 0, *frame
;
830 unsigned short *ins_addr
;
832 unsigned int i
, j
, ret_addr
, frame_no
= 0;
835 * If we have been passed a specific stack, use that one otherwise
836 * if we have been passed a task structure, use that, otherwise
837 * use the stack of where the variable "stack" exists
842 /* We know this is a kernel stack, so this is the start/end */
843 stack
= (unsigned long *)task
->thread
.ksp
;
844 endstack
= (unsigned int *)(((unsigned int)(stack
) & ~(THREAD_SIZE
- 1)) + THREAD_SIZE
);
846 /* print out the existing stack info */
847 stack
= (unsigned long *)&stack
;
848 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
851 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
853 printk(KERN_NOTICE
"Stack info:\n");
854 decode_address(buf
, (unsigned int)stack
);
855 printk(KERN_NOTICE
" SP: [0x%p] %s\n", stack
, buf
);
857 if (!access_ok(VERIFY_READ
, stack
, (unsigned int)endstack
- (unsigned int)stack
)) {
858 printk(KERN_NOTICE
"Invalid stack pointer\n");
862 /* First thing is to look for a frame pointer */
863 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF); addr
< endstack
; addr
++) {
866 ins_addr
= (unsigned short *)*addr
;
868 if (is_bfin_call(ins_addr
))
872 /* Let's check to see if it is a frame pointer */
873 while (fp
>= (addr
- 1) && fp
< endstack
874 && fp
&& ((unsigned int) fp
& 0x3) == 0)
875 fp
= (unsigned int *)*fp
;
876 if (fp
== 0 || fp
== endstack
) {
885 printk(KERN_NOTICE
" FP: (0x%p)\n", fp
);
890 * Now that we think we know where things are, we
891 * walk the stack again, this time printing things out
892 * incase there is no frame pointer, we still look for
893 * valid return addresses
896 /* First time print out data, next time, print out symbols */
897 for (j
= 0; j
<= 1; j
++) {
899 printk(KERN_NOTICE
"Return addresses in stack:\n");
901 printk(KERN_NOTICE
" Memory from 0x%08lx to %p", ((long unsigned int)stack
& ~0xF), endstack
);
906 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF), i
= 0;
907 addr
<= endstack
; addr
++, i
++) {
910 if (!j
&& i
% 8 == 0)
911 printk(KERN_NOTICE
"%p:",addr
);
913 /* if it is an odd address, or zero, just skip it */
914 if (*addr
& 0x1 || !*addr
)
917 ins_addr
= (unsigned short *)*addr
;
919 /* Go back one instruction, and see if it is a CALL */
921 ret_addr
= is_bfin_call(ins_addr
);
923 if (!j
&& stack
== (unsigned long *)addr
)
924 printk("[%08x]", *addr
);
927 decode_address(buf
, (unsigned int)*addr
);
929 printk(KERN_NOTICE
" frame %2i : %s\n", frame_no
, buf
);
932 printk(KERN_NOTICE
" address : %s\n", buf
);
934 printk("<%08x>", *addr
);
935 else if (fp
== addr
) {
939 printk("(%08x)", *addr
);
941 fp
= (unsigned int *)*addr
;
945 printk(" %08x ", *addr
);
953 void dump_stack(void)
956 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
959 trace_buffer_save(tflags
);
960 dump_bfin_trace_buffer();
961 show_stack(current
, &stack
);
962 trace_buffer_restore(tflags
);
964 EXPORT_SYMBOL(dump_stack
);
966 void dump_bfin_process(struct pt_regs
*fp
)
968 #ifdef CONFIG_DEBUG_VERBOSE
969 /* We should be able to look at fp->ipend, but we don't push it on the
970 * stack all the time, so do this until we fix that */
971 unsigned int context
= bfin_read_IPEND();
973 if (oops_in_progress
)
974 verbose_printk(KERN_EMERG
"Kernel OOPS in progress\n");
976 if (context
& 0x0020 && (fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
)
977 verbose_printk(KERN_NOTICE
"HW Error context\n");
978 else if (context
& 0x0020)
979 verbose_printk(KERN_NOTICE
"Deferred Exception context\n");
980 else if (context
& 0x3FC0)
981 verbose_printk(KERN_NOTICE
"Interrupt context\n");
982 else if (context
& 0x4000)
983 verbose_printk(KERN_NOTICE
"Deferred Interrupt context\n");
984 else if (context
& 0x8000)
985 verbose_printk(KERN_NOTICE
"Kernel process context\n");
987 /* Because we are crashing, and pointers could be bad, we check things
988 * pretty closely before we use them
990 if ((unsigned long)current
>= FIXED_CODE_START
&&
991 !((unsigned long)current
& 0x3) && current
->pid
) {
992 verbose_printk(KERN_NOTICE
"CURRENT PROCESS:\n");
993 if (current
->comm
>= (char *)FIXED_CODE_START
)
994 verbose_printk(KERN_NOTICE
"COMM=%s PID=%d\n",
995 current
->comm
, current
->pid
);
997 verbose_printk(KERN_NOTICE
"COMM= invalid\n");
999 printk(KERN_NOTICE
"CPU = %d\n", current_thread_info()->cpu
);
1000 if (!((unsigned long)current
->mm
& 0x3) && (unsigned long)current
->mm
>= FIXED_CODE_START
)
1001 verbose_printk(KERN_NOTICE
1002 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
1003 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
1004 (void *)current
->mm
->start_code
,
1005 (void *)current
->mm
->end_code
,
1006 (void *)current
->mm
->start_data
,
1007 (void *)current
->mm
->end_data
,
1008 (void *)current
->mm
->end_data
,
1009 (void *)current
->mm
->brk
,
1010 (void *)current
->mm
->start_stack
);
1012 verbose_printk(KERN_NOTICE
"invalid mm\n");
1014 verbose_printk(KERN_NOTICE
1015 "No Valid process in current context\n");
1019 void dump_bfin_mem(struct pt_regs
*fp
)
1021 #ifdef CONFIG_DEBUG_VERBOSE
1022 unsigned short *addr
, *erraddr
, val
= 0, err
= 0;
1023 char sti
= 0, buf
[6];
1025 erraddr
= (void *)fp
->pc
;
1027 verbose_printk(KERN_NOTICE
"return address: [0x%p]; contents of:", erraddr
);
1029 for (addr
= (unsigned short *)((unsigned long)erraddr
& ~0xF) - 0x10;
1030 addr
< (unsigned short *)((unsigned long)erraddr
& ~0xF) + 0x10;
1032 if (!((unsigned long)addr
& 0xF))
1033 verbose_printk(KERN_NOTICE
"0x%p: ", addr
);
1035 if (!get_instruction(&val
, addr
)) {
1037 sprintf(buf
, "????");
1039 sprintf(buf
, "%04x", val
);
1041 if (addr
== erraddr
) {
1042 verbose_printk("[%s]", buf
);
1045 verbose_printk(" %s ", buf
);
1047 /* Do any previous instructions turn on interrupts? */
1048 if (addr
<= erraddr
&& /* in the past */
1049 ((val
>= 0x0040 && val
<= 0x0047) || /* STI instruction */
1050 val
== 0x017b)) /* [SP++] = RETI */
1054 verbose_printk("\n");
1056 /* Hardware error interrupts can be deferred */
1057 if (unlikely(sti
&& (fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
&&
1059 verbose_printk(KERN_NOTICE
"Looks like this was a deferred error - sorry\n");
1060 #ifndef CONFIG_DEBUG_HWERR
1061 verbose_printk(KERN_NOTICE
1062 "The remaining message may be meaningless\n"
1063 "You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
1065 /* If we are handling only one peripheral interrupt
1066 * and current mm and pid are valid, and the last error
1067 * was in that user space process's text area
1068 * print it out - because that is where the problem exists
1070 if ((!(((fp
)->ipend
& ~0x30) & (((fp
)->ipend
& ~0x30) - 1))) &&
1071 (current
->pid
&& current
->mm
)) {
1072 /* And the last RETI points to the current userspace context */
1073 if ((fp
+ 1)->pc
>= current
->mm
->start_code
&&
1074 (fp
+ 1)->pc
<= current
->mm
->end_code
) {
1075 verbose_printk(KERN_NOTICE
"It might be better to look around here : \n");
1076 verbose_printk(KERN_NOTICE
"-------------------------------------------\n");
1078 verbose_printk(KERN_NOTICE
"-------------------------------------------\n");
1086 void show_regs(struct pt_regs
*fp
)
1088 #ifdef CONFIG_DEBUG_VERBOSE
1090 struct irqaction
*action
;
1092 unsigned long flags
= 0;
1093 unsigned int cpu
= smp_processor_id();
1094 unsigned char in_atomic
= (bfin_read_IPEND() & 0x10) || in_atomic();
1096 verbose_printk(KERN_NOTICE
"\n");
1097 if (CPUID
!= bfin_cpuid())
1098 verbose_printk(KERN_NOTICE
"Compiled for cpu family 0x%04x (Rev %d), "
1099 "but running on:0x%04x (Rev %d)\n",
1100 CPUID
, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1102 verbose_printk(KERN_NOTICE
"ADSP-%s-0.%d",
1103 CPU
, bfin_compiled_revid());
1105 if (bfin_compiled_revid() != bfin_revid())
1106 verbose_printk("(Detected 0.%d)", bfin_revid());
1108 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1109 get_cclk()/1000000, get_sclk()/1000000,
1117 verbose_printk(KERN_NOTICE
"%s", linux_banner
);
1119 verbose_printk(KERN_NOTICE
"\nSEQUENCER STATUS:\t\t%s\n",
1121 verbose_printk(KERN_NOTICE
" SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1122 (long)fp
->seqstat
, fp
->ipend
, fp
->syscfg
);
1123 if ((fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
) {
1124 verbose_printk(KERN_NOTICE
" HWERRCAUSE: 0x%lx\n",
1125 (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) >> 14);
1127 /* If the error was from the EBIU, print it out */
1128 if (bfin_read_EBIU_ERRMST() & CORE_ERROR
) {
1129 verbose_printk(KERN_NOTICE
" EBIU Error Reason : 0x%04x\n",
1130 bfin_read_EBIU_ERRMST());
1131 verbose_printk(KERN_NOTICE
" EBIU Error Address : 0x%08x\n",
1132 bfin_read_EBIU_ERRADD());
1136 verbose_printk(KERN_NOTICE
" EXCAUSE : 0x%lx\n",
1137 fp
->seqstat
& SEQSTAT_EXCAUSE
);
1138 for (i
= 2; i
<= 15 ; i
++) {
1139 if (fp
->ipend
& (1 << i
)) {
1141 decode_address(buf
, bfin_read32(EVT0
+ 4*i
));
1142 verbose_printk(KERN_NOTICE
" physical IVG%i asserted : %s\n", i
, buf
);
1144 verbose_printk(KERN_NOTICE
" interrupts disabled\n");
1148 /* if no interrupts are going off, don't print this out */
1149 if (fp
->ipend
& ~0x3F) {
1150 for (i
= 0; i
< (NR_IRQS
- 1); i
++) {
1152 spin_lock_irqsave(&irq_desc
[i
].lock
, flags
);
1154 action
= irq_desc
[i
].action
;
1158 decode_address(buf
, (unsigned int)action
->handler
);
1159 verbose_printk(KERN_NOTICE
" logical irq %3d mapped : %s", i
, buf
);
1160 for (action
= action
->next
; action
; action
= action
->next
) {
1161 decode_address(buf
, (unsigned int)action
->handler
);
1162 verbose_printk(", %s", buf
);
1164 verbose_printk("\n");
1167 spin_unlock_irqrestore(&irq_desc
[i
].lock
, flags
);
1171 decode_address(buf
, fp
->rete
);
1172 verbose_printk(KERN_NOTICE
" RETE: %s\n", buf
);
1173 decode_address(buf
, fp
->retn
);
1174 verbose_printk(KERN_NOTICE
" RETN: %s\n", buf
);
1175 decode_address(buf
, fp
->retx
);
1176 verbose_printk(KERN_NOTICE
" RETX: %s\n", buf
);
1177 decode_address(buf
, fp
->rets
);
1178 verbose_printk(KERN_NOTICE
" RETS: %s\n", buf
);
1179 decode_address(buf
, fp
->pc
);
1180 verbose_printk(KERN_NOTICE
" PC : %s\n", buf
);
1182 if (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) &&
1183 (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) != VEC_HWERR
)) {
1184 decode_address(buf
, cpu_pda
[cpu
].dcplb_fault_addr
);
1185 verbose_printk(KERN_NOTICE
"DCPLB_FAULT_ADDR: %s\n", buf
);
1186 decode_address(buf
, cpu_pda
[cpu
].icplb_fault_addr
);
1187 verbose_printk(KERN_NOTICE
"ICPLB_FAULT_ADDR: %s\n", buf
);
1190 verbose_printk(KERN_NOTICE
"PROCESSOR STATE:\n");
1191 verbose_printk(KERN_NOTICE
" R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1192 fp
->r0
, fp
->r1
, fp
->r2
, fp
->r3
);
1193 verbose_printk(KERN_NOTICE
" R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1194 fp
->r4
, fp
->r5
, fp
->r6
, fp
->r7
);
1195 verbose_printk(KERN_NOTICE
" P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1196 fp
->p0
, fp
->p1
, fp
->p2
, fp
->p3
);
1197 verbose_printk(KERN_NOTICE
" P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1198 fp
->p4
, fp
->p5
, fp
->fp
, (long)fp
);
1199 verbose_printk(KERN_NOTICE
" LB0: %08lx LT0: %08lx LC0: %08lx\n",
1200 fp
->lb0
, fp
->lt0
, fp
->lc0
);
1201 verbose_printk(KERN_NOTICE
" LB1: %08lx LT1: %08lx LC1: %08lx\n",
1202 fp
->lb1
, fp
->lt1
, fp
->lc1
);
1203 verbose_printk(KERN_NOTICE
" B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1204 fp
->b0
, fp
->l0
, fp
->m0
, fp
->i0
);
1205 verbose_printk(KERN_NOTICE
" B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1206 fp
->b1
, fp
->l1
, fp
->m1
, fp
->i1
);
1207 verbose_printk(KERN_NOTICE
" B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1208 fp
->b2
, fp
->l2
, fp
->m2
, fp
->i2
);
1209 verbose_printk(KERN_NOTICE
" B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1210 fp
->b3
, fp
->l3
, fp
->m3
, fp
->i3
);
1211 verbose_printk(KERN_NOTICE
"A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1212 fp
->a0w
, fp
->a0x
, fp
->a1w
, fp
->a1x
);
1214 verbose_printk(KERN_NOTICE
"USP : %08lx ASTAT: %08lx\n",
1215 rdusp(), fp
->astat
);
1217 verbose_printk(KERN_NOTICE
"\n");
1221 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1222 asmlinkage
int sys_bfin_spinlock(int *spinlock
)__attribute__((l1_text
));
1225 static DEFINE_SPINLOCK(bfin_spinlock_lock
);
1227 asmlinkage
int sys_bfin_spinlock(int *p
)
1231 spin_lock(&bfin_spinlock_lock
); /* This would also hold kernel preemption. */
1232 ret
= get_user(tmp
, p
);
1233 if (likely(ret
== 0)) {
1239 spin_unlock(&bfin_spinlock_lock
);
1243 int bfin_request_exception(unsigned int exception
, void (*handler
)(void))
1245 void (*curr_handler
)(void);
1247 if (exception
> 0x3F)
1250 curr_handler
= ex_table
[exception
];
1252 if (curr_handler
!= ex_replaceable
)
1255 ex_table
[exception
] = handler
;
1259 EXPORT_SYMBOL(bfin_request_exception
);
1261 int bfin_free_exception(unsigned int exception
, void (*handler
)(void))
1263 void (*curr_handler
)(void);
1265 if (exception
> 0x3F)
1268 curr_handler
= ex_table
[exception
];
1270 if (curr_handler
!= handler
)
1273 ex_table
[exception
] = ex_replaceable
;
1277 EXPORT_SYMBOL(bfin_free_exception
);
1279 void panic_cplb_error(int cplb_panic
, struct pt_regs
*fp
)
1281 switch (cplb_panic
) {
1282 case CPLB_NO_UNLOCKED
:
1283 printk(KERN_EMERG
"All CPLBs are locked\n");
1285 case CPLB_PROT_VIOL
:
1287 case CPLB_NO_ADDR_MATCH
:
1289 case CPLB_UNKNOWN_ERR
:
1290 printk(KERN_EMERG
"Unknown CPLB Exception\n");
1294 oops_in_progress
= 1;
1296 dump_bfin_process(fp
);
1300 panic("Unrecoverable event");