2 * File: arch/blackfin/kernel/traps.c
4 * Author: Hamish Macdonald
7 * Description: uses S/W interrupt 15 for the system calls
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/bug.h>
31 #include <linux/uaccess.h>
32 #include <linux/interrupt.h>
33 #include <linux/module.h>
34 #include <linux/kallsyms.h>
36 #include <linux/rbtree.h>
37 #include <asm/traps.h>
38 #include <asm/cacheflush.h>
41 #include <asm/blackfin.h>
42 #include <asm/irq_handler.h>
43 #include <linux/irq.h>
44 #include <asm/trace.h>
45 #include <asm/fixed_code.h>
48 # include <linux/kgdb.h>
50 # define CHK_DEBUGGER_TRAP() \
52 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
54 # define CHK_DEBUGGER_TRAP_MAYBE() \
57 CHK_DEBUGGER_TRAP(); \
60 # define CHK_DEBUGGER_TRAP() do { } while (0)
61 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
65 #ifdef CONFIG_DEBUG_VERBOSE
66 #define verbose_printk(fmt, arg...) \
69 #define verbose_printk(fmt, arg...) \
70 ({ if (0) printk(fmt, ##arg); 0; })
73 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
75 #ifdef CONFIG_DEBUG_MMRS_MODULE
76 EXPORT_SYMBOL(last_seqstat);
80 /* Initiate the event table handler */
81 void __init trap_init(void)
84 bfin_write_EVT3(trap);
88 static void decode_address(char *buf, unsigned long address)
90 #ifdef CONFIG_DEBUG_VERBOSE
91 struct task_struct *p;
93 unsigned long flags, offset;
94 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
97 #ifdef CONFIG_KALLSYMS
98 unsigned long symsize;
105 buf += sprintf(buf, "<0x%08lx> ", address);
107 #ifdef CONFIG_KALLSYMS
108 /* look up the address and see if we are in kernel space */
109 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
112 /* yeah! kernel space! */
114 modname = delim = "";
115 sprintf(buf, "{ %s%s%s%s + 0x%lx }",
116 delim, modname, delim, symname,
117 (unsigned long)offset);
122 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
123 /* Problem in fixed code section? */
124 strcat(buf, "/* Maybe fixed code section */");
127 } else if (address < CONFIG_BOOT_LOAD) {
128 /* Problem somewhere before the kernel start address */
129 strcat(buf, "/* Maybe null pointer? */");
132 } else if (address >= COREMMR_BASE) {
133 strcat(buf, "/* core mmrs */");
136 } else if (address >= SYSMMR_BASE) {
137 strcat(buf, "/* system mmrs */");
140 } else if (address >= L1_ROM_START && address < L1_ROM_START + L1_ROM_LENGTH) {
141 strcat(buf, "/* on-chip L1 ROM */");
145 /* looks like we're off in user-land, so let's walk all the
146 * mappings of all our processes and see if we can't be a whee
149 write_lock_irqsave(&tasklist_lock, flags);
150 for_each_process(p) {
151 mm = (in_atomic ? p->mm : get_task_mm(p));
155 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
156 struct vm_area_struct *vma;
158 vma = rb_entry(n, struct vm_area_struct, vm_rb);
160 if (address >= vma->vm_start && address < vma->vm_end) {
162 char *name = p->comm;
163 struct file *file = vma->vm_file;
166 char *d_name = d_path(&file->f_path, _tmpbuf,
172 /* FLAT does not have its text aligned to the start of
173 * the map while FDPIC ELF does ...
176 /* before we can check flat/fdpic, we need to
177 * make sure current is valid
179 if ((unsigned long)current >= FIXED_CODE_START &&
180 !((unsigned long)current & 0x3)) {
182 (address > current->mm->start_code) &&
183 (address < current->mm->end_code))
184 offset = address - current->mm->start_code;
186 offset = (address - vma->vm_start) +
187 (vma->vm_pgoff << PAGE_SHIFT);
189 sprintf(buf, "[ %s + 0x%lx ]", name, offset);
191 sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
192 name, vma->vm_start, vma->vm_end);
198 sprintf(buf, "[ %s ] dynamic memory", name);
207 /* we were unable to find this address anywhere */
208 sprintf(buf, "/* kernel dynamic memory */");
211 write_unlock_irqrestore(&tasklist_lock, flags);
217 asmlinkage void double_fault_c(struct pt_regs *fp)
219 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
221 trace_buffer_save(j);
225 oops_in_progress = 1;
226 #ifdef CONFIG_DEBUG_VERBOSE
227 printk(KERN_EMERG "Double Fault\n");
228 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
229 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
230 unsigned int cpu = smp_processor_id();
232 decode_address(buf, cpu_pda[cpu].retx);
233 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
234 (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
235 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
236 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
237 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
238 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
240 decode_address(buf, fp->retx);
241 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
245 dump_bfin_process(fp);
248 dump_bfin_trace_buffer();
251 panic("Double Fault - unrecoverable event");
255 static int kernel_mode_regs(struct pt_regs *regs)
257 return regs->ipend & 0xffc0;
260 asmlinkage void trap_c(struct pt_regs *fp)
262 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
265 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
266 unsigned int cpu = smp_processor_id();
268 const char *strerror = NULL;
271 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
273 trace_buffer_save(j);
274 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
275 last_seqstat = (u32)fp->seqstat;
278 /* Important - be very careful dereferncing pointers - will lead to
279 * double faults if the stack has become corrupt
282 /* trap_c() will be called for exceptions. During exceptions
283 * processing, the pc value should be set with retx value.
284 * With this change we can cleanup some code in signal.c- TODO
286 fp->orig_pc = fp->retx;
287 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
288 trapnr, fp->ipend, fp->pc, fp->retx); */
290 /* send the appropriate signal to the user program */
293 /* This table works in conjuction with the one in ./mach-common/entry.S
294 * Some exceptions are handled there (in assembly, in exception space)
295 * Some are handled here, (in C, in interrupt space)
296 * Some, like CPLB, are handled in both, where the normal path is
297 * handled in assembly/exception space, and the error path is handled
301 /* 0x00 - Linux Syscall, getting here is an error */
302 /* 0x01 - userspace gdb breakpoint, handled here */
304 info.si_code = TRAP_ILLTRAP;
306 CHK_DEBUGGER_TRAP_MAYBE();
307 /* Check if this is a breakpoint in kernel space */
308 if (kernel_mode_regs(fp))
312 /* 0x03 - User Defined, userspace stack overflow */
314 info.si_code = SEGV_STACKFLOW;
316 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
317 CHK_DEBUGGER_TRAP_MAYBE();
319 /* 0x02 - KGDB initial connection and break signal trap */
322 info.si_code = TRAP_ILLTRAP;
327 /* 0x04 - User Defined */
328 /* 0x05 - User Defined */
329 /* 0x06 - User Defined */
330 /* 0x07 - User Defined */
331 /* 0x08 - User Defined */
332 /* 0x09 - User Defined */
333 /* 0x0A - User Defined */
334 /* 0x0B - User Defined */
335 /* 0x0C - User Defined */
336 /* 0x0D - User Defined */
337 /* 0x0E - User Defined */
338 /* 0x0F - User Defined */
339 /* If we got here, it is most likely that someone was trying to use a
340 * custom exception handler, and it is not actually installed properly
342 case VEC_EXCPT04 ... VEC_EXCPT15:
343 info.si_code = ILL_ILLPARAOP;
345 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
346 CHK_DEBUGGER_TRAP_MAYBE();
348 /* 0x10 HW Single step, handled here */
350 info.si_code = TRAP_STEP;
352 CHK_DEBUGGER_TRAP_MAYBE();
353 /* Check if this is a single step in kernel space */
354 if (kernel_mode_regs(fp))
358 /* 0x11 - Trace Buffer Full, handled here */
360 info.si_code = TRAP_TRACEFLOW;
362 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
363 CHK_DEBUGGER_TRAP_MAYBE();
365 /* 0x12 - Reserved, Caught by default */
366 /* 0x13 - Reserved, Caught by default */
367 /* 0x14 - Reserved, Caught by default */
368 /* 0x15 - Reserved, Caught by default */
369 /* 0x16 - Reserved, Caught by default */
370 /* 0x17 - Reserved, Caught by default */
371 /* 0x18 - Reserved, Caught by default */
372 /* 0x19 - Reserved, Caught by default */
373 /* 0x1A - Reserved, Caught by default */
374 /* 0x1B - Reserved, Caught by default */
375 /* 0x1C - Reserved, Caught by default */
376 /* 0x1D - Reserved, Caught by default */
377 /* 0x1E - Reserved, Caught by default */
378 /* 0x1F - Reserved, Caught by default */
379 /* 0x20 - Reserved, Caught by default */
380 /* 0x21 - Undefined Instruction, handled here */
383 if (kernel_mode_regs(fp)) {
384 switch (report_bug(fp->pc, fp)) {
385 case BUG_TRAP_TYPE_NONE:
387 case BUG_TRAP_TYPE_WARN:
388 dump_bfin_trace_buffer();
391 case BUG_TRAP_TYPE_BUG:
392 /* call to panic() will dump trace, and it is
393 * off at this point, so it won't be clobbered
399 info.si_code = ILL_ILLOPC;
401 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
402 CHK_DEBUGGER_TRAP_MAYBE();
404 /* 0x22 - Illegal Instruction Combination, handled here */
406 info.si_code = ILL_ILLPARAOP;
408 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
409 CHK_DEBUGGER_TRAP_MAYBE();
411 /* 0x23 - Data CPLB protection violation, handled here */
413 info.si_code = ILL_CPLB_VI;
415 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
416 CHK_DEBUGGER_TRAP_MAYBE();
418 /* 0x24 - Data access misaligned, handled here */
420 info.si_code = BUS_ADRALN;
422 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
423 CHK_DEBUGGER_TRAP_MAYBE();
425 /* 0x25 - Unrecoverable Event, handled here */
427 info.si_code = ILL_ILLEXCPT;
429 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
430 CHK_DEBUGGER_TRAP_MAYBE();
432 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
433 error case is handled here */
435 info.si_code = BUS_ADRALN;
437 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
439 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
441 info.si_code = ILL_CPLB_MULHIT;
443 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
444 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
445 strerror = KERN_NOTICE "NULL pointer access\n";
448 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
449 CHK_DEBUGGER_TRAP_MAYBE();
451 /* 0x28 - Emulation Watchpoint, handled here */
453 info.si_code = TRAP_WATCHPT;
455 pr_debug(EXC_0x28(KERN_DEBUG));
456 CHK_DEBUGGER_TRAP_MAYBE();
457 /* Check if this is a watchpoint in kernel space */
458 if (kernel_mode_regs(fp))
463 /* 0x29 - Instruction fetch access error (535 only) */
464 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
465 info.si_code = BUS_OPFETCH;
467 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
468 CHK_DEBUGGER_TRAP_MAYBE();
471 /* 0x29 - Reserved, Caught by default */
473 /* 0x2A - Instruction fetch misaligned, handled here */
475 info.si_code = BUS_ADRALN;
477 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
478 CHK_DEBUGGER_TRAP_MAYBE();
480 /* 0x2B - Instruction CPLB protection violation, handled here */
482 info.si_code = ILL_CPLB_VI;
484 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
485 CHK_DEBUGGER_TRAP_MAYBE();
487 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
489 info.si_code = ILL_CPLB_MISS;
491 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
493 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
494 case VEC_CPLB_I_MHIT:
495 info.si_code = ILL_CPLB_MULHIT;
497 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
498 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
499 strerror = KERN_NOTICE "Jump to NULL address\n";
502 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
503 CHK_DEBUGGER_TRAP_MAYBE();
505 /* 0x2E - Illegal use of Supervisor Resource, handled here */
507 info.si_code = ILL_PRVOPC;
509 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
510 CHK_DEBUGGER_TRAP_MAYBE();
512 /* 0x2F - Reserved, Caught by default */
513 /* 0x30 - Reserved, Caught by default */
514 /* 0x31 - Reserved, Caught by default */
515 /* 0x32 - Reserved, Caught by default */
516 /* 0x33 - Reserved, Caught by default */
517 /* 0x34 - Reserved, Caught by default */
518 /* 0x35 - Reserved, Caught by default */
519 /* 0x36 - Reserved, Caught by default */
520 /* 0x37 - Reserved, Caught by default */
521 /* 0x38 - Reserved, Caught by default */
522 /* 0x39 - Reserved, Caught by default */
523 /* 0x3A - Reserved, Caught by default */
524 /* 0x3B - Reserved, Caught by default */
525 /* 0x3C - Reserved, Caught by default */
526 /* 0x3D - Reserved, Caught by default */
527 /* 0x3E - Reserved, Caught by default */
528 /* 0x3F - Reserved, Caught by default */
530 info.si_code = BUS_ADRALN;
532 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
533 /* System MMR Error */
534 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
535 info.si_code = BUS_ADRALN;
537 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
539 /* External Memory Addressing Error */
540 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
541 info.si_code = BUS_ADRERR;
543 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
545 /* Performance Monitor Overflow */
546 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
547 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
549 /* RAISE 5 instruction */
550 case (SEQSTAT_HWERRCAUSE_RAISE_5):
551 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
553 default: /* Reserved */
554 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
557 CHK_DEBUGGER_TRAP_MAYBE();
560 * We should be handling all known exception types above,
561 * if we get here we hit a reserved one, so panic
564 info.si_code = ILL_ILLPARAOP;
566 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
567 (fp->seqstat & SEQSTAT_EXCAUSE));
568 CHK_DEBUGGER_TRAP_MAYBE();
574 /* If the fault was caused by a kernel thread, or interrupt handler
575 * we will kernel panic, so the system reboots.
577 if (kernel_mode_regs(fp) || (current && !current->mm)) {
579 oops_in_progress = 1;
582 if (sig != SIGTRAP) {
584 verbose_printk(strerror);
586 dump_bfin_process(fp);
590 /* Print out the trace buffer if it makes sense */
591 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
592 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
593 verbose_printk(KERN_NOTICE "No trace since you do not have "
594 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
597 dump_bfin_trace_buffer();
599 if (oops_in_progress) {
600 /* Dump the current kernel stack */
601 verbose_printk(KERN_NOTICE "Kernel Stack\n");
602 show_stack(current, NULL);
604 #ifndef CONFIG_ACCESS_CHECK
605 verbose_printk(KERN_EMERG "Please turn on "
606 "CONFIG_ACCESS_CHECK\n");
608 panic("Kernel exception");
610 #ifdef CONFIG_DEBUG_VERBOSE
611 unsigned long *stack;
612 /* Dump the user space stack */
613 stack = (unsigned long *)rdusp();
614 verbose_printk(KERN_NOTICE "Userspace Stack\n");
615 show_stack(NULL, stack);
621 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
626 info.si_addr = (void __user *)fp->pc;
627 force_sig_info(sig, &info, current);
630 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
631 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
632 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
633 fp->pc = SAFE_USER_INSTRUCTION;
636 trace_buffer_restore(j);
639 /* Typical exception handling routines */
641 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
644 * Similar to get_user, do some address checking, then dereference
645 * Return true on sucess, false on bad address
647 static bool get_instruction(unsigned short *val, unsigned short *address)
649 unsigned long addr = (unsigned long)address;
651 /* Check for odd addresses */
655 /* MMR region will never have instructions */
656 if (addr >= SYSMMR_BASE)
659 switch (bfin_mem_access_type(addr, 2)) {
660 case BFIN_MEM_ACCESS_CORE:
661 case BFIN_MEM_ACCESS_CORE_ONLY:
664 case BFIN_MEM_ACCESS_DMA:
665 dma_memcpy(val, address, 2);
667 case BFIN_MEM_ACCESS_ITEST:
668 isram_memcpy(val, address, 2);
670 default: /* invalid access */
676 * decode the instruction if we are printing out the trace, as it
677 * makes things easier to follow, without running it through objdump
678 * These are the normal instructions which cause change of flow, which
679 * would be at the source of the trace buffer
681 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
682 static void decode_instruction(unsigned short *address)
684 unsigned short opcode;
686 if (get_instruction(&opcode, address)) {
687 if (opcode == 0x0010)
688 verbose_printk("RTS");
689 else if (opcode == 0x0011)
690 verbose_printk("RTI");
691 else if (opcode == 0x0012)
692 verbose_printk("RTX");
693 else if (opcode == 0x0013)
694 verbose_printk("RTN");
695 else if (opcode == 0x0014)
696 verbose_printk("RTE");
697 else if (opcode == 0x0025)
698 verbose_printk("EMUEXCPT");
699 else if (opcode == 0x0040 && opcode <= 0x0047)
700 verbose_printk("STI R%i", opcode & 7);
701 else if (opcode >= 0x0050 && opcode <= 0x0057)
702 verbose_printk("JUMP (P%i)", opcode & 7);
703 else if (opcode >= 0x0060 && opcode <= 0x0067)
704 verbose_printk("CALL (P%i)", opcode & 7);
705 else if (opcode >= 0x0070 && opcode <= 0x0077)
706 verbose_printk("CALL (PC+P%i)", opcode & 7);
707 else if (opcode >= 0x0080 && opcode <= 0x0087)
708 verbose_printk("JUMP (PC+P%i)", opcode & 7);
709 else if (opcode >= 0x0090 && opcode <= 0x009F)
710 verbose_printk("RAISE 0x%x", opcode & 0xF);
711 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
712 verbose_printk("EXCPT 0x%x", opcode & 0xF);
713 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
714 verbose_printk("IF !CC JUMP");
715 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
716 verbose_printk("IF CC JUMP");
717 else if (opcode >= 0x2000 && opcode <= 0x2fff)
718 verbose_printk("JUMP.S");
719 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
720 verbose_printk("LSETUP");
721 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
722 verbose_printk("JUMP.L");
723 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
724 verbose_printk("CALL pcrel");
726 verbose_printk("0x%04x", opcode);
732 void dump_bfin_trace_buffer(void)
734 #ifdef CONFIG_DEBUG_VERBOSE
735 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
738 unsigned short *addr;
739 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
743 trace_buffer_save(tflags);
745 printk(KERN_NOTICE "Hardware Trace:\n");
747 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
748 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
751 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
752 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
753 decode_address(buf, (unsigned long)bfin_read_TBUF());
754 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
755 addr = (unsigned short *)bfin_read_TBUF();
756 decode_address(buf, (unsigned long)addr);
757 printk(KERN_NOTICE " Source : %s ", buf);
758 decode_instruction(addr);
763 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
764 if (trace_buff_offset)
765 index = trace_buff_offset / 4;
769 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
771 decode_address(buf, software_trace_buff[index]);
772 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
776 decode_address(buf, software_trace_buff[index]);
777 printk(KERN_NOTICE " Source : %s ", buf);
778 decode_instruction((unsigned short *)software_trace_buff[index]);
788 trace_buffer_restore(tflags);
792 EXPORT_SYMBOL(dump_bfin_trace_buffer);
795 int is_valid_bugaddr(unsigned long addr)
797 unsigned short opcode;
799 if (!get_instruction(&opcode, (unsigned short *)addr))
802 return opcode == BFIN_BUG_OPCODE;
807 * Checks to see if the address pointed to is either a
808 * 16-bit CALL instruction, or a 32-bit CALL instruction
810 static bool is_bfin_call(unsigned short *addr)
812 unsigned short opcode = 0, *ins_addr;
813 ins_addr = (unsigned short *)addr;
815 if (!get_instruction(&opcode, ins_addr))
818 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
819 (opcode >= 0x0070 && opcode <= 0x0077))
823 if (!get_instruction(&opcode, ins_addr))
826 if (opcode >= 0xE300 && opcode <= 0xE3FF)
833 void show_stack(struct task_struct *task, unsigned long *stack)
836 unsigned int *addr, *endstack, *fp = 0, *frame;
837 unsigned short *ins_addr;
839 unsigned int i, j, ret_addr, frame_no = 0;
842 * If we have been passed a specific stack, use that one otherwise
843 * if we have been passed a task structure, use that, otherwise
844 * use the stack of where the variable "stack" exists
849 /* We know this is a kernel stack, so this is the start/end */
850 stack = (unsigned long *)task->thread.ksp;
851 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
853 /* print out the existing stack info */
854 stack = (unsigned long *)&stack;
855 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
858 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
860 printk(KERN_NOTICE "Stack info:\n");
861 decode_address(buf, (unsigned int)stack);
862 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
864 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
865 printk(KERN_NOTICE "Invalid stack pointer\n");
869 /* First thing is to look for a frame pointer */
870 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
873 ins_addr = (unsigned short *)*addr;
875 if (is_bfin_call(ins_addr))
879 /* Let's check to see if it is a frame pointer */
880 while (fp >= (addr - 1) && fp < endstack
881 && fp && ((unsigned int) fp & 0x3) == 0)
882 fp = (unsigned int *)*fp;
883 if (fp == 0 || fp == endstack) {
892 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
897 * Now that we think we know where things are, we
898 * walk the stack again, this time printing things out
899 * incase there is no frame pointer, we still look for
900 * valid return addresses
903 /* First time print out data, next time, print out symbols */
904 for (j = 0; j <= 1; j++) {
906 printk(KERN_NOTICE "Return addresses in stack:\n");
908 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
913 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
914 addr < endstack; addr++, i++) {
917 if (!j && i % 8 == 0)
918 printk(KERN_NOTICE "%p:",addr);
920 /* if it is an odd address, or zero, just skip it */
921 if (*addr & 0x1 || !*addr)
924 ins_addr = (unsigned short *)*addr;
926 /* Go back one instruction, and see if it is a CALL */
928 ret_addr = is_bfin_call(ins_addr);
930 if (!j && stack == (unsigned long *)addr)
931 printk("[%08x]", *addr);
934 decode_address(buf, (unsigned int)*addr);
936 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
939 printk(KERN_NOTICE " address : %s\n", buf);
941 printk("<%08x>", *addr);
942 else if (fp == addr) {
946 printk("(%08x)", *addr);
948 fp = (unsigned int *)*addr;
952 printk(" %08x ", *addr);
959 EXPORT_SYMBOL(show_stack);
961 void dump_stack(void)
964 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
967 trace_buffer_save(tflags);
968 dump_bfin_trace_buffer();
969 show_stack(current, &stack);
970 trace_buffer_restore(tflags);
972 EXPORT_SYMBOL(dump_stack);
974 void dump_bfin_process(struct pt_regs *fp)
976 #ifdef CONFIG_DEBUG_VERBOSE
977 /* We should be able to look at fp->ipend, but we don't push it on the
978 * stack all the time, so do this until we fix that */
979 unsigned int context = bfin_read_IPEND();
981 if (oops_in_progress)
982 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
984 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
985 verbose_printk(KERN_NOTICE "HW Error context\n");
986 else if (context & 0x0020)
987 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
988 else if (context & 0x3FC0)
989 verbose_printk(KERN_NOTICE "Interrupt context\n");
990 else if (context & 0x4000)
991 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
992 else if (context & 0x8000)
993 verbose_printk(KERN_NOTICE "Kernel process context\n");
995 /* Because we are crashing, and pointers could be bad, we check things
996 * pretty closely before we use them
998 if ((unsigned long)current >= FIXED_CODE_START &&
999 !((unsigned long)current & 0x3) && current->pid) {
1000 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
1001 if (current->comm >= (char *)FIXED_CODE_START)
1002 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
1003 current->comm, current->pid);
1005 verbose_printk(KERN_NOTICE "COMM= invalid\n");
1007 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
1008 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
1009 verbose_printk(KERN_NOTICE
1010 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
1011 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
1012 (void *)current->mm->start_code,
1013 (void *)current->mm->end_code,
1014 (void *)current->mm->start_data,
1015 (void *)current->mm->end_data,
1016 (void *)current->mm->end_data,
1017 (void *)current->mm->brk,
1018 (void *)current->mm->start_stack);
1020 verbose_printk(KERN_NOTICE "invalid mm\n");
1022 verbose_printk(KERN_NOTICE
1023 "No Valid process in current context\n");
1027 void dump_bfin_mem(struct pt_regs *fp)
1029 #ifdef CONFIG_DEBUG_VERBOSE
1030 unsigned short *addr, *erraddr, val = 0, err = 0;
1031 char sti = 0, buf[6];
1033 erraddr = (void *)fp->pc;
1035 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
1037 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1038 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1040 if (!((unsigned long)addr & 0xF))
1041 verbose_printk(KERN_NOTICE "0x%p: ", addr);
1043 if (!get_instruction(&val, addr)) {
1045 sprintf(buf, "????");
1047 sprintf(buf, "%04x", val);
1049 if (addr == erraddr) {
1050 verbose_printk("[%s]", buf);
1053 verbose_printk(" %s ", buf);
1055 /* Do any previous instructions turn on interrupts? */
1056 if (addr <= erraddr && /* in the past */
1057 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1058 val == 0x017b)) /* [SP++] = RETI */
1062 verbose_printk("\n");
1064 /* Hardware error interrupts can be deferred */
1065 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1067 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
1068 #ifndef CONFIG_DEBUG_HWERR
1069 verbose_printk(KERN_NOTICE
1070 "The remaining message may be meaningless\n"
1071 "You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
1073 /* If we are handling only one peripheral interrupt
1074 * and current mm and pid are valid, and the last error
1075 * was in that user space process's text area
1076 * print it out - because that is where the problem exists
1078 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1079 (current->pid && current->mm)) {
1080 /* And the last RETI points to the current userspace context */
1081 if ((fp + 1)->pc >= current->mm->start_code &&
1082 (fp + 1)->pc <= current->mm->end_code) {
1083 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1084 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1086 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1094 void show_regs(struct pt_regs *fp)
1096 #ifdef CONFIG_DEBUG_VERBOSE
1098 struct irqaction *action;
1100 unsigned long flags = 0;
1101 unsigned int cpu = smp_processor_id();
1102 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
1104 verbose_printk(KERN_NOTICE "\n");
1105 if (CPUID != bfin_cpuid())
1106 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1107 "but running on:0x%04x (Rev %d)\n",
1108 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1110 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1111 CPU, bfin_compiled_revid());
1113 if (bfin_compiled_revid() != bfin_revid())
1114 verbose_printk("(Detected 0.%d)", bfin_revid());
1116 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1117 get_cclk()/1000000, get_sclk()/1000000,
1125 verbose_printk(KERN_NOTICE "%s", linux_banner);
1127 verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
1128 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
1129 (long)fp->seqstat, fp->ipend, cpu_pda[smp_processor_id()].ex_imask, fp->syscfg);
1130 if (fp->ipend & EVT_IRPTEN)
1131 verbose_printk(KERN_NOTICE " Global Interrupts Disabled (IPEND[4])\n");
1132 if (!(cpu_pda[smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
1133 EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
1134 verbose_printk(KERN_NOTICE " Peripheral interrupts masked off\n");
1135 if (!(cpu_pda[smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
1136 verbose_printk(KERN_NOTICE " Kernel interrupts masked off\n");
1137 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
1138 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1139 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1141 /* If the error was from the EBIU, print it out */
1142 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
1143 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
1144 bfin_read_EBIU_ERRMST());
1145 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
1146 bfin_read_EBIU_ERRADD());
1150 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1151 fp->seqstat & SEQSTAT_EXCAUSE);
1152 for (i = 2; i <= 15 ; i++) {
1153 if (fp->ipend & (1 << i)) {
1155 decode_address(buf, bfin_read32(EVT0 + 4*i));
1156 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1158 verbose_printk(KERN_NOTICE " interrupts disabled\n");
1162 /* if no interrupts are going off, don't print this out */
1163 if (fp->ipend & ~0x3F) {
1164 for (i = 0; i < (NR_IRQS - 1); i++) {
1166 spin_lock_irqsave(&irq_desc[i].lock, flags);
1168 action = irq_desc[i].action;
1172 decode_address(buf, (unsigned int)action->handler);
1173 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1174 for (action = action->next; action; action = action->next) {
1175 decode_address(buf, (unsigned int)action->handler);
1176 verbose_printk(", %s", buf);
1178 verbose_printk("\n");
1181 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1185 decode_address(buf, fp->rete);
1186 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
1187 decode_address(buf, fp->retn);
1188 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
1189 decode_address(buf, fp->retx);
1190 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
1191 decode_address(buf, fp->rets);
1192 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
1193 decode_address(buf, fp->pc);
1194 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
1196 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1197 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1198 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
1199 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1200 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
1201 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1204 verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
1205 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1206 fp->r0, fp->r1, fp->r2, fp->r3);
1207 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1208 fp->r4, fp->r5, fp->r6, fp->r7);
1209 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1210 fp->p0, fp->p1, fp->p2, fp->p3);
1211 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1212 fp->p4, fp->p5, fp->fp, (long)fp);
1213 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1214 fp->lb0, fp->lt0, fp->lc0);
1215 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1216 fp->lb1, fp->lt1, fp->lc1);
1217 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1218 fp->b0, fp->l0, fp->m0, fp->i0);
1219 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1220 fp->b1, fp->l1, fp->m1, fp->i1);
1221 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1222 fp->b2, fp->l2, fp->m2, fp->i2);
1223 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1224 fp->b3, fp->l3, fp->m3, fp->i3);
1225 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1226 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1228 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1229 rdusp(), fp->astat);
1231 verbose_printk(KERN_NOTICE "\n");
1235 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1236 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1239 static DEFINE_SPINLOCK(bfin_spinlock_lock);
1241 asmlinkage int sys_bfin_spinlock(int *p)
1245 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1246 ret = get_user(tmp, p);
1247 if (likely(ret == 0)) {
1253 spin_unlock(&bfin_spinlock_lock);
1257 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1259 void (*curr_handler)(void);
1261 if (exception > 0x3F)
1264 curr_handler = ex_table[exception];
1266 if (curr_handler != ex_replaceable)
1269 ex_table[exception] = handler;
1273 EXPORT_SYMBOL(bfin_request_exception);
1275 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1277 void (*curr_handler)(void);
1279 if (exception > 0x3F)
1282 curr_handler = ex_table[exception];
1284 if (curr_handler != handler)
1287 ex_table[exception] = ex_replaceable;
1291 EXPORT_SYMBOL(bfin_free_exception);
1293 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1295 switch (cplb_panic) {
1296 case CPLB_NO_UNLOCKED:
1297 printk(KERN_EMERG "All CPLBs are locked\n");
1299 case CPLB_PROT_VIOL:
1301 case CPLB_NO_ADDR_MATCH:
1303 case CPLB_UNKNOWN_ERR:
1304 printk(KERN_EMERG "Unknown CPLB Exception\n");
1308 oops_in_progress = 1;
1310 dump_bfin_process(fp);
1314 panic("Unrecoverable event");