blob: 8bbfef31666b3ed47f8c2f5098063d565292ba06 [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>
Robin Getzd8f66c82007-12-24 15:27:56 +080039#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080040#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080041#include <asm/fixed_code.h>
Bryan Wu1394f032007-05-06 14:50:22 -070042
43#ifdef CONFIG_KGDB
44# include <linux/debugger.h>
45# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080046
47# define CHK_DEBUGGER_TRAP() \
48 do { \
49 CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \
50 } while (0)
51# define CHK_DEBUGGER_TRAP_MAYBE() \
52 do { \
53 if (kgdb_connected) \
54 CHK_DEBUGGER_TRAP(); \
55 } while (0)
56#else
57# define CHK_DEBUGGER_TRAP() do { } while (0)
58# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070059#endif
60
61/* Initiate the event table handler */
62void __init trap_init(void)
63{
64 CSYNC();
65 bfin_write_EVT3(trap);
66 CSYNC();
67}
68
Bryan Wu1394f032007-05-06 14:50:22 -070069int kstack_depth_to_print = 48;
70
Robin Getz226eb1e2007-10-29 17:59:07 +080071static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070072{
73 struct vm_list_struct *vml;
74 struct task_struct *p;
75 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080076 unsigned long flags, offset;
77 unsigned int in_exception = bfin_read_IPEND() & 0x10;
Bryan Wu1394f032007-05-06 14:50:22 -070078
79#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080080 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070081 const char *symname;
82 char *modname;
83 char *delim = ":";
84 char namebuf[128];
85
86 /* look up the address and see if we are in kernel space */
87 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
88
89 if (symname) {
90 /* yeah! kernel space! */
91 if (!modname)
92 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +080093 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080094 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -070095 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +080096 return;
Bryan Wu1394f032007-05-06 14:50:22 -070097
98 }
99#endif
100
Robin Getz226eb1e2007-10-29 17:59:07 +0800101 /* Problem in fixed code section? */
102 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
103 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
104 return;
105 }
106
107 /* Problem somewhere before the kernel start address */
108 if (address < CONFIG_BOOT_LOAD) {
109 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
110 return;
111 }
112
Bryan Wu1394f032007-05-06 14:50:22 -0700113 /* looks like we're off in user-land, so let's walk all the
114 * mappings of all our processes and see if we can't be a whee
115 * bit more specific
116 */
Robin Getz885be032007-10-29 17:20:41 +0800117 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700118 for_each_process(p) {
Robin Getz885be032007-10-29 17:20:41 +0800119 mm = (in_exception ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700120 if (!mm)
121 continue;
122
123 vml = mm->context.vmlist;
124 while (vml) {
125 struct vm_area_struct *vma = vml->vma;
126
127 if (address >= vma->vm_start && address < vma->vm_end) {
128 char *name = p->comm;
129 struct file *file = vma->vm_file;
130 if (file) {
131 char _tmpbuf[256];
132 name = d_path(file->f_dentry,
133 file->f_vfsmnt,
134 _tmpbuf,
135 sizeof(_tmpbuf));
136 }
137
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800138 /* FLAT does not have its text aligned to the start of
139 * the map while FDPIC ELF does ...
140 */
141 if (current->mm &&
142 (address > current->mm->start_code) &&
143 (address < current->mm->end_code))
144 offset = address - current->mm->start_code;
145 else
146 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
147
Robin Getz226eb1e2007-10-29 17:59:07 +0800148 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
Robin Getz885be032007-10-29 17:20:41 +0800149 (void *)address, name, offset);
150 if (!in_exception)
151 mmput(mm);
152 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700153 }
154
155 vml = vml->next;
156 }
Robin Getz885be032007-10-29 17:20:41 +0800157 if (!in_exception)
158 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700159 }
Bryan Wu1394f032007-05-06 14:50:22 -0700160
161 /* we were unable to find this address anywhere */
Robin Getz4a589e12007-11-12 22:46:46 +0800162 sprintf(buf, "<0x%p> /* unknown address */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800163
164done:
165 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700166}
167
Robin Getz2ebcade2007-10-09 17:24:30 +0800168asmlinkage void double_fault_c(struct pt_regs *fp)
169{
Robin Getz226eb1e2007-10-29 17:59:07 +0800170 console_verbose();
171 oops_in_progress = 1;
Robin Getz2ebcade2007-10-09 17:24:30 +0800172 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800173 dump_bfin_process(fp);
174 dump_bfin_mem((void *)fp->retx);
175 show_regs(fp);
Robin Getz2ebcade2007-10-09 17:24:30 +0800176 panic("Double Fault - unrecoverable event\n");
177
178}
179
Bryan Wu1394f032007-05-06 14:50:22 -0700180asmlinkage void trap_c(struct pt_regs *fp)
181{
Robin Getz518039b2007-07-25 11:03:28 +0800182#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
183 int j;
184#endif
185 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700186 siginfo_t info;
187 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
188
Bryan Wu1394f032007-05-06 14:50:22 -0700189 trace_buffer_save(j);
190
Robin Getz226eb1e2007-10-29 17:59:07 +0800191 /* Important - be very careful dereferncing pointers - will lead to
192 * double faults if the stack has become corrupt
193 */
194
195 /* If the fault was caused by a kernel thread, or interrupt handler
196 * we will kernel panic, so the system reboots.
197 * If KGDB is enabled, don't set this for kernel breakpoints
198 */
199 if ((bfin_read_IPEND() & 0xFFC0)
200#ifdef CONFIG_KGDB
201 && trapnr != VEC_EXCPT02
202#endif
203 ){
204 console_verbose();
205 oops_in_progress = 1;
206 } else if (current) {
207 if (current->mm == NULL) {
208 console_verbose();
209 oops_in_progress = 1;
210 }
211 }
212
Bryan Wu1394f032007-05-06 14:50:22 -0700213 /* trap_c() will be called for exceptions. During exceptions
214 * processing, the pc value should be set with retx value.
215 * With this change we can cleanup some code in signal.c- TODO
216 */
217 fp->orig_pc = fp->retx;
218 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
219 trapnr, fp->ipend, fp->pc, fp->retx); */
220
221 /* send the appropriate signal to the user program */
222 switch (trapnr) {
223
224 /* This table works in conjuction with the one in ./mach-common/entry.S
225 * Some exceptions are handled there (in assembly, in exception space)
226 * Some are handled here, (in C, in interrupt space)
227 * Some, like CPLB, are handled in both, where the normal path is
228 * handled in assembly/exception space, and the error path is handled
229 * here
230 */
231
232 /* 0x00 - Linux Syscall, getting here is an error */
233 /* 0x01 - userspace gdb breakpoint, handled here */
234 case VEC_EXCPT01:
235 info.si_code = TRAP_ILLTRAP;
236 sig = SIGTRAP;
237 CHK_DEBUGGER_TRAP_MAYBE();
238 /* Check if this is a breakpoint in kernel space */
239 if (fp->ipend & 0xffc0)
240 return;
241 else
242 break;
243#ifdef CONFIG_KGDB
244 case VEC_EXCPT02 : /* gdb connection */
245 info.si_code = TRAP_ILLTRAP;
246 sig = SIGTRAP;
247 CHK_DEBUGGER_TRAP();
248 return;
249#else
250 /* 0x02 - User Defined, Caught by default */
251#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800252 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700253 case VEC_EXCPT03:
254 info.si_code = SEGV_STACKFLOW;
255 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800256 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700257 CHK_DEBUGGER_TRAP();
258 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800259 /* 0x04 - User Defined, Caught by default */
Bryan Wu1394f032007-05-06 14:50:22 -0700260 /* 0x05 - User Defined, Caught by default */
261 /* 0x06 - User Defined, Caught by default */
262 /* 0x07 - User Defined, Caught by default */
263 /* 0x08 - User Defined, Caught by default */
264 /* 0x09 - User Defined, Caught by default */
265 /* 0x0A - User Defined, Caught by default */
266 /* 0x0B - User Defined, Caught by default */
267 /* 0x0C - User Defined, Caught by default */
268 /* 0x0D - User Defined, Caught by default */
269 /* 0x0E - User Defined, Caught by default */
270 /* 0x0F - User Defined, Caught by default */
271 /* 0x10 HW Single step, handled here */
272 case VEC_STEP:
273 info.si_code = TRAP_STEP;
274 sig = SIGTRAP;
275 CHK_DEBUGGER_TRAP_MAYBE();
276 /* Check if this is a single step in kernel space */
277 if (fp->ipend & 0xffc0)
278 return;
279 else
280 break;
281 /* 0x11 - Trace Buffer Full, handled here */
282 case VEC_OVFLOW:
283 info.si_code = TRAP_TRACEFLOW;
284 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800285 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700286 CHK_DEBUGGER_TRAP();
287 break;
288 /* 0x12 - Reserved, Caught by default */
289 /* 0x13 - Reserved, Caught by default */
290 /* 0x14 - Reserved, Caught by default */
291 /* 0x15 - Reserved, Caught by default */
292 /* 0x16 - Reserved, Caught by default */
293 /* 0x17 - Reserved, Caught by default */
294 /* 0x18 - Reserved, Caught by default */
295 /* 0x19 - Reserved, Caught by default */
296 /* 0x1A - Reserved, Caught by default */
297 /* 0x1B - Reserved, Caught by default */
298 /* 0x1C - Reserved, Caught by default */
299 /* 0x1D - Reserved, Caught by default */
300 /* 0x1E - Reserved, Caught by default */
301 /* 0x1F - Reserved, Caught by default */
302 /* 0x20 - Reserved, Caught by default */
303 /* 0x21 - Undefined Instruction, handled here */
304 case VEC_UNDEF_I:
305 info.si_code = ILL_ILLOPC;
306 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800307 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700308 CHK_DEBUGGER_TRAP();
309 break;
310 /* 0x22 - Illegal Instruction Combination, handled here */
311 case VEC_ILGAL_I:
312 info.si_code = ILL_ILLPARAOP;
313 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800314 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700315 CHK_DEBUGGER_TRAP();
316 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800317 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700318 case VEC_CPLB_VL:
319 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800320 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800321 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700322 CHK_DEBUGGER_TRAP();
323 break;
324 /* 0x24 - Data access misaligned, handled here */
325 case VEC_MISALI_D:
326 info.si_code = BUS_ADRALN;
327 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800328 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700329 CHK_DEBUGGER_TRAP();
330 break;
331 /* 0x25 - Unrecoverable Event, handled here */
332 case VEC_UNCOV:
333 info.si_code = ILL_ILLEXCPT;
334 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800335 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700336 CHK_DEBUGGER_TRAP();
337 break;
338 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
339 error case is handled here */
340 case VEC_CPLB_M:
341 info.si_code = BUS_ADRALN;
342 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800343 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700344 CHK_DEBUGGER_TRAP();
345 break;
346 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
347 case VEC_CPLB_MHIT:
348 info.si_code = ILL_CPLB_MULHIT;
349#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
350 sig = SIGSEGV;
Robin Getz226eb1e2007-10-29 17:59:07 +0800351 printk(KERN_NOTICE "NULL pointer access (probably)\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700352#else
353 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800354 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700355#endif
356 CHK_DEBUGGER_TRAP();
357 break;
358 /* 0x28 - Emulation Watchpoint, handled here */
359 case VEC_WATCH:
360 info.si_code = TRAP_WATCHPT;
361 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800362 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700363 CHK_DEBUGGER_TRAP_MAYBE();
364 /* Check if this is a watchpoint in kernel space */
365 if (fp->ipend & 0xffc0)
366 return;
367 else
368 break;
369#ifdef CONFIG_BF535
370 /* 0x29 - Instruction fetch access error (535 only) */
371 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
372 info.si_code = BUS_OPFETCH;
373 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800374 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700375 CHK_DEBUGGER_TRAP();
376 break;
377#else
378 /* 0x29 - Reserved, Caught by default */
379#endif
380 /* 0x2A - Instruction fetch misaligned, handled here */
381 case VEC_MISALI_I:
382 info.si_code = BUS_ADRALN;
383 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800384 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700385 CHK_DEBUGGER_TRAP();
386 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800387 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700388 case VEC_CPLB_I_VL:
389 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800390 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800391 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700392 CHK_DEBUGGER_TRAP();
393 break;
394 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
395 case VEC_CPLB_I_M:
396 info.si_code = ILL_CPLB_MISS;
397 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800398 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700399 CHK_DEBUGGER_TRAP();
400 break;
401 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
402 case VEC_CPLB_I_MHIT:
403 info.si_code = ILL_CPLB_MULHIT;
404#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
405 sig = SIGSEGV;
Robin Getz226eb1e2007-10-29 17:59:07 +0800406 printk(KERN_NOTICE "Jump to address 0 - 0x0fff\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700407#else
408 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800409 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700410#endif
411 CHK_DEBUGGER_TRAP();
412 break;
413 /* 0x2E - Illegal use of Supervisor Resource, handled here */
414 case VEC_ILL_RES:
415 info.si_code = ILL_PRVOPC;
416 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800417 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700418 CHK_DEBUGGER_TRAP();
419 break;
420 /* 0x2F - Reserved, Caught by default */
421 /* 0x30 - Reserved, Caught by default */
422 /* 0x31 - Reserved, Caught by default */
423 /* 0x32 - Reserved, Caught by default */
424 /* 0x33 - Reserved, Caught by default */
425 /* 0x34 - Reserved, Caught by default */
426 /* 0x35 - Reserved, Caught by default */
427 /* 0x36 - Reserved, Caught by default */
428 /* 0x37 - Reserved, Caught by default */
429 /* 0x38 - Reserved, Caught by default */
430 /* 0x39 - Reserved, Caught by default */
431 /* 0x3A - Reserved, Caught by default */
432 /* 0x3B - Reserved, Caught by default */
433 /* 0x3C - Reserved, Caught by default */
434 /* 0x3D - Reserved, Caught by default */
435 /* 0x3E - Reserved, Caught by default */
436 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800437 case VEC_HWERR:
438 info.si_code = BUS_ADRALN;
439 sig = SIGBUS;
440 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
441 /* System MMR Error */
442 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
443 info.si_code = BUS_ADRALN;
444 sig = SIGBUS;
445 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
446 break;
447 /* External Memory Addressing Error */
448 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
449 info.si_code = BUS_ADRERR;
450 sig = SIGBUS;
451 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
452 break;
453 /* Performance Monitor Overflow */
454 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
455 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
456 break;
457 /* RAISE 5 instruction */
458 case (SEQSTAT_HWERRCAUSE_RAISE_5):
459 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
460 break;
461 default: /* Reserved */
462 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
463 break;
464 }
465 CHK_DEBUGGER_TRAP();
466 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700467 default:
468 info.si_code = TRAP_ILLTRAP;
469 sig = SIGTRAP;
470 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
471 (fp->seqstat & SEQSTAT_EXCAUSE));
472 CHK_DEBUGGER_TRAP();
473 break;
474 }
475
Robin Getz226eb1e2007-10-29 17:59:07 +0800476 BUG_ON(sig == 0);
477
478 if (sig != SIGTRAP) {
Bryan Wu1394f032007-05-06 14:50:22 -0700479 unsigned long stack;
Mike Frysinger49dce912007-11-21 16:46:49 +0800480 dump_bfin_process(fp);
Robin Getz13fe24f2008-01-27 15:38:56 +0800481 /* Is it an interrupt, or an exception? */
482 if (trapnr == VEC_HWERR)
483 dump_bfin_mem((void *)fp->pc);
484 else
485 dump_bfin_mem((void *)fp->retx);
Mike Frysinger49dce912007-11-21 16:46:49 +0800486 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800487
488 /* Print out the trace buffer if it makes sense */
489#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
490 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
491 printk(KERN_NOTICE "No trace since you do not have "
492 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
493 KERN_NOTICE "\n");
494 else
495#endif
496 dump_bfin_trace_buffer();
Bryan Wu1394f032007-05-06 14:50:22 -0700497 show_stack(current, &stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800498 if (oops_in_progress) {
499#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800500 printk(KERN_EMERG "Please turn on "
501 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800502#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700503 panic("Kernel exception");
Robin Getz226eb1e2007-10-29 17:59:07 +0800504 }
Bryan Wu1394f032007-05-06 14:50:22 -0700505 }
Robin Getzfb322912007-11-21 16:38:05 +0800506
Robin Getzce3afa12007-10-09 17:28:36 +0800507 info.si_signo = sig;
508 info.si_errno = 0;
509 info.si_addr = (void *)fp->pc;
510 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700511
Bryan Wu1394f032007-05-06 14:50:22 -0700512 trace_buffer_restore(j);
513 return;
514}
515
516/* Typical exception handling routines */
517
Robin Getz518039b2007-07-25 11:03:28 +0800518#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
519
Bryan Wu1394f032007-05-06 14:50:22 -0700520void dump_bfin_trace_buffer(void)
521{
Robin Getz518039b2007-07-25 11:03:28 +0800522#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
523 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800524 char buf[150];
Robin Getz518039b2007-07-25 11:03:28 +0800525#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
526 int j, index;
527#endif
528
Bryan Wu1394f032007-05-06 14:50:22 -0700529 trace_buffer_save(tflags);
530
Robin Getz226eb1e2007-10-29 17:59:07 +0800531 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800532
Bryan Wu1394f032007-05-06 14:50:22 -0700533 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800534 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800535 decode_address(buf, (unsigned long)bfin_read_TBUF());
536 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
537 decode_address(buf, (unsigned long)bfin_read_TBUF());
538 printk(KERN_NOTICE " Source : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700539 }
540 }
541
Robin Getz518039b2007-07-25 11:03:28 +0800542#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
543 if (trace_buff_offset)
544 index = trace_buff_offset/4 - 1;
545 else
546 index = EXPAND_LEN;
547
548 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
549 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800550 decode_address(buf, software_trace_buff[index]);
551 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800552 index -= 1;
553 if (index < 0 )
554 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800555 decode_address(buf, software_trace_buff[index]);
556 printk(KERN_NOTICE " Source : %s\n", buf);
Robin Getz518039b2007-07-25 11:03:28 +0800557 index -= 1;
558 if (index < 0)
559 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800560 j--;
561 i++;
562 }
563#endif
564
Bryan Wu1394f032007-05-06 14:50:22 -0700565 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800566#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700567}
568EXPORT_SYMBOL(dump_bfin_trace_buffer);
569
570static void show_trace(struct task_struct *tsk, unsigned long *sp)
571{
572 unsigned long addr;
573
Robin Getz226eb1e2007-10-29 17:59:07 +0800574 printk(KERN_NOTICE "\n" KERN_NOTICE "Call Trace:\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700575
576 while (!kstack_end(sp)) {
577 addr = *sp++;
578 /*
579 * If the address is either in the text segment of the
580 * kernel, or in the region which contains vmalloc'ed
581 * memory, it *may* be the address of a calling
582 * routine; if so, print it so that someone tracing
583 * down the cause of the crash will be able to figure
584 * out the call path that was taken.
585 */
586 if (kernel_text_address(addr))
587 print_ip_sym(addr);
588 }
589
Robin Getz226eb1e2007-10-29 17:59:07 +0800590 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700591}
592
593void show_stack(struct task_struct *task, unsigned long *stack)
594{
595 unsigned long *endstack, addr;
596 int i;
597
598 /* Cannot call dump_bfin_trace_buffer() here as show_stack() is
599 * called externally in some places in the kernel.
600 */
601
602 if (!stack) {
603 if (task)
604 stack = (unsigned long *)task->thread.ksp;
605 else
606 stack = (unsigned long *)&stack;
607 }
608
609 addr = (unsigned long)stack;
610 endstack = (unsigned long *)PAGE_ALIGN(addr);
611
Robin Getz226eb1e2007-10-29 17:59:07 +0800612 printk(KERN_NOTICE "Stack from %08lx:", (unsigned long)stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700613 for (i = 0; i < kstack_depth_to_print; i++) {
614 if (stack + 1 > endstack)
615 break;
616 if (i % 8 == 0)
Robin Getz226eb1e2007-10-29 17:59:07 +0800617 printk("\n" KERN_NOTICE " ");
Bryan Wu1394f032007-05-06 14:50:22 -0700618 printk(" %08lx", *stack++);
619 }
Robin Getz226eb1e2007-10-29 17:59:07 +0800620 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700621
622 show_trace(task, stack);
623}
624
625void dump_stack(void)
626{
627 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800628#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700629 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800630#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700631 trace_buffer_save(tflags);
632 dump_bfin_trace_buffer();
633 show_stack(current, &stack);
634 trace_buffer_restore(tflags);
635}
Bryan Wu1394f032007-05-06 14:50:22 -0700636EXPORT_SYMBOL(dump_stack);
637
Mike Frysinger49dce912007-11-21 16:46:49 +0800638void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700639{
Mike Frysinger49dce912007-11-21 16:46:49 +0800640 /* We should be able to look at fp->ipend, but we don't push it on the
641 * stack all the time, so do this until we fix that */
642 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800643
Mike Frysinger49dce912007-11-21 16:46:49 +0800644 if (oops_in_progress)
645 printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800646
Mike Frysinger49dce912007-11-21 16:46:49 +0800647 if (context & 0x0020)
648 printk(KERN_NOTICE "Deferred excecption or HW Error context\n");
649 else if (context & 0x3FC0)
650 printk(KERN_NOTICE "Interrupt context\n");
651 else if (context & 0x4000)
652 printk(KERN_NOTICE "Deferred Interrupt context\n");
653 else if (context & 0x8000)
654 printk(KERN_NOTICE "Kernel process context\n");
655
656 if (current->pid && current->mm) {
657 printk(KERN_NOTICE "CURRENT PROCESS:\n");
658 printk(KERN_NOTICE "COMM=%s PID=%d\n",
659 current->comm, current->pid);
660
661 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
662 KERN_NOTICE "BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
663 KERN_NOTICE "\n",
664 (void *)current->mm->start_code,
665 (void *)current->mm->end_code,
666 (void *)current->mm->start_data,
667 (void *)current->mm->end_data,
668 (void *)current->mm->end_data,
669 (void *)current->mm->brk,
670 (void *)current->mm->start_stack);
671 } else
672 printk(KERN_NOTICE "\n" KERN_NOTICE
673 "No Valid process in current context\n");
674}
675
676void dump_bfin_mem(void *retaddr)
677{
Bryan Wu1394f032007-05-06 14:50:22 -0700678
Robin Getz226eb1e2007-10-29 17:59:07 +0800679 if (retaddr >= (void *)FIXED_CODE_START && retaddr < (void *)physical_mem_end
Bryan Wu1394f032007-05-06 14:50:22 -0700680#if L1_CODE_LENGTH != 0
681 /* FIXME: Copy the code out of L1 Instruction SRAM through dma
682 memcpy. */
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800683 && !(retaddr >= (void *)L1_CODE_START
684 && retaddr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
Bryan Wu1394f032007-05-06 14:50:22 -0700685#endif
686 ) {
Robin Getzc5d88d92007-06-21 11:34:16 +0800687 int i = ((unsigned int)retaddr & 0xFFFFFFF0) - 32;
Bryan Wu1394f032007-05-06 14:50:22 -0700688 unsigned short x = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800689 printk(KERN_NOTICE "return address: [0x%p]; contents of:", retaddr);
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800690 for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
691 if (!(i & 0xF))
Robin Getz226eb1e2007-10-29 17:59:07 +0800692 printk("\n" KERN_NOTICE "0x%08x: ", i);
Robin Getzc5d88d92007-06-21 11:34:16 +0800693
694 if (get_user(x, (unsigned short *)i))
Bryan Wu1394f032007-05-06 14:50:22 -0700695 break;
696#ifndef CONFIG_DEBUG_HWERR
697 /* If one of the last few instructions was a STI
Simon Arlottd2d50aa2007-06-11 15:31:30 +0800698 * it is likely that the error occured awhile ago
Robin Getz226eb1e2007-10-29 17:59:07 +0800699 * and we just noticed. This only happens in kernel
700 * context, which should mean an oops is happening
Bryan Wu1394f032007-05-06 14:50:22 -0700701 */
Robin Getz226eb1e2007-10-29 17:59:07 +0800702 if (oops_in_progress && x >= 0x0040 && x <= 0x0047 && i <= 0)
Robin Getz13fe24f2008-01-27 15:38:56 +0800703 printk(KERN_EMERG "\n"
704 KERN_EMERG "WARNING : You should reconfigure"
Robin Getzc5d88d92007-06-21 11:34:16 +0800705 " the kernel to turn on\n"
Robin Getz13fe24f2008-01-27 15:38:56 +0800706 KERN_EMERG " 'Hardware error interrupt debugging'\n"
707 KERN_EMERG " The rest of this error is meanless\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700708#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800709 if (i == (unsigned int)retaddr)
Robin Getzc5d88d92007-06-21 11:34:16 +0800710 printk("[%04x]", x);
711 else
712 printk(" %04x ", x);
Bryan Wu1394f032007-05-06 14:50:22 -0700713 }
Robin Getz226eb1e2007-10-29 17:59:07 +0800714 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700715 } else
Robin Getz226eb1e2007-10-29 17:59:07 +0800716 printk("\n" KERN_NOTICE
Robin Getz6a3f0b42007-11-15 15:10:48 +0800717 "Cannot look at the [PC] <%p> for it is"
718 " in unreadable memory - sorry\n", retaddr);
Mike Frysinger49dce912007-11-21 16:46:49 +0800719}
720
721void show_regs(struct pt_regs *fp)
722{
723 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +0800724 struct irqaction *action;
725 unsigned int i;
726 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700727
Robin Getz226eb1e2007-10-29 17:59:07 +0800728 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\n");
729 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
730 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz13fe24f2008-01-27 15:38:56 +0800731 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
732 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
733 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
734 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getzd8f66c82007-12-24 15:27:56 +0800735 for (i = 6; i <= 15 ; i++) {
736 if (fp->ipend & (1 << i)) {
737 decode_address(buf, bfin_read32(EVT0 + 4*i));
738 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
739 }
740 }
741
742 /* if no interrupts are going off, don't print this out */
743 if (fp->ipend & ~0x3F) {
744 for (i = 0; i < (NR_IRQS - 1); i++) {
745 spin_lock_irqsave(&irq_desc[i].lock, flags);
746 action = irq_desc[i].action;
747 if (!action)
748 goto unlock;
749
750 decode_address(buf, (unsigned int)action->handler);
751 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
752 for (action = action->next; action; action = action->next) {
753 decode_address(buf, (unsigned int)action->handler);
754 printk(", %s", buf);
755 }
756 printk("\n");
757unlock:
758 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
759 }
760 }
Bryan Wu1394f032007-05-06 14:50:22 -0700761
Robin Getz226eb1e2007-10-29 17:59:07 +0800762 decode_address(buf, fp->rete);
763 printk(KERN_NOTICE " RETE: %s\n", buf);
764 decode_address(buf, fp->retn);
765 printk(KERN_NOTICE " RETN: %s\n", buf);
766 decode_address(buf, fp->retx);
767 printk(KERN_NOTICE " RETX: %s\n", buf);
768 decode_address(buf, fp->rets);
769 printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +0800770 decode_address(buf, fp->pc);
Robin Getz13fe24f2008-01-27 15:38:56 +0800771 printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700772
Robin Getz13fe24f2008-01-27 15:38:56 +0800773 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
774 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800775 decode_address(buf, bfin_read_DCPLB_FAULT_ADDR());
776 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
777 decode_address(buf, bfin_read_ICPLB_FAULT_ADDR());
778 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700779 }
780
Robin Getz226eb1e2007-10-29 17:59:07 +0800781 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
782 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
783 fp->r0, fp->r1, fp->r2, fp->r3);
784 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
785 fp->r4, fp->r5, fp->r6, fp->r7);
786 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
787 fp->p0, fp->p1, fp->p2, fp->p3);
788 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
789 fp->p4, fp->p5, fp->fp, (long)fp);
790 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
791 fp->lb0, fp->lt0, fp->lc0);
792 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
793 fp->lb1, fp->lt1, fp->lc1);
794 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
795 fp->b0, fp->l0, fp->m0, fp->i0);
796 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
797 fp->b1, fp->l1, fp->m1, fp->i1);
798 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
799 fp->b2, fp->l2, fp->m2, fp->i2);
800 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
801 fp->b3, fp->l3, fp->m3, fp->i3);
802 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
803 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
804
805 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
806 rdusp(), fp->astat);
807
808 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700809}
810
811#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
812asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
813#endif
814
815asmlinkage int sys_bfin_spinlock(int *spinlock)
816{
817 int ret = 0;
818 int tmp = 0;
819
820 local_irq_disable();
821 ret = get_user(tmp, spinlock);
822 if (ret == 0) {
823 if (tmp)
824 ret = 1;
825 tmp = 1;
826 put_user(tmp, spinlock);
827 }
828 local_irq_enable();
829 return ret;
830}
831
Mike Frysinger1ffe6642007-08-05 17:14:04 +0800832int bfin_request_exception(unsigned int exception, void (*handler)(void))
833{
834 void (*curr_handler)(void);
835
836 if (exception > 0x3F)
837 return -EINVAL;
838
839 curr_handler = ex_table[exception];
840
841 if (curr_handler != ex_replaceable)
842 return -EBUSY;
843
844 ex_table[exception] = handler;
845
846 return 0;
847}
848EXPORT_SYMBOL(bfin_request_exception);
849
850int bfin_free_exception(unsigned int exception, void (*handler)(void))
851{
852 void (*curr_handler)(void);
853
854 if (exception > 0x3F)
855 return -EINVAL;
856
857 curr_handler = ex_table[exception];
858
859 if (curr_handler != handler)
860 return -EBUSY;
861
862 ex_table[exception] = ex_replaceable;
863
864 return 0;
865}
866EXPORT_SYMBOL(bfin_free_exception);
867
Bryan Wu1394f032007-05-06 14:50:22 -0700868void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
869{
870 switch (cplb_panic) {
871 case CPLB_NO_UNLOCKED:
872 printk(KERN_EMERG "All CPLBs are locked\n");
873 break;
874 case CPLB_PROT_VIOL:
875 return;
876 case CPLB_NO_ADDR_MATCH:
877 return;
878 case CPLB_UNKNOWN_ERR:
879 printk(KERN_EMERG "Unknown CPLB Exception\n");
880 break;
881 }
882
Robin Getz226eb1e2007-10-29 17:59:07 +0800883 oops_in_progress = 1;
884
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800885 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR());
886 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR());
Mike Frysinger49dce912007-11-21 16:46:49 +0800887 dump_bfin_process(fp);
888 dump_bfin_mem((void *)fp->retx);
889 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -0700890 dump_stack();
891 panic("Unrecoverable event\n");
892}