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