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