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