2 * File: arch/blackfin/kernel/traps.c
4 * Author: Hamish Macdonald
7 * Description: uses S/W interrupt 15 for the system calls
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/uaccess.h>
31 #include <linux/interrupt.h>
32 #include <linux/module.h>
33 #include <linux/kallsyms.h>
35 #include <linux/rbtree.h>
36 #include <asm/traps.h>
37 #include <asm/cacheflush.h>
39 #include <asm/blackfin.h>
40 #include <asm/irq_handler.h>
41 #include <linux/irq.h>
42 #include <asm/trace.h>
43 #include <asm/fixed_code.h>
46 # include <linux/kgdb.h>
48 # define CHK_DEBUGGER_TRAP() \
50 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
52 # define CHK_DEBUGGER_TRAP_MAYBE() \
55 CHK_DEBUGGER_TRAP(); \
58 # define CHK_DEBUGGER_TRAP() do { } while (0)
59 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
63 #ifdef CONFIG_DEBUG_VERBOSE
64 #define verbose_printk(fmt, arg...) \
67 #define verbose_printk(fmt, arg...) \
68 ({ if (0) printk(fmt, ##arg); 0; })
71 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
73 #ifdef CONFIG_DEBUG_MMRS_MODULE
74 EXPORT_SYMBOL(last_seqstat);
78 /* Initiate the event table handler */
79 void __init trap_init(void)
82 bfin_write_EVT3(trap);
86 static void decode_address(char *buf, unsigned long address)
88 #ifdef CONFIG_DEBUG_VERBOSE
89 struct task_struct *p;
91 unsigned long flags, offset;
92 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
95 #ifdef CONFIG_KALLSYMS
96 unsigned long symsize;
102 /* look up the address and see if we are in kernel space */
103 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
106 /* yeah! kernel space! */
108 modname = delim = "";
109 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
110 (void *)address, delim, modname, delim, symname,
111 (unsigned long)offset);
117 /* Problem in fixed code section? */
118 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
119 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
123 /* Problem somewhere before the kernel start address */
124 if (address < CONFIG_BOOT_LOAD) {
125 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
129 /* looks like we're off in user-land, so let's walk all the
130 * mappings of all our processes and see if we can't be a whee
133 write_lock_irqsave(&tasklist_lock, flags);
134 for_each_process(p) {
135 mm = (in_atomic ? p->mm : get_task_mm(p));
139 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
140 struct vm_area_struct *vma;
142 vma = rb_entry(n, struct vm_area_struct, vm_rb);
144 if (address >= vma->vm_start && address < vma->vm_end) {
146 char *name = p->comm;
147 struct file *file = vma->vm_file;
150 char *d_name = d_path(&file->f_path, _tmpbuf,
156 /* FLAT does not have its text aligned to the start of
157 * the map while FDPIC ELF does ...
160 /* before we can check flat/fdpic, we need to
161 * make sure current is valid
163 if ((unsigned long)current >= FIXED_CODE_START &&
164 !((unsigned long)current & 0x3)) {
166 (address > current->mm->start_code) &&
167 (address < current->mm->end_code))
168 offset = address - current->mm->start_code;
170 offset = (address - vma->vm_start) +
171 (vma->vm_pgoff << PAGE_SHIFT);
173 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
174 (void *)address, name, offset);
176 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
177 (void *)address, name,
178 vma->vm_start, vma->vm_end);
184 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
193 /* we were unable to find this address anywhere */
194 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
197 write_unlock_irqrestore(&tasklist_lock, flags);
203 asmlinkage void double_fault_c(struct pt_regs *fp)
205 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
207 trace_buffer_save(j);
211 oops_in_progress = 1;
212 #ifdef CONFIG_DEBUG_VERBOSE
213 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
214 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
215 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
216 unsigned int cpu = smp_processor_id();
218 decode_address(buf, cpu_pda[cpu].retx);
219 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
220 (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
221 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
222 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
223 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
224 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
226 decode_address(buf, fp->retx);
227 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
231 dump_bfin_process(fp);
234 dump_bfin_trace_buffer();
237 panic("Double Fault - unrecoverable event");
241 asmlinkage void trap_c(struct pt_regs *fp)
243 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
246 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
247 unsigned int cpu = smp_processor_id();
251 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
253 trace_buffer_save(j);
254 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
255 last_seqstat = (u32)fp->seqstat;
258 /* Important - be very careful dereferncing pointers - will lead to
259 * double faults if the stack has become corrupt
262 /* If the fault was caused by a kernel thread, or interrupt handler
263 * we will kernel panic, so the system reboots.
264 * If KGDB is enabled, don't set this for kernel breakpoints
267 /* TODO: check to see if we are in some sort of deferred HWERR
268 * that we should be able to recover from, not kernel panic
270 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
272 && (trapnr != VEC_EXCPT02)
276 oops_in_progress = 1;
277 } else if (current) {
278 if (current->mm == NULL) {
280 oops_in_progress = 1;
284 /* trap_c() will be called for exceptions. During exceptions
285 * processing, the pc value should be set with retx value.
286 * With this change we can cleanup some code in signal.c- TODO
288 fp->orig_pc = fp->retx;
289 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
290 trapnr, fp->ipend, fp->pc, fp->retx); */
292 /* send the appropriate signal to the user program */
295 /* This table works in conjuction with the one in ./mach-common/entry.S
296 * Some exceptions are handled there (in assembly, in exception space)
297 * Some are handled here, (in C, in interrupt space)
298 * Some, like CPLB, are handled in both, where the normal path is
299 * handled in assembly/exception space, and the error path is handled
303 /* 0x00 - Linux Syscall, getting here is an error */
304 /* 0x01 - userspace gdb breakpoint, handled here */
306 info.si_code = TRAP_ILLTRAP;
308 CHK_DEBUGGER_TRAP_MAYBE();
309 /* Check if this is a breakpoint in kernel space */
310 if (fp->ipend & 0xffc0)
314 /* 0x03 - User Defined, userspace stack overflow */
316 info.si_code = SEGV_STACKFLOW;
318 verbose_printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
319 CHK_DEBUGGER_TRAP_MAYBE();
321 /* 0x02 - KGDB initial connection and break signal trap */
324 info.si_code = TRAP_ILLTRAP;
329 /* 0x04 - User Defined */
330 /* 0x05 - User Defined */
331 /* 0x06 - User Defined */
332 /* 0x07 - User Defined */
333 /* 0x08 - User Defined */
334 /* 0x09 - User Defined */
335 /* 0x0A - User Defined */
336 /* 0x0B - User Defined */
337 /* 0x0C - User Defined */
338 /* 0x0D - User Defined */
339 /* 0x0E - User Defined */
340 /* 0x0F - User Defined */
341 /* If we got here, it is most likely that someone was trying to use a
342 * custom exception handler, and it is not actually installed properly
344 case VEC_EXCPT04 ... VEC_EXCPT15:
345 info.si_code = ILL_ILLPARAOP;
347 verbose_printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
348 CHK_DEBUGGER_TRAP_MAYBE();
350 /* 0x10 HW Single step, handled here */
352 info.si_code = TRAP_STEP;
354 CHK_DEBUGGER_TRAP_MAYBE();
355 /* Check if this is a single step in kernel space */
356 if (fp->ipend & 0xffc0)
360 /* 0x11 - Trace Buffer Full, handled here */
362 info.si_code = TRAP_TRACEFLOW;
364 verbose_printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
365 CHK_DEBUGGER_TRAP_MAYBE();
367 /* 0x12 - Reserved, Caught by default */
368 /* 0x13 - Reserved, Caught by default */
369 /* 0x14 - Reserved, Caught by default */
370 /* 0x15 - Reserved, Caught by default */
371 /* 0x16 - Reserved, Caught by default */
372 /* 0x17 - Reserved, Caught by default */
373 /* 0x18 - Reserved, Caught by default */
374 /* 0x19 - Reserved, Caught by default */
375 /* 0x1A - Reserved, Caught by default */
376 /* 0x1B - Reserved, Caught by default */
377 /* 0x1C - Reserved, Caught by default */
378 /* 0x1D - Reserved, Caught by default */
379 /* 0x1E - Reserved, Caught by default */
380 /* 0x1F - Reserved, Caught by default */
381 /* 0x20 - Reserved, Caught by default */
382 /* 0x21 - Undefined Instruction, handled here */
384 info.si_code = ILL_ILLOPC;
386 verbose_printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
387 CHK_DEBUGGER_TRAP_MAYBE();
389 /* 0x22 - Illegal Instruction Combination, handled here */
391 info.si_code = ILL_ILLPARAOP;
393 verbose_printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
394 CHK_DEBUGGER_TRAP_MAYBE();
396 /* 0x23 - Data CPLB protection violation, handled here */
398 info.si_code = ILL_CPLB_VI;
400 verbose_printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
401 CHK_DEBUGGER_TRAP_MAYBE();
403 /* 0x24 - Data access misaligned, handled here */
405 info.si_code = BUS_ADRALN;
407 verbose_printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
408 CHK_DEBUGGER_TRAP_MAYBE();
410 /* 0x25 - Unrecoverable Event, handled here */
412 info.si_code = ILL_ILLEXCPT;
414 verbose_printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
415 CHK_DEBUGGER_TRAP_MAYBE();
417 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
418 error case is handled here */
420 info.si_code = BUS_ADRALN;
422 verbose_printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
424 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
426 info.si_code = ILL_CPLB_MULHIT;
428 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
429 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
430 verbose_printk(KERN_NOTICE "NULL pointer access\n");
433 verbose_printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
434 CHK_DEBUGGER_TRAP_MAYBE();
436 /* 0x28 - Emulation Watchpoint, handled here */
438 info.si_code = TRAP_WATCHPT;
440 pr_debug(EXC_0x28(KERN_DEBUG));
441 CHK_DEBUGGER_TRAP_MAYBE();
442 /* Check if this is a watchpoint in kernel space */
443 if (fp->ipend & 0xffc0)
448 /* 0x29 - Instruction fetch access error (535 only) */
449 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
450 info.si_code = BUS_OPFETCH;
452 verbose_printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
453 CHK_DEBUGGER_TRAP_MAYBE();
456 /* 0x29 - Reserved, Caught by default */
458 /* 0x2A - Instruction fetch misaligned, handled here */
460 info.si_code = BUS_ADRALN;
462 verbose_printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
463 CHK_DEBUGGER_TRAP_MAYBE();
465 /* 0x2B - Instruction CPLB protection violation, handled here */
467 info.si_code = ILL_CPLB_VI;
469 verbose_printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
470 CHK_DEBUGGER_TRAP_MAYBE();
472 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
474 info.si_code = ILL_CPLB_MISS;
476 verbose_printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
478 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
479 case VEC_CPLB_I_MHIT:
480 info.si_code = ILL_CPLB_MULHIT;
482 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
483 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
484 verbose_printk(KERN_NOTICE "Jump to NULL address\n");
487 verbose_printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
488 CHK_DEBUGGER_TRAP_MAYBE();
490 /* 0x2E - Illegal use of Supervisor Resource, handled here */
492 info.si_code = ILL_PRVOPC;
494 verbose_printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
495 CHK_DEBUGGER_TRAP_MAYBE();
497 /* 0x2F - Reserved, Caught by default */
498 /* 0x30 - Reserved, Caught by default */
499 /* 0x31 - Reserved, Caught by default */
500 /* 0x32 - Reserved, Caught by default */
501 /* 0x33 - Reserved, Caught by default */
502 /* 0x34 - Reserved, Caught by default */
503 /* 0x35 - Reserved, Caught by default */
504 /* 0x36 - Reserved, Caught by default */
505 /* 0x37 - Reserved, Caught by default */
506 /* 0x38 - Reserved, Caught by default */
507 /* 0x39 - Reserved, Caught by default */
508 /* 0x3A - Reserved, Caught by default */
509 /* 0x3B - Reserved, Caught by default */
510 /* 0x3C - Reserved, Caught by default */
511 /* 0x3D - Reserved, Caught by default */
512 /* 0x3E - Reserved, Caught by default */
513 /* 0x3F - Reserved, Caught by default */
515 info.si_code = BUS_ADRALN;
517 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
518 /* System MMR Error */
519 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
520 info.si_code = BUS_ADRALN;
522 verbose_printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
524 /* External Memory Addressing Error */
525 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
526 info.si_code = BUS_ADRERR;
528 verbose_printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
530 /* Performance Monitor Overflow */
531 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
532 verbose_printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
534 /* RAISE 5 instruction */
535 case (SEQSTAT_HWERRCAUSE_RAISE_5):
536 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
538 default: /* Reserved */
539 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
542 CHK_DEBUGGER_TRAP_MAYBE();
545 * We should be handling all known exception types above,
546 * if we get here we hit a reserved one, so panic
549 oops_in_progress = 1;
550 info.si_code = ILL_ILLPARAOP;
552 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
553 (fp->seqstat & SEQSTAT_EXCAUSE));
554 CHK_DEBUGGER_TRAP_MAYBE();
560 if (sig != SIGTRAP) {
561 dump_bfin_process(fp);
565 /* Print out the trace buffer if it makes sense */
566 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
567 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
568 verbose_printk(KERN_NOTICE "No trace since you do not have "
569 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
573 dump_bfin_trace_buffer();
575 if (oops_in_progress) {
576 /* Dump the current kernel stack */
577 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
578 show_stack(current, NULL);
580 #ifndef CONFIG_ACCESS_CHECK
581 verbose_printk(KERN_EMERG "Please turn on "
582 "CONFIG_ACCESS_CHECK\n");
584 panic("Kernel exception");
586 #ifdef CONFIG_DEBUG_VERBOSE
587 unsigned long *stack;
588 /* Dump the user space stack */
589 stack = (unsigned long *)rdusp();
590 verbose_printk(KERN_NOTICE "Userspace Stack\n");
591 show_stack(NULL, stack);
597 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
602 info.si_addr = (void __user *)fp->pc;
603 force_sig_info(sig, &info, current);
606 if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
607 fp->pc = SAFE_USER_INSTRUCTION;
609 trace_buffer_restore(j);
613 /* Typical exception handling routines */
615 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
618 * Similar to get_user, do some address checking, then dereference
619 * Return true on sucess, false on bad address
621 static bool get_instruction(unsigned short *val, unsigned short *address)
626 addr = (unsigned long)address;
628 /* Check for odd addresses */
632 /* Check that things do not wrap around */
633 if (addr > (addr + 2))
637 * Since we are in exception context, we need to do a little address checking
638 * We need to make sure we are only accessing valid memory, and
639 * we don't read something in the async space that can hang forever
641 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
643 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
645 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
646 #if L1_DATA_A_LENGTH != 0
647 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
649 #if L1_DATA_B_LENGTH != 0
650 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
652 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
653 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
654 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
655 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
656 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
657 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
658 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
659 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
660 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
665 #if L1_CODE_LENGTH != 0
666 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
667 isram_memcpy(val, address, 2);
677 * decode the instruction if we are printing out the trace, as it
678 * makes things easier to follow, without running it through objdump
679 * These are the normal instructions which cause change of flow, which
680 * would be at the source of the trace buffer
682 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
683 static void decode_instruction(unsigned short *address)
685 unsigned short opcode;
687 if (get_instruction(&opcode, address)) {
688 if (opcode == 0x0010)
689 verbose_printk("RTS");
690 else if (opcode == 0x0011)
691 verbose_printk("RTI");
692 else if (opcode == 0x0012)
693 verbose_printk("RTX");
694 else if (opcode == 0x0013)
695 verbose_printk("RTN");
696 else if (opcode == 0x0014)
697 verbose_printk("RTE");
698 else if (opcode == 0x0025)
699 verbose_printk("EMUEXCPT");
700 else if (opcode == 0x0040 && opcode <= 0x0047)
701 verbose_printk("STI R%i", opcode & 7);
702 else if (opcode >= 0x0050 && opcode <= 0x0057)
703 verbose_printk("JUMP (P%i)", opcode & 7);
704 else if (opcode >= 0x0060 && opcode <= 0x0067)
705 verbose_printk("CALL (P%i)", opcode & 7);
706 else if (opcode >= 0x0070 && opcode <= 0x0077)
707 verbose_printk("CALL (PC+P%i)", opcode & 7);
708 else if (opcode >= 0x0080 && opcode <= 0x0087)
709 verbose_printk("JUMP (PC+P%i)", opcode & 7);
710 else if (opcode >= 0x0090 && opcode <= 0x009F)
711 verbose_printk("RAISE 0x%x", opcode & 0xF);
712 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
713 verbose_printk("EXCPT 0x%x", opcode & 0xF);
714 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
715 verbose_printk("IF !CC JUMP");
716 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
717 verbose_printk("IF CC JUMP");
718 else if (opcode >= 0x2000 && opcode <= 0x2fff)
719 verbose_printk("JUMP.S");
720 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
721 verbose_printk("LSETUP");
722 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
723 verbose_printk("JUMP.L");
724 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
725 verbose_printk("CALL pcrel");
727 verbose_printk("0x%04x", opcode);
733 void dump_bfin_trace_buffer(void)
735 #ifdef CONFIG_DEBUG_VERBOSE
736 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
739 unsigned short *addr;
740 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
744 trace_buffer_save(tflags);
746 printk(KERN_NOTICE "Hardware Trace:\n");
748 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
749 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
752 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
753 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
754 decode_address(buf, (unsigned long)bfin_read_TBUF());
755 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
756 addr = (unsigned short *)bfin_read_TBUF();
757 decode_address(buf, (unsigned long)addr);
758 printk(KERN_NOTICE " Source : %s ", buf);
759 decode_instruction(addr);
764 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
765 if (trace_buff_offset)
766 index = trace_buff_offset / 4;
770 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
772 decode_address(buf, software_trace_buff[index]);
773 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
777 decode_address(buf, software_trace_buff[index]);
778 printk(KERN_NOTICE " Source : %s ", buf);
779 decode_instruction((unsigned short *)software_trace_buff[index]);
789 trace_buffer_restore(tflags);
793 EXPORT_SYMBOL(dump_bfin_trace_buffer);
796 * Checks to see if the address pointed to is either a
797 * 16-bit CALL instruction, or a 32-bit CALL instruction
799 static bool is_bfin_call(unsigned short *addr)
801 unsigned short opcode = 0, *ins_addr;
802 ins_addr = (unsigned short *)addr;
804 if (!get_instruction(&opcode, ins_addr))
807 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
808 (opcode >= 0x0070 && opcode <= 0x0077))
812 if (!get_instruction(&opcode, ins_addr))
815 if (opcode >= 0xE300 && opcode <= 0xE3FF)
822 void show_stack(struct task_struct *task, unsigned long *stack)
825 unsigned int *addr, *endstack, *fp = 0, *frame;
826 unsigned short *ins_addr;
828 unsigned int i, j, ret_addr, frame_no = 0;
831 * If we have been passed a specific stack, use that one otherwise
832 * if we have been passed a task structure, use that, otherwise
833 * use the stack of where the variable "stack" exists
838 /* We know this is a kernel stack, so this is the start/end */
839 stack = (unsigned long *)task->thread.ksp;
840 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
842 /* print out the existing stack info */
843 stack = (unsigned long *)&stack;
844 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
847 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
849 printk(KERN_NOTICE "Stack info:\n");
850 decode_address(buf, (unsigned int)stack);
851 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
853 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
854 printk(KERN_NOTICE "Invalid stack pointer\n");
858 /* First thing is to look for a frame pointer */
859 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
862 ins_addr = (unsigned short *)*addr;
864 if (is_bfin_call(ins_addr))
868 /* Let's check to see if it is a frame pointer */
869 while (fp >= (addr - 1) && fp < endstack
870 && fp && ((unsigned int) fp & 0x3) == 0)
871 fp = (unsigned int *)*fp;
872 if (fp == 0 || fp == endstack) {
881 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
886 * Now that we think we know where things are, we
887 * walk the stack again, this time printing things out
888 * incase there is no frame pointer, we still look for
889 * valid return addresses
892 /* First time print out data, next time, print out symbols */
893 for (j = 0; j <= 1; j++) {
895 printk(KERN_NOTICE "Return addresses in stack:\n");
897 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
902 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
903 addr <= endstack; addr++, i++) {
906 if (!j && i % 8 == 0)
907 printk("\n" KERN_NOTICE "%p:",addr);
909 /* if it is an odd address, or zero, just skip it */
910 if (*addr & 0x1 || !*addr)
913 ins_addr = (unsigned short *)*addr;
915 /* Go back one instruction, and see if it is a CALL */
917 ret_addr = is_bfin_call(ins_addr);
919 if (!j && stack == (unsigned long *)addr)
920 printk("[%08x]", *addr);
923 decode_address(buf, (unsigned int)*addr);
925 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
928 printk(KERN_NOTICE " address : %s\n", buf);
930 printk("<%08x>", *addr);
931 else if (fp == addr) {
935 printk("(%08x)", *addr);
937 fp = (unsigned int *)*addr;
941 printk(" %08x ", *addr);
949 void dump_stack(void)
952 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
955 trace_buffer_save(tflags);
956 dump_bfin_trace_buffer();
957 show_stack(current, &stack);
958 trace_buffer_restore(tflags);
960 EXPORT_SYMBOL(dump_stack);
962 void dump_bfin_process(struct pt_regs *fp)
964 #ifdef CONFIG_DEBUG_VERBOSE
965 /* We should be able to look at fp->ipend, but we don't push it on the
966 * stack all the time, so do this until we fix that */
967 unsigned int context = bfin_read_IPEND();
969 if (oops_in_progress)
970 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
972 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
973 verbose_printk(KERN_NOTICE "HW Error context\n");
974 else if (context & 0x0020)
975 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
976 else if (context & 0x3FC0)
977 verbose_printk(KERN_NOTICE "Interrupt context\n");
978 else if (context & 0x4000)
979 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
980 else if (context & 0x8000)
981 verbose_printk(KERN_NOTICE "Kernel process context\n");
983 /* Because we are crashing, and pointers could be bad, we check things
984 * pretty closely before we use them
986 if ((unsigned long)current >= FIXED_CODE_START &&
987 !((unsigned long)current & 0x3) && current->pid) {
988 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
989 if (current->comm >= (char *)FIXED_CODE_START)
990 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
991 current->comm, current->pid);
993 verbose_printk(KERN_NOTICE "COMM= invalid\n");
995 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
996 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
997 verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
998 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
1000 (void *)current->mm->start_code,
1001 (void *)current->mm->end_code,
1002 (void *)current->mm->start_data,
1003 (void *)current->mm->end_data,
1004 (void *)current->mm->end_data,
1005 (void *)current->mm->brk,
1006 (void *)current->mm->start_stack);
1008 verbose_printk(KERN_NOTICE "invalid mm\n");
1010 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
1011 "No Valid process in current context\n");
1015 void dump_bfin_mem(struct pt_regs *fp)
1017 #ifdef CONFIG_DEBUG_VERBOSE
1018 unsigned short *addr, *erraddr, val = 0, err = 0;
1019 char sti = 0, buf[6];
1021 erraddr = (void *)fp->pc;
1023 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
1025 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1026 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1028 if (!((unsigned long)addr & 0xF))
1029 verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
1031 if (!get_instruction(&val, addr)) {
1033 sprintf(buf, "????");
1035 sprintf(buf, "%04x", val);
1037 if (addr == erraddr) {
1038 verbose_printk("[%s]", buf);
1041 verbose_printk(" %s ", buf);
1043 /* Do any previous instructions turn on interrupts? */
1044 if (addr <= erraddr && /* in the past */
1045 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1046 val == 0x017b)) /* [SP++] = RETI */
1050 verbose_printk("\n");
1052 /* Hardware error interrupts can be deferred */
1053 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1055 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
1056 #ifndef CONFIG_DEBUG_HWERR
1057 verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
1058 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
1059 " better idea where it came from\n");
1061 /* If we are handling only one peripheral interrupt
1062 * and current mm and pid are valid, and the last error
1063 * was in that user space process's text area
1064 * print it out - because that is where the problem exists
1066 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1067 (current->pid && current->mm)) {
1068 /* And the last RETI points to the current userspace context */
1069 if ((fp + 1)->pc >= current->mm->start_code &&
1070 (fp + 1)->pc <= current->mm->end_code) {
1071 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1072 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1074 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1082 void show_regs(struct pt_regs *fp)
1084 #ifdef CONFIG_DEBUG_VERBOSE
1086 struct irqaction *action;
1088 unsigned long flags = 0;
1089 unsigned int cpu = smp_processor_id();
1090 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
1092 verbose_printk(KERN_NOTICE "\n");
1093 if (CPUID != bfin_cpuid())
1094 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1095 "but running on:0x%04x (Rev %d)\n",
1096 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1098 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1099 CPU, bfin_compiled_revid());
1101 if (bfin_compiled_revid() != bfin_revid())
1102 verbose_printk("(Detected 0.%d)", bfin_revid());
1104 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1105 get_cclk()/1000000, get_sclk()/1000000,
1113 verbose_printk(KERN_NOTICE "%s", linux_banner);
1115 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
1116 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1117 (long)fp->seqstat, fp->ipend, fp->syscfg);
1118 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
1119 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1120 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1122 /* If the error was from the EBIU, print it out */
1123 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
1124 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
1125 bfin_read_EBIU_ERRMST());
1126 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
1127 bfin_read_EBIU_ERRADD());
1131 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1132 fp->seqstat & SEQSTAT_EXCAUSE);
1133 for (i = 2; i <= 15 ; i++) {
1134 if (fp->ipend & (1 << i)) {
1136 decode_address(buf, bfin_read32(EVT0 + 4*i));
1137 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1139 verbose_printk(KERN_NOTICE " interrupts disabled\n");
1143 /* if no interrupts are going off, don't print this out */
1144 if (fp->ipend & ~0x3F) {
1145 for (i = 0; i < (NR_IRQS - 1); i++) {
1147 spin_lock_irqsave(&irq_desc[i].lock, flags);
1149 action = irq_desc[i].action;
1153 decode_address(buf, (unsigned int)action->handler);
1154 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1155 for (action = action->next; action; action = action->next) {
1156 decode_address(buf, (unsigned int)action->handler);
1157 verbose_printk(", %s", buf);
1159 verbose_printk("\n");
1162 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1166 decode_address(buf, fp->rete);
1167 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
1168 decode_address(buf, fp->retn);
1169 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
1170 decode_address(buf, fp->retx);
1171 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
1172 decode_address(buf, fp->rets);
1173 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
1174 decode_address(buf, fp->pc);
1175 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
1177 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1178 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1179 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
1180 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1181 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
1182 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1185 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1186 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1187 fp->r0, fp->r1, fp->r2, fp->r3);
1188 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1189 fp->r4, fp->r5, fp->r6, fp->r7);
1190 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1191 fp->p0, fp->p1, fp->p2, fp->p3);
1192 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1193 fp->p4, fp->p5, fp->fp, (long)fp);
1194 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1195 fp->lb0, fp->lt0, fp->lc0);
1196 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1197 fp->lb1, fp->lt1, fp->lc1);
1198 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1199 fp->b0, fp->l0, fp->m0, fp->i0);
1200 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1201 fp->b1, fp->l1, fp->m1, fp->i1);
1202 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1203 fp->b2, fp->l2, fp->m2, fp->i2);
1204 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1205 fp->b3, fp->l3, fp->m3, fp->i3);
1206 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1207 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1209 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1210 rdusp(), fp->astat);
1212 verbose_printk(KERN_NOTICE "\n");
1216 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1217 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1220 static DEFINE_SPINLOCK(bfin_spinlock_lock);
1222 asmlinkage int sys_bfin_spinlock(int *p)
1226 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1227 ret = get_user(tmp, p);
1228 if (likely(ret == 0)) {
1234 spin_unlock(&bfin_spinlock_lock);
1238 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1240 void (*curr_handler)(void);
1242 if (exception > 0x3F)
1245 curr_handler = ex_table[exception];
1247 if (curr_handler != ex_replaceable)
1250 ex_table[exception] = handler;
1254 EXPORT_SYMBOL(bfin_request_exception);
1256 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1258 void (*curr_handler)(void);
1260 if (exception > 0x3F)
1263 curr_handler = ex_table[exception];
1265 if (curr_handler != handler)
1268 ex_table[exception] = ex_replaceable;
1272 EXPORT_SYMBOL(bfin_free_exception);
1274 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1276 switch (cplb_panic) {
1277 case CPLB_NO_UNLOCKED:
1278 printk(KERN_EMERG "All CPLBs are locked\n");
1280 case CPLB_PROT_VIOL:
1282 case CPLB_NO_ADDR_MATCH:
1284 case CPLB_UNKNOWN_ERR:
1285 printk(KERN_EMERG "Unknown CPLB Exception\n");
1289 oops_in_progress = 1;
1291 dump_bfin_process(fp);
1295 panic("Unrecoverable event");