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