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