blob: 4eaca2d1deedee9fdd4e354a47d17137940d1545 [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
Graf Yangc6669c22010-01-13 06:09:34 +0000141 if (!down_read_trylock(&mm->mmap_sem)) {
142 if (!in_atomic)
143 mmput(mm);
144 continue;
145 }
146
David Howells8feae132009-01-08 12:04:47 +0000147 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
148 struct vm_area_struct *vma;
149
150 vma = rb_entry(n, struct vm_area_struct, vm_rb);
Bryan Wu1394f032007-05-06 14:50:22 -0700151
152 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800153 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700154 char *name = p->comm;
155 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800156
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800157 if (file) {
158 char *d_name = d_path(&file->f_path, _tmpbuf,
Jan Blunckcf28b482008-02-14 19:38:44 -0800159 sizeof(_tmpbuf));
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800160 if (!IS_ERR(d_name))
161 name = d_name;
162 }
Bryan Wu1394f032007-05-06 14:50:22 -0700163
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800164 /* FLAT does not have its text aligned to the start of
165 * the map while FDPIC ELF does ...
166 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800167
Robin Getz7f1c9062008-04-25 03:36:31 +0800168 /* before we can check flat/fdpic, we need to
169 * make sure current is valid
170 */
171 if ((unsigned long)current >= FIXED_CODE_START &&
172 !((unsigned long)current & 0x3)) {
173 if (current->mm &&
174 (address > current->mm->start_code) &&
175 (address < current->mm->end_code))
176 offset = address - current->mm->start_code;
177 else
178 offset = (address - vma->vm_start) +
179 (vma->vm_pgoff << PAGE_SHIFT);
180
Mike Frysinger18070dd2009-06-23 20:17:21 +0000181 sprintf(buf, "[ %s + 0x%lx ]", name, offset);
Robin Getz7f1c9062008-04-25 03:36:31 +0800182 } else
Mike Frysinger18070dd2009-06-23 20:17:21 +0000183 sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
184 name, vma->vm_start, vma->vm_end);
Robin Getz7f1c9062008-04-25 03:36:31 +0800185
Graf Yangc6669c22010-01-13 06:09:34 +0000186 up_read(&mm->mmap_sem);
Robin Getz904656c2008-03-26 09:17:43 +0800187 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800188 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800189
Mike Frysinger18070dd2009-06-23 20:17:21 +0000190 if (buf[0] == '\0')
191 sprintf(buf, "[ %s ] dynamic memory", name);
Robin Getzf09630b2008-07-26 19:45:46 +0800192
Robin Getz885be032007-10-29 17:20:41 +0800193 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700194 }
Bryan Wu1394f032007-05-06 14:50:22 -0700195 }
Graf Yangc6669c22010-01-13 06:09:34 +0000196
197 up_read(&mm->mmap_sem);
Robin Getz904656c2008-03-26 09:17:43 +0800198 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800199 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700200 }
Bryan Wu1394f032007-05-06 14:50:22 -0700201
Graf Yangc6669c22010-01-13 06:09:34 +0000202 /*
203 * we were unable to find this address anywhere,
204 * or some MMs were skipped because they were in use.
205 */
Mike Frysinger18070dd2009-06-23 20:17:21 +0000206 sprintf(buf, "/* kernel dynamic memory */");
Robin Getz885be032007-10-29 17:20:41 +0800207
208done:
209 write_unlock_irqrestore(&tasklist_lock, flags);
Robin Getz9f06c382008-10-10 18:13:21 +0800210#else
211 sprintf(buf, " ");
212#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700213}
214
Robin Getz2ebcade2007-10-09 17:24:30 +0800215asmlinkage void double_fault_c(struct pt_regs *fp)
216{
Robin Getza0cab652009-05-11 18:34:41 +0000217#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
218 int j;
219 trace_buffer_save(j);
220#endif
221
Robin Getz226eb1e2007-10-29 17:59:07 +0800222 console_verbose();
223 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800224#ifdef CONFIG_DEBUG_VERBOSE
Joe Perchesad361c92009-07-06 13:05:40 -0700225 printk(KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800226#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
227 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
Yi Lib6dbde22009-08-20 04:17:47 +0000228 unsigned int cpu = raw_smp_processor_id();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800229 char buf[150];
Graf Yang01b9f4b2009-07-22 11:56:24 +0000230 decode_address(buf, cpu_pda[cpu].retx_doublefault);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800231 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
Graf Yang01b9f4b2009-07-22 11:56:24 +0000232 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
233 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800234 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang01b9f4b2009-07-22 11:56:24 +0000235 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800236 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
237
238 decode_address(buf, fp->retx);
Graf Yang8f658732008-11-18 17:48:22 +0800239 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800240 } else
241#endif
242 {
243 dump_bfin_process(fp);
244 dump_bfin_mem(fp);
245 show_regs(fp);
Robin Getza0cab652009-05-11 18:34:41 +0000246 dump_bfin_trace_buffer();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800247 }
Robin Getz9f06c382008-10-10 18:13:21 +0800248#endif
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000249 panic("Double Fault - unrecoverable event");
Robin Getz2ebcade2007-10-09 17:24:30 +0800250
251}
252
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400253static int kernel_mode_regs(struct pt_regs *regs)
254{
255 return regs->ipend & 0xffc0;
256}
257
Yi Lic4baebf2009-08-12 23:05:35 +0000258asmlinkage notrace void trap_c(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700259{
Robin Getz518039b2007-07-25 11:03:28 +0800260#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
261 int j;
262#endif
Yi Lib6dbde22009-08-20 04:17:47 +0000263 unsigned int cpu = raw_smp_processor_id();
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400264 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +0800265 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700266 siginfo_t info;
267 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
268
Bryan Wu1394f032007-05-06 14:50:22 -0700269 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +0000270#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
271 last_seqstat = (u32)fp->seqstat;
272#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700273
Robin Getz226eb1e2007-10-29 17:59:07 +0800274 /* Important - be very careful dereferncing pointers - will lead to
275 * double faults if the stack has become corrupt
276 */
277
Bryan Wu1394f032007-05-06 14:50:22 -0700278 /* trap_c() will be called for exceptions. During exceptions
279 * processing, the pc value should be set with retx value.
280 * With this change we can cleanup some code in signal.c- TODO
281 */
282 fp->orig_pc = fp->retx;
283 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
284 trapnr, fp->ipend, fp->pc, fp->retx); */
285
286 /* send the appropriate signal to the user program */
287 switch (trapnr) {
288
289 /* This table works in conjuction with the one in ./mach-common/entry.S
290 * Some exceptions are handled there (in assembly, in exception space)
291 * Some are handled here, (in C, in interrupt space)
292 * Some, like CPLB, are handled in both, where the normal path is
293 * handled in assembly/exception space, and the error path is handled
294 * here
295 */
296
297 /* 0x00 - Linux Syscall, getting here is an error */
298 /* 0x01 - userspace gdb breakpoint, handled here */
299 case VEC_EXCPT01:
300 info.si_code = TRAP_ILLTRAP;
301 sig = SIGTRAP;
302 CHK_DEBUGGER_TRAP_MAYBE();
303 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400304 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400305 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700306 else
307 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800308 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700309 case VEC_EXCPT03:
310 info.si_code = SEGV_STACKFLOW;
311 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400312 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800313 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700314 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800315 /* 0x02 - KGDB initial connection and break signal trap */
316 case VEC_EXCPT02:
317#ifdef CONFIG_KGDB
318 info.si_code = TRAP_ILLTRAP;
319 sig = SIGTRAP;
320 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400321 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800322#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800323 /* 0x04 - User Defined */
324 /* 0x05 - User Defined */
325 /* 0x06 - User Defined */
326 /* 0x07 - User Defined */
327 /* 0x08 - User Defined */
328 /* 0x09 - User Defined */
329 /* 0x0A - User Defined */
330 /* 0x0B - User Defined */
331 /* 0x0C - User Defined */
332 /* 0x0D - User Defined */
333 /* 0x0E - User Defined */
334 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800335 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800336 * custom exception handler, and it is not actually installed properly
337 */
338 case VEC_EXCPT04 ... VEC_EXCPT15:
339 info.si_code = ILL_ILLPARAOP;
340 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400341 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800342 CHK_DEBUGGER_TRAP_MAYBE();
343 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700344 /* 0x10 HW Single step, handled here */
345 case VEC_STEP:
346 info.si_code = TRAP_STEP;
347 sig = SIGTRAP;
348 CHK_DEBUGGER_TRAP_MAYBE();
349 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400350 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400351 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700352 else
353 break;
354 /* 0x11 - Trace Buffer Full, handled here */
355 case VEC_OVFLOW:
356 info.si_code = TRAP_TRACEFLOW;
357 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400358 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800359 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700360 break;
361 /* 0x12 - Reserved, Caught by default */
362 /* 0x13 - Reserved, Caught by default */
363 /* 0x14 - Reserved, Caught by default */
364 /* 0x15 - Reserved, Caught by default */
365 /* 0x16 - Reserved, Caught by default */
366 /* 0x17 - Reserved, Caught by default */
367 /* 0x18 - Reserved, Caught by default */
368 /* 0x19 - Reserved, Caught by default */
369 /* 0x1A - Reserved, Caught by default */
370 /* 0x1B - Reserved, Caught by default */
371 /* 0x1C - Reserved, Caught by default */
372 /* 0x1D - Reserved, Caught by default */
373 /* 0x1E - Reserved, Caught by default */
374 /* 0x1F - Reserved, Caught by default */
375 /* 0x20 - Reserved, Caught by default */
376 /* 0x21 - Undefined Instruction, handled here */
377 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400378#ifdef CONFIG_BUG
379 if (kernel_mode_regs(fp)) {
380 switch (report_bug(fp->pc, fp)) {
381 case BUG_TRAP_TYPE_NONE:
382 break;
383 case BUG_TRAP_TYPE_WARN:
384 dump_bfin_trace_buffer();
385 fp->pc += 2;
386 goto traps_done;
387 case BUG_TRAP_TYPE_BUG:
388 /* call to panic() will dump trace, and it is
389 * off at this point, so it won't be clobbered
390 */
391 panic("BUG()");
392 }
393 }
394#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700395 info.si_code = ILL_ILLOPC;
396 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400397 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800398 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700399 break;
400 /* 0x22 - Illegal Instruction Combination, handled here */
401 case VEC_ILGAL_I:
402 info.si_code = ILL_ILLPARAOP;
403 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400404 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800405 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700406 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800407 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700408 case VEC_CPLB_VL:
409 info.si_code = ILL_CPLB_VI;
Graf Yang36b84122009-07-21 02:26:57 +0000410 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400411 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800412 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700413 break;
414 /* 0x24 - Data access misaligned, handled here */
415 case VEC_MISALI_D:
416 info.si_code = BUS_ADRALN;
417 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400418 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800419 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700420 break;
421 /* 0x25 - Unrecoverable Event, handled here */
422 case VEC_UNCOV:
423 info.si_code = ILL_ILLEXCPT;
424 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400425 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800426 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700427 break;
428 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
429 error case is handled here */
430 case VEC_CPLB_M:
431 info.si_code = BUS_ADRALN;
432 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400433 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700434 break;
435 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
436 case VEC_CPLB_MHIT:
437 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700438 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800439#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800440 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400441 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800442 else
Bryan Wu1394f032007-05-06 14:50:22 -0700443#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400444 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800445 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700446 break;
447 /* 0x28 - Emulation Watchpoint, handled here */
448 case VEC_WATCH:
449 info.si_code = TRAP_WATCHPT;
450 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800451 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700452 CHK_DEBUGGER_TRAP_MAYBE();
453 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400454 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400455 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700456 else
457 break;
458#ifdef CONFIG_BF535
459 /* 0x29 - Instruction fetch access error (535 only) */
460 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
461 info.si_code = BUS_OPFETCH;
462 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400463 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800464 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700465 break;
466#else
467 /* 0x29 - Reserved, Caught by default */
468#endif
469 /* 0x2A - Instruction fetch misaligned, handled here */
470 case VEC_MISALI_I:
471 info.si_code = BUS_ADRALN;
472 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400473 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800474 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700475 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800476 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700477 case VEC_CPLB_I_VL:
478 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800479 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400480 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800481 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700482 break;
483 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
484 case VEC_CPLB_I_M:
485 info.si_code = ILL_CPLB_MISS;
486 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400487 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700488 break;
489 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
490 case VEC_CPLB_I_MHIT:
491 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700492 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800493#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800494 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400495 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800496 else
Bryan Wu1394f032007-05-06 14:50:22 -0700497#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400498 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800499 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700500 break;
501 /* 0x2E - Illegal use of Supervisor Resource, handled here */
502 case VEC_ILL_RES:
503 info.si_code = ILL_PRVOPC;
504 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400505 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800506 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700507 break;
508 /* 0x2F - Reserved, Caught by default */
509 /* 0x30 - Reserved, Caught by default */
510 /* 0x31 - Reserved, Caught by default */
511 /* 0x32 - Reserved, Caught by default */
512 /* 0x33 - Reserved, Caught by default */
513 /* 0x34 - Reserved, Caught by default */
514 /* 0x35 - Reserved, Caught by default */
515 /* 0x36 - Reserved, Caught by default */
516 /* 0x37 - Reserved, Caught by default */
517 /* 0x38 - Reserved, Caught by default */
518 /* 0x39 - Reserved, Caught by default */
519 /* 0x3A - Reserved, Caught by default */
520 /* 0x3B - Reserved, Caught by default */
521 /* 0x3C - Reserved, Caught by default */
522 /* 0x3D - Reserved, Caught by default */
523 /* 0x3E - Reserved, Caught by default */
524 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800525 case VEC_HWERR:
526 info.si_code = BUS_ADRALN;
527 sig = SIGBUS;
528 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
529 /* System MMR Error */
530 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
531 info.si_code = BUS_ADRALN;
532 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400533 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800534 break;
535 /* External Memory Addressing Error */
536 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
Barry Songa00b4fe2009-11-27 09:18:21 +0000537 if (ANOMALY_05000310) {
538 static unsigned long anomaly_rets;
539
540 if ((fp->pc >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
541 (fp->pc < (L1_CODE_START + L1_CODE_LENGTH))) {
542 /*
543 * A false hardware error will happen while fetching at
544 * the L1 instruction SRAM boundary. Ignore it.
545 */
546 anomaly_rets = fp->rets;
547 goto traps_done;
548 } else if (fp->rets == anomaly_rets) {
549 /*
550 * While boundary code returns to a function, at the ret
551 * point, a new false hardware error might occur too based
552 * on tests. Ignore it too.
553 */
554 goto traps_done;
555 } else if ((fp->rets >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
556 (fp->rets < (L1_CODE_START + L1_CODE_LENGTH))) {
557 /*
558 * If boundary code calls a function, at the entry point,
559 * a new false hardware error maybe happen based on tests.
560 * Ignore it too.
561 */
562 goto traps_done;
563 } else
564 anomaly_rets = 0;
565 }
566
Robin Getz13fe24f2008-01-27 15:38:56 +0800567 info.si_code = BUS_ADRERR;
568 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400569 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800570 break;
571 /* Performance Monitor Overflow */
572 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400573 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800574 break;
575 /* RAISE 5 instruction */
576 case (SEQSTAT_HWERRCAUSE_RAISE_5):
577 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
578 break;
579 default: /* Reserved */
580 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
581 break;
582 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800583 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800584 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800585 /*
586 * We should be handling all known exception types above,
587 * if we get here we hit a reserved one, so panic
588 */
Bryan Wu1394f032007-05-06 14:50:22 -0700589 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800590 info.si_code = ILL_ILLPARAOP;
591 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800592 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700593 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800594 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700595 break;
596 }
597
Robin Getz226eb1e2007-10-29 17:59:07 +0800598 BUG_ON(sig == 0);
599
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400600 /* If the fault was caused by a kernel thread, or interrupt handler
601 * we will kernel panic, so the system reboots.
602 */
603 if (kernel_mode_regs(fp) || (current && !current->mm)) {
604 console_verbose();
605 oops_in_progress = 1;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400606 }
607
Robin Getz226eb1e2007-10-29 17:59:07 +0800608 if (sig != SIGTRAP) {
Mike Frysinger15627bd2009-06-23 11:21:34 +0000609 if (strerror)
610 verbose_printk(strerror);
611
Mike Frysinger49dce912007-11-21 16:46:49 +0800612 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800613 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800614 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800615
616 /* Print out the trace buffer if it makes sense */
617#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
618 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800619 verbose_printk(KERN_NOTICE "No trace since you do not have "
Joe Perchesad361c92009-07-06 13:05:40 -0700620 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800621 else
622#endif
623 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800624
Robin Getz226eb1e2007-10-29 17:59:07 +0800625 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800626 /* Dump the current kernel stack */
Joe Perchesad361c92009-07-06 13:05:40 -0700627 verbose_printk(KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800628 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800629 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800630#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800631 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800632 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800633#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700634 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800635 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800636#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800637 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800638 /* Dump the user space stack */
639 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800640 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800641 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800642#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800643 }
Bryan Wu1394f032007-05-06 14:50:22 -0700644 }
Robin Getzfb322912007-11-21 16:38:05 +0800645
Yi Li6a01f232009-01-07 23:14:39 +0800646#ifdef CONFIG_IPIPE
647 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
648#endif
649 {
650 info.si_signo = sig;
651 info.si_errno = 0;
Barry Song5e8d3212010-01-19 11:01:08 +0000652 switch (trapnr) {
653 case VEC_CPLB_VL:
654 case VEC_MISALI_D:
655 case VEC_CPLB_M:
656 case VEC_CPLB_MHIT:
657 info.si_addr = (void __user *)cpu_pda[cpu].dcplb_fault_addr;
658 break;
659 default:
660 info.si_addr = (void __user *)fp->pc;
661 break;
662 }
Yi Li6a01f232009-01-07 23:14:39 +0800663 force_sig_info(sig, &info, current);
664 }
Bryan Wu1394f032007-05-06 14:50:22 -0700665
Robin Getz0e4edcf2009-06-22 20:23:48 +0000666 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
Robin Getzf574a762009-07-09 15:11:52 +0000667 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
668 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
Robin Getz0acad8d2009-05-11 18:55:16 +0000669 fp->pc = SAFE_USER_INSTRUCTION;
670
Mike Frysinger6510a202009-06-07 15:07:25 -0400671 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700672 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700673}
674
675/* Typical exception handling routines */
676
Robin Getz518039b2007-07-25 11:03:28 +0800677#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
678
Robin Getzf09630b2008-07-26 19:45:46 +0800679/*
680 * Similar to get_user, do some address checking, then dereference
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200681 * Return true on success, false on bad address
Robin Getzf09630b2008-07-26 19:45:46 +0800682 */
Robin Getz9f06c382008-10-10 18:13:21 +0800683static bool get_instruction(unsigned short *val, unsigned short *address)
Robin Getzf09630b2008-07-26 19:45:46 +0800684{
Mike Frysingere56e03b2009-06-07 16:31:52 -0400685 unsigned long addr = (unsigned long)address;
Robin Getzf09630b2008-07-26 19:45:46 +0800686
687 /* Check for odd addresses */
688 if (addr & 0x1)
689 return false;
690
Mike Frysingere56e03b2009-06-07 16:31:52 -0400691 /* MMR region will never have instructions */
692 if (addr >= SYSMMR_BASE)
Robin Getzf09630b2008-07-26 19:45:46 +0800693 return false;
694
Mike Frysingere56e03b2009-06-07 16:31:52 -0400695 switch (bfin_mem_access_type(addr, 2)) {
696 case BFIN_MEM_ACCESS_CORE:
697 case BFIN_MEM_ACCESS_CORE_ONLY:
698 *val = *address;
699 return true;
700 case BFIN_MEM_ACCESS_DMA:
701 dma_memcpy(val, address, 2);
702 return true;
703 case BFIN_MEM_ACCESS_ITEST:
704 isram_memcpy(val, address, 2);
705 return true;
706 default: /* invalid access */
707 return false;
Robin Getzf09630b2008-07-26 19:45:46 +0800708 }
Robin Getzf09630b2008-07-26 19:45:46 +0800709}
710
Mike Frysinger36f649a2008-11-18 17:48:22 +0800711/*
Robin Getzd3d0ac22008-08-06 17:49:27 +0800712 * decode the instruction if we are printing out the trace, as it
713 * makes things easier to follow, without running it through objdump
714 * These are the normal instructions which cause change of flow, which
715 * would be at the source of the trace buffer
716 */
Mike Frysinger36f649a2008-11-18 17:48:22 +0800717#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
Robin Getz9f06c382008-10-10 18:13:21 +0800718static void decode_instruction(unsigned short *address)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800719{
720 unsigned short opcode;
721
722 if (get_instruction(&opcode, address)) {
723 if (opcode == 0x0010)
Robin Getz9f06c382008-10-10 18:13:21 +0800724 verbose_printk("RTS");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800725 else if (opcode == 0x0011)
Robin Getz9f06c382008-10-10 18:13:21 +0800726 verbose_printk("RTI");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800727 else if (opcode == 0x0012)
Robin Getz9f06c382008-10-10 18:13:21 +0800728 verbose_printk("RTX");
Robin Getz0be58932009-02-04 16:49:45 +0800729 else if (opcode == 0x0013)
730 verbose_printk("RTN");
731 else if (opcode == 0x0014)
732 verbose_printk("RTE");
733 else if (opcode == 0x0025)
734 verbose_printk("EMUEXCPT");
Roel Kluin48a74f92010-01-08 20:06:22 +0100735 else if (opcode >= 0x0040 && opcode <= 0x0047)
Robin Getz0be58932009-02-04 16:49:45 +0800736 verbose_printk("STI R%i", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800737 else if (opcode >= 0x0050 && opcode <= 0x0057)
Robin Getz9f06c382008-10-10 18:13:21 +0800738 verbose_printk("JUMP (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800739 else if (opcode >= 0x0060 && opcode <= 0x0067)
Robin Getz9f06c382008-10-10 18:13:21 +0800740 verbose_printk("CALL (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800741 else if (opcode >= 0x0070 && opcode <= 0x0077)
Robin Getz9f06c382008-10-10 18:13:21 +0800742 verbose_printk("CALL (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800743 else if (opcode >= 0x0080 && opcode <= 0x0087)
Robin Getz9f06c382008-10-10 18:13:21 +0800744 verbose_printk("JUMP (PC+P%i)", opcode & 7);
Robin Getz0be58932009-02-04 16:49:45 +0800745 else if (opcode >= 0x0090 && opcode <= 0x009F)
746 verbose_printk("RAISE 0x%x", opcode & 0xF);
747 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
748 verbose_printk("EXCPT 0x%x", opcode & 0xF);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800749 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
Robin Getz9f06c382008-10-10 18:13:21 +0800750 verbose_printk("IF !CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800751 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
Robin Getz9f06c382008-10-10 18:13:21 +0800752 verbose_printk("IF CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800753 else if (opcode >= 0x2000 && opcode <= 0x2fff)
Robin Getz9f06c382008-10-10 18:13:21 +0800754 verbose_printk("JUMP.S");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800755 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800756 verbose_printk("LSETUP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800757 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800758 verbose_printk("JUMP.L");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800759 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800760 verbose_printk("CALL pcrel");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800761 else
Robin Getz9f06c382008-10-10 18:13:21 +0800762 verbose_printk("0x%04x", opcode);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800763 }
764
765}
Robin Getz9f06c382008-10-10 18:13:21 +0800766#endif
Robin Getzd3d0ac22008-08-06 17:49:27 +0800767
Bryan Wu1394f032007-05-06 14:50:22 -0700768void dump_bfin_trace_buffer(void)
769{
Robin Getz9f06c382008-10-10 18:13:21 +0800770#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz518039b2007-07-25 11:03:28 +0800771#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
772 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800773 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800774 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800775#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
776 int j, index;
777#endif
778
Bryan Wu1394f032007-05-06 14:50:22 -0700779 trace_buffer_save(tflags);
780
Robin Getz226eb1e2007-10-29 17:59:07 +0800781 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800782
Robin Getzd3d0ac22008-08-06 17:49:27 +0800783#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
784 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
785#endif
786
Bryan Wu1394f032007-05-06 14:50:22 -0700787 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800788 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800789 decode_address(buf, (unsigned long)bfin_read_TBUF());
790 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800791 addr = (unsigned short *)bfin_read_TBUF();
792 decode_address(buf, (unsigned long)addr);
793 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800794 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800795 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700796 }
797 }
798
Robin Getz518039b2007-07-25 11:03:28 +0800799#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
800 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800801 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800802 else
803 index = EXPAND_LEN;
804
805 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
806 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800807 decode_address(buf, software_trace_buff[index]);
808 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800809 index -= 1;
810 if (index < 0 )
811 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800812 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800813 printk(KERN_NOTICE " Source : %s ", buf);
814 decode_instruction((unsigned short *)software_trace_buff[index]);
815 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800816 index -= 1;
817 if (index < 0)
818 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800819 j--;
820 i++;
821 }
822#endif
823
Bryan Wu1394f032007-05-06 14:50:22 -0700824 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800825#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800826#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700827}
828EXPORT_SYMBOL(dump_bfin_trace_buffer);
829
Mike Frysinger70f12562009-06-07 17:18:25 -0400830#ifdef CONFIG_BUG
831int is_valid_bugaddr(unsigned long addr)
832{
833 unsigned short opcode;
834
835 if (!get_instruction(&opcode, (unsigned short *)addr))
836 return 0;
837
838 return opcode == BFIN_BUG_OPCODE;
839}
840#endif
841
Robin Getzf09630b2008-07-26 19:45:46 +0800842/*
843 * Checks to see if the address pointed to is either a
844 * 16-bit CALL instruction, or a 32-bit CALL instruction
845 */
Robin Getz9f06c382008-10-10 18:13:21 +0800846static bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700847{
Robin Getzf09630b2008-07-26 19:45:46 +0800848 unsigned short opcode = 0, *ins_addr;
849 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700850
Robin Getzf09630b2008-07-26 19:45:46 +0800851 if (!get_instruction(&opcode, ins_addr))
852 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700853
Robin Getzf09630b2008-07-26 19:45:46 +0800854 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
855 (opcode >= 0x0070 && opcode <= 0x0077))
856 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700857
Robin Getzf09630b2008-07-26 19:45:46 +0800858 ins_addr--;
859 if (!get_instruction(&opcode, ins_addr))
860 return false;
861
862 if (opcode >= 0xE300 && opcode <= 0xE3FF)
863 return true;
864
865 return false;
866
Bryan Wu1394f032007-05-06 14:50:22 -0700867}
Robin Getz9f06c382008-10-10 18:13:21 +0800868
Bryan Wu1394f032007-05-06 14:50:22 -0700869void show_stack(struct task_struct *task, unsigned long *stack)
870{
Robin Getz9f06c382008-10-10 18:13:21 +0800871#ifdef CONFIG_PRINTK
Robin Getzf09630b2008-07-26 19:45:46 +0800872 unsigned int *addr, *endstack, *fp = 0, *frame;
873 unsigned short *ins_addr;
874 char buf[150];
875 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700876
Robin Getzf09630b2008-07-26 19:45:46 +0800877 /*
878 * If we have been passed a specific stack, use that one otherwise
879 * if we have been passed a task structure, use that, otherwise
880 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700881 */
882
Robin Getzf09630b2008-07-26 19:45:46 +0800883 if (stack == NULL) {
884 if (task) {
885 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700886 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800887 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
888 } else {
889 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700890 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800891 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
892 }
893 } else
894 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
895
Robin Getz9f06c382008-10-10 18:13:21 +0800896 printk(KERN_NOTICE "Stack info:\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800897 decode_address(buf, (unsigned int)stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800898 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
899
Robin Getza0cab652009-05-11 18:34:41 +0000900 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
901 printk(KERN_NOTICE "Invalid stack pointer\n");
902 return;
903 }
904
Robin Getzf09630b2008-07-26 19:45:46 +0800905 /* First thing is to look for a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800906 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800907 if (*addr & 0x1)
908 continue;
909 ins_addr = (unsigned short *)*addr;
910 ins_addr--;
911 if (is_bfin_call(ins_addr))
912 fp = addr - 1;
913
914 if (fp) {
915 /* Let's check to see if it is a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800916 while (fp >= (addr - 1) && fp < endstack
917 && fp && ((unsigned int) fp & 0x3) == 0)
Robin Getzf09630b2008-07-26 19:45:46 +0800918 fp = (unsigned int *)*fp;
919 if (fp == 0 || fp == endstack) {
920 fp = addr - 1;
921 break;
922 }
923 fp = 0;
924 }
925 }
926 if (fp) {
927 frame = fp;
Jie Zhangb339dc72009-01-07 23:14:39 +0800928 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
Robin Getzf09630b2008-07-26 19:45:46 +0800929 } else
930 frame = 0;
931
932 /*
933 * Now that we think we know where things are, we
934 * walk the stack again, this time printing things out
935 * incase there is no frame pointer, we still look for
936 * valid return addresses
937 */
938
939 /* First time print out data, next time, print out symbols */
940 for (j = 0; j <= 1; j++) {
941 if (j)
942 printk(KERN_NOTICE "Return addresses in stack:\n");
943 else
944 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
945
946 fp = frame;
947 frame_no = 0;
948
949 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
Sonic Zhang407505d2009-07-16 10:36:35 +0000950 addr < endstack; addr++, i++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800951
952 ret_addr = 0;
953 if (!j && i % 8 == 0)
Joe Perchesad361c92009-07-06 13:05:40 -0700954 printk(KERN_NOTICE "%p:",addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800955
956 /* if it is an odd address, or zero, just skip it */
957 if (*addr & 0x1 || !*addr)
958 goto print;
959
960 ins_addr = (unsigned short *)*addr;
961
962 /* Go back one instruction, and see if it is a CALL */
963 ins_addr--;
964 ret_addr = is_bfin_call(ins_addr);
965 print:
966 if (!j && stack == (unsigned long *)addr)
967 printk("[%08x]", *addr);
968 else if (ret_addr)
969 if (j) {
970 decode_address(buf, (unsigned int)*addr);
971 if (frame == addr) {
972 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
973 continue;
974 }
975 printk(KERN_NOTICE " address : %s\n", buf);
976 } else
977 printk("<%08x>", *addr);
978 else if (fp == addr) {
979 if (j)
980 frame = addr+1;
981 else
982 printk("(%08x)", *addr);
983
984 fp = (unsigned int *)*addr;
985 frame_no++;
986
987 } else if (!j)
988 printk(" %08x ", *addr);
989 }
990 if (!j)
991 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700992 }
Robin Getz9f06c382008-10-10 18:13:21 +0800993#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700994}
Philippe Gerumbc569f12009-06-22 18:23:12 +0200995EXPORT_SYMBOL(show_stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700996
997void dump_stack(void)
998{
999 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +08001000#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -07001001 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +08001002#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001003 trace_buffer_save(tflags);
1004 dump_bfin_trace_buffer();
1005 show_stack(current, &stack);
1006 trace_buffer_restore(tflags);
1007}
Bryan Wu1394f032007-05-06 14:50:22 -07001008EXPORT_SYMBOL(dump_stack);
1009
Mike Frysinger49dce912007-11-21 16:46:49 +08001010void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -07001011{
Robin Getz9f06c382008-10-10 18:13:21 +08001012#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001013 /* We should be able to look at fp->ipend, but we don't push it on the
1014 * stack all the time, so do this until we fix that */
1015 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +08001016
Mike Frysinger49dce912007-11-21 16:46:49 +08001017 if (oops_in_progress)
Robin Getz9f06c382008-10-10 18:13:21 +08001018 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +08001019
Robin Getzb03b08b2007-12-23 22:57:01 +08001020 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
Robin Getz9f06c382008-10-10 18:13:21 +08001021 verbose_printk(KERN_NOTICE "HW Error context\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001022 else if (context & 0x0020)
Robin Getz9f06c382008-10-10 18:13:21 +08001023 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001024 else if (context & 0x3FC0)
Robin Getz9f06c382008-10-10 18:13:21 +08001025 verbose_printk(KERN_NOTICE "Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001026 else if (context & 0x4000)
Robin Getz9f06c382008-10-10 18:13:21 +08001027 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001028 else if (context & 0x8000)
Robin Getz9f06c382008-10-10 18:13:21 +08001029 verbose_printk(KERN_NOTICE "Kernel process context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001030
Robin Getz9a62ca42008-03-26 09:15:58 +08001031 /* Because we are crashing, and pointers could be bad, we check things
1032 * pretty closely before we use them
1033 */
Robin Getz7f1c9062008-04-25 03:36:31 +08001034 if ((unsigned long)current >= FIXED_CODE_START &&
1035 !((unsigned long)current & 0x3) && current->pid) {
Robin Getz9f06c382008-10-10 18:13:21 +08001036 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +08001037 if (current->comm >= (char *)FIXED_CODE_START)
Mike Frysinger13a13202009-10-22 10:14:53 +00001038 verbose_printk(KERN_NOTICE "COMM=%s PID=%d",
Robin Getz9a62ca42008-03-26 09:15:58 +08001039 current->comm, current->pid);
1040 else
Mike Frysinger13a13202009-10-22 10:14:53 +00001041 verbose_printk(KERN_NOTICE "COMM= invalid");
Mike Frysinger49dce912007-11-21 16:46:49 +08001042
Mike Frysinger13a13202009-10-22 10:14:53 +00001043 printk(KERN_CONT " CPU=%d\n", current_thread_info()->cpu);
Robin Getz9a62ca42008-03-26 09:15:58 +08001044 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
Joe Perchesad361c92009-07-06 13:05:40 -07001045 verbose_printk(KERN_NOTICE
1046 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
1047 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
Robin Getz9a62ca42008-03-26 09:15:58 +08001048 (void *)current->mm->start_code,
1049 (void *)current->mm->end_code,
1050 (void *)current->mm->start_data,
1051 (void *)current->mm->end_data,
1052 (void *)current->mm->end_data,
1053 (void *)current->mm->brk,
1054 (void *)current->mm->start_stack);
1055 else
Robin Getz9f06c382008-10-10 18:13:21 +08001056 verbose_printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001057 } else
Joe Perchesad361c92009-07-06 13:05:40 -07001058 verbose_printk(KERN_NOTICE
1059 "No Valid process in current context\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001060#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001061}
1062
Robin Getzb03b08b2007-12-23 22:57:01 +08001063void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +08001064{
Robin Getz9f06c382008-10-10 18:13:21 +08001065#ifdef CONFIG_DEBUG_VERBOSE
Robin Getzb03b08b2007-12-23 22:57:01 +08001066 unsigned short *addr, *erraddr, val = 0, err = 0;
1067 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -07001068
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001069 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +08001070
Robin Getz9f06c382008-10-10 18:13:21 +08001071 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001072
1073 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1074 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1075 addr++) {
1076 if (!((unsigned long)addr & 0xF))
Joe Perchesad361c92009-07-06 13:05:40 -07001077 verbose_printk(KERN_NOTICE "0x%p: ", addr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001078
Robin Getz7d98c882008-10-08 16:29:01 +08001079 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +08001080 val = 0;
1081 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +08001082 } else
1083 sprintf(buf, "%04x", val);
1084
1085 if (addr == erraddr) {
Robin Getz9f06c382008-10-10 18:13:21 +08001086 verbose_printk("[%s]", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001087 err = val;
1088 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001089 verbose_printk(" %s ", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001090
1091 /* Do any previous instructions turn on interrupts? */
1092 if (addr <= erraddr && /* in the past */
1093 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1094 val == 0x017b)) /* [SP++] = RETI */
1095 sti = 1;
1096 }
1097
Robin Getz9f06c382008-10-10 18:13:21 +08001098 verbose_printk("\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001099
1100 /* Hardware error interrupts can be deferred */
1101 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1102 oops_in_progress)){
Robin Getz9f06c382008-10-10 18:13:21 +08001103 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001104#ifndef CONFIG_DEBUG_HWERR
Joe Perchesad361c92009-07-06 13:05:40 -07001105 verbose_printk(KERN_NOTICE
1106"The remaining message may be meaningless\n"
1107"You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001108#else
1109 /* If we are handling only one peripheral interrupt
1110 * and current mm and pid are valid, and the last error
1111 * was in that user space process's text area
1112 * print it out - because that is where the problem exists
1113 */
1114 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1115 (current->pid && current->mm)) {
1116 /* And the last RETI points to the current userspace context */
1117 if ((fp + 1)->pc >= current->mm->start_code &&
1118 (fp + 1)->pc <= current->mm->end_code) {
Robin Getz9f06c382008-10-10 18:13:21 +08001119 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1120 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001121 show_regs(fp + 1);
Robin Getz9f06c382008-10-10 18:13:21 +08001122 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001123 }
Bryan Wu1394f032007-05-06 14:50:22 -07001124 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001125#endif
1126 }
Robin Getz9f06c382008-10-10 18:13:21 +08001127#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001128}
1129
1130void show_regs(struct pt_regs *fp)
1131{
Robin Getz9f06c382008-10-10 18:13:21 +08001132#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001133 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001134 struct irqaction *action;
1135 unsigned int i;
Robin Getz2f95d5b2009-02-04 16:49:45 +08001136 unsigned long flags = 0;
Yi Lib6dbde22009-08-20 04:17:47 +00001137 unsigned int cpu = raw_smp_processor_id();
Robin Getz2f95d5b2009-02-04 16:49:45 +08001138 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -07001139
Robin Getz9ba3c242009-05-20 21:19:21 +00001140 verbose_printk(KERN_NOTICE "\n");
1141 if (CPUID != bfin_cpuid())
1142 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1143 "but running on:0x%04x (Rev %d)\n",
1144 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1145
1146 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1147 CPU, bfin_compiled_revid());
1148
1149 if (bfin_compiled_revid() != bfin_revid())
1150 verbose_printk("(Detected 0.%d)", bfin_revid());
1151
1152 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1153 get_cclk()/1000000, get_sclk()/1000000,
1154#ifdef CONFIG_MPU
1155 "mpu on"
1156#else
1157 "mpu off"
1158#endif
1159 );
1160
1161 verbose_printk(KERN_NOTICE "%s", linux_banner);
1162
Robin Getzae4f0732009-06-22 02:02:16 +00001163 verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
1164 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
Yi Lib6dbde22009-08-20 04:17:47 +00001165 (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
Robin Getzae4f0732009-06-22 02:02:16 +00001166 if (fp->ipend & EVT_IRPTEN)
1167 verbose_printk(KERN_NOTICE " Global Interrupts Disabled (IPEND[4])\n");
Yi Lib6dbde22009-08-20 04:17:47 +00001168 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
Robin Getzae4f0732009-06-22 02:02:16 +00001169 EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
1170 verbose_printk(KERN_NOTICE " Peripheral interrupts masked off\n");
Yi Lib6dbde22009-08-20 04:17:47 +00001171 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
Robin Getzae4f0732009-06-22 02:02:16 +00001172 verbose_printk(KERN_NOTICE " Kernel interrupts masked off\n");
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001173 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001174 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001175 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1176#ifdef EBIU_ERRMST
1177 /* If the error was from the EBIU, print it out */
1178 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001179 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001180 bfin_read_EBIU_ERRMST());
Robin Getz9f06c382008-10-10 18:13:21 +08001181 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001182 bfin_read_EBIU_ERRADD());
1183 }
1184#endif
1185 }
Robin Getz9f06c382008-10-10 18:13:21 +08001186 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
Robin Getz13fe24f2008-01-27 15:38:56 +08001187 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getz2f95d5b2009-02-04 16:49:45 +08001188 for (i = 2; i <= 15 ; i++) {
Robin Getzd8f66c82007-12-24 15:27:56 +08001189 if (fp->ipend & (1 << i)) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001190 if (i != 4) {
1191 decode_address(buf, bfin_read32(EVT0 + 4*i));
1192 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1193 } else
1194 verbose_printk(KERN_NOTICE " interrupts disabled\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001195 }
1196 }
1197
1198 /* if no interrupts are going off, don't print this out */
1199 if (fp->ipend & ~0x3F) {
1200 for (i = 0; i < (NR_IRQS - 1); i++) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001201 if (!in_atomic)
Thomas Gleixner239007b2009-11-17 16:46:45 +01001202 raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
Robin Getz2f95d5b2009-02-04 16:49:45 +08001203
Robin Getzd8f66c82007-12-24 15:27:56 +08001204 action = irq_desc[i].action;
1205 if (!action)
1206 goto unlock;
1207
1208 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001209 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001210 for (action = action->next; action; action = action->next) {
1211 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001212 verbose_printk(", %s", buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001213 }
Robin Getz9f06c382008-10-10 18:13:21 +08001214 verbose_printk("\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001215unlock:
Robin Getz2f95d5b2009-02-04 16:49:45 +08001216 if (!in_atomic)
Thomas Gleixner239007b2009-11-17 16:46:45 +01001217 raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Robin Getzd8f66c82007-12-24 15:27:56 +08001218 }
1219 }
Bryan Wu1394f032007-05-06 14:50:22 -07001220
Robin Getz226eb1e2007-10-29 17:59:07 +08001221 decode_address(buf, fp->rete);
Robin Getz9f06c382008-10-10 18:13:21 +08001222 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001223 decode_address(buf, fp->retn);
Robin Getz9f06c382008-10-10 18:13:21 +08001224 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001225 decode_address(buf, fp->retx);
Robin Getz9f06c382008-10-10 18:13:21 +08001226 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001227 decode_address(buf, fp->rets);
Robin Getz9f06c382008-10-10 18:13:21 +08001228 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001229 decode_address(buf, fp->pc);
Robin Getz9f06c382008-10-10 18:13:21 +08001230 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001231
Robin Getz13fe24f2008-01-27 15:38:56 +08001232 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1233 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Graf Yang8f658732008-11-18 17:48:22 +08001234 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001235 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +08001236 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001237 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001238 }
1239
Joe Perchesad361c92009-07-06 13:05:40 -07001240 verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001241 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001242 fp->r0, fp->r1, fp->r2, fp->r3);
Robin Getz9f06c382008-10-10 18:13:21 +08001243 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001244 fp->r4, fp->r5, fp->r6, fp->r7);
Robin Getz9f06c382008-10-10 18:13:21 +08001245 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001246 fp->p0, fp->p1, fp->p2, fp->p3);
Robin Getz9f06c382008-10-10 18:13:21 +08001247 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001248 fp->p4, fp->p5, fp->fp, (long)fp);
Robin Getz9f06c382008-10-10 18:13:21 +08001249 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001250 fp->lb0, fp->lt0, fp->lc0);
Robin Getz9f06c382008-10-10 18:13:21 +08001251 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001252 fp->lb1, fp->lt1, fp->lc1);
Robin Getz9f06c382008-10-10 18:13:21 +08001253 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001254 fp->b0, fp->l0, fp->m0, fp->i0);
Robin Getz9f06c382008-10-10 18:13:21 +08001255 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001256 fp->b1, fp->l1, fp->m1, fp->i1);
Robin Getz9f06c382008-10-10 18:13:21 +08001257 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001258 fp->b2, fp->l2, fp->m2, fp->i2);
Robin Getz9f06c382008-10-10 18:13:21 +08001259 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001260 fp->b3, fp->l3, fp->m3, fp->i3);
Robin Getz9f06c382008-10-10 18:13:21 +08001261 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001262 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1263
Robin Getz9f06c382008-10-10 18:13:21 +08001264 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001265 rdusp(), fp->astat);
1266
Robin Getz9f06c382008-10-10 18:13:21 +08001267 verbose_printk(KERN_NOTICE "\n");
1268#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001269}
1270
1271#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1272asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1273#endif
1274
Graf Yang8f658732008-11-18 17:48:22 +08001275static DEFINE_SPINLOCK(bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001276
Graf Yang8f658732008-11-18 17:48:22 +08001277asmlinkage int sys_bfin_spinlock(int *p)
1278{
1279 int ret, tmp = 0;
1280
1281 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1282 ret = get_user(tmp, p);
1283 if (likely(ret == 0)) {
1284 if (unlikely(tmp))
Bryan Wu1394f032007-05-06 14:50:22 -07001285 ret = 1;
Graf Yang8f658732008-11-18 17:48:22 +08001286 else
1287 put_user(1, p);
Bryan Wu1394f032007-05-06 14:50:22 -07001288 }
Graf Yang8f658732008-11-18 17:48:22 +08001289 spin_unlock(&bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001290 return ret;
1291}
1292
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001293int bfin_request_exception(unsigned int exception, void (*handler)(void))
1294{
1295 void (*curr_handler)(void);
1296
1297 if (exception > 0x3F)
1298 return -EINVAL;
1299
1300 curr_handler = ex_table[exception];
1301
1302 if (curr_handler != ex_replaceable)
1303 return -EBUSY;
1304
1305 ex_table[exception] = handler;
1306
1307 return 0;
1308}
1309EXPORT_SYMBOL(bfin_request_exception);
1310
1311int bfin_free_exception(unsigned int exception, void (*handler)(void))
1312{
1313 void (*curr_handler)(void);
1314
1315 if (exception > 0x3F)
1316 return -EINVAL;
1317
1318 curr_handler = ex_table[exception];
1319
1320 if (curr_handler != handler)
1321 return -EBUSY;
1322
1323 ex_table[exception] = ex_replaceable;
1324
1325 return 0;
1326}
1327EXPORT_SYMBOL(bfin_free_exception);
1328
Bryan Wu1394f032007-05-06 14:50:22 -07001329void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1330{
1331 switch (cplb_panic) {
1332 case CPLB_NO_UNLOCKED:
1333 printk(KERN_EMERG "All CPLBs are locked\n");
1334 break;
1335 case CPLB_PROT_VIOL:
1336 return;
1337 case CPLB_NO_ADDR_MATCH:
1338 return;
1339 case CPLB_UNKNOWN_ERR:
1340 printk(KERN_EMERG "Unknown CPLB Exception\n");
1341 break;
1342 }
1343
Robin Getz226eb1e2007-10-29 17:59:07 +08001344 oops_in_progress = 1;
1345
Mike Frysinger49dce912007-11-21 16:46:49 +08001346 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001347 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001348 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001349 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +00001350 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -07001351}