tree-wide: fix assorted typos all over the place
[linux-2.6-block.git] / arch / blackfin / kernel / traps.c
CommitLineData
1394f032 1/*
96f1050d 2 * Copyright 2004-2009 Analog Devices Inc.
1394f032 3 *
96f1050d 4 * Licensed under the GPL-2 or later
1394f032
BW
5 */
6
70f12567 7#include <linux/bug.h>
1f83b8f1
MF
8#include <linux/uaccess.h>
9#include <linux/interrupt.h>
10#include <linux/module.h>
11#include <linux/kallsyms.h>
d31c5ab1 12#include <linux/fs.h>
8feae131 13#include <linux/rbtree.h>
1394f032
BW
14#include <asm/traps.h>
15#include <asm/cacheflush.h>
f4585a08 16#include <asm/cplb.h>
e56e03b0 17#include <asm/dma.h>
1394f032 18#include <asm/blackfin.h>
1394f032 19#include <asm/irq_handler.h>
d8f66c8c 20#include <linux/irq.h>
669b792c 21#include <asm/trace.h>
226eb1ef 22#include <asm/fixed_code.h>
1394f032
BW
23
24#ifdef CONFIG_KGDB
1394f032 25# include <linux/kgdb.h>
226eb1ef
RG
26
27# define CHK_DEBUGGER_TRAP() \
28 do { \
a5ac0129 29 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
226eb1ef
RG
30 } 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)
1394f032
BW
39#endif
40
9f06c38f 41
4ee1c453 42#ifdef CONFIG_DEBUG_VERBOSE
9f06c38f
RG
43#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
81f7f456
RG
50#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
1394f032
BW
57/* Initiate the event table handler */
58void __init trap_init(void)
59{
60 CSYNC();
61 bfin_write_EVT3(trap);
62 CSYNC();
63}
64
226eb1ef 65static void decode_address(char *buf, unsigned long address)
1394f032 66{
9f06c38f 67#ifdef CONFIG_DEBUG_VERBOSE
1394f032
BW
68 struct task_struct *p;
69 struct mm_struct *mm;
885be03b 70 unsigned long flags, offset;
904656cd 71 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
8feae131 72 struct rb_node *n;
1394f032
BW
73
74#ifdef CONFIG_KALLSYMS
8a0e6656 75 unsigned long symsize;
1394f032
BW
76 const char *symname;
77 char *modname;
78 char *delim = ":";
79 char namebuf[128];
18070dd6
MF
80#endif
81
82 buf += sprintf(buf, "<0x%08lx> ", address);
1394f032 83
18070dd6 84#ifdef CONFIG_KALLSYMS
1394f032
BW
85 /* 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 = "";
18070dd6
MF
92 sprintf(buf, "{ %s%s%s%s + 0x%lx }",
93 delim, modname, delim, symname,
94 (unsigned long)offset);
885be03b 95 return;
1394f032
BW
96 }
97#endif
98
226eb1ef 99 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
18070dd6
MF
100 /* Problem in fixed code section? */
101 strcat(buf, "/* Maybe fixed code section */");
102 return;
103
104 } 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 */");
226eb1ef 115 return;
226eb1ef 116
18070dd6
MF
117 } else if (address >= L1_ROM_START && address < L1_ROM_START + L1_ROM_LENGTH) {
118 strcat(buf, "/* on-chip L1 ROM */");
226eb1ef
RG
119 return;
120 }
121
1394f032
BW
122 /* looks like we're off in user-land, so let's walk all the
123 * mappings of all our processes and see if we can't be a whee
124 * bit more specific
125 */
885be03b 126 write_lock_irqsave(&tasklist_lock, flags);
1394f032 127 for_each_process(p) {
904656cd 128 mm = (in_atomic ? p->mm : get_task_mm(p));
1394f032
BW
129 if (!mm)
130 continue;
131
8feae131
DH
132 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
133 struct vm_area_struct *vma;
134
135 vma = rb_entry(n, struct vm_area_struct, vm_rb);
1394f032
BW
136
137 if (address >= vma->vm_start && address < vma->vm_end) {
cf28b486 138 char _tmpbuf[256];
1394f032
BW
139 char *name = p->comm;
140 struct file *file = vma->vm_file;
cf28b486 141
6a0bfff4
TP
142 if (file) {
143 char *d_name = d_path(&file->f_path, _tmpbuf,
cf28b486 144 sizeof(_tmpbuf));
6a0bfff4
TP
145 if (!IS_ERR(d_name))
146 name = d_name;
147 }
1394f032 148
8a0e6656
MF
149 /* FLAT does not have its text aligned to the start of
150 * the map while FDPIC ELF does ...
151 */
7f1c9068
RG
152
153 /* before we can check flat/fdpic, we need to
154 * make sure current is valid
155 */
156 if ((unsigned long)current >= FIXED_CODE_START &&
157 !((unsigned long)current & 0x3)) {
158 if (current->mm &&
159 (address > current->mm->start_code) &&
160 (address < current->mm->end_code))
161 offset = address - current->mm->start_code;
162 else
163 offset = (address - vma->vm_start) +
164 (vma->vm_pgoff << PAGE_SHIFT);
165
18070dd6 166 sprintf(buf, "[ %s + 0x%lx ]", name, offset);
7f1c9068 167 } else
18070dd6
MF
168 sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
169 name, vma->vm_start, vma->vm_end);
7f1c9068 170
904656cd 171 if (!in_atomic)
885be03b 172 mmput(mm);
7f1c9068 173
18070dd6
MF
174 if (buf[0] == '\0')
175 sprintf(buf, "[ %s ] dynamic memory", name);
f09630bf 176
885be03b 177 goto done;
1394f032 178 }
1394f032 179 }
904656cd 180 if (!in_atomic)
885be03b 181 mmput(mm);
1394f032 182 }
1394f032
BW
183
184 /* we were unable to find this address anywhere */
18070dd6 185 sprintf(buf, "/* kernel dynamic memory */");
885be03b
RG
186
187done:
188 write_unlock_irqrestore(&tasklist_lock, flags);
9f06c38f
RG
189#else
190 sprintf(buf, " ");
191#endif
1394f032
BW
192}
193
2ebcade5
RG
194asmlinkage void double_fault_c(struct pt_regs *fp)
195{
a0cab656
RG
196#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
197 int j;
198 trace_buffer_save(j);
199#endif
200
226eb1ef
RG
201 console_verbose();
202 oops_in_progress = 1;
9f06c38f 203#ifdef CONFIG_DEBUG_VERBOSE
ad361c98 204 printk(KERN_EMERG "Double Fault\n");
0c7a6b21
RG
205#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
206 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
b6dbde27 207 unsigned int cpu = raw_smp_processor_id();
0c7a6b21 208 char buf[150];
01b9f4b0 209 decode_address(buf, cpu_pda[cpu].retx_doublefault);
0c7a6b21 210 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
01b9f4b0
GY
211 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
212 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
0c7a6b21 213 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
01b9f4b0 214 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
0c7a6b21
RG
215 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
216
217 decode_address(buf, fp->retx);
8f65873e 218 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
0c7a6b21
RG
219 } else
220#endif
221 {
222 dump_bfin_process(fp);
223 dump_bfin_mem(fp);
224 show_regs(fp);
a0cab656 225 dump_bfin_trace_buffer();
0c7a6b21 226 }
9f06c38f 227#endif
d8804adf 228 panic("Double Fault - unrecoverable event");
2ebcade5
RG
229
230}
231
82bd1d7d
MF
232static int kernel_mode_regs(struct pt_regs *regs)
233{
234 return regs->ipend & 0xffc0;
235}
236
c4baebf2 237asmlinkage notrace void trap_c(struct pt_regs *fp)
1394f032 238{
518039bc
RG
239#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
240 int j;
8f65873e
GY
241#endif
242#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
b6dbde27 243 unsigned int cpu = raw_smp_processor_id();
518039bc 244#endif
82bd1d7d 245 const char *strerror = NULL;
518039bc 246 int sig = 0;
1394f032
BW
247 siginfo_t info;
248 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
249
226eb1ef 250 trace_buffer_save(j);
81f7f456
RG
251#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
252 last_seqstat = (u32)fp->seqstat;
253#endif
226eb1ef
RG
254
255 /* Important - be very careful dereferncing pointers - will lead to
256 * double faults if the stack has become corrupt
257 */
258
1394f032
BW
259 /* trap_c() will be called for exceptions. During exceptions
260 * processing, the pc value should be set with retx value.
261 * With this change we can cleanup some code in signal.c- TODO
262 */
263 fp->orig_pc = fp->retx;
264 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
265 trapnr, fp->ipend, fp->pc, fp->retx); */
266
267 /* send the appropriate signal to the user program */
268 switch (trapnr) {
269
270 /* This table works in conjuction with the one in ./mach-common/entry.S
271 * Some exceptions are handled there (in assembly, in exception space)
272 * Some are handled here, (in C, in interrupt space)
273 * Some, like CPLB, are handled in both, where the normal path is
274 * handled in assembly/exception space, and the error path is handled
275 * here
276 */
277
278 /* 0x00 - Linux Syscall, getting here is an error */
279 /* 0x01 - userspace gdb breakpoint, handled here */
280 case VEC_EXCPT01:
281 info.si_code = TRAP_ILLTRAP;
282 sig = SIGTRAP;
283 CHK_DEBUGGER_TRAP_MAYBE();
284 /* Check if this is a breakpoint in kernel space */
82bd1d7d 285 if (kernel_mode_regs(fp))
6510a20e 286 goto traps_done;
1394f032
BW
287 else
288 break;
9401e618 289 /* 0x03 - User Defined, userspace stack overflow */
1394f032
BW
290 case VEC_EXCPT03:
291 info.si_code = SEGV_STACKFLOW;
292 sig = SIGSEGV;
82bd1d7d 293 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
a5ac0129 294 CHK_DEBUGGER_TRAP_MAYBE();
1394f032 295 break;
27707d3e
SZ
296 /* 0x02 - KGDB initial connection and break signal trap */
297 case VEC_EXCPT02:
298#ifdef CONFIG_KGDB
299 info.si_code = TRAP_ILLTRAP;
300 sig = SIGTRAP;
301 CHK_DEBUGGER_TRAP();
6510a20e 302 goto traps_done;
27707d3e 303#endif
5c64e0d5
RG
304 /* 0x04 - User Defined */
305 /* 0x05 - User Defined */
306 /* 0x06 - User Defined */
307 /* 0x07 - User Defined */
308 /* 0x08 - User Defined */
309 /* 0x09 - User Defined */
310 /* 0x0A - User Defined */
311 /* 0x0B - User Defined */
312 /* 0x0C - User Defined */
313 /* 0x0D - User Defined */
314 /* 0x0E - User Defined */
315 /* 0x0F - User Defined */
27707d3e 316 /* If we got here, it is most likely that someone was trying to use a
5c64e0d5
RG
317 * custom exception handler, and it is not actually installed properly
318 */
319 case VEC_EXCPT04 ... VEC_EXCPT15:
320 info.si_code = ILL_ILLPARAOP;
321 sig = SIGILL;
82bd1d7d 322 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
5c64e0d5
RG
323 CHK_DEBUGGER_TRAP_MAYBE();
324 break;
1394f032
BW
325 /* 0x10 HW Single step, handled here */
326 case VEC_STEP:
327 info.si_code = TRAP_STEP;
328 sig = SIGTRAP;
329 CHK_DEBUGGER_TRAP_MAYBE();
330 /* Check if this is a single step in kernel space */
82bd1d7d 331 if (kernel_mode_regs(fp))
6510a20e 332 goto traps_done;
1394f032
BW
333 else
334 break;
335 /* 0x11 - Trace Buffer Full, handled here */
336 case VEC_OVFLOW:
337 info.si_code = TRAP_TRACEFLOW;
338 sig = SIGTRAP;
82bd1d7d 339 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
a5ac0129 340 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
341 break;
342 /* 0x12 - Reserved, Caught by default */
343 /* 0x13 - Reserved, Caught by default */
344 /* 0x14 - Reserved, Caught by default */
345 /* 0x15 - Reserved, Caught by default */
346 /* 0x16 - Reserved, Caught by default */
347 /* 0x17 - Reserved, Caught by default */
348 /* 0x18 - Reserved, Caught by default */
349 /* 0x19 - Reserved, Caught by default */
350 /* 0x1A - Reserved, Caught by default */
351 /* 0x1B - Reserved, Caught by default */
352 /* 0x1C - Reserved, Caught by default */
353 /* 0x1D - Reserved, Caught by default */
354 /* 0x1E - Reserved, Caught by default */
355 /* 0x1F - Reserved, Caught by default */
356 /* 0x20 - Reserved, Caught by default */
357 /* 0x21 - Undefined Instruction, handled here */
358 case VEC_UNDEF_I:
70f12567
MF
359#ifdef CONFIG_BUG
360 if (kernel_mode_regs(fp)) {
361 switch (report_bug(fp->pc, fp)) {
362 case BUG_TRAP_TYPE_NONE:
363 break;
364 case BUG_TRAP_TYPE_WARN:
365 dump_bfin_trace_buffer();
366 fp->pc += 2;
367 goto traps_done;
368 case BUG_TRAP_TYPE_BUG:
369 /* call to panic() will dump trace, and it is
370 * off at this point, so it won't be clobbered
371 */
372 panic("BUG()");
373 }
374 }
375#endif
1394f032
BW
376 info.si_code = ILL_ILLOPC;
377 sig = SIGILL;
82bd1d7d 378 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
a5ac0129 379 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
380 break;
381 /* 0x22 - Illegal Instruction Combination, handled here */
382 case VEC_ILGAL_I:
383 info.si_code = ILL_ILLPARAOP;
384 sig = SIGILL;
82bd1d7d 385 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
a5ac0129 386 CHK_DEBUGGER_TRAP_MAYBE();
1394f032 387 break;
f26fbc48 388 /* 0x23 - Data CPLB protection violation, handled here */
1394f032
BW
389 case VEC_CPLB_VL:
390 info.si_code = ILL_CPLB_VI;
36b84128 391 sig = SIGSEGV;
82bd1d7d 392 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
a5ac0129 393 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
394 break;
395 /* 0x24 - Data access misaligned, handled here */
396 case VEC_MISALI_D:
397 info.si_code = BUS_ADRALN;
398 sig = SIGBUS;
82bd1d7d 399 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
a5ac0129 400 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
401 break;
402 /* 0x25 - Unrecoverable Event, handled here */
403 case VEC_UNCOV:
404 info.si_code = ILL_ILLEXCPT;
405 sig = SIGILL;
82bd1d7d 406 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
a5ac0129 407 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
408 break;
409 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
410 error case is handled here */
411 case VEC_CPLB_M:
412 info.si_code = BUS_ADRALN;
413 sig = SIGBUS;
82bd1d7d 414 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
1394f032
BW
415 break;
416 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
417 case VEC_CPLB_MHIT:
418 info.si_code = ILL_CPLB_MULHIT;
1394f032 419 sig = SIGSEGV;
c6c6f75d 420#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
8f65873e 421 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
82bd1d7d 422 strerror = KERN_NOTICE "NULL pointer access\n";
c6c6f75d 423 else
1394f032 424#endif
82bd1d7d 425 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
a5ac0129 426 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
427 break;
428 /* 0x28 - Emulation Watchpoint, handled here */
429 case VEC_WATCH:
430 info.si_code = TRAP_WATCHPT;
431 sig = SIGTRAP;
569a50ca 432 pr_debug(EXC_0x28(KERN_DEBUG));
1394f032
BW
433 CHK_DEBUGGER_TRAP_MAYBE();
434 /* Check if this is a watchpoint in kernel space */
82bd1d7d 435 if (kernel_mode_regs(fp))
6510a20e 436 goto traps_done;
1394f032
BW
437 else
438 break;
439#ifdef CONFIG_BF535
440 /* 0x29 - Instruction fetch access error (535 only) */
441 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
442 info.si_code = BUS_OPFETCH;
443 sig = SIGBUS;
82bd1d7d 444 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
a5ac0129 445 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
446 break;
447#else
448 /* 0x29 - Reserved, Caught by default */
449#endif
450 /* 0x2A - Instruction fetch misaligned, handled here */
451 case VEC_MISALI_I:
452 info.si_code = BUS_ADRALN;
453 sig = SIGBUS;
82bd1d7d 454 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
a5ac0129 455 CHK_DEBUGGER_TRAP_MAYBE();
1394f032 456 break;
f26fbc48 457 /* 0x2B - Instruction CPLB protection violation, handled here */
1394f032
BW
458 case VEC_CPLB_I_VL:
459 info.si_code = ILL_CPLB_VI;
f26fbc48 460 sig = SIGBUS;
82bd1d7d 461 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
a5ac0129 462 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
463 break;
464 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
465 case VEC_CPLB_I_M:
466 info.si_code = ILL_CPLB_MISS;
467 sig = SIGBUS;
82bd1d7d 468 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
1394f032
BW
469 break;
470 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
471 case VEC_CPLB_I_MHIT:
472 info.si_code = ILL_CPLB_MULHIT;
1394f032 473 sig = SIGSEGV;
c6c6f75d 474#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
8f65873e 475 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
82bd1d7d 476 strerror = KERN_NOTICE "Jump to NULL address\n";
c6c6f75d 477 else
1394f032 478#endif
82bd1d7d 479 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
a5ac0129 480 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
481 break;
482 /* 0x2E - Illegal use of Supervisor Resource, handled here */
483 case VEC_ILL_RES:
484 info.si_code = ILL_PRVOPC;
485 sig = SIGILL;
82bd1d7d 486 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
a5ac0129 487 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
488 break;
489 /* 0x2F - Reserved, Caught by default */
490 /* 0x30 - Reserved, Caught by default */
491 /* 0x31 - Reserved, Caught by default */
492 /* 0x32 - Reserved, Caught by default */
493 /* 0x33 - Reserved, Caught by default */
494 /* 0x34 - Reserved, Caught by default */
495 /* 0x35 - Reserved, Caught by default */
496 /* 0x36 - Reserved, Caught by default */
497 /* 0x37 - Reserved, Caught by default */
498 /* 0x38 - Reserved, Caught by default */
499 /* 0x39 - Reserved, Caught by default */
500 /* 0x3A - Reserved, Caught by default */
501 /* 0x3B - Reserved, Caught by default */
502 /* 0x3C - Reserved, Caught by default */
503 /* 0x3D - Reserved, Caught by default */
504 /* 0x3E - Reserved, Caught by default */
505 /* 0x3F - Reserved, Caught by default */
13fe24f3
RG
506 case VEC_HWERR:
507 info.si_code = BUS_ADRALN;
508 sig = SIGBUS;
509 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
510 /* System MMR Error */
511 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
512 info.si_code = BUS_ADRALN;
513 sig = SIGBUS;
82bd1d7d 514 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
13fe24f3
RG
515 break;
516 /* External Memory Addressing Error */
517 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
518 info.si_code = BUS_ADRERR;
519 sig = SIGBUS;
82bd1d7d 520 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
13fe24f3
RG
521 break;
522 /* Performance Monitor Overflow */
523 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
82bd1d7d 524 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
13fe24f3
RG
525 break;
526 /* RAISE 5 instruction */
527 case (SEQSTAT_HWERRCAUSE_RAISE_5):
528 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
529 break;
530 default: /* Reserved */
531 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
532 break;
533 }
a5ac0129 534 CHK_DEBUGGER_TRAP_MAYBE();
13fe24f3 535 break;
5c64e0d5
RG
536 /*
537 * We should be handling all known exception types above,
538 * if we get here we hit a reserved one, so panic
539 */
1394f032 540 default:
5c64e0d5
RG
541 info.si_code = ILL_ILLPARAOP;
542 sig = SIGILL;
9f06c38f 543 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
1394f032 544 (fp->seqstat & SEQSTAT_EXCAUSE));
a5ac0129 545 CHK_DEBUGGER_TRAP_MAYBE();
1394f032
BW
546 break;
547 }
548
226eb1ef
RG
549 BUG_ON(sig == 0);
550
82bd1d7d
MF
551 /* If the fault was caused by a kernel thread, or interrupt handler
552 * we will kernel panic, so the system reboots.
553 */
554 if (kernel_mode_regs(fp) || (current && !current->mm)) {
555 console_verbose();
556 oops_in_progress = 1;
82bd1d7d
MF
557 }
558
226eb1ef 559 if (sig != SIGTRAP) {
15627bd3
MF
560 if (strerror)
561 verbose_printk(strerror);
562
49dce912 563 dump_bfin_process(fp);
b03b08ba 564 dump_bfin_mem(fp);
49dce912 565 show_regs(fp);
226eb1ef
RG
566
567 /* Print out the trace buffer if it makes sense */
568#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
569 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
9f06c38f 570 verbose_printk(KERN_NOTICE "No trace since you do not have "
ad361c98 571 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
226eb1ef
RG
572 else
573#endif
574 dump_bfin_trace_buffer();
f09630bf 575
226eb1ef 576 if (oops_in_progress) {
f09630bf 577 /* Dump the current kernel stack */
ad361c98 578 verbose_printk(KERN_NOTICE "Kernel Stack\n");
f09630bf 579 show_stack(current, NULL);
aee3a292 580 print_modules();
226eb1ef 581#ifndef CONFIG_ACCESS_CHECK
9f06c38f 582 verbose_printk(KERN_EMERG "Please turn on "
90c7f468 583 "CONFIG_ACCESS_CHECK\n");
226eb1ef 584#endif
1394f032 585 panic("Kernel exception");
f09630bf 586 } else {
4ee1c453 587#ifdef CONFIG_DEBUG_VERBOSE
9f06c38f 588 unsigned long *stack;
f09630bf
RG
589 /* Dump the user space stack */
590 stack = (unsigned long *)rdusp();
9f06c38f 591 verbose_printk(KERN_NOTICE "Userspace Stack\n");
f09630bf 592 show_stack(NULL, stack);
9f06c38f 593#endif
226eb1ef 594 }
1394f032 595 }
fb322915 596
6a01f230
YL
597#ifdef CONFIG_IPIPE
598 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
599#endif
600 {
601 info.si_signo = sig;
602 info.si_errno = 0;
603 info.si_addr = (void __user *)fp->pc;
604 force_sig_info(sig, &info, current);
605 }
1394f032 606
0e4edcf0 607 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
f574a76a
RG
608 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
609 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
0acad8df
RG
610 fp->pc = SAFE_USER_INSTRUCTION;
611
6510a20e 612 traps_done:
1394f032 613 trace_buffer_restore(j);
1394f032
BW
614}
615
616/* Typical exception handling routines */
617
518039bc
RG
618#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
619
f09630bf
RG
620/*
621 * Similar to get_user, do some address checking, then dereference
af901ca1 622 * Return true on success, false on bad address
f09630bf 623 */
9f06c38f 624static bool get_instruction(unsigned short *val, unsigned short *address)
f09630bf 625{
e56e03b0 626 unsigned long addr = (unsigned long)address;
f09630bf
RG
627
628 /* Check for odd addresses */
629 if (addr & 0x1)
630 return false;
631
e56e03b0
MF
632 /* MMR region will never have instructions */
633 if (addr >= SYSMMR_BASE)
f09630bf
RG
634 return false;
635
e56e03b0
MF
636 switch (bfin_mem_access_type(addr, 2)) {
637 case BFIN_MEM_ACCESS_CORE:
638 case BFIN_MEM_ACCESS_CORE_ONLY:
639 *val = *address;
640 return true;
641 case BFIN_MEM_ACCESS_DMA:
642 dma_memcpy(val, address, 2);
643 return true;
644 case BFIN_MEM_ACCESS_ITEST:
645 isram_memcpy(val, address, 2);
646 return true;
647 default: /* invalid access */
648 return false;
f09630bf 649 }
f09630bf
RG
650}
651
36f649a5 652/*
d3d0ac23
RG
653 * decode the instruction if we are printing out the trace, as it
654 * makes things easier to follow, without running it through objdump
655 * These are the normal instructions which cause change of flow, which
656 * would be at the source of the trace buffer
657 */
36f649a5 658#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
9f06c38f 659static void decode_instruction(unsigned short *address)
d3d0ac23
RG
660{
661 unsigned short opcode;
662
663 if (get_instruction(&opcode, address)) {
664 if (opcode == 0x0010)
9f06c38f 665 verbose_printk("RTS");
d3d0ac23 666 else if (opcode == 0x0011)
9f06c38f 667 verbose_printk("RTI");
d3d0ac23 668 else if (opcode == 0x0012)
9f06c38f 669 verbose_printk("RTX");
0be58939
RG
670 else if (opcode == 0x0013)
671 verbose_printk("RTN");
672 else if (opcode == 0x0014)
673 verbose_printk("RTE");
674 else if (opcode == 0x0025)
675 verbose_printk("EMUEXCPT");
676 else if (opcode == 0x0040 && opcode <= 0x0047)
677 verbose_printk("STI R%i", opcode & 7);
d3d0ac23 678 else if (opcode >= 0x0050 && opcode <= 0x0057)
9f06c38f 679 verbose_printk("JUMP (P%i)", opcode & 7);
d3d0ac23 680 else if (opcode >= 0x0060 && opcode <= 0x0067)
9f06c38f 681 verbose_printk("CALL (P%i)", opcode & 7);
d3d0ac23 682 else if (opcode >= 0x0070 && opcode <= 0x0077)
9f06c38f 683 verbose_printk("CALL (PC+P%i)", opcode & 7);
d3d0ac23 684 else if (opcode >= 0x0080 && opcode <= 0x0087)
9f06c38f 685 verbose_printk("JUMP (PC+P%i)", opcode & 7);
0be58939
RG
686 else if (opcode >= 0x0090 && opcode <= 0x009F)
687 verbose_printk("RAISE 0x%x", opcode & 0xF);
688 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
689 verbose_printk("EXCPT 0x%x", opcode & 0xF);
d3d0ac23 690 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
9f06c38f 691 verbose_printk("IF !CC JUMP");
d3d0ac23 692 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
9f06c38f 693 verbose_printk("IF CC JUMP");
d3d0ac23 694 else if (opcode >= 0x2000 && opcode <= 0x2fff)
9f06c38f 695 verbose_printk("JUMP.S");
d3d0ac23 696 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
9f06c38f 697 verbose_printk("LSETUP");
d3d0ac23 698 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
9f06c38f 699 verbose_printk("JUMP.L");
d3d0ac23 700 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
9f06c38f 701 verbose_printk("CALL pcrel");
d3d0ac23 702 else
9f06c38f 703 verbose_printk("0x%04x", opcode);
d3d0ac23
RG
704 }
705
706}
9f06c38f 707#endif
d3d0ac23 708
1394f032
BW
709void dump_bfin_trace_buffer(void)
710{
9f06c38f 711#ifdef CONFIG_DEBUG_VERBOSE
518039bc
RG
712#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
713 int tflags, i = 0;
226eb1ef 714 char buf[150];
d3d0ac23 715 unsigned short *addr;
518039bc
RG
716#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
717 int j, index;
718#endif
719
1394f032
BW
720 trace_buffer_save(tflags);
721
226eb1ef 722 printk(KERN_NOTICE "Hardware Trace:\n");
518039bc 723
d3d0ac23
RG
724#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
725 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
726#endif
727
1394f032 728 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
518039bc 729 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
226eb1ef
RG
730 decode_address(buf, (unsigned long)bfin_read_TBUF());
731 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
f09630bf
RG
732 addr = (unsigned short *)bfin_read_TBUF();
733 decode_address(buf, (unsigned long)addr);
734 printk(KERN_NOTICE " Source : %s ", buf);
d3d0ac23 735 decode_instruction(addr);
f09630bf 736 printk("\n");
1394f032
BW
737 }
738 }
739
518039bc
RG
740#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
741 if (trace_buff_offset)
d3d0ac23 742 index = trace_buff_offset / 4;
518039bc
RG
743 else
744 index = EXPAND_LEN;
745
746 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
747 while (j) {
226eb1ef
RG
748 decode_address(buf, software_trace_buff[index]);
749 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
518039bc
RG
750 index -= 1;
751 if (index < 0 )
752 index = EXPAND_LEN;
226eb1ef 753 decode_address(buf, software_trace_buff[index]);
d3d0ac23
RG
754 printk(KERN_NOTICE " Source : %s ", buf);
755 decode_instruction((unsigned short *)software_trace_buff[index]);
756 printk("\n");
518039bc
RG
757 index -= 1;
758 if (index < 0)
759 index = EXPAND_LEN;
518039bc
RG
760 j--;
761 i++;
762 }
763#endif
764
1394f032 765 trace_buffer_restore(tflags);
518039bc 766#endif
9f06c38f 767#endif
1394f032
BW
768}
769EXPORT_SYMBOL(dump_bfin_trace_buffer);
770
70f12567
MF
771#ifdef CONFIG_BUG
772int is_valid_bugaddr(unsigned long addr)
773{
774 unsigned short opcode;
775
776 if (!get_instruction(&opcode, (unsigned short *)addr))
777 return 0;
778
779 return opcode == BFIN_BUG_OPCODE;
780}
781#endif
782
f09630bf
RG
783/*
784 * Checks to see if the address pointed to is either a
785 * 16-bit CALL instruction, or a 32-bit CALL instruction
786 */
9f06c38f 787static bool is_bfin_call(unsigned short *addr)
1394f032 788{
f09630bf
RG
789 unsigned short opcode = 0, *ins_addr;
790 ins_addr = (unsigned short *)addr;
1394f032 791
f09630bf
RG
792 if (!get_instruction(&opcode, ins_addr))
793 return false;
1394f032 794
f09630bf
RG
795 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
796 (opcode >= 0x0070 && opcode <= 0x0077))
797 return true;
798
799 ins_addr--;
800 if (!get_instruction(&opcode, ins_addr))
801 return false;
1394f032 802
f09630bf
RG
803 if (opcode >= 0xE300 && opcode <= 0xE3FF)
804 return true;
805
806 return false;
807
808}
9f06c38f 809
1394f032
BW
810void show_stack(struct task_struct *task, unsigned long *stack)
811{
9f06c38f 812#ifdef CONFIG_PRINTK
f09630bf
RG
813 unsigned int *addr, *endstack, *fp = 0, *frame;
814 unsigned short *ins_addr;
815 char buf[150];
816 unsigned int i, j, ret_addr, frame_no = 0;
1394f032 817
f09630bf
RG
818 /*
819 * If we have been passed a specific stack, use that one otherwise
820 * if we have been passed a task structure, use that, otherwise
821 * use the stack of where the variable "stack" exists
1394f032
BW
822 */
823
f09630bf
RG
824 if (stack == NULL) {
825 if (task) {
826 /* We know this is a kernel stack, so this is the start/end */
1394f032 827 stack = (unsigned long *)task->thread.ksp;
f09630bf
RG
828 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
829 } else {
830 /* print out the existing stack info */
1394f032 831 stack = (unsigned long *)&stack;
f09630bf
RG
832 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
833 }
834 } else
835 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
836
9f06c38f 837 printk(KERN_NOTICE "Stack info:\n");
f09630bf 838 decode_address(buf, (unsigned int)stack);
9f06c38f
RG
839 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
840
a0cab656
RG
841 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
842 printk(KERN_NOTICE "Invalid stack pointer\n");
843 return;
844 }
845
f09630bf 846 /* First thing is to look for a frame pointer */
881eb621 847 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
f09630bf
RG
848 if (*addr & 0x1)
849 continue;
850 ins_addr = (unsigned short *)*addr;
851 ins_addr--;
852 if (is_bfin_call(ins_addr))
853 fp = addr - 1;
854
855 if (fp) {
856 /* Let's check to see if it is a frame pointer */
881eb621
JZ
857 while (fp >= (addr - 1) && fp < endstack
858 && fp && ((unsigned int) fp & 0x3) == 0)
f09630bf
RG
859 fp = (unsigned int *)*fp;
860 if (fp == 0 || fp == endstack) {
861 fp = addr - 1;
862 break;
863 }
864 fp = 0;
865 }
1394f032 866 }
f09630bf
RG
867 if (fp) {
868 frame = fp;
b339dc79 869 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
f09630bf
RG
870 } else
871 frame = 0;
1394f032 872
f09630bf
RG
873 /*
874 * Now that we think we know where things are, we
875 * walk the stack again, this time printing things out
876 * incase there is no frame pointer, we still look for
877 * valid return addresses
878 */
1394f032 879
f09630bf
RG
880 /* First time print out data, next time, print out symbols */
881 for (j = 0; j <= 1; j++) {
882 if (j)
883 printk(KERN_NOTICE "Return addresses in stack:\n");
884 else
885 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
886
887 fp = frame;
888 frame_no = 0;
889
890 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
407505dc 891 addr < endstack; addr++, i++) {
f09630bf
RG
892
893 ret_addr = 0;
894 if (!j && i % 8 == 0)
ad361c98 895 printk(KERN_NOTICE "%p:",addr);
f09630bf
RG
896
897 /* if it is an odd address, or zero, just skip it */
898 if (*addr & 0x1 || !*addr)
899 goto print;
900
901 ins_addr = (unsigned short *)*addr;
902
903 /* Go back one instruction, and see if it is a CALL */
904 ins_addr--;
905 ret_addr = is_bfin_call(ins_addr);
906 print:
907 if (!j && stack == (unsigned long *)addr)
908 printk("[%08x]", *addr);
909 else if (ret_addr)
910 if (j) {
911 decode_address(buf, (unsigned int)*addr);
912 if (frame == addr) {
913 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
914 continue;
915 }
916 printk(KERN_NOTICE " address : %s\n", buf);
917 } else
918 printk("<%08x>", *addr);
919 else if (fp == addr) {
920 if (j)
921 frame = addr+1;
922 else
923 printk("(%08x)", *addr);
924
925 fp = (unsigned int *)*addr;
926 frame_no++;
927
928 } else if (!j)
929 printk(" %08x ", *addr);
930 }
931 if (!j)
932 printk("\n");
1394f032 933 }
9f06c38f 934#endif
1394f032 935}
bc569f1a 936EXPORT_SYMBOL(show_stack);
1394f032
BW
937
938void dump_stack(void)
939{
940 unsigned long stack;
518039bc 941#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
1394f032 942 int tflags;
518039bc 943#endif
1394f032
BW
944 trace_buffer_save(tflags);
945 dump_bfin_trace_buffer();
946 show_stack(current, &stack);
947 trace_buffer_restore(tflags);
948}
1394f032
BW
949EXPORT_SYMBOL(dump_stack);
950
49dce912 951void dump_bfin_process(struct pt_regs *fp)
1394f032 952{
9f06c38f 953#ifdef CONFIG_DEBUG_VERBOSE
49dce912
MF
954 /* We should be able to look at fp->ipend, but we don't push it on the
955 * stack all the time, so do this until we fix that */
956 unsigned int context = bfin_read_IPEND();
957
958 if (oops_in_progress)
9f06c38f 959 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
49dce912 960
b03b08ba 961 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
9f06c38f 962 verbose_printk(KERN_NOTICE "HW Error context\n");
b03b08ba 963 else if (context & 0x0020)
9f06c38f 964 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
49dce912 965 else if (context & 0x3FC0)
9f06c38f 966 verbose_printk(KERN_NOTICE "Interrupt context\n");
49dce912 967 else if (context & 0x4000)
9f06c38f 968 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
49dce912 969 else if (context & 0x8000)
9f06c38f 970 verbose_printk(KERN_NOTICE "Kernel process context\n");
49dce912 971
9a62ca40
RG
972 /* Because we are crashing, and pointers could be bad, we check things
973 * pretty closely before we use them
974 */
7f1c9068
RG
975 if ((unsigned long)current >= FIXED_CODE_START &&
976 !((unsigned long)current & 0x3) && current->pid) {
9f06c38f 977 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
9a62ca40 978 if (current->comm >= (char *)FIXED_CODE_START)
9f06c38f 979 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
9a62ca40
RG
980 current->comm, current->pid);
981 else
9f06c38f 982 verbose_printk(KERN_NOTICE "COMM= invalid\n");
9a62ca40 983
8f65873e 984 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
9a62ca40 985 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
ad361c98
JP
986 verbose_printk(KERN_NOTICE
987 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
988 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
9a62ca40
RG
989 (void *)current->mm->start_code,
990 (void *)current->mm->end_code,
991 (void *)current->mm->start_data,
992 (void *)current->mm->end_data,
993 (void *)current->mm->end_data,
994 (void *)current->mm->brk,
995 (void *)current->mm->start_stack);
996 else
9f06c38f 997 verbose_printk(KERN_NOTICE "invalid mm\n");
49dce912 998 } else
ad361c98
JP
999 verbose_printk(KERN_NOTICE
1000 "No Valid process in current context\n");
9f06c38f 1001#endif
49dce912 1002}
226eb1ef 1003
b03b08ba 1004void dump_bfin_mem(struct pt_regs *fp)
49dce912 1005{
9f06c38f 1006#ifdef CONFIG_DEBUG_VERBOSE
b03b08ba
RG
1007 unsigned short *addr, *erraddr, val = 0, err = 0;
1008 char sti = 0, buf[6];
1394f032 1009
5d750b9e 1010 erraddr = (void *)fp->pc;
b03b08ba 1011
9f06c38f 1012 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
b03b08ba
RG
1013
1014 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1015 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1016 addr++) {
1017 if (!((unsigned long)addr & 0xF))
ad361c98 1018 verbose_printk(KERN_NOTICE "0x%p: ", addr);
b03b08ba 1019
7d98c881 1020 if (!get_instruction(&val, addr)) {
b03b08ba
RG
1021 val = 0;
1022 sprintf(buf, "????");
b03b08ba
RG
1023 } else
1024 sprintf(buf, "%04x", val);
1025
1026 if (addr == erraddr) {
9f06c38f 1027 verbose_printk("[%s]", buf);
b03b08ba
RG
1028 err = val;
1029 } else
9f06c38f 1030 verbose_printk(" %s ", buf);
b03b08ba
RG
1031
1032 /* Do any previous instructions turn on interrupts? */
1033 if (addr <= erraddr && /* in the past */
1034 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1035 val == 0x017b)) /* [SP++] = RETI */
1036 sti = 1;
1037 }
1038
9f06c38f 1039 verbose_printk("\n");
b03b08ba
RG
1040
1041 /* Hardware error interrupts can be deferred */
1042 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1043 oops_in_progress)){
9f06c38f 1044 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
1394f032 1045#ifndef CONFIG_DEBUG_HWERR
ad361c98
JP
1046 verbose_printk(KERN_NOTICE
1047"The remaining message may be meaningless\n"
1048"You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
b03b08ba
RG
1049#else
1050 /* If we are handling only one peripheral interrupt
1051 * and current mm and pid are valid, and the last error
1052 * was in that user space process's text area
1053 * print it out - because that is where the problem exists
1054 */
1055 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1056 (current->pid && current->mm)) {
1057 /* And the last RETI points to the current userspace context */
1058 if ((fp + 1)->pc >= current->mm->start_code &&
1059 (fp + 1)->pc <= current->mm->end_code) {
9f06c38f
RG
1060 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1061 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
b03b08ba 1062 show_regs(fp + 1);
9f06c38f 1063 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
b03b08ba 1064 }
1394f032 1065 }
b03b08ba
RG
1066#endif
1067 }
9f06c38f 1068#endif
49dce912
MF
1069}
1070
1071void show_regs(struct pt_regs *fp)
1072{
9f06c38f 1073#ifdef CONFIG_DEBUG_VERBOSE
49dce912 1074 char buf [150];
d8f66c8c
RG
1075 struct irqaction *action;
1076 unsigned int i;
2f95d5bd 1077 unsigned long flags = 0;
b6dbde27 1078 unsigned int cpu = raw_smp_processor_id();
2f95d5bd 1079 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
226eb1ef 1080
9ba3c24f
RG
1081 verbose_printk(KERN_NOTICE "\n");
1082 if (CPUID != bfin_cpuid())
1083 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1084 "but running on:0x%04x (Rev %d)\n",
1085 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1086
1087 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1088 CPU, bfin_compiled_revid());
1089
1090 if (bfin_compiled_revid() != bfin_revid())
1091 verbose_printk("(Detected 0.%d)", bfin_revid());
1092
1093 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1094 get_cclk()/1000000, get_sclk()/1000000,
1095#ifdef CONFIG_MPU
1096 "mpu on"
1097#else
1098 "mpu off"
1099#endif
1100 );
1101
1102 verbose_printk(KERN_NOTICE "%s", linux_banner);
1103
ae4f073c
RG
1104 verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
1105 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
b6dbde27 1106 (long)fp->seqstat, fp->ipend, cpu_pda[raw_smp_processor_id()].ex_imask, fp->syscfg);
ae4f073c
RG
1107 if (fp->ipend & EVT_IRPTEN)
1108 verbose_printk(KERN_NOTICE " Global Interrupts Disabled (IPEND[4])\n");
b6dbde27 1109 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
ae4f073c
RG
1110 EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
1111 verbose_printk(KERN_NOTICE " Peripheral interrupts masked off\n");
b6dbde27 1112 if (!(cpu_pda[raw_smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
ae4f073c 1113 verbose_printk(KERN_NOTICE " Kernel interrupts masked off\n");
1d5ff7e2 1114 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
9f06c38f 1115 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1d5ff7e2
RG
1116 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1117#ifdef EBIU_ERRMST
1118 /* If the error was from the EBIU, print it out */
1119 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
9f06c38f 1120 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
1d5ff7e2 1121 bfin_read_EBIU_ERRMST());
9f06c38f 1122 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
1d5ff7e2
RG
1123 bfin_read_EBIU_ERRADD());
1124 }
1125#endif
1126 }
9f06c38f 1127 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
13fe24f3 1128 fp->seqstat & SEQSTAT_EXCAUSE);
2f95d5bd 1129 for (i = 2; i <= 15 ; i++) {
d8f66c8c 1130 if (fp->ipend & (1 << i)) {
2f95d5bd
RG
1131 if (i != 4) {
1132 decode_address(buf, bfin_read32(EVT0 + 4*i));
1133 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1134 } else
1135 verbose_printk(KERN_NOTICE " interrupts disabled\n");
d8f66c8c
RG
1136 }
1137 }
1138
1139 /* if no interrupts are going off, don't print this out */
1140 if (fp->ipend & ~0x3F) {
1141 for (i = 0; i < (NR_IRQS - 1); i++) {
2f95d5bd
RG
1142 if (!in_atomic)
1143 spin_lock_irqsave(&irq_desc[i].lock, flags);
1144
d8f66c8c
RG
1145 action = irq_desc[i].action;
1146 if (!action)
1147 goto unlock;
1148
1149 decode_address(buf, (unsigned int)action->handler);
9f06c38f 1150 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
d8f66c8c
RG
1151 for (action = action->next; action; action = action->next) {
1152 decode_address(buf, (unsigned int)action->handler);
9f06c38f 1153 verbose_printk(", %s", buf);
d8f66c8c 1154 }
9f06c38f 1155 verbose_printk("\n");
d8f66c8c 1156unlock:
2f95d5bd
RG
1157 if (!in_atomic)
1158 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
d8f66c8c
RG
1159 }
1160 }
c5d88d9e 1161
226eb1ef 1162 decode_address(buf, fp->rete);
9f06c38f 1163 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
226eb1ef 1164 decode_address(buf, fp->retn);
9f06c38f 1165 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
226eb1ef 1166 decode_address(buf, fp->retx);
9f06c38f 1167 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
226eb1ef 1168 decode_address(buf, fp->rets);
9f06c38f 1169 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
49dce912 1170 decode_address(buf, fp->pc);
9f06c38f 1171 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
c5d88d9e 1172
13fe24f3
RG
1173 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1174 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
8f65873e 1175 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
9f06c38f 1176 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
8f65873e 1177 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
9f06c38f 1178 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
226eb1ef
RG
1179 }
1180
ad361c98 1181 verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
9f06c38f 1182 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
c5d88d9e 1183 fp->r0, fp->r1, fp->r2, fp->r3);
9f06c38f 1184 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
c5d88d9e 1185 fp->r4, fp->r5, fp->r6, fp->r7);
9f06c38f 1186 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
c5d88d9e 1187 fp->p0, fp->p1, fp->p2, fp->p3);
9f06c38f 1188 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
226eb1ef 1189 fp->p4, fp->p5, fp->fp, (long)fp);
9f06c38f 1190 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
c5d88d9e 1191 fp->lb0, fp->lt0, fp->lc0);
9f06c38f 1192 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
c5d88d9e 1193 fp->lb1, fp->lt1, fp->lc1);
9f06c38f 1194 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
c5d88d9e 1195 fp->b0, fp->l0, fp->m0, fp->i0);
9f06c38f 1196 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
c5d88d9e 1197 fp->b1, fp->l1, fp->m1, fp->i1);
9f06c38f 1198 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
c5d88d9e 1199 fp->b2, fp->l2, fp->m2, fp->i2);
9f06c38f 1200 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
c5d88d9e 1201 fp->b3, fp->l3, fp->m3, fp->i3);
9f06c38f 1202 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
226eb1ef 1203 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
c5d88d9e 1204
9f06c38f 1205 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
c5d88d9e 1206 rdusp(), fp->astat);
1394f032 1207
9f06c38f
RG
1208 verbose_printk(KERN_NOTICE "\n");
1209#endif
1394f032
BW
1210}
1211
1212#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1213asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1214#endif
1215
8f65873e
GY
1216static DEFINE_SPINLOCK(bfin_spinlock_lock);
1217
1218asmlinkage int sys_bfin_spinlock(int *p)
1394f032 1219{
8f65873e 1220 int ret, tmp = 0;
1394f032 1221
8f65873e
GY
1222 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1223 ret = get_user(tmp, p);
1224 if (likely(ret == 0)) {
1225 if (unlikely(tmp))
1394f032 1226 ret = 1;
8f65873e
GY
1227 else
1228 put_user(1, p);
1394f032 1229 }
8f65873e 1230 spin_unlock(&bfin_spinlock_lock);
1394f032
BW
1231 return ret;
1232}
1233
1ffe6646
MF
1234int bfin_request_exception(unsigned int exception, void (*handler)(void))
1235{
1236 void (*curr_handler)(void);
1237
1238 if (exception > 0x3F)
1239 return -EINVAL;
1240
1241 curr_handler = ex_table[exception];
1242
1243 if (curr_handler != ex_replaceable)
1244 return -EBUSY;
1245
1246 ex_table[exception] = handler;
1247
1248 return 0;
1249}
1250EXPORT_SYMBOL(bfin_request_exception);
1251
1252int bfin_free_exception(unsigned int exception, void (*handler)(void))
1253{
1254 void (*curr_handler)(void);
1255
1256 if (exception > 0x3F)
1257 return -EINVAL;
1258
1259 curr_handler = ex_table[exception];
1260
1261 if (curr_handler != handler)
1262 return -EBUSY;
1263
1264 ex_table[exception] = ex_replaceable;
1265
1266 return 0;
1267}
1268EXPORT_SYMBOL(bfin_free_exception);
1269
1394f032
BW
1270void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1271{
1272 switch (cplb_panic) {
1273 case CPLB_NO_UNLOCKED:
1274 printk(KERN_EMERG "All CPLBs are locked\n");
1275 break;
1276 case CPLB_PROT_VIOL:
1277 return;
1278 case CPLB_NO_ADDR_MATCH:
1279 return;
1280 case CPLB_UNKNOWN_ERR:
1281 printk(KERN_EMERG "Unknown CPLB Exception\n");
1282 break;
1283 }
1284
226eb1ef
RG
1285 oops_in_progress = 1;
1286
49dce912 1287 dump_bfin_process(fp);
b03b08ba 1288 dump_bfin_mem(fp);
49dce912 1289 show_regs(fp);
1394f032 1290 dump_stack();
d8804adf 1291 panic("Unrecoverable event");
1394f032 1292}