blob: fd24e04fc19ed2f886db0f97983c555413320d56 [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>
Mike Frysingerf4585a02008-10-13 14:45:21 +080037#include <asm/cplb.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080038#include <asm/blackfin.h>
39#include <asm/irq_handler.h>
Robin Getzd8f66c82007-12-24 15:27:56 +080040#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080041#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080042#include <asm/fixed_code.h>
Robin Getzb03b08b2007-12-23 22:57:01 +080043#include <asm/dma.h>
Bryan Wu1394f032007-05-06 14:50:22 -070044
45#ifdef CONFIG_KGDB
46# include <linux/debugger.h>
47# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080048
49# define CHK_DEBUGGER_TRAP() \
50 do { \
51 CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \
52 } while (0)
53# define CHK_DEBUGGER_TRAP_MAYBE() \
54 do { \
55 if (kgdb_connected) \
56 CHK_DEBUGGER_TRAP(); \
57 } while (0)
58#else
59# define CHK_DEBUGGER_TRAP() do { } while (0)
60# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070061#endif
62
63/* Initiate the event table handler */
64void __init trap_init(void)
65{
66 CSYNC();
67 bfin_write_EVT3(trap);
68 CSYNC();
69}
70
Mike Frysingerbd628bd2008-06-03 12:23:45 +080071unsigned long saved_icplb_fault_addr, saved_dcplb_fault_addr;
Bernd Schmidt5d750b92008-04-25 05:02:33 +080072
Robin Getz226eb1e2007-10-29 17:59:07 +080073static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070074{
75 struct vm_list_struct *vml;
76 struct task_struct *p;
77 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080078 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080079 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -070080
81#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080082 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070083 const char *symname;
84 char *modname;
85 char *delim = ":";
86 char namebuf[128];
87
88 /* look up the address and see if we are in kernel space */
89 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
90
91 if (symname) {
92 /* yeah! kernel space! */
93 if (!modname)
94 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +080095 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080096 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -070097 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +080098 return;
Bryan Wu1394f032007-05-06 14:50:22 -070099
100 }
101#endif
102
Robin Getz226eb1e2007-10-29 17:59:07 +0800103 /* Problem in fixed code section? */
104 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
105 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
106 return;
107 }
108
109 /* Problem somewhere before the kernel start address */
110 if (address < CONFIG_BOOT_LOAD) {
111 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
112 return;
113 }
114
Bryan Wu1394f032007-05-06 14:50:22 -0700115 /* looks like we're off in user-land, so let's walk all the
116 * mappings of all our processes and see if we can't be a whee
117 * bit more specific
118 */
Robin Getz885be032007-10-29 17:20:41 +0800119 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700120 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800121 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700122 if (!mm)
123 continue;
124
125 vml = mm->context.vmlist;
126 while (vml) {
127 struct vm_area_struct *vma = vml->vma;
128
129 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800130 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700131 char *name = p->comm;
132 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800133
134 if (file)
135 name = d_path(&file->f_path, _tmpbuf,
136 sizeof(_tmpbuf));
Bryan Wu1394f032007-05-06 14:50:22 -0700137
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 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800141
Robin Getz7f1c9062008-04-25 03:36:31 +0800142 /* before we can check flat/fdpic, we need to
143 * make sure current is valid
144 */
145 if ((unsigned long)current >= FIXED_CODE_START &&
146 !((unsigned long)current & 0x3)) {
147 if (current->mm &&
148 (address > current->mm->start_code) &&
149 (address < current->mm->end_code))
150 offset = address - current->mm->start_code;
151 else
152 offset = (address - vma->vm_start) +
153 (vma->vm_pgoff << PAGE_SHIFT);
154
155 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
156 (void *)address, name, offset);
157 } else
158 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
159 (void *)address, name,
160 vma->vm_start, vma->vm_end);
161
Robin Getz904656c2008-03-26 09:17:43 +0800162 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800163 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800164
Robin Getzf09630b2008-07-26 19:45:46 +0800165 if (!strlen(buf))
166 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
167
Robin Getz885be032007-10-29 17:20:41 +0800168 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700169 }
170
171 vml = vml->next;
172 }
Robin Getz904656c2008-03-26 09:17:43 +0800173 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800174 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700175 }
Bryan Wu1394f032007-05-06 14:50:22 -0700176
177 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800178 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800179
180done:
181 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700182}
183
Robin Getz2ebcade2007-10-09 17:24:30 +0800184asmlinkage void double_fault_c(struct pt_regs *fp)
185{
Robin Getz226eb1e2007-10-29 17:59:07 +0800186 console_verbose();
187 oops_in_progress = 1;
Robin Getz2ebcade2007-10-09 17:24:30 +0800188 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800189 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800190 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800191 show_regs(fp);
Robin Getz2ebcade2007-10-09 17:24:30 +0800192 panic("Double Fault - unrecoverable event\n");
193
194}
195
Bryan Wu1394f032007-05-06 14:50:22 -0700196asmlinkage void trap_c(struct pt_regs *fp)
197{
Robin Getz518039b2007-07-25 11:03:28 +0800198#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
199 int j;
200#endif
201 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700202 siginfo_t info;
203 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
204
Bryan Wu1394f032007-05-06 14:50:22 -0700205 trace_buffer_save(j);
206
Robin Getz226eb1e2007-10-29 17:59:07 +0800207 /* Important - be very careful dereferncing pointers - will lead to
208 * double faults if the stack has become corrupt
209 */
210
211 /* If the fault was caused by a kernel thread, or interrupt handler
212 * we will kernel panic, so the system reboots.
213 * If KGDB is enabled, don't set this for kernel breakpoints
214 */
Robin Getzb03b08b2007-12-23 22:57:01 +0800215
216 /* TODO: check to see if we are in some sort of deferred HWERR
217 * that we should be able to recover from, not kernel panic
218 */
Robin Getz6b5eace2008-01-10 17:57:56 +0800219 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
Robin Getz226eb1e2007-10-29 17:59:07 +0800220#ifdef CONFIG_KGDB
Robin Getz6b5eace2008-01-10 17:57:56 +0800221 && (trapnr != VEC_EXCPT02)
Robin Getz226eb1e2007-10-29 17:59:07 +0800222#endif
223 ){
224 console_verbose();
225 oops_in_progress = 1;
226 } else if (current) {
227 if (current->mm == NULL) {
228 console_verbose();
229 oops_in_progress = 1;
230 }
231 }
232
Bryan Wu1394f032007-05-06 14:50:22 -0700233 /* trap_c() will be called for exceptions. During exceptions
234 * processing, the pc value should be set with retx value.
235 * With this change we can cleanup some code in signal.c- TODO
236 */
237 fp->orig_pc = fp->retx;
238 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
239 trapnr, fp->ipend, fp->pc, fp->retx); */
240
241 /* send the appropriate signal to the user program */
242 switch (trapnr) {
243
244 /* This table works in conjuction with the one in ./mach-common/entry.S
245 * Some exceptions are handled there (in assembly, in exception space)
246 * Some are handled here, (in C, in interrupt space)
247 * Some, like CPLB, are handled in both, where the normal path is
248 * handled in assembly/exception space, and the error path is handled
249 * here
250 */
251
252 /* 0x00 - Linux Syscall, getting here is an error */
253 /* 0x01 - userspace gdb breakpoint, handled here */
254 case VEC_EXCPT01:
255 info.si_code = TRAP_ILLTRAP;
256 sig = SIGTRAP;
257 CHK_DEBUGGER_TRAP_MAYBE();
258 /* Check if this is a breakpoint in kernel space */
259 if (fp->ipend & 0xffc0)
260 return;
261 else
262 break;
263#ifdef CONFIG_KGDB
264 case VEC_EXCPT02 : /* gdb connection */
265 info.si_code = TRAP_ILLTRAP;
266 sig = SIGTRAP;
267 CHK_DEBUGGER_TRAP();
268 return;
269#else
270 /* 0x02 - User Defined, Caught by default */
271#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800272 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700273 case VEC_EXCPT03:
274 info.si_code = SEGV_STACKFLOW;
275 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800276 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700277 CHK_DEBUGGER_TRAP();
278 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800279 /* 0x04 - User Defined, Caught by default */
Bryan Wu1394f032007-05-06 14:50:22 -0700280 /* 0x05 - User Defined, Caught by default */
281 /* 0x06 - User Defined, Caught by default */
282 /* 0x07 - User Defined, Caught by default */
283 /* 0x08 - User Defined, Caught by default */
284 /* 0x09 - User Defined, Caught by default */
285 /* 0x0A - User Defined, Caught by default */
286 /* 0x0B - User Defined, Caught by default */
287 /* 0x0C - User Defined, Caught by default */
288 /* 0x0D - User Defined, Caught by default */
289 /* 0x0E - User Defined, Caught by default */
290 /* 0x0F - User Defined, Caught by default */
291 /* 0x10 HW Single step, handled here */
292 case VEC_STEP:
293 info.si_code = TRAP_STEP;
294 sig = SIGTRAP;
295 CHK_DEBUGGER_TRAP_MAYBE();
296 /* Check if this is a single step in kernel space */
297 if (fp->ipend & 0xffc0)
298 return;
299 else
300 break;
301 /* 0x11 - Trace Buffer Full, handled here */
302 case VEC_OVFLOW:
303 info.si_code = TRAP_TRACEFLOW;
304 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800305 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700306 CHK_DEBUGGER_TRAP();
307 break;
308 /* 0x12 - Reserved, Caught by default */
309 /* 0x13 - Reserved, Caught by default */
310 /* 0x14 - Reserved, Caught by default */
311 /* 0x15 - Reserved, Caught by default */
312 /* 0x16 - Reserved, Caught by default */
313 /* 0x17 - Reserved, Caught by default */
314 /* 0x18 - Reserved, Caught by default */
315 /* 0x19 - Reserved, Caught by default */
316 /* 0x1A - Reserved, Caught by default */
317 /* 0x1B - Reserved, Caught by default */
318 /* 0x1C - Reserved, Caught by default */
319 /* 0x1D - Reserved, Caught by default */
320 /* 0x1E - Reserved, Caught by default */
321 /* 0x1F - Reserved, Caught by default */
322 /* 0x20 - Reserved, Caught by default */
323 /* 0x21 - Undefined Instruction, handled here */
324 case VEC_UNDEF_I:
325 info.si_code = ILL_ILLOPC;
326 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800327 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700328 CHK_DEBUGGER_TRAP();
329 break;
330 /* 0x22 - Illegal Instruction Combination, handled here */
331 case VEC_ILGAL_I:
332 info.si_code = ILL_ILLPARAOP;
333 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800334 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700335 CHK_DEBUGGER_TRAP();
336 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800337 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700338 case VEC_CPLB_VL:
339 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800340 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800341 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700342 CHK_DEBUGGER_TRAP();
343 break;
344 /* 0x24 - Data access misaligned, handled here */
345 case VEC_MISALI_D:
346 info.si_code = BUS_ADRALN;
347 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800348 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700349 CHK_DEBUGGER_TRAP();
350 break;
351 /* 0x25 - Unrecoverable Event, handled here */
352 case VEC_UNCOV:
353 info.si_code = ILL_ILLEXCPT;
354 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800355 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700356 CHK_DEBUGGER_TRAP();
357 break;
358 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
359 error case is handled here */
360 case VEC_CPLB_M:
361 info.si_code = BUS_ADRALN;
362 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800363 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700364 CHK_DEBUGGER_TRAP();
365 break;
366 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
367 case VEC_CPLB_MHIT:
368 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700369 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800370#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800371 if (saved_dcplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800372 printk(KERN_NOTICE "NULL pointer access\n");
373 else
Bryan Wu1394f032007-05-06 14:50:22 -0700374#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800375 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700376 CHK_DEBUGGER_TRAP();
377 break;
378 /* 0x28 - Emulation Watchpoint, handled here */
379 case VEC_WATCH:
380 info.si_code = TRAP_WATCHPT;
381 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800382 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700383 CHK_DEBUGGER_TRAP_MAYBE();
384 /* Check if this is a watchpoint in kernel space */
385 if (fp->ipend & 0xffc0)
386 return;
387 else
388 break;
389#ifdef CONFIG_BF535
390 /* 0x29 - Instruction fetch access error (535 only) */
391 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
392 info.si_code = BUS_OPFETCH;
393 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800394 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700395 CHK_DEBUGGER_TRAP();
396 break;
397#else
398 /* 0x29 - Reserved, Caught by default */
399#endif
400 /* 0x2A - Instruction fetch misaligned, handled here */
401 case VEC_MISALI_I:
402 info.si_code = BUS_ADRALN;
403 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800404 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700405 CHK_DEBUGGER_TRAP();
406 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800407 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700408 case VEC_CPLB_I_VL:
409 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800410 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800411 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700412 CHK_DEBUGGER_TRAP();
413 break;
414 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
415 case VEC_CPLB_I_M:
416 info.si_code = ILL_CPLB_MISS;
417 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800418 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700419 CHK_DEBUGGER_TRAP();
420 break;
421 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
422 case VEC_CPLB_I_MHIT:
423 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700424 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800425#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800426 if (saved_icplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800427 printk(KERN_NOTICE "Jump to NULL address\n");
428 else
Bryan Wu1394f032007-05-06 14:50:22 -0700429#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800430 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700431 CHK_DEBUGGER_TRAP();
432 break;
433 /* 0x2E - Illegal use of Supervisor Resource, handled here */
434 case VEC_ILL_RES:
435 info.si_code = ILL_PRVOPC;
436 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800437 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700438 CHK_DEBUGGER_TRAP();
439 break;
440 /* 0x2F - Reserved, Caught by default */
441 /* 0x30 - Reserved, Caught by default */
442 /* 0x31 - Reserved, Caught by default */
443 /* 0x32 - Reserved, Caught by default */
444 /* 0x33 - Reserved, Caught by default */
445 /* 0x34 - Reserved, Caught by default */
446 /* 0x35 - Reserved, Caught by default */
447 /* 0x36 - Reserved, Caught by default */
448 /* 0x37 - Reserved, Caught by default */
449 /* 0x38 - Reserved, Caught by default */
450 /* 0x39 - Reserved, Caught by default */
451 /* 0x3A - Reserved, Caught by default */
452 /* 0x3B - Reserved, Caught by default */
453 /* 0x3C - Reserved, Caught by default */
454 /* 0x3D - Reserved, Caught by default */
455 /* 0x3E - Reserved, Caught by default */
456 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800457 case VEC_HWERR:
458 info.si_code = BUS_ADRALN;
459 sig = SIGBUS;
460 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
461 /* System MMR Error */
462 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
463 info.si_code = BUS_ADRALN;
464 sig = SIGBUS;
465 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
466 break;
467 /* External Memory Addressing Error */
468 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
469 info.si_code = BUS_ADRERR;
470 sig = SIGBUS;
471 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
472 break;
473 /* Performance Monitor Overflow */
474 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
475 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
476 break;
477 /* RAISE 5 instruction */
478 case (SEQSTAT_HWERRCAUSE_RAISE_5):
479 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
480 break;
481 default: /* Reserved */
482 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
483 break;
484 }
485 CHK_DEBUGGER_TRAP();
486 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700487 default:
488 info.si_code = TRAP_ILLTRAP;
489 sig = SIGTRAP;
490 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
491 (fp->seqstat & SEQSTAT_EXCAUSE));
492 CHK_DEBUGGER_TRAP();
493 break;
494 }
495
Robin Getz226eb1e2007-10-29 17:59:07 +0800496 BUG_ON(sig == 0);
497
498 if (sig != SIGTRAP) {
Robin Getzf09630b2008-07-26 19:45:46 +0800499 unsigned long *stack;
Mike Frysinger49dce912007-11-21 16:46:49 +0800500 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800501 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800502 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800503
504 /* Print out the trace buffer if it makes sense */
505#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
506 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
507 printk(KERN_NOTICE "No trace since you do not have "
508 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
509 KERN_NOTICE "\n");
510 else
511#endif
512 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800513
Robin Getz226eb1e2007-10-29 17:59:07 +0800514 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800515 /* Dump the current kernel stack */
516 printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
517 show_stack(current, NULL);
518
Robin Getzaee3a292008-01-11 16:53:00 +0800519 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800520#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800521 printk(KERN_EMERG "Please turn on "
522 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800523#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700524 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800525 } else {
526 /* Dump the user space stack */
527 stack = (unsigned long *)rdusp();
528 printk(KERN_NOTICE "Userspace Stack\n");
529 show_stack(NULL, stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800530 }
Bryan Wu1394f032007-05-06 14:50:22 -0700531 }
Robin Getzfb322912007-11-21 16:38:05 +0800532
Robin Getzce3afa12007-10-09 17:28:36 +0800533 info.si_signo = sig;
534 info.si_errno = 0;
Mike Frysinger0ddeeca2008-03-07 02:37:41 +0800535 info.si_addr = (void __user *)fp->pc;
Robin Getzce3afa12007-10-09 17:28:36 +0800536 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700537
Bryan Wu1394f032007-05-06 14:50:22 -0700538 trace_buffer_restore(j);
539 return;
540}
541
542/* Typical exception handling routines */
543
Robin Getz518039b2007-07-25 11:03:28 +0800544#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
545
Robin Getzf09630b2008-07-26 19:45:46 +0800546/*
547 * Similar to get_user, do some address checking, then dereference
548 * Return true on sucess, false on bad address
549 */
550bool get_instruction(unsigned short *val, unsigned short *address)
551{
552
553 unsigned long addr;
554
555 addr = (unsigned long)address;
556
557 /* Check for odd addresses */
558 if (addr & 0x1)
559 return false;
560
561 /* Check that things do not wrap around */
562 if (addr > (addr + 2))
563 return false;
564
565 /*
566 * Since we are in exception context, we need to do a little address checking
567 * We need to make sure we are only accessing valid memory, and
568 * we don't read something in the async space that can hang forever
569 */
570 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800571#if L2_LENGTH != 0
Robin Getzf09630b2008-07-26 19:45:46 +0800572 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
573#endif
574 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
575#if L1_DATA_A_LENGTH != 0
576 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
577#endif
578#if L1_DATA_B_LENGTH != 0
579 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
580#endif
581 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
582 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
583 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
584 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
585 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
586 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
587 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
588 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
589 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
590 *val = *address;
591 return true;
592 }
593
594#if L1_CODE_LENGTH != 0
595 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
596 dma_memcpy(val, address, 2);
597 return true;
598 }
599#endif
600
601
602 return false;
603}
604
Robin Getzd3d0ac22008-08-06 17:49:27 +0800605/*
606 * decode the instruction if we are printing out the trace, as it
607 * makes things easier to follow, without running it through objdump
608 * These are the normal instructions which cause change of flow, which
609 * would be at the source of the trace buffer
610 */
611void decode_instruction(unsigned short *address)
612{
613 unsigned short opcode;
614
615 if (get_instruction(&opcode, address)) {
616 if (opcode == 0x0010)
617 printk("RTS");
618 else if (opcode == 0x0011)
619 printk("RTI");
620 else if (opcode == 0x0012)
621 printk("RTX");
622 else if (opcode >= 0x0050 && opcode <= 0x0057)
623 printk("JUMP (P%i)", opcode & 7);
624 else if (opcode >= 0x0060 && opcode <= 0x0067)
625 printk("CALL (P%i)", opcode & 7);
626 else if (opcode >= 0x0070 && opcode <= 0x0077)
627 printk("CALL (PC+P%i)", opcode & 7);
628 else if (opcode >= 0x0080 && opcode <= 0x0087)
629 printk("JUMP (PC+P%i)", opcode & 7);
630 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
631 printk("IF !CC JUMP");
632 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
633 printk("IF CC JUMP");
634 else if (opcode >= 0x2000 && opcode <= 0x2fff)
635 printk("JUMP.S");
636 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
637 printk("LSETUP");
638 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
639 printk("JUMP.L");
640 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
641 printk("CALL pcrel");
642 else
643 printk("0x%04x", opcode);
644 }
645
646}
647
Bryan Wu1394f032007-05-06 14:50:22 -0700648void dump_bfin_trace_buffer(void)
649{
Robin Getz518039b2007-07-25 11:03:28 +0800650#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
651 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800652 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800653 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800654#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
655 int j, index;
656#endif
657
Bryan Wu1394f032007-05-06 14:50:22 -0700658 trace_buffer_save(tflags);
659
Robin Getz226eb1e2007-10-29 17:59:07 +0800660 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800661
Robin Getzd3d0ac22008-08-06 17:49:27 +0800662#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
663 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
664#endif
665
Bryan Wu1394f032007-05-06 14:50:22 -0700666 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800667 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800668 decode_address(buf, (unsigned long)bfin_read_TBUF());
669 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800670 addr = (unsigned short *)bfin_read_TBUF();
671 decode_address(buf, (unsigned long)addr);
672 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800673 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800674 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700675 }
676 }
677
Robin Getz518039b2007-07-25 11:03:28 +0800678#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
679 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800680 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800681 else
682 index = EXPAND_LEN;
683
684 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
685 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800686 decode_address(buf, software_trace_buff[index]);
687 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800688 index -= 1;
689 if (index < 0 )
690 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800691 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800692 printk(KERN_NOTICE " Source : %s ", buf);
693 decode_instruction((unsigned short *)software_trace_buff[index]);
694 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800695 index -= 1;
696 if (index < 0)
697 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800698 j--;
699 i++;
700 }
701#endif
702
Bryan Wu1394f032007-05-06 14:50:22 -0700703 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800704#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700705}
706EXPORT_SYMBOL(dump_bfin_trace_buffer);
707
Robin Getzf09630b2008-07-26 19:45:46 +0800708/*
709 * Checks to see if the address pointed to is either a
710 * 16-bit CALL instruction, or a 32-bit CALL instruction
711 */
712bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700713{
Robin Getzf09630b2008-07-26 19:45:46 +0800714 unsigned short opcode = 0, *ins_addr;
715 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700716
Robin Getzf09630b2008-07-26 19:45:46 +0800717 if (!get_instruction(&opcode, ins_addr))
718 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700719
Robin Getzf09630b2008-07-26 19:45:46 +0800720 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
721 (opcode >= 0x0070 && opcode <= 0x0077))
722 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700723
Robin Getzf09630b2008-07-26 19:45:46 +0800724 ins_addr--;
725 if (!get_instruction(&opcode, ins_addr))
726 return false;
727
728 if (opcode >= 0xE300 && opcode <= 0xE3FF)
729 return true;
730
731 return false;
732
Bryan Wu1394f032007-05-06 14:50:22 -0700733}
Bryan Wu1394f032007-05-06 14:50:22 -0700734void show_stack(struct task_struct *task, unsigned long *stack)
735{
Robin Getzf09630b2008-07-26 19:45:46 +0800736 unsigned int *addr, *endstack, *fp = 0, *frame;
737 unsigned short *ins_addr;
738 char buf[150];
739 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700740
Robin Getzf09630b2008-07-26 19:45:46 +0800741 /*
742 * If we have been passed a specific stack, use that one otherwise
743 * if we have been passed a task structure, use that, otherwise
744 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700745 */
746
Robin Getzf09630b2008-07-26 19:45:46 +0800747 if (stack == NULL) {
748 if (task) {
749 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700750 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800751 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
752 } else {
753 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700754 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800755 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
756 }
757 } else
758 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
759
760 decode_address(buf, (unsigned int)stack);
761 printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
762 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
763
764 /* First thing is to look for a frame pointer */
765 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
766 addr < endstack; addr++, i++) {
767 if (*addr & 0x1)
768 continue;
769 ins_addr = (unsigned short *)*addr;
770 ins_addr--;
771 if (is_bfin_call(ins_addr))
772 fp = addr - 1;
773
774 if (fp) {
775 /* Let's check to see if it is a frame pointer */
776 while (fp >= (addr - 1) && fp < endstack && fp)
777 fp = (unsigned int *)*fp;
778 if (fp == 0 || fp == endstack) {
779 fp = addr - 1;
780 break;
781 }
782 fp = 0;
783 }
784 }
785 if (fp) {
786 frame = fp;
787 printk(" FP: (0x%p)\n", fp);
788 } else
789 frame = 0;
790
791 /*
792 * Now that we think we know where things are, we
793 * walk the stack again, this time printing things out
794 * incase there is no frame pointer, we still look for
795 * valid return addresses
796 */
797
798 /* First time print out data, next time, print out symbols */
799 for (j = 0; j <= 1; j++) {
800 if (j)
801 printk(KERN_NOTICE "Return addresses in stack:\n");
802 else
803 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
804
805 fp = frame;
806 frame_no = 0;
807
808 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
809 addr <= endstack; addr++, i++) {
810
811 ret_addr = 0;
812 if (!j && i % 8 == 0)
813 printk("\n" KERN_NOTICE "%p:",addr);
814
815 /* if it is an odd address, or zero, just skip it */
816 if (*addr & 0x1 || !*addr)
817 goto print;
818
819 ins_addr = (unsigned short *)*addr;
820
821 /* Go back one instruction, and see if it is a CALL */
822 ins_addr--;
823 ret_addr = is_bfin_call(ins_addr);
824 print:
825 if (!j && stack == (unsigned long *)addr)
826 printk("[%08x]", *addr);
827 else if (ret_addr)
828 if (j) {
829 decode_address(buf, (unsigned int)*addr);
830 if (frame == addr) {
831 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
832 continue;
833 }
834 printk(KERN_NOTICE " address : %s\n", buf);
835 } else
836 printk("<%08x>", *addr);
837 else if (fp == addr) {
838 if (j)
839 frame = addr+1;
840 else
841 printk("(%08x)", *addr);
842
843 fp = (unsigned int *)*addr;
844 frame_no++;
845
846 } else if (!j)
847 printk(" %08x ", *addr);
848 }
849 if (!j)
850 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700851 }
852
Bryan Wu1394f032007-05-06 14:50:22 -0700853}
854
855void dump_stack(void)
856{
857 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800858#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700859 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800860#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700861 trace_buffer_save(tflags);
862 dump_bfin_trace_buffer();
863 show_stack(current, &stack);
864 trace_buffer_restore(tflags);
865}
Bryan Wu1394f032007-05-06 14:50:22 -0700866EXPORT_SYMBOL(dump_stack);
867
Mike Frysinger49dce912007-11-21 16:46:49 +0800868void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700869{
Mike Frysinger49dce912007-11-21 16:46:49 +0800870 /* We should be able to look at fp->ipend, but we don't push it on the
871 * stack all the time, so do this until we fix that */
872 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800873
Mike Frysinger49dce912007-11-21 16:46:49 +0800874 if (oops_in_progress)
875 printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800876
Robin Getzb03b08b2007-12-23 22:57:01 +0800877 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
878 printk(KERN_NOTICE "HW Error context\n");
879 else if (context & 0x0020)
Mike Frysingera3acf522008-02-02 15:45:27 +0800880 printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800881 else if (context & 0x3FC0)
882 printk(KERN_NOTICE "Interrupt context\n");
883 else if (context & 0x4000)
884 printk(KERN_NOTICE "Deferred Interrupt context\n");
885 else if (context & 0x8000)
886 printk(KERN_NOTICE "Kernel process context\n");
887
Robin Getz9a62ca42008-03-26 09:15:58 +0800888 /* Because we are crashing, and pointers could be bad, we check things
889 * pretty closely before we use them
890 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800891 if ((unsigned long)current >= FIXED_CODE_START &&
892 !((unsigned long)current & 0x3) && current->pid) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800893 printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800894 if (current->comm >= (char *)FIXED_CODE_START)
895 printk(KERN_NOTICE "COMM=%s PID=%d\n",
896 current->comm, current->pid);
897 else
898 printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800899
Robin Getz9a62ca42008-03-26 09:15:58 +0800900 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
901 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
902 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
903 KERN_NOTICE "\n",
904 (void *)current->mm->start_code,
905 (void *)current->mm->end_code,
906 (void *)current->mm->start_data,
907 (void *)current->mm->end_data,
908 (void *)current->mm->end_data,
909 (void *)current->mm->brk,
910 (void *)current->mm->start_stack);
911 else
912 printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800913 } else
914 printk(KERN_NOTICE "\n" KERN_NOTICE
915 "No Valid process in current context\n");
916}
917
Robin Getzb03b08b2007-12-23 22:57:01 +0800918void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +0800919{
Robin Getzb03b08b2007-12-23 22:57:01 +0800920 unsigned short *addr, *erraddr, val = 0, err = 0;
921 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -0700922
Bernd Schmidt5d750b92008-04-25 05:02:33 +0800923 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +0800924
Robin Getzb03b08b2007-12-23 22:57:01 +0800925 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
926
927 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
928 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
929 addr++) {
930 if (!((unsigned long)addr & 0xF))
931 printk("\n" KERN_NOTICE "0x%p: ", addr);
932
Robin Getzf09630b2008-07-26 19:45:46 +0800933 if (get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +0800934 val = 0;
935 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +0800936 } else
937 sprintf(buf, "%04x", val);
938
939 if (addr == erraddr) {
940 printk("[%s]", buf);
941 err = val;
942 } else
943 printk(" %s ", buf);
944
945 /* Do any previous instructions turn on interrupts? */
946 if (addr <= erraddr && /* in the past */
947 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
948 val == 0x017b)) /* [SP++] = RETI */
949 sti = 1;
950 }
951
952 printk("\n");
953
954 /* Hardware error interrupts can be deferred */
955 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
956 oops_in_progress)){
957 printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700958#ifndef CONFIG_DEBUG_HWERR
Robin Getzb03b08b2007-12-23 22:57:01 +0800959 printk(KERN_NOTICE "The remaining message may be meaningless\n"
960 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
961 " better idea where it came from\n");
962#else
963 /* If we are handling only one peripheral interrupt
964 * and current mm and pid are valid, and the last error
965 * was in that user space process's text area
966 * print it out - because that is where the problem exists
967 */
968 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
969 (current->pid && current->mm)) {
970 /* And the last RETI points to the current userspace context */
971 if ((fp + 1)->pc >= current->mm->start_code &&
972 (fp + 1)->pc <= current->mm->end_code) {
973 printk(KERN_NOTICE "It might be better to look around here : \n");
974 printk(KERN_NOTICE "-------------------------------------------\n");
975 show_regs(fp + 1);
976 printk(KERN_NOTICE "-------------------------------------------\n");
977 }
Bryan Wu1394f032007-05-06 14:50:22 -0700978 }
Robin Getzb03b08b2007-12-23 22:57:01 +0800979#endif
980 }
Mike Frysinger49dce912007-11-21 16:46:49 +0800981}
982
983void show_regs(struct pt_regs *fp)
984{
985 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +0800986 struct irqaction *action;
987 unsigned int i;
988 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700989
Robin Getzaee3a292008-01-11 16:53:00 +0800990 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
Robin Getz226eb1e2007-10-29 17:59:07 +0800991 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
992 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz13fe24f2008-01-27 15:38:56 +0800993 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
994 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
995 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
996 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getzd8f66c82007-12-24 15:27:56 +0800997 for (i = 6; i <= 15 ; i++) {
998 if (fp->ipend & (1 << i)) {
999 decode_address(buf, bfin_read32(EVT0 + 4*i));
1000 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1001 }
1002 }
1003
1004 /* if no interrupts are going off, don't print this out */
1005 if (fp->ipend & ~0x3F) {
1006 for (i = 0; i < (NR_IRQS - 1); i++) {
1007 spin_lock_irqsave(&irq_desc[i].lock, flags);
1008 action = irq_desc[i].action;
1009 if (!action)
1010 goto unlock;
1011
1012 decode_address(buf, (unsigned int)action->handler);
1013 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1014 for (action = action->next; action; action = action->next) {
1015 decode_address(buf, (unsigned int)action->handler);
1016 printk(", %s", buf);
1017 }
1018 printk("\n");
1019unlock:
1020 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1021 }
1022 }
Bryan Wu1394f032007-05-06 14:50:22 -07001023
Robin Getz226eb1e2007-10-29 17:59:07 +08001024 decode_address(buf, fp->rete);
1025 printk(KERN_NOTICE " RETE: %s\n", buf);
1026 decode_address(buf, fp->retn);
1027 printk(KERN_NOTICE " RETN: %s\n", buf);
1028 decode_address(buf, fp->retx);
1029 printk(KERN_NOTICE " RETX: %s\n", buf);
1030 decode_address(buf, fp->rets);
1031 printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001032 decode_address(buf, fp->pc);
Robin Getz13fe24f2008-01-27 15:38:56 +08001033 printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001034
Robin Getz13fe24f2008-01-27 15:38:56 +08001035 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1036 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001037 decode_address(buf, saved_dcplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001038 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001039 decode_address(buf, saved_icplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001040 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001041 }
1042
Robin Getz226eb1e2007-10-29 17:59:07 +08001043 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1044 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1045 fp->r0, fp->r1, fp->r2, fp->r3);
1046 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1047 fp->r4, fp->r5, fp->r6, fp->r7);
1048 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1049 fp->p0, fp->p1, fp->p2, fp->p3);
1050 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1051 fp->p4, fp->p5, fp->fp, (long)fp);
1052 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1053 fp->lb0, fp->lt0, fp->lc0);
1054 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1055 fp->lb1, fp->lt1, fp->lc1);
1056 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1057 fp->b0, fp->l0, fp->m0, fp->i0);
1058 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1059 fp->b1, fp->l1, fp->m1, fp->i1);
1060 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1061 fp->b2, fp->l2, fp->m2, fp->i2);
1062 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1063 fp->b3, fp->l3, fp->m3, fp->i3);
1064 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1065 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1066
1067 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1068 rdusp(), fp->astat);
1069
1070 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001071}
1072
1073#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1074asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1075#endif
1076
1077asmlinkage int sys_bfin_spinlock(int *spinlock)
1078{
1079 int ret = 0;
1080 int tmp = 0;
1081
1082 local_irq_disable();
1083 ret = get_user(tmp, spinlock);
1084 if (ret == 0) {
1085 if (tmp)
1086 ret = 1;
1087 tmp = 1;
1088 put_user(tmp, spinlock);
1089 }
1090 local_irq_enable();
1091 return ret;
1092}
1093
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001094int bfin_request_exception(unsigned int exception, void (*handler)(void))
1095{
1096 void (*curr_handler)(void);
1097
1098 if (exception > 0x3F)
1099 return -EINVAL;
1100
1101 curr_handler = ex_table[exception];
1102
1103 if (curr_handler != ex_replaceable)
1104 return -EBUSY;
1105
1106 ex_table[exception] = handler;
1107
1108 return 0;
1109}
1110EXPORT_SYMBOL(bfin_request_exception);
1111
1112int bfin_free_exception(unsigned int exception, void (*handler)(void))
1113{
1114 void (*curr_handler)(void);
1115
1116 if (exception > 0x3F)
1117 return -EINVAL;
1118
1119 curr_handler = ex_table[exception];
1120
1121 if (curr_handler != handler)
1122 return -EBUSY;
1123
1124 ex_table[exception] = ex_replaceable;
1125
1126 return 0;
1127}
1128EXPORT_SYMBOL(bfin_free_exception);
1129
Bryan Wu1394f032007-05-06 14:50:22 -07001130void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1131{
1132 switch (cplb_panic) {
1133 case CPLB_NO_UNLOCKED:
1134 printk(KERN_EMERG "All CPLBs are locked\n");
1135 break;
1136 case CPLB_PROT_VIOL:
1137 return;
1138 case CPLB_NO_ADDR_MATCH:
1139 return;
1140 case CPLB_UNKNOWN_ERR:
1141 printk(KERN_EMERG "Unknown CPLB Exception\n");
1142 break;
1143 }
1144
Robin Getz226eb1e2007-10-29 17:59:07 +08001145 oops_in_progress = 1;
1146
Mike Frysinger49dce912007-11-21 16:46:49 +08001147 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001148 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001149 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001150 dump_stack();
1151 panic("Unrecoverable event\n");
1152}