2 * Copyright 2004-2009 Analog Devices Inc.
4 * Licensed under the GPL-2 or later
8 #include <linux/uaccess.h>
9 #include <linux/interrupt.h>
10 #include <linux/module.h>
11 #include <linux/kallsyms.h>
13 #include <linux/rbtree.h>
14 #include <asm/traps.h>
15 #include <asm/cacheflush.h>
18 #include <asm/blackfin.h>
19 #include <asm/irq_handler.h>
20 #include <linux/irq.h>
21 #include <asm/trace.h>
22 #include <asm/fixed_code.h>
25 # include <linux/kgdb.h>
27 # define CHK_DEBUGGER_TRAP() \
29 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
31 # define CHK_DEBUGGER_TRAP_MAYBE() \
34 CHK_DEBUGGER_TRAP(); \
37 # define CHK_DEBUGGER_TRAP() do { } while (0)
38 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
42 #ifdef CONFIG_DEBUG_VERBOSE
43 #define verbose_printk(fmt, arg...) \
46 #define verbose_printk(fmt, arg...) \
47 ({ if (0) printk(fmt, ##arg); 0; })
50 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
52 #ifdef CONFIG_DEBUG_MMRS_MODULE
53 EXPORT_SYMBOL(last_seqstat);
57 /* Initiate the event table handler */
58 void __init trap_init(void)
61 bfin_write_EVT3(trap);
65 static void decode_address(char *buf, unsigned long address)
67 #ifdef CONFIG_DEBUG_VERBOSE
68 struct task_struct *p;
70 unsigned long flags, offset;
71 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
74 #ifdef CONFIG_KALLSYMS
75 unsigned long symsize;
82 buf += sprintf(buf, "<0x%08lx> ", address);
84 #ifdef CONFIG_KALLSYMS
85 /* look up the address and see if we are in kernel space */
86 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
89 /* yeah! kernel space! */
92 sprintf(buf, "{ %s%s%s%s + 0x%lx }",
93 delim, modname, delim, symname,
94 (unsigned long)offset);
99 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
100 /* Problem in fixed code section? */
101 strcat(buf, "/* Maybe fixed code section */");
104 } else if (address < CONFIG_BOOT_LOAD) {
105 /* Problem somewhere before the kernel start address */
106 strcat(buf, "/* Maybe null pointer? */");
109 } else if (address >= COREMMR_BASE) {
110 strcat(buf, "/* core mmrs */");
113 } else if (address >= SYSMMR_BASE) {
114 strcat(buf, "/* system mmrs */");
117 } else if (address >= L1_ROM_START && address < L1_ROM_START + L1_ROM_LENGTH) {
118 strcat(buf, "/* on-chip L1 ROM */");
123 * Don't walk any of the vmas if we are oopsing, it has been known
124 * to cause problems - corrupt vmas (kernel crashes) cause double faults
126 if (oops_in_progress) {
127 strcat(buf, "/* kernel dynamic memory (maybe user-space) */");
131 /* looks like we're off in user-land, so let's walk all the
132 * mappings of all our processes and see if we can't be a whee
135 write_lock_irqsave(&tasklist_lock, flags);
136 for_each_process(p) {
137 mm = (in_atomic ? p->mm : get_task_mm(p));
141 if (!down_read_trylock(&mm->mmap_sem)) {
147 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
148 struct vm_area_struct *vma;
150 vma = rb_entry(n, struct vm_area_struct, vm_rb);
152 if (address >= vma->vm_start && address < vma->vm_end) {
154 char *name = p->comm;
155 struct file *file = vma->vm_file;
158 char *d_name = d_path(&file->f_path, _tmpbuf,
164 /* FLAT does not have its text aligned to the start of
165 * the map while FDPIC ELF does ...
168 /* before we can check flat/fdpic, we need to
169 * make sure current is valid
171 if ((unsigned long)current >= FIXED_CODE_START &&
172 !((unsigned long)current & 0x3)) {
174 (address > current->mm->start_code) &&
175 (address < current->mm->end_code))
176 offset = address - current->mm->start_code;
178 offset = (address - vma->vm_start) +
179 (vma->vm_pgoff << PAGE_SHIFT);
181 sprintf(buf, "[ %s + 0x%lx ]", name, offset);
183 sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
184 name, vma->vm_start, vma->vm_end);
186 up_read(&mm->mmap_sem);
191 sprintf(buf, "[ %s ] dynamic memory", name);
197 up_read(&mm->mmap_sem);
203 * we were unable to find this address anywhere,
204 * or some MMs were skipped because they were in use.
206 sprintf(buf, "/* kernel dynamic memory */");
209 write_unlock_irqrestore(&tasklist_lock, flags);
215 asmlinkage void double_fault_c(struct pt_regs *fp)
217 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
219 trace_buffer_save(j);
223 oops_in_progress = 1;
224 #ifdef CONFIG_DEBUG_VERBOSE
225 printk(KERN_EMERG "Double Fault\n");
226 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
227 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
228 unsigned int cpu = raw_smp_processor_id();
230 decode_address(buf, cpu_pda[cpu].retx_doublefault);
231 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
232 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
233 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
234 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
235 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
236 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
238 decode_address(buf, fp->retx);
239 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
243 dump_bfin_process(fp);
246 dump_bfin_trace_buffer();
249 panic("Double Fault - unrecoverable event");
253 static int kernel_mode_regs(struct pt_regs *regs)
255 return regs->ipend & 0xffc0;
258 asmlinkage notrace void trap_c(struct pt_regs *fp)
260 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
263 unsigned int cpu = raw_smp_processor_id();
264 const char *strerror = NULL;
267 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
269 trace_buffer_save(j);
270 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
271 last_seqstat = (u32)fp->seqstat;
274 /* Important - be very careful dereferncing pointers - will lead to
275 * double faults if the stack has become corrupt
278 /* trap_c() will be called for exceptions. During exceptions
279 * processing, the pc value should be set with retx value.
280 * With this change we can cleanup some code in signal.c- TODO
282 fp->orig_pc = fp->retx;
283 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
284 trapnr, fp->ipend, fp->pc, fp->retx); */
286 /* send the appropriate signal to the user program */
289 /* This table works in conjuction with the one in ./mach-common/entry.S
290 * Some exceptions are handled there (in assembly, in exception space)
291 * Some are handled here, (in C, in interrupt space)
292 * Some, like CPLB, are handled in both, where the normal path is
293 * handled in assembly/exception space, and the error path is handled
297 /* 0x00 - Linux Syscall, getting here is an error */
298 /* 0x01 - userspace gdb breakpoint, handled here */
300 info.si_code = TRAP_ILLTRAP;
302 CHK_DEBUGGER_TRAP_MAYBE();
303 /* Check if this is a breakpoint in kernel space */
304 if (kernel_mode_regs(fp))
308 /* 0x03 - User Defined, userspace stack overflow */
310 info.si_code = SEGV_STACKFLOW;
312 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
313 CHK_DEBUGGER_TRAP_MAYBE();
315 /* 0x02 - KGDB initial connection and break signal trap */
318 info.si_code = TRAP_ILLTRAP;
323 /* 0x04 - User Defined */
324 /* 0x05 - User Defined */
325 /* 0x06 - User Defined */
326 /* 0x07 - User Defined */
327 /* 0x08 - User Defined */
328 /* 0x09 - User Defined */
329 /* 0x0A - User Defined */
330 /* 0x0B - User Defined */
331 /* 0x0C - User Defined */
332 /* 0x0D - User Defined */
333 /* 0x0E - User Defined */
334 /* 0x0F - User Defined */
335 /* If we got here, it is most likely that someone was trying to use a
336 * custom exception handler, and it is not actually installed properly
338 case VEC_EXCPT04 ... VEC_EXCPT15:
339 info.si_code = ILL_ILLPARAOP;
341 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
342 CHK_DEBUGGER_TRAP_MAYBE();
344 /* 0x10 HW Single step, handled here */
346 info.si_code = TRAP_STEP;
348 CHK_DEBUGGER_TRAP_MAYBE();
349 /* Check if this is a single step in kernel space */
350 if (kernel_mode_regs(fp))
354 /* 0x11 - Trace Buffer Full, handled here */
356 info.si_code = TRAP_TRACEFLOW;
358 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
359 CHK_DEBUGGER_TRAP_MAYBE();
361 /* 0x12 - Reserved, Caught by default */
362 /* 0x13 - Reserved, Caught by default */
363 /* 0x14 - Reserved, Caught by default */
364 /* 0x15 - Reserved, Caught by default */
365 /* 0x16 - Reserved, Caught by default */
366 /* 0x17 - Reserved, Caught by default */
367 /* 0x18 - Reserved, Caught by default */
368 /* 0x19 - Reserved, Caught by default */
369 /* 0x1A - Reserved, Caught by default */
370 /* 0x1B - Reserved, Caught by default */
371 /* 0x1C - Reserved, Caught by default */
372 /* 0x1D - Reserved, Caught by default */
373 /* 0x1E - Reserved, Caught by default */
374 /* 0x1F - Reserved, Caught by default */
375 /* 0x20 - Reserved, Caught by default */
376 /* 0x21 - Undefined Instruction, handled here */
379 if (kernel_mode_regs(fp)) {
380 switch (report_bug(fp->pc, fp)) {
381 case BUG_TRAP_TYPE_NONE:
383 case BUG_TRAP_TYPE_WARN:
384 dump_bfin_trace_buffer();
387 case BUG_TRAP_TYPE_BUG:
388 /* call to panic() will dump trace, and it is
389 * off at this point, so it won't be clobbered
395 info.si_code = ILL_ILLOPC;
397 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
398 CHK_DEBUGGER_TRAP_MAYBE();
400 /* 0x22 - Illegal Instruction Combination, handled here */
402 info.si_code = ILL_ILLPARAOP;
404 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
405 CHK_DEBUGGER_TRAP_MAYBE();
407 /* 0x23 - Data CPLB protection violation, handled here */
409 info.si_code = ILL_CPLB_VI;
411 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
412 CHK_DEBUGGER_TRAP_MAYBE();
414 /* 0x24 - Data access misaligned, handled here */
416 info.si_code = BUS_ADRALN;
418 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
419 CHK_DEBUGGER_TRAP_MAYBE();
421 /* 0x25 - Unrecoverable Event, handled here */
423 info.si_code = ILL_ILLEXCPT;
425 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
426 CHK_DEBUGGER_TRAP_MAYBE();
428 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
429 error case is handled here */
431 info.si_code = BUS_ADRALN;
433 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
435 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
437 info.si_code = ILL_CPLB_MULHIT;
439 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
440 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
441 strerror = KERN_NOTICE "NULL pointer access\n";
444 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
445 CHK_DEBUGGER_TRAP_MAYBE();
447 /* 0x28 - Emulation Watchpoint, handled here */
449 info.si_code = TRAP_WATCHPT;
451 pr_debug(EXC_0x28(KERN_DEBUG));
452 CHK_DEBUGGER_TRAP_MAYBE();
453 /* Check if this is a watchpoint in kernel space */
454 if (kernel_mode_regs(fp))
459 /* 0x29 - Instruction fetch access error (535 only) */
460 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
461 info.si_code = BUS_OPFETCH;
463 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
464 CHK_DEBUGGER_TRAP_MAYBE();
467 /* 0x29 - Reserved, Caught by default */
469 /* 0x2A - Instruction fetch misaligned, handled here */
471 info.si_code = BUS_ADRALN;
473 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
474 CHK_DEBUGGER_TRAP_MAYBE();
476 /* 0x2B - Instruction CPLB protection violation, handled here */
478 info.si_code = ILL_CPLB_VI;
480 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
481 CHK_DEBUGGER_TRAP_MAYBE();
483 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
485 info.si_code = ILL_CPLB_MISS;
487 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
489 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
490 case VEC_CPLB_I_MHIT:
491 info.si_code = ILL_CPLB_MULHIT;
493 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
494 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
495 strerror = KERN_NOTICE "Jump to NULL address\n";
498 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
499 CHK_DEBUGGER_TRAP_MAYBE();
501 /* 0x2E - Illegal use of Supervisor Resource, handled here */
503 info.si_code = ILL_PRVOPC;
505 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
506 CHK_DEBUGGER_TRAP_MAYBE();
508 /* 0x2F - Reserved, Caught by default */
509 /* 0x30 - Reserved, Caught by default */
510 /* 0x31 - Reserved, Caught by default */
511 /* 0x32 - Reserved, Caught by default */
512 /* 0x33 - Reserved, Caught by default */
513 /* 0x34 - Reserved, Caught by default */
514 /* 0x35 - Reserved, Caught by default */
515 /* 0x36 - Reserved, Caught by default */
516 /* 0x37 - Reserved, Caught by default */
517 /* 0x38 - Reserved, Caught by default */
518 /* 0x39 - Reserved, Caught by default */
519 /* 0x3A - Reserved, Caught by default */
520 /* 0x3B - Reserved, Caught by default */
521 /* 0x3C - Reserved, Caught by default */
522 /* 0x3D - Reserved, Caught by default */
523 /* 0x3E - Reserved, Caught by default */
524 /* 0x3F - Reserved, Caught by default */
526 info.si_code = BUS_ADRALN;
528 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
529 /* System MMR Error */
530 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
531 info.si_code = BUS_ADRALN;
533 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
535 /* External Memory Addressing Error */
536 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
537 if (ANOMALY_05000310) {
538 static unsigned long anomaly_rets;
540 if ((fp->pc >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
541 (fp->pc < (L1_CODE_START + L1_CODE_LENGTH))) {
543 * A false hardware error will happen while fetching at
544 * the L1 instruction SRAM boundary. Ignore it.
546 anomaly_rets = fp->rets;
548 } else if (fp->rets == anomaly_rets) {
550 * While boundary code returns to a function, at the ret
551 * point, a new false hardware error might occur too based
552 * on tests. Ignore it too.
555 } else if ((fp->rets >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
556 (fp->rets < (L1_CODE_START + L1_CODE_LENGTH))) {
558 * If boundary code calls a function, at the entry point,
559 * a new false hardware error maybe happen based on tests.
567 info.si_code = BUS_ADRERR;
569 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
571 /* Performance Monitor Overflow */
572 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
573 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
575 /* RAISE 5 instruction */
576 case (SEQSTAT_HWERRCAUSE_RAISE_5):
577 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
579 default: /* Reserved */
580 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
583 CHK_DEBUGGER_TRAP_MAYBE();
586 * We should be handling all known exception types above,
587 * if we get here we hit a reserved one, so panic
590 info.si_code = ILL_ILLPARAOP;
592 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
593 (fp->seqstat & SEQSTAT_EXCAUSE));
594 CHK_DEBUGGER_TRAP_MAYBE();
600 /* If the fault was caused by a kernel thread, or interrupt handler
601 * we will kernel panic, so the system reboots.
603 if (kernel_mode_regs(fp) || (current && !current->mm)) {
605 oops_in_progress = 1;
608 if (sig != SIGTRAP) {
610 verbose_printk(strerror);
612 dump_bfin_process(fp);
616 /* Print out the trace buffer if it makes sense */
617 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
618 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
619 verbose_printk(KERN_NOTICE "No trace since you do not have "
620 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
623 dump_bfin_trace_buffer();
625 if (oops_in_progress) {
626 /* Dump the current kernel stack */
627 verbose_printk(KERN_NOTICE "Kernel Stack\n");
628 show_stack(current, NULL);
630 #ifndef CONFIG_ACCESS_CHECK
631 verbose_printk(KERN_EMERG "Please turn on "
632 "CONFIG_ACCESS_CHECK\n");
634 panic("Kernel exception");
636 #ifdef CONFIG_DEBUG_VERBOSE
637 unsigned long *stack;
638 /* Dump the user space stack */
639 stack = (unsigned long *)rdusp();
640 verbose_printk(KERN_NOTICE "Userspace Stack\n");
641 show_stack(NULL, stack);
647 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
657 info.si_addr = (void __user *)cpu_pda[cpu].dcplb_fault_addr;
660 info.si_addr = (void __user *)fp->pc;
663 force_sig_info(sig, &info, current);
666 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
667 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
668 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
669 fp->pc = SAFE_USER_INSTRUCTION;
672 trace_buffer_restore(j);
675 /* Typical exception handling routines */
677 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
680 * Similar to get_user, do some address checking, then dereference
681 * Return true on success, false on bad address
683 static bool get_instruction(unsigned short *val, unsigned short *address)
685 unsigned long addr = (unsigned long)address;
687 /* Check for odd addresses */
691 /* MMR region will never have instructions */
692 if (addr >= SYSMMR_BASE)
695 switch (bfin_mem_access_type(addr, 2)) {
696 case BFIN_MEM_ACCESS_CORE:
697 case BFIN_MEM_ACCESS_CORE_ONLY:
700 case BFIN_MEM_ACCESS_DMA:
701 dma_memcpy(val, address, 2);
703 case BFIN_MEM_ACCESS_ITEST:
704 isram_memcpy(val, address, 2);
706 default: /* invalid access */
712 * decode the instruction if we are printing out the trace, as it
713 * makes things easier to follow, without running it through objdump
714 * These are the normal instructions which cause change of flow, which
715 * would be at the source of the trace buffer
717 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
718 static void decode_instruction(unsigned short *address)
720 unsigned short opcode;
722 if (get_instruction(&opcode, address)) {
723 if (opcode == 0x0010)
724 verbose_printk("RTS");
725 else if (opcode == 0x0011)
726 verbose_printk("RTI");
727 else if (opcode == 0x0012)
728 verbose_printk("RTX");
729 else if (opcode == 0x0013)
730 verbose_printk("RTN");
731 else if (opcode == 0x0014)
732 verbose_printk("RTE");
733 else if (opcode == 0x0025)
734 verbose_printk("EMUEXCPT");
735 else if (opcode >= 0x0040 && opcode <= 0x0047)
736 verbose_printk("STI R%i", opcode & 7);
737 else if (opcode >= 0x0050 && opcode <= 0x0057)
738 verbose_printk("JUMP (P%i)", opcode & 7);
739 else if (opcode >= 0x0060 && opcode <= 0x0067)
740 verbose_printk("CALL (P%i)", opcode & 7);
741 else if (opcode >= 0x0070 && opcode <= 0x0077)
742 verbose_printk("CALL (PC+P%i)", opcode & 7);
743 else if (opcode >= 0x0080 && opcode <= 0x0087)
744 verbose_printk("JUMP (PC+P%i)", opcode & 7);
745 else if (opcode >= 0x0090 && opcode <= 0x009F)
746 verbose_printk("RAISE 0x%x", opcode & 0xF);
747 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
748 verbose_printk("EXCPT 0x%x", opcode & 0xF);
749 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
750 verbose_printk("IF !CC JUMP");
751 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
752 verbose_printk("IF CC JUMP");
753 else if (opcode >= 0x2000 && opcode <= 0x2fff)
754 verbose_printk("JUMP.S");
755 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
756 verbose_printk("LSETUP");
757 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
758 verbose_printk("JUMP.L");
759 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
760 verbose_printk("CALL pcrel");
762 verbose_printk("0x%04x", opcode);
768 void dump_bfin_trace_buffer(void)
770 #ifdef CONFIG_DEBUG_VERBOSE
771 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
774 unsigned short *addr;
775 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
779 trace_buffer_save(tflags);
781 printk(KERN_NOTICE "Hardware Trace:\n");
783 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
784 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
787 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
788 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
789 decode_address(buf, (unsigned long)bfin_read_TBUF());
790 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
791 addr = (unsigned short *)bfin_read_TBUF();
792 decode_address(buf, (unsigned long)addr);
793 printk(KERN_NOTICE " Source : %s ", buf);
794 decode_instruction(addr);
799 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
800 if (trace_buff_offset)
801 index = trace_buff_offset / 4;
805 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
807 decode_address(buf, software_trace_buff[index]);
808 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
812 decode_address(buf, software_trace_buff[index]);
813 printk(KERN_NOTICE " Source : %s ", buf);
814 decode_instruction((unsigned short *)software_trace_buff[index]);
824 trace_buffer_restore(tflags);
828 EXPORT_SYMBOL(dump_bfin_trace_buffer);
831 int is_valid_bugaddr(unsigned long addr)
833 unsigned short opcode;
835 if (!get_instruction(&opcode, (unsigned short *)addr))
838 return opcode == BFIN_BUG_OPCODE;
843 * Checks to see if the address pointed to is either a
844 * 16-bit CALL instruction, or a 32-bit CALL instruction
846 static bool is_bfin_call(unsigned short *addr)
848 unsigned short opcode = 0, *ins_addr;
849 ins_addr = (unsigned short *)addr;
851 if (!get_instruction(&opcode, ins_addr))
854 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
855 (opcode >= 0x0070 && opcode <= 0x0077))
859 if (!get_instruction(&opcode, ins_addr))
862 if (opcode >= 0xE300 && opcode <= 0xE3FF)
869 void show_stack(struct task_struct *task, unsigned long *stack)
872 unsigned int *addr, *endstack, *fp = 0, *frame;
873 unsigned short *ins_addr;
875 unsigned int i, j, ret_addr, frame_no = 0;
878 * If we have been passed a specific stack, use that one otherwise
879 * if we have been passed a task structure, use that, otherwise
880 * use the stack of where the variable "stack" exists
885 /* We know this is a kernel stack, so this is the start/end */
886 stack = (unsigned long *)task->thread.ksp;
887 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
889 /* print out the existing stack info */
890 stack = (unsigned long *)&stack;
891 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
894 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
896 printk(KERN_NOTICE "Stack info:\n");
897 decode_address(buf, (unsigned int)stack);
898 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
900 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
901 printk(KERN_NOTICE "Invalid stack pointer\n");
905 /* First thing is to look for a frame pointer */
906 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
909 ins_addr = (unsigned short *)*addr;
911 if (is_bfin_call(ins_addr))
915 /* Let's check to see if it is a frame pointer */
916 while (fp >= (addr - 1) && fp < endstack
917 && fp && ((unsigned int) fp & 0x3) == 0)
918 fp = (unsigned int *)*fp;
919 if (fp == 0 || fp == endstack) {
928 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
933 * Now that we think we know where things are, we
934 * walk the stack again, this time printing things out
935 * incase there is no frame pointer, we still look for
936 * valid return addresses
939 /* First time print out data, next time, print out symbols */
940 for (j = 0; j <= 1; j++) {
942 printk(KERN_NOTICE "Return addresses in stack:\n");
944 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
949 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
950 addr < endstack; addr++, i++) {
953 if (!j && i % 8 == 0)
954 printk(KERN_NOTICE "%p:",addr);
956 /* if it is an odd address, or zero, just skip it */
957 if (*addr & 0x1 || !*addr)
960 ins_addr = (unsigned short *)*addr;
962 /* Go back one instruction, and see if it is a CALL */
964 ret_addr = is_bfin_call(ins_addr);
966 if (!j && stack == (unsigned long *)addr)
967 printk("[%08x]", *addr);
970 decode_address(buf, (unsigned int)*addr);
972 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
975 printk(KERN_NOTICE " address : %s\n", buf);
977 printk("<%08x>", *addr);
978 else if (fp == addr) {
982 printk("(%08x)", *addr);
984 fp = (unsigned int *)*addr;
988 printk(" %08x ", *addr);
995 EXPORT_SYMBOL(show_stack);
997 void dump_stack(void)
1000 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
1003 trace_buffer_save(tflags);
1004 dump_bfin_trace_buffer();
1005 show_stack(current, &stack);
1006 trace_buffer_restore(tflags);
1008 EXPORT_SYMBOL(dump_stack);
1010 void dump_bfin_process(struct pt_regs *fp)
1012 #ifdef CONFIG_DEBUG_VERBOSE
1013 /* We should be able to look at fp->ipend, but we don't push it on the
1014 * stack all the time, so do this until we fix that */
1015 unsigned int context = bfin_read_IPEND();
1017 if (oops_in_progress)
1018 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
1020 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
1021 verbose_printk(KERN_NOTICE "HW Error context\n");
1022 else if (context & 0x0020)
1023 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
1024 else if (context & 0x3FC0)
1025 verbose_printk(KERN_NOTICE "Interrupt context\n");
1026 else if (context & 0x4000)
1027 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
1028 else if (context & 0x8000)
1029 verbose_printk(KERN_NOTICE "Kernel process context\n");
1031 /* Because we are crashing, and pointers could be bad, we check things
1032 * pretty closely before we use them
1034 if ((unsigned long)current >= FIXED_CODE_START &&
1035 !((unsigned long)current & 0x3) && current->pid) {
1036 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
1037 if (current->comm >= (char *)FIXED_CODE_START)
1038 verbose_printk(KERN_NOTICE "COMM=%s PID=%d",
1039 current->comm, current->pid);
1041 verbose_printk(KERN_NOTICE "COMM= invalid");
1043 printk(KERN_CONT " CPU=%d\n", current_thread_info()->cpu);
1044 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
1045 verbose_printk(KERN_NOTICE
1046 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
1047 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
1048 (void *)current->mm->start_code,
1049 (void *)current->mm->end_code,
1050 (void *)current->mm->start_data,
1051 (void *)current->mm->end_data,
1052 (void *)current->mm->end_data,
1053 (void *)current->mm->brk,
1054 (void *)current->mm->start_stack);
1056 verbose_printk(KERN_NOTICE "invalid mm\n");
1058 verbose_printk(KERN_NOTICE
1059 "No Valid process in current context\n");
1063 void dump_bfin_mem(struct pt_regs *fp)
1065 #ifdef CONFIG_DEBUG_VERBOSE
1066 unsigned short *addr, *erraddr, val = 0, err = 0;
1067 char sti = 0, buf[6];
1069 erraddr = (void *)fp->pc;
1071 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
1073 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1074 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1076 if (!((unsigned long)addr & 0xF))
1077 verbose_printk(KERN_NOTICE "0x%p: ", addr);
1079 if (!get_instruction(&val, addr)) {
1081 sprintf(buf, "????");
1083 sprintf(buf, "%04x", val);
1085 if (addr == erraddr) {
1086 verbose_printk("[%s]", buf);
1089 verbose_printk(" %s ", buf);
1091 /* Do any previous instructions turn on interrupts? */
1092 if (addr <= erraddr && /* in the past */
1093 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1094 val == 0x017b)) /* [SP++] = RETI */
1098 verbose_printk("\n");
1100 /* Hardware error interrupts can be deferred */
1101 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1103 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
1104 #ifndef CONFIG_DEBUG_HWERR
1105 verbose_printk(KERN_NOTICE
1106 "The remaining message may be meaningless\n"
1107 "You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
1109 /* If we are handling only one peripheral interrupt
1110 * and current mm and pid are valid, and the last error
1111 * was in that user space process's text area
1112 * print it out - because that is where the problem exists
1114 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1115 (current->pid && current->mm)) {
1116 /* And the last RETI points to the current userspace context */
1117 if ((fp + 1)->pc >= current->mm->start_code &&
1118 (fp + 1)->pc <= current->mm->end_code) {
1119 verbose_printk(KERN_NOTICE "It might be better to look around here :\n");
1120 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1122 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1130 void show_regs(struct pt_regs *fp)
1132 #ifdef CONFIG_DEBUG_VERBOSE
1134 struct irqaction *action;
1136 unsigned long flags = 0;
1137 unsigned int cpu = raw_smp_processor_id();
1138 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
1140 verbose_printk(KERN_NOTICE "\n");
1141 if (CPUID != bfin_cpuid())
1142 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1143 "but running on:0x%04x (Rev %d)\n",
1144 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1146 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1147 CPU, bfin_compiled_revid());
1149 if (bfin_compiled_revid() != bfin_revid())
1150 verbose_printk("(Detected 0.%d)", bfin_revid());
1152 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1153 get_cclk()/1000000, get_sclk()/1000000,
1161 verbose_printk(KERN_NOTICE "%s", linux_banner);
1163 verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
1164 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
1165 (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
1166 if (fp->ipend & EVT_IRPTEN)
1167 verbose_printk(KERN_NOTICE " Global Interrupts Disabled (IPEND[4])\n");
1168 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
1169 EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
1170 verbose_printk(KERN_NOTICE " Peripheral interrupts masked off\n");
1171 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
1172 verbose_printk(KERN_NOTICE " Kernel interrupts masked off\n");
1173 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
1174 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1175 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1177 /* If the error was from the EBIU, print it out */
1178 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
1179 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
1180 bfin_read_EBIU_ERRMST());
1181 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
1182 bfin_read_EBIU_ERRADD());
1186 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1187 fp->seqstat & SEQSTAT_EXCAUSE);
1188 for (i = 2; i <= 15 ; i++) {
1189 if (fp->ipend & (1 << i)) {
1191 decode_address(buf, bfin_read32(EVT0 + 4*i));
1192 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1194 verbose_printk(KERN_NOTICE " interrupts disabled\n");
1198 /* if no interrupts are going off, don't print this out */
1199 if (fp->ipend & ~0x3F) {
1200 for (i = 0; i < (NR_IRQS - 1); i++) {
1202 raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
1204 action = irq_desc[i].action;
1208 decode_address(buf, (unsigned int)action->handler);
1209 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1210 for (action = action->next; action; action = action->next) {
1211 decode_address(buf, (unsigned int)action->handler);
1212 verbose_printk(", %s", buf);
1214 verbose_printk("\n");
1217 raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1221 decode_address(buf, fp->rete);
1222 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
1223 decode_address(buf, fp->retn);
1224 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
1225 decode_address(buf, fp->retx);
1226 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
1227 decode_address(buf, fp->rets);
1228 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
1229 decode_address(buf, fp->pc);
1230 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
1232 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1233 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1234 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
1235 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1236 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
1237 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1240 verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
1241 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1242 fp->r0, fp->r1, fp->r2, fp->r3);
1243 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1244 fp->r4, fp->r5, fp->r6, fp->r7);
1245 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1246 fp->p0, fp->p1, fp->p2, fp->p3);
1247 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1248 fp->p4, fp->p5, fp->fp, (long)fp);
1249 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1250 fp->lb0, fp->lt0, fp->lc0);
1251 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1252 fp->lb1, fp->lt1, fp->lc1);
1253 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1254 fp->b0, fp->l0, fp->m0, fp->i0);
1255 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1256 fp->b1, fp->l1, fp->m1, fp->i1);
1257 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1258 fp->b2, fp->l2, fp->m2, fp->i2);
1259 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1260 fp->b3, fp->l3, fp->m3, fp->i3);
1261 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1262 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1264 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1265 rdusp(), fp->astat);
1267 verbose_printk(KERN_NOTICE "\n");
1271 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1272 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1275 static DEFINE_SPINLOCK(bfin_spinlock_lock);
1277 asmlinkage int sys_bfin_spinlock(int *p)
1281 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1282 ret = get_user(tmp, p);
1283 if (likely(ret == 0)) {
1289 spin_unlock(&bfin_spinlock_lock);
1293 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1295 void (*curr_handler)(void);
1297 if (exception > 0x3F)
1300 curr_handler = ex_table[exception];
1302 if (curr_handler != ex_replaceable)
1305 ex_table[exception] = handler;
1309 EXPORT_SYMBOL(bfin_request_exception);
1311 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1313 void (*curr_handler)(void);
1315 if (exception > 0x3F)
1318 curr_handler = ex_table[exception];
1320 if (curr_handler != handler)
1323 ex_table[exception] = ex_replaceable;
1327 EXPORT_SYMBOL(bfin_free_exception);
1329 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1331 switch (cplb_panic) {
1332 case CPLB_NO_UNLOCKED:
1333 printk(KERN_EMERG "All CPLBs are locked\n");
1335 case CPLB_PROT_VIOL:
1337 case CPLB_NO_ADDR_MATCH:
1339 case CPLB_UNKNOWN_ERR:
1340 printk(KERN_EMERG "Unknown CPLB Exception\n");
1344 oops_in_progress = 1;
1346 dump_bfin_process(fp);
1350 panic("Unrecoverable event");