Blackfin arch: add an exception request/free api
[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 <asm/traps.h>
36 #include <asm/cacheflush.h>
37 #include <asm/blackfin.h>
38 #include <asm/irq_handler.h>
39 #include <asm/trace.h>
40
41 #ifdef CONFIG_KGDB
42 # include <linux/debugger.h>
43 # include <linux/kgdb.h>
44 #endif
45
46 /* Initiate the event table handler */
47 void __init trap_init(void)
48 {
49         CSYNC();
50         bfin_write_EVT3(trap);
51         CSYNC();
52 }
53
54 int kstack_depth_to_print = 48;
55
56 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
57 static int printk_address(unsigned long address)
58 {
59         struct vm_list_struct *vml;
60         struct task_struct *p;
61         struct mm_struct *mm;
62         unsigned long offset;
63
64 #ifdef CONFIG_KALLSYMS
65         unsigned long symsize;
66         const char *symname;
67         char *modname;
68         char *delim = ":";
69         char namebuf[128];
70
71         /* look up the address and see if we are in kernel space */
72         symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
73
74         if (symname) {
75                 /* yeah! kernel space! */
76                 if (!modname)
77                         modname = delim = "";
78                 return printk("<0x%p> { %s%s%s%s + 0x%lx }",
79                               (void *)address, delim, modname, delim, symname,
80                               (unsigned long)offset);
81
82         }
83 #endif
84
85         /* looks like we're off in user-land, so let's walk all the
86          * mappings of all our processes and see if we can't be a whee
87          * bit more specific
88          */
89         write_lock_irq(&tasklist_lock);
90         for_each_process(p) {
91                 mm = get_task_mm(p);
92                 if (!mm)
93                         continue;
94
95                 vml = mm->context.vmlist;
96                 while (vml) {
97                         struct vm_area_struct *vma = vml->vma;
98
99                         if (address >= vma->vm_start && address < vma->vm_end) {
100                                 char *name = p->comm;
101                                 struct file *file = vma->vm_file;
102                                 if (file) {
103                                         char _tmpbuf[256];
104                                         name = d_path(file->f_dentry,
105                                                       file->f_vfsmnt,
106                                                       _tmpbuf,
107                                                       sizeof(_tmpbuf));
108                                 }
109
110                                 /* FLAT does not have its text aligned to the start of
111                                  * the map while FDPIC ELF does ...
112                                  */
113                                 if (current->mm &&
114                                     (address > current->mm->start_code) &&
115                                     (address < current->mm->end_code))
116                                         offset = address - current->mm->start_code;
117                                 else
118                                         offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
119
120                                 write_unlock_irq(&tasklist_lock);
121                                 return printk("<0x%p> [ %s + 0x%lx ]",
122                                               (void *)address, name, offset);
123                         }
124
125                         vml = vml->next;
126                 }
127         }
128         write_unlock_irq(&tasklist_lock);
129
130         /* we were unable to find this address anywhere */
131         return printk("[<0x%p>]", (void *)address);
132 }
133 #endif
134
135 asmlinkage void trap_c(struct pt_regs *fp)
136 {
137 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
138         int j;
139 #endif
140         int sig = 0;
141         siginfo_t info;
142         unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
143
144 #ifdef CONFIG_KGDB
145 # define CHK_DEBUGGER_TRAP() \
146         do { \
147                 CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \
148         } while (0)
149 # define CHK_DEBUGGER_TRAP_MAYBE() \
150         do { \
151                 if (kgdb_connected) \
152                         CHK_DEBUGGER_TRAP(); \
153         } while (0)
154 #else
155 # define CHK_DEBUGGER_TRAP() do { } while (0)
156 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
157 #endif
158
159         trace_buffer_save(j);
160
161         /* trap_c() will be called for exceptions. During exceptions
162          * processing, the pc value should be set with retx value.
163          * With this change we can cleanup some code in signal.c- TODO
164          */
165         fp->orig_pc = fp->retx;
166         /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
167                 trapnr, fp->ipend, fp->pc, fp->retx); */
168
169         /* send the appropriate signal to the user program */
170         switch (trapnr) {
171
172         /* This table works in conjuction with the one in ./mach-common/entry.S
173          * Some exceptions are handled there (in assembly, in exception space)
174          * Some are handled here, (in C, in interrupt space)
175          * Some, like CPLB, are handled in both, where the normal path is
176          * handled in assembly/exception space, and the error path is handled
177          * here
178          */
179
180         /* 0x00 - Linux Syscall, getting here is an error */
181         /* 0x01 - userspace gdb breakpoint, handled here */
182         case VEC_EXCPT01:
183                 info.si_code = TRAP_ILLTRAP;
184                 sig = SIGTRAP;
185                 CHK_DEBUGGER_TRAP_MAYBE();
186                 /* Check if this is a breakpoint in kernel space */
187                 if (fp->ipend & 0xffc0)
188                         return;
189                 else
190                         break;
191 #ifdef CONFIG_KGDB
192         case VEC_EXCPT02 :               /* gdb connection */
193                 info.si_code = TRAP_ILLTRAP;
194                 sig = SIGTRAP;
195                 CHK_DEBUGGER_TRAP();
196                 return;
197 #else
198         /* 0x02 - User Defined, Caught by default */
199 #endif
200         /* 0x03 - User Defined, userspace stack overflow */
201         case VEC_EXCPT03:
202                 info.si_code = SEGV_STACKFLOW;
203                 sig = SIGSEGV;
204                 printk(KERN_EMERG EXC_0x03);
205                 CHK_DEBUGGER_TRAP();
206                 break;
207         /* 0x04 - User Defined, Caught by default */
208         /* 0x05 - User Defined, Caught by default */
209         /* 0x06 - User Defined, Caught by default */
210         /* 0x07 - User Defined, Caught by default */
211         /* 0x08 - User Defined, Caught by default */
212         /* 0x09 - User Defined, Caught by default */
213         /* 0x0A - User Defined, Caught by default */
214         /* 0x0B - User Defined, Caught by default */
215         /* 0x0C - User Defined, Caught by default */
216         /* 0x0D - User Defined, Caught by default */
217         /* 0x0E - User Defined, Caught by default */
218         /* 0x0F - User Defined, Caught by default */
219         /* 0x10 HW Single step, handled here */
220         case VEC_STEP:
221                 info.si_code = TRAP_STEP;
222                 sig = SIGTRAP;
223                 CHK_DEBUGGER_TRAP_MAYBE();
224                 /* Check if this is a single step in kernel space */
225                 if (fp->ipend & 0xffc0)
226                         return;
227                 else
228                         break;
229         /* 0x11 - Trace Buffer Full, handled here */
230         case VEC_OVFLOW:
231                 info.si_code = TRAP_TRACEFLOW;
232                 sig = SIGTRAP;
233                 printk(KERN_EMERG EXC_0x11);
234                 CHK_DEBUGGER_TRAP();
235                 break;
236         /* 0x12 - Reserved, Caught by default */
237         /* 0x13 - Reserved, Caught by default */
238         /* 0x14 - Reserved, Caught by default */
239         /* 0x15 - Reserved, Caught by default */
240         /* 0x16 - Reserved, Caught by default */
241         /* 0x17 - Reserved, Caught by default */
242         /* 0x18 - Reserved, Caught by default */
243         /* 0x19 - Reserved, Caught by default */
244         /* 0x1A - Reserved, Caught by default */
245         /* 0x1B - Reserved, Caught by default */
246         /* 0x1C - Reserved, Caught by default */
247         /* 0x1D - Reserved, Caught by default */
248         /* 0x1E - Reserved, Caught by default */
249         /* 0x1F - Reserved, Caught by default */
250         /* 0x20 - Reserved, Caught by default */
251         /* 0x21 - Undefined Instruction, handled here */
252         case VEC_UNDEF_I:
253                 info.si_code = ILL_ILLOPC;
254                 sig = SIGILL;
255                 printk(KERN_EMERG EXC_0x21);
256                 CHK_DEBUGGER_TRAP();
257                 break;
258         /* 0x22 - Illegal Instruction Combination, handled here */
259         case VEC_ILGAL_I:
260                 info.si_code = ILL_ILLPARAOP;
261                 sig = SIGILL;
262                 printk(KERN_EMERG EXC_0x22);
263                 CHK_DEBUGGER_TRAP();
264                 break;
265         /* 0x23 - Data CPLB Protection Violation,
266                  normal case is handled in _cplb_hdr */
267         case VEC_CPLB_VL:
268                 info.si_code = ILL_CPLB_VI;
269                 sig = SIGILL;
270                 printk(KERN_EMERG EXC_0x23);
271                 CHK_DEBUGGER_TRAP();
272                 break;
273         /* 0x24 - Data access misaligned, handled here */
274         case VEC_MISALI_D:
275                 info.si_code = BUS_ADRALN;
276                 sig = SIGBUS;
277                 printk(KERN_EMERG EXC_0x24);
278                 CHK_DEBUGGER_TRAP();
279                 break;
280         /* 0x25 - Unrecoverable Event, handled here */
281         case VEC_UNCOV:
282                 info.si_code = ILL_ILLEXCPT;
283                 sig = SIGILL;
284                 printk(KERN_EMERG EXC_0x25);
285                 CHK_DEBUGGER_TRAP();
286                 break;
287         /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
288                 error case is handled here */
289         case VEC_CPLB_M:
290                 info.si_code = BUS_ADRALN;
291                 sig = SIGBUS;
292                 printk(KERN_EMERG EXC_0x26);
293                 CHK_DEBUGGER_TRAP();
294                 break;
295         /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
296         case VEC_CPLB_MHIT:
297                 info.si_code = ILL_CPLB_MULHIT;
298 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
299                 sig = SIGSEGV;
300                 printk(KERN_EMERG "\n"
301                         KERN_EMERG "NULL pointer access (probably)\n");
302 #else
303                 sig = SIGILL;
304                 printk(KERN_EMERG EXC_0x27);
305 #endif
306                 CHK_DEBUGGER_TRAP();
307                 break;
308         /* 0x28 - Emulation Watchpoint, handled here */
309         case VEC_WATCH:
310                 info.si_code = TRAP_WATCHPT;
311                 sig = SIGTRAP;
312                 pr_debug(EXC_0x28);
313                 CHK_DEBUGGER_TRAP_MAYBE();
314                 /* Check if this is a watchpoint in kernel space */
315                 if (fp->ipend & 0xffc0)
316                         return;
317                 else
318                         break;
319 #ifdef CONFIG_BF535
320         /* 0x29 - Instruction fetch access error (535 only) */
321         case VEC_ISTRU_VL:      /* ADSP-BF535 only (MH) */
322                 info.si_code = BUS_OPFETCH;
323                 sig = SIGBUS;
324                 printk(KERN_EMERG "BF535: VEC_ISTRU_VL\n");
325                 CHK_DEBUGGER_TRAP();
326                 break;
327 #else
328         /* 0x29 - Reserved, Caught by default */
329 #endif
330         /* 0x2A - Instruction fetch misaligned, handled here */
331         case VEC_MISALI_I:
332                 info.si_code = BUS_ADRALN;
333                 sig = SIGBUS;
334                 printk(KERN_EMERG EXC_0x2A);
335                 CHK_DEBUGGER_TRAP();
336                 break;
337         /* 0x2B - Instruction CPLB protection Violation,
338                 handled in _cplb_hdr */
339         case VEC_CPLB_I_VL:
340                 info.si_code = ILL_CPLB_VI;
341                 sig = SIGILL;
342                 printk(KERN_EMERG EXC_0x2B);
343                 CHK_DEBUGGER_TRAP();
344                 break;
345         /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
346         case VEC_CPLB_I_M:
347                 info.si_code = ILL_CPLB_MISS;
348                 sig = SIGBUS;
349                 printk(KERN_EMERG EXC_0x2C);
350                 CHK_DEBUGGER_TRAP();
351                 break;
352         /* 0x2D - Instruction CPLB Multiple Hits, handled here */
353         case VEC_CPLB_I_MHIT:
354                 info.si_code = ILL_CPLB_MULHIT;
355 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
356                 sig = SIGSEGV;
357                 printk(KERN_EMERG "\n\nJump to address 0 - 0x0fff\n");
358 #else
359                 sig = SIGILL;
360                 printk(KERN_EMERG EXC_0x2D);
361 #endif
362                 CHK_DEBUGGER_TRAP();
363                 break;
364         /* 0x2E - Illegal use of Supervisor Resource, handled here */
365         case VEC_ILL_RES:
366                 info.si_code = ILL_PRVOPC;
367                 sig = SIGILL;
368                 printk(KERN_EMERG EXC_0x2E);
369                 CHK_DEBUGGER_TRAP();
370                 break;
371         /* 0x2F - Reserved, Caught by default */
372         /* 0x30 - Reserved, Caught by default */
373         /* 0x31 - Reserved, Caught by default */
374         /* 0x32 - Reserved, Caught by default */
375         /* 0x33 - Reserved, Caught by default */
376         /* 0x34 - Reserved, Caught by default */
377         /* 0x35 - Reserved, Caught by default */
378         /* 0x36 - Reserved, Caught by default */
379         /* 0x37 - Reserved, Caught by default */
380         /* 0x38 - Reserved, Caught by default */
381         /* 0x39 - Reserved, Caught by default */
382         /* 0x3A - Reserved, Caught by default */
383         /* 0x3B - Reserved, Caught by default */
384         /* 0x3C - Reserved, Caught by default */
385         /* 0x3D - Reserved, Caught by default */
386         /* 0x3E - Reserved, Caught by default */
387         /* 0x3F - Reserved, Caught by default */
388         default:
389                 info.si_code = TRAP_ILLTRAP;
390                 sig = SIGTRAP;
391                 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
392                         (fp->seqstat & SEQSTAT_EXCAUSE));
393                 CHK_DEBUGGER_TRAP();
394                 break;
395         }
396
397         info.si_signo = sig;
398         info.si_errno = 0;
399         info.si_addr = (void *)fp->pc;
400         force_sig_info(sig, &info, current);
401         if (sig != 0 && sig != SIGTRAP) {
402                 unsigned long stack;
403                 dump_bfin_regs(fp, (void *)fp->retx);
404                 dump_bfin_trace_buffer();
405                 show_stack(current, &stack);
406                 if (current->mm == NULL)
407                         panic("Kernel exception");
408         }
409
410         /* if the address that we are about to return to is not valid, set it
411          * to a valid address, if we have a current application or panic
412          */
413         if (!(fp->pc <= physical_mem_end
414 #if L1_CODE_LENGTH != 0
415             || (fp->pc >= L1_CODE_START &&
416                 fp->pc <= (L1_CODE_START + L1_CODE_LENGTH))
417 #endif
418         )) {
419                 if (current->mm) {
420                         fp->pc = current->mm->start_code;
421                 } else {
422                         printk(KERN_EMERG
423                                 "I can't return to memory that doesn't exist"
424                                 " - bad things happen\n");
425                         panic("Help - I've fallen and can't get up\n");
426                 }
427         }
428
429         trace_buffer_restore(j);
430         return;
431 }
432
433 /* Typical exception handling routines  */
434
435 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
436
437 void dump_bfin_trace_buffer(void)
438 {
439 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
440         int tflags, i = 0;
441 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
442         int j, index;
443 #endif
444
445         trace_buffer_save(tflags);
446
447         printk(KERN_EMERG "Hardware Trace:\n");
448
449         if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
450                 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
451                         printk(KERN_EMERG "%4i Target : ", i);
452                         printk_address((unsigned long)bfin_read_TBUF());
453                         printk("\n" KERN_EMERG "     Source : ");
454                         printk_address((unsigned long)bfin_read_TBUF());
455                         printk("\n");
456                 }
457         }
458
459 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
460         if (trace_buff_offset)
461                 index = trace_buff_offset/4 - 1;
462         else
463                 index = EXPAND_LEN;
464
465         j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
466         while (j) {
467                 printk(KERN_EMERG "%4i Target : ", i);
468                 printk_address(software_trace_buff[index]);
469                 index -= 1;
470                 if (index < 0 )
471                         index = EXPAND_LEN;
472                 printk("\n" KERN_EMERG "     Source : ");
473                 printk_address(software_trace_buff[index]);
474                 index -= 1;
475                 if (index < 0)
476                         index = EXPAND_LEN;
477                 printk("\n");
478                 j--;
479                 i++;
480         }
481 #endif
482
483         trace_buffer_restore(tflags);
484 #endif
485 }
486 EXPORT_SYMBOL(dump_bfin_trace_buffer);
487
488 static void show_trace(struct task_struct *tsk, unsigned long *sp)
489 {
490         unsigned long addr;
491
492         printk("\nCall Trace:");
493 #ifdef CONFIG_KALLSYMS
494         printk("\n");
495 #endif
496
497         while (!kstack_end(sp)) {
498                 addr = *sp++;
499                 /*
500                  * If the address is either in the text segment of the
501                  * kernel, or in the region which contains vmalloc'ed
502                  * memory, it *may* be the address of a calling
503                  * routine; if so, print it so that someone tracing
504                  * down the cause of the crash will be able to figure
505                  * out the call path that was taken.
506                  */
507                 if (kernel_text_address(addr))
508                         print_ip_sym(addr);
509         }
510
511         printk("\n");
512 }
513
514 void show_stack(struct task_struct *task, unsigned long *stack)
515 {
516         unsigned long *endstack, addr;
517         int i;
518
519         /* Cannot call dump_bfin_trace_buffer() here as show_stack() is
520          * called externally in some places in the kernel.
521          */
522
523         if (!stack) {
524                 if (task)
525                         stack = (unsigned long *)task->thread.ksp;
526                 else
527                         stack = (unsigned long *)&stack;
528         }
529
530         addr = (unsigned long)stack;
531         endstack = (unsigned long *)PAGE_ALIGN(addr);
532
533         printk(KERN_EMERG "Stack from %08lx:", (unsigned long)stack);
534         for (i = 0; i < kstack_depth_to_print; i++) {
535                 if (stack + 1 > endstack)
536                         break;
537                 if (i % 8 == 0)
538                         printk("\n" KERN_EMERG "       ");
539                 printk(" %08lx", *stack++);
540         }
541
542         show_trace(task, stack);
543 }
544
545 void dump_stack(void)
546 {
547         unsigned long stack;
548 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
549         int tflags;
550 #endif
551         trace_buffer_save(tflags);
552         dump_bfin_trace_buffer();
553         show_stack(current, &stack);
554         trace_buffer_restore(tflags);
555 }
556
557 EXPORT_SYMBOL(dump_stack);
558
559 void dump_bfin_regs(struct pt_regs *fp, void *retaddr)
560 {
561         if (current->pid) {
562                 printk(KERN_EMERG "\n" KERN_EMERG "CURRENT PROCESS:\n"
563                         KERN_EMERG "\n");
564                 printk(KERN_EMERG "COMM=%s PID=%d\n",
565                         current->comm, current->pid);
566         } else {
567                 printk
568                     (KERN_EMERG "\n" KERN_EMERG
569                      "No Valid pid - Either things are really messed up,"
570                      " or you are in the kernel\n");
571         }
572
573         if (current->mm) {
574                 printk(KERN_EMERG "TEXT = 0x%p-0x%p  DATA = 0x%p-0x%p\n"
575                        KERN_EMERG "BSS = 0x%p-0x%p   USER-STACK = 0x%p\n"
576                        KERN_EMERG "\n",
577                        (void *)current->mm->start_code,
578                        (void *)current->mm->end_code,
579                        (void *)current->mm->start_data,
580                        (void *)current->mm->end_data,
581                        (void *)current->mm->end_data,
582                        (void *)current->mm->brk,
583                        (void *)current->mm->start_stack);
584         }
585
586         printk(KERN_EMERG "return address: [0x%p]; contents of:", retaddr);
587         if (retaddr != 0 && retaddr <= (void *)physical_mem_end
588 #if L1_CODE_LENGTH != 0
589             /* FIXME: Copy the code out of L1 Instruction SRAM through dma
590                memcpy.  */
591             && !(retaddr >= (void *)L1_CODE_START
592                  && retaddr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
593 #endif
594         ) {
595                 int i = ((unsigned int)retaddr & 0xFFFFFFF0) - 32;
596                 unsigned short x = 0;
597                 for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
598                         if (!(i & 0xF))
599                                 printk("\n" KERN_EMERG "0x%08x: ", i);
600
601                         if (get_user(x, (unsigned short *)i))
602                                 break;
603 #ifndef CONFIG_DEBUG_HWERR
604                         /* If one of the last few instructions was a STI
605                          * it is likely that the error occured awhile ago
606                          * and we just noticed
607                          */
608                         if (x >= 0x0040 && x <= 0x0047 && i <= 0)
609                                 panic("\n\nWARNING : You should reconfigure"
610                                         " the kernel to turn on\n"
611                                         " 'Hardware error interrupt"
612                                         " debugging'\n"
613                                         " The rest of this error"
614                                         " is meanless\n");
615 #endif
616                         if (i == (unsigned int)retaddr)
617                                 printk("[%04x]", x);
618                         else
619                                 printk(" %04x ", x);
620                 }
621                 printk("\n" KERN_EMERG "\n");
622         } else
623                 printk(KERN_EMERG
624                         "Cannot look at the [PC] for it is"
625                         "in unreadable L1 SRAM - sorry\n");
626
627
628         printk(KERN_EMERG
629                 "RETE:  %08lx  RETN: %08lx  RETX: %08lx  RETS: %08lx\n",
630                 fp->rete, fp->retn, fp->retx, fp->rets);
631         printk(KERN_EMERG "IPEND: %04lx  SYSCFG: %04lx\n",
632                 fp->ipend, fp->syscfg);
633         printk(KERN_EMERG "SEQSTAT: %08lx    SP: %08lx\n",
634                 (long)fp->seqstat, (long)fp);
635         printk(KERN_EMERG "R0: %08lx    R1: %08lx    R2: %08lx    R3: %08lx\n",
636                 fp->r0, fp->r1, fp->r2, fp->r3);
637         printk(KERN_EMERG "R4: %08lx    R5: %08lx    R6: %08lx    R7: %08lx\n",
638                 fp->r4, fp->r5, fp->r6, fp->r7);
639         printk(KERN_EMERG "P0: %08lx    P1: %08lx    P2: %08lx    P3: %08lx\n",
640                 fp->p0, fp->p1, fp->p2, fp->p3);
641         printk(KERN_EMERG
642                 "P4: %08lx    P5: %08lx    FP: %08lx\n",
643                 fp->p4, fp->p5, fp->fp);
644         printk(KERN_EMERG
645                 "A0.w: %08lx    A0.x: %08lx    A1.w: %08lx    A1.x: %08lx\n",
646                 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
647
648         printk(KERN_EMERG "LB0: %08lx  LT0: %08lx  LC0: %08lx\n",
649                 fp->lb0, fp->lt0, fp->lc0);
650         printk(KERN_EMERG "LB1: %08lx  LT1: %08lx  LC1: %08lx\n",
651                 fp->lb1, fp->lt1, fp->lc1);
652         printk(KERN_EMERG "B0: %08lx  L0: %08lx  M0: %08lx  I0: %08lx\n",
653                 fp->b0, fp->l0, fp->m0, fp->i0);
654         printk(KERN_EMERG "B1: %08lx  L1: %08lx  M1: %08lx  I1: %08lx\n",
655                 fp->b1, fp->l1, fp->m1, fp->i1);
656         printk(KERN_EMERG "B2: %08lx  L2: %08lx  M2: %08lx  I2: %08lx\n",
657                 fp->b2, fp->l2, fp->m2, fp->i2);
658         printk(KERN_EMERG "B3: %08lx  L3: %08lx  M3: %08lx  I3: %08lx\n",
659                 fp->b3, fp->l3, fp->m3, fp->i3);
660
661         printk(KERN_EMERG "\n" KERN_EMERG "USP: %08lx   ASTAT: %08lx\n",
662                 rdusp(), fp->astat);
663         if ((long)fp->seqstat & SEQSTAT_EXCAUSE) {
664                 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n",
665                         (void *)bfin_read_DCPLB_FAULT_ADDR());
666                 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n",
667                         (void *)bfin_read_ICPLB_FAULT_ADDR());
668         }
669
670         printk("\n\n");
671 }
672
673 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
674 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
675 #endif
676
677 asmlinkage int sys_bfin_spinlock(int *spinlock)
678 {
679         int ret = 0;
680         int tmp = 0;
681
682         local_irq_disable();
683         ret = get_user(tmp, spinlock);
684         if (ret == 0) {
685                 if (tmp)
686                         ret = 1;
687                 tmp = 1;
688                 put_user(tmp, spinlock);
689         }
690         local_irq_enable();
691         return ret;
692 }
693
694 int bfin_request_exception(unsigned int exception, void (*handler)(void))
695 {
696         void (*curr_handler)(void);
697
698         if (exception > 0x3F)
699                 return -EINVAL;
700
701         curr_handler = ex_table[exception];
702
703         if (curr_handler != ex_replaceable)
704                 return -EBUSY;
705
706         ex_table[exception] = handler;
707
708         return 0;
709 }
710 EXPORT_SYMBOL(bfin_request_exception);
711
712 int bfin_free_exception(unsigned int exception, void (*handler)(void))
713 {
714         void (*curr_handler)(void);
715
716         if (exception > 0x3F)
717                 return -EINVAL;
718
719         curr_handler = ex_table[exception];
720
721         if (curr_handler != handler)
722                 return -EBUSY;
723
724         ex_table[exception] = ex_replaceable;
725
726         return 0;
727 }
728 EXPORT_SYMBOL(bfin_free_exception);
729
730 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
731 {
732         switch (cplb_panic) {
733         case CPLB_NO_UNLOCKED:
734                 printk(KERN_EMERG "All CPLBs are locked\n");
735                 break;
736         case CPLB_PROT_VIOL:
737                 return;
738         case CPLB_NO_ADDR_MATCH:
739                 return;
740         case CPLB_UNKNOWN_ERR:
741                 printk(KERN_EMERG "Unknown CPLB Exception\n");
742                 break;
743         }
744
745         printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR());
746         printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR());
747         dump_bfin_regs(fp, (void *)fp->retx);
748         dump_stack();
749         panic("Unrecoverable event\n");
750 }