2 * File: arch/blackfin/kernel/traps.c
4 * Author: Hamish Macdonald
7 * Description: uses S/W interrupt 15 for the system calls
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/uaccess.h>
31 #include <linux/interrupt.h>
32 #include <linux/module.h>
33 #include <linux/kallsyms.h>
35 #include <asm/traps.h>
36 #include <asm/cacheflush.h>
38 #include <asm/blackfin.h>
39 #include <asm/irq_handler.h>
40 #include <linux/irq.h>
41 #include <asm/trace.h>
42 #include <asm/fixed_code.h>
45 # include <linux/kgdb.h>
47 # define CHK_DEBUGGER_TRAP() \
49 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
51 # define CHK_DEBUGGER_TRAP_MAYBE() \
54 CHK_DEBUGGER_TRAP(); \
57 # define CHK_DEBUGGER_TRAP() do { } while (0)
58 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
62 #ifdef CONFIG_DEBUG_VERBOSE
63 #define verbose_printk(fmt, arg...) \
66 #define verbose_printk(fmt, arg...) \
67 ({ if (0) printk(fmt, ##arg); 0; })
70 /* Initiate the event table handler */
71 void __init trap_init(void)
74 bfin_write_EVT3(trap);
78 static void decode_address(char *buf, unsigned long address)
80 #ifdef CONFIG_DEBUG_VERBOSE
81 struct vm_list_struct *vml;
82 struct task_struct *p;
84 unsigned long flags, offset;
85 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
87 #ifdef CONFIG_KALLSYMS
88 unsigned long symsize;
94 /* look up the address and see if we are in kernel space */
95 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
98 /* yeah! kernel space! */
100 modname = delim = "";
101 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
102 (void *)address, delim, modname, delim, symname,
103 (unsigned long)offset);
109 /* Problem in fixed code section? */
110 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
111 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
115 /* Problem somewhere before the kernel start address */
116 if (address < CONFIG_BOOT_LOAD) {
117 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
121 /* looks like we're off in user-land, so let's walk all the
122 * mappings of all our processes and see if we can't be a whee
125 write_lock_irqsave(&tasklist_lock, flags);
126 for_each_process(p) {
127 mm = (in_atomic ? p->mm : get_task_mm(p));
131 vml = mm->context.vmlist;
133 struct vm_area_struct *vma = vml->vma;
135 if (address >= vma->vm_start && address < vma->vm_end) {
137 char *name = p->comm;
138 struct file *file = vma->vm_file;
141 char *d_name = d_path(&file->f_path, _tmpbuf,
147 /* FLAT does not have its text aligned to the start of
148 * the map while FDPIC ELF does ...
151 /* before we can check flat/fdpic, we need to
152 * make sure current is valid
154 if ((unsigned long)current >= FIXED_CODE_START &&
155 !((unsigned long)current & 0x3)) {
157 (address > current->mm->start_code) &&
158 (address < current->mm->end_code))
159 offset = address - current->mm->start_code;
161 offset = (address - vma->vm_start) +
162 (vma->vm_pgoff << PAGE_SHIFT);
164 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
165 (void *)address, name, offset);
167 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
168 (void *)address, name,
169 vma->vm_start, vma->vm_end);
175 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
186 /* we were unable to find this address anywhere */
187 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
190 write_unlock_irqrestore(&tasklist_lock, flags);
196 asmlinkage void double_fault_c(struct pt_regs *fp)
199 oops_in_progress = 1;
200 #ifdef CONFIG_DEBUG_VERBOSE
201 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
202 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
203 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
204 unsigned int cpu = smp_processor_id();
206 decode_address(buf, cpu_pda[cpu].retx);
207 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
208 (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
209 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
210 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
211 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
212 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
214 decode_address(buf, fp->retx);
215 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
219 dump_bfin_process(fp);
224 panic("Double Fault - unrecoverable event\n");
228 asmlinkage void trap_c(struct pt_regs *fp)
230 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
233 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
234 unsigned int cpu = smp_processor_id();
238 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
240 trace_buffer_save(j);
242 /* Important - be very careful dereferncing pointers - will lead to
243 * double faults if the stack has become corrupt
246 /* If the fault was caused by a kernel thread, or interrupt handler
247 * we will kernel panic, so the system reboots.
248 * If KGDB is enabled, don't set this for kernel breakpoints
251 /* TODO: check to see if we are in some sort of deferred HWERR
252 * that we should be able to recover from, not kernel panic
254 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
256 && (trapnr != VEC_EXCPT02)
260 oops_in_progress = 1;
261 } else if (current) {
262 if (current->mm == NULL) {
264 oops_in_progress = 1;
268 /* trap_c() will be called for exceptions. During exceptions
269 * processing, the pc value should be set with retx value.
270 * With this change we can cleanup some code in signal.c- TODO
272 fp->orig_pc = fp->retx;
273 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
274 trapnr, fp->ipend, fp->pc, fp->retx); */
276 /* send the appropriate signal to the user program */
279 /* This table works in conjuction with the one in ./mach-common/entry.S
280 * Some exceptions are handled there (in assembly, in exception space)
281 * Some are handled here, (in C, in interrupt space)
282 * Some, like CPLB, are handled in both, where the normal path is
283 * handled in assembly/exception space, and the error path is handled
287 /* 0x00 - Linux Syscall, getting here is an error */
288 /* 0x01 - userspace gdb breakpoint, handled here */
290 info.si_code = TRAP_ILLTRAP;
292 CHK_DEBUGGER_TRAP_MAYBE();
293 /* Check if this is a breakpoint in kernel space */
294 if (fp->ipend & 0xffc0)
298 /* 0x03 - User Defined, userspace stack overflow */
300 info.si_code = SEGV_STACKFLOW;
302 verbose_printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
303 CHK_DEBUGGER_TRAP_MAYBE();
305 /* 0x02 - KGDB initial connection and break signal trap */
308 info.si_code = TRAP_ILLTRAP;
313 /* 0x04 - User Defined */
314 /* 0x05 - User Defined */
315 /* 0x06 - User Defined */
316 /* 0x07 - User Defined */
317 /* 0x08 - User Defined */
318 /* 0x09 - User Defined */
319 /* 0x0A - User Defined */
320 /* 0x0B - User Defined */
321 /* 0x0C - User Defined */
322 /* 0x0D - User Defined */
323 /* 0x0E - User Defined */
324 /* 0x0F - User Defined */
325 /* If we got here, it is most likely that someone was trying to use a
326 * custom exception handler, and it is not actually installed properly
328 case VEC_EXCPT04 ... VEC_EXCPT15:
329 info.si_code = ILL_ILLPARAOP;
331 verbose_printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
332 CHK_DEBUGGER_TRAP_MAYBE();
334 /* 0x10 HW Single step, handled here */
336 info.si_code = TRAP_STEP;
338 CHK_DEBUGGER_TRAP_MAYBE();
339 /* Check if this is a single step in kernel space */
340 if (fp->ipend & 0xffc0)
344 /* 0x11 - Trace Buffer Full, handled here */
346 info.si_code = TRAP_TRACEFLOW;
348 verbose_printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
349 CHK_DEBUGGER_TRAP_MAYBE();
351 /* 0x12 - Reserved, Caught by default */
352 /* 0x13 - Reserved, Caught by default */
353 /* 0x14 - Reserved, Caught by default */
354 /* 0x15 - Reserved, Caught by default */
355 /* 0x16 - Reserved, Caught by default */
356 /* 0x17 - Reserved, Caught by default */
357 /* 0x18 - Reserved, Caught by default */
358 /* 0x19 - Reserved, Caught by default */
359 /* 0x1A - Reserved, Caught by default */
360 /* 0x1B - Reserved, Caught by default */
361 /* 0x1C - Reserved, Caught by default */
362 /* 0x1D - Reserved, Caught by default */
363 /* 0x1E - Reserved, Caught by default */
364 /* 0x1F - Reserved, Caught by default */
365 /* 0x20 - Reserved, Caught by default */
366 /* 0x21 - Undefined Instruction, handled here */
368 info.si_code = ILL_ILLOPC;
370 verbose_printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
371 CHK_DEBUGGER_TRAP_MAYBE();
373 /* 0x22 - Illegal Instruction Combination, handled here */
375 info.si_code = ILL_ILLPARAOP;
377 verbose_printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
378 CHK_DEBUGGER_TRAP_MAYBE();
380 /* 0x23 - Data CPLB protection violation, handled here */
382 info.si_code = ILL_CPLB_VI;
384 verbose_printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
385 CHK_DEBUGGER_TRAP_MAYBE();
387 /* 0x24 - Data access misaligned, handled here */
389 info.si_code = BUS_ADRALN;
391 verbose_printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
392 CHK_DEBUGGER_TRAP_MAYBE();
394 /* 0x25 - Unrecoverable Event, handled here */
396 info.si_code = ILL_ILLEXCPT;
398 verbose_printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
399 CHK_DEBUGGER_TRAP_MAYBE();
401 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
402 error case is handled here */
404 info.si_code = BUS_ADRALN;
406 verbose_printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
408 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
410 info.si_code = ILL_CPLB_MULHIT;
412 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
413 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
414 verbose_printk(KERN_NOTICE "NULL pointer access\n");
417 verbose_printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
418 CHK_DEBUGGER_TRAP_MAYBE();
420 /* 0x28 - Emulation Watchpoint, handled here */
422 info.si_code = TRAP_WATCHPT;
424 pr_debug(EXC_0x28(KERN_DEBUG));
425 CHK_DEBUGGER_TRAP_MAYBE();
426 /* Check if this is a watchpoint in kernel space */
427 if (fp->ipend & 0xffc0)
432 /* 0x29 - Instruction fetch access error (535 only) */
433 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
434 info.si_code = BUS_OPFETCH;
436 verbose_printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
437 CHK_DEBUGGER_TRAP_MAYBE();
440 /* 0x29 - Reserved, Caught by default */
442 /* 0x2A - Instruction fetch misaligned, handled here */
444 info.si_code = BUS_ADRALN;
446 verbose_printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
447 CHK_DEBUGGER_TRAP_MAYBE();
449 /* 0x2B - Instruction CPLB protection violation, handled here */
451 info.si_code = ILL_CPLB_VI;
453 verbose_printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
454 CHK_DEBUGGER_TRAP_MAYBE();
456 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
458 info.si_code = ILL_CPLB_MISS;
460 verbose_printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
462 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
463 case VEC_CPLB_I_MHIT:
464 info.si_code = ILL_CPLB_MULHIT;
466 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
467 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
468 verbose_printk(KERN_NOTICE "Jump to NULL address\n");
471 verbose_printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
472 CHK_DEBUGGER_TRAP_MAYBE();
474 /* 0x2E - Illegal use of Supervisor Resource, handled here */
476 info.si_code = ILL_PRVOPC;
478 verbose_printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
479 CHK_DEBUGGER_TRAP_MAYBE();
481 /* 0x2F - Reserved, Caught by default */
482 /* 0x30 - Reserved, Caught by default */
483 /* 0x31 - Reserved, Caught by default */
484 /* 0x32 - Reserved, Caught by default */
485 /* 0x33 - Reserved, Caught by default */
486 /* 0x34 - Reserved, Caught by default */
487 /* 0x35 - Reserved, Caught by default */
488 /* 0x36 - Reserved, Caught by default */
489 /* 0x37 - Reserved, Caught by default */
490 /* 0x38 - Reserved, Caught by default */
491 /* 0x39 - Reserved, Caught by default */
492 /* 0x3A - Reserved, Caught by default */
493 /* 0x3B - Reserved, Caught by default */
494 /* 0x3C - Reserved, Caught by default */
495 /* 0x3D - Reserved, Caught by default */
496 /* 0x3E - Reserved, Caught by default */
497 /* 0x3F - Reserved, Caught by default */
499 info.si_code = BUS_ADRALN;
501 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
502 /* System MMR Error */
503 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
504 info.si_code = BUS_ADRALN;
506 verbose_printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
508 /* External Memory Addressing Error */
509 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
510 info.si_code = BUS_ADRERR;
512 verbose_printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
514 /* Performance Monitor Overflow */
515 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
516 verbose_printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
518 /* RAISE 5 instruction */
519 case (SEQSTAT_HWERRCAUSE_RAISE_5):
520 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
522 default: /* Reserved */
523 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
526 CHK_DEBUGGER_TRAP_MAYBE();
529 * We should be handling all known exception types above,
530 * if we get here we hit a reserved one, so panic
533 oops_in_progress = 1;
534 info.si_code = ILL_ILLPARAOP;
536 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
537 (fp->seqstat & SEQSTAT_EXCAUSE));
538 CHK_DEBUGGER_TRAP_MAYBE();
544 if (sig != SIGTRAP) {
545 dump_bfin_process(fp);
549 /* Print out the trace buffer if it makes sense */
550 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
551 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
552 verbose_printk(KERN_NOTICE "No trace since you do not have "
553 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
557 dump_bfin_trace_buffer();
559 if (oops_in_progress) {
560 /* Dump the current kernel stack */
561 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
562 show_stack(current, NULL);
564 #ifndef CONFIG_ACCESS_CHECK
565 verbose_printk(KERN_EMERG "Please turn on "
566 "CONFIG_ACCESS_CHECK\n");
568 panic("Kernel exception");
570 #ifdef CONFIG_DEBUG_VERBOSE
571 unsigned long *stack;
572 /* Dump the user space stack */
573 stack = (unsigned long *)rdusp();
574 verbose_printk(KERN_NOTICE "Userspace Stack\n");
575 show_stack(NULL, stack);
581 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
586 info.si_addr = (void __user *)fp->pc;
587 force_sig_info(sig, &info, current);
590 trace_buffer_restore(j);
594 /* Typical exception handling routines */
596 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
599 * Similar to get_user, do some address checking, then dereference
600 * Return true on sucess, false on bad address
602 static bool get_instruction(unsigned short *val, unsigned short *address)
607 addr = (unsigned long)address;
609 /* Check for odd addresses */
613 /* Check that things do not wrap around */
614 if (addr > (addr + 2))
618 * Since we are in exception context, we need to do a little address checking
619 * We need to make sure we are only accessing valid memory, and
620 * we don't read something in the async space that can hang forever
622 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
624 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
626 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
627 #if L1_DATA_A_LENGTH != 0
628 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
630 #if L1_DATA_B_LENGTH != 0
631 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
633 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
634 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
635 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
636 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
637 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
638 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
639 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
640 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
641 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
646 #if L1_CODE_LENGTH != 0
647 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
648 isram_memcpy(val, address, 2);
658 * decode the instruction if we are printing out the trace, as it
659 * makes things easier to follow, without running it through objdump
660 * These are the normal instructions which cause change of flow, which
661 * would be at the source of the trace buffer
663 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
664 static void decode_instruction(unsigned short *address)
666 unsigned short opcode;
668 if (get_instruction(&opcode, address)) {
669 if (opcode == 0x0010)
670 verbose_printk("RTS");
671 else if (opcode == 0x0011)
672 verbose_printk("RTI");
673 else if (opcode == 0x0012)
674 verbose_printk("RTX");
675 else if (opcode >= 0x0050 && opcode <= 0x0057)
676 verbose_printk("JUMP (P%i)", opcode & 7);
677 else if (opcode >= 0x0060 && opcode <= 0x0067)
678 verbose_printk("CALL (P%i)", opcode & 7);
679 else if (opcode >= 0x0070 && opcode <= 0x0077)
680 verbose_printk("CALL (PC+P%i)", opcode & 7);
681 else if (opcode >= 0x0080 && opcode <= 0x0087)
682 verbose_printk("JUMP (PC+P%i)", opcode & 7);
683 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
684 verbose_printk("IF !CC JUMP");
685 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
686 verbose_printk("IF CC JUMP");
687 else if (opcode >= 0x2000 && opcode <= 0x2fff)
688 verbose_printk("JUMP.S");
689 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
690 verbose_printk("LSETUP");
691 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
692 verbose_printk("JUMP.L");
693 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
694 verbose_printk("CALL pcrel");
696 verbose_printk("0x%04x", opcode);
702 void dump_bfin_trace_buffer(void)
704 #ifdef CONFIG_DEBUG_VERBOSE
705 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
708 unsigned short *addr;
709 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
713 trace_buffer_save(tflags);
715 printk(KERN_NOTICE "Hardware Trace:\n");
717 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
718 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
721 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
722 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
723 decode_address(buf, (unsigned long)bfin_read_TBUF());
724 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
725 addr = (unsigned short *)bfin_read_TBUF();
726 decode_address(buf, (unsigned long)addr);
727 printk(KERN_NOTICE " Source : %s ", buf);
728 decode_instruction(addr);
733 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
734 if (trace_buff_offset)
735 index = trace_buff_offset / 4;
739 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
741 decode_address(buf, software_trace_buff[index]);
742 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
746 decode_address(buf, software_trace_buff[index]);
747 printk(KERN_NOTICE " Source : %s ", buf);
748 decode_instruction((unsigned short *)software_trace_buff[index]);
758 trace_buffer_restore(tflags);
762 EXPORT_SYMBOL(dump_bfin_trace_buffer);
765 * Checks to see if the address pointed to is either a
766 * 16-bit CALL instruction, or a 32-bit CALL instruction
768 static bool is_bfin_call(unsigned short *addr)
770 unsigned short opcode = 0, *ins_addr;
771 ins_addr = (unsigned short *)addr;
773 if (!get_instruction(&opcode, ins_addr))
776 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
777 (opcode >= 0x0070 && opcode <= 0x0077))
781 if (!get_instruction(&opcode, ins_addr))
784 if (opcode >= 0xE300 && opcode <= 0xE3FF)
791 void show_stack(struct task_struct *task, unsigned long *stack)
794 unsigned int *addr, *endstack, *fp = 0, *frame;
795 unsigned short *ins_addr;
797 unsigned int i, j, ret_addr, frame_no = 0;
800 * If we have been passed a specific stack, use that one otherwise
801 * if we have been passed a task structure, use that, otherwise
802 * use the stack of where the variable "stack" exists
807 /* We know this is a kernel stack, so this is the start/end */
808 stack = (unsigned long *)task->thread.ksp;
809 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
811 /* print out the existing stack info */
812 stack = (unsigned long *)&stack;
813 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
816 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
818 printk(KERN_NOTICE "Stack info:\n");
819 decode_address(buf, (unsigned int)stack);
820 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
822 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
824 /* First thing is to look for a frame pointer */
825 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
826 addr < endstack; addr++, i++) {
829 ins_addr = (unsigned short *)*addr;
831 if (is_bfin_call(ins_addr))
835 /* Let's check to see if it is a frame pointer */
836 while (fp >= (addr - 1) && fp < endstack && fp)
837 fp = (unsigned int *)*fp;
838 if (fp == 0 || fp == endstack) {
847 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
852 * Now that we think we know where things are, we
853 * walk the stack again, this time printing things out
854 * incase there is no frame pointer, we still look for
855 * valid return addresses
858 /* First time print out data, next time, print out symbols */
859 for (j = 0; j <= 1; j++) {
861 printk(KERN_NOTICE "Return addresses in stack:\n");
863 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
868 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
869 addr <= endstack; addr++, i++) {
872 if (!j && i % 8 == 0)
873 printk("\n" KERN_NOTICE "%p:",addr);
875 /* if it is an odd address, or zero, just skip it */
876 if (*addr & 0x1 || !*addr)
879 ins_addr = (unsigned short *)*addr;
881 /* Go back one instruction, and see if it is a CALL */
883 ret_addr = is_bfin_call(ins_addr);
885 if (!j && stack == (unsigned long *)addr)
886 printk("[%08x]", *addr);
889 decode_address(buf, (unsigned int)*addr);
891 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
894 printk(KERN_NOTICE " address : %s\n", buf);
896 printk("<%08x>", *addr);
897 else if (fp == addr) {
901 printk("(%08x)", *addr);
903 fp = (unsigned int *)*addr;
907 printk(" %08x ", *addr);
915 void dump_stack(void)
918 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
921 trace_buffer_save(tflags);
922 dump_bfin_trace_buffer();
923 show_stack(current, &stack);
924 trace_buffer_restore(tflags);
926 EXPORT_SYMBOL(dump_stack);
928 void dump_bfin_process(struct pt_regs *fp)
930 #ifdef CONFIG_DEBUG_VERBOSE
931 /* We should be able to look at fp->ipend, but we don't push it on the
932 * stack all the time, so do this until we fix that */
933 unsigned int context = bfin_read_IPEND();
935 if (oops_in_progress)
936 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
938 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
939 verbose_printk(KERN_NOTICE "HW Error context\n");
940 else if (context & 0x0020)
941 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
942 else if (context & 0x3FC0)
943 verbose_printk(KERN_NOTICE "Interrupt context\n");
944 else if (context & 0x4000)
945 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
946 else if (context & 0x8000)
947 verbose_printk(KERN_NOTICE "Kernel process context\n");
949 /* Because we are crashing, and pointers could be bad, we check things
950 * pretty closely before we use them
952 if ((unsigned long)current >= FIXED_CODE_START &&
953 !((unsigned long)current & 0x3) && current->pid) {
954 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
955 if (current->comm >= (char *)FIXED_CODE_START)
956 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
957 current->comm, current->pid);
959 verbose_printk(KERN_NOTICE "COMM= invalid\n");
961 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
962 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
963 verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
964 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
966 (void *)current->mm->start_code,
967 (void *)current->mm->end_code,
968 (void *)current->mm->start_data,
969 (void *)current->mm->end_data,
970 (void *)current->mm->end_data,
971 (void *)current->mm->brk,
972 (void *)current->mm->start_stack);
974 verbose_printk(KERN_NOTICE "invalid mm\n");
976 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
977 "No Valid process in current context\n");
981 void dump_bfin_mem(struct pt_regs *fp)
983 #ifdef CONFIG_DEBUG_VERBOSE
984 unsigned short *addr, *erraddr, val = 0, err = 0;
985 char sti = 0, buf[6];
987 erraddr = (void *)fp->pc;
989 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
991 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
992 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
994 if (!((unsigned long)addr & 0xF))
995 verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
997 if (!get_instruction(&val, addr)) {
999 sprintf(buf, "????");
1001 sprintf(buf, "%04x", val);
1003 if (addr == erraddr) {
1004 verbose_printk("[%s]", buf);
1007 verbose_printk(" %s ", buf);
1009 /* Do any previous instructions turn on interrupts? */
1010 if (addr <= erraddr && /* in the past */
1011 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1012 val == 0x017b)) /* [SP++] = RETI */
1016 verbose_printk("\n");
1018 /* Hardware error interrupts can be deferred */
1019 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1021 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
1022 #ifndef CONFIG_DEBUG_HWERR
1023 verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
1024 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
1025 " better idea where it came from\n");
1027 /* If we are handling only one peripheral interrupt
1028 * and current mm and pid are valid, and the last error
1029 * was in that user space process's text area
1030 * print it out - because that is where the problem exists
1032 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1033 (current->pid && current->mm)) {
1034 /* And the last RETI points to the current userspace context */
1035 if ((fp + 1)->pc >= current->mm->start_code &&
1036 (fp + 1)->pc <= current->mm->end_code) {
1037 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1038 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1040 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1048 void show_regs(struct pt_regs *fp)
1050 #ifdef CONFIG_DEBUG_VERBOSE
1052 struct irqaction *action;
1054 unsigned long flags;
1055 unsigned int cpu = smp_processor_id();
1057 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
1058 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1059 (long)fp->seqstat, fp->ipend, fp->syscfg);
1060 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
1061 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1062 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1064 /* If the error was from the EBIU, print it out */
1065 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
1066 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
1067 bfin_read_EBIU_ERRMST());
1068 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
1069 bfin_read_EBIU_ERRADD());
1073 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1074 fp->seqstat & SEQSTAT_EXCAUSE);
1075 for (i = 6; i <= 15 ; i++) {
1076 if (fp->ipend & (1 << i)) {
1077 decode_address(buf, bfin_read32(EVT0 + 4*i));
1078 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1082 /* if no interrupts are going off, don't print this out */
1083 if (fp->ipend & ~0x3F) {
1084 for (i = 0; i < (NR_IRQS - 1); i++) {
1085 spin_lock_irqsave(&irq_desc[i].lock, flags);
1086 action = irq_desc[i].action;
1090 decode_address(buf, (unsigned int)action->handler);
1091 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1092 for (action = action->next; action; action = action->next) {
1093 decode_address(buf, (unsigned int)action->handler);
1094 verbose_printk(", %s", buf);
1096 verbose_printk("\n");
1098 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1102 decode_address(buf, fp->rete);
1103 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
1104 decode_address(buf, fp->retn);
1105 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
1106 decode_address(buf, fp->retx);
1107 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
1108 decode_address(buf, fp->rets);
1109 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
1110 decode_address(buf, fp->pc);
1111 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
1113 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1114 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1115 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
1116 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1117 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
1118 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1121 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1122 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1123 fp->r0, fp->r1, fp->r2, fp->r3);
1124 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1125 fp->r4, fp->r5, fp->r6, fp->r7);
1126 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1127 fp->p0, fp->p1, fp->p2, fp->p3);
1128 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1129 fp->p4, fp->p5, fp->fp, (long)fp);
1130 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1131 fp->lb0, fp->lt0, fp->lc0);
1132 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1133 fp->lb1, fp->lt1, fp->lc1);
1134 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1135 fp->b0, fp->l0, fp->m0, fp->i0);
1136 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1137 fp->b1, fp->l1, fp->m1, fp->i1);
1138 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1139 fp->b2, fp->l2, fp->m2, fp->i2);
1140 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1141 fp->b3, fp->l3, fp->m3, fp->i3);
1142 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1143 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1145 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1146 rdusp(), fp->astat);
1148 verbose_printk(KERN_NOTICE "\n");
1152 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1153 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1156 static DEFINE_SPINLOCK(bfin_spinlock_lock);
1158 asmlinkage int sys_bfin_spinlock(int *p)
1162 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1163 ret = get_user(tmp, p);
1164 if (likely(ret == 0)) {
1170 spin_unlock(&bfin_spinlock_lock);
1174 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1176 void (*curr_handler)(void);
1178 if (exception > 0x3F)
1181 curr_handler = ex_table[exception];
1183 if (curr_handler != ex_replaceable)
1186 ex_table[exception] = handler;
1190 EXPORT_SYMBOL(bfin_request_exception);
1192 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1194 void (*curr_handler)(void);
1196 if (exception > 0x3F)
1199 curr_handler = ex_table[exception];
1201 if (curr_handler != handler)
1204 ex_table[exception] = ex_replaceable;
1208 EXPORT_SYMBOL(bfin_free_exception);
1210 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1212 switch (cplb_panic) {
1213 case CPLB_NO_UNLOCKED:
1214 printk(KERN_EMERG "All CPLBs are locked\n");
1216 case CPLB_PROT_VIOL:
1218 case CPLB_NO_ADDR_MATCH:
1220 case CPLB_UNKNOWN_ERR:
1221 printk(KERN_EMERG "Unknown CPLB Exception\n");
1225 oops_in_progress = 1;
1227 dump_bfin_process(fp);
1231 panic("Unrecoverable event\n");