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>
40 #include <asm/blackfin.h>
41 #include <asm/irq_handler.h>
42 #include <linux/irq.h>
43 #include <asm/trace.h>
44 #include <asm/fixed_code.h>
47 # include <linux/kgdb.h>
49 # define CHK_DEBUGGER_TRAP() \
51 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
53 # define CHK_DEBUGGER_TRAP_MAYBE() \
56 CHK_DEBUGGER_TRAP(); \
59 # define CHK_DEBUGGER_TRAP() do { } while (0)
60 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
64 #ifdef CONFIG_DEBUG_VERBOSE
65 #define verbose_printk(fmt, arg...) \
68 #define verbose_printk(fmt, arg...) \
69 ({ if (0) printk(fmt, ##arg); 0; })
72 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
74 #ifdef CONFIG_DEBUG_MMRS_MODULE
75 EXPORT_SYMBOL(last_seqstat
);
79 /* Initiate the event table handler */
80 void __init
trap_init(void)
83 bfin_write_EVT3(trap
);
87 static void decode_address(char *buf
, unsigned long address
)
89 #ifdef CONFIG_DEBUG_VERBOSE
90 struct task_struct
*p
;
92 unsigned long flags
, offset
;
93 unsigned char in_atomic
= (bfin_read_IPEND() & 0x10) || in_atomic();
96 #ifdef CONFIG_KALLSYMS
97 unsigned long symsize
;
103 /* look up the address and see if we are in kernel space */
104 symname
= kallsyms_lookup(address
, &symsize
, &offset
, &modname
, namebuf
);
107 /* yeah! kernel space! */
109 modname
= delim
= "";
110 sprintf(buf
, "<0x%p> { %s%s%s%s + 0x%lx }",
111 (void *)address
, delim
, modname
, delim
, symname
,
112 (unsigned long)offset
);
118 /* Problem in fixed code section? */
119 if (address
>= FIXED_CODE_START
&& address
< FIXED_CODE_END
) {
120 sprintf(buf
, "<0x%p> /* Maybe fixed code section */", (void *)address
);
124 /* Problem somewhere before the kernel start address */
125 if (address
< CONFIG_BOOT_LOAD
) {
126 sprintf(buf
, "<0x%p> /* Maybe null pointer? */", (void *)address
);
130 /* looks like we're off in user-land, so let's walk all the
131 * mappings of all our processes and see if we can't be a whee
134 write_lock_irqsave(&tasklist_lock
, flags
);
135 for_each_process(p
) {
136 mm
= (in_atomic
? p
->mm
: get_task_mm(p
));
140 for (n
= rb_first(&mm
->mm_rb
); n
; n
= rb_next(n
)) {
141 struct vm_area_struct
*vma
;
143 vma
= rb_entry(n
, struct vm_area_struct
, vm_rb
);
145 if (address
>= vma
->vm_start
&& address
< vma
->vm_end
) {
147 char *name
= p
->comm
;
148 struct file
*file
= vma
->vm_file
;
151 char *d_name
= d_path(&file
->f_path
, _tmpbuf
,
157 /* FLAT does not have its text aligned to the start of
158 * the map while FDPIC ELF does ...
161 /* before we can check flat/fdpic, we need to
162 * make sure current is valid
164 if ((unsigned long)current
>= FIXED_CODE_START
&&
165 !((unsigned long)current
& 0x3)) {
167 (address
> current
->mm
->start_code
) &&
168 (address
< current
->mm
->end_code
))
169 offset
= address
- current
->mm
->start_code
;
171 offset
= (address
- vma
->vm_start
) +
172 (vma
->vm_pgoff
<< PAGE_SHIFT
);
174 sprintf(buf
, "<0x%p> [ %s + 0x%lx ]",
175 (void *)address
, name
, offset
);
177 sprintf(buf
, "<0x%p> [ %s vma:0x%lx-0x%lx]",
178 (void *)address
, name
,
179 vma
->vm_start
, vma
->vm_end
);
185 sprintf(buf
, "<0x%p> [ %s ] dynamic memory", (void *)address
, name
);
194 /* we were unable to find this address anywhere */
195 sprintf(buf
, "<0x%p> /* kernel dynamic memory */", (void *)address
);
198 write_unlock_irqrestore(&tasklist_lock
, flags
);
204 asmlinkage
void double_fault_c(struct pt_regs
*fp
)
206 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
208 trace_buffer_save(j
);
212 oops_in_progress
= 1;
213 #ifdef CONFIG_DEBUG_VERBOSE
214 printk(KERN_EMERG
"\n" KERN_EMERG
"Double Fault\n");
215 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
216 if (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_UNCOV
) {
217 unsigned int cpu
= smp_processor_id();
219 decode_address(buf
, cpu_pda
[cpu
].retx
);
220 printk(KERN_EMERG
"While handling exception (EXCAUSE = 0x%x) at %s:\n",
221 (unsigned int)cpu_pda
[cpu
].seqstat
& SEQSTAT_EXCAUSE
, buf
);
222 decode_address(buf
, cpu_pda
[cpu
].dcplb_fault_addr
);
223 printk(KERN_NOTICE
" DCPLB_FAULT_ADDR: %s\n", buf
);
224 decode_address(buf
, cpu_pda
[cpu
].icplb_fault_addr
);
225 printk(KERN_NOTICE
" ICPLB_FAULT_ADDR: %s\n", buf
);
227 decode_address(buf
, fp
->retx
);
228 printk(KERN_NOTICE
"The instruction at %s caused a double exception\n", buf
);
232 dump_bfin_process(fp
);
235 dump_bfin_trace_buffer();
238 panic("Double Fault - unrecoverable event");
242 static int kernel_mode_regs(struct pt_regs
*regs
)
244 return regs
->ipend
& 0xffc0;
247 asmlinkage
void trap_c(struct pt_regs
*fp
)
249 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
252 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
253 unsigned int cpu
= smp_processor_id();
255 const char *strerror
= NULL
;
258 unsigned long trapnr
= fp
->seqstat
& SEQSTAT_EXCAUSE
;
260 trace_buffer_save(j
);
261 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
262 last_seqstat
= (u32
)fp
->seqstat
;
265 /* Important - be very careful dereferncing pointers - will lead to
266 * double faults if the stack has become corrupt
270 /* IPEND is skipped if KGDB isn't enabled (see entry code) */
271 fp
->ipend
= bfin_read_IPEND();
274 /* trap_c() will be called for exceptions. During exceptions
275 * processing, the pc value should be set with retx value.
276 * With this change we can cleanup some code in signal.c- TODO
278 fp
->orig_pc
= fp
->retx
;
279 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
280 trapnr, fp->ipend, fp->pc, fp->retx); */
282 /* send the appropriate signal to the user program */
285 /* This table works in conjuction with the one in ./mach-common/entry.S
286 * Some exceptions are handled there (in assembly, in exception space)
287 * Some are handled here, (in C, in interrupt space)
288 * Some, like CPLB, are handled in both, where the normal path is
289 * handled in assembly/exception space, and the error path is handled
293 /* 0x00 - Linux Syscall, getting here is an error */
294 /* 0x01 - userspace gdb breakpoint, handled here */
296 info
.si_code
= TRAP_ILLTRAP
;
298 CHK_DEBUGGER_TRAP_MAYBE();
299 /* Check if this is a breakpoint in kernel space */
300 if (kernel_mode_regs(fp
))
304 /* 0x03 - User Defined, userspace stack overflow */
306 info
.si_code
= SEGV_STACKFLOW
;
308 strerror
= KERN_NOTICE
EXC_0x03(KERN_NOTICE
);
309 CHK_DEBUGGER_TRAP_MAYBE();
311 /* 0x02 - KGDB initial connection and break signal trap */
314 info
.si_code
= TRAP_ILLTRAP
;
319 /* 0x04 - User Defined */
320 /* 0x05 - User Defined */
321 /* 0x06 - User Defined */
322 /* 0x07 - User Defined */
323 /* 0x08 - User Defined */
324 /* 0x09 - User Defined */
325 /* 0x0A - User Defined */
326 /* 0x0B - User Defined */
327 /* 0x0C - User Defined */
328 /* 0x0D - User Defined */
329 /* 0x0E - User Defined */
330 /* 0x0F - User Defined */
331 /* If we got here, it is most likely that someone was trying to use a
332 * custom exception handler, and it is not actually installed properly
334 case VEC_EXCPT04
... VEC_EXCPT15
:
335 info
.si_code
= ILL_ILLPARAOP
;
337 strerror
= KERN_NOTICE
EXC_0x04(KERN_NOTICE
);
338 CHK_DEBUGGER_TRAP_MAYBE();
340 /* 0x10 HW Single step, handled here */
342 info
.si_code
= TRAP_STEP
;
344 CHK_DEBUGGER_TRAP_MAYBE();
345 /* Check if this is a single step in kernel space */
346 if (kernel_mode_regs(fp
))
350 /* 0x11 - Trace Buffer Full, handled here */
352 info
.si_code
= TRAP_TRACEFLOW
;
354 strerror
= KERN_NOTICE
EXC_0x11(KERN_NOTICE
);
355 CHK_DEBUGGER_TRAP_MAYBE();
357 /* 0x12 - Reserved, Caught by default */
358 /* 0x13 - Reserved, Caught by default */
359 /* 0x14 - Reserved, Caught by default */
360 /* 0x15 - Reserved, Caught by default */
361 /* 0x16 - Reserved, Caught by default */
362 /* 0x17 - Reserved, Caught by default */
363 /* 0x18 - Reserved, Caught by default */
364 /* 0x19 - Reserved, Caught by default */
365 /* 0x1A - Reserved, Caught by default */
366 /* 0x1B - Reserved, Caught by default */
367 /* 0x1C - Reserved, Caught by default */
368 /* 0x1D - Reserved, Caught by default */
369 /* 0x1E - Reserved, Caught by default */
370 /* 0x1F - Reserved, Caught by default */
371 /* 0x20 - Reserved, Caught by default */
372 /* 0x21 - Undefined Instruction, handled here */
375 if (kernel_mode_regs(fp
)) {
376 switch (report_bug(fp
->pc
, fp
)) {
377 case BUG_TRAP_TYPE_NONE
:
379 case BUG_TRAP_TYPE_WARN
:
380 dump_bfin_trace_buffer();
383 case BUG_TRAP_TYPE_BUG
:
384 /* call to panic() will dump trace, and it is
385 * off at this point, so it won't be clobbered
391 info
.si_code
= ILL_ILLOPC
;
393 strerror
= KERN_NOTICE
EXC_0x21(KERN_NOTICE
);
394 CHK_DEBUGGER_TRAP_MAYBE();
396 /* 0x22 - Illegal Instruction Combination, handled here */
398 info
.si_code
= ILL_ILLPARAOP
;
400 strerror
= KERN_NOTICE
EXC_0x22(KERN_NOTICE
);
401 CHK_DEBUGGER_TRAP_MAYBE();
403 /* 0x23 - Data CPLB protection violation, handled here */
405 info
.si_code
= ILL_CPLB_VI
;
407 strerror
= KERN_NOTICE
EXC_0x23(KERN_NOTICE
);
408 CHK_DEBUGGER_TRAP_MAYBE();
410 /* 0x24 - Data access misaligned, handled here */
412 info
.si_code
= BUS_ADRALN
;
414 strerror
= KERN_NOTICE
EXC_0x24(KERN_NOTICE
);
415 CHK_DEBUGGER_TRAP_MAYBE();
417 /* 0x25 - Unrecoverable Event, handled here */
419 info
.si_code
= ILL_ILLEXCPT
;
421 strerror
= KERN_NOTICE
EXC_0x25(KERN_NOTICE
);
422 CHK_DEBUGGER_TRAP_MAYBE();
424 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
425 error case is handled here */
427 info
.si_code
= BUS_ADRALN
;
429 strerror
= KERN_NOTICE
EXC_0x26(KERN_NOTICE
);
431 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
433 info
.si_code
= ILL_CPLB_MULHIT
;
435 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
436 if (cpu_pda
[cpu
].dcplb_fault_addr
< FIXED_CODE_START
)
437 strerror
= KERN_NOTICE
"NULL pointer access\n";
440 strerror
= KERN_NOTICE
EXC_0x27(KERN_NOTICE
);
441 CHK_DEBUGGER_TRAP_MAYBE();
443 /* 0x28 - Emulation Watchpoint, handled here */
445 info
.si_code
= TRAP_WATCHPT
;
447 pr_debug(EXC_0x28(KERN_DEBUG
));
448 CHK_DEBUGGER_TRAP_MAYBE();
449 /* Check if this is a watchpoint in kernel space */
450 if (kernel_mode_regs(fp
))
455 /* 0x29 - Instruction fetch access error (535 only) */
456 case VEC_ISTRU_VL
: /* ADSP-BF535 only (MH) */
457 info
.si_code
= BUS_OPFETCH
;
459 strerror
= KERN_NOTICE
"BF535: VEC_ISTRU_VL\n";
460 CHK_DEBUGGER_TRAP_MAYBE();
463 /* 0x29 - Reserved, Caught by default */
465 /* 0x2A - Instruction fetch misaligned, handled here */
467 info
.si_code
= BUS_ADRALN
;
469 strerror
= KERN_NOTICE
EXC_0x2A(KERN_NOTICE
);
470 CHK_DEBUGGER_TRAP_MAYBE();
472 /* 0x2B - Instruction CPLB protection violation, handled here */
474 info
.si_code
= ILL_CPLB_VI
;
476 strerror
= KERN_NOTICE
EXC_0x2B(KERN_NOTICE
);
477 CHK_DEBUGGER_TRAP_MAYBE();
479 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
481 info
.si_code
= ILL_CPLB_MISS
;
483 strerror
= KERN_NOTICE
EXC_0x2C(KERN_NOTICE
);
485 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
486 case VEC_CPLB_I_MHIT
:
487 info
.si_code
= ILL_CPLB_MULHIT
;
489 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
490 if (cpu_pda
[cpu
].icplb_fault_addr
< FIXED_CODE_START
)
491 strerror
= KERN_NOTICE
"Jump to NULL address\n";
494 strerror
= KERN_NOTICE
EXC_0x2D(KERN_NOTICE
);
495 CHK_DEBUGGER_TRAP_MAYBE();
497 /* 0x2E - Illegal use of Supervisor Resource, handled here */
499 info
.si_code
= ILL_PRVOPC
;
501 strerror
= KERN_NOTICE
EXC_0x2E(KERN_NOTICE
);
502 CHK_DEBUGGER_TRAP_MAYBE();
504 /* 0x2F - Reserved, Caught by default */
505 /* 0x30 - Reserved, Caught by default */
506 /* 0x31 - Reserved, Caught by default */
507 /* 0x32 - Reserved, Caught by default */
508 /* 0x33 - Reserved, Caught by default */
509 /* 0x34 - Reserved, Caught by default */
510 /* 0x35 - Reserved, Caught by default */
511 /* 0x36 - Reserved, Caught by default */
512 /* 0x37 - Reserved, Caught by default */
513 /* 0x38 - Reserved, Caught by default */
514 /* 0x39 - Reserved, Caught by default */
515 /* 0x3A - Reserved, Caught by default */
516 /* 0x3B - Reserved, Caught by default */
517 /* 0x3C - Reserved, Caught by default */
518 /* 0x3D - Reserved, Caught by default */
519 /* 0x3E - Reserved, Caught by default */
520 /* 0x3F - Reserved, Caught by default */
522 info
.si_code
= BUS_ADRALN
;
524 switch (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) {
525 /* System MMR Error */
526 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR
):
527 info
.si_code
= BUS_ADRALN
;
529 strerror
= KERN_NOTICE
HWC_x2(KERN_NOTICE
);
531 /* External Memory Addressing Error */
532 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR
):
533 info
.si_code
= BUS_ADRERR
;
535 strerror
= KERN_NOTICE
HWC_x3(KERN_NOTICE
);
537 /* Performance Monitor Overflow */
538 case (SEQSTAT_HWERRCAUSE_PERF_FLOW
):
539 strerror
= KERN_NOTICE
HWC_x12(KERN_NOTICE
);
541 /* RAISE 5 instruction */
542 case (SEQSTAT_HWERRCAUSE_RAISE_5
):
543 printk(KERN_NOTICE
HWC_x18(KERN_NOTICE
));
545 default: /* Reserved */
546 printk(KERN_NOTICE
HWC_default(KERN_NOTICE
));
549 CHK_DEBUGGER_TRAP_MAYBE();
552 * We should be handling all known exception types above,
553 * if we get here we hit a reserved one, so panic
556 info
.si_code
= ILL_ILLPARAOP
;
558 verbose_printk(KERN_EMERG
"Caught Unhandled Exception, code = %08lx\n",
559 (fp
->seqstat
& SEQSTAT_EXCAUSE
));
560 CHK_DEBUGGER_TRAP_MAYBE();
566 /* If the fault was caused by a kernel thread, or interrupt handler
567 * we will kernel panic, so the system reboots.
569 if (kernel_mode_regs(fp
) || (current
&& !current
->mm
)) {
571 oops_in_progress
= 1;
573 verbose_printk(strerror
);
576 if (sig
!= SIGTRAP
) {
577 dump_bfin_process(fp
);
581 /* Print out the trace buffer if it makes sense */
582 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
583 if (trapnr
== VEC_CPLB_I_M
|| trapnr
== VEC_CPLB_M
)
584 verbose_printk(KERN_NOTICE
"No trace since you do not have "
585 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
589 dump_bfin_trace_buffer();
591 if (oops_in_progress
) {
592 /* Dump the current kernel stack */
593 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
"Kernel Stack\n");
594 show_stack(current
, NULL
);
596 #ifndef CONFIG_ACCESS_CHECK
597 verbose_printk(KERN_EMERG
"Please turn on "
598 "CONFIG_ACCESS_CHECK\n");
600 panic("Kernel exception");
602 #ifdef CONFIG_DEBUG_VERBOSE
603 unsigned long *stack
;
604 /* Dump the user space stack */
605 stack
= (unsigned long *)rdusp();
606 verbose_printk(KERN_NOTICE
"Userspace Stack\n");
607 show_stack(NULL
, stack
);
613 if (!ipipe_trap_notify(fp
->seqstat
& 0x3f, fp
))
618 info
.si_addr
= (void __user
*)fp
->pc
;
619 force_sig_info(sig
, &info
, current
);
622 if (ANOMALY_05000461
&& trapnr
== VEC_HWERR
&& !access_ok(VERIFY_READ
, fp
->pc
, 8))
623 fp
->pc
= SAFE_USER_INSTRUCTION
;
626 trace_buffer_restore(j
);
629 /* Typical exception handling routines */
631 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
634 * Similar to get_user, do some address checking, then dereference
635 * Return true on sucess, false on bad address
637 static bool get_instruction(unsigned short *val
, unsigned short *address
)
642 addr
= (unsigned long)address
;
644 /* Check for odd addresses */
648 /* Check that things do not wrap around */
649 if (addr
> (addr
+ 2))
653 * Since we are in exception context, we need to do a little address checking
654 * We need to make sure we are only accessing valid memory, and
655 * we don't read something in the async space that can hang forever
657 if ((addr
>= FIXED_CODE_START
&& (addr
+ 2) <= physical_mem_end
) ||
659 (addr
>= L2_START
&& (addr
+ 2) <= (L2_START
+ L2_LENGTH
)) ||
661 (addr
>= BOOT_ROM_START
&& (addr
+ 2) <= (BOOT_ROM_START
+ BOOT_ROM_LENGTH
)) ||
662 #if L1_DATA_A_LENGTH != 0
663 (addr
>= L1_DATA_A_START
&& (addr
+ 2) <= (L1_DATA_A_START
+ L1_DATA_A_LENGTH
)) ||
665 #if L1_DATA_B_LENGTH != 0
666 (addr
>= L1_DATA_B_START
&& (addr
+ 2) <= (L1_DATA_B_START
+ L1_DATA_B_LENGTH
)) ||
668 (addr
>= L1_SCRATCH_START
&& (addr
+ 2) <= (L1_SCRATCH_START
+ L1_SCRATCH_LENGTH
)) ||
669 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN
) &&
670 addr
>= ASYNC_BANK0_BASE
&& (addr
+ 2) <= (ASYNC_BANK0_BASE
+ ASYNC_BANK0_SIZE
)) ||
671 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN
) &&
672 addr
>= ASYNC_BANK1_BASE
&& (addr
+ 2) <= (ASYNC_BANK1_BASE
+ ASYNC_BANK1_SIZE
)) ||
673 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN
) &&
674 addr
>= ASYNC_BANK2_BASE
&& (addr
+ 2) <= (ASYNC_BANK2_BASE
+ ASYNC_BANK1_SIZE
)) ||
675 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN
) &&
676 addr
>= ASYNC_BANK3_BASE
&& (addr
+ 2) <= (ASYNC_BANK3_BASE
+ ASYNC_BANK1_SIZE
))) {
681 #if L1_CODE_LENGTH != 0
682 if (addr
>= L1_CODE_START
&& (addr
+ 2) <= (L1_CODE_START
+ L1_CODE_LENGTH
)) {
683 isram_memcpy(val
, address
, 2);
693 * decode the instruction if we are printing out the trace, as it
694 * makes things easier to follow, without running it through objdump
695 * These are the normal instructions which cause change of flow, which
696 * would be at the source of the trace buffer
698 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
699 static void decode_instruction(unsigned short *address
)
701 unsigned short opcode
;
703 if (get_instruction(&opcode
, address
)) {
704 if (opcode
== 0x0010)
705 verbose_printk("RTS");
706 else if (opcode
== 0x0011)
707 verbose_printk("RTI");
708 else if (opcode
== 0x0012)
709 verbose_printk("RTX");
710 else if (opcode
== 0x0013)
711 verbose_printk("RTN");
712 else if (opcode
== 0x0014)
713 verbose_printk("RTE");
714 else if (opcode
== 0x0025)
715 verbose_printk("EMUEXCPT");
716 else if (opcode
== 0x0040 && opcode
<= 0x0047)
717 verbose_printk("STI R%i", opcode
& 7);
718 else if (opcode
>= 0x0050 && opcode
<= 0x0057)
719 verbose_printk("JUMP (P%i)", opcode
& 7);
720 else if (opcode
>= 0x0060 && opcode
<= 0x0067)
721 verbose_printk("CALL (P%i)", opcode
& 7);
722 else if (opcode
>= 0x0070 && opcode
<= 0x0077)
723 verbose_printk("CALL (PC+P%i)", opcode
& 7);
724 else if (opcode
>= 0x0080 && opcode
<= 0x0087)
725 verbose_printk("JUMP (PC+P%i)", opcode
& 7);
726 else if (opcode
>= 0x0090 && opcode
<= 0x009F)
727 verbose_printk("RAISE 0x%x", opcode
& 0xF);
728 else if (opcode
>= 0x00A0 && opcode
<= 0x00AF)
729 verbose_printk("EXCPT 0x%x", opcode
& 0xF);
730 else if ((opcode
>= 0x1000 && opcode
<= 0x13FF) || (opcode
>= 0x1800 && opcode
<= 0x1BFF))
731 verbose_printk("IF !CC JUMP");
732 else if ((opcode
>= 0x1400 && opcode
<= 0x17ff) || (opcode
>= 0x1c00 && opcode
<= 0x1fff))
733 verbose_printk("IF CC JUMP");
734 else if (opcode
>= 0x2000 && opcode
<= 0x2fff)
735 verbose_printk("JUMP.S");
736 else if (opcode
>= 0xe080 && opcode
<= 0xe0ff)
737 verbose_printk("LSETUP");
738 else if (opcode
>= 0xe200 && opcode
<= 0xe2ff)
739 verbose_printk("JUMP.L");
740 else if (opcode
>= 0xe300 && opcode
<= 0xe3ff)
741 verbose_printk("CALL pcrel");
743 verbose_printk("0x%04x", opcode
);
749 void dump_bfin_trace_buffer(void)
751 #ifdef CONFIG_DEBUG_VERBOSE
752 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
755 unsigned short *addr
;
756 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
760 trace_buffer_save(tflags
);
762 printk(KERN_NOTICE
"Hardware Trace:\n");
764 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
765 printk(KERN_NOTICE
"WARNING: Expanded trace turned on - can not trace exceptions\n");
768 if (likely(bfin_read_TBUFSTAT() & TBUFCNT
)) {
769 for (; bfin_read_TBUFSTAT() & TBUFCNT
; i
++) {
770 decode_address(buf
, (unsigned long)bfin_read_TBUF());
771 printk(KERN_NOTICE
"%4i Target : %s\n", i
, buf
);
772 addr
= (unsigned short *)bfin_read_TBUF();
773 decode_address(buf
, (unsigned long)addr
);
774 printk(KERN_NOTICE
" Source : %s ", buf
);
775 decode_instruction(addr
);
780 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
781 if (trace_buff_offset
)
782 index
= trace_buff_offset
/ 4;
786 j
= (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN
) * 128;
788 decode_address(buf
, software_trace_buff
[index
]);
789 printk(KERN_NOTICE
"%4i Target : %s\n", i
, buf
);
793 decode_address(buf
, software_trace_buff
[index
]);
794 printk(KERN_NOTICE
" Source : %s ", buf
);
795 decode_instruction((unsigned short *)software_trace_buff
[index
]);
805 trace_buffer_restore(tflags
);
809 EXPORT_SYMBOL(dump_bfin_trace_buffer
);
812 int is_valid_bugaddr(unsigned long addr
)
814 unsigned short opcode
;
816 if (!get_instruction(&opcode
, (unsigned short *)addr
))
819 return opcode
== BFIN_BUG_OPCODE
;
824 * Checks to see if the address pointed to is either a
825 * 16-bit CALL instruction, or a 32-bit CALL instruction
827 static bool is_bfin_call(unsigned short *addr
)
829 unsigned short opcode
= 0, *ins_addr
;
830 ins_addr
= (unsigned short *)addr
;
832 if (!get_instruction(&opcode
, ins_addr
))
835 if ((opcode
>= 0x0060 && opcode
<= 0x0067) ||
836 (opcode
>= 0x0070 && opcode
<= 0x0077))
840 if (!get_instruction(&opcode
, ins_addr
))
843 if (opcode
>= 0xE300 && opcode
<= 0xE3FF)
850 void show_stack(struct task_struct
*task
, unsigned long *stack
)
853 unsigned int *addr
, *endstack
, *fp
= 0, *frame
;
854 unsigned short *ins_addr
;
856 unsigned int i
, j
, ret_addr
, frame_no
= 0;
859 * If we have been passed a specific stack, use that one otherwise
860 * if we have been passed a task structure, use that, otherwise
861 * use the stack of where the variable "stack" exists
866 /* We know this is a kernel stack, so this is the start/end */
867 stack
= (unsigned long *)task
->thread
.ksp
;
868 endstack
= (unsigned int *)(((unsigned int)(stack
) & ~(THREAD_SIZE
- 1)) + THREAD_SIZE
);
870 /* print out the existing stack info */
871 stack
= (unsigned long *)&stack
;
872 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
875 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
877 printk(KERN_NOTICE
"Stack info:\n");
878 decode_address(buf
, (unsigned int)stack
);
879 printk(KERN_NOTICE
" SP: [0x%p] %s\n", stack
, buf
);
881 if (!access_ok(VERIFY_READ
, stack
, (unsigned int)endstack
- (unsigned int)stack
)) {
882 printk(KERN_NOTICE
"Invalid stack pointer\n");
886 /* First thing is to look for a frame pointer */
887 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF); addr
< endstack
; addr
++) {
890 ins_addr
= (unsigned short *)*addr
;
892 if (is_bfin_call(ins_addr
))
896 /* Let's check to see if it is a frame pointer */
897 while (fp
>= (addr
- 1) && fp
< endstack
898 && fp
&& ((unsigned int) fp
& 0x3) == 0)
899 fp
= (unsigned int *)*fp
;
900 if (fp
== 0 || fp
== endstack
) {
909 printk(KERN_NOTICE
" FP: (0x%p)\n", fp
);
914 * Now that we think we know where things are, we
915 * walk the stack again, this time printing things out
916 * incase there is no frame pointer, we still look for
917 * valid return addresses
920 /* First time print out data, next time, print out symbols */
921 for (j
= 0; j
<= 1; j
++) {
923 printk(KERN_NOTICE
"Return addresses in stack:\n");
925 printk(KERN_NOTICE
" Memory from 0x%08lx to %p", ((long unsigned int)stack
& ~0xF), endstack
);
930 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF), i
= 0;
931 addr
<= endstack
; addr
++, i
++) {
934 if (!j
&& i
% 8 == 0)
935 printk("\n" KERN_NOTICE
"%p:",addr
);
937 /* if it is an odd address, or zero, just skip it */
938 if (*addr
& 0x1 || !*addr
)
941 ins_addr
= (unsigned short *)*addr
;
943 /* Go back one instruction, and see if it is a CALL */
945 ret_addr
= is_bfin_call(ins_addr
);
947 if (!j
&& stack
== (unsigned long *)addr
)
948 printk("[%08x]", *addr
);
951 decode_address(buf
, (unsigned int)*addr
);
953 printk(KERN_NOTICE
" frame %2i : %s\n", frame_no
, buf
);
956 printk(KERN_NOTICE
" address : %s\n", buf
);
958 printk("<%08x>", *addr
);
959 else if (fp
== addr
) {
963 printk("(%08x)", *addr
);
965 fp
= (unsigned int *)*addr
;
969 printk(" %08x ", *addr
);
977 void dump_stack(void)
980 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
983 trace_buffer_save(tflags
);
984 dump_bfin_trace_buffer();
985 show_stack(current
, &stack
);
986 trace_buffer_restore(tflags
);
988 EXPORT_SYMBOL(dump_stack
);
990 void dump_bfin_process(struct pt_regs
*fp
)
992 #ifdef CONFIG_DEBUG_VERBOSE
993 /* We should be able to look at fp->ipend, but we don't push it on the
994 * stack all the time, so do this until we fix that */
995 unsigned int context
= bfin_read_IPEND();
997 if (oops_in_progress
)
998 verbose_printk(KERN_EMERG
"Kernel OOPS in progress\n");
1000 if (context
& 0x0020 && (fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
)
1001 verbose_printk(KERN_NOTICE
"HW Error context\n");
1002 else if (context
& 0x0020)
1003 verbose_printk(KERN_NOTICE
"Deferred Exception context\n");
1004 else if (context
& 0x3FC0)
1005 verbose_printk(KERN_NOTICE
"Interrupt context\n");
1006 else if (context
& 0x4000)
1007 verbose_printk(KERN_NOTICE
"Deferred Interrupt context\n");
1008 else if (context
& 0x8000)
1009 verbose_printk(KERN_NOTICE
"Kernel process context\n");
1011 /* Because we are crashing, and pointers could be bad, we check things
1012 * pretty closely before we use them
1014 if ((unsigned long)current
>= FIXED_CODE_START
&&
1015 !((unsigned long)current
& 0x3) && current
->pid
) {
1016 verbose_printk(KERN_NOTICE
"CURRENT PROCESS:\n");
1017 if (current
->comm
>= (char *)FIXED_CODE_START
)
1018 verbose_printk(KERN_NOTICE
"COMM=%s PID=%d\n",
1019 current
->comm
, current
->pid
);
1021 verbose_printk(KERN_NOTICE
"COMM= invalid\n");
1023 printk(KERN_NOTICE
"CPU = %d\n", current_thread_info()->cpu
);
1024 if (!((unsigned long)current
->mm
& 0x3) && (unsigned long)current
->mm
>= FIXED_CODE_START
)
1025 verbose_printk(KERN_NOTICE
"TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
1026 KERN_NOTICE
" BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
1028 (void *)current
->mm
->start_code
,
1029 (void *)current
->mm
->end_code
,
1030 (void *)current
->mm
->start_data
,
1031 (void *)current
->mm
->end_data
,
1032 (void *)current
->mm
->end_data
,
1033 (void *)current
->mm
->brk
,
1034 (void *)current
->mm
->start_stack
);
1036 verbose_printk(KERN_NOTICE
"invalid mm\n");
1038 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
1039 "No Valid process in current context\n");
1043 void dump_bfin_mem(struct pt_regs
*fp
)
1045 #ifdef CONFIG_DEBUG_VERBOSE
1046 unsigned short *addr
, *erraddr
, val
= 0, err
= 0;
1047 char sti
= 0, buf
[6];
1049 erraddr
= (void *)fp
->pc
;
1051 verbose_printk(KERN_NOTICE
"return address: [0x%p]; contents of:", erraddr
);
1053 for (addr
= (unsigned short *)((unsigned long)erraddr
& ~0xF) - 0x10;
1054 addr
< (unsigned short *)((unsigned long)erraddr
& ~0xF) + 0x10;
1056 if (!((unsigned long)addr
& 0xF))
1057 verbose_printk("\n" KERN_NOTICE
"0x%p: ", addr
);
1059 if (!get_instruction(&val
, addr
)) {
1061 sprintf(buf
, "????");
1063 sprintf(buf
, "%04x", val
);
1065 if (addr
== erraddr
) {
1066 verbose_printk("[%s]", buf
);
1069 verbose_printk(" %s ", buf
);
1071 /* Do any previous instructions turn on interrupts? */
1072 if (addr
<= erraddr
&& /* in the past */
1073 ((val
>= 0x0040 && val
<= 0x0047) || /* STI instruction */
1074 val
== 0x017b)) /* [SP++] = RETI */
1078 verbose_printk("\n");
1080 /* Hardware error interrupts can be deferred */
1081 if (unlikely(sti
&& (fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
&&
1083 verbose_printk(KERN_NOTICE
"Looks like this was a deferred error - sorry\n");
1084 #ifndef CONFIG_DEBUG_HWERR
1085 verbose_printk(KERN_NOTICE
"The remaining message may be meaningless\n"
1086 KERN_NOTICE
"You should enable CONFIG_DEBUG_HWERR to get a"
1087 " better idea where it came from\n");
1089 /* If we are handling only one peripheral interrupt
1090 * and current mm and pid are valid, and the last error
1091 * was in that user space process's text area
1092 * print it out - because that is where the problem exists
1094 if ((!(((fp
)->ipend
& ~0x30) & (((fp
)->ipend
& ~0x30) - 1))) &&
1095 (current
->pid
&& current
->mm
)) {
1096 /* And the last RETI points to the current userspace context */
1097 if ((fp
+ 1)->pc
>= current
->mm
->start_code
&&
1098 (fp
+ 1)->pc
<= current
->mm
->end_code
) {
1099 verbose_printk(KERN_NOTICE
"It might be better to look around here : \n");
1100 verbose_printk(KERN_NOTICE
"-------------------------------------------\n");
1102 verbose_printk(KERN_NOTICE
"-------------------------------------------\n");
1110 void show_regs(struct pt_regs
*fp
)
1112 #ifdef CONFIG_DEBUG_VERBOSE
1114 struct irqaction
*action
;
1116 unsigned long flags
= 0;
1117 unsigned int cpu
= smp_processor_id();
1118 unsigned char in_atomic
= (bfin_read_IPEND() & 0x10) || in_atomic();
1120 verbose_printk(KERN_NOTICE
"\n");
1121 if (CPUID
!= bfin_cpuid())
1122 verbose_printk(KERN_NOTICE
"Compiled for cpu family 0x%04x (Rev %d), "
1123 "but running on:0x%04x (Rev %d)\n",
1124 CPUID
, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1126 verbose_printk(KERN_NOTICE
"ADSP-%s-0.%d",
1127 CPU
, bfin_compiled_revid());
1129 if (bfin_compiled_revid() != bfin_revid())
1130 verbose_printk("(Detected 0.%d)", bfin_revid());
1132 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1133 get_cclk()/1000000, get_sclk()/1000000,
1141 verbose_printk(KERN_NOTICE
"%s", linux_banner
);
1143 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
"SEQUENCER STATUS:\t\t%s\n", print_tainted());
1144 verbose_printk(KERN_NOTICE
" SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1145 (long)fp
->seqstat
, fp
->ipend
, fp
->syscfg
);
1146 if ((fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
) {
1147 verbose_printk(KERN_NOTICE
" HWERRCAUSE: 0x%lx\n",
1148 (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) >> 14);
1150 /* If the error was from the EBIU, print it out */
1151 if (bfin_read_EBIU_ERRMST() & CORE_ERROR
) {
1152 verbose_printk(KERN_NOTICE
" EBIU Error Reason : 0x%04x\n",
1153 bfin_read_EBIU_ERRMST());
1154 verbose_printk(KERN_NOTICE
" EBIU Error Address : 0x%08x\n",
1155 bfin_read_EBIU_ERRADD());
1159 verbose_printk(KERN_NOTICE
" EXCAUSE : 0x%lx\n",
1160 fp
->seqstat
& SEQSTAT_EXCAUSE
);
1161 for (i
= 2; i
<= 15 ; i
++) {
1162 if (fp
->ipend
& (1 << i
)) {
1164 decode_address(buf
, bfin_read32(EVT0
+ 4*i
));
1165 verbose_printk(KERN_NOTICE
" physical IVG%i asserted : %s\n", i
, buf
);
1167 verbose_printk(KERN_NOTICE
" interrupts disabled\n");
1171 /* if no interrupts are going off, don't print this out */
1172 if (fp
->ipend
& ~0x3F) {
1173 for (i
= 0; i
< (NR_IRQS
- 1); i
++) {
1175 spin_lock_irqsave(&irq_desc
[i
].lock
, flags
);
1177 action
= irq_desc
[i
].action
;
1181 decode_address(buf
, (unsigned int)action
->handler
);
1182 verbose_printk(KERN_NOTICE
" logical irq %3d mapped : %s", i
, buf
);
1183 for (action
= action
->next
; action
; action
= action
->next
) {
1184 decode_address(buf
, (unsigned int)action
->handler
);
1185 verbose_printk(", %s", buf
);
1187 verbose_printk("\n");
1190 spin_unlock_irqrestore(&irq_desc
[i
].lock
, flags
);
1194 decode_address(buf
, fp
->rete
);
1195 verbose_printk(KERN_NOTICE
" RETE: %s\n", buf
);
1196 decode_address(buf
, fp
->retn
);
1197 verbose_printk(KERN_NOTICE
" RETN: %s\n", buf
);
1198 decode_address(buf
, fp
->retx
);
1199 verbose_printk(KERN_NOTICE
" RETX: %s\n", buf
);
1200 decode_address(buf
, fp
->rets
);
1201 verbose_printk(KERN_NOTICE
" RETS: %s\n", buf
);
1202 decode_address(buf
, fp
->pc
);
1203 verbose_printk(KERN_NOTICE
" PC : %s\n", buf
);
1205 if (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) &&
1206 (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) != VEC_HWERR
)) {
1207 decode_address(buf
, cpu_pda
[cpu
].dcplb_fault_addr
);
1208 verbose_printk(KERN_NOTICE
"DCPLB_FAULT_ADDR: %s\n", buf
);
1209 decode_address(buf
, cpu_pda
[cpu
].icplb_fault_addr
);
1210 verbose_printk(KERN_NOTICE
"ICPLB_FAULT_ADDR: %s\n", buf
);
1213 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
"PROCESSOR STATE:\n");
1214 verbose_printk(KERN_NOTICE
" R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1215 fp
->r0
, fp
->r1
, fp
->r2
, fp
->r3
);
1216 verbose_printk(KERN_NOTICE
" R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1217 fp
->r4
, fp
->r5
, fp
->r6
, fp
->r7
);
1218 verbose_printk(KERN_NOTICE
" P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1219 fp
->p0
, fp
->p1
, fp
->p2
, fp
->p3
);
1220 verbose_printk(KERN_NOTICE
" P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1221 fp
->p4
, fp
->p5
, fp
->fp
, (long)fp
);
1222 verbose_printk(KERN_NOTICE
" LB0: %08lx LT0: %08lx LC0: %08lx\n",
1223 fp
->lb0
, fp
->lt0
, fp
->lc0
);
1224 verbose_printk(KERN_NOTICE
" LB1: %08lx LT1: %08lx LC1: %08lx\n",
1225 fp
->lb1
, fp
->lt1
, fp
->lc1
);
1226 verbose_printk(KERN_NOTICE
" B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1227 fp
->b0
, fp
->l0
, fp
->m0
, fp
->i0
);
1228 verbose_printk(KERN_NOTICE
" B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1229 fp
->b1
, fp
->l1
, fp
->m1
, fp
->i1
);
1230 verbose_printk(KERN_NOTICE
" B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1231 fp
->b2
, fp
->l2
, fp
->m2
, fp
->i2
);
1232 verbose_printk(KERN_NOTICE
" B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1233 fp
->b3
, fp
->l3
, fp
->m3
, fp
->i3
);
1234 verbose_printk(KERN_NOTICE
"A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1235 fp
->a0w
, fp
->a0x
, fp
->a1w
, fp
->a1x
);
1237 verbose_printk(KERN_NOTICE
"USP : %08lx ASTAT: %08lx\n",
1238 rdusp(), fp
->astat
);
1240 verbose_printk(KERN_NOTICE
"\n");
1244 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1245 asmlinkage
int sys_bfin_spinlock(int *spinlock
)__attribute__((l1_text
));
1248 static DEFINE_SPINLOCK(bfin_spinlock_lock
);
1250 asmlinkage
int sys_bfin_spinlock(int *p
)
1254 spin_lock(&bfin_spinlock_lock
); /* This would also hold kernel preemption. */
1255 ret
= get_user(tmp
, p
);
1256 if (likely(ret
== 0)) {
1262 spin_unlock(&bfin_spinlock_lock
);
1266 int bfin_request_exception(unsigned int exception
, void (*handler
)(void))
1268 void (*curr_handler
)(void);
1270 if (exception
> 0x3F)
1273 curr_handler
= ex_table
[exception
];
1275 if (curr_handler
!= ex_replaceable
)
1278 ex_table
[exception
] = handler
;
1282 EXPORT_SYMBOL(bfin_request_exception
);
1284 int bfin_free_exception(unsigned int exception
, void (*handler
)(void))
1286 void (*curr_handler
)(void);
1288 if (exception
> 0x3F)
1291 curr_handler
= ex_table
[exception
];
1293 if (curr_handler
!= handler
)
1296 ex_table
[exception
] = ex_replaceable
;
1300 EXPORT_SYMBOL(bfin_free_exception
);
1302 void panic_cplb_error(int cplb_panic
, struct pt_regs
*fp
)
1304 switch (cplb_panic
) {
1305 case CPLB_NO_UNLOCKED
:
1306 printk(KERN_EMERG
"All CPLBs are locked\n");
1308 case CPLB_PROT_VIOL
:
1310 case CPLB_NO_ADDR_MATCH
:
1312 case CPLB_UNKNOWN_ERR
:
1313 printk(KERN_EMERG
"Unknown CPLB Exception\n");
1317 oops_in_progress
= 1;
1319 dump_bfin_process(fp
);
1323 panic("Unrecoverable event");