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