Blackfin: export the last exception cause via debugfs
[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/uaccess.h>
31 #include <linux/interrupt.h>
32 #include <linux/module.h>
33 #include <linux/kallsyms.h>
34 #include <linux/fs.h>
35 #include <linux/rbtree.h>
36 #include <asm/traps.h>
37 #include <asm/cacheflush.h>
38 #include <asm/cplb.h>
39 #include <asm/blackfin.h>
40 #include <asm/irq_handler.h>
41 #include <linux/irq.h>
42 #include <asm/trace.h>
43 #include <asm/fixed_code.h>
44
45 #ifdef CONFIG_KGDB
46 # include <linux/kgdb.h>
47
48 # define CHK_DEBUGGER_TRAP() \
49         do { \
50                 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
51         } while (0)
52 # define CHK_DEBUGGER_TRAP_MAYBE() \
53         do { \
54                 if (kgdb_connected) \
55                         CHK_DEBUGGER_TRAP(); \
56         } while (0)
57 #else
58 # define CHK_DEBUGGER_TRAP() do { } while (0)
59 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
60 #endif
61
62
63 #ifdef CONFIG_DEBUG_VERBOSE
64 #define verbose_printk(fmt, arg...) \
65         printk(fmt, ##arg)
66 #else
67 #define verbose_printk(fmt, arg...) \
68         ({ if (0) printk(fmt, ##arg); 0; })
69 #endif
70
71 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
72 u32 last_seqstat;
73 #ifdef CONFIG_DEBUG_MMRS_MODULE
74 EXPORT_SYMBOL(last_seqstat);
75 #endif
76 #endif
77
78 /* Initiate the event table handler */
79 void __init trap_init(void)
80 {
81         CSYNC();
82         bfin_write_EVT3(trap);
83         CSYNC();
84 }
85
86 static void decode_address(char *buf, unsigned long address)
87 {
88 #ifdef CONFIG_DEBUG_VERBOSE
89         struct vm_list_struct *vml;
90         struct task_struct *p;
91         struct mm_struct *mm;
92         unsigned long flags, offset;
93         unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
94         struct rb_node *n;
95
96 #ifdef CONFIG_KALLSYMS
97         unsigned long symsize;
98         const char *symname;
99         char *modname;
100         char *delim = ":";
101         char namebuf[128];
102
103         /* look up the address and see if we are in kernel space */
104         symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
105
106         if (symname) {
107                 /* yeah! kernel space! */
108                 if (!modname)
109                         modname = delim = "";
110                 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
111                               (void *)address, delim, modname, delim, symname,
112                               (unsigned long)offset);
113                 return;
114
115         }
116 #endif
117
118         /* Problem in fixed code section? */
119         if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
120                 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
121                 return;
122         }
123
124         /* Problem somewhere before the kernel start address */
125         if (address < CONFIG_BOOT_LOAD) {
126                 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
127                 return;
128         }
129
130         /* looks like we're off in user-land, so let's walk all the
131          * mappings of all our processes and see if we can't be a whee
132          * bit more specific
133          */
134         write_lock_irqsave(&tasklist_lock, flags);
135         for_each_process(p) {
136                 mm = (in_atomic ? p->mm : get_task_mm(p));
137                 if (!mm)
138                         continue;
139
140                 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
141                         struct vm_area_struct *vma;
142
143                         vma = rb_entry(n, struct vm_area_struct, vm_rb);
144
145                         if (address >= vma->vm_start && address < vma->vm_end) {
146                                 char _tmpbuf[256];
147                                 char *name = p->comm;
148                                 struct file *file = vma->vm_file;
149
150                                 if (file) {
151                                         char *d_name = d_path(&file->f_path, _tmpbuf,
152                                                       sizeof(_tmpbuf));
153                                         if (!IS_ERR(d_name))
154                                                 name = d_name;
155                                 }
156
157                                 /* FLAT does not have its text aligned to the start of
158                                  * the map while FDPIC ELF does ...
159                                  */
160
161                                 /* before we can check flat/fdpic, we need to
162                                  * make sure current is valid
163                                  */
164                                 if ((unsigned long)current >= FIXED_CODE_START &&
165                                     !((unsigned long)current & 0x3)) {
166                                         if (current->mm &&
167                                             (address > current->mm->start_code) &&
168                                             (address < current->mm->end_code))
169                                                 offset = address - current->mm->start_code;
170                                         else
171                                                 offset = (address - vma->vm_start) +
172                                                          (vma->vm_pgoff << PAGE_SHIFT);
173
174                                         sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
175                                                 (void *)address, name, offset);
176                                 } else
177                                         sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
178                                                 (void *)address, name,
179                                                 vma->vm_start, vma->vm_end);
180
181                                 if (!in_atomic)
182                                         mmput(mm);
183
184                                 if (!strlen(buf))
185                                         sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
186
187                                 goto done;
188                         }
189                 }
190                 if (!in_atomic)
191                         mmput(mm);
192         }
193
194         /* we were unable to find this address anywhere */
195         sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
196
197 done:
198         write_unlock_irqrestore(&tasklist_lock, flags);
199 #else
200         sprintf(buf, " ");
201 #endif
202 }
203
204 asmlinkage void double_fault_c(struct pt_regs *fp)
205 {
206 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
207         int j;
208         trace_buffer_save(j);
209 #endif
210
211         console_verbose();
212         oops_in_progress = 1;
213 #ifdef CONFIG_DEBUG_VERBOSE
214         printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
215 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
216         if (((long)fp->seqstat &  SEQSTAT_EXCAUSE) == VEC_UNCOV) {
217                 unsigned int cpu = smp_processor_id();
218                 char buf[150];
219                 decode_address(buf, cpu_pda[cpu].retx);
220                 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
221                         (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
222                 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
223                 printk(KERN_NOTICE "   DCPLB_FAULT_ADDR: %s\n", buf);
224                 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
225                 printk(KERN_NOTICE "   ICPLB_FAULT_ADDR: %s\n", buf);
226
227                 decode_address(buf, fp->retx);
228                 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
229         } else
230 #endif
231         {
232                 dump_bfin_process(fp);
233                 dump_bfin_mem(fp);
234                 show_regs(fp);
235                 dump_bfin_trace_buffer();
236         }
237 #endif
238         panic("Double Fault - unrecoverable event");
239
240 }
241
242 asmlinkage void trap_c(struct pt_regs *fp)
243 {
244 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
245         int j;
246 #endif
247 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
248         unsigned int cpu = smp_processor_id();
249 #endif
250         int sig = 0;
251         siginfo_t info;
252         unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
253
254         trace_buffer_save(j);
255 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
256         last_seqstat = (u32)fp->seqstat;
257 #endif
258
259         /* Important - be very careful dereferncing pointers - will lead to
260          * double faults if the stack has become corrupt
261          */
262
263         /* If the fault was caused by a kernel thread, or interrupt handler
264          * we will kernel panic, so the system reboots.
265          * If KGDB is enabled, don't set this for kernel breakpoints
266         */
267
268         /* TODO: check to see if we are in some sort of deferred HWERR
269          * that we should be able to recover from, not kernel panic
270          */
271         if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
272 #ifdef CONFIG_KGDB
273                 && (trapnr != VEC_EXCPT02)
274 #endif
275         ){
276                 console_verbose();
277                 oops_in_progress = 1;
278         } else if (current) {
279                 if (current->mm == NULL) {
280                         console_verbose();
281                         oops_in_progress = 1;
282                 }
283         }
284
285         /* trap_c() will be called for exceptions. During exceptions
286          * processing, the pc value should be set with retx value.
287          * With this change we can cleanup some code in signal.c- TODO
288          */
289         fp->orig_pc = fp->retx;
290         /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
291                 trapnr, fp->ipend, fp->pc, fp->retx); */
292
293         /* send the appropriate signal to the user program */
294         switch (trapnr) {
295
296         /* This table works in conjuction with the one in ./mach-common/entry.S
297          * Some exceptions are handled there (in assembly, in exception space)
298          * Some are handled here, (in C, in interrupt space)
299          * Some, like CPLB, are handled in both, where the normal path is
300          * handled in assembly/exception space, and the error path is handled
301          * here
302          */
303
304         /* 0x00 - Linux Syscall, getting here is an error */
305         /* 0x01 - userspace gdb breakpoint, handled here */
306         case VEC_EXCPT01:
307                 info.si_code = TRAP_ILLTRAP;
308                 sig = SIGTRAP;
309                 CHK_DEBUGGER_TRAP_MAYBE();
310                 /* Check if this is a breakpoint in kernel space */
311                 if (fp->ipend & 0xffc0)
312                         return;
313                 else
314                         break;
315         /* 0x03 - User Defined, userspace stack overflow */
316         case VEC_EXCPT03:
317                 info.si_code = SEGV_STACKFLOW;
318                 sig = SIGSEGV;
319                 verbose_printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
320                 CHK_DEBUGGER_TRAP_MAYBE();
321                 break;
322         /* 0x02 - KGDB initial connection and break signal trap */
323         case VEC_EXCPT02:
324 #ifdef CONFIG_KGDB
325                 info.si_code = TRAP_ILLTRAP;
326                 sig = SIGTRAP;
327                 CHK_DEBUGGER_TRAP();
328                 return;
329 #endif
330         /* 0x04 - User Defined */
331         /* 0x05 - User Defined */
332         /* 0x06 - User Defined */
333         /* 0x07 - User Defined */
334         /* 0x08 - User Defined */
335         /* 0x09 - User Defined */
336         /* 0x0A - User Defined */
337         /* 0x0B - User Defined */
338         /* 0x0C - User Defined */
339         /* 0x0D - User Defined */
340         /* 0x0E - User Defined */
341         /* 0x0F - User Defined */
342         /* If we got here, it is most likely that someone was trying to use a
343          * custom exception handler, and it is not actually installed properly
344          */
345         case VEC_EXCPT04 ... VEC_EXCPT15:
346                 info.si_code = ILL_ILLPARAOP;
347                 sig = SIGILL;
348                 verbose_printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
349                 CHK_DEBUGGER_TRAP_MAYBE();
350                 break;
351         /* 0x10 HW Single step, handled here */
352         case VEC_STEP:
353                 info.si_code = TRAP_STEP;
354                 sig = SIGTRAP;
355                 CHK_DEBUGGER_TRAP_MAYBE();
356                 /* Check if this is a single step in kernel space */
357                 if (fp->ipend & 0xffc0)
358                         return;
359                 else
360                         break;
361         /* 0x11 - Trace Buffer Full, handled here */
362         case VEC_OVFLOW:
363                 info.si_code = TRAP_TRACEFLOW;
364                 sig = SIGTRAP;
365                 verbose_printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
366                 CHK_DEBUGGER_TRAP_MAYBE();
367                 break;
368         /* 0x12 - Reserved, Caught by default */
369         /* 0x13 - Reserved, Caught by default */
370         /* 0x14 - Reserved, Caught by default */
371         /* 0x15 - Reserved, Caught by default */
372         /* 0x16 - Reserved, Caught by default */
373         /* 0x17 - Reserved, Caught by default */
374         /* 0x18 - Reserved, Caught by default */
375         /* 0x19 - Reserved, Caught by default */
376         /* 0x1A - Reserved, Caught by default */
377         /* 0x1B - Reserved, Caught by default */
378         /* 0x1C - Reserved, Caught by default */
379         /* 0x1D - Reserved, Caught by default */
380         /* 0x1E - Reserved, Caught by default */
381         /* 0x1F - Reserved, Caught by default */
382         /* 0x20 - Reserved, Caught by default */
383         /* 0x21 - Undefined Instruction, handled here */
384         case VEC_UNDEF_I:
385                 info.si_code = ILL_ILLOPC;
386                 sig = SIGILL;
387                 verbose_printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
388                 CHK_DEBUGGER_TRAP_MAYBE();
389                 break;
390         /* 0x22 - Illegal Instruction Combination, handled here */
391         case VEC_ILGAL_I:
392                 info.si_code = ILL_ILLPARAOP;
393                 sig = SIGILL;
394                 verbose_printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
395                 CHK_DEBUGGER_TRAP_MAYBE();
396                 break;
397         /* 0x23 - Data CPLB protection violation, handled here */
398         case VEC_CPLB_VL:
399                 info.si_code = ILL_CPLB_VI;
400                 sig = SIGBUS;
401                 verbose_printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
402                 CHK_DEBUGGER_TRAP_MAYBE();
403                 break;
404         /* 0x24 - Data access misaligned, handled here */
405         case VEC_MISALI_D:
406                 info.si_code = BUS_ADRALN;
407                 sig = SIGBUS;
408                 verbose_printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
409                 CHK_DEBUGGER_TRAP_MAYBE();
410                 break;
411         /* 0x25 - Unrecoverable Event, handled here */
412         case VEC_UNCOV:
413                 info.si_code = ILL_ILLEXCPT;
414                 sig = SIGILL;
415                 verbose_printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
416                 CHK_DEBUGGER_TRAP_MAYBE();
417                 break;
418         /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
419                 error case is handled here */
420         case VEC_CPLB_M:
421                 info.si_code = BUS_ADRALN;
422                 sig = SIGBUS;
423                 verbose_printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
424                 break;
425         /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
426         case VEC_CPLB_MHIT:
427                 info.si_code = ILL_CPLB_MULHIT;
428                 sig = SIGSEGV;
429 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
430                 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
431                         verbose_printk(KERN_NOTICE "NULL pointer access\n");
432                 else
433 #endif
434                         verbose_printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
435                 CHK_DEBUGGER_TRAP_MAYBE();
436                 break;
437         /* 0x28 - Emulation Watchpoint, handled here */
438         case VEC_WATCH:
439                 info.si_code = TRAP_WATCHPT;
440                 sig = SIGTRAP;
441                 pr_debug(EXC_0x28(KERN_DEBUG));
442                 CHK_DEBUGGER_TRAP_MAYBE();
443                 /* Check if this is a watchpoint in kernel space */
444                 if (fp->ipend & 0xffc0)
445                         return;
446                 else
447                         break;
448 #ifdef CONFIG_BF535
449         /* 0x29 - Instruction fetch access error (535 only) */
450         case VEC_ISTRU_VL:      /* ADSP-BF535 only (MH) */
451                 info.si_code = BUS_OPFETCH;
452                 sig = SIGBUS;
453                 verbose_printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
454                 CHK_DEBUGGER_TRAP_MAYBE();
455                 break;
456 #else
457         /* 0x29 - Reserved, Caught by default */
458 #endif
459         /* 0x2A - Instruction fetch misaligned, handled here */
460         case VEC_MISALI_I:
461                 info.si_code = BUS_ADRALN;
462                 sig = SIGBUS;
463                 verbose_printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
464                 CHK_DEBUGGER_TRAP_MAYBE();
465                 break;
466         /* 0x2B - Instruction CPLB protection violation, handled here */
467         case VEC_CPLB_I_VL:
468                 info.si_code = ILL_CPLB_VI;
469                 sig = SIGBUS;
470                 verbose_printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
471                 CHK_DEBUGGER_TRAP_MAYBE();
472                 break;
473         /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
474         case VEC_CPLB_I_M:
475                 info.si_code = ILL_CPLB_MISS;
476                 sig = SIGBUS;
477                 verbose_printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
478                 break;
479         /* 0x2D - Instruction CPLB Multiple Hits, handled here */
480         case VEC_CPLB_I_MHIT:
481                 info.si_code = ILL_CPLB_MULHIT;
482                 sig = SIGSEGV;
483 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
484                 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
485                         verbose_printk(KERN_NOTICE "Jump to NULL address\n");
486                 else
487 #endif
488                         verbose_printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
489                 CHK_DEBUGGER_TRAP_MAYBE();
490                 break;
491         /* 0x2E - Illegal use of Supervisor Resource, handled here */
492         case VEC_ILL_RES:
493                 info.si_code = ILL_PRVOPC;
494                 sig = SIGILL;
495                 verbose_printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
496                 CHK_DEBUGGER_TRAP_MAYBE();
497                 break;
498         /* 0x2F - Reserved, Caught by default */
499         /* 0x30 - Reserved, Caught by default */
500         /* 0x31 - Reserved, Caught by default */
501         /* 0x32 - Reserved, Caught by default */
502         /* 0x33 - Reserved, Caught by default */
503         /* 0x34 - Reserved, Caught by default */
504         /* 0x35 - Reserved, Caught by default */
505         /* 0x36 - Reserved, Caught by default */
506         /* 0x37 - Reserved, Caught by default */
507         /* 0x38 - Reserved, Caught by default */
508         /* 0x39 - Reserved, Caught by default */
509         /* 0x3A - Reserved, Caught by default */
510         /* 0x3B - Reserved, Caught by default */
511         /* 0x3C - Reserved, Caught by default */
512         /* 0x3D - Reserved, Caught by default */
513         /* 0x3E - Reserved, Caught by default */
514         /* 0x3F - Reserved, Caught by default */
515         case VEC_HWERR:
516                 info.si_code = BUS_ADRALN;
517                 sig = SIGBUS;
518                 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
519                 /* System MMR Error */
520                 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
521                         info.si_code = BUS_ADRALN;
522                         sig = SIGBUS;
523                         verbose_printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
524                         break;
525                 /* External Memory Addressing Error */
526                 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
527                         info.si_code = BUS_ADRERR;
528                         sig = SIGBUS;
529                         verbose_printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
530                         break;
531                 /* Performance Monitor Overflow */
532                 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
533                         verbose_printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
534                         break;
535                 /* RAISE 5 instruction */
536                 case (SEQSTAT_HWERRCAUSE_RAISE_5):
537                         printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
538                         break;
539                 default:        /* Reserved */
540                         printk(KERN_NOTICE HWC_default(KERN_NOTICE));
541                         break;
542                 }
543                 CHK_DEBUGGER_TRAP_MAYBE();
544                 break;
545         /*
546          * We should be handling all known exception types above,
547          * if we get here we hit a reserved one, so panic
548          */
549         default:
550                 oops_in_progress = 1;
551                 info.si_code = ILL_ILLPARAOP;
552                 sig = SIGILL;
553                 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
554                         (fp->seqstat & SEQSTAT_EXCAUSE));
555                 CHK_DEBUGGER_TRAP_MAYBE();
556                 break;
557         }
558
559         BUG_ON(sig == 0);
560
561         if (sig != SIGTRAP) {
562                 dump_bfin_process(fp);
563                 dump_bfin_mem(fp);
564                 show_regs(fp);
565
566                 /* Print out the trace buffer if it makes sense */
567 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
568                 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
569                         verbose_printk(KERN_NOTICE "No trace since you do not have "
570                                 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
571                                 KERN_NOTICE "\n");
572                 else
573 #endif
574                         dump_bfin_trace_buffer();
575
576                 if (oops_in_progress) {
577                         /* Dump the current kernel stack */
578                         verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
579                         show_stack(current, NULL);
580                         print_modules();
581 #ifndef CONFIG_ACCESS_CHECK
582                         verbose_printk(KERN_EMERG "Please turn on "
583                                "CONFIG_ACCESS_CHECK\n");
584 #endif
585                         panic("Kernel exception");
586                 } else {
587 #ifdef CONFIG_DEBUG_VERBOSE
588                         unsigned long *stack;
589                         /* Dump the user space stack */
590                         stack = (unsigned long *)rdusp();
591                         verbose_printk(KERN_NOTICE "Userspace Stack\n");
592                         show_stack(NULL, stack);
593 #endif
594                 }
595         }
596
597 #ifdef CONFIG_IPIPE
598         if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
599 #endif
600         {
601                 info.si_signo = sig;
602                 info.si_errno = 0;
603                 info.si_addr = (void __user *)fp->pc;
604                 force_sig_info(sig, &info, current);
605         }
606
607         if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
608                 fp->pc = SAFE_USER_INSTRUCTION;
609
610         trace_buffer_restore(j);
611         return;
612 }
613
614 /* Typical exception handling routines  */
615
616 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
617
618 /*
619  * Similar to get_user, do some address checking, then dereference
620  * Return true on sucess, false on bad address
621  */
622 static bool get_instruction(unsigned short *val, unsigned short *address)
623 {
624
625         unsigned long addr;
626
627         addr = (unsigned long)address;
628
629         /* Check for odd addresses */
630         if (addr & 0x1)
631                 return false;
632
633         /* Check that things do not wrap around */
634         if (addr > (addr + 2))
635                 return false;
636
637         /*
638          * Since we are in exception context, we need to do a little address checking
639          * We need to make sure we are only accessing valid memory, and
640          * we don't read something in the async space that can hang forever
641          */
642         if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
643 #if L2_LENGTH != 0
644             (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
645 #endif
646             (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
647 #if L1_DATA_A_LENGTH != 0
648             (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
649 #endif
650 #if L1_DATA_B_LENGTH != 0
651             (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
652 #endif
653             (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
654             (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
655                addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
656             (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
657                addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
658             (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
659                addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
660             (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
661               addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
662                 *val = *address;
663                 return true;
664         }
665
666 #if L1_CODE_LENGTH != 0
667         if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
668                 isram_memcpy(val, address, 2);
669                 return true;
670         }
671 #endif
672
673
674         return false;
675 }
676
677 /*
678  * decode the instruction if we are printing out the trace, as it
679  * makes things easier to follow, without running it through objdump
680  * These are the normal instructions which cause change of flow, which
681  * would be at the source of the trace buffer
682  */
683 #if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
684 static void decode_instruction(unsigned short *address)
685 {
686         unsigned short opcode;
687
688         if (get_instruction(&opcode, address)) {
689                 if (opcode == 0x0010)
690                         verbose_printk("RTS");
691                 else if (opcode == 0x0011)
692                         verbose_printk("RTI");
693                 else if (opcode == 0x0012)
694                         verbose_printk("RTX");
695                 else if (opcode == 0x0013)
696                         verbose_printk("RTN");
697                 else if (opcode == 0x0014)
698                         verbose_printk("RTE");
699                 else if (opcode == 0x0025)
700                         verbose_printk("EMUEXCPT");
701                 else if (opcode == 0x0040 && opcode <= 0x0047)
702                         verbose_printk("STI R%i", opcode & 7);
703                 else if (opcode >= 0x0050 && opcode <= 0x0057)
704                         verbose_printk("JUMP (P%i)", opcode & 7);
705                 else if (opcode >= 0x0060 && opcode <= 0x0067)
706                         verbose_printk("CALL (P%i)", opcode & 7);
707                 else if (opcode >= 0x0070 && opcode <= 0x0077)
708                         verbose_printk("CALL (PC+P%i)", opcode & 7);
709                 else if (opcode >= 0x0080 && opcode <= 0x0087)
710                         verbose_printk("JUMP (PC+P%i)", opcode & 7);
711                 else if (opcode >= 0x0090 && opcode <= 0x009F)
712                         verbose_printk("RAISE 0x%x", opcode & 0xF);
713                 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
714                         verbose_printk("EXCPT 0x%x", opcode & 0xF);
715                 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
716                         verbose_printk("IF !CC JUMP");
717                 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
718                         verbose_printk("IF CC JUMP");
719                 else if (opcode >= 0x2000 && opcode <= 0x2fff)
720                         verbose_printk("JUMP.S");
721                 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
722                         verbose_printk("LSETUP");
723                 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
724                         verbose_printk("JUMP.L");
725                 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
726                         verbose_printk("CALL pcrel");
727                 else
728                         verbose_printk("0x%04x", opcode);
729         }
730
731 }
732 #endif
733
734 void dump_bfin_trace_buffer(void)
735 {
736 #ifdef CONFIG_DEBUG_VERBOSE
737 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
738         int tflags, i = 0;
739         char buf[150];
740         unsigned short *addr;
741 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
742         int j, index;
743 #endif
744
745         trace_buffer_save(tflags);
746
747         printk(KERN_NOTICE "Hardware Trace:\n");
748
749 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
750         printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
751 #endif
752
753         if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
754                 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
755                         decode_address(buf, (unsigned long)bfin_read_TBUF());
756                         printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
757                         addr = (unsigned short *)bfin_read_TBUF();
758                         decode_address(buf, (unsigned long)addr);
759                         printk(KERN_NOTICE "     Source : %s ", buf);
760                         decode_instruction(addr);
761                         printk("\n");
762                 }
763         }
764
765 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
766         if (trace_buff_offset)
767                 index = trace_buff_offset / 4;
768         else
769                 index = EXPAND_LEN;
770
771         j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
772         while (j) {
773                 decode_address(buf, software_trace_buff[index]);
774                 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
775                 index -= 1;
776                 if (index < 0 )
777                         index = EXPAND_LEN;
778                 decode_address(buf, software_trace_buff[index]);
779                 printk(KERN_NOTICE "     Source : %s ", buf);
780                 decode_instruction((unsigned short *)software_trace_buff[index]);
781                 printk("\n");
782                 index -= 1;
783                 if (index < 0)
784                         index = EXPAND_LEN;
785                 j--;
786                 i++;
787         }
788 #endif
789
790         trace_buffer_restore(tflags);
791 #endif
792 #endif
793 }
794 EXPORT_SYMBOL(dump_bfin_trace_buffer);
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("\n" 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  "TEXT = 0x%p-0x%p        DATA = 0x%p-0x%p\n"
999                                 KERN_NOTICE " BSS = 0x%p-0x%p  USER-STACK = 0x%p\n"
1000                                 KERN_NOTICE "\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 "\n" 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("\n" 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 "The remaining message may be meaningless\n"
1059                         KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
1060                          " 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 "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
1117         verbose_printk(KERN_NOTICE " SEQSTAT: %08lx  IPEND: %04lx  SYSCFG: %04lx\n",
1118                 (long)fp->seqstat, fp->ipend, fp->syscfg);
1119         if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
1120                 verbose_printk(KERN_NOTICE "  HWERRCAUSE: 0x%lx\n",
1121                         (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1122 #ifdef EBIU_ERRMST
1123                 /* If the error was from the EBIU, print it out */
1124                 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
1125                         verbose_printk(KERN_NOTICE "  EBIU Error Reason  : 0x%04x\n",
1126                                 bfin_read_EBIU_ERRMST());
1127                         verbose_printk(KERN_NOTICE "  EBIU Error Address : 0x%08x\n",
1128                                 bfin_read_EBIU_ERRADD());
1129                 }
1130 #endif
1131         }
1132         verbose_printk(KERN_NOTICE "  EXCAUSE   : 0x%lx\n",
1133                 fp->seqstat & SEQSTAT_EXCAUSE);
1134         for (i = 2; i <= 15 ; i++) {
1135                 if (fp->ipend & (1 << i)) {
1136                         if (i != 4) {
1137                                 decode_address(buf, bfin_read32(EVT0 + 4*i));
1138                                 verbose_printk(KERN_NOTICE "  physical IVG%i asserted : %s\n", i, buf);
1139                         } else
1140                                 verbose_printk(KERN_NOTICE "  interrupts disabled\n");
1141                 }
1142         }
1143
1144         /* if no interrupts are going off, don't print this out */
1145         if (fp->ipend & ~0x3F) {
1146                 for (i = 0; i < (NR_IRQS - 1); i++) {
1147                         if (!in_atomic)
1148                                 spin_lock_irqsave(&irq_desc[i].lock, flags);
1149
1150                         action = irq_desc[i].action;
1151                         if (!action)
1152                                 goto unlock;
1153
1154                         decode_address(buf, (unsigned int)action->handler);
1155                         verbose_printk(KERN_NOTICE "  logical irq %3d mapped  : %s", i, buf);
1156                         for (action = action->next; action; action = action->next) {
1157                                 decode_address(buf, (unsigned int)action->handler);
1158                                 verbose_printk(", %s", buf);
1159                         }
1160                         verbose_printk("\n");
1161 unlock:
1162                         if (!in_atomic)
1163                                 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1164                 }
1165         }
1166
1167         decode_address(buf, fp->rete);
1168         verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
1169         decode_address(buf, fp->retn);
1170         verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
1171         decode_address(buf, fp->retx);
1172         verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
1173         decode_address(buf, fp->rets);
1174         verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
1175         decode_address(buf, fp->pc);
1176         verbose_printk(KERN_NOTICE " PC  : %s\n", buf);
1177
1178         if (((long)fp->seqstat &  SEQSTAT_EXCAUSE) &&
1179             (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1180                 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
1181                 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1182                 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
1183                 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1184         }
1185
1186         verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1187         verbose_printk(KERN_NOTICE " R0 : %08lx    R1 : %08lx    R2 : %08lx    R3 : %08lx\n",
1188                 fp->r0, fp->r1, fp->r2, fp->r3);
1189         verbose_printk(KERN_NOTICE " R4 : %08lx    R5 : %08lx    R6 : %08lx    R7 : %08lx\n",
1190                 fp->r4, fp->r5, fp->r6, fp->r7);
1191         verbose_printk(KERN_NOTICE " P0 : %08lx    P1 : %08lx    P2 : %08lx    P3 : %08lx\n",
1192                 fp->p0, fp->p1, fp->p2, fp->p3);
1193         verbose_printk(KERN_NOTICE " P4 : %08lx    P5 : %08lx    FP : %08lx    SP : %08lx\n",
1194                 fp->p4, fp->p5, fp->fp, (long)fp);
1195         verbose_printk(KERN_NOTICE " LB0: %08lx    LT0: %08lx    LC0: %08lx\n",
1196                 fp->lb0, fp->lt0, fp->lc0);
1197         verbose_printk(KERN_NOTICE " LB1: %08lx    LT1: %08lx    LC1: %08lx\n",
1198                 fp->lb1, fp->lt1, fp->lc1);
1199         verbose_printk(KERN_NOTICE " B0 : %08lx    L0 : %08lx    M0 : %08lx    I0 : %08lx\n",
1200                 fp->b0, fp->l0, fp->m0, fp->i0);
1201         verbose_printk(KERN_NOTICE " B1 : %08lx    L1 : %08lx    M1 : %08lx    I1 : %08lx\n",
1202                 fp->b1, fp->l1, fp->m1, fp->i1);
1203         verbose_printk(KERN_NOTICE " B2 : %08lx    L2 : %08lx    M2 : %08lx    I2 : %08lx\n",
1204                 fp->b2, fp->l2, fp->m2, fp->i2);
1205         verbose_printk(KERN_NOTICE " B3 : %08lx    L3 : %08lx    M3 : %08lx    I3 : %08lx\n",
1206                 fp->b3, fp->l3, fp->m3, fp->i3);
1207         verbose_printk(KERN_NOTICE "A0.w: %08lx   A0.x: %08lx   A1.w: %08lx   A1.x: %08lx\n",
1208                 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1209
1210         verbose_printk(KERN_NOTICE "USP : %08lx  ASTAT: %08lx\n",
1211                 rdusp(), fp->astat);
1212
1213         verbose_printk(KERN_NOTICE "\n");
1214 #endif
1215 }
1216
1217 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1218 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1219 #endif
1220
1221 static DEFINE_SPINLOCK(bfin_spinlock_lock);
1222
1223 asmlinkage int sys_bfin_spinlock(int *p)
1224 {
1225         int ret, tmp = 0;
1226
1227         spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1228         ret = get_user(tmp, p);
1229         if (likely(ret == 0)) {
1230                 if (unlikely(tmp))
1231                         ret = 1;
1232                 else
1233                         put_user(1, p);
1234         }
1235         spin_unlock(&bfin_spinlock_lock);
1236         return ret;
1237 }
1238
1239 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1240 {
1241         void (*curr_handler)(void);
1242
1243         if (exception > 0x3F)
1244                 return -EINVAL;
1245
1246         curr_handler = ex_table[exception];
1247
1248         if (curr_handler != ex_replaceable)
1249                 return -EBUSY;
1250
1251         ex_table[exception] = handler;
1252
1253         return 0;
1254 }
1255 EXPORT_SYMBOL(bfin_request_exception);
1256
1257 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1258 {
1259         void (*curr_handler)(void);
1260
1261         if (exception > 0x3F)
1262                 return -EINVAL;
1263
1264         curr_handler = ex_table[exception];
1265
1266         if (curr_handler != handler)
1267                 return -EBUSY;
1268
1269         ex_table[exception] = ex_replaceable;
1270
1271         return 0;
1272 }
1273 EXPORT_SYMBOL(bfin_free_exception);
1274
1275 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1276 {
1277         switch (cplb_panic) {
1278         case CPLB_NO_UNLOCKED:
1279                 printk(KERN_EMERG "All CPLBs are locked\n");
1280                 break;
1281         case CPLB_PROT_VIOL:
1282                 return;
1283         case CPLB_NO_ADDR_MATCH:
1284                 return;
1285         case CPLB_UNKNOWN_ERR:
1286                 printk(KERN_EMERG "Unknown CPLB Exception\n");
1287                 break;
1288         }
1289
1290         oops_in_progress = 1;
1291
1292         dump_bfin_process(fp);
1293         dump_bfin_mem(fp);
1294         show_regs(fp);
1295         dump_stack();
1296         panic("Unrecoverable event");
1297 }