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