blob: ce86659f9b65a9ce853d8bfed5df1904fe19fdd5 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
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
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080030#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -070031#include <linux/interrupt.h>
32#include <linux/module.h>
33#include <linux/kallsyms.h>
Bryan Wud31c5ab2007-08-10 13:00:42 -070034#include <linux/fs.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080035#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>
Bryan Wu1394f032007-05-06 14:50:22 -070040
41#ifdef CONFIG_KGDB
42# include <linux/debugger.h>
43# include <linux/kgdb.h>
44#endif
45
46/* Initiate the event table handler */
47void __init trap_init(void)
48{
49 CSYNC();
50 bfin_write_EVT3(trap);
51 CSYNC();
52}
53
Bryan Wu1394f032007-05-06 14:50:22 -070054int kstack_depth_to_print = 48;
55
Robin Getz518039b2007-07-25 11:03:28 +080056#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Robin Getz885be032007-10-29 17:20:41 +080057static void printk_address(unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070058{
59 struct vm_list_struct *vml;
60 struct task_struct *p;
61 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080062 unsigned long flags, offset;
63 unsigned int in_exception = bfin_read_IPEND() & 0x10;
Bryan Wu1394f032007-05-06 14:50:22 -070064
65#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080066 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070067 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 = "";
Robin Getz885be032007-10-29 17:20:41 +080079 printk("<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080080 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -070081 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +080082 return;
Bryan Wu1394f032007-05-06 14:50:22 -070083
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 */
Robin Getz885be032007-10-29 17:20:41 +080091 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -070092 for_each_process(p) {
Robin Getz885be032007-10-29 17:20:41 +080093 mm = (in_exception ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -070094 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
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800112 /* 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
Robin Getz885be032007-10-29 17:20:41 +0800122 printk("<0x%p> [ %s + 0x%lx ]",
123 (void *)address, name, offset);
124 if (!in_exception)
125 mmput(mm);
126 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700127 }
128
129 vml = vml->next;
130 }
Robin Getz885be032007-10-29 17:20:41 +0800131 if (!in_exception)
132 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700133 }
Bryan Wu1394f032007-05-06 14:50:22 -0700134
135 /* we were unable to find this address anywhere */
Robin Getz885be032007-10-29 17:20:41 +0800136 printk("[<0x%p>]", (void *)address);
137
138done:
139 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700140}
Robin Getz518039b2007-07-25 11:03:28 +0800141#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700142
Robin Getz2ebcade2007-10-09 17:24:30 +0800143asmlinkage void double_fault_c(struct pt_regs *fp)
144{
145 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
146 dump_bfin_regs(fp, (void *)fp->retx);
147 panic("Double Fault - unrecoverable event\n");
148
149}
150
Bryan Wu1394f032007-05-06 14:50:22 -0700151asmlinkage void trap_c(struct pt_regs *fp)
152{
Robin Getz518039b2007-07-25 11:03:28 +0800153#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
154 int j;
155#endif
156 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700157 siginfo_t info;
158 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
159
160#ifdef CONFIG_KGDB
Robin Getzc5d88d92007-06-21 11:34:16 +0800161# define CHK_DEBUGGER_TRAP() \
162 do { \
Sonic Zhang64c5cb82007-07-25 10:46:45 +0800163 CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \
Robin Getzc5d88d92007-06-21 11:34:16 +0800164 } while (0)
165# define CHK_DEBUGGER_TRAP_MAYBE() \
166 do { \
167 if (kgdb_connected) \
168 CHK_DEBUGGER_TRAP(); \
169 } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -0700170#else
171# define CHK_DEBUGGER_TRAP() do { } while (0)
172# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
173#endif
174
175 trace_buffer_save(j);
176
177 /* trap_c() will be called for exceptions. During exceptions
178 * processing, the pc value should be set with retx value.
179 * With this change we can cleanup some code in signal.c- TODO
180 */
181 fp->orig_pc = fp->retx;
182 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
183 trapnr, fp->ipend, fp->pc, fp->retx); */
184
185 /* send the appropriate signal to the user program */
186 switch (trapnr) {
187
188 /* This table works in conjuction with the one in ./mach-common/entry.S
189 * Some exceptions are handled there (in assembly, in exception space)
190 * Some are handled here, (in C, in interrupt space)
191 * Some, like CPLB, are handled in both, where the normal path is
192 * handled in assembly/exception space, and the error path is handled
193 * here
194 */
195
196 /* 0x00 - Linux Syscall, getting here is an error */
197 /* 0x01 - userspace gdb breakpoint, handled here */
198 case VEC_EXCPT01:
199 info.si_code = TRAP_ILLTRAP;
200 sig = SIGTRAP;
201 CHK_DEBUGGER_TRAP_MAYBE();
202 /* Check if this is a breakpoint in kernel space */
203 if (fp->ipend & 0xffc0)
204 return;
205 else
206 break;
207#ifdef CONFIG_KGDB
208 case VEC_EXCPT02 : /* gdb connection */
209 info.si_code = TRAP_ILLTRAP;
210 sig = SIGTRAP;
211 CHK_DEBUGGER_TRAP();
212 return;
213#else
214 /* 0x02 - User Defined, Caught by default */
215#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800216 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700217 case VEC_EXCPT03:
218 info.si_code = SEGV_STACKFLOW;
219 sig = SIGSEGV;
220 printk(KERN_EMERG EXC_0x03);
221 CHK_DEBUGGER_TRAP();
222 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800223 /* 0x04 - User Defined, Caught by default */
Bryan Wu1394f032007-05-06 14:50:22 -0700224 /* 0x05 - User Defined, Caught by default */
225 /* 0x06 - User Defined, Caught by default */
226 /* 0x07 - User Defined, Caught by default */
227 /* 0x08 - User Defined, Caught by default */
228 /* 0x09 - User Defined, Caught by default */
229 /* 0x0A - User Defined, Caught by default */
230 /* 0x0B - User Defined, Caught by default */
231 /* 0x0C - User Defined, Caught by default */
232 /* 0x0D - User Defined, Caught by default */
233 /* 0x0E - User Defined, Caught by default */
234 /* 0x0F - User Defined, Caught by default */
235 /* 0x10 HW Single step, handled here */
236 case VEC_STEP:
237 info.si_code = TRAP_STEP;
238 sig = SIGTRAP;
239 CHK_DEBUGGER_TRAP_MAYBE();
240 /* Check if this is a single step in kernel space */
241 if (fp->ipend & 0xffc0)
242 return;
243 else
244 break;
245 /* 0x11 - Trace Buffer Full, handled here */
246 case VEC_OVFLOW:
247 info.si_code = TRAP_TRACEFLOW;
248 sig = SIGTRAP;
249 printk(KERN_EMERG EXC_0x11);
250 CHK_DEBUGGER_TRAP();
251 break;
252 /* 0x12 - Reserved, Caught by default */
253 /* 0x13 - Reserved, Caught by default */
254 /* 0x14 - Reserved, Caught by default */
255 /* 0x15 - Reserved, Caught by default */
256 /* 0x16 - Reserved, Caught by default */
257 /* 0x17 - Reserved, Caught by default */
258 /* 0x18 - Reserved, Caught by default */
259 /* 0x19 - Reserved, Caught by default */
260 /* 0x1A - Reserved, Caught by default */
261 /* 0x1B - Reserved, Caught by default */
262 /* 0x1C - Reserved, Caught by default */
263 /* 0x1D - Reserved, Caught by default */
264 /* 0x1E - Reserved, Caught by default */
265 /* 0x1F - Reserved, Caught by default */
266 /* 0x20 - Reserved, Caught by default */
267 /* 0x21 - Undefined Instruction, handled here */
268 case VEC_UNDEF_I:
269 info.si_code = ILL_ILLOPC;
270 sig = SIGILL;
271 printk(KERN_EMERG EXC_0x21);
272 CHK_DEBUGGER_TRAP();
273 break;
274 /* 0x22 - Illegal Instruction Combination, handled here */
275 case VEC_ILGAL_I:
276 info.si_code = ILL_ILLPARAOP;
277 sig = SIGILL;
278 printk(KERN_EMERG EXC_0x22);
279 CHK_DEBUGGER_TRAP();
280 break;
281 /* 0x23 - Data CPLB Protection Violation,
282 normal case is handled in _cplb_hdr */
283 case VEC_CPLB_VL:
284 info.si_code = ILL_CPLB_VI;
285 sig = SIGILL;
286 printk(KERN_EMERG EXC_0x23);
287 CHK_DEBUGGER_TRAP();
288 break;
289 /* 0x24 - Data access misaligned, handled here */
290 case VEC_MISALI_D:
291 info.si_code = BUS_ADRALN;
292 sig = SIGBUS;
293 printk(KERN_EMERG EXC_0x24);
294 CHK_DEBUGGER_TRAP();
295 break;
296 /* 0x25 - Unrecoverable Event, handled here */
297 case VEC_UNCOV:
298 info.si_code = ILL_ILLEXCPT;
299 sig = SIGILL;
300 printk(KERN_EMERG EXC_0x25);
301 CHK_DEBUGGER_TRAP();
302 break;
303 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
304 error case is handled here */
305 case VEC_CPLB_M:
306 info.si_code = BUS_ADRALN;
307 sig = SIGBUS;
308 printk(KERN_EMERG EXC_0x26);
309 CHK_DEBUGGER_TRAP();
310 break;
311 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
312 case VEC_CPLB_MHIT:
313 info.si_code = ILL_CPLB_MULHIT;
314#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
315 sig = SIGSEGV;
Robin Getzc5d88d92007-06-21 11:34:16 +0800316 printk(KERN_EMERG "\n"
317 KERN_EMERG "NULL pointer access (probably)\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700318#else
319 sig = SIGILL;
320 printk(KERN_EMERG EXC_0x27);
321#endif
322 CHK_DEBUGGER_TRAP();
323 break;
324 /* 0x28 - Emulation Watchpoint, handled here */
325 case VEC_WATCH:
326 info.si_code = TRAP_WATCHPT;
327 sig = SIGTRAP;
328 pr_debug(EXC_0x28);
329 CHK_DEBUGGER_TRAP_MAYBE();
330 /* Check if this is a watchpoint in kernel space */
331 if (fp->ipend & 0xffc0)
332 return;
333 else
334 break;
335#ifdef CONFIG_BF535
336 /* 0x29 - Instruction fetch access error (535 only) */
337 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
338 info.si_code = BUS_OPFETCH;
339 sig = SIGBUS;
340 printk(KERN_EMERG "BF535: VEC_ISTRU_VL\n");
341 CHK_DEBUGGER_TRAP();
342 break;
343#else
344 /* 0x29 - Reserved, Caught by default */
345#endif
346 /* 0x2A - Instruction fetch misaligned, handled here */
347 case VEC_MISALI_I:
348 info.si_code = BUS_ADRALN;
349 sig = SIGBUS;
350 printk(KERN_EMERG EXC_0x2A);
351 CHK_DEBUGGER_TRAP();
352 break;
353 /* 0x2B - Instruction CPLB protection Violation,
354 handled in _cplb_hdr */
355 case VEC_CPLB_I_VL:
356 info.si_code = ILL_CPLB_VI;
357 sig = SIGILL;
358 printk(KERN_EMERG EXC_0x2B);
359 CHK_DEBUGGER_TRAP();
360 break;
361 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
362 case VEC_CPLB_I_M:
363 info.si_code = ILL_CPLB_MISS;
364 sig = SIGBUS;
365 printk(KERN_EMERG EXC_0x2C);
366 CHK_DEBUGGER_TRAP();
367 break;
368 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
369 case VEC_CPLB_I_MHIT:
370 info.si_code = ILL_CPLB_MULHIT;
371#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
372 sig = SIGSEGV;
373 printk(KERN_EMERG "\n\nJump to address 0 - 0x0fff\n");
374#else
375 sig = SIGILL;
376 printk(KERN_EMERG EXC_0x2D);
377#endif
378 CHK_DEBUGGER_TRAP();
379 break;
380 /* 0x2E - Illegal use of Supervisor Resource, handled here */
381 case VEC_ILL_RES:
382 info.si_code = ILL_PRVOPC;
383 sig = SIGILL;
384 printk(KERN_EMERG EXC_0x2E);
385 CHK_DEBUGGER_TRAP();
386 break;
387 /* 0x2F - Reserved, Caught by default */
388 /* 0x30 - Reserved, Caught by default */
389 /* 0x31 - Reserved, Caught by default */
390 /* 0x32 - Reserved, Caught by default */
391 /* 0x33 - Reserved, Caught by default */
392 /* 0x34 - Reserved, Caught by default */
393 /* 0x35 - Reserved, Caught by default */
394 /* 0x36 - Reserved, Caught by default */
395 /* 0x37 - Reserved, Caught by default */
396 /* 0x38 - Reserved, Caught by default */
397 /* 0x39 - Reserved, Caught by default */
398 /* 0x3A - Reserved, Caught by default */
399 /* 0x3B - Reserved, Caught by default */
400 /* 0x3C - Reserved, Caught by default */
401 /* 0x3D - Reserved, Caught by default */
402 /* 0x3E - Reserved, Caught by default */
403 /* 0x3F - Reserved, Caught by default */
404 default:
405 info.si_code = TRAP_ILLTRAP;
406 sig = SIGTRAP;
407 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
408 (fp->seqstat & SEQSTAT_EXCAUSE));
409 CHK_DEBUGGER_TRAP();
410 break;
411 }
412
Bryan Wu1394f032007-05-06 14:50:22 -0700413 if (sig != 0 && sig != SIGTRAP) {
414 unsigned long stack;
415 dump_bfin_regs(fp, (void *)fp->retx);
416 dump_bfin_trace_buffer();
417 show_stack(current, &stack);
418 if (current->mm == NULL)
419 panic("Kernel exception");
420 }
Robin Getzce3afa12007-10-09 17:28:36 +0800421 info.si_signo = sig;
422 info.si_errno = 0;
423 info.si_addr = (void *)fp->pc;
424 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700425
426 /* if the address that we are about to return to is not valid, set it
427 * to a valid address, if we have a current application or panic
428 */
429 if (!(fp->pc <= physical_mem_end
430#if L1_CODE_LENGTH != 0
431 || (fp->pc >= L1_CODE_START &&
432 fp->pc <= (L1_CODE_START + L1_CODE_LENGTH))
433#endif
434 )) {
435 if (current->mm) {
436 fp->pc = current->mm->start_code;
437 } else {
Robin Getzc5d88d92007-06-21 11:34:16 +0800438 printk(KERN_EMERG
439 "I can't return to memory that doesn't exist"
440 " - bad things happen\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700441 panic("Help - I've fallen and can't get up\n");
442 }
443 }
444
445 trace_buffer_restore(j);
446 return;
447}
448
449/* Typical exception handling routines */
450
Robin Getz518039b2007-07-25 11:03:28 +0800451#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
452
Bryan Wu1394f032007-05-06 14:50:22 -0700453void dump_bfin_trace_buffer(void)
454{
Robin Getz518039b2007-07-25 11:03:28 +0800455#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
456 int tflags, i = 0;
457#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
458 int j, index;
459#endif
460
Bryan Wu1394f032007-05-06 14:50:22 -0700461 trace_buffer_save(tflags);
462
Robin Getz518039b2007-07-25 11:03:28 +0800463 printk(KERN_EMERG "Hardware Trace:\n");
464
Bryan Wu1394f032007-05-06 14:50:22 -0700465 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800466 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
467 printk(KERN_EMERG "%4i Target : ", i);
Bryan Wu1394f032007-05-06 14:50:22 -0700468 printk_address((unsigned long)bfin_read_TBUF());
Robin Getz518039b2007-07-25 11:03:28 +0800469 printk("\n" KERN_EMERG " Source : ");
Bryan Wu1394f032007-05-06 14:50:22 -0700470 printk_address((unsigned long)bfin_read_TBUF());
471 printk("\n");
472 }
473 }
474
Robin Getz518039b2007-07-25 11:03:28 +0800475#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
476 if (trace_buff_offset)
477 index = trace_buff_offset/4 - 1;
478 else
479 index = EXPAND_LEN;
480
481 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
482 while (j) {
483 printk(KERN_EMERG "%4i Target : ", i);
484 printk_address(software_trace_buff[index]);
485 index -= 1;
486 if (index < 0 )
487 index = EXPAND_LEN;
488 printk("\n" KERN_EMERG " Source : ");
489 printk_address(software_trace_buff[index]);
490 index -= 1;
491 if (index < 0)
492 index = EXPAND_LEN;
493 printk("\n");
494 j--;
495 i++;
496 }
497#endif
498
Bryan Wu1394f032007-05-06 14:50:22 -0700499 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800500#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700501}
502EXPORT_SYMBOL(dump_bfin_trace_buffer);
503
504static void show_trace(struct task_struct *tsk, unsigned long *sp)
505{
506 unsigned long addr;
507
508 printk("\nCall Trace:");
509#ifdef CONFIG_KALLSYMS
510 printk("\n");
511#endif
512
513 while (!kstack_end(sp)) {
514 addr = *sp++;
515 /*
516 * If the address is either in the text segment of the
517 * kernel, or in the region which contains vmalloc'ed
518 * memory, it *may* be the address of a calling
519 * routine; if so, print it so that someone tracing
520 * down the cause of the crash will be able to figure
521 * out the call path that was taken.
522 */
523 if (kernel_text_address(addr))
524 print_ip_sym(addr);
525 }
526
527 printk("\n");
528}
529
530void show_stack(struct task_struct *task, unsigned long *stack)
531{
532 unsigned long *endstack, addr;
533 int i;
534
535 /* Cannot call dump_bfin_trace_buffer() here as show_stack() is
536 * called externally in some places in the kernel.
537 */
538
539 if (!stack) {
540 if (task)
541 stack = (unsigned long *)task->thread.ksp;
542 else
543 stack = (unsigned long *)&stack;
544 }
545
546 addr = (unsigned long)stack;
547 endstack = (unsigned long *)PAGE_ALIGN(addr);
548
549 printk(KERN_EMERG "Stack from %08lx:", (unsigned long)stack);
550 for (i = 0; i < kstack_depth_to_print; i++) {
551 if (stack + 1 > endstack)
552 break;
553 if (i % 8 == 0)
554 printk("\n" KERN_EMERG " ");
555 printk(" %08lx", *stack++);
556 }
557
558 show_trace(task, stack);
559}
560
561void dump_stack(void)
562{
563 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800564#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700565 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800566#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700567 trace_buffer_save(tflags);
568 dump_bfin_trace_buffer();
569 show_stack(current, &stack);
570 trace_buffer_restore(tflags);
571}
572
573EXPORT_SYMBOL(dump_stack);
574
575void dump_bfin_regs(struct pt_regs *fp, void *retaddr)
576{
577 if (current->pid) {
Robin Getzc5d88d92007-06-21 11:34:16 +0800578 printk(KERN_EMERG "\n" KERN_EMERG "CURRENT PROCESS:\n"
579 KERN_EMERG "\n");
580 printk(KERN_EMERG "COMM=%s PID=%d\n",
581 current->comm, current->pid);
Bryan Wu1394f032007-05-06 14:50:22 -0700582 } else {
583 printk
Robin Getzc5d88d92007-06-21 11:34:16 +0800584 (KERN_EMERG "\n" KERN_EMERG
585 "No Valid pid - Either things are really messed up,"
586 " or you are in the kernel\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700587 }
588
589 if (current->mm) {
Robin Getzc5d88d92007-06-21 11:34:16 +0800590 printk(KERN_EMERG "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
Robin Getzda1f95b2007-06-25 18:05:53 +0800591 KERN_EMERG "BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
592 KERN_EMERG "\n",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800593 (void *)current->mm->start_code,
594 (void *)current->mm->end_code,
595 (void *)current->mm->start_data,
596 (void *)current->mm->end_data,
597 (void *)current->mm->end_data,
598 (void *)current->mm->brk,
599 (void *)current->mm->start_stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700600 }
601
Robin Getzc5d88d92007-06-21 11:34:16 +0800602 printk(KERN_EMERG "return address: [0x%p]; contents of:", retaddr);
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800603 if (retaddr != 0 && retaddr <= (void *)physical_mem_end
Bryan Wu1394f032007-05-06 14:50:22 -0700604#if L1_CODE_LENGTH != 0
605 /* FIXME: Copy the code out of L1 Instruction SRAM through dma
606 memcpy. */
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800607 && !(retaddr >= (void *)L1_CODE_START
608 && retaddr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
Bryan Wu1394f032007-05-06 14:50:22 -0700609#endif
610 ) {
Robin Getzc5d88d92007-06-21 11:34:16 +0800611 int i = ((unsigned int)retaddr & 0xFFFFFFF0) - 32;
Bryan Wu1394f032007-05-06 14:50:22 -0700612 unsigned short x = 0;
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800613 for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
614 if (!(i & 0xF))
Mike Frysingerb4055d72007-08-05 14:00:11 +0800615 printk("\n" KERN_EMERG "0x%08x: ", i);
Robin Getzc5d88d92007-06-21 11:34:16 +0800616
617 if (get_user(x, (unsigned short *)i))
Bryan Wu1394f032007-05-06 14:50:22 -0700618 break;
619#ifndef CONFIG_DEBUG_HWERR
620 /* If one of the last few instructions was a STI
Simon Arlottd2d50aa2007-06-11 15:31:30 +0800621 * it is likely that the error occured awhile ago
Bryan Wu1394f032007-05-06 14:50:22 -0700622 * and we just noticed
623 */
624 if (x >= 0x0040 && x <= 0x0047 && i <= 0)
Robin Getzc5d88d92007-06-21 11:34:16 +0800625 panic("\n\nWARNING : You should reconfigure"
626 " the kernel to turn on\n"
627 " 'Hardware error interrupt"
628 " debugging'\n"
629 " The rest of this error"
630 " is meanless\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700631#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800632 if (i == (unsigned int)retaddr)
Robin Getzc5d88d92007-06-21 11:34:16 +0800633 printk("[%04x]", x);
634 else
635 printk(" %04x ", x);
Bryan Wu1394f032007-05-06 14:50:22 -0700636 }
Robin Getzc5d88d92007-06-21 11:34:16 +0800637 printk("\n" KERN_EMERG "\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700638 } else
Robin Getzc5d88d92007-06-21 11:34:16 +0800639 printk(KERN_EMERG
640 "Cannot look at the [PC] for it is"
641 "in unreadable L1 SRAM - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700642
Bryan Wu1394f032007-05-06 14:50:22 -0700643
Robin Getzc5d88d92007-06-21 11:34:16 +0800644 printk(KERN_EMERG
645 "RETE: %08lx RETN: %08lx RETX: %08lx RETS: %08lx\n",
646 fp->rete, fp->retn, fp->retx, fp->rets);
647 printk(KERN_EMERG "IPEND: %04lx SYSCFG: %04lx\n",
648 fp->ipend, fp->syscfg);
649 printk(KERN_EMERG "SEQSTAT: %08lx SP: %08lx\n",
650 (long)fp->seqstat, (long)fp);
651 printk(KERN_EMERG "R0: %08lx R1: %08lx R2: %08lx R3: %08lx\n",
652 fp->r0, fp->r1, fp->r2, fp->r3);
653 printk(KERN_EMERG "R4: %08lx R5: %08lx R6: %08lx R7: %08lx\n",
654 fp->r4, fp->r5, fp->r6, fp->r7);
655 printk(KERN_EMERG "P0: %08lx P1: %08lx P2: %08lx P3: %08lx\n",
656 fp->p0, fp->p1, fp->p2, fp->p3);
657 printk(KERN_EMERG
658 "P4: %08lx P5: %08lx FP: %08lx\n",
659 fp->p4, fp->p5, fp->fp);
660 printk(KERN_EMERG
661 "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
662 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
Bryan Wu1394f032007-05-06 14:50:22 -0700663
Robin Getzc5d88d92007-06-21 11:34:16 +0800664 printk(KERN_EMERG "LB0: %08lx LT0: %08lx LC0: %08lx\n",
665 fp->lb0, fp->lt0, fp->lc0);
666 printk(KERN_EMERG "LB1: %08lx LT1: %08lx LC1: %08lx\n",
667 fp->lb1, fp->lt1, fp->lc1);
668 printk(KERN_EMERG "B0: %08lx L0: %08lx M0: %08lx I0: %08lx\n",
669 fp->b0, fp->l0, fp->m0, fp->i0);
670 printk(KERN_EMERG "B1: %08lx L1: %08lx M1: %08lx I1: %08lx\n",
671 fp->b1, fp->l1, fp->m1, fp->i1);
672 printk(KERN_EMERG "B2: %08lx L2: %08lx M2: %08lx I2: %08lx\n",
673 fp->b2, fp->l2, fp->m2, fp->i2);
674 printk(KERN_EMERG "B3: %08lx L3: %08lx M3: %08lx I3: %08lx\n",
675 fp->b3, fp->l3, fp->m3, fp->i3);
Bryan Wu1394f032007-05-06 14:50:22 -0700676
Robin Getzc5d88d92007-06-21 11:34:16 +0800677 printk(KERN_EMERG "\n" KERN_EMERG "USP: %08lx ASTAT: %08lx\n",
678 rdusp(), fp->astat);
Bryan Wu1394f032007-05-06 14:50:22 -0700679 if ((long)fp->seqstat & SEQSTAT_EXCAUSE) {
Robin Getzc5d88d92007-06-21 11:34:16 +0800680 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n",
681 (void *)bfin_read_DCPLB_FAULT_ADDR());
682 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n",
683 (void *)bfin_read_ICPLB_FAULT_ADDR());
Bryan Wu1394f032007-05-06 14:50:22 -0700684 }
685
686 printk("\n\n");
687}
688
689#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
690asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
691#endif
692
693asmlinkage int sys_bfin_spinlock(int *spinlock)
694{
695 int ret = 0;
696 int tmp = 0;
697
698 local_irq_disable();
699 ret = get_user(tmp, spinlock);
700 if (ret == 0) {
701 if (tmp)
702 ret = 1;
703 tmp = 1;
704 put_user(tmp, spinlock);
705 }
706 local_irq_enable();
707 return ret;
708}
709
Mike Frysinger1ffe6642007-08-05 17:14:04 +0800710int bfin_request_exception(unsigned int exception, void (*handler)(void))
711{
712 void (*curr_handler)(void);
713
714 if (exception > 0x3F)
715 return -EINVAL;
716
717 curr_handler = ex_table[exception];
718
719 if (curr_handler != ex_replaceable)
720 return -EBUSY;
721
722 ex_table[exception] = handler;
723
724 return 0;
725}
726EXPORT_SYMBOL(bfin_request_exception);
727
728int bfin_free_exception(unsigned int exception, void (*handler)(void))
729{
730 void (*curr_handler)(void);
731
732 if (exception > 0x3F)
733 return -EINVAL;
734
735 curr_handler = ex_table[exception];
736
737 if (curr_handler != handler)
738 return -EBUSY;
739
740 ex_table[exception] = ex_replaceable;
741
742 return 0;
743}
744EXPORT_SYMBOL(bfin_free_exception);
745
Bryan Wu1394f032007-05-06 14:50:22 -0700746void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
747{
748 switch (cplb_panic) {
749 case CPLB_NO_UNLOCKED:
750 printk(KERN_EMERG "All CPLBs are locked\n");
751 break;
752 case CPLB_PROT_VIOL:
753 return;
754 case CPLB_NO_ADDR_MATCH:
755 return;
756 case CPLB_UNKNOWN_ERR:
757 printk(KERN_EMERG "Unknown CPLB Exception\n");
758 break;
759 }
760
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800761 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR());
762 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR());
Bryan Wu1394f032007-05-06 14:50:22 -0700763 dump_bfin_regs(fp, (void *)fp->retx);
764 dump_stack();
765 panic("Unrecoverable event\n");
766}