blob: 427294c47f1b19ff1c1ef308b5184a62d973082b [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 Getz9f06c382008-10-10 18:13:21 +080041
Robin Getz4ee1c452008-10-28 11:36:11 +080042#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-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 Getz9f06c382008-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
Robin Getzdbc5e692009-11-05 15:44:44 +0000122 /*
123 * Don't walk any of the vmas if we are oopsing, it has been known
124 * to cause problems - corrupt vmas (kernel crashes) cause double faults
125 */
126 if (oops_in_progress) {
127 strcat(buf, "/* kernel dynamic memory (maybe user-space) */");
128 return;
129 }
130
Bryan Wu1394f032007-05-06 14:50:22 -0700131 /* looks like we're off in user-land, so let's walk all the
132 * mappings of all our processes and see if we can't be a whee
133 * bit more specific
134 */
Robin Getz885be032007-10-29 17:20:41 +0800135 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700136 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800137 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700138 if (!mm)
139 continue;
140
David Howells8feae132009-01-08 12:04:47 +0000141 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
142 struct vm_area_struct *vma;
143
144 vma = rb_entry(n, struct vm_area_struct, vm_rb);
Bryan Wu1394f032007-05-06 14:50:22 -0700145
146 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800147 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700148 char *name = p->comm;
149 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800150
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800151 if (file) {
152 char *d_name = d_path(&file->f_path, _tmpbuf,
Jan Blunckcf28b482008-02-14 19:38:44 -0800153 sizeof(_tmpbuf));
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800154 if (!IS_ERR(d_name))
155 name = d_name;
156 }
Bryan Wu1394f032007-05-06 14:50:22 -0700157
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800158 /* FLAT does not have its text aligned to the start of
159 * the map while FDPIC ELF does ...
160 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800161
Robin Getz7f1c9062008-04-25 03:36:31 +0800162 /* before we can check flat/fdpic, we need to
163 * make sure current is valid
164 */
165 if ((unsigned long)current >= FIXED_CODE_START &&
166 !((unsigned long)current & 0x3)) {
167 if (current->mm &&
168 (address > current->mm->start_code) &&
169 (address < current->mm->end_code))
170 offset = address - current->mm->start_code;
171 else
172 offset = (address - vma->vm_start) +
173 (vma->vm_pgoff << PAGE_SHIFT);
174
Mike Frysinger18070dd2009-06-23 20:17:21 +0000175 sprintf(buf, "[ %s + 0x%lx ]", name, offset);
Robin Getz7f1c9062008-04-25 03:36:31 +0800176 } else
Mike Frysinger18070dd2009-06-23 20:17:21 +0000177 sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
178 name, vma->vm_start, vma->vm_end);
Robin Getz7f1c9062008-04-25 03:36:31 +0800179
Robin Getz904656c2008-03-26 09:17:43 +0800180 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800181 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800182
Mike Frysinger18070dd2009-06-23 20:17:21 +0000183 if (buf[0] == '\0')
184 sprintf(buf, "[ %s ] dynamic memory", name);
Robin Getzf09630b2008-07-26 19:45:46 +0800185
Robin Getz885be032007-10-29 17:20:41 +0800186 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700187 }
Bryan Wu1394f032007-05-06 14:50:22 -0700188 }
Robin Getz904656c2008-03-26 09:17:43 +0800189 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800190 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700191 }
Bryan Wu1394f032007-05-06 14:50:22 -0700192
193 /* we were unable to find this address anywhere */
Mike Frysinger18070dd2009-06-23 20:17:21 +0000194 sprintf(buf, "/* kernel dynamic memory */");
Robin Getz885be032007-10-29 17:20:41 +0800195
196done:
197 write_unlock_irqrestore(&tasklist_lock, flags);
Robin Getz9f06c382008-10-10 18:13:21 +0800198#else
199 sprintf(buf, " ");
200#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700201}
202
Robin Getz2ebcade2007-10-09 17:24:30 +0800203asmlinkage void double_fault_c(struct pt_regs *fp)
204{
Robin Getza0cab652009-05-11 18:34:41 +0000205#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
206 int j;
207 trace_buffer_save(j);
208#endif
209
Robin Getz226eb1e2007-10-29 17:59:07 +0800210 console_verbose();
211 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800212#ifdef CONFIG_DEBUG_VERBOSE
Joe Perchesad361c92009-07-06 13:05:40 -0700213 printk(KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800214#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
215 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
Yi Lib6dbde22009-08-20 04:17:47 +0000216 unsigned int cpu = raw_smp_processor_id();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800217 char buf[150];
Graf Yang01b9f4b2009-07-22 11:56:24 +0000218 decode_address(buf, cpu_pda[cpu].retx_doublefault);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800219 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
Graf Yang01b9f4b2009-07-22 11:56:24 +0000220 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
221 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800222 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang01b9f4b2009-07-22 11:56:24 +0000223 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800224 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
225
226 decode_address(buf, fp->retx);
Graf Yang8f658732008-11-18 17:48:22 +0800227 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800228 } else
229#endif
230 {
231 dump_bfin_process(fp);
232 dump_bfin_mem(fp);
233 show_regs(fp);
Robin Getza0cab652009-05-11 18:34:41 +0000234 dump_bfin_trace_buffer();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800235 }
Robin Getz9f06c382008-10-10 18:13:21 +0800236#endif
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000237 panic("Double Fault - unrecoverable event");
Robin Getz2ebcade2007-10-09 17:24:30 +0800238
239}
240
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400241static int kernel_mode_regs(struct pt_regs *regs)
242{
243 return regs->ipend & 0xffc0;
244}
245
Yi Lic4baebf2009-08-12 23:05:35 +0000246asmlinkage notrace void trap_c(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700247{
Robin Getz518039b2007-07-25 11:03:28 +0800248#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
249 int j;
250#endif
Graf Yang8f658732008-11-18 17:48:22 +0800251#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Yi Lib6dbde22009-08-20 04:17:47 +0000252 unsigned int cpu = raw_smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800253#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400254 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +0800255 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700256 siginfo_t info;
257 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
258
Bryan Wu1394f032007-05-06 14:50:22 -0700259 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +0000260#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
261 last_seqstat = (u32)fp->seqstat;
262#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700263
Robin Getz226eb1e2007-10-29 17:59:07 +0800264 /* Important - be very careful dereferncing pointers - will lead to
265 * double faults if the stack has become corrupt
266 */
267
Bryan Wu1394f032007-05-06 14:50:22 -0700268 /* 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
271 */
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); */
275
276 /* send the appropriate signal to the user program */
277 switch (trapnr) {
278
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
284 * here
285 */
286
287 /* 0x00 - Linux Syscall, getting here is an error */
288 /* 0x01 - userspace gdb breakpoint, handled here */
289 case VEC_EXCPT01:
290 info.si_code = TRAP_ILLTRAP;
291 sig = SIGTRAP;
292 CHK_DEBUGGER_TRAP_MAYBE();
293 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400294 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400295 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700296 else
297 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800298 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700299 case VEC_EXCPT03:
300 info.si_code = SEGV_STACKFLOW;
301 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400302 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800303 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700304 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800305 /* 0x02 - KGDB initial connection and break signal trap */
306 case VEC_EXCPT02:
307#ifdef CONFIG_KGDB
308 info.si_code = TRAP_ILLTRAP;
309 sig = SIGTRAP;
310 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400311 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800312#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800313 /* 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 */
Sonic Zhang27707d32008-10-09 14:04:41 +0800325 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800326 * custom exception handler, and it is not actually installed properly
327 */
328 case VEC_EXCPT04 ... VEC_EXCPT15:
329 info.si_code = ILL_ILLPARAOP;
330 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400331 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800332 CHK_DEBUGGER_TRAP_MAYBE();
333 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700334 /* 0x10 HW Single step, handled here */
335 case VEC_STEP:
336 info.si_code = TRAP_STEP;
337 sig = SIGTRAP;
338 CHK_DEBUGGER_TRAP_MAYBE();
339 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400340 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400341 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700342 else
343 break;
344 /* 0x11 - Trace Buffer Full, handled here */
345 case VEC_OVFLOW:
346 info.si_code = TRAP_TRACEFLOW;
347 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400348 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800349 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700350 break;
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 */
367 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400368#ifdef CONFIG_BUG
369 if (kernel_mode_regs(fp)) {
370 switch (report_bug(fp->pc, fp)) {
371 case BUG_TRAP_TYPE_NONE:
372 break;
373 case BUG_TRAP_TYPE_WARN:
374 dump_bfin_trace_buffer();
375 fp->pc += 2;
376 goto traps_done;
377 case BUG_TRAP_TYPE_BUG:
378 /* call to panic() will dump trace, and it is
379 * off at this point, so it won't be clobbered
380 */
381 panic("BUG()");
382 }
383 }
384#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700385 info.si_code = ILL_ILLOPC;
386 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400387 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800388 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700389 break;
390 /* 0x22 - Illegal Instruction Combination, handled here */
391 case VEC_ILGAL_I:
392 info.si_code = ILL_ILLPARAOP;
393 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400394 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800395 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700396 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800397 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700398 case VEC_CPLB_VL:
399 info.si_code = ILL_CPLB_VI;
Graf Yang36b84122009-07-21 02:26:57 +0000400 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400401 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800402 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700403 break;
404 /* 0x24 - Data access misaligned, handled here */
405 case VEC_MISALI_D:
406 info.si_code = BUS_ADRALN;
407 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400408 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800409 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700410 break;
411 /* 0x25 - Unrecoverable Event, handled here */
412 case VEC_UNCOV:
413 info.si_code = ILL_ILLEXCPT;
414 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400415 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800416 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700417 break;
418 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
419 error case is handled here */
420 case VEC_CPLB_M:
421 info.si_code = BUS_ADRALN;
422 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400423 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700424 break;
425 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
426 case VEC_CPLB_MHIT:
427 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700428 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800429#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800430 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400431 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800432 else
Bryan Wu1394f032007-05-06 14:50:22 -0700433#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400434 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800435 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700436 break;
437 /* 0x28 - Emulation Watchpoint, handled here */
438 case VEC_WATCH:
439 info.si_code = TRAP_WATCHPT;
440 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800441 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700442 CHK_DEBUGGER_TRAP_MAYBE();
443 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400444 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400445 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700446 else
447 break;
448#ifdef CONFIG_BF535
449 /* 0x29 - Instruction fetch access error (535 only) */
450 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
451 info.si_code = BUS_OPFETCH;
452 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400453 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800454 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700455 break;
456#else
457 /* 0x29 - Reserved, Caught by default */
458#endif
459 /* 0x2A - Instruction fetch misaligned, handled here */
460 case VEC_MISALI_I:
461 info.si_code = BUS_ADRALN;
462 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400463 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800464 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700465 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800466 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700467 case VEC_CPLB_I_VL:
468 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800469 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400470 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800471 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700472 break;
473 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
474 case VEC_CPLB_I_M:
475 info.si_code = ILL_CPLB_MISS;
476 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400477 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700478 break;
479 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
480 case VEC_CPLB_I_MHIT:
481 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700482 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800483#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800484 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400485 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800486 else
Bryan Wu1394f032007-05-06 14:50:22 -0700487#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400488 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800489 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700490 break;
491 /* 0x2E - Illegal use of Supervisor Resource, handled here */
492 case VEC_ILL_RES:
493 info.si_code = ILL_PRVOPC;
494 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400495 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800496 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700497 break;
498 /* 0x2F - Reserved, Caught by default */
499 /* 0x30 - Reserved, Caught by default */
500 /* 0x31 - Reserved, Caught by default */
501 /* 0x32 - Reserved, Caught by default */
502 /* 0x33 - Reserved, Caught by default */
503 /* 0x34 - Reserved, Caught by default */
504 /* 0x35 - Reserved, Caught by default */
505 /* 0x36 - Reserved, Caught by default */
506 /* 0x37 - Reserved, Caught by default */
507 /* 0x38 - Reserved, Caught by default */
508 /* 0x39 - Reserved, Caught by default */
509 /* 0x3A - Reserved, Caught by default */
510 /* 0x3B - Reserved, Caught by default */
511 /* 0x3C - Reserved, Caught by default */
512 /* 0x3D - Reserved, Caught by default */
513 /* 0x3E - Reserved, Caught by default */
514 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800515 case VEC_HWERR:
516 info.si_code = BUS_ADRALN;
517 sig = SIGBUS;
518 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
519 /* System MMR Error */
520 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
521 info.si_code = BUS_ADRALN;
522 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400523 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800524 break;
525 /* External Memory Addressing Error */
526 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
527 info.si_code = BUS_ADRERR;
528 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400529 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800530 break;
531 /* Performance Monitor Overflow */
532 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400533 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800534 break;
535 /* RAISE 5 instruction */
536 case (SEQSTAT_HWERRCAUSE_RAISE_5):
537 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
538 break;
539 default: /* Reserved */
540 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
541 break;
542 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800543 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800544 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800545 /*
546 * We should be handling all known exception types above,
547 * if we get here we hit a reserved one, so panic
548 */
Bryan Wu1394f032007-05-06 14:50:22 -0700549 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800550 info.si_code = ILL_ILLPARAOP;
551 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800552 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700553 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800554 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700555 break;
556 }
557
Robin Getz226eb1e2007-10-29 17:59:07 +0800558 BUG_ON(sig == 0);
559
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400560 /* If the fault was caused by a kernel thread, or interrupt handler
561 * we will kernel panic, so the system reboots.
562 */
563 if (kernel_mode_regs(fp) || (current && !current->mm)) {
564 console_verbose();
565 oops_in_progress = 1;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400566 }
567
Robin Getz226eb1e2007-10-29 17:59:07 +0800568 if (sig != SIGTRAP) {
Mike Frysinger15627bd2009-06-23 11:21:34 +0000569 if (strerror)
570 verbose_printk(strerror);
571
Mike Frysinger49dce912007-11-21 16:46:49 +0800572 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800573 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800574 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800575
576 /* Print out the trace buffer if it makes sense */
577#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
578 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800579 verbose_printk(KERN_NOTICE "No trace since you do not have "
Joe Perchesad361c92009-07-06 13:05:40 -0700580 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800581 else
582#endif
583 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800584
Robin Getz226eb1e2007-10-29 17:59:07 +0800585 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800586 /* Dump the current kernel stack */
Joe Perchesad361c92009-07-06 13:05:40 -0700587 verbose_printk(KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800588 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800589 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800590#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800591 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800592 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800593#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700594 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800595 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800596#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800597 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800598 /* Dump the user space stack */
599 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800600 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800601 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800602#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800603 }
Bryan Wu1394f032007-05-06 14:50:22 -0700604 }
Robin Getzfb322912007-11-21 16:38:05 +0800605
Yi Li6a01f232009-01-07 23:14:39 +0800606#ifdef CONFIG_IPIPE
607 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
608#endif
609 {
610 info.si_signo = sig;
611 info.si_errno = 0;
612 info.si_addr = (void __user *)fp->pc;
613 force_sig_info(sig, &info, current);
614 }
Bryan Wu1394f032007-05-06 14:50:22 -0700615
Robin Getz0e4edcf2009-06-22 20:23:48 +0000616 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
Robin Getzf574a762009-07-09 15:11:52 +0000617 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
618 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
Robin Getz0acad8d2009-05-11 18:55:16 +0000619 fp->pc = SAFE_USER_INSTRUCTION;
620
Mike Frysinger6510a202009-06-07 15:07:25 -0400621 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700622 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700623}
624
625/* Typical exception handling routines */
626
Robin Getz518039b2007-07-25 11:03:28 +0800627#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
628
Robin Getzf09630b2008-07-26 19:45:46 +0800629/*
630 * Similar to get_user, do some address checking, then dereference
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200631 * Return true on success, false on bad address
Robin Getzf09630b2008-07-26 19:45:46 +0800632 */
Robin Getz9f06c382008-10-10 18:13:21 +0800633static bool get_instruction(unsigned short *val, unsigned short *address)
Robin Getzf09630b2008-07-26 19:45:46 +0800634{
Mike Frysingere56e03b2009-06-07 16:31:52 -0400635 unsigned long addr = (unsigned long)address;
Robin Getzf09630b2008-07-26 19:45:46 +0800636
637 /* Check for odd addresses */
638 if (addr & 0x1)
639 return false;
640
Mike Frysingere56e03b2009-06-07 16:31:52 -0400641 /* MMR region will never have instructions */
642 if (addr >= SYSMMR_BASE)
Robin Getzf09630b2008-07-26 19:45:46 +0800643 return false;
644
Mike Frysingere56e03b2009-06-07 16:31:52 -0400645 switch (bfin_mem_access_type(addr, 2)) {
646 case BFIN_MEM_ACCESS_CORE:
647 case BFIN_MEM_ACCESS_CORE_ONLY:
648 *val = *address;
649 return true;
650 case BFIN_MEM_ACCESS_DMA:
651 dma_memcpy(val, address, 2);
652 return true;
653 case BFIN_MEM_ACCESS_ITEST:
654 isram_memcpy(val, address, 2);
655 return true;
656 default: /* invalid access */
657 return false;
Robin Getzf09630b2008-07-26 19:45:46 +0800658 }
Robin Getzf09630b2008-07-26 19:45:46 +0800659}
660
Mike Frysinger36f649a2008-11-18 17:48:22 +0800661/*
Robin Getzd3d0ac22008-08-06 17:49:27 +0800662 * decode the instruction if we are printing out the trace, as it
663 * makes things easier to follow, without running it through objdump
664 * These are the normal instructions which cause change of flow, which
665 * would be at the source of the trace buffer
666 */
Mike Frysinger36f649a2008-11-18 17:48:22 +0800667#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
Robin Getz9f06c382008-10-10 18:13:21 +0800668static void decode_instruction(unsigned short *address)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800669{
670 unsigned short opcode;
671
672 if (get_instruction(&opcode, address)) {
673 if (opcode == 0x0010)
Robin Getz9f06c382008-10-10 18:13:21 +0800674 verbose_printk("RTS");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800675 else if (opcode == 0x0011)
Robin Getz9f06c382008-10-10 18:13:21 +0800676 verbose_printk("RTI");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800677 else if (opcode == 0x0012)
Robin Getz9f06c382008-10-10 18:13:21 +0800678 verbose_printk("RTX");
Robin Getz0be58932009-02-04 16:49:45 +0800679 else if (opcode == 0x0013)
680 verbose_printk("RTN");
681 else if (opcode == 0x0014)
682 verbose_printk("RTE");
683 else if (opcode == 0x0025)
684 verbose_printk("EMUEXCPT");
685 else if (opcode == 0x0040 && opcode <= 0x0047)
686 verbose_printk("STI R%i", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800687 else if (opcode >= 0x0050 && opcode <= 0x0057)
Robin Getz9f06c382008-10-10 18:13:21 +0800688 verbose_printk("JUMP (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800689 else if (opcode >= 0x0060 && opcode <= 0x0067)
Robin Getz9f06c382008-10-10 18:13:21 +0800690 verbose_printk("CALL (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800691 else if (opcode >= 0x0070 && opcode <= 0x0077)
Robin Getz9f06c382008-10-10 18:13:21 +0800692 verbose_printk("CALL (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800693 else if (opcode >= 0x0080 && opcode <= 0x0087)
Robin Getz9f06c382008-10-10 18:13:21 +0800694 verbose_printk("JUMP (PC+P%i)", opcode & 7);
Robin Getz0be58932009-02-04 16:49:45 +0800695 else if (opcode >= 0x0090 && opcode <= 0x009F)
696 verbose_printk("RAISE 0x%x", opcode & 0xF);
697 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
698 verbose_printk("EXCPT 0x%x", opcode & 0xF);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800699 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
Robin Getz9f06c382008-10-10 18:13:21 +0800700 verbose_printk("IF !CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800701 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
Robin Getz9f06c382008-10-10 18:13:21 +0800702 verbose_printk("IF CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800703 else if (opcode >= 0x2000 && opcode <= 0x2fff)
Robin Getz9f06c382008-10-10 18:13:21 +0800704 verbose_printk("JUMP.S");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800705 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800706 verbose_printk("LSETUP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800707 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800708 verbose_printk("JUMP.L");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800709 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800710 verbose_printk("CALL pcrel");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800711 else
Robin Getz9f06c382008-10-10 18:13:21 +0800712 verbose_printk("0x%04x", opcode);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800713 }
714
715}
Robin Getz9f06c382008-10-10 18:13:21 +0800716#endif
Robin Getzd3d0ac22008-08-06 17:49:27 +0800717
Bryan Wu1394f032007-05-06 14:50:22 -0700718void dump_bfin_trace_buffer(void)
719{
Robin Getz9f06c382008-10-10 18:13:21 +0800720#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz518039b2007-07-25 11:03:28 +0800721#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
722 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800723 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800724 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800725#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
726 int j, index;
727#endif
728
Bryan Wu1394f032007-05-06 14:50:22 -0700729 trace_buffer_save(tflags);
730
Robin Getz226eb1e2007-10-29 17:59:07 +0800731 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800732
Robin Getzd3d0ac22008-08-06 17:49:27 +0800733#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
734 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
735#endif
736
Bryan Wu1394f032007-05-06 14:50:22 -0700737 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800738 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800739 decode_address(buf, (unsigned long)bfin_read_TBUF());
740 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800741 addr = (unsigned short *)bfin_read_TBUF();
742 decode_address(buf, (unsigned long)addr);
743 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800744 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800745 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700746 }
747 }
748
Robin Getz518039b2007-07-25 11:03:28 +0800749#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
750 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800751 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800752 else
753 index = EXPAND_LEN;
754
755 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
756 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800757 decode_address(buf, software_trace_buff[index]);
758 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800759 index -= 1;
760 if (index < 0 )
761 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800762 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800763 printk(KERN_NOTICE " Source : %s ", buf);
764 decode_instruction((unsigned short *)software_trace_buff[index]);
765 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800766 index -= 1;
767 if (index < 0)
768 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800769 j--;
770 i++;
771 }
772#endif
773
Bryan Wu1394f032007-05-06 14:50:22 -0700774 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800775#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800776#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700777}
778EXPORT_SYMBOL(dump_bfin_trace_buffer);
779
Mike Frysinger70f12562009-06-07 17:18:25 -0400780#ifdef CONFIG_BUG
781int is_valid_bugaddr(unsigned long addr)
782{
783 unsigned short opcode;
784
785 if (!get_instruction(&opcode, (unsigned short *)addr))
786 return 0;
787
788 return opcode == BFIN_BUG_OPCODE;
789}
790#endif
791
Robin Getzf09630b2008-07-26 19:45:46 +0800792/*
793 * Checks to see if the address pointed to is either a
794 * 16-bit CALL instruction, or a 32-bit CALL instruction
795 */
Robin Getz9f06c382008-10-10 18:13:21 +0800796static bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700797{
Robin Getzf09630b2008-07-26 19:45:46 +0800798 unsigned short opcode = 0, *ins_addr;
799 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700800
Robin Getzf09630b2008-07-26 19:45:46 +0800801 if (!get_instruction(&opcode, ins_addr))
802 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700803
Robin Getzf09630b2008-07-26 19:45:46 +0800804 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
805 (opcode >= 0x0070 && opcode <= 0x0077))
806 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700807
Robin Getzf09630b2008-07-26 19:45:46 +0800808 ins_addr--;
809 if (!get_instruction(&opcode, ins_addr))
810 return false;
811
812 if (opcode >= 0xE300 && opcode <= 0xE3FF)
813 return true;
814
815 return false;
816
Bryan Wu1394f032007-05-06 14:50:22 -0700817}
Robin Getz9f06c382008-10-10 18:13:21 +0800818
Bryan Wu1394f032007-05-06 14:50:22 -0700819void show_stack(struct task_struct *task, unsigned long *stack)
820{
Robin Getz9f06c382008-10-10 18:13:21 +0800821#ifdef CONFIG_PRINTK
Robin Getzf09630b2008-07-26 19:45:46 +0800822 unsigned int *addr, *endstack, *fp = 0, *frame;
823 unsigned short *ins_addr;
824 char buf[150];
825 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700826
Robin Getzf09630b2008-07-26 19:45:46 +0800827 /*
828 * If we have been passed a specific stack, use that one otherwise
829 * if we have been passed a task structure, use that, otherwise
830 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700831 */
832
Robin Getzf09630b2008-07-26 19:45:46 +0800833 if (stack == NULL) {
834 if (task) {
835 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700836 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800837 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
838 } else {
839 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700840 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800841 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
842 }
843 } else
844 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
845
Robin Getz9f06c382008-10-10 18:13:21 +0800846 printk(KERN_NOTICE "Stack info:\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800847 decode_address(buf, (unsigned int)stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800848 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
849
Robin Getza0cab652009-05-11 18:34:41 +0000850 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
851 printk(KERN_NOTICE "Invalid stack pointer\n");
852 return;
853 }
854
Robin Getzf09630b2008-07-26 19:45:46 +0800855 /* First thing is to look for a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800856 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800857 if (*addr & 0x1)
858 continue;
859 ins_addr = (unsigned short *)*addr;
860 ins_addr--;
861 if (is_bfin_call(ins_addr))
862 fp = addr - 1;
863
864 if (fp) {
865 /* Let's check to see if it is a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800866 while (fp >= (addr - 1) && fp < endstack
867 && fp && ((unsigned int) fp & 0x3) == 0)
Robin Getzf09630b2008-07-26 19:45:46 +0800868 fp = (unsigned int *)*fp;
869 if (fp == 0 || fp == endstack) {
870 fp = addr - 1;
871 break;
872 }
873 fp = 0;
874 }
875 }
876 if (fp) {
877 frame = fp;
Jie Zhangb339dc72009-01-07 23:14:39 +0800878 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
Robin Getzf09630b2008-07-26 19:45:46 +0800879 } else
880 frame = 0;
881
882 /*
883 * Now that we think we know where things are, we
884 * walk the stack again, this time printing things out
885 * incase there is no frame pointer, we still look for
886 * valid return addresses
887 */
888
889 /* First time print out data, next time, print out symbols */
890 for (j = 0; j <= 1; j++) {
891 if (j)
892 printk(KERN_NOTICE "Return addresses in stack:\n");
893 else
894 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
895
896 fp = frame;
897 frame_no = 0;
898
899 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
Sonic Zhang407505d2009-07-16 10:36:35 +0000900 addr < endstack; addr++, i++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800901
902 ret_addr = 0;
903 if (!j && i % 8 == 0)
Joe Perchesad361c92009-07-06 13:05:40 -0700904 printk(KERN_NOTICE "%p:",addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800905
906 /* if it is an odd address, or zero, just skip it */
907 if (*addr & 0x1 || !*addr)
908 goto print;
909
910 ins_addr = (unsigned short *)*addr;
911
912 /* Go back one instruction, and see if it is a CALL */
913 ins_addr--;
914 ret_addr = is_bfin_call(ins_addr);
915 print:
916 if (!j && stack == (unsigned long *)addr)
917 printk("[%08x]", *addr);
918 else if (ret_addr)
919 if (j) {
920 decode_address(buf, (unsigned int)*addr);
921 if (frame == addr) {
922 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
923 continue;
924 }
925 printk(KERN_NOTICE " address : %s\n", buf);
926 } else
927 printk("<%08x>", *addr);
928 else if (fp == addr) {
929 if (j)
930 frame = addr+1;
931 else
932 printk("(%08x)", *addr);
933
934 fp = (unsigned int *)*addr;
935 frame_no++;
936
937 } else if (!j)
938 printk(" %08x ", *addr);
939 }
940 if (!j)
941 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700942 }
Robin Getz9f06c382008-10-10 18:13:21 +0800943#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700944}
Philippe Gerumbc569f12009-06-22 18:23:12 +0200945EXPORT_SYMBOL(show_stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700946
947void dump_stack(void)
948{
949 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800950#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700951 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800952#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700953 trace_buffer_save(tflags);
954 dump_bfin_trace_buffer();
955 show_stack(current, &stack);
956 trace_buffer_restore(tflags);
957}
Bryan Wu1394f032007-05-06 14:50:22 -0700958EXPORT_SYMBOL(dump_stack);
959
Mike Frysinger49dce912007-11-21 16:46:49 +0800960void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700961{
Robin Getz9f06c382008-10-10 18:13:21 +0800962#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +0800963 /* We should be able to look at fp->ipend, but we don't push it on the
964 * stack all the time, so do this until we fix that */
965 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800966
Mike Frysinger49dce912007-11-21 16:46:49 +0800967 if (oops_in_progress)
Robin Getz9f06c382008-10-10 18:13:21 +0800968 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800969
Robin Getzb03b08b2007-12-23 22:57:01 +0800970 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
Robin Getz9f06c382008-10-10 18:13:21 +0800971 verbose_printk(KERN_NOTICE "HW Error context\n");
Robin Getzb03b08b2007-12-23 22:57:01 +0800972 else if (context & 0x0020)
Robin Getz9f06c382008-10-10 18:13:21 +0800973 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800974 else if (context & 0x3FC0)
Robin Getz9f06c382008-10-10 18:13:21 +0800975 verbose_printk(KERN_NOTICE "Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800976 else if (context & 0x4000)
Robin Getz9f06c382008-10-10 18:13:21 +0800977 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800978 else if (context & 0x8000)
Robin Getz9f06c382008-10-10 18:13:21 +0800979 verbose_printk(KERN_NOTICE "Kernel process context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800980
Robin Getz9a62ca42008-03-26 09:15:58 +0800981 /* Because we are crashing, and pointers could be bad, we check things
982 * pretty closely before we use them
983 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800984 if ((unsigned long)current >= FIXED_CODE_START &&
985 !((unsigned long)current & 0x3) && current->pid) {
Robin Getz9f06c382008-10-10 18:13:21 +0800986 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800987 if (current->comm >= (char *)FIXED_CODE_START)
Mike Frysinger13a13202009-10-22 10:14:53 +0000988 verbose_printk(KERN_NOTICE "COMM=%s PID=%d",
Robin Getz9a62ca42008-03-26 09:15:58 +0800989 current->comm, current->pid);
990 else
Mike Frysinger13a13202009-10-22 10:14:53 +0000991 verbose_printk(KERN_NOTICE "COMM= invalid");
Mike Frysinger49dce912007-11-21 16:46:49 +0800992
Mike Frysinger13a13202009-10-22 10:14:53 +0000993 printk(KERN_CONT " CPU=%d\n", current_thread_info()->cpu);
Robin Getz9a62ca42008-03-26 09:15:58 +0800994 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
Joe Perchesad361c92009-07-06 13:05:40 -0700995 verbose_printk(KERN_NOTICE
996 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
997 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
Robin Getz9a62ca42008-03-26 09:15:58 +0800998 (void *)current->mm->start_code,
999 (void *)current->mm->end_code,
1000 (void *)current->mm->start_data,
1001 (void *)current->mm->end_data,
1002 (void *)current->mm->end_data,
1003 (void *)current->mm->brk,
1004 (void *)current->mm->start_stack);
1005 else
Robin Getz9f06c382008-10-10 18:13:21 +08001006 verbose_printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001007 } else
Joe Perchesad361c92009-07-06 13:05:40 -07001008 verbose_printk(KERN_NOTICE
1009 "No Valid process in current context\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001010#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001011}
1012
Robin Getzb03b08b2007-12-23 22:57:01 +08001013void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +08001014{
Robin Getz9f06c382008-10-10 18:13:21 +08001015#ifdef CONFIG_DEBUG_VERBOSE
Robin Getzb03b08b2007-12-23 22:57:01 +08001016 unsigned short *addr, *erraddr, val = 0, err = 0;
1017 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -07001018
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001019 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +08001020
Robin Getz9f06c382008-10-10 18:13:21 +08001021 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001022
1023 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1024 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1025 addr++) {
1026 if (!((unsigned long)addr & 0xF))
Joe Perchesad361c92009-07-06 13:05:40 -07001027 verbose_printk(KERN_NOTICE "0x%p: ", addr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001028
Robin Getz7d98c882008-10-08 16:29:01 +08001029 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +08001030 val = 0;
1031 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +08001032 } else
1033 sprintf(buf, "%04x", val);
1034
1035 if (addr == erraddr) {
Robin Getz9f06c382008-10-10 18:13:21 +08001036 verbose_printk("[%s]", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001037 err = val;
1038 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001039 verbose_printk(" %s ", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001040
1041 /* Do any previous instructions turn on interrupts? */
1042 if (addr <= erraddr && /* in the past */
1043 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1044 val == 0x017b)) /* [SP++] = RETI */
1045 sti = 1;
1046 }
1047
Robin Getz9f06c382008-10-10 18:13:21 +08001048 verbose_printk("\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001049
1050 /* Hardware error interrupts can be deferred */
1051 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1052 oops_in_progress)){
Robin Getz9f06c382008-10-10 18:13:21 +08001053 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001054#ifndef CONFIG_DEBUG_HWERR
Joe Perchesad361c92009-07-06 13:05:40 -07001055 verbose_printk(KERN_NOTICE
1056"The remaining message may be meaningless\n"
1057"You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001058#else
1059 /* If we are handling only one peripheral interrupt
1060 * and current mm and pid are valid, and the last error
1061 * was in that user space process's text area
1062 * print it out - because that is where the problem exists
1063 */
1064 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1065 (current->pid && current->mm)) {
1066 /* And the last RETI points to the current userspace context */
1067 if ((fp + 1)->pc >= current->mm->start_code &&
1068 (fp + 1)->pc <= current->mm->end_code) {
Robin Getz9f06c382008-10-10 18:13:21 +08001069 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1070 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001071 show_regs(fp + 1);
Robin Getz9f06c382008-10-10 18:13:21 +08001072 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001073 }
Bryan Wu1394f032007-05-06 14:50:22 -07001074 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001075#endif
1076 }
Robin Getz9f06c382008-10-10 18:13:21 +08001077#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001078}
1079
1080void show_regs(struct pt_regs *fp)
1081{
Robin Getz9f06c382008-10-10 18:13:21 +08001082#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001083 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001084 struct irqaction *action;
1085 unsigned int i;
Robin Getz2f95d5b2009-02-04 16:49:45 +08001086 unsigned long flags = 0;
Yi Lib6dbde22009-08-20 04:17:47 +00001087 unsigned int cpu = raw_smp_processor_id();
Robin Getz2f95d5b2009-02-04 16:49:45 +08001088 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -07001089
Robin Getz9ba3c242009-05-20 21:19:21 +00001090 verbose_printk(KERN_NOTICE "\n");
1091 if (CPUID != bfin_cpuid())
1092 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1093 "but running on:0x%04x (Rev %d)\n",
1094 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1095
1096 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1097 CPU, bfin_compiled_revid());
1098
1099 if (bfin_compiled_revid() != bfin_revid())
1100 verbose_printk("(Detected 0.%d)", bfin_revid());
1101
1102 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1103 get_cclk()/1000000, get_sclk()/1000000,
1104#ifdef CONFIG_MPU
1105 "mpu on"
1106#else
1107 "mpu off"
1108#endif
1109 );
1110
1111 verbose_printk(KERN_NOTICE "%s", linux_banner);
1112
Robin Getzae4f0732009-06-22 02:02:16 +00001113 verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
1114 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
Yi Lib6dbde22009-08-20 04:17:47 +00001115 (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
Robin Getzae4f0732009-06-22 02:02:16 +00001116 if (fp->ipend & EVT_IRPTEN)
1117 verbose_printk(KERN_NOTICE " Global Interrupts Disabled (IPEND[4])\n");
Yi Lib6dbde22009-08-20 04:17:47 +00001118 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
Robin Getzae4f0732009-06-22 02:02:16 +00001119 EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
1120 verbose_printk(KERN_NOTICE " Peripheral interrupts masked off\n");
Yi Lib6dbde22009-08-20 04:17:47 +00001121 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
Robin Getzae4f0732009-06-22 02:02:16 +00001122 verbose_printk(KERN_NOTICE " Kernel interrupts masked off\n");
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001123 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001124 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001125 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1126#ifdef EBIU_ERRMST
1127 /* If the error was from the EBIU, print it out */
1128 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001129 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001130 bfin_read_EBIU_ERRMST());
Robin Getz9f06c382008-10-10 18:13:21 +08001131 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001132 bfin_read_EBIU_ERRADD());
1133 }
1134#endif
1135 }
Robin Getz9f06c382008-10-10 18:13:21 +08001136 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
Robin Getz13fe24f2008-01-27 15:38:56 +08001137 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getz2f95d5b2009-02-04 16:49:45 +08001138 for (i = 2; i <= 15 ; i++) {
Robin Getzd8f66c82007-12-24 15:27:56 +08001139 if (fp->ipend & (1 << i)) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001140 if (i != 4) {
1141 decode_address(buf, bfin_read32(EVT0 + 4*i));
1142 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1143 } else
1144 verbose_printk(KERN_NOTICE " interrupts disabled\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001145 }
1146 }
1147
1148 /* if no interrupts are going off, don't print this out */
1149 if (fp->ipend & ~0x3F) {
1150 for (i = 0; i < (NR_IRQS - 1); i++) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001151 if (!in_atomic)
1152 spin_lock_irqsave(&irq_desc[i].lock, flags);
1153
Robin Getzd8f66c82007-12-24 15:27:56 +08001154 action = irq_desc[i].action;
1155 if (!action)
1156 goto unlock;
1157
1158 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001159 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001160 for (action = action->next; action; action = action->next) {
1161 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001162 verbose_printk(", %s", buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001163 }
Robin Getz9f06c382008-10-10 18:13:21 +08001164 verbose_printk("\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001165unlock:
Robin Getz2f95d5b2009-02-04 16:49:45 +08001166 if (!in_atomic)
1167 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Robin Getzd8f66c82007-12-24 15:27:56 +08001168 }
1169 }
Bryan Wu1394f032007-05-06 14:50:22 -07001170
Robin Getz226eb1e2007-10-29 17:59:07 +08001171 decode_address(buf, fp->rete);
Robin Getz9f06c382008-10-10 18:13:21 +08001172 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001173 decode_address(buf, fp->retn);
Robin Getz9f06c382008-10-10 18:13:21 +08001174 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001175 decode_address(buf, fp->retx);
Robin Getz9f06c382008-10-10 18:13:21 +08001176 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001177 decode_address(buf, fp->rets);
Robin Getz9f06c382008-10-10 18:13:21 +08001178 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001179 decode_address(buf, fp->pc);
Robin Getz9f06c382008-10-10 18:13:21 +08001180 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001181
Robin Getz13fe24f2008-01-27 15:38:56 +08001182 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1183 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Graf Yang8f658732008-11-18 17:48:22 +08001184 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001185 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +08001186 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001187 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001188 }
1189
Joe Perchesad361c92009-07-06 13:05:40 -07001190 verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001191 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001192 fp->r0, fp->r1, fp->r2, fp->r3);
Robin Getz9f06c382008-10-10 18:13:21 +08001193 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001194 fp->r4, fp->r5, fp->r6, fp->r7);
Robin Getz9f06c382008-10-10 18:13:21 +08001195 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001196 fp->p0, fp->p1, fp->p2, fp->p3);
Robin Getz9f06c382008-10-10 18:13:21 +08001197 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001198 fp->p4, fp->p5, fp->fp, (long)fp);
Robin Getz9f06c382008-10-10 18:13:21 +08001199 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001200 fp->lb0, fp->lt0, fp->lc0);
Robin Getz9f06c382008-10-10 18:13:21 +08001201 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001202 fp->lb1, fp->lt1, fp->lc1);
Robin Getz9f06c382008-10-10 18:13:21 +08001203 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001204 fp->b0, fp->l0, fp->m0, fp->i0);
Robin Getz9f06c382008-10-10 18:13:21 +08001205 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001206 fp->b1, fp->l1, fp->m1, fp->i1);
Robin Getz9f06c382008-10-10 18:13:21 +08001207 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001208 fp->b2, fp->l2, fp->m2, fp->i2);
Robin Getz9f06c382008-10-10 18:13:21 +08001209 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001210 fp->b3, fp->l3, fp->m3, fp->i3);
Robin Getz9f06c382008-10-10 18:13:21 +08001211 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001212 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1213
Robin Getz9f06c382008-10-10 18:13:21 +08001214 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001215 rdusp(), fp->astat);
1216
Robin Getz9f06c382008-10-10 18:13:21 +08001217 verbose_printk(KERN_NOTICE "\n");
1218#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001219}
1220
1221#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1222asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1223#endif
1224
Graf Yang8f658732008-11-18 17:48:22 +08001225static DEFINE_SPINLOCK(bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001226
Graf Yang8f658732008-11-18 17:48:22 +08001227asmlinkage int sys_bfin_spinlock(int *p)
1228{
1229 int ret, tmp = 0;
1230
1231 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1232 ret = get_user(tmp, p);
1233 if (likely(ret == 0)) {
1234 if (unlikely(tmp))
Bryan Wu1394f032007-05-06 14:50:22 -07001235 ret = 1;
Graf Yang8f658732008-11-18 17:48:22 +08001236 else
1237 put_user(1, p);
Bryan Wu1394f032007-05-06 14:50:22 -07001238 }
Graf Yang8f658732008-11-18 17:48:22 +08001239 spin_unlock(&bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001240 return ret;
1241}
1242
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001243int bfin_request_exception(unsigned int exception, void (*handler)(void))
1244{
1245 void (*curr_handler)(void);
1246
1247 if (exception > 0x3F)
1248 return -EINVAL;
1249
1250 curr_handler = ex_table[exception];
1251
1252 if (curr_handler != ex_replaceable)
1253 return -EBUSY;
1254
1255 ex_table[exception] = handler;
1256
1257 return 0;
1258}
1259EXPORT_SYMBOL(bfin_request_exception);
1260
1261int bfin_free_exception(unsigned int exception, void (*handler)(void))
1262{
1263 void (*curr_handler)(void);
1264
1265 if (exception > 0x3F)
1266 return -EINVAL;
1267
1268 curr_handler = ex_table[exception];
1269
1270 if (curr_handler != handler)
1271 return -EBUSY;
1272
1273 ex_table[exception] = ex_replaceable;
1274
1275 return 0;
1276}
1277EXPORT_SYMBOL(bfin_free_exception);
1278
Bryan Wu1394f032007-05-06 14:50:22 -07001279void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1280{
1281 switch (cplb_panic) {
1282 case CPLB_NO_UNLOCKED:
1283 printk(KERN_EMERG "All CPLBs are locked\n");
1284 break;
1285 case CPLB_PROT_VIOL:
1286 return;
1287 case CPLB_NO_ADDR_MATCH:
1288 return;
1289 case CPLB_UNKNOWN_ERR:
1290 printk(KERN_EMERG "Unknown CPLB Exception\n");
1291 break;
1292 }
1293
Robin Getz226eb1e2007-10-29 17:59:07 +08001294 oops_in_progress = 1;
1295
Mike Frysinger49dce912007-11-21 16:46:49 +08001296 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001297 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001298 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001299 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +00001300 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -07001301}