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/uaccess.h>
31 #include <linux/interrupt.h>
32 #include <linux/module.h>
33 #include <linux/kallsyms.h>
35 #include <linux/rbtree.h>
36 #include <asm/traps.h>
37 #include <asm/cacheflush.h>
39 #include <asm/blackfin.h>
40 #include <asm/irq_handler.h>
41 #include <linux/irq.h>
42 #include <asm/trace.h>
43 #include <asm/fixed_code.h>
46 # include <linux/kgdb.h>
48 # define CHK_DEBUGGER_TRAP() \
50 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
52 # define CHK_DEBUGGER_TRAP_MAYBE() \
55 CHK_DEBUGGER_TRAP(); \
58 # define CHK_DEBUGGER_TRAP() do { } while (0)
59 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
63 #ifdef CONFIG_DEBUG_VERBOSE
64 #define verbose_printk(fmt, arg...) \
67 #define verbose_printk(fmt, arg...) \
68 ({ if (0) printk(fmt, ##arg); 0; })
71 /* Initiate the event table handler */
72 void __init
trap_init(void)
75 bfin_write_EVT3(trap
);
79 static void decode_address(char *buf
, unsigned long address
)
81 #ifdef CONFIG_DEBUG_VERBOSE
82 struct vm_list_struct
*vml
;
83 struct task_struct
*p
;
85 unsigned long flags
, offset
;
86 unsigned char in_atomic
= (bfin_read_IPEND() & 0x10) || in_atomic();
89 #ifdef CONFIG_KALLSYMS
90 unsigned long symsize
;
96 /* look up the address and see if we are in kernel space */
97 symname
= kallsyms_lookup(address
, &symsize
, &offset
, &modname
, namebuf
);
100 /* yeah! kernel space! */
102 modname
= delim
= "";
103 sprintf(buf
, "<0x%p> { %s%s%s%s + 0x%lx }",
104 (void *)address
, delim
, modname
, delim
, symname
,
105 (unsigned long)offset
);
111 /* Problem in fixed code section? */
112 if (address
>= FIXED_CODE_START
&& address
< FIXED_CODE_END
) {
113 sprintf(buf
, "<0x%p> /* Maybe fixed code section */", (void *)address
);
117 /* Problem somewhere before the kernel start address */
118 if (address
< CONFIG_BOOT_LOAD
) {
119 sprintf(buf
, "<0x%p> /* Maybe null pointer? */", (void *)address
);
123 /* looks like we're off in user-land, so let's walk all the
124 * mappings of all our processes and see if we can't be a whee
127 write_lock_irqsave(&tasklist_lock
, flags
);
128 for_each_process(p
) {
129 mm
= (in_atomic
? p
->mm
: get_task_mm(p
));
133 for (n
= rb_first(&mm
->mm_rb
); n
; n
= rb_next(n
)) {
134 struct vm_area_struct
*vma
;
136 vma
= rb_entry(n
, struct vm_area_struct
, vm_rb
);
138 if (address
>= vma
->vm_start
&& address
< vma
->vm_end
) {
140 char *name
= p
->comm
;
141 struct file
*file
= vma
->vm_file
;
144 char *d_name
= d_path(&file
->f_path
, _tmpbuf
,
150 /* FLAT does not have its text aligned to the start of
151 * the map while FDPIC ELF does ...
154 /* before we can check flat/fdpic, we need to
155 * make sure current is valid
157 if ((unsigned long)current
>= FIXED_CODE_START
&&
158 !((unsigned long)current
& 0x3)) {
160 (address
> current
->mm
->start_code
) &&
161 (address
< current
->mm
->end_code
))
162 offset
= address
- current
->mm
->start_code
;
164 offset
= (address
- vma
->vm_start
) +
165 (vma
->vm_pgoff
<< PAGE_SHIFT
);
167 sprintf(buf
, "<0x%p> [ %s + 0x%lx ]",
168 (void *)address
, name
, offset
);
170 sprintf(buf
, "<0x%p> [ %s vma:0x%lx-0x%lx]",
171 (void *)address
, name
,
172 vma
->vm_start
, vma
->vm_end
);
178 sprintf(buf
, "<0x%p> [ %s ] dynamic memory", (void *)address
, name
);
187 /* we were unable to find this address anywhere */
188 sprintf(buf
, "<0x%p> /* kernel dynamic memory */", (void *)address
);
191 write_unlock_irqrestore(&tasklist_lock
, flags
);
197 asmlinkage
void double_fault_c(struct pt_regs
*fp
)
200 oops_in_progress
= 1;
201 #ifdef CONFIG_DEBUG_VERBOSE
202 printk(KERN_EMERG
"\n" KERN_EMERG
"Double Fault\n");
203 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
204 if (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_UNCOV
) {
205 unsigned int cpu
= smp_processor_id();
207 decode_address(buf
, cpu_pda
[cpu
].retx
);
208 printk(KERN_EMERG
"While handling exception (EXCAUSE = 0x%x) at %s:\n",
209 (unsigned int)cpu_pda
[cpu
].seqstat
& SEQSTAT_EXCAUSE
, buf
);
210 decode_address(buf
, cpu_pda
[cpu
].dcplb_fault_addr
);
211 printk(KERN_NOTICE
" DCPLB_FAULT_ADDR: %s\n", buf
);
212 decode_address(buf
, cpu_pda
[cpu
].icplb_fault_addr
);
213 printk(KERN_NOTICE
" ICPLB_FAULT_ADDR: %s\n", buf
);
215 decode_address(buf
, fp
->retx
);
216 printk(KERN_NOTICE
"The instruction at %s caused a double exception\n", buf
);
220 dump_bfin_process(fp
);
225 panic("Double Fault - unrecoverable event\n");
229 asmlinkage
void trap_c(struct pt_regs
*fp
)
231 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
234 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
235 unsigned int cpu
= smp_processor_id();
239 unsigned long trapnr
= fp
->seqstat
& SEQSTAT_EXCAUSE
;
241 trace_buffer_save(j
);
243 /* Important - be very careful dereferncing pointers - will lead to
244 * double faults if the stack has become corrupt
247 /* If the fault was caused by a kernel thread, or interrupt handler
248 * we will kernel panic, so the system reboots.
249 * If KGDB is enabled, don't set this for kernel breakpoints
252 /* TODO: check to see if we are in some sort of deferred HWERR
253 * that we should be able to recover from, not kernel panic
255 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr
!= VEC_STEP
)
257 && (trapnr
!= VEC_EXCPT02
)
261 oops_in_progress
= 1;
262 } else if (current
) {
263 if (current
->mm
== NULL
) {
265 oops_in_progress
= 1;
269 /* trap_c() will be called for exceptions. During exceptions
270 * processing, the pc value should be set with retx value.
271 * With this change we can cleanup some code in signal.c- TODO
273 fp
->orig_pc
= fp
->retx
;
274 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
275 trapnr, fp->ipend, fp->pc, fp->retx); */
277 /* send the appropriate signal to the user program */
280 /* This table works in conjuction with the one in ./mach-common/entry.S
281 * Some exceptions are handled there (in assembly, in exception space)
282 * Some are handled here, (in C, in interrupt space)
283 * Some, like CPLB, are handled in both, where the normal path is
284 * handled in assembly/exception space, and the error path is handled
288 /* 0x00 - Linux Syscall, getting here is an error */
289 /* 0x01 - userspace gdb breakpoint, handled here */
291 info
.si_code
= TRAP_ILLTRAP
;
293 CHK_DEBUGGER_TRAP_MAYBE();
294 /* Check if this is a breakpoint in kernel space */
295 if (fp
->ipend
& 0xffc0)
299 /* 0x03 - User Defined, userspace stack overflow */
301 info
.si_code
= SEGV_STACKFLOW
;
303 verbose_printk(KERN_NOTICE
EXC_0x03(KERN_NOTICE
));
304 CHK_DEBUGGER_TRAP_MAYBE();
306 /* 0x02 - KGDB initial connection and break signal trap */
309 info
.si_code
= TRAP_ILLTRAP
;
314 /* 0x04 - User Defined */
315 /* 0x05 - User Defined */
316 /* 0x06 - User Defined */
317 /* 0x07 - User Defined */
318 /* 0x08 - User Defined */
319 /* 0x09 - User Defined */
320 /* 0x0A - User Defined */
321 /* 0x0B - User Defined */
322 /* 0x0C - User Defined */
323 /* 0x0D - User Defined */
324 /* 0x0E - User Defined */
325 /* 0x0F - User Defined */
326 /* If we got here, it is most likely that someone was trying to use a
327 * custom exception handler, and it is not actually installed properly
329 case VEC_EXCPT04
... VEC_EXCPT15
:
330 info
.si_code
= ILL_ILLPARAOP
;
332 verbose_printk(KERN_NOTICE
EXC_0x04(KERN_NOTICE
));
333 CHK_DEBUGGER_TRAP_MAYBE();
335 /* 0x10 HW Single step, handled here */
337 info
.si_code
= TRAP_STEP
;
339 CHK_DEBUGGER_TRAP_MAYBE();
340 /* Check if this is a single step in kernel space */
341 if (fp
->ipend
& 0xffc0)
345 /* 0x11 - Trace Buffer Full, handled here */
347 info
.si_code
= TRAP_TRACEFLOW
;
349 verbose_printk(KERN_NOTICE
EXC_0x11(KERN_NOTICE
));
350 CHK_DEBUGGER_TRAP_MAYBE();
352 /* 0x12 - Reserved, Caught by default */
353 /* 0x13 - Reserved, Caught by default */
354 /* 0x14 - Reserved, Caught by default */
355 /* 0x15 - Reserved, Caught by default */
356 /* 0x16 - Reserved, Caught by default */
357 /* 0x17 - Reserved, Caught by default */
358 /* 0x18 - Reserved, Caught by default */
359 /* 0x19 - Reserved, Caught by default */
360 /* 0x1A - Reserved, Caught by default */
361 /* 0x1B - Reserved, Caught by default */
362 /* 0x1C - Reserved, Caught by default */
363 /* 0x1D - Reserved, Caught by default */
364 /* 0x1E - Reserved, Caught by default */
365 /* 0x1F - Reserved, Caught by default */
366 /* 0x20 - Reserved, Caught by default */
367 /* 0x21 - Undefined Instruction, handled here */
369 info
.si_code
= ILL_ILLOPC
;
371 verbose_printk(KERN_NOTICE
EXC_0x21(KERN_NOTICE
));
372 CHK_DEBUGGER_TRAP_MAYBE();
374 /* 0x22 - Illegal Instruction Combination, handled here */
376 info
.si_code
= ILL_ILLPARAOP
;
378 verbose_printk(KERN_NOTICE
EXC_0x22(KERN_NOTICE
));
379 CHK_DEBUGGER_TRAP_MAYBE();
381 /* 0x23 - Data CPLB protection violation, handled here */
383 info
.si_code
= ILL_CPLB_VI
;
385 verbose_printk(KERN_NOTICE
EXC_0x23(KERN_NOTICE
));
386 CHK_DEBUGGER_TRAP_MAYBE();
388 /* 0x24 - Data access misaligned, handled here */
390 info
.si_code
= BUS_ADRALN
;
392 verbose_printk(KERN_NOTICE
EXC_0x24(KERN_NOTICE
));
393 CHK_DEBUGGER_TRAP_MAYBE();
395 /* 0x25 - Unrecoverable Event, handled here */
397 info
.si_code
= ILL_ILLEXCPT
;
399 verbose_printk(KERN_NOTICE
EXC_0x25(KERN_NOTICE
));
400 CHK_DEBUGGER_TRAP_MAYBE();
402 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
403 error case is handled here */
405 info
.si_code
= BUS_ADRALN
;
407 verbose_printk(KERN_NOTICE
EXC_0x26(KERN_NOTICE
));
409 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
411 info
.si_code
= ILL_CPLB_MULHIT
;
413 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
414 if (cpu_pda
[cpu
].dcplb_fault_addr
< FIXED_CODE_START
)
415 verbose_printk(KERN_NOTICE
"NULL pointer access\n");
418 verbose_printk(KERN_NOTICE
EXC_0x27(KERN_NOTICE
));
419 CHK_DEBUGGER_TRAP_MAYBE();
421 /* 0x28 - Emulation Watchpoint, handled here */
423 info
.si_code
= TRAP_WATCHPT
;
425 pr_debug(EXC_0x28(KERN_DEBUG
));
426 CHK_DEBUGGER_TRAP_MAYBE();
427 /* Check if this is a watchpoint in kernel space */
428 if (fp
->ipend
& 0xffc0)
433 /* 0x29 - Instruction fetch access error (535 only) */
434 case VEC_ISTRU_VL
: /* ADSP-BF535 only (MH) */
435 info
.si_code
= BUS_OPFETCH
;
437 verbose_printk(KERN_NOTICE
"BF535: VEC_ISTRU_VL\n");
438 CHK_DEBUGGER_TRAP_MAYBE();
441 /* 0x29 - Reserved, Caught by default */
443 /* 0x2A - Instruction fetch misaligned, handled here */
445 info
.si_code
= BUS_ADRALN
;
447 verbose_printk(KERN_NOTICE
EXC_0x2A(KERN_NOTICE
));
448 CHK_DEBUGGER_TRAP_MAYBE();
450 /* 0x2B - Instruction CPLB protection violation, handled here */
452 info
.si_code
= ILL_CPLB_VI
;
454 verbose_printk(KERN_NOTICE
EXC_0x2B(KERN_NOTICE
));
455 CHK_DEBUGGER_TRAP_MAYBE();
457 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
459 info
.si_code
= ILL_CPLB_MISS
;
461 verbose_printk(KERN_NOTICE
EXC_0x2C(KERN_NOTICE
));
463 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
464 case VEC_CPLB_I_MHIT
:
465 info
.si_code
= ILL_CPLB_MULHIT
;
467 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
468 if (cpu_pda
[cpu
].icplb_fault_addr
< FIXED_CODE_START
)
469 verbose_printk(KERN_NOTICE
"Jump to NULL address\n");
472 verbose_printk(KERN_NOTICE
EXC_0x2D(KERN_NOTICE
));
473 CHK_DEBUGGER_TRAP_MAYBE();
475 /* 0x2E - Illegal use of Supervisor Resource, handled here */
477 info
.si_code
= ILL_PRVOPC
;
479 verbose_printk(KERN_NOTICE
EXC_0x2E(KERN_NOTICE
));
480 CHK_DEBUGGER_TRAP_MAYBE();
482 /* 0x2F - Reserved, Caught by default */
483 /* 0x30 - Reserved, Caught by default */
484 /* 0x31 - Reserved, Caught by default */
485 /* 0x32 - Reserved, Caught by default */
486 /* 0x33 - Reserved, Caught by default */
487 /* 0x34 - Reserved, Caught by default */
488 /* 0x35 - Reserved, Caught by default */
489 /* 0x36 - Reserved, Caught by default */
490 /* 0x37 - Reserved, Caught by default */
491 /* 0x38 - Reserved, Caught by default */
492 /* 0x39 - Reserved, Caught by default */
493 /* 0x3A - Reserved, Caught by default */
494 /* 0x3B - Reserved, Caught by default */
495 /* 0x3C - Reserved, Caught by default */
496 /* 0x3D - Reserved, Caught by default */
497 /* 0x3E - Reserved, Caught by default */
498 /* 0x3F - Reserved, Caught by default */
500 info
.si_code
= BUS_ADRALN
;
502 switch (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) {
503 /* System MMR Error */
504 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR
):
505 info
.si_code
= BUS_ADRALN
;
507 verbose_printk(KERN_NOTICE
HWC_x2(KERN_NOTICE
));
509 /* External Memory Addressing Error */
510 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR
):
511 info
.si_code
= BUS_ADRERR
;
513 verbose_printk(KERN_NOTICE
HWC_x3(KERN_NOTICE
));
515 /* Performance Monitor Overflow */
516 case (SEQSTAT_HWERRCAUSE_PERF_FLOW
):
517 verbose_printk(KERN_NOTICE
HWC_x12(KERN_NOTICE
));
519 /* RAISE 5 instruction */
520 case (SEQSTAT_HWERRCAUSE_RAISE_5
):
521 printk(KERN_NOTICE
HWC_x18(KERN_NOTICE
));
523 default: /* Reserved */
524 printk(KERN_NOTICE
HWC_default(KERN_NOTICE
));
527 CHK_DEBUGGER_TRAP_MAYBE();
530 * We should be handling all known exception types above,
531 * if we get here we hit a reserved one, so panic
534 oops_in_progress
= 1;
535 info
.si_code
= ILL_ILLPARAOP
;
537 verbose_printk(KERN_EMERG
"Caught Unhandled Exception, code = %08lx\n",
538 (fp
->seqstat
& SEQSTAT_EXCAUSE
));
539 CHK_DEBUGGER_TRAP_MAYBE();
545 if (sig
!= SIGTRAP
) {
546 dump_bfin_process(fp
);
550 /* Print out the trace buffer if it makes sense */
551 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
552 if (trapnr
== VEC_CPLB_I_M
|| trapnr
== VEC_CPLB_M
)
553 verbose_printk(KERN_NOTICE
"No trace since you do not have "
554 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
558 dump_bfin_trace_buffer();
560 if (oops_in_progress
) {
561 /* Dump the current kernel stack */
562 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
"Kernel Stack\n");
563 show_stack(current
, NULL
);
565 #ifndef CONFIG_ACCESS_CHECK
566 verbose_printk(KERN_EMERG
"Please turn on "
567 "CONFIG_ACCESS_CHECK\n");
569 panic("Kernel exception");
571 #ifdef CONFIG_DEBUG_VERBOSE
572 unsigned long *stack
;
573 /* Dump the user space stack */
574 stack
= (unsigned long *)rdusp();
575 verbose_printk(KERN_NOTICE
"Userspace Stack\n");
576 show_stack(NULL
, stack
);
582 if (!ipipe_trap_notify(fp
->seqstat
& 0x3f, fp
))
587 info
.si_addr
= (void __user
*)fp
->pc
;
588 force_sig_info(sig
, &info
, current
);
591 trace_buffer_restore(j
);
595 /* Typical exception handling routines */
597 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
600 * Similar to get_user, do some address checking, then dereference
601 * Return true on sucess, false on bad address
603 static bool get_instruction(unsigned short *val
, unsigned short *address
)
608 addr
= (unsigned long)address
;
610 /* Check for odd addresses */
614 /* Check that things do not wrap around */
615 if (addr
> (addr
+ 2))
619 * Since we are in exception context, we need to do a little address checking
620 * We need to make sure we are only accessing valid memory, and
621 * we don't read something in the async space that can hang forever
623 if ((addr
>= FIXED_CODE_START
&& (addr
+ 2) <= physical_mem_end
) ||
625 (addr
>= L2_START
&& (addr
+ 2) <= (L2_START
+ L2_LENGTH
)) ||
627 (addr
>= BOOT_ROM_START
&& (addr
+ 2) <= (BOOT_ROM_START
+ BOOT_ROM_LENGTH
)) ||
628 #if L1_DATA_A_LENGTH != 0
629 (addr
>= L1_DATA_A_START
&& (addr
+ 2) <= (L1_DATA_A_START
+ L1_DATA_A_LENGTH
)) ||
631 #if L1_DATA_B_LENGTH != 0
632 (addr
>= L1_DATA_B_START
&& (addr
+ 2) <= (L1_DATA_B_START
+ L1_DATA_B_LENGTH
)) ||
634 (addr
>= L1_SCRATCH_START
&& (addr
+ 2) <= (L1_SCRATCH_START
+ L1_SCRATCH_LENGTH
)) ||
635 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN
) &&
636 addr
>= ASYNC_BANK0_BASE
&& (addr
+ 2) <= (ASYNC_BANK0_BASE
+ ASYNC_BANK0_SIZE
)) ||
637 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN
) &&
638 addr
>= ASYNC_BANK1_BASE
&& (addr
+ 2) <= (ASYNC_BANK1_BASE
+ ASYNC_BANK1_SIZE
)) ||
639 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN
) &&
640 addr
>= ASYNC_BANK2_BASE
&& (addr
+ 2) <= (ASYNC_BANK2_BASE
+ ASYNC_BANK1_SIZE
)) ||
641 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN
) &&
642 addr
>= ASYNC_BANK3_BASE
&& (addr
+ 2) <= (ASYNC_BANK3_BASE
+ ASYNC_BANK1_SIZE
))) {
647 #if L1_CODE_LENGTH != 0
648 if (addr
>= L1_CODE_START
&& (addr
+ 2) <= (L1_CODE_START
+ L1_CODE_LENGTH
)) {
649 isram_memcpy(val
, address
, 2);
659 * decode the instruction if we are printing out the trace, as it
660 * makes things easier to follow, without running it through objdump
661 * These are the normal instructions which cause change of flow, which
662 * would be at the source of the trace buffer
664 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
665 static void decode_instruction(unsigned short *address
)
667 unsigned short opcode
;
669 if (get_instruction(&opcode
, address
)) {
670 if (opcode
== 0x0010)
671 verbose_printk("RTS");
672 else if (opcode
== 0x0011)
673 verbose_printk("RTI");
674 else if (opcode
== 0x0012)
675 verbose_printk("RTX");
676 else if (opcode
== 0x0013)
677 verbose_printk("RTN");
678 else if (opcode
== 0x0014)
679 verbose_printk("RTE");
680 else if (opcode
== 0x0025)
681 verbose_printk("EMUEXCPT");
682 else if (opcode
== 0x0040 && opcode
<= 0x0047)
683 verbose_printk("STI R%i", opcode
& 7);
684 else if (opcode
>= 0x0050 && opcode
<= 0x0057)
685 verbose_printk("JUMP (P%i)", opcode
& 7);
686 else if (opcode
>= 0x0060 && opcode
<= 0x0067)
687 verbose_printk("CALL (P%i)", opcode
& 7);
688 else if (opcode
>= 0x0070 && opcode
<= 0x0077)
689 verbose_printk("CALL (PC+P%i)", opcode
& 7);
690 else if (opcode
>= 0x0080 && opcode
<= 0x0087)
691 verbose_printk("JUMP (PC+P%i)", opcode
& 7);
692 else if (opcode
>= 0x0090 && opcode
<= 0x009F)
693 verbose_printk("RAISE 0x%x", opcode
& 0xF);
694 else if (opcode
>= 0x00A0 && opcode
<= 0x00AF)
695 verbose_printk("EXCPT 0x%x", opcode
& 0xF);
696 else if ((opcode
>= 0x1000 && opcode
<= 0x13FF) || (opcode
>= 0x1800 && opcode
<= 0x1BFF))
697 verbose_printk("IF !CC JUMP");
698 else if ((opcode
>= 0x1400 && opcode
<= 0x17ff) || (opcode
>= 0x1c00 && opcode
<= 0x1fff))
699 verbose_printk("IF CC JUMP");
700 else if (opcode
>= 0x2000 && opcode
<= 0x2fff)
701 verbose_printk("JUMP.S");
702 else if (opcode
>= 0xe080 && opcode
<= 0xe0ff)
703 verbose_printk("LSETUP");
704 else if (opcode
>= 0xe200 && opcode
<= 0xe2ff)
705 verbose_printk("JUMP.L");
706 else if (opcode
>= 0xe300 && opcode
<= 0xe3ff)
707 verbose_printk("CALL pcrel");
709 verbose_printk("0x%04x", opcode
);
715 void dump_bfin_trace_buffer(void)
717 #ifdef CONFIG_DEBUG_VERBOSE
718 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
721 unsigned short *addr
;
722 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
726 trace_buffer_save(tflags
);
728 printk(KERN_NOTICE
"Hardware Trace:\n");
730 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
731 printk(KERN_NOTICE
"WARNING: Expanded trace turned on - can not trace exceptions\n");
734 if (likely(bfin_read_TBUFSTAT() & TBUFCNT
)) {
735 for (; bfin_read_TBUFSTAT() & TBUFCNT
; i
++) {
736 decode_address(buf
, (unsigned long)bfin_read_TBUF());
737 printk(KERN_NOTICE
"%4i Target : %s\n", i
, buf
);
738 addr
= (unsigned short *)bfin_read_TBUF();
739 decode_address(buf
, (unsigned long)addr
);
740 printk(KERN_NOTICE
" Source : %s ", buf
);
741 decode_instruction(addr
);
746 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
747 if (trace_buff_offset
)
748 index
= trace_buff_offset
/ 4;
752 j
= (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN
) * 128;
754 decode_address(buf
, software_trace_buff
[index
]);
755 printk(KERN_NOTICE
"%4i Target : %s\n", i
, buf
);
759 decode_address(buf
, software_trace_buff
[index
]);
760 printk(KERN_NOTICE
" Source : %s ", buf
);
761 decode_instruction((unsigned short *)software_trace_buff
[index
]);
771 trace_buffer_restore(tflags
);
775 EXPORT_SYMBOL(dump_bfin_trace_buffer
);
778 * Checks to see if the address pointed to is either a
779 * 16-bit CALL instruction, or a 32-bit CALL instruction
781 static bool is_bfin_call(unsigned short *addr
)
783 unsigned short opcode
= 0, *ins_addr
;
784 ins_addr
= (unsigned short *)addr
;
786 if (!get_instruction(&opcode
, ins_addr
))
789 if ((opcode
>= 0x0060 && opcode
<= 0x0067) ||
790 (opcode
>= 0x0070 && opcode
<= 0x0077))
794 if (!get_instruction(&opcode
, ins_addr
))
797 if (opcode
>= 0xE300 && opcode
<= 0xE3FF)
804 void show_stack(struct task_struct
*task
, unsigned long *stack
)
807 unsigned int *addr
, *endstack
, *fp
= 0, *frame
;
808 unsigned short *ins_addr
;
810 unsigned int i
, j
, ret_addr
, frame_no
= 0;
813 * If we have been passed a specific stack, use that one otherwise
814 * if we have been passed a task structure, use that, otherwise
815 * use the stack of where the variable "stack" exists
820 /* We know this is a kernel stack, so this is the start/end */
821 stack
= (unsigned long *)task
->thread
.ksp
;
822 endstack
= (unsigned int *)(((unsigned int)(stack
) & ~(THREAD_SIZE
- 1)) + THREAD_SIZE
);
824 /* print out the existing stack info */
825 stack
= (unsigned long *)&stack
;
826 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
829 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
831 printk(KERN_NOTICE
"Stack info:\n");
832 decode_address(buf
, (unsigned int)stack
);
833 printk(KERN_NOTICE
" SP: [0x%p] %s\n", stack
, buf
);
835 /* First thing is to look for a frame pointer */
836 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF); addr
< endstack
; addr
++) {
839 ins_addr
= (unsigned short *)*addr
;
841 if (is_bfin_call(ins_addr
))
845 /* Let's check to see if it is a frame pointer */
846 while (fp
>= (addr
- 1) && fp
< endstack
847 && fp
&& ((unsigned int) fp
& 0x3) == 0)
848 fp
= (unsigned int *)*fp
;
849 if (fp
== 0 || fp
== endstack
) {
858 printk(KERN_NOTICE
" FP: (0x%p)\n", fp
);
863 * Now that we think we know where things are, we
864 * walk the stack again, this time printing things out
865 * incase there is no frame pointer, we still look for
866 * valid return addresses
869 /* First time print out data, next time, print out symbols */
870 for (j
= 0; j
<= 1; j
++) {
872 printk(KERN_NOTICE
"Return addresses in stack:\n");
874 printk(KERN_NOTICE
" Memory from 0x%08lx to %p", ((long unsigned int)stack
& ~0xF), endstack
);
879 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF), i
= 0;
880 addr
<= endstack
; addr
++, i
++) {
883 if (!j
&& i
% 8 == 0)
884 printk("\n" KERN_NOTICE
"%p:",addr
);
886 /* if it is an odd address, or zero, just skip it */
887 if (*addr
& 0x1 || !*addr
)
890 ins_addr
= (unsigned short *)*addr
;
892 /* Go back one instruction, and see if it is a CALL */
894 ret_addr
= is_bfin_call(ins_addr
);
896 if (!j
&& stack
== (unsigned long *)addr
)
897 printk("[%08x]", *addr
);
900 decode_address(buf
, (unsigned int)*addr
);
902 printk(KERN_NOTICE
" frame %2i : %s\n", frame_no
, buf
);
905 printk(KERN_NOTICE
" address : %s\n", buf
);
907 printk("<%08x>", *addr
);
908 else if (fp
== addr
) {
912 printk("(%08x)", *addr
);
914 fp
= (unsigned int *)*addr
;
918 printk(" %08x ", *addr
);
926 void dump_stack(void)
929 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
932 trace_buffer_save(tflags
);
933 dump_bfin_trace_buffer();
934 show_stack(current
, &stack
);
935 trace_buffer_restore(tflags
);
937 EXPORT_SYMBOL(dump_stack
);
939 void dump_bfin_process(struct pt_regs
*fp
)
941 #ifdef CONFIG_DEBUG_VERBOSE
942 /* We should be able to look at fp->ipend, but we don't push it on the
943 * stack all the time, so do this until we fix that */
944 unsigned int context
= bfin_read_IPEND();
946 if (oops_in_progress
)
947 verbose_printk(KERN_EMERG
"Kernel OOPS in progress\n");
949 if (context
& 0x0020 && (fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
)
950 verbose_printk(KERN_NOTICE
"HW Error context\n");
951 else if (context
& 0x0020)
952 verbose_printk(KERN_NOTICE
"Deferred Exception context\n");
953 else if (context
& 0x3FC0)
954 verbose_printk(KERN_NOTICE
"Interrupt context\n");
955 else if (context
& 0x4000)
956 verbose_printk(KERN_NOTICE
"Deferred Interrupt context\n");
957 else if (context
& 0x8000)
958 verbose_printk(KERN_NOTICE
"Kernel process context\n");
960 /* Because we are crashing, and pointers could be bad, we check things
961 * pretty closely before we use them
963 if ((unsigned long)current
>= FIXED_CODE_START
&&
964 !((unsigned long)current
& 0x3) && current
->pid
) {
965 verbose_printk(KERN_NOTICE
"CURRENT PROCESS:\n");
966 if (current
->comm
>= (char *)FIXED_CODE_START
)
967 verbose_printk(KERN_NOTICE
"COMM=%s PID=%d\n",
968 current
->comm
, current
->pid
);
970 verbose_printk(KERN_NOTICE
"COMM= invalid\n");
972 printk(KERN_NOTICE
"CPU = %d\n", current_thread_info()->cpu
);
973 if (!((unsigned long)current
->mm
& 0x3) && (unsigned long)current
->mm
>= FIXED_CODE_START
)
974 verbose_printk(KERN_NOTICE
"TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
975 KERN_NOTICE
" BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
977 (void *)current
->mm
->start_code
,
978 (void *)current
->mm
->end_code
,
979 (void *)current
->mm
->start_data
,
980 (void *)current
->mm
->end_data
,
981 (void *)current
->mm
->end_data
,
982 (void *)current
->mm
->brk
,
983 (void *)current
->mm
->start_stack
);
985 verbose_printk(KERN_NOTICE
"invalid mm\n");
987 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
988 "No Valid process in current context\n");
992 void dump_bfin_mem(struct pt_regs
*fp
)
994 #ifdef CONFIG_DEBUG_VERBOSE
995 unsigned short *addr
, *erraddr
, val
= 0, err
= 0;
996 char sti
= 0, buf
[6];
998 erraddr
= (void *)fp
->pc
;
1000 verbose_printk(KERN_NOTICE
"return address: [0x%p]; contents of:", erraddr
);
1002 for (addr
= (unsigned short *)((unsigned long)erraddr
& ~0xF) - 0x10;
1003 addr
< (unsigned short *)((unsigned long)erraddr
& ~0xF) + 0x10;
1005 if (!((unsigned long)addr
& 0xF))
1006 verbose_printk("\n" KERN_NOTICE
"0x%p: ", addr
);
1008 if (!get_instruction(&val
, addr
)) {
1010 sprintf(buf
, "????");
1012 sprintf(buf
, "%04x", val
);
1014 if (addr
== erraddr
) {
1015 verbose_printk("[%s]", buf
);
1018 verbose_printk(" %s ", buf
);
1020 /* Do any previous instructions turn on interrupts? */
1021 if (addr
<= erraddr
&& /* in the past */
1022 ((val
>= 0x0040 && val
<= 0x0047) || /* STI instruction */
1023 val
== 0x017b)) /* [SP++] = RETI */
1027 verbose_printk("\n");
1029 /* Hardware error interrupts can be deferred */
1030 if (unlikely(sti
&& (fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
&&
1032 verbose_printk(KERN_NOTICE
"Looks like this was a deferred error - sorry\n");
1033 #ifndef CONFIG_DEBUG_HWERR
1034 verbose_printk(KERN_NOTICE
"The remaining message may be meaningless\n"
1035 KERN_NOTICE
"You should enable CONFIG_DEBUG_HWERR to get a"
1036 " better idea where it came from\n");
1038 /* If we are handling only one peripheral interrupt
1039 * and current mm and pid are valid, and the last error
1040 * was in that user space process's text area
1041 * print it out - because that is where the problem exists
1043 if ((!(((fp
)->ipend
& ~0x30) & (((fp
)->ipend
& ~0x30) - 1))) &&
1044 (current
->pid
&& current
->mm
)) {
1045 /* And the last RETI points to the current userspace context */
1046 if ((fp
+ 1)->pc
>= current
->mm
->start_code
&&
1047 (fp
+ 1)->pc
<= current
->mm
->end_code
) {
1048 verbose_printk(KERN_NOTICE
"It might be better to look around here : \n");
1049 verbose_printk(KERN_NOTICE
"-------------------------------------------\n");
1051 verbose_printk(KERN_NOTICE
"-------------------------------------------\n");
1059 void show_regs(struct pt_regs
*fp
)
1061 #ifdef CONFIG_DEBUG_VERBOSE
1063 struct irqaction
*action
;
1065 unsigned long flags
= 0;
1066 unsigned int cpu
= smp_processor_id();
1067 unsigned char in_atomic
= (bfin_read_IPEND() & 0x10) || in_atomic();
1069 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
"SEQUENCER STATUS:\t\t%s\n", print_tainted());
1070 verbose_printk(KERN_NOTICE
" SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1071 (long)fp
->seqstat
, fp
->ipend
, fp
->syscfg
);
1072 if ((fp
->seqstat
& SEQSTAT_EXCAUSE
) == VEC_HWERR
) {
1073 verbose_printk(KERN_NOTICE
" HWERRCAUSE: 0x%lx\n",
1074 (fp
->seqstat
& SEQSTAT_HWERRCAUSE
) >> 14);
1076 /* If the error was from the EBIU, print it out */
1077 if (bfin_read_EBIU_ERRMST() & CORE_ERROR
) {
1078 verbose_printk(KERN_NOTICE
" EBIU Error Reason : 0x%04x\n",
1079 bfin_read_EBIU_ERRMST());
1080 verbose_printk(KERN_NOTICE
" EBIU Error Address : 0x%08x\n",
1081 bfin_read_EBIU_ERRADD());
1085 verbose_printk(KERN_NOTICE
" EXCAUSE : 0x%lx\n",
1086 fp
->seqstat
& SEQSTAT_EXCAUSE
);
1087 for (i
= 2; i
<= 15 ; i
++) {
1088 if (fp
->ipend
& (1 << i
)) {
1090 decode_address(buf
, bfin_read32(EVT0
+ 4*i
));
1091 verbose_printk(KERN_NOTICE
" physical IVG%i asserted : %s\n", i
, buf
);
1093 verbose_printk(KERN_NOTICE
" interrupts disabled\n");
1097 /* if no interrupts are going off, don't print this out */
1098 if (fp
->ipend
& ~0x3F) {
1099 for (i
= 0; i
< (NR_IRQS
- 1); i
++) {
1101 spin_lock_irqsave(&irq_desc
[i
].lock
, flags
);
1103 action
= irq_desc
[i
].action
;
1107 decode_address(buf
, (unsigned int)action
->handler
);
1108 verbose_printk(KERN_NOTICE
" logical irq %3d mapped : %s", i
, buf
);
1109 for (action
= action
->next
; action
; action
= action
->next
) {
1110 decode_address(buf
, (unsigned int)action
->handler
);
1111 verbose_printk(", %s", buf
);
1113 verbose_printk("\n");
1116 spin_unlock_irqrestore(&irq_desc
[i
].lock
, flags
);
1120 decode_address(buf
, fp
->rete
);
1121 verbose_printk(KERN_NOTICE
" RETE: %s\n", buf
);
1122 decode_address(buf
, fp
->retn
);
1123 verbose_printk(KERN_NOTICE
" RETN: %s\n", buf
);
1124 decode_address(buf
, fp
->retx
);
1125 verbose_printk(KERN_NOTICE
" RETX: %s\n", buf
);
1126 decode_address(buf
, fp
->rets
);
1127 verbose_printk(KERN_NOTICE
" RETS: %s\n", buf
);
1128 decode_address(buf
, fp
->pc
);
1129 verbose_printk(KERN_NOTICE
" PC : %s\n", buf
);
1131 if (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) &&
1132 (((long)fp
->seqstat
& SEQSTAT_EXCAUSE
) != VEC_HWERR
)) {
1133 decode_address(buf
, cpu_pda
[cpu
].dcplb_fault_addr
);
1134 verbose_printk(KERN_NOTICE
"DCPLB_FAULT_ADDR: %s\n", buf
);
1135 decode_address(buf
, cpu_pda
[cpu
].icplb_fault_addr
);
1136 verbose_printk(KERN_NOTICE
"ICPLB_FAULT_ADDR: %s\n", buf
);
1139 verbose_printk(KERN_NOTICE
"\n" KERN_NOTICE
"PROCESSOR STATE:\n");
1140 verbose_printk(KERN_NOTICE
" R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1141 fp
->r0
, fp
->r1
, fp
->r2
, fp
->r3
);
1142 verbose_printk(KERN_NOTICE
" R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1143 fp
->r4
, fp
->r5
, fp
->r6
, fp
->r7
);
1144 verbose_printk(KERN_NOTICE
" P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1145 fp
->p0
, fp
->p1
, fp
->p2
, fp
->p3
);
1146 verbose_printk(KERN_NOTICE
" P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1147 fp
->p4
, fp
->p5
, fp
->fp
, (long)fp
);
1148 verbose_printk(KERN_NOTICE
" LB0: %08lx LT0: %08lx LC0: %08lx\n",
1149 fp
->lb0
, fp
->lt0
, fp
->lc0
);
1150 verbose_printk(KERN_NOTICE
" LB1: %08lx LT1: %08lx LC1: %08lx\n",
1151 fp
->lb1
, fp
->lt1
, fp
->lc1
);
1152 verbose_printk(KERN_NOTICE
" B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1153 fp
->b0
, fp
->l0
, fp
->m0
, fp
->i0
);
1154 verbose_printk(KERN_NOTICE
" B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1155 fp
->b1
, fp
->l1
, fp
->m1
, fp
->i1
);
1156 verbose_printk(KERN_NOTICE
" B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1157 fp
->b2
, fp
->l2
, fp
->m2
, fp
->i2
);
1158 verbose_printk(KERN_NOTICE
" B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1159 fp
->b3
, fp
->l3
, fp
->m3
, fp
->i3
);
1160 verbose_printk(KERN_NOTICE
"A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1161 fp
->a0w
, fp
->a0x
, fp
->a1w
, fp
->a1x
);
1163 verbose_printk(KERN_NOTICE
"USP : %08lx ASTAT: %08lx\n",
1164 rdusp(), fp
->astat
);
1166 verbose_printk(KERN_NOTICE
"\n");
1170 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1171 asmlinkage
int sys_bfin_spinlock(int *spinlock
)__attribute__((l1_text
));
1174 static DEFINE_SPINLOCK(bfin_spinlock_lock
);
1176 asmlinkage
int sys_bfin_spinlock(int *p
)
1180 spin_lock(&bfin_spinlock_lock
); /* This would also hold kernel preemption. */
1181 ret
= get_user(tmp
, p
);
1182 if (likely(ret
== 0)) {
1188 spin_unlock(&bfin_spinlock_lock
);
1192 int bfin_request_exception(unsigned int exception
, void (*handler
)(void))
1194 void (*curr_handler
)(void);
1196 if (exception
> 0x3F)
1199 curr_handler
= ex_table
[exception
];
1201 if (curr_handler
!= ex_replaceable
)
1204 ex_table
[exception
] = handler
;
1208 EXPORT_SYMBOL(bfin_request_exception
);
1210 int bfin_free_exception(unsigned int exception
, void (*handler
)(void))
1212 void (*curr_handler
)(void);
1214 if (exception
> 0x3F)
1217 curr_handler
= ex_table
[exception
];
1219 if (curr_handler
!= handler
)
1222 ex_table
[exception
] = ex_replaceable
;
1226 EXPORT_SYMBOL(bfin_free_exception
);
1228 void panic_cplb_error(int cplb_panic
, struct pt_regs
*fp
)
1230 switch (cplb_panic
) {
1231 case CPLB_NO_UNLOCKED
:
1232 printk(KERN_EMERG
"All CPLBs are locked\n");
1234 case CPLB_PROT_VIOL
:
1236 case CPLB_NO_ADDR_MATCH
:
1238 case CPLB_UNKNOWN_ERR
:
1239 printk(KERN_EMERG
"Unknown CPLB Exception\n");
1243 oops_in_progress
= 1;
1245 dump_bfin_process(fp
);
1249 panic("Unrecoverable event\n");