Merge branch 'fix/misc' into for-linus
[pandora-kernel.git] / 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 #ifndef CONFIG_KGDB
271         /* IPEND is skipped if KGDB isn't enabled (see entry code) */
272         fp->ipend = bfin_read_IPEND();
273 #endif
274
275         /* trap_c() will be called for exceptions. During exceptions
276          * processing, the pc value should be set with retx value.
277          * With this change we can cleanup some code in signal.c- TODO
278          */
279         fp->orig_pc = fp->retx;
280         /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
281                 trapnr, fp->ipend, fp->pc, fp->retx); */
282
283         /* send the appropriate signal to the user program */
284         switch (trapnr) {
285
286         /* This table works in conjuction with the one in ./mach-common/entry.S
287          * Some exceptions are handled there (in assembly, in exception space)
288          * Some are handled here, (in C, in interrupt space)
289          * Some, like CPLB, are handled in both, where the normal path is
290          * handled in assembly/exception space, and the error path is handled
291          * here
292          */
293
294         /* 0x00 - Linux Syscall, getting here is an error */
295         /* 0x01 - userspace gdb breakpoint, handled here */
296         case VEC_EXCPT01:
297                 info.si_code = TRAP_ILLTRAP;
298                 sig = SIGTRAP;
299                 CHK_DEBUGGER_TRAP_MAYBE();
300                 /* Check if this is a breakpoint in kernel space */
301                 if (kernel_mode_regs(fp))
302                         goto traps_done;
303                 else
304                         break;
305         /* 0x03 - User Defined, userspace stack overflow */
306         case VEC_EXCPT03:
307                 info.si_code = SEGV_STACKFLOW;
308                 sig = SIGSEGV;
309                 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
310                 CHK_DEBUGGER_TRAP_MAYBE();
311                 break;
312         /* 0x02 - KGDB initial connection and break signal trap */
313         case VEC_EXCPT02:
314 #ifdef CONFIG_KGDB
315                 info.si_code = TRAP_ILLTRAP;
316                 sig = SIGTRAP;
317                 CHK_DEBUGGER_TRAP();
318                 goto traps_done;
319 #endif
320         /* 0x04 - User Defined */
321         /* 0x05 - User Defined */
322         /* 0x06 - User Defined */
323         /* 0x07 - User Defined */
324         /* 0x08 - User Defined */
325         /* 0x09 - User Defined */
326         /* 0x0A - User Defined */
327         /* 0x0B - User Defined */
328         /* 0x0C - User Defined */
329         /* 0x0D - User Defined */
330         /* 0x0E - User Defined */
331         /* 0x0F - User Defined */
332         /* If we got here, it is most likely that someone was trying to use a
333          * custom exception handler, and it is not actually installed properly
334          */
335         case VEC_EXCPT04 ... VEC_EXCPT15:
336                 info.si_code = ILL_ILLPARAOP;
337                 sig = SIGILL;
338                 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
339                 CHK_DEBUGGER_TRAP_MAYBE();
340                 break;
341         /* 0x10 HW Single step, handled here */
342         case VEC_STEP:
343                 info.si_code = TRAP_STEP;
344                 sig = SIGTRAP;
345                 CHK_DEBUGGER_TRAP_MAYBE();
346                 /* Check if this is a single step in kernel space */
347                 if (kernel_mode_regs(fp))
348                         goto traps_done;
349                 else
350                         break;
351         /* 0x11 - Trace Buffer Full, handled here */
352         case VEC_OVFLOW:
353                 info.si_code = TRAP_TRACEFLOW;
354                 sig = SIGTRAP;
355                 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
356                 CHK_DEBUGGER_TRAP_MAYBE();
357                 break;
358         /* 0x12 - Reserved, Caught by default */
359         /* 0x13 - Reserved, Caught by default */
360         /* 0x14 - Reserved, Caught by default */
361         /* 0x15 - Reserved, Caught by default */
362         /* 0x16 - Reserved, Caught by default */
363         /* 0x17 - Reserved, Caught by default */
364         /* 0x18 - Reserved, Caught by default */
365         /* 0x19 - Reserved, Caught by default */
366         /* 0x1A - Reserved, Caught by default */
367         /* 0x1B - Reserved, Caught by default */
368         /* 0x1C - Reserved, Caught by default */
369         /* 0x1D - Reserved, Caught by default */
370         /* 0x1E - Reserved, Caught by default */
371         /* 0x1F - Reserved, Caught by default */
372         /* 0x20 - Reserved, Caught by default */
373         /* 0x21 - Undefined Instruction, handled here */
374         case VEC_UNDEF_I:
375 #ifdef CONFIG_BUG
376                 if (kernel_mode_regs(fp)) {
377                         switch (report_bug(fp->pc, fp)) {
378                         case BUG_TRAP_TYPE_NONE:
379                                 break;
380                         case BUG_TRAP_TYPE_WARN:
381                                 dump_bfin_trace_buffer();
382                                 fp->pc += 2;
383                                 goto traps_done;
384                         case BUG_TRAP_TYPE_BUG:
385                                 /* call to panic() will dump trace, and it is
386                                  * off at this point, so it won't be clobbered
387                                  */
388                                 panic("BUG()");
389                         }
390                 }
391 #endif
392                 info.si_code = ILL_ILLOPC;
393                 sig = SIGILL;
394                 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
395                 CHK_DEBUGGER_TRAP_MAYBE();
396                 break;
397         /* 0x22 - Illegal Instruction Combination, handled here */
398         case VEC_ILGAL_I:
399                 info.si_code = ILL_ILLPARAOP;
400                 sig = SIGILL;
401                 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
402                 CHK_DEBUGGER_TRAP_MAYBE();
403                 break;
404         /* 0x23 - Data CPLB protection violation, handled here */
405         case VEC_CPLB_VL:
406                 info.si_code = ILL_CPLB_VI;
407                 sig = SIGBUS;
408                 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
409                 CHK_DEBUGGER_TRAP_MAYBE();
410                 break;
411         /* 0x24 - Data access misaligned, handled here */
412         case VEC_MISALI_D:
413                 info.si_code = BUS_ADRALN;
414                 sig = SIGBUS;
415                 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
416                 CHK_DEBUGGER_TRAP_MAYBE();
417                 break;
418         /* 0x25 - Unrecoverable Event, handled here */
419         case VEC_UNCOV:
420                 info.si_code = ILL_ILLEXCPT;
421                 sig = SIGILL;
422                 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
423                 CHK_DEBUGGER_TRAP_MAYBE();
424                 break;
425         /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
426                 error case is handled here */
427         case VEC_CPLB_M:
428                 info.si_code = BUS_ADRALN;
429                 sig = SIGBUS;
430                 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
431                 break;
432         /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
433         case VEC_CPLB_MHIT:
434                 info.si_code = ILL_CPLB_MULHIT;
435                 sig = SIGSEGV;
436 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
437                 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
438                         strerror = KERN_NOTICE "NULL pointer access\n";
439                 else
440 #endif
441                         strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
442                 CHK_DEBUGGER_TRAP_MAYBE();
443                 break;
444         /* 0x28 - Emulation Watchpoint, handled here */
445         case VEC_WATCH:
446                 info.si_code = TRAP_WATCHPT;
447                 sig = SIGTRAP;
448                 pr_debug(EXC_0x28(KERN_DEBUG));
449                 CHK_DEBUGGER_TRAP_MAYBE();
450                 /* Check if this is a watchpoint in kernel space */
451                 if (kernel_mode_regs(fp))
452                         goto traps_done;
453                 else
454                         break;
455 #ifdef CONFIG_BF535
456         /* 0x29 - Instruction fetch access error (535 only) */
457         case VEC_ISTRU_VL:      /* ADSP-BF535 only (MH) */
458                 info.si_code = BUS_OPFETCH;
459                 sig = SIGBUS;
460                 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
461                 CHK_DEBUGGER_TRAP_MAYBE();
462                 break;
463 #else
464         /* 0x29 - Reserved, Caught by default */
465 #endif
466         /* 0x2A - Instruction fetch misaligned, handled here */
467         case VEC_MISALI_I:
468                 info.si_code = BUS_ADRALN;
469                 sig = SIGBUS;
470                 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
471                 CHK_DEBUGGER_TRAP_MAYBE();
472                 break;
473         /* 0x2B - Instruction CPLB protection violation, handled here */
474         case VEC_CPLB_I_VL:
475                 info.si_code = ILL_CPLB_VI;
476                 sig = SIGBUS;
477                 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
478                 CHK_DEBUGGER_TRAP_MAYBE();
479                 break;
480         /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
481         case VEC_CPLB_I_M:
482                 info.si_code = ILL_CPLB_MISS;
483                 sig = SIGBUS;
484                 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
485                 break;
486         /* 0x2D - Instruction CPLB Multiple Hits, handled here */
487         case VEC_CPLB_I_MHIT:
488                 info.si_code = ILL_CPLB_MULHIT;
489                 sig = SIGSEGV;
490 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
491                 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
492                         strerror = KERN_NOTICE "Jump to NULL address\n";
493                 else
494 #endif
495                         strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
496                 CHK_DEBUGGER_TRAP_MAYBE();
497                 break;
498         /* 0x2E - Illegal use of Supervisor Resource, handled here */
499         case VEC_ILL_RES:
500                 info.si_code = ILL_PRVOPC;
501                 sig = SIGILL;
502                 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
503                 CHK_DEBUGGER_TRAP_MAYBE();
504                 break;
505         /* 0x2F - Reserved, Caught by default */
506         /* 0x30 - Reserved, Caught by default */
507         /* 0x31 - Reserved, Caught by default */
508         /* 0x32 - Reserved, Caught by default */
509         /* 0x33 - Reserved, Caught by default */
510         /* 0x34 - Reserved, Caught by default */
511         /* 0x35 - Reserved, Caught by default */
512         /* 0x36 - Reserved, Caught by default */
513         /* 0x37 - Reserved, Caught by default */
514         /* 0x38 - Reserved, Caught by default */
515         /* 0x39 - Reserved, Caught by default */
516         /* 0x3A - Reserved, Caught by default */
517         /* 0x3B - Reserved, Caught by default */
518         /* 0x3C - Reserved, Caught by default */
519         /* 0x3D - Reserved, Caught by default */
520         /* 0x3E - Reserved, Caught by default */
521         /* 0x3F - Reserved, Caught by default */
522         case VEC_HWERR:
523                 info.si_code = BUS_ADRALN;
524                 sig = SIGBUS;
525                 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
526                 /* System MMR Error */
527                 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
528                         info.si_code = BUS_ADRALN;
529                         sig = SIGBUS;
530                         strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
531                         break;
532                 /* External Memory Addressing Error */
533                 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
534                         info.si_code = BUS_ADRERR;
535                         sig = SIGBUS;
536                         strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
537                         break;
538                 /* Performance Monitor Overflow */
539                 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
540                         strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
541                         break;
542                 /* RAISE 5 instruction */
543                 case (SEQSTAT_HWERRCAUSE_RAISE_5):
544                         printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
545                         break;
546                 default:        /* Reserved */
547                         printk(KERN_NOTICE HWC_default(KERN_NOTICE));
548                         break;
549                 }
550                 CHK_DEBUGGER_TRAP_MAYBE();
551                 break;
552         /*
553          * We should be handling all known exception types above,
554          * if we get here we hit a reserved one, so panic
555          */
556         default:
557                 info.si_code = ILL_ILLPARAOP;
558                 sig = SIGILL;
559                 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
560                         (fp->seqstat & SEQSTAT_EXCAUSE));
561                 CHK_DEBUGGER_TRAP_MAYBE();
562                 break;
563         }
564
565         BUG_ON(sig == 0);
566
567         /* If the fault was caused by a kernel thread, or interrupt handler
568          * we will kernel panic, so the system reboots.
569          */
570         if (kernel_mode_regs(fp) || (current && !current->mm)) {
571                 console_verbose();
572                 oops_in_progress = 1;
573                 if (strerror)
574                         verbose_printk(strerror);
575         }
576
577         if (sig != SIGTRAP) {
578                 dump_bfin_process(fp);
579                 dump_bfin_mem(fp);
580                 show_regs(fp);
581
582                 /* Print out the trace buffer if it makes sense */
583 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
584                 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
585                         verbose_printk(KERN_NOTICE "No trace since you do not have "
586                                "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
587                 else
588 #endif
589                         dump_bfin_trace_buffer();
590
591                 if (oops_in_progress) {
592                         /* Dump the current kernel stack */
593                         verbose_printk(KERN_NOTICE "Kernel Stack\n");
594                         show_stack(current, NULL);
595                         print_modules();
596 #ifndef CONFIG_ACCESS_CHECK
597                         verbose_printk(KERN_EMERG "Please turn on "
598                                "CONFIG_ACCESS_CHECK\n");
599 #endif
600                         panic("Kernel exception");
601                 } else {
602 #ifdef CONFIG_DEBUG_VERBOSE
603                         unsigned long *stack;
604                         /* Dump the user space stack */
605                         stack = (unsigned long *)rdusp();
606                         verbose_printk(KERN_NOTICE "Userspace Stack\n");
607                         show_stack(NULL, stack);
608 #endif
609                 }
610         }
611
612 #ifdef CONFIG_IPIPE
613         if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
614 #endif
615         {
616                 info.si_signo = sig;
617                 info.si_errno = 0;
618                 info.si_addr = (void __user *)fp->pc;
619                 force_sig_info(sig, &info, current);
620         }
621
622         if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
623                 fp->pc = SAFE_USER_INSTRUCTION;
624
625  traps_done:
626         trace_buffer_restore(j);
627 }
628
629 /* Typical exception handling routines  */
630
631 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
632
633 /*
634  * Similar to get_user, do some address checking, then dereference
635  * Return true on sucess, false on bad address
636  */
637 static bool get_instruction(unsigned short *val, unsigned short *address)
638 {
639         unsigned long addr = (unsigned long)address;
640
641         /* Check for odd addresses */
642         if (addr & 0x1)
643                 return false;
644
645         /* MMR region will never have instructions */
646         if (addr >= SYSMMR_BASE)
647                 return false;
648
649         switch (bfin_mem_access_type(addr, 2)) {
650                 case BFIN_MEM_ACCESS_CORE:
651                 case BFIN_MEM_ACCESS_CORE_ONLY:
652                         *val = *address;
653                         return true;
654                 case BFIN_MEM_ACCESS_DMA:
655                         dma_memcpy(val, address, 2);
656                         return true;
657                 case BFIN_MEM_ACCESS_ITEST:
658                         isram_memcpy(val, address, 2);
659                         return true;
660                 default: /* invalid access */
661                         return false;
662         }
663 }
664
665 /*
666  * decode the instruction if we are printing out the trace, as it
667  * makes things easier to follow, without running it through objdump
668  * These are the normal instructions which cause change of flow, which
669  * would be at the source of the trace buffer
670  */
671 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
672 static void decode_instruction(unsigned short *address)
673 {
674         unsigned short opcode;
675
676         if (get_instruction(&opcode, address)) {
677                 if (opcode == 0x0010)
678                         verbose_printk("RTS");
679                 else if (opcode == 0x0011)
680                         verbose_printk("RTI");
681                 else if (opcode == 0x0012)
682                         verbose_printk("RTX");
683                 else if (opcode == 0x0013)
684                         verbose_printk("RTN");
685                 else if (opcode == 0x0014)
686                         verbose_printk("RTE");
687                 else if (opcode == 0x0025)
688                         verbose_printk("EMUEXCPT");
689                 else if (opcode == 0x0040 && opcode <= 0x0047)
690                         verbose_printk("STI R%i", opcode & 7);
691                 else if (opcode >= 0x0050 && opcode <= 0x0057)
692                         verbose_printk("JUMP (P%i)", opcode & 7);
693                 else if (opcode >= 0x0060 && opcode <= 0x0067)
694                         verbose_printk("CALL (P%i)", opcode & 7);
695                 else if (opcode >= 0x0070 && opcode <= 0x0077)
696                         verbose_printk("CALL (PC+P%i)", opcode & 7);
697                 else if (opcode >= 0x0080 && opcode <= 0x0087)
698                         verbose_printk("JUMP (PC+P%i)", opcode & 7);
699                 else if (opcode >= 0x0090 && opcode <= 0x009F)
700                         verbose_printk("RAISE 0x%x", opcode & 0xF);
701                 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
702                         verbose_printk("EXCPT 0x%x", opcode & 0xF);
703                 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
704                         verbose_printk("IF !CC JUMP");
705                 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
706                         verbose_printk("IF CC JUMP");
707                 else if (opcode >= 0x2000 && opcode <= 0x2fff)
708                         verbose_printk("JUMP.S");
709                 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
710                         verbose_printk("LSETUP");
711                 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
712                         verbose_printk("JUMP.L");
713                 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
714                         verbose_printk("CALL pcrel");
715                 else
716                         verbose_printk("0x%04x", opcode);
717         }
718
719 }
720 #endif
721
722 void dump_bfin_trace_buffer(void)
723 {
724 #ifdef CONFIG_DEBUG_VERBOSE
725 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
726         int tflags, i = 0;
727         char buf[150];
728         unsigned short *addr;
729 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
730         int j, index;
731 #endif
732
733         trace_buffer_save(tflags);
734
735         printk(KERN_NOTICE "Hardware Trace:\n");
736
737 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
738         printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
739 #endif
740
741         if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
742                 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
743                         decode_address(buf, (unsigned long)bfin_read_TBUF());
744                         printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
745                         addr = (unsigned short *)bfin_read_TBUF();
746                         decode_address(buf, (unsigned long)addr);
747                         printk(KERN_NOTICE "     Source : %s ", buf);
748                         decode_instruction(addr);
749                         printk("\n");
750                 }
751         }
752
753 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
754         if (trace_buff_offset)
755                 index = trace_buff_offset / 4;
756         else
757                 index = EXPAND_LEN;
758
759         j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
760         while (j) {
761                 decode_address(buf, software_trace_buff[index]);
762                 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
763                 index -= 1;
764                 if (index < 0 )
765                         index = EXPAND_LEN;
766                 decode_address(buf, software_trace_buff[index]);
767                 printk(KERN_NOTICE "     Source : %s ", buf);
768                 decode_instruction((unsigned short *)software_trace_buff[index]);
769                 printk("\n");
770                 index -= 1;
771                 if (index < 0)
772                         index = EXPAND_LEN;
773                 j--;
774                 i++;
775         }
776 #endif
777
778         trace_buffer_restore(tflags);
779 #endif
780 #endif
781 }
782 EXPORT_SYMBOL(dump_bfin_trace_buffer);
783
784 #ifdef CONFIG_BUG
785 int is_valid_bugaddr(unsigned long addr)
786 {
787         unsigned short opcode;
788
789         if (!get_instruction(&opcode, (unsigned short *)addr))
790                 return 0;
791
792         return opcode == BFIN_BUG_OPCODE;
793 }
794 #endif
795
796 /*
797  * Checks to see if the address pointed to is either a
798  * 16-bit CALL instruction, or a 32-bit CALL instruction
799  */
800 static bool is_bfin_call(unsigned short *addr)
801 {
802         unsigned short opcode = 0, *ins_addr;
803         ins_addr = (unsigned short *)addr;
804
805         if (!get_instruction(&opcode, ins_addr))
806                 return false;
807
808         if ((opcode >= 0x0060 && opcode <= 0x0067) ||
809             (opcode >= 0x0070 && opcode <= 0x0077))
810                 return true;
811
812         ins_addr--;
813         if (!get_instruction(&opcode, ins_addr))
814                 return false;
815
816         if (opcode >= 0xE300 && opcode <= 0xE3FF)
817                 return true;
818
819         return false;
820
821 }
822
823 void show_stack(struct task_struct *task, unsigned long *stack)
824 {
825 #ifdef CONFIG_PRINTK
826         unsigned int *addr, *endstack, *fp = 0, *frame;
827         unsigned short *ins_addr;
828         char buf[150];
829         unsigned int i, j, ret_addr, frame_no = 0;
830
831         /*
832          * If we have been passed a specific stack, use that one otherwise
833          *    if we have been passed a task structure, use that, otherwise
834          *    use the stack of where the variable "stack" exists
835          */
836
837         if (stack == NULL) {
838                 if (task) {
839                         /* We know this is a kernel stack, so this is the start/end */
840                         stack = (unsigned long *)task->thread.ksp;
841                         endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
842                 } else {
843                         /* print out the existing stack info */
844                         stack = (unsigned long *)&stack;
845                         endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
846                 }
847         } else
848                 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
849
850         printk(KERN_NOTICE "Stack info:\n");
851         decode_address(buf, (unsigned int)stack);
852         printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
853
854         if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
855                 printk(KERN_NOTICE "Invalid stack pointer\n");
856                 return;
857         }
858
859         /* First thing is to look for a frame pointer */
860         for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
861                 if (*addr & 0x1)
862                         continue;
863                 ins_addr = (unsigned short *)*addr;
864                 ins_addr--;
865                 if (is_bfin_call(ins_addr))
866                         fp = addr - 1;
867
868                 if (fp) {
869                         /* Let's check to see if it is a frame pointer */
870                         while (fp >= (addr - 1) && fp < endstack
871                                && fp && ((unsigned int) fp & 0x3) == 0)
872                                 fp = (unsigned int *)*fp;
873                         if (fp == 0 || fp == endstack) {
874                                 fp = addr - 1;
875                                 break;
876                         }
877                         fp = 0;
878                 }
879         }
880         if (fp) {
881                 frame = fp;
882                 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
883         } else
884                 frame = 0;
885
886         /*
887          * Now that we think we know where things are, we
888          * walk the stack again, this time printing things out
889          * incase there is no frame pointer, we still look for
890          * valid return addresses
891          */
892
893         /* First time print out data, next time, print out symbols */
894         for (j = 0; j <= 1; j++) {
895                 if (j)
896                         printk(KERN_NOTICE "Return addresses in stack:\n");
897                 else
898                         printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
899
900                 fp = frame;
901                 frame_no = 0;
902
903                 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
904                      addr <= endstack; addr++, i++) {
905
906                         ret_addr = 0;
907                         if (!j && i % 8 == 0)
908                                 printk(KERN_NOTICE "%p:",addr);
909
910                         /* if it is an odd address, or zero, just skip it */
911                         if (*addr & 0x1 || !*addr)
912                                 goto print;
913
914                         ins_addr = (unsigned short *)*addr;
915
916                         /* Go back one instruction, and see if it is a CALL */
917                         ins_addr--;
918                         ret_addr = is_bfin_call(ins_addr);
919  print:
920                         if (!j && stack == (unsigned long *)addr)
921                                 printk("[%08x]", *addr);
922                         else if (ret_addr)
923                                 if (j) {
924                                         decode_address(buf, (unsigned int)*addr);
925                                         if (frame == addr) {
926                                                 printk(KERN_NOTICE "   frame %2i : %s\n", frame_no, buf);
927                                                 continue;
928                                         }
929                                         printk(KERN_NOTICE "    address : %s\n", buf);
930                                 } else
931                                         printk("<%08x>", *addr);
932                         else if (fp == addr) {
933                                 if (j)
934                                         frame = addr+1;
935                                 else
936                                         printk("(%08x)", *addr);
937
938                                 fp = (unsigned int *)*addr;
939                                 frame_no++;
940
941                         } else if (!j)
942                                 printk(" %08x ", *addr);
943                 }
944                 if (!j)
945                         printk("\n");
946         }
947 #endif
948 }
949
950 void dump_stack(void)
951 {
952         unsigned long stack;
953 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
954         int tflags;
955 #endif
956         trace_buffer_save(tflags);
957         dump_bfin_trace_buffer();
958         show_stack(current, &stack);
959         trace_buffer_restore(tflags);
960 }
961 EXPORT_SYMBOL(dump_stack);
962
963 void dump_bfin_process(struct pt_regs *fp)
964 {
965 #ifdef CONFIG_DEBUG_VERBOSE
966         /* We should be able to look at fp->ipend, but we don't push it on the
967          * stack all the time, so do this until we fix that */
968         unsigned int context = bfin_read_IPEND();
969
970         if (oops_in_progress)
971                 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
972
973         if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
974                 verbose_printk(KERN_NOTICE "HW Error context\n");
975         else if (context & 0x0020)
976                 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
977         else if (context & 0x3FC0)
978                 verbose_printk(KERN_NOTICE "Interrupt context\n");
979         else if (context & 0x4000)
980                 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
981         else if (context & 0x8000)
982                 verbose_printk(KERN_NOTICE "Kernel process context\n");
983
984         /* Because we are crashing, and pointers could be bad, we check things
985          * pretty closely before we use them
986          */
987         if ((unsigned long)current >= FIXED_CODE_START &&
988             !((unsigned long)current & 0x3) && current->pid) {
989                 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
990                 if (current->comm >= (char *)FIXED_CODE_START)
991                         verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
992                                 current->comm, current->pid);
993                 else
994                         verbose_printk(KERN_NOTICE "COMM= invalid\n");
995
996                 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
997                 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
998                         verbose_printk(KERN_NOTICE
999                                 "TEXT = 0x%p-0x%p        DATA = 0x%p-0x%p\n"
1000                                 " BSS = 0x%p-0x%p  USER-STACK = 0x%p\n\n",
1001                                 (void *)current->mm->start_code,
1002                                 (void *)current->mm->end_code,
1003                                 (void *)current->mm->start_data,
1004                                 (void *)current->mm->end_data,
1005                                 (void *)current->mm->end_data,
1006                                 (void *)current->mm->brk,
1007                                 (void *)current->mm->start_stack);
1008                 else
1009                         verbose_printk(KERN_NOTICE "invalid mm\n");
1010         } else
1011                 verbose_printk(KERN_NOTICE
1012                                "No Valid process in current context\n");
1013 #endif
1014 }
1015
1016 void dump_bfin_mem(struct pt_regs *fp)
1017 {
1018 #ifdef CONFIG_DEBUG_VERBOSE
1019         unsigned short *addr, *erraddr, val = 0, err = 0;
1020         char sti = 0, buf[6];
1021
1022         erraddr = (void *)fp->pc;
1023
1024         verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
1025
1026         for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1027              addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1028              addr++) {
1029                 if (!((unsigned long)addr & 0xF))
1030                         verbose_printk(KERN_NOTICE "0x%p: ", addr);
1031
1032                 if (!get_instruction(&val, addr)) {
1033                                 val = 0;
1034                                 sprintf(buf, "????");
1035                 } else
1036                         sprintf(buf, "%04x", val);
1037
1038                 if (addr == erraddr) {
1039                         verbose_printk("[%s]", buf);
1040                         err = val;
1041                 } else
1042                         verbose_printk(" %s ", buf);
1043
1044                 /* Do any previous instructions turn on interrupts? */
1045                 if (addr <= erraddr &&                          /* in the past */
1046                     ((val >= 0x0040 && val <= 0x0047) ||        /* STI instruction */
1047                       val == 0x017b))                           /* [SP++] = RETI */
1048                         sti = 1;
1049         }
1050
1051         verbose_printk("\n");
1052
1053         /* Hardware error interrupts can be deferred */
1054         if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1055             oops_in_progress)){
1056                 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
1057 #ifndef CONFIG_DEBUG_HWERR
1058                 verbose_printk(KERN_NOTICE
1059 "The remaining message may be meaningless\n"
1060 "You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
1061 #else
1062                 /* If we are handling only one peripheral interrupt
1063                  * and current mm and pid are valid, and the last error
1064                  * was in that user space process's text area
1065                  * print it out - because that is where the problem exists
1066                  */
1067                 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1068                      (current->pid && current->mm)) {
1069                         /* And the last RETI points to the current userspace context */
1070                         if ((fp + 1)->pc >= current->mm->start_code &&
1071                             (fp + 1)->pc <= current->mm->end_code) {
1072                                 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1073                                 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1074                                 show_regs(fp + 1);
1075                                 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
1076                         }
1077                 }
1078 #endif
1079         }
1080 #endif
1081 }
1082
1083 void show_regs(struct pt_regs *fp)
1084 {
1085 #ifdef CONFIG_DEBUG_VERBOSE
1086         char buf [150];
1087         struct irqaction *action;
1088         unsigned int i;
1089         unsigned long flags = 0;
1090         unsigned int cpu = smp_processor_id();
1091         unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
1092
1093         verbose_printk(KERN_NOTICE "\n");
1094         if (CPUID != bfin_cpuid())
1095                 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1096                         "but running on:0x%04x (Rev %d)\n",
1097                         CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1098
1099         verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1100                 CPU, bfin_compiled_revid());
1101
1102         if (bfin_compiled_revid() !=  bfin_revid())
1103                 verbose_printk("(Detected 0.%d)", bfin_revid());
1104
1105         verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1106                 get_cclk()/1000000, get_sclk()/1000000,
1107 #ifdef CONFIG_MPU
1108                 "mpu on"
1109 #else
1110                 "mpu off"
1111 #endif
1112                 );
1113
1114         verbose_printk(KERN_NOTICE "%s", linux_banner);
1115
1116         verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n",
1117                        print_tainted());
1118         verbose_printk(KERN_NOTICE " SEQSTAT: %08lx  IPEND: %04lx  SYSCFG: %04lx\n",
1119                        (long)fp->seqstat, fp->ipend, fp->syscfg);
1120         if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
1121                 verbose_printk(KERN_NOTICE "  HWERRCAUSE: 0x%lx\n",
1122                         (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1123 #ifdef EBIU_ERRMST
1124                 /* If the error was from the EBIU, print it out */
1125                 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
1126                         verbose_printk(KERN_NOTICE "  EBIU Error Reason  : 0x%04x\n",
1127                                 bfin_read_EBIU_ERRMST());
1128                         verbose_printk(KERN_NOTICE "  EBIU Error Address : 0x%08x\n",
1129                                 bfin_read_EBIU_ERRADD());
1130                 }
1131 #endif
1132         }
1133         verbose_printk(KERN_NOTICE "  EXCAUSE   : 0x%lx\n",
1134                 fp->seqstat & SEQSTAT_EXCAUSE);
1135         for (i = 2; i <= 15 ; i++) {
1136                 if (fp->ipend & (1 << i)) {
1137                         if (i != 4) {
1138                                 decode_address(buf, bfin_read32(EVT0 + 4*i));
1139                                 verbose_printk(KERN_NOTICE "  physical IVG%i asserted : %s\n", i, buf);
1140                         } else
1141                                 verbose_printk(KERN_NOTICE "  interrupts disabled\n");
1142                 }
1143         }
1144
1145         /* if no interrupts are going off, don't print this out */
1146         if (fp->ipend & ~0x3F) {
1147                 for (i = 0; i < (NR_IRQS - 1); i++) {
1148                         if (!in_atomic)
1149                                 spin_lock_irqsave(&irq_desc[i].lock, flags);
1150
1151                         action = irq_desc[i].action;
1152                         if (!action)
1153                                 goto unlock;
1154
1155                         decode_address(buf, (unsigned int)action->handler);
1156                         verbose_printk(KERN_NOTICE "  logical irq %3d mapped  : %s", i, buf);
1157                         for (action = action->next; action; action = action->next) {
1158                                 decode_address(buf, (unsigned int)action->handler);
1159                                 verbose_printk(", %s", buf);
1160                         }
1161                         verbose_printk("\n");
1162 unlock:
1163                         if (!in_atomic)
1164                                 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1165                 }
1166         }
1167
1168         decode_address(buf, fp->rete);
1169         verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
1170         decode_address(buf, fp->retn);
1171         verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
1172         decode_address(buf, fp->retx);
1173         verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
1174         decode_address(buf, fp->rets);
1175         verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
1176         decode_address(buf, fp->pc);
1177         verbose_printk(KERN_NOTICE " PC  : %s\n", buf);
1178
1179         if (((long)fp->seqstat &  SEQSTAT_EXCAUSE) &&
1180             (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1181                 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
1182                 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1183                 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
1184                 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1185         }
1186
1187         verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
1188         verbose_printk(KERN_NOTICE " R0 : %08lx    R1 : %08lx    R2 : %08lx    R3 : %08lx\n",
1189                 fp->r0, fp->r1, fp->r2, fp->r3);
1190         verbose_printk(KERN_NOTICE " R4 : %08lx    R5 : %08lx    R6 : %08lx    R7 : %08lx\n",
1191                 fp->r4, fp->r5, fp->r6, fp->r7);
1192         verbose_printk(KERN_NOTICE " P0 : %08lx    P1 : %08lx    P2 : %08lx    P3 : %08lx\n",
1193                 fp->p0, fp->p1, fp->p2, fp->p3);
1194         verbose_printk(KERN_NOTICE " P4 : %08lx    P5 : %08lx    FP : %08lx    SP : %08lx\n",
1195                 fp->p4, fp->p5, fp->fp, (long)fp);
1196         verbose_printk(KERN_NOTICE " LB0: %08lx    LT0: %08lx    LC0: %08lx\n",
1197                 fp->lb0, fp->lt0, fp->lc0);
1198         verbose_printk(KERN_NOTICE " LB1: %08lx    LT1: %08lx    LC1: %08lx\n",
1199                 fp->lb1, fp->lt1, fp->lc1);
1200         verbose_printk(KERN_NOTICE " B0 : %08lx    L0 : %08lx    M0 : %08lx    I0 : %08lx\n",
1201                 fp->b0, fp->l0, fp->m0, fp->i0);
1202         verbose_printk(KERN_NOTICE " B1 : %08lx    L1 : %08lx    M1 : %08lx    I1 : %08lx\n",
1203                 fp->b1, fp->l1, fp->m1, fp->i1);
1204         verbose_printk(KERN_NOTICE " B2 : %08lx    L2 : %08lx    M2 : %08lx    I2 : %08lx\n",
1205                 fp->b2, fp->l2, fp->m2, fp->i2);
1206         verbose_printk(KERN_NOTICE " B3 : %08lx    L3 : %08lx    M3 : %08lx    I3 : %08lx\n",
1207                 fp->b3, fp->l3, fp->m3, fp->i3);
1208         verbose_printk(KERN_NOTICE "A0.w: %08lx   A0.x: %08lx   A1.w: %08lx   A1.x: %08lx\n",
1209                 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1210
1211         verbose_printk(KERN_NOTICE "USP : %08lx  ASTAT: %08lx\n",
1212                 rdusp(), fp->astat);
1213
1214         verbose_printk(KERN_NOTICE "\n");
1215 #endif
1216 }
1217
1218 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1219 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1220 #endif
1221
1222 static DEFINE_SPINLOCK(bfin_spinlock_lock);
1223
1224 asmlinkage int sys_bfin_spinlock(int *p)
1225 {
1226         int ret, tmp = 0;
1227
1228         spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1229         ret = get_user(tmp, p);
1230         if (likely(ret == 0)) {
1231                 if (unlikely(tmp))
1232                         ret = 1;
1233                 else
1234                         put_user(1, p);
1235         }
1236         spin_unlock(&bfin_spinlock_lock);
1237         return ret;
1238 }
1239
1240 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1241 {
1242         void (*curr_handler)(void);
1243
1244         if (exception > 0x3F)
1245                 return -EINVAL;
1246
1247         curr_handler = ex_table[exception];
1248
1249         if (curr_handler != ex_replaceable)
1250                 return -EBUSY;
1251
1252         ex_table[exception] = handler;
1253
1254         return 0;
1255 }
1256 EXPORT_SYMBOL(bfin_request_exception);
1257
1258 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1259 {
1260         void (*curr_handler)(void);
1261
1262         if (exception > 0x3F)
1263                 return -EINVAL;
1264
1265         curr_handler = ex_table[exception];
1266
1267         if (curr_handler != handler)
1268                 return -EBUSY;
1269
1270         ex_table[exception] = ex_replaceable;
1271
1272         return 0;
1273 }
1274 EXPORT_SYMBOL(bfin_free_exception);
1275
1276 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1277 {
1278         switch (cplb_panic) {
1279         case CPLB_NO_UNLOCKED:
1280                 printk(KERN_EMERG "All CPLBs are locked\n");
1281                 break;
1282         case CPLB_PROT_VIOL:
1283                 return;
1284         case CPLB_NO_ADDR_MATCH:
1285                 return;
1286         case CPLB_UNKNOWN_ERR:
1287                 printk(KERN_EMERG "Unknown CPLB Exception\n");
1288                 break;
1289         }
1290
1291         oops_in_progress = 1;
1292
1293         dump_bfin_process(fp);
1294         dump_bfin_mem(fp);
1295         show_regs(fp);
1296         dump_stack();
1297         panic("Unrecoverable event");
1298 }