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