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 <asm/traps.h>
36 #include <asm/cacheflush.h>
37 #include <asm/blackfin.h>
38 #include <asm/irq_handler.h>
39 #include <linux/irq.h>
40 #include <asm/trace.h>
41 #include <asm/fixed_code.h>
45 # include <linux/debugger.h>
46 # include <linux/kgdb.h>
48 # define CHK_DEBUGGER_TRAP() \
50 CHK_DEBUGGER(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)
62 /* Initiate the event table handler */
63 void __init trap_init(void)
66 bfin_write_EVT3(trap);
70 unsigned long saved_icplb_fault_addr, saved_dcplb_fault_addr;
72 static void decode_address(char *buf, unsigned long address)
74 struct vm_list_struct *vml;
75 struct task_struct *p;
77 unsigned long flags, offset;
78 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
80 #ifdef CONFIG_KALLSYMS
81 unsigned long symsize;
87 /* look up the address and see if we are in kernel space */
88 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
91 /* yeah! kernel space! */
94 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
95 (void *)address, delim, modname, delim, symname,
96 (unsigned long)offset);
102 /* Problem in fixed code section? */
103 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
104 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
108 /* Problem somewhere before the kernel start address */
109 if (address < CONFIG_BOOT_LOAD) {
110 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
114 /* looks like we're off in user-land, so let's walk all the
115 * mappings of all our processes and see if we can't be a whee
118 write_lock_irqsave(&tasklist_lock, flags);
119 for_each_process(p) {
120 mm = (in_atomic ? p->mm : get_task_mm(p));
124 vml = mm->context.vmlist;
126 struct vm_area_struct *vma = vml->vma;
128 if (address >= vma->vm_start && address < vma->vm_end) {
130 char *name = p->comm;
131 struct file *file = vma->vm_file;
134 name = d_path(&file->f_path, _tmpbuf,
137 /* FLAT does not have its text aligned to the start of
138 * the map while FDPIC ELF does ...
141 /* before we can check flat/fdpic, we need to
142 * make sure current is valid
144 if ((unsigned long)current >= FIXED_CODE_START &&
145 !((unsigned long)current & 0x3)) {
147 (address > current->mm->start_code) &&
148 (address < current->mm->end_code))
149 offset = address - current->mm->start_code;
151 offset = (address - vma->vm_start) +
152 (vma->vm_pgoff << PAGE_SHIFT);
154 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
155 (void *)address, name, offset);
157 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
158 (void *)address, name,
159 vma->vm_start, vma->vm_end);
165 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
176 /* we were unable to find this address anywhere */
177 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
180 write_unlock_irqrestore(&tasklist_lock, flags);
183 asmlinkage void double_fault_c(struct pt_regs *fp)
186 oops_in_progress = 1;
187 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
188 dump_bfin_process(fp);
191 panic("Double Fault - unrecoverable event\n");
195 asmlinkage void trap_c(struct pt_regs *fp)
197 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
202 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
204 trace_buffer_save(j);
206 /* Important - be very careful dereferncing pointers - will lead to
207 * double faults if the stack has become corrupt
210 /* If the fault was caused by a kernel thread, or interrupt handler
211 * we will kernel panic, so the system reboots.
212 * If KGDB is enabled, don't set this for kernel breakpoints
215 /* TODO: check to see if we are in some sort of deferred HWERR
216 * that we should be able to recover from, not kernel panic
218 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
220 && (trapnr != VEC_EXCPT02)
224 oops_in_progress = 1;
225 } else if (current) {
226 if (current->mm == NULL) {
228 oops_in_progress = 1;
232 /* trap_c() will be called for exceptions. During exceptions
233 * processing, the pc value should be set with retx value.
234 * With this change we can cleanup some code in signal.c- TODO
236 fp->orig_pc = fp->retx;
237 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
238 trapnr, fp->ipend, fp->pc, fp->retx); */
240 /* send the appropriate signal to the user program */
243 /* This table works in conjuction with the one in ./mach-common/entry.S
244 * Some exceptions are handled there (in assembly, in exception space)
245 * Some are handled here, (in C, in interrupt space)
246 * Some, like CPLB, are handled in both, where the normal path is
247 * handled in assembly/exception space, and the error path is handled
251 /* 0x00 - Linux Syscall, getting here is an error */
252 /* 0x01 - userspace gdb breakpoint, handled here */
254 info.si_code = TRAP_ILLTRAP;
256 CHK_DEBUGGER_TRAP_MAYBE();
257 /* Check if this is a breakpoint in kernel space */
258 if (fp->ipend & 0xffc0)
263 case VEC_EXCPT02 : /* gdb connection */
264 info.si_code = TRAP_ILLTRAP;
269 /* 0x02 - User Defined, Caught by default */
271 /* 0x03 - User Defined, userspace stack overflow */
273 info.si_code = SEGV_STACKFLOW;
275 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
278 /* 0x04 - User Defined, Caught by default */
279 /* 0x05 - User Defined, Caught by default */
280 /* 0x06 - User Defined, Caught by default */
281 /* 0x07 - User Defined, Caught by default */
282 /* 0x08 - User Defined, Caught by default */
283 /* 0x09 - User Defined, Caught by default */
284 /* 0x0A - User Defined, Caught by default */
285 /* 0x0B - User Defined, Caught by default */
286 /* 0x0C - User Defined, Caught by default */
287 /* 0x0D - User Defined, Caught by default */
288 /* 0x0E - User Defined, Caught by default */
289 /* 0x0F - User Defined, Caught by default */
290 /* 0x10 HW Single step, handled here */
292 info.si_code = TRAP_STEP;
294 CHK_DEBUGGER_TRAP_MAYBE();
295 /* Check if this is a single step in kernel space */
296 if (fp->ipend & 0xffc0)
300 /* 0x11 - Trace Buffer Full, handled here */
302 info.si_code = TRAP_TRACEFLOW;
304 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
307 /* 0x12 - Reserved, Caught by default */
308 /* 0x13 - Reserved, Caught by default */
309 /* 0x14 - Reserved, Caught by default */
310 /* 0x15 - Reserved, Caught by default */
311 /* 0x16 - Reserved, Caught by default */
312 /* 0x17 - Reserved, Caught by default */
313 /* 0x18 - Reserved, Caught by default */
314 /* 0x19 - Reserved, Caught by default */
315 /* 0x1A - Reserved, Caught by default */
316 /* 0x1B - Reserved, Caught by default */
317 /* 0x1C - Reserved, Caught by default */
318 /* 0x1D - Reserved, Caught by default */
319 /* 0x1E - Reserved, Caught by default */
320 /* 0x1F - Reserved, Caught by default */
321 /* 0x20 - Reserved, Caught by default */
322 /* 0x21 - Undefined Instruction, handled here */
324 info.si_code = ILL_ILLOPC;
326 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
329 /* 0x22 - Illegal Instruction Combination, handled here */
331 info.si_code = ILL_ILLPARAOP;
333 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
336 /* 0x23 - Data CPLB protection violation, handled here */
338 info.si_code = ILL_CPLB_VI;
340 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
343 /* 0x24 - Data access misaligned, handled here */
345 info.si_code = BUS_ADRALN;
347 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
350 /* 0x25 - Unrecoverable Event, handled here */
352 info.si_code = ILL_ILLEXCPT;
354 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
357 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
358 error case is handled here */
360 info.si_code = BUS_ADRALN;
362 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
365 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
367 info.si_code = ILL_CPLB_MULHIT;
369 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
370 if (saved_dcplb_fault_addr < FIXED_CODE_START)
371 printk(KERN_NOTICE "NULL pointer access\n");
374 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
377 /* 0x28 - Emulation Watchpoint, handled here */
379 info.si_code = TRAP_WATCHPT;
381 pr_debug(EXC_0x28(KERN_DEBUG));
382 CHK_DEBUGGER_TRAP_MAYBE();
383 /* Check if this is a watchpoint in kernel space */
384 if (fp->ipend & 0xffc0)
389 /* 0x29 - Instruction fetch access error (535 only) */
390 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
391 info.si_code = BUS_OPFETCH;
393 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
397 /* 0x29 - Reserved, Caught by default */
399 /* 0x2A - Instruction fetch misaligned, handled here */
401 info.si_code = BUS_ADRALN;
403 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
406 /* 0x2B - Instruction CPLB protection violation, handled here */
408 info.si_code = ILL_CPLB_VI;
410 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
413 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
415 info.si_code = ILL_CPLB_MISS;
417 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
420 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
421 case VEC_CPLB_I_MHIT:
422 info.si_code = ILL_CPLB_MULHIT;
424 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
425 if (saved_icplb_fault_addr < FIXED_CODE_START)
426 printk(KERN_NOTICE "Jump to NULL address\n");
429 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
432 /* 0x2E - Illegal use of Supervisor Resource, handled here */
434 info.si_code = ILL_PRVOPC;
436 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
439 /* 0x2F - Reserved, Caught by default */
440 /* 0x30 - Reserved, Caught by default */
441 /* 0x31 - Reserved, Caught by default */
442 /* 0x32 - Reserved, Caught by default */
443 /* 0x33 - Reserved, Caught by default */
444 /* 0x34 - Reserved, Caught by default */
445 /* 0x35 - Reserved, Caught by default */
446 /* 0x36 - Reserved, Caught by default */
447 /* 0x37 - Reserved, Caught by default */
448 /* 0x38 - Reserved, Caught by default */
449 /* 0x39 - Reserved, Caught by default */
450 /* 0x3A - Reserved, Caught by default */
451 /* 0x3B - Reserved, Caught by default */
452 /* 0x3C - Reserved, Caught by default */
453 /* 0x3D - Reserved, Caught by default */
454 /* 0x3E - Reserved, Caught by default */
455 /* 0x3F - Reserved, Caught by default */
457 info.si_code = BUS_ADRALN;
459 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
460 /* System MMR Error */
461 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
462 info.si_code = BUS_ADRALN;
464 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
466 /* External Memory Addressing Error */
467 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
468 info.si_code = BUS_ADRERR;
470 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
472 /* Performance Monitor Overflow */
473 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
474 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
476 /* RAISE 5 instruction */
477 case (SEQSTAT_HWERRCAUSE_RAISE_5):
478 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
480 default: /* Reserved */
481 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
487 info.si_code = TRAP_ILLTRAP;
489 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
490 (fp->seqstat & SEQSTAT_EXCAUSE));
497 if (sig != SIGTRAP) {
498 unsigned long *stack;
499 dump_bfin_process(fp);
503 /* Print out the trace buffer if it makes sense */
504 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
505 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
506 printk(KERN_NOTICE "No trace since you do not have "
507 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
511 dump_bfin_trace_buffer();
513 if (oops_in_progress) {
514 /* Dump the current kernel stack */
515 printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
516 show_stack(current, NULL);
519 #ifndef CONFIG_ACCESS_CHECK
520 printk(KERN_EMERG "Please turn on "
521 "CONFIG_ACCESS_CHECK\n");
523 panic("Kernel exception");
525 /* Dump the user space stack */
526 stack = (unsigned long *)rdusp();
527 printk(KERN_NOTICE "Userspace Stack\n");
528 show_stack(NULL, stack);
534 info.si_addr = (void __user *)fp->pc;
535 force_sig_info(sig, &info, current);
537 trace_buffer_restore(j);
541 /* Typical exception handling routines */
543 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
546 * Similar to get_user, do some address checking, then dereference
547 * Return true on sucess, false on bad address
549 bool get_instruction(unsigned short *val, unsigned short *address)
554 addr = (unsigned long)address;
556 /* Check for odd addresses */
560 /* Check that things do not wrap around */
561 if (addr > (addr + 2))
565 * Since we are in exception context, we need to do a little address checking
566 * We need to make sure we are only accessing valid memory, and
567 * we don't read something in the async space that can hang forever
569 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
571 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
573 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
574 #if L1_DATA_A_LENGTH != 0
575 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
577 #if L1_DATA_B_LENGTH != 0
578 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
580 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
581 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
582 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
583 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
584 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
585 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
586 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
587 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
588 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
593 #if L1_CODE_LENGTH != 0
594 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
595 dma_memcpy(val, address, 2);
604 void dump_bfin_trace_buffer(void)
606 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
609 unsigned short val = 0, *addr;
610 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
614 trace_buffer_save(tflags);
616 printk(KERN_NOTICE "Hardware Trace:\n");
618 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
619 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
620 decode_address(buf, (unsigned long)bfin_read_TBUF());
621 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
622 addr = (unsigned short *)bfin_read_TBUF();
623 decode_address(buf, (unsigned long)addr);
624 printk(KERN_NOTICE " Source : %s ", buf);
625 if (get_instruction(&val, addr)) {
628 else if (val == 0x0011)
630 else if (val == 0x0012)
632 else if (val >= 0x0050 && val <= 0x0057)
633 printk("JUMP (P%i)", val & 7);
634 else if (val >= 0x0060 && val <= 0x0067)
635 printk("CALL (P%i)", val & 7);
636 else if (val >= 0x0070 && val <= 0x0077)
637 printk("CALL (PC+P%i)", val & 7);
638 else if (val >= 0x0080 && val <= 0x0087)
639 printk("JUMP (PC+P%i)", val & 7);
640 else if ((val >= 0x1000 && val <= 0x13FF) ||
641 (val >= 0x1800 && val <= 0x1BFF))
642 printk("IF !CC JUMP");
643 else if ((val >= 0x1400 && val <= 0x17ff) ||
644 (val >= 0x1c00 && val <= 0x1fff))
645 printk("IF CC JUMP");
646 else if (val >= 0x2000 && val <= 0x2fff)
648 else if (val >= 0xe080 && val <= 0xe0ff)
650 else if (val >= 0xe200 && val <= 0xe2ff)
652 else if (val >= 0xe300 && val <= 0xe3ff)
653 printk("CALL pcrel");
655 printk("0x%04x", val);
661 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
662 if (trace_buff_offset)
663 index = trace_buff_offset/4 - 1;
667 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
669 decode_address(buf, software_trace_buff[index]);
670 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
674 decode_address(buf, software_trace_buff[index]);
675 printk(KERN_NOTICE " Source : %s\n", buf);
684 trace_buffer_restore(tflags);
687 EXPORT_SYMBOL(dump_bfin_trace_buffer);
690 * Checks to see if the address pointed to is either a
691 * 16-bit CALL instruction, or a 32-bit CALL instruction
693 bool is_bfin_call(unsigned short *addr)
695 unsigned short opcode = 0, *ins_addr;
696 ins_addr = (unsigned short *)addr;
698 if (!get_instruction(&opcode, ins_addr))
701 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
702 (opcode >= 0x0070 && opcode <= 0x0077))
706 if (!get_instruction(&opcode, ins_addr))
709 if (opcode >= 0xE300 && opcode <= 0xE3FF)
715 void show_stack(struct task_struct *task, unsigned long *stack)
717 unsigned int *addr, *endstack, *fp = 0, *frame;
718 unsigned short *ins_addr;
720 unsigned int i, j, ret_addr, frame_no = 0;
723 * If we have been passed a specific stack, use that one otherwise
724 * if we have been passed a task structure, use that, otherwise
725 * use the stack of where the variable "stack" exists
730 /* We know this is a kernel stack, so this is the start/end */
731 stack = (unsigned long *)task->thread.ksp;
732 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
734 /* print out the existing stack info */
735 stack = (unsigned long *)&stack;
736 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
739 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
741 decode_address(buf, (unsigned int)stack);
742 printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
743 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
745 /* First thing is to look for a frame pointer */
746 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
747 addr < endstack; addr++, i++) {
750 ins_addr = (unsigned short *)*addr;
752 if (is_bfin_call(ins_addr))
756 /* Let's check to see if it is a frame pointer */
757 while (fp >= (addr - 1) && fp < endstack && fp)
758 fp = (unsigned int *)*fp;
759 if (fp == 0 || fp == endstack) {
768 printk(" FP: (0x%p)\n", fp);
773 * Now that we think we know where things are, we
774 * walk the stack again, this time printing things out
775 * incase there is no frame pointer, we still look for
776 * valid return addresses
779 /* First time print out data, next time, print out symbols */
780 for (j = 0; j <= 1; j++) {
782 printk(KERN_NOTICE "Return addresses in stack:\n");
784 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
789 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
790 addr <= endstack; addr++, i++) {
793 if (!j && i % 8 == 0)
794 printk("\n" KERN_NOTICE "%p:",addr);
796 /* if it is an odd address, or zero, just skip it */
797 if (*addr & 0x1 || !*addr)
800 ins_addr = (unsigned short *)*addr;
802 /* Go back one instruction, and see if it is a CALL */
804 ret_addr = is_bfin_call(ins_addr);
806 if (!j && stack == (unsigned long *)addr)
807 printk("[%08x]", *addr);
810 decode_address(buf, (unsigned int)*addr);
812 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
815 printk(KERN_NOTICE " address : %s\n", buf);
817 printk("<%08x>", *addr);
818 else if (fp == addr) {
822 printk("(%08x)", *addr);
824 fp = (unsigned int *)*addr;
828 printk(" %08x ", *addr);
836 void dump_stack(void)
839 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
842 trace_buffer_save(tflags);
843 dump_bfin_trace_buffer();
844 show_stack(current, &stack);
845 trace_buffer_restore(tflags);
847 EXPORT_SYMBOL(dump_stack);
849 void dump_bfin_process(struct pt_regs *fp)
851 /* We should be able to look at fp->ipend, but we don't push it on the
852 * stack all the time, so do this until we fix that */
853 unsigned int context = bfin_read_IPEND();
855 if (oops_in_progress)
856 printk(KERN_EMERG "Kernel OOPS in progress\n");
858 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
859 printk(KERN_NOTICE "HW Error context\n");
860 else if (context & 0x0020)
861 printk(KERN_NOTICE "Deferred Exception context\n");
862 else if (context & 0x3FC0)
863 printk(KERN_NOTICE "Interrupt context\n");
864 else if (context & 0x4000)
865 printk(KERN_NOTICE "Deferred Interrupt context\n");
866 else if (context & 0x8000)
867 printk(KERN_NOTICE "Kernel process context\n");
869 /* Because we are crashing, and pointers could be bad, we check things
870 * pretty closely before we use them
872 if ((unsigned long)current >= FIXED_CODE_START &&
873 !((unsigned long)current & 0x3) && current->pid) {
874 printk(KERN_NOTICE "CURRENT PROCESS:\n");
875 if (current->comm >= (char *)FIXED_CODE_START)
876 printk(KERN_NOTICE "COMM=%s PID=%d\n",
877 current->comm, current->pid);
879 printk(KERN_NOTICE "COMM= invalid\n");
881 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
882 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
883 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
885 (void *)current->mm->start_code,
886 (void *)current->mm->end_code,
887 (void *)current->mm->start_data,
888 (void *)current->mm->end_data,
889 (void *)current->mm->end_data,
890 (void *)current->mm->brk,
891 (void *)current->mm->start_stack);
893 printk(KERN_NOTICE "invalid mm\n");
895 printk(KERN_NOTICE "\n" KERN_NOTICE
896 "No Valid process in current context\n");
899 void dump_bfin_mem(struct pt_regs *fp)
901 unsigned short *addr, *erraddr, val = 0, err = 0;
902 char sti = 0, buf[6];
904 erraddr = (void *)fp->pc;
906 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
908 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
909 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
911 if (!((unsigned long)addr & 0xF))
912 printk("\n" KERN_NOTICE "0x%p: ", addr);
914 if (get_instruction(&val, addr)) {
916 sprintf(buf, "????");
918 sprintf(buf, "%04x", val);
920 if (addr == erraddr) {
926 /* Do any previous instructions turn on interrupts? */
927 if (addr <= erraddr && /* in the past */
928 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
929 val == 0x017b)) /* [SP++] = RETI */
935 /* Hardware error interrupts can be deferred */
936 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
938 printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
939 #ifndef CONFIG_DEBUG_HWERR
940 printk(KERN_NOTICE "The remaining message may be meaningless\n"
941 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
942 " better idea where it came from\n");
944 /* If we are handling only one peripheral interrupt
945 * and current mm and pid are valid, and the last error
946 * was in that user space process's text area
947 * print it out - because that is where the problem exists
949 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
950 (current->pid && current->mm)) {
951 /* And the last RETI points to the current userspace context */
952 if ((fp + 1)->pc >= current->mm->start_code &&
953 (fp + 1)->pc <= current->mm->end_code) {
954 printk(KERN_NOTICE "It might be better to look around here : \n");
955 printk(KERN_NOTICE "-------------------------------------------\n");
957 printk(KERN_NOTICE "-------------------------------------------\n");
964 void show_regs(struct pt_regs *fp)
967 struct irqaction *action;
971 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
972 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
973 (long)fp->seqstat, fp->ipend, fp->syscfg);
974 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
975 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
976 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
977 fp->seqstat & SEQSTAT_EXCAUSE);
978 for (i = 6; i <= 15 ; i++) {
979 if (fp->ipend & (1 << i)) {
980 decode_address(buf, bfin_read32(EVT0 + 4*i));
981 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
985 /* if no interrupts are going off, don't print this out */
986 if (fp->ipend & ~0x3F) {
987 for (i = 0; i < (NR_IRQS - 1); i++) {
988 spin_lock_irqsave(&irq_desc[i].lock, flags);
989 action = irq_desc[i].action;
993 decode_address(buf, (unsigned int)action->handler);
994 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
995 for (action = action->next; action; action = action->next) {
996 decode_address(buf, (unsigned int)action->handler);
1001 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1005 decode_address(buf, fp->rete);
1006 printk(KERN_NOTICE " RETE: %s\n", buf);
1007 decode_address(buf, fp->retn);
1008 printk(KERN_NOTICE " RETN: %s\n", buf);
1009 decode_address(buf, fp->retx);
1010 printk(KERN_NOTICE " RETX: %s\n", buf);
1011 decode_address(buf, fp->rets);
1012 printk(KERN_NOTICE " RETS: %s\n", buf);
1013 decode_address(buf, fp->pc);
1014 printk(KERN_NOTICE " PC : %s\n", buf);
1016 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1017 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1018 decode_address(buf, saved_dcplb_fault_addr);
1019 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1020 decode_address(buf, saved_icplb_fault_addr);
1021 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1024 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1025 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1026 fp->r0, fp->r1, fp->r2, fp->r3);
1027 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1028 fp->r4, fp->r5, fp->r6, fp->r7);
1029 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1030 fp->p0, fp->p1, fp->p2, fp->p3);
1031 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1032 fp->p4, fp->p5, fp->fp, (long)fp);
1033 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1034 fp->lb0, fp->lt0, fp->lc0);
1035 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1036 fp->lb1, fp->lt1, fp->lc1);
1037 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1038 fp->b0, fp->l0, fp->m0, fp->i0);
1039 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1040 fp->b1, fp->l1, fp->m1, fp->i1);
1041 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1042 fp->b2, fp->l2, fp->m2, fp->i2);
1043 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1044 fp->b3, fp->l3, fp->m3, fp->i3);
1045 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1046 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1048 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1049 rdusp(), fp->astat);
1051 printk(KERN_NOTICE "\n");
1054 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1055 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1058 asmlinkage int sys_bfin_spinlock(int *spinlock)
1063 local_irq_disable();
1064 ret = get_user(tmp, spinlock);
1069 put_user(tmp, spinlock);
1075 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1077 void (*curr_handler)(void);
1079 if (exception > 0x3F)
1082 curr_handler = ex_table[exception];
1084 if (curr_handler != ex_replaceable)
1087 ex_table[exception] = handler;
1091 EXPORT_SYMBOL(bfin_request_exception);
1093 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1095 void (*curr_handler)(void);
1097 if (exception > 0x3F)
1100 curr_handler = ex_table[exception];
1102 if (curr_handler != handler)
1105 ex_table[exception] = ex_replaceable;
1109 EXPORT_SYMBOL(bfin_free_exception);
1111 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1113 switch (cplb_panic) {
1114 case CPLB_NO_UNLOCKED:
1115 printk(KERN_EMERG "All CPLBs are locked\n");
1117 case CPLB_PROT_VIOL:
1119 case CPLB_NO_ADDR_MATCH:
1121 case CPLB_UNKNOWN_ERR:
1122 printk(KERN_EMERG "Unknown CPLB Exception\n");
1126 oops_in_progress = 1;
1128 dump_bfin_process(fp);
1132 panic("Unrecoverable event\n");