blob: 6b7325d634afe28659aef236303558be7a1f2967 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Copyright 2004-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Licensed under the GPL-2 or later
Bryan Wu1394f032007-05-06 14:50:22 -07005 */
6
Mike Frysinger70f12562009-06-07 17:18:25 -04007#include <linux/bug.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08008#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -07009#include <linux/interrupt.h>
10#include <linux/module.h>
11#include <linux/kallsyms.h>
Bryan Wud31c5ab2007-08-10 13:00:42 -070012#include <linux/fs.h>
David Howells8feae132009-01-08 12:04:47 +000013#include <linux/rbtree.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080014#include <asm/traps.h>
15#include <asm/cacheflush.h>
Mike Frysingerf4585a02008-10-13 14:45:21 +080016#include <asm/cplb.h>
Mike Frysingere56e03b2009-06-07 16:31:52 -040017#include <asm/dma.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080018#include <asm/blackfin.h>
19#include <asm/irq_handler.h>
Robin Getzd8f66c82007-12-24 15:27:56 +080020#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080021#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080022#include <asm/fixed_code.h>
Bryan Wu1394f032007-05-06 14:50:22 -070023
24#ifdef CONFIG_KGDB
Bryan Wu1394f032007-05-06 14:50:22 -070025# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080026
27# define CHK_DEBUGGER_TRAP() \
28 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080029 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080030 } while (0)
31# define CHK_DEBUGGER_TRAP_MAYBE() \
32 do { \
33 if (kgdb_connected) \
34 CHK_DEBUGGER_TRAP(); \
35 } while (0)
36#else
37# define CHK_DEBUGGER_TRAP() do { } while (0)
38# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070039#endif
40
Robin Getz9f06c38f2008-10-10 18:13:21 +080041
Robin Getz4ee1c452008-10-28 11:36:11 +080042#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c38f2008-10-10 18:13:21 +080043#define verbose_printk(fmt, arg...) \
44 printk(fmt, ##arg)
45#else
46#define verbose_printk(fmt, arg...) \
47 ({ if (0) printk(fmt, ##arg); 0; })
48#endif
49
Robin Getz81f7f452009-06-03 18:58:26 +000050#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
51u32 last_seqstat;
52#ifdef CONFIG_DEBUG_MMRS_MODULE
53EXPORT_SYMBOL(last_seqstat);
54#endif
55#endif
56
Bryan Wu1394f032007-05-06 14:50:22 -070057/* Initiate the event table handler */
58void __init trap_init(void)
59{
60 CSYNC();
61 bfin_write_EVT3(trap);
62 CSYNC();
63}
64
Robin Getz226eb1e2007-10-29 17:59:07 +080065static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070066{
Robin Getz9f06c38f2008-10-10 18:13:21 +080067#ifdef CONFIG_DEBUG_VERBOSE
Bryan Wu1394f032007-05-06 14:50:22 -070068 struct task_struct *p;
69 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080070 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080071 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
David Howells8feae132009-01-08 12:04:47 +000072 struct rb_node *n;
Bryan Wu1394f032007-05-06 14:50:22 -070073
74#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080075 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070076 const char *symname;
77 char *modname;
78 char *delim = ":";
79 char namebuf[128];
Mike Frysinger18070dd2009-06-23 20:17:21 +000080#endif
Bryan Wu1394f032007-05-06 14:50:22 -070081
Mike Frysinger18070dd2009-06-23 20:17:21 +000082 buf += sprintf(buf, "<0x%08lx> ", address);
83
84#ifdef CONFIG_KALLSYMS
Bryan Wu1394f032007-05-06 14:50:22 -070085 /* look up the address and see if we are in kernel space */
86 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
87
88 if (symname) {
89 /* yeah! kernel space! */
90 if (!modname)
91 modname = delim = "";
Mike Frysinger18070dd2009-06-23 20:17:21 +000092 sprintf(buf, "{ %s%s%s%s + 0x%lx }",
93 delim, modname, delim, symname,
94 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +080095 return;
Bryan Wu1394f032007-05-06 14:50:22 -070096 }
97#endif
98
Robin Getz226eb1e2007-10-29 17:59:07 +080099 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
Mike Frysinger18070dd2009-06-23 20:17:21 +0000100 /* Problem in fixed code section? */
101 strcat(buf, "/* Maybe fixed code section */");
Robin Getz226eb1e2007-10-29 17:59:07 +0800102 return;
Robin Getz226eb1e2007-10-29 17:59:07 +0800103
Mike Frysinger18070dd2009-06-23 20:17:21 +0000104 } else if (address < CONFIG_BOOT_LOAD) {
105 /* Problem somewhere before the kernel start address */
106 strcat(buf, "/* Maybe null pointer? */");
107 return;
108
109 } else if (address >= COREMMR_BASE) {
110 strcat(buf, "/* core mmrs */");
111 return;
112
113 } else if (address >= SYSMMR_BASE) {
114 strcat(buf, "/* system mmrs */");
115 return;
116
117 } else if (address >= L1_ROM_START && address < L1_ROM_START + L1_ROM_LENGTH) {
118 strcat(buf, "/* on-chip L1 ROM */");
Robin Getz226eb1e2007-10-29 17:59:07 +0800119 return;
120 }
121
Bryan Wu1394f032007-05-06 14:50:22 -0700122 /* looks like we're off in user-land, so let's walk all the
123 * mappings of all our processes and see if we can't be a whee
124 * bit more specific
125 */
Robin Getz885be032007-10-29 17:20:41 +0800126 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700127 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800128 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700129 if (!mm)
130 continue;
131
David Howells8feae132009-01-08 12:04:47 +0000132 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
133 struct vm_area_struct *vma;
134
135 vma = rb_entry(n, struct vm_area_struct, vm_rb);
Bryan Wu1394f032007-05-06 14:50:22 -0700136
137 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800138 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700139 char *name = p->comm;
140 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800141
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800142 if (file) {
143 char *d_name = d_path(&file->f_path, _tmpbuf,
Jan Blunckcf28b482008-02-14 19:38:44 -0800144 sizeof(_tmpbuf));
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800145 if (!IS_ERR(d_name))
146 name = d_name;
147 }
Bryan Wu1394f032007-05-06 14:50:22 -0700148
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800149 /* FLAT does not have its text aligned to the start of
150 * the map while FDPIC ELF does ...
151 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800152
Robin Getz7f1c9062008-04-25 03:36:31 +0800153 /* before we can check flat/fdpic, we need to
154 * make sure current is valid
155 */
156 if ((unsigned long)current >= FIXED_CODE_START &&
157 !((unsigned long)current & 0x3)) {
158 if (current->mm &&
159 (address > current->mm->start_code) &&
160 (address < current->mm->end_code))
161 offset = address - current->mm->start_code;
162 else
163 offset = (address - vma->vm_start) +
164 (vma->vm_pgoff << PAGE_SHIFT);
165
Mike Frysinger18070dd2009-06-23 20:17:21 +0000166 sprintf(buf, "[ %s + 0x%lx ]", name, offset);
Robin Getz7f1c9062008-04-25 03:36:31 +0800167 } else
Mike Frysinger18070dd2009-06-23 20:17:21 +0000168 sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
169 name, vma->vm_start, vma->vm_end);
Robin Getz7f1c9062008-04-25 03:36:31 +0800170
Robin Getz904656c2008-03-26 09:17:43 +0800171 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800172 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800173
Mike Frysinger18070dd2009-06-23 20:17:21 +0000174 if (buf[0] == '\0')
175 sprintf(buf, "[ %s ] dynamic memory", name);
Robin Getzf09630b2008-07-26 19:45:46 +0800176
Robin Getz885be032007-10-29 17:20:41 +0800177 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700178 }
Bryan Wu1394f032007-05-06 14:50:22 -0700179 }
Robin Getz904656c2008-03-26 09:17:43 +0800180 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800181 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700182 }
Bryan Wu1394f032007-05-06 14:50:22 -0700183
184 /* we were unable to find this address anywhere */
Mike Frysinger18070dd2009-06-23 20:17:21 +0000185 sprintf(buf, "/* kernel dynamic memory */");
Robin Getz885be032007-10-29 17:20:41 +0800186
187done:
188 write_unlock_irqrestore(&tasklist_lock, flags);
Robin Getz9f06c38f2008-10-10 18:13:21 +0800189#else
190 sprintf(buf, " ");
191#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700192}
193
Robin Getz2ebcade2007-10-09 17:24:30 +0800194asmlinkage void double_fault_c(struct pt_regs *fp)
195{
Robin Getza0cab652009-05-11 18:34:41 +0000196#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
197 int j;
198 trace_buffer_save(j);
199#endif
200
Robin Getz226eb1e2007-10-29 17:59:07 +0800201 console_verbose();
202 oops_in_progress = 1;
Robin Getz9f06c38f2008-10-10 18:13:21 +0800203#ifdef CONFIG_DEBUG_VERBOSE
Joe Perchesad361c92009-07-06 13:05:40 -0700204 printk(KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800205#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
206 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
Yi Lib6dbde22009-08-20 04:17:47 +0000207 unsigned int cpu = raw_smp_processor_id();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800208 char buf[150];
Graf Yang01b9f4b2009-07-22 11:56:24 +0000209 decode_address(buf, cpu_pda[cpu].retx_doublefault);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800210 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
Graf Yang01b9f4b2009-07-22 11:56:24 +0000211 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
212 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800213 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang01b9f4b2009-07-22 11:56:24 +0000214 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800215 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
216
217 decode_address(buf, fp->retx);
Graf Yang8f658732008-11-18 17:48:22 +0800218 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800219 } else
220#endif
221 {
222 dump_bfin_process(fp);
223 dump_bfin_mem(fp);
224 show_regs(fp);
Robin Getza0cab652009-05-11 18:34:41 +0000225 dump_bfin_trace_buffer();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800226 }
Robin Getz9f06c38f2008-10-10 18:13:21 +0800227#endif
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000228 panic("Double Fault - unrecoverable event");
Robin Getz2ebcade2007-10-09 17:24:30 +0800229
230}
231
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400232static int kernel_mode_regs(struct pt_regs *regs)
233{
234 return regs->ipend & 0xffc0;
235}
236
Yi Lic4baebf2009-08-12 23:05:35 +0000237asmlinkage notrace void trap_c(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700238{
Robin Getz518039b2007-07-25 11:03:28 +0800239#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
240 int j;
241#endif
Graf Yang8f658732008-11-18 17:48:22 +0800242#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Yi Lib6dbde22009-08-20 04:17:47 +0000243 unsigned int cpu = raw_smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800244#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400245 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +0800246 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700247 siginfo_t info;
248 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
249
Bryan Wu1394f032007-05-06 14:50:22 -0700250 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +0000251#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
252 last_seqstat = (u32)fp->seqstat;
253#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700254
Robin Getz226eb1e2007-10-29 17:59:07 +0800255 /* Important - be very careful dereferncing pointers - will lead to
256 * double faults if the stack has become corrupt
257 */
258
Bryan Wu1394f032007-05-06 14:50:22 -0700259 /* trap_c() will be called for exceptions. During exceptions
260 * processing, the pc value should be set with retx value.
261 * With this change we can cleanup some code in signal.c- TODO
262 */
263 fp->orig_pc = fp->retx;
264 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
265 trapnr, fp->ipend, fp->pc, fp->retx); */
266
267 /* send the appropriate signal to the user program */
268 switch (trapnr) {
269
270 /* This table works in conjuction with the one in ./mach-common/entry.S
271 * Some exceptions are handled there (in assembly, in exception space)
272 * Some are handled here, (in C, in interrupt space)
273 * Some, like CPLB, are handled in both, where the normal path is
274 * handled in assembly/exception space, and the error path is handled
275 * here
276 */
277
278 /* 0x00 - Linux Syscall, getting here is an error */
279 /* 0x01 - userspace gdb breakpoint, handled here */
280 case VEC_EXCPT01:
281 info.si_code = TRAP_ILLTRAP;
282 sig = SIGTRAP;
283 CHK_DEBUGGER_TRAP_MAYBE();
284 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400285 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400286 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700287 else
288 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800289 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700290 case VEC_EXCPT03:
291 info.si_code = SEGV_STACKFLOW;
292 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400293 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800294 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700295 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800296 /* 0x02 - KGDB initial connection and break signal trap */
297 case VEC_EXCPT02:
298#ifdef CONFIG_KGDB
299 info.si_code = TRAP_ILLTRAP;
300 sig = SIGTRAP;
301 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400302 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800303#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800304 /* 0x04 - User Defined */
305 /* 0x05 - User Defined */
306 /* 0x06 - User Defined */
307 /* 0x07 - User Defined */
308 /* 0x08 - User Defined */
309 /* 0x09 - User Defined */
310 /* 0x0A - User Defined */
311 /* 0x0B - User Defined */
312 /* 0x0C - User Defined */
313 /* 0x0D - User Defined */
314 /* 0x0E - User Defined */
315 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800316 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800317 * custom exception handler, and it is not actually installed properly
318 */
319 case VEC_EXCPT04 ... VEC_EXCPT15:
320 info.si_code = ILL_ILLPARAOP;
321 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400322 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800323 CHK_DEBUGGER_TRAP_MAYBE();
324 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700325 /* 0x10 HW Single step, handled here */
326 case VEC_STEP:
327 info.si_code = TRAP_STEP;
328 sig = SIGTRAP;
329 CHK_DEBUGGER_TRAP_MAYBE();
330 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400331 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400332 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700333 else
334 break;
335 /* 0x11 - Trace Buffer Full, handled here */
336 case VEC_OVFLOW:
337 info.si_code = TRAP_TRACEFLOW;
338 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400339 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800340 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700341 break;
342 /* 0x12 - Reserved, Caught by default */
343 /* 0x13 - Reserved, Caught by default */
344 /* 0x14 - Reserved, Caught by default */
345 /* 0x15 - Reserved, Caught by default */
346 /* 0x16 - Reserved, Caught by default */
347 /* 0x17 - Reserved, Caught by default */
348 /* 0x18 - Reserved, Caught by default */
349 /* 0x19 - Reserved, Caught by default */
350 /* 0x1A - Reserved, Caught by default */
351 /* 0x1B - Reserved, Caught by default */
352 /* 0x1C - Reserved, Caught by default */
353 /* 0x1D - Reserved, Caught by default */
354 /* 0x1E - Reserved, Caught by default */
355 /* 0x1F - Reserved, Caught by default */
356 /* 0x20 - Reserved, Caught by default */
357 /* 0x21 - Undefined Instruction, handled here */
358 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400359#ifdef CONFIG_BUG
360 if (kernel_mode_regs(fp)) {
361 switch (report_bug(fp->pc, fp)) {
362 case BUG_TRAP_TYPE_NONE:
363 break;
364 case BUG_TRAP_TYPE_WARN:
365 dump_bfin_trace_buffer();
366 fp->pc += 2;
367 goto traps_done;
368 case BUG_TRAP_TYPE_BUG:
369 /* call to panic() will dump trace, and it is
370 * off at this point, so it won't be clobbered
371 */
372 panic("BUG()");
373 }
374 }
375#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700376 info.si_code = ILL_ILLOPC;
377 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400378 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800379 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700380 break;
381 /* 0x22 - Illegal Instruction Combination, handled here */
382 case VEC_ILGAL_I:
383 info.si_code = ILL_ILLPARAOP;
384 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400385 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800386 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700387 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800388 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700389 case VEC_CPLB_VL:
390 info.si_code = ILL_CPLB_VI;
Graf Yang36b84122009-07-21 02:26:57 +0000391 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400392 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800393 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700394 break;
395 /* 0x24 - Data access misaligned, handled here */
396 case VEC_MISALI_D:
397 info.si_code = BUS_ADRALN;
398 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400399 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800400 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700401 break;
402 /* 0x25 - Unrecoverable Event, handled here */
403 case VEC_UNCOV:
404 info.si_code = ILL_ILLEXCPT;
405 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400406 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800407 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700408 break;
409 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
410 error case is handled here */
411 case VEC_CPLB_M:
412 info.si_code = BUS_ADRALN;
413 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400414 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700415 break;
416 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
417 case VEC_CPLB_MHIT:
418 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700419 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800420#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800421 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400422 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800423 else
Bryan Wu1394f032007-05-06 14:50:22 -0700424#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400425 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800426 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700427 break;
428 /* 0x28 - Emulation Watchpoint, handled here */
429 case VEC_WATCH:
430 info.si_code = TRAP_WATCHPT;
431 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800432 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700433 CHK_DEBUGGER_TRAP_MAYBE();
434 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400435 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400436 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700437 else
438 break;
439#ifdef CONFIG_BF535
440 /* 0x29 - Instruction fetch access error (535 only) */
441 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
442 info.si_code = BUS_OPFETCH;
443 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400444 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800445 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700446 break;
447#else
448 /* 0x29 - Reserved, Caught by default */
449#endif
450 /* 0x2A - Instruction fetch misaligned, handled here */
451 case VEC_MISALI_I:
452 info.si_code = BUS_ADRALN;
453 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400454 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800455 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700456 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800457 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700458 case VEC_CPLB_I_VL:
459 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800460 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400461 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800462 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700463 break;
464 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
465 case VEC_CPLB_I_M:
466 info.si_code = ILL_CPLB_MISS;
467 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400468 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700469 break;
470 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
471 case VEC_CPLB_I_MHIT:
472 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700473 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800474#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800475 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400476 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800477 else
Bryan Wu1394f032007-05-06 14:50:22 -0700478#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400479 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800480 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700481 break;
482 /* 0x2E - Illegal use of Supervisor Resource, handled here */
483 case VEC_ILL_RES:
484 info.si_code = ILL_PRVOPC;
485 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400486 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800487 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700488 break;
489 /* 0x2F - Reserved, Caught by default */
490 /* 0x30 - Reserved, Caught by default */
491 /* 0x31 - Reserved, Caught by default */
492 /* 0x32 - Reserved, Caught by default */
493 /* 0x33 - Reserved, Caught by default */
494 /* 0x34 - Reserved, Caught by default */
495 /* 0x35 - Reserved, Caught by default */
496 /* 0x36 - Reserved, Caught by default */
497 /* 0x37 - Reserved, Caught by default */
498 /* 0x38 - Reserved, Caught by default */
499 /* 0x39 - Reserved, Caught by default */
500 /* 0x3A - Reserved, Caught by default */
501 /* 0x3B - Reserved, Caught by default */
502 /* 0x3C - Reserved, Caught by default */
503 /* 0x3D - Reserved, Caught by default */
504 /* 0x3E - Reserved, Caught by default */
505 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800506 case VEC_HWERR:
507 info.si_code = BUS_ADRALN;
508 sig = SIGBUS;
509 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
510 /* System MMR Error */
511 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
512 info.si_code = BUS_ADRALN;
513 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400514 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800515 break;
516 /* External Memory Addressing Error */
517 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
518 info.si_code = BUS_ADRERR;
519 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400520 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800521 break;
522 /* Performance Monitor Overflow */
523 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400524 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800525 break;
526 /* RAISE 5 instruction */
527 case (SEQSTAT_HWERRCAUSE_RAISE_5):
528 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
529 break;
530 default: /* Reserved */
531 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
532 break;
533 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800534 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800535 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800536 /*
537 * We should be handling all known exception types above,
538 * if we get here we hit a reserved one, so panic
539 */
Bryan Wu1394f032007-05-06 14:50:22 -0700540 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800541 info.si_code = ILL_ILLPARAOP;
542 sig = SIGILL;
Robin Getz9f06c38f2008-10-10 18:13:21 +0800543 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700544 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800545 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700546 break;
547 }
548
Robin Getz226eb1e2007-10-29 17:59:07 +0800549 BUG_ON(sig == 0);
550
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400551 /* If the fault was caused by a kernel thread, or interrupt handler
552 * we will kernel panic, so the system reboots.
553 */
554 if (kernel_mode_regs(fp) || (current && !current->mm)) {
555 console_verbose();
556 oops_in_progress = 1;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400557 }
558
Robin Getz226eb1e2007-10-29 17:59:07 +0800559 if (sig != SIGTRAP) {
Mike Frysinger15627bd2009-06-23 11:21:34 +0000560 if (strerror)
561 verbose_printk(strerror);
562
Mike Frysinger49dce912007-11-21 16:46:49 +0800563 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800564 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800565 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800566
567 /* Print out the trace buffer if it makes sense */
568#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
569 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800570 verbose_printk(KERN_NOTICE "No trace since you do not have "
Joe Perchesad361c92009-07-06 13:05:40 -0700571 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800572 else
573#endif
574 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800575
Robin Getz226eb1e2007-10-29 17:59:07 +0800576 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800577 /* Dump the current kernel stack */
Joe Perchesad361c92009-07-06 13:05:40 -0700578 verbose_printk(KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800579 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800580 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800581#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c38f2008-10-10 18:13:21 +0800582 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800583 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800584#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700585 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800586 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800587#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c38f2008-10-10 18:13:21 +0800588 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800589 /* Dump the user space stack */
590 stack = (unsigned long *)rdusp();
Robin Getz9f06c38f2008-10-10 18:13:21 +0800591 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800592 show_stack(NULL, stack);
Robin Getz9f06c38f2008-10-10 18:13:21 +0800593#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800594 }
Bryan Wu1394f032007-05-06 14:50:22 -0700595 }
Robin Getzfb322912007-11-21 16:38:05 +0800596
Yi Li6a01f232009-01-07 23:14:39 +0800597#ifdef CONFIG_IPIPE
598 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
599#endif
600 {
601 info.si_signo = sig;
602 info.si_errno = 0;
603 info.si_addr = (void __user *)fp->pc;
604 force_sig_info(sig, &info, current);
605 }
Bryan Wu1394f032007-05-06 14:50:22 -0700606
Robin Getz0e4edcf2009-06-22 20:23:48 +0000607 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
Robin Getzf574a762009-07-09 15:11:52 +0000608 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
609 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
Robin Getz0acad8d2009-05-11 18:55:16 +0000610 fp->pc = SAFE_USER_INSTRUCTION;
611
Mike Frysinger6510a202009-06-07 15:07:25 -0400612 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700613 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700614}
615
616/* Typical exception handling routines */
617
Robin Getz518039b2007-07-25 11:03:28 +0800618#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
619
Robin Getzf09630b2008-07-26 19:45:46 +0800620/*
621 * Similar to get_user, do some address checking, then dereference
622 * Return true on sucess, false on bad address
623 */
Robin Getz9f06c38f2008-10-10 18:13:21 +0800624static bool get_instruction(unsigned short *val, unsigned short *address)
Robin Getzf09630b2008-07-26 19:45:46 +0800625{
Mike Frysingere56e03b2009-06-07 16:31:52 -0400626 unsigned long addr = (unsigned long)address;
Robin Getzf09630b2008-07-26 19:45:46 +0800627
628 /* Check for odd addresses */
629 if (addr & 0x1)
630 return false;
631
Mike Frysingere56e03b2009-06-07 16:31:52 -0400632 /* MMR region will never have instructions */
633 if (addr >= SYSMMR_BASE)
Robin Getzf09630b2008-07-26 19:45:46 +0800634 return false;
635
Mike Frysingere56e03b2009-06-07 16:31:52 -0400636 switch (bfin_mem_access_type(addr, 2)) {
637 case BFIN_MEM_ACCESS_CORE:
638 case BFIN_MEM_ACCESS_CORE_ONLY:
639 *val = *address;
640 return true;
641 case BFIN_MEM_ACCESS_DMA:
642 dma_memcpy(val, address, 2);
643 return true;
644 case BFIN_MEM_ACCESS_ITEST:
645 isram_memcpy(val, address, 2);
646 return true;
647 default: /* invalid access */
648 return false;
Robin Getzf09630b2008-07-26 19:45:46 +0800649 }
Robin Getzf09630b2008-07-26 19:45:46 +0800650}
651
Mike Frysinger36f649a2008-11-18 17:48:22 +0800652/*
Robin Getzd3d0ac22008-08-06 17:49:27 +0800653 * decode the instruction if we are printing out the trace, as it
654 * makes things easier to follow, without running it through objdump
655 * These are the normal instructions which cause change of flow, which
656 * would be at the source of the trace buffer
657 */
Mike Frysinger36f649a2008-11-18 17:48:22 +0800658#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800659static void decode_instruction(unsigned short *address)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800660{
661 unsigned short opcode;
662
663 if (get_instruction(&opcode, address)) {
664 if (opcode == 0x0010)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800665 verbose_printk("RTS");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800666 else if (opcode == 0x0011)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800667 verbose_printk("RTI");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800668 else if (opcode == 0x0012)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800669 verbose_printk("RTX");
Robin Getz0be58932009-02-04 16:49:45 +0800670 else if (opcode == 0x0013)
671 verbose_printk("RTN");
672 else if (opcode == 0x0014)
673 verbose_printk("RTE");
674 else if (opcode == 0x0025)
675 verbose_printk("EMUEXCPT");
676 else if (opcode == 0x0040 && opcode <= 0x0047)
677 verbose_printk("STI R%i", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800678 else if (opcode >= 0x0050 && opcode <= 0x0057)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800679 verbose_printk("JUMP (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800680 else if (opcode >= 0x0060 && opcode <= 0x0067)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800681 verbose_printk("CALL (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800682 else if (opcode >= 0x0070 && opcode <= 0x0077)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800683 verbose_printk("CALL (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800684 else if (opcode >= 0x0080 && opcode <= 0x0087)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800685 verbose_printk("JUMP (PC+P%i)", opcode & 7);
Robin Getz0be58932009-02-04 16:49:45 +0800686 else if (opcode >= 0x0090 && opcode <= 0x009F)
687 verbose_printk("RAISE 0x%x", opcode & 0xF);
688 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
689 verbose_printk("EXCPT 0x%x", opcode & 0xF);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800690 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
Robin Getz9f06c38f2008-10-10 18:13:21 +0800691 verbose_printk("IF !CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800692 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
Robin Getz9f06c38f2008-10-10 18:13:21 +0800693 verbose_printk("IF CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800694 else if (opcode >= 0x2000 && opcode <= 0x2fff)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800695 verbose_printk("JUMP.S");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800696 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800697 verbose_printk("LSETUP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800698 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800699 verbose_printk("JUMP.L");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800700 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800701 verbose_printk("CALL pcrel");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800702 else
Robin Getz9f06c38f2008-10-10 18:13:21 +0800703 verbose_printk("0x%04x", opcode);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800704 }
705
706}
Robin Getz9f06c38f2008-10-10 18:13:21 +0800707#endif
Robin Getzd3d0ac22008-08-06 17:49:27 +0800708
Bryan Wu1394f032007-05-06 14:50:22 -0700709void dump_bfin_trace_buffer(void)
710{
Robin Getz9f06c38f2008-10-10 18:13:21 +0800711#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz518039b2007-07-25 11:03:28 +0800712#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
713 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800714 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800715 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800716#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
717 int j, index;
718#endif
719
Bryan Wu1394f032007-05-06 14:50:22 -0700720 trace_buffer_save(tflags);
721
Robin Getz226eb1e2007-10-29 17:59:07 +0800722 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800723
Robin Getzd3d0ac22008-08-06 17:49:27 +0800724#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
725 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
726#endif
727
Bryan Wu1394f032007-05-06 14:50:22 -0700728 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800729 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800730 decode_address(buf, (unsigned long)bfin_read_TBUF());
731 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800732 addr = (unsigned short *)bfin_read_TBUF();
733 decode_address(buf, (unsigned long)addr);
734 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800735 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800736 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700737 }
738 }
739
Robin Getz518039b2007-07-25 11:03:28 +0800740#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
741 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800742 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800743 else
744 index = EXPAND_LEN;
745
746 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
747 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800748 decode_address(buf, software_trace_buff[index]);
749 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800750 index -= 1;
751 if (index < 0 )
752 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800753 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800754 printk(KERN_NOTICE " Source : %s ", buf);
755 decode_instruction((unsigned short *)software_trace_buff[index]);
756 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800757 index -= 1;
758 if (index < 0)
759 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800760 j--;
761 i++;
762 }
763#endif
764
Bryan Wu1394f032007-05-06 14:50:22 -0700765 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800766#endif
Robin Getz9f06c38f2008-10-10 18:13:21 +0800767#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700768}
769EXPORT_SYMBOL(dump_bfin_trace_buffer);
770
Mike Frysinger70f12562009-06-07 17:18:25 -0400771#ifdef CONFIG_BUG
772int is_valid_bugaddr(unsigned long addr)
773{
774 unsigned short opcode;
775
776 if (!get_instruction(&opcode, (unsigned short *)addr))
777 return 0;
778
779 return opcode == BFIN_BUG_OPCODE;
780}
781#endif
782
Robin Getzf09630b2008-07-26 19:45:46 +0800783/*
784 * Checks to see if the address pointed to is either a
785 * 16-bit CALL instruction, or a 32-bit CALL instruction
786 */
Robin Getz9f06c38f2008-10-10 18:13:21 +0800787static bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700788{
Robin Getzf09630b2008-07-26 19:45:46 +0800789 unsigned short opcode = 0, *ins_addr;
790 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700791
Robin Getzf09630b2008-07-26 19:45:46 +0800792 if (!get_instruction(&opcode, ins_addr))
793 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700794
Robin Getzf09630b2008-07-26 19:45:46 +0800795 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
796 (opcode >= 0x0070 && opcode <= 0x0077))
797 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700798
Robin Getzf09630b2008-07-26 19:45:46 +0800799 ins_addr--;
800 if (!get_instruction(&opcode, ins_addr))
801 return false;
802
803 if (opcode >= 0xE300 && opcode <= 0xE3FF)
804 return true;
805
806 return false;
807
Bryan Wu1394f032007-05-06 14:50:22 -0700808}
Robin Getz9f06c38f2008-10-10 18:13:21 +0800809
Bryan Wu1394f032007-05-06 14:50:22 -0700810void show_stack(struct task_struct *task, unsigned long *stack)
811{
Robin Getz9f06c38f2008-10-10 18:13:21 +0800812#ifdef CONFIG_PRINTK
Robin Getzf09630b2008-07-26 19:45:46 +0800813 unsigned int *addr, *endstack, *fp = 0, *frame;
814 unsigned short *ins_addr;
815 char buf[150];
816 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700817
Robin Getzf09630b2008-07-26 19:45:46 +0800818 /*
819 * If we have been passed a specific stack, use that one otherwise
820 * if we have been passed a task structure, use that, otherwise
821 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700822 */
823
Robin Getzf09630b2008-07-26 19:45:46 +0800824 if (stack == NULL) {
825 if (task) {
826 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700827 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800828 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
829 } else {
830 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700831 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800832 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
833 }
834 } else
835 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
836
Robin Getz9f06c38f2008-10-10 18:13:21 +0800837 printk(KERN_NOTICE "Stack info:\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800838 decode_address(buf, (unsigned int)stack);
Robin Getz9f06c38f2008-10-10 18:13:21 +0800839 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
840
Robin Getza0cab652009-05-11 18:34:41 +0000841 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
842 printk(KERN_NOTICE "Invalid stack pointer\n");
843 return;
844 }
845
Robin Getzf09630b2008-07-26 19:45:46 +0800846 /* First thing is to look for a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800847 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800848 if (*addr & 0x1)
849 continue;
850 ins_addr = (unsigned short *)*addr;
851 ins_addr--;
852 if (is_bfin_call(ins_addr))
853 fp = addr - 1;
854
855 if (fp) {
856 /* Let's check to see if it is a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800857 while (fp >= (addr - 1) && fp < endstack
858 && fp && ((unsigned int) fp & 0x3) == 0)
Robin Getzf09630b2008-07-26 19:45:46 +0800859 fp = (unsigned int *)*fp;
860 if (fp == 0 || fp == endstack) {
861 fp = addr - 1;
862 break;
863 }
864 fp = 0;
865 }
866 }
867 if (fp) {
868 frame = fp;
Jie Zhangb339dc72009-01-07 23:14:39 +0800869 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
Robin Getzf09630b2008-07-26 19:45:46 +0800870 } else
871 frame = 0;
872
873 /*
874 * Now that we think we know where things are, we
875 * walk the stack again, this time printing things out
876 * incase there is no frame pointer, we still look for
877 * valid return addresses
878 */
879
880 /* First time print out data, next time, print out symbols */
881 for (j = 0; j <= 1; j++) {
882 if (j)
883 printk(KERN_NOTICE "Return addresses in stack:\n");
884 else
885 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
886
887 fp = frame;
888 frame_no = 0;
889
890 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
Sonic Zhang407505d2009-07-16 10:36:35 +0000891 addr < endstack; addr++, i++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800892
893 ret_addr = 0;
894 if (!j && i % 8 == 0)
Joe Perchesad361c92009-07-06 13:05:40 -0700895 printk(KERN_NOTICE "%p:",addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800896
897 /* if it is an odd address, or zero, just skip it */
898 if (*addr & 0x1 || !*addr)
899 goto print;
900
901 ins_addr = (unsigned short *)*addr;
902
903 /* Go back one instruction, and see if it is a CALL */
904 ins_addr--;
905 ret_addr = is_bfin_call(ins_addr);
906 print:
907 if (!j && stack == (unsigned long *)addr)
908 printk("[%08x]", *addr);
909 else if (ret_addr)
910 if (j) {
911 decode_address(buf, (unsigned int)*addr);
912 if (frame == addr) {
913 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
914 continue;
915 }
916 printk(KERN_NOTICE " address : %s\n", buf);
917 } else
918 printk("<%08x>", *addr);
919 else if (fp == addr) {
920 if (j)
921 frame = addr+1;
922 else
923 printk("(%08x)", *addr);
924
925 fp = (unsigned int *)*addr;
926 frame_no++;
927
928 } else if (!j)
929 printk(" %08x ", *addr);
930 }
931 if (!j)
932 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700933 }
Robin Getz9f06c38f2008-10-10 18:13:21 +0800934#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700935}
Philippe Gerumbc569f12009-06-22 18:23:12 +0200936EXPORT_SYMBOL(show_stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700937
938void dump_stack(void)
939{
940 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800941#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700942 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800943#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700944 trace_buffer_save(tflags);
945 dump_bfin_trace_buffer();
946 show_stack(current, &stack);
947 trace_buffer_restore(tflags);
948}
Bryan Wu1394f032007-05-06 14:50:22 -0700949EXPORT_SYMBOL(dump_stack);
950
Mike Frysinger49dce912007-11-21 16:46:49 +0800951void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700952{
Robin Getz9f06c38f2008-10-10 18:13:21 +0800953#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +0800954 /* We should be able to look at fp->ipend, but we don't push it on the
955 * stack all the time, so do this until we fix that */
956 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800957
Mike Frysinger49dce912007-11-21 16:46:49 +0800958 if (oops_in_progress)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800959 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800960
Robin Getzb03b08b2007-12-23 22:57:01 +0800961 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800962 verbose_printk(KERN_NOTICE "HW Error context\n");
Robin Getzb03b08b2007-12-23 22:57:01 +0800963 else if (context & 0x0020)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800964 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800965 else if (context & 0x3FC0)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800966 verbose_printk(KERN_NOTICE "Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800967 else if (context & 0x4000)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800968 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800969 else if (context & 0x8000)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800970 verbose_printk(KERN_NOTICE "Kernel process context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800971
Robin Getz9a62ca42008-03-26 09:15:58 +0800972 /* Because we are crashing, and pointers could be bad, we check things
973 * pretty closely before we use them
974 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800975 if ((unsigned long)current >= FIXED_CODE_START &&
976 !((unsigned long)current & 0x3) && current->pid) {
Robin Getz9f06c38f2008-10-10 18:13:21 +0800977 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800978 if (current->comm >= (char *)FIXED_CODE_START)
Robin Getz9f06c38f2008-10-10 18:13:21 +0800979 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
Robin Getz9a62ca42008-03-26 09:15:58 +0800980 current->comm, current->pid);
981 else
Robin Getz9f06c38f2008-10-10 18:13:21 +0800982 verbose_printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800983
Graf Yang8f658732008-11-18 17:48:22 +0800984 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
Robin Getz9a62ca42008-03-26 09:15:58 +0800985 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
Joe Perchesad361c92009-07-06 13:05:40 -0700986 verbose_printk(KERN_NOTICE
987 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
988 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
Robin Getz9a62ca42008-03-26 09:15:58 +0800989 (void *)current->mm->start_code,
990 (void *)current->mm->end_code,
991 (void *)current->mm->start_data,
992 (void *)current->mm->end_data,
993 (void *)current->mm->end_data,
994 (void *)current->mm->brk,
995 (void *)current->mm->start_stack);
996 else
Robin Getz9f06c38f2008-10-10 18:13:21 +0800997 verbose_printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800998 } else
Joe Perchesad361c92009-07-06 13:05:40 -0700999 verbose_printk(KERN_NOTICE
1000 "No Valid process in current context\n");
Robin Getz9f06c38f2008-10-10 18:13:21 +08001001#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001002}
1003
Robin Getzb03b08b2007-12-23 22:57:01 +08001004void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +08001005{
Robin Getz9f06c38f2008-10-10 18:13:21 +08001006#ifdef CONFIG_DEBUG_VERBOSE
Robin Getzb03b08b2007-12-23 22:57:01 +08001007 unsigned short *addr, *erraddr, val = 0, err = 0;
1008 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -07001009
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001010 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +08001011
Robin Getz9f06c38f2008-10-10 18:13:21 +08001012 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001013
1014 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1015 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1016 addr++) {
1017 if (!((unsigned long)addr & 0xF))
Joe Perchesad361c92009-07-06 13:05:40 -07001018 verbose_printk(KERN_NOTICE "0x%p: ", addr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001019
Robin Getz7d98c882008-10-08 16:29:01 +08001020 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +08001021 val = 0;
1022 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +08001023 } else
1024 sprintf(buf, "%04x", val);
1025
1026 if (addr == erraddr) {
Robin Getz9f06c38f2008-10-10 18:13:21 +08001027 verbose_printk("[%s]", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001028 err = val;
1029 } else
Robin Getz9f06c38f2008-10-10 18:13:21 +08001030 verbose_printk(" %s ", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001031
1032 /* Do any previous instructions turn on interrupts? */
1033 if (addr <= erraddr && /* in the past */
1034 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1035 val == 0x017b)) /* [SP++] = RETI */
1036 sti = 1;
1037 }
1038
Robin Getz9f06c38f2008-10-10 18:13:21 +08001039 verbose_printk("\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001040
1041 /* Hardware error interrupts can be deferred */
1042 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1043 oops_in_progress)){
Robin Getz9f06c38f2008-10-10 18:13:21 +08001044 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001045#ifndef CONFIG_DEBUG_HWERR
Joe Perchesad361c92009-07-06 13:05:40 -07001046 verbose_printk(KERN_NOTICE
1047"The remaining message may be meaningless\n"
1048"You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001049#else
1050 /* If we are handling only one peripheral interrupt
1051 * and current mm and pid are valid, and the last error
1052 * was in that user space process's text area
1053 * print it out - because that is where the problem exists
1054 */
1055 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1056 (current->pid && current->mm)) {
1057 /* And the last RETI points to the current userspace context */
1058 if ((fp + 1)->pc >= current->mm->start_code &&
1059 (fp + 1)->pc <= current->mm->end_code) {
Robin Getz9f06c38f2008-10-10 18:13:21 +08001060 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1061 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001062 show_regs(fp + 1);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001063 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001064 }
Bryan Wu1394f032007-05-06 14:50:22 -07001065 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001066#endif
1067 }
Robin Getz9f06c38f2008-10-10 18:13:21 +08001068#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001069}
1070
1071void show_regs(struct pt_regs *fp)
1072{
Robin Getz9f06c38f2008-10-10 18:13:21 +08001073#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001074 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001075 struct irqaction *action;
1076 unsigned int i;
Robin Getz2f95d5b2009-02-04 16:49:45 +08001077 unsigned long flags = 0;
Yi Lib6dbde22009-08-20 04:17:47 +00001078 unsigned int cpu = raw_smp_processor_id();
Robin Getz2f95d5b2009-02-04 16:49:45 +08001079 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -07001080
Robin Getz9ba3c242009-05-20 21:19:21 +00001081 verbose_printk(KERN_NOTICE "\n");
1082 if (CPUID != bfin_cpuid())
1083 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1084 "but running on:0x%04x (Rev %d)\n",
1085 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1086
1087 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1088 CPU, bfin_compiled_revid());
1089
1090 if (bfin_compiled_revid() != bfin_revid())
1091 verbose_printk("(Detected 0.%d)", bfin_revid());
1092
1093 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1094 get_cclk()/1000000, get_sclk()/1000000,
1095#ifdef CONFIG_MPU
1096 "mpu on"
1097#else
1098 "mpu off"
1099#endif
1100 );
1101
1102 verbose_printk(KERN_NOTICE "%s", linux_banner);
1103
Robin Getzae4f0732009-06-22 02:02:16 +00001104 verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
1105 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
Yi Lib6dbde22009-08-20 04:17:47 +00001106 (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
Robin Getzae4f0732009-06-22 02:02:16 +00001107 if (fp->ipend & EVT_IRPTEN)
1108 verbose_printk(KERN_NOTICE " Global Interrupts Disabled (IPEND[4])\n");
Yi Lib6dbde22009-08-20 04:17:47 +00001109 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
Robin Getzae4f0732009-06-22 02:02:16 +00001110 EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
1111 verbose_printk(KERN_NOTICE " Peripheral interrupts masked off\n");
Yi Lib6dbde22009-08-20 04:17:47 +00001112 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
Robin Getzae4f0732009-06-22 02:02:16 +00001113 verbose_printk(KERN_NOTICE " Kernel interrupts masked off\n");
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001114 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
Robin Getz9f06c38f2008-10-10 18:13:21 +08001115 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001116 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1117#ifdef EBIU_ERRMST
1118 /* If the error was from the EBIU, print it out */
1119 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
Robin Getz9f06c38f2008-10-10 18:13:21 +08001120 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001121 bfin_read_EBIU_ERRMST());
Robin Getz9f06c38f2008-10-10 18:13:21 +08001122 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001123 bfin_read_EBIU_ERRADD());
1124 }
1125#endif
1126 }
Robin Getz9f06c38f2008-10-10 18:13:21 +08001127 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
Robin Getz13fe24f2008-01-27 15:38:56 +08001128 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getz2f95d5b2009-02-04 16:49:45 +08001129 for (i = 2; i <= 15 ; i++) {
Robin Getzd8f66c82007-12-24 15:27:56 +08001130 if (fp->ipend & (1 << i)) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001131 if (i != 4) {
1132 decode_address(buf, bfin_read32(EVT0 + 4*i));
1133 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1134 } else
1135 verbose_printk(KERN_NOTICE " interrupts disabled\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001136 }
1137 }
1138
1139 /* if no interrupts are going off, don't print this out */
1140 if (fp->ipend & ~0x3F) {
1141 for (i = 0; i < (NR_IRQS - 1); i++) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001142 if (!in_atomic)
1143 spin_lock_irqsave(&irq_desc[i].lock, flags);
1144
Robin Getzd8f66c82007-12-24 15:27:56 +08001145 action = irq_desc[i].action;
1146 if (!action)
1147 goto unlock;
1148
1149 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001150 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001151 for (action = action->next; action; action = action->next) {
1152 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001153 verbose_printk(", %s", buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001154 }
Robin Getz9f06c38f2008-10-10 18:13:21 +08001155 verbose_printk("\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001156unlock:
Robin Getz2f95d5b2009-02-04 16:49:45 +08001157 if (!in_atomic)
1158 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Robin Getzd8f66c82007-12-24 15:27:56 +08001159 }
1160 }
Bryan Wu1394f032007-05-06 14:50:22 -07001161
Robin Getz226eb1e2007-10-29 17:59:07 +08001162 decode_address(buf, fp->rete);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001163 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001164 decode_address(buf, fp->retn);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001165 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001166 decode_address(buf, fp->retx);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001167 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001168 decode_address(buf, fp->rets);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001169 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001170 decode_address(buf, fp->pc);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001171 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001172
Robin Getz13fe24f2008-01-27 15:38:56 +08001173 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1174 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Graf Yang8f658732008-11-18 17:48:22 +08001175 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001176 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +08001177 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001178 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001179 }
1180
Joe Perchesad361c92009-07-06 13:05:40 -07001181 verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
Robin Getz9f06c38f2008-10-10 18:13:21 +08001182 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001183 fp->r0, fp->r1, fp->r2, fp->r3);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001184 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001185 fp->r4, fp->r5, fp->r6, fp->r7);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001186 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001187 fp->p0, fp->p1, fp->p2, fp->p3);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001188 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001189 fp->p4, fp->p5, fp->fp, (long)fp);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001190 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001191 fp->lb0, fp->lt0, fp->lc0);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001192 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001193 fp->lb1, fp->lt1, fp->lc1);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001194 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001195 fp->b0, fp->l0, fp->m0, fp->i0);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001196 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001197 fp->b1, fp->l1, fp->m1, fp->i1);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001198 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001199 fp->b2, fp->l2, fp->m2, fp->i2);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001200 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001201 fp->b3, fp->l3, fp->m3, fp->i3);
Robin Getz9f06c38f2008-10-10 18:13:21 +08001202 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001203 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1204
Robin Getz9f06c38f2008-10-10 18:13:21 +08001205 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001206 rdusp(), fp->astat);
1207
Robin Getz9f06c38f2008-10-10 18:13:21 +08001208 verbose_printk(KERN_NOTICE "\n");
1209#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001210}
1211
1212#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1213asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1214#endif
1215
Graf Yang8f658732008-11-18 17:48:22 +08001216static DEFINE_SPINLOCK(bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001217
Graf Yang8f658732008-11-18 17:48:22 +08001218asmlinkage int sys_bfin_spinlock(int *p)
1219{
1220 int ret, tmp = 0;
1221
1222 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1223 ret = get_user(tmp, p);
1224 if (likely(ret == 0)) {
1225 if (unlikely(tmp))
Bryan Wu1394f032007-05-06 14:50:22 -07001226 ret = 1;
Graf Yang8f658732008-11-18 17:48:22 +08001227 else
1228 put_user(1, p);
Bryan Wu1394f032007-05-06 14:50:22 -07001229 }
Graf Yang8f658732008-11-18 17:48:22 +08001230 spin_unlock(&bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001231 return ret;
1232}
1233
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001234int bfin_request_exception(unsigned int exception, void (*handler)(void))
1235{
1236 void (*curr_handler)(void);
1237
1238 if (exception > 0x3F)
1239 return -EINVAL;
1240
1241 curr_handler = ex_table[exception];
1242
1243 if (curr_handler != ex_replaceable)
1244 return -EBUSY;
1245
1246 ex_table[exception] = handler;
1247
1248 return 0;
1249}
1250EXPORT_SYMBOL(bfin_request_exception);
1251
1252int bfin_free_exception(unsigned int exception, void (*handler)(void))
1253{
1254 void (*curr_handler)(void);
1255
1256 if (exception > 0x3F)
1257 return -EINVAL;
1258
1259 curr_handler = ex_table[exception];
1260
1261 if (curr_handler != handler)
1262 return -EBUSY;
1263
1264 ex_table[exception] = ex_replaceable;
1265
1266 return 0;
1267}
1268EXPORT_SYMBOL(bfin_free_exception);
1269
Bryan Wu1394f032007-05-06 14:50:22 -07001270void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1271{
1272 switch (cplb_panic) {
1273 case CPLB_NO_UNLOCKED:
1274 printk(KERN_EMERG "All CPLBs are locked\n");
1275 break;
1276 case CPLB_PROT_VIOL:
1277 return;
1278 case CPLB_NO_ADDR_MATCH:
1279 return;
1280 case CPLB_UNKNOWN_ERR:
1281 printk(KERN_EMERG "Unknown CPLB Exception\n");
1282 break;
1283 }
1284
Robin Getz226eb1e2007-10-29 17:59:07 +08001285 oops_in_progress = 1;
1286
Mike Frysinger49dce912007-11-21 16:46:49 +08001287 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001288 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001289 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001290 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +00001291 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -07001292}