blob: bd41fca315dd011bce4083c8cb291ce3d8c84b64 [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
Robin Getz0c7a6b22008-10-08 16:27:12 +080071/*
72 * Used to save the RETX, SEQSTAT, I/D CPLB FAULT ADDR
73 * values across the transition from exception to IRQ5.
74 * We put these in L1, so they are going to be in a valid
75 * location during exception context
76 */
77__attribute__((l1_data))
78unsigned long saved_retx, saved_seqstat,
79 saved_icplb_fault_addr, saved_dcplb_fault_addr;
Bernd Schmidt5d750b92008-04-25 05:02:33 +080080
Robin Getz226eb1e2007-10-29 17:59:07 +080081static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070082{
83 struct vm_list_struct *vml;
84 struct task_struct *p;
85 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080086 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080087 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -070088
89#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080090 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070091 const char *symname;
92 char *modname;
93 char *delim = ":";
94 char namebuf[128];
95
96 /* look up the address and see if we are in kernel space */
97 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
98
99 if (symname) {
100 /* yeah! kernel space! */
101 if (!modname)
102 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +0800103 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800104 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -0700105 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +0800106 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700107
108 }
109#endif
110
Robin Getz226eb1e2007-10-29 17:59:07 +0800111 /* Problem in fixed code section? */
112 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
113 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
114 return;
115 }
116
117 /* Problem somewhere before the kernel start address */
118 if (address < CONFIG_BOOT_LOAD) {
119 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
120 return;
121 }
122
Bryan Wu1394f032007-05-06 14:50:22 -0700123 /* looks like we're off in user-land, so let's walk all the
124 * mappings of all our processes and see if we can't be a whee
125 * bit more specific
126 */
Robin Getz885be032007-10-29 17:20:41 +0800127 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700128 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800129 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700130 if (!mm)
131 continue;
132
133 vml = mm->context.vmlist;
134 while (vml) {
135 struct vm_area_struct *vma = vml->vma;
136
137 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800138 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700139 char *name = p->comm;
140 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800141
142 if (file)
143 name = d_path(&file->f_path, _tmpbuf,
144 sizeof(_tmpbuf));
Bryan Wu1394f032007-05-06 14:50:22 -0700145
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800146 /* FLAT does not have its text aligned to the start of
147 * the map while FDPIC ELF does ...
148 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800149
Robin Getz7f1c9062008-04-25 03:36:31 +0800150 /* before we can check flat/fdpic, we need to
151 * make sure current is valid
152 */
153 if ((unsigned long)current >= FIXED_CODE_START &&
154 !((unsigned long)current & 0x3)) {
155 if (current->mm &&
156 (address > current->mm->start_code) &&
157 (address < current->mm->end_code))
158 offset = address - current->mm->start_code;
159 else
160 offset = (address - vma->vm_start) +
161 (vma->vm_pgoff << PAGE_SHIFT);
162
163 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
164 (void *)address, name, offset);
165 } else
166 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
167 (void *)address, name,
168 vma->vm_start, vma->vm_end);
169
Robin Getz904656c2008-03-26 09:17:43 +0800170 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800171 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800172
Robin Getzf09630b2008-07-26 19:45:46 +0800173 if (!strlen(buf))
174 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
175
Robin Getz885be032007-10-29 17:20:41 +0800176 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700177 }
178
179 vml = vml->next;
180 }
Robin Getz904656c2008-03-26 09:17:43 +0800181 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800182 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700183 }
Bryan Wu1394f032007-05-06 14:50:22 -0700184
185 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800186 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800187
188done:
189 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700190}
191
Robin Getz2ebcade2007-10-09 17:24:30 +0800192asmlinkage void double_fault_c(struct pt_regs *fp)
193{
Robin Getz226eb1e2007-10-29 17:59:07 +0800194 console_verbose();
195 oops_in_progress = 1;
Robin Getz2ebcade2007-10-09 17:24:30 +0800196 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800197#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
198 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
199 char buf[150];
200 decode_address(buf, saved_retx);
201 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
202 (int)saved_seqstat & SEQSTAT_EXCAUSE, buf);
203 decode_address(buf, saved_dcplb_fault_addr);
204 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
205 decode_address(buf, saved_icplb_fault_addr);
206 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
207
208 decode_address(buf, fp->retx);
209 printk(KERN_NOTICE "The instruction at %s caused a double exception\n",
210 buf);
211 } else
212#endif
213 {
214 dump_bfin_process(fp);
215 dump_bfin_mem(fp);
216 show_regs(fp);
217 }
Robin Getz2ebcade2007-10-09 17:24:30 +0800218 panic("Double Fault - unrecoverable event\n");
219
220}
221
Bryan Wu1394f032007-05-06 14:50:22 -0700222asmlinkage void trap_c(struct pt_regs *fp)
223{
Robin Getz518039b2007-07-25 11:03:28 +0800224#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
225 int j;
226#endif
227 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700228 siginfo_t info;
229 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
230
Bryan Wu1394f032007-05-06 14:50:22 -0700231 trace_buffer_save(j);
232
Robin Getz226eb1e2007-10-29 17:59:07 +0800233 /* Important - be very careful dereferncing pointers - will lead to
234 * double faults if the stack has become corrupt
235 */
236
237 /* If the fault was caused by a kernel thread, or interrupt handler
238 * we will kernel panic, so the system reboots.
239 * If KGDB is enabled, don't set this for kernel breakpoints
240 */
Robin Getzb03b08b2007-12-23 22:57:01 +0800241
242 /* TODO: check to see if we are in some sort of deferred HWERR
243 * that we should be able to recover from, not kernel panic
244 */
Robin Getz6b5eace2008-01-10 17:57:56 +0800245 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
Robin Getz226eb1e2007-10-29 17:59:07 +0800246#ifdef CONFIG_KGDB
Robin Getz6b5eace2008-01-10 17:57:56 +0800247 && (trapnr != VEC_EXCPT02)
Robin Getz226eb1e2007-10-29 17:59:07 +0800248#endif
249 ){
250 console_verbose();
251 oops_in_progress = 1;
252 } else if (current) {
253 if (current->mm == NULL) {
254 console_verbose();
255 oops_in_progress = 1;
256 }
257 }
258
Bryan Wu1394f032007-05-06 14:50:22 -0700259 /* trap_c() will be called for exceptions. During exceptions
260 * processing, the pc value should be set with retx value.
261 * With this change we can cleanup some code in signal.c- TODO
262 */
263 fp->orig_pc = fp->retx;
264 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
265 trapnr, fp->ipend, fp->pc, fp->retx); */
266
267 /* send the appropriate signal to the user program */
268 switch (trapnr) {
269
270 /* This table works in conjuction with the one in ./mach-common/entry.S
271 * Some exceptions are handled there (in assembly, in exception space)
272 * Some are handled here, (in C, in interrupt space)
273 * Some, like CPLB, are handled in both, where the normal path is
274 * handled in assembly/exception space, and the error path is handled
275 * here
276 */
277
278 /* 0x00 - Linux Syscall, getting here is an error */
279 /* 0x01 - userspace gdb breakpoint, handled here */
280 case VEC_EXCPT01:
281 info.si_code = TRAP_ILLTRAP;
282 sig = SIGTRAP;
283 CHK_DEBUGGER_TRAP_MAYBE();
284 /* Check if this is a breakpoint in kernel space */
285 if (fp->ipend & 0xffc0)
286 return;
287 else
288 break;
289#ifdef CONFIG_KGDB
290 case VEC_EXCPT02 : /* gdb connection */
291 info.si_code = TRAP_ILLTRAP;
292 sig = SIGTRAP;
293 CHK_DEBUGGER_TRAP();
294 return;
295#else
296 /* 0x02 - User Defined, Caught by default */
297#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800298 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700299 case VEC_EXCPT03:
300 info.si_code = SEGV_STACKFLOW;
301 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800302 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700303 CHK_DEBUGGER_TRAP();
304 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800305 /* 0x04 - User Defined, Caught by default */
Bryan Wu1394f032007-05-06 14:50:22 -0700306 /* 0x05 - User Defined, Caught by default */
307 /* 0x06 - User Defined, Caught by default */
308 /* 0x07 - User Defined, Caught by default */
309 /* 0x08 - User Defined, Caught by default */
310 /* 0x09 - User Defined, Caught by default */
311 /* 0x0A - User Defined, Caught by default */
312 /* 0x0B - User Defined, Caught by default */
313 /* 0x0C - User Defined, Caught by default */
314 /* 0x0D - User Defined, Caught by default */
315 /* 0x0E - User Defined, Caught by default */
316 /* 0x0F - User Defined, Caught by default */
317 /* 0x10 HW Single step, handled here */
318 case VEC_STEP:
319 info.si_code = TRAP_STEP;
320 sig = SIGTRAP;
321 CHK_DEBUGGER_TRAP_MAYBE();
322 /* Check if this is a single step in kernel space */
323 if (fp->ipend & 0xffc0)
324 return;
325 else
326 break;
327 /* 0x11 - Trace Buffer Full, handled here */
328 case VEC_OVFLOW:
329 info.si_code = TRAP_TRACEFLOW;
330 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800331 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700332 CHK_DEBUGGER_TRAP();
333 break;
334 /* 0x12 - Reserved, Caught by default */
335 /* 0x13 - Reserved, Caught by default */
336 /* 0x14 - Reserved, Caught by default */
337 /* 0x15 - Reserved, Caught by default */
338 /* 0x16 - Reserved, Caught by default */
339 /* 0x17 - Reserved, Caught by default */
340 /* 0x18 - Reserved, Caught by default */
341 /* 0x19 - Reserved, Caught by default */
342 /* 0x1A - Reserved, Caught by default */
343 /* 0x1B - Reserved, Caught by default */
344 /* 0x1C - Reserved, Caught by default */
345 /* 0x1D - Reserved, Caught by default */
346 /* 0x1E - Reserved, Caught by default */
347 /* 0x1F - Reserved, Caught by default */
348 /* 0x20 - Reserved, Caught by default */
349 /* 0x21 - Undefined Instruction, handled here */
350 case VEC_UNDEF_I:
351 info.si_code = ILL_ILLOPC;
352 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800353 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700354 CHK_DEBUGGER_TRAP();
355 break;
356 /* 0x22 - Illegal Instruction Combination, handled here */
357 case VEC_ILGAL_I:
358 info.si_code = ILL_ILLPARAOP;
359 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800360 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700361 CHK_DEBUGGER_TRAP();
362 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800363 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700364 case VEC_CPLB_VL:
365 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800366 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800367 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700368 CHK_DEBUGGER_TRAP();
369 break;
370 /* 0x24 - Data access misaligned, handled here */
371 case VEC_MISALI_D:
372 info.si_code = BUS_ADRALN;
373 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800374 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700375 CHK_DEBUGGER_TRAP();
376 break;
377 /* 0x25 - Unrecoverable Event, handled here */
378 case VEC_UNCOV:
379 info.si_code = ILL_ILLEXCPT;
380 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800381 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700382 CHK_DEBUGGER_TRAP();
383 break;
384 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
385 error case is handled here */
386 case VEC_CPLB_M:
387 info.si_code = BUS_ADRALN;
388 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800389 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700390 CHK_DEBUGGER_TRAP();
391 break;
392 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
393 case VEC_CPLB_MHIT:
394 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700395 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800396#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800397 if (saved_dcplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800398 printk(KERN_NOTICE "NULL pointer access\n");
399 else
Bryan Wu1394f032007-05-06 14:50:22 -0700400#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800401 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700402 CHK_DEBUGGER_TRAP();
403 break;
404 /* 0x28 - Emulation Watchpoint, handled here */
405 case VEC_WATCH:
406 info.si_code = TRAP_WATCHPT;
407 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800408 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700409 CHK_DEBUGGER_TRAP_MAYBE();
410 /* Check if this is a watchpoint in kernel space */
411 if (fp->ipend & 0xffc0)
412 return;
413 else
414 break;
415#ifdef CONFIG_BF535
416 /* 0x29 - Instruction fetch access error (535 only) */
417 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
418 info.si_code = BUS_OPFETCH;
419 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800420 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700421 CHK_DEBUGGER_TRAP();
422 break;
423#else
424 /* 0x29 - Reserved, Caught by default */
425#endif
426 /* 0x2A - Instruction fetch misaligned, handled here */
427 case VEC_MISALI_I:
428 info.si_code = BUS_ADRALN;
429 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800430 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700431 CHK_DEBUGGER_TRAP();
432 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800433 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700434 case VEC_CPLB_I_VL:
435 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800436 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800437 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700438 CHK_DEBUGGER_TRAP();
439 break;
440 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
441 case VEC_CPLB_I_M:
442 info.si_code = ILL_CPLB_MISS;
443 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800444 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700445 CHK_DEBUGGER_TRAP();
446 break;
447 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
448 case VEC_CPLB_I_MHIT:
449 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700450 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800451#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800452 if (saved_icplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800453 printk(KERN_NOTICE "Jump to NULL address\n");
454 else
Bryan Wu1394f032007-05-06 14:50:22 -0700455#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800456 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700457 CHK_DEBUGGER_TRAP();
458 break;
459 /* 0x2E - Illegal use of Supervisor Resource, handled here */
460 case VEC_ILL_RES:
461 info.si_code = ILL_PRVOPC;
462 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800463 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700464 CHK_DEBUGGER_TRAP();
465 break;
466 /* 0x2F - Reserved, Caught by default */
467 /* 0x30 - Reserved, Caught by default */
468 /* 0x31 - Reserved, Caught by default */
469 /* 0x32 - Reserved, Caught by default */
470 /* 0x33 - Reserved, Caught by default */
471 /* 0x34 - Reserved, Caught by default */
472 /* 0x35 - Reserved, Caught by default */
473 /* 0x36 - Reserved, Caught by default */
474 /* 0x37 - Reserved, Caught by default */
475 /* 0x38 - Reserved, Caught by default */
476 /* 0x39 - Reserved, Caught by default */
477 /* 0x3A - Reserved, Caught by default */
478 /* 0x3B - Reserved, Caught by default */
479 /* 0x3C - Reserved, Caught by default */
480 /* 0x3D - Reserved, Caught by default */
481 /* 0x3E - Reserved, Caught by default */
482 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800483 case VEC_HWERR:
484 info.si_code = BUS_ADRALN;
485 sig = SIGBUS;
486 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
487 /* System MMR Error */
488 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
489 info.si_code = BUS_ADRALN;
490 sig = SIGBUS;
491 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
492 break;
493 /* External Memory Addressing Error */
494 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
495 info.si_code = BUS_ADRERR;
496 sig = SIGBUS;
497 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
498 break;
499 /* Performance Monitor Overflow */
500 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
501 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
502 break;
503 /* RAISE 5 instruction */
504 case (SEQSTAT_HWERRCAUSE_RAISE_5):
505 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
506 break;
507 default: /* Reserved */
508 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
509 break;
510 }
511 CHK_DEBUGGER_TRAP();
512 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700513 default:
514 info.si_code = TRAP_ILLTRAP;
515 sig = SIGTRAP;
516 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
517 (fp->seqstat & SEQSTAT_EXCAUSE));
518 CHK_DEBUGGER_TRAP();
519 break;
520 }
521
Robin Getz226eb1e2007-10-29 17:59:07 +0800522 BUG_ON(sig == 0);
523
524 if (sig != SIGTRAP) {
Robin Getzf09630b2008-07-26 19:45:46 +0800525 unsigned long *stack;
Mike Frysinger49dce912007-11-21 16:46:49 +0800526 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800527 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800528 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800529
530 /* Print out the trace buffer if it makes sense */
531#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
532 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
533 printk(KERN_NOTICE "No trace since you do not have "
534 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
535 KERN_NOTICE "\n");
536 else
537#endif
538 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800539
Robin Getz226eb1e2007-10-29 17:59:07 +0800540 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800541 /* Dump the current kernel stack */
542 printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
543 show_stack(current, NULL);
544
Robin Getzaee3a292008-01-11 16:53:00 +0800545 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800546#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800547 printk(KERN_EMERG "Please turn on "
548 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800549#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700550 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800551 } else {
552 /* Dump the user space stack */
553 stack = (unsigned long *)rdusp();
554 printk(KERN_NOTICE "Userspace Stack\n");
555 show_stack(NULL, stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800556 }
Bryan Wu1394f032007-05-06 14:50:22 -0700557 }
Robin Getzfb322912007-11-21 16:38:05 +0800558
Robin Getzce3afa12007-10-09 17:28:36 +0800559 info.si_signo = sig;
560 info.si_errno = 0;
Mike Frysinger0ddeeca2008-03-07 02:37:41 +0800561 info.si_addr = (void __user *)fp->pc;
Robin Getzce3afa12007-10-09 17:28:36 +0800562 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700563
Bryan Wu1394f032007-05-06 14:50:22 -0700564 trace_buffer_restore(j);
565 return;
566}
567
568/* Typical exception handling routines */
569
Robin Getz518039b2007-07-25 11:03:28 +0800570#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
571
Robin Getzf09630b2008-07-26 19:45:46 +0800572/*
573 * Similar to get_user, do some address checking, then dereference
574 * Return true on sucess, false on bad address
575 */
576bool get_instruction(unsigned short *val, unsigned short *address)
577{
578
579 unsigned long addr;
580
581 addr = (unsigned long)address;
582
583 /* Check for odd addresses */
584 if (addr & 0x1)
585 return false;
586
587 /* Check that things do not wrap around */
588 if (addr > (addr + 2))
589 return false;
590
591 /*
592 * Since we are in exception context, we need to do a little address checking
593 * We need to make sure we are only accessing valid memory, and
594 * we don't read something in the async space that can hang forever
595 */
596 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800597#if L2_LENGTH != 0
Robin Getzf09630b2008-07-26 19:45:46 +0800598 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
599#endif
600 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
601#if L1_DATA_A_LENGTH != 0
602 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
603#endif
604#if L1_DATA_B_LENGTH != 0
605 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
606#endif
607 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
608 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
609 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
610 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
611 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
612 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
613 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
614 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
615 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
616 *val = *address;
617 return true;
618 }
619
620#if L1_CODE_LENGTH != 0
621 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
622 dma_memcpy(val, address, 2);
623 return true;
624 }
625#endif
626
627
628 return false;
629}
630
Robin Getzd3d0ac22008-08-06 17:49:27 +0800631/*
632 * decode the instruction if we are printing out the trace, as it
633 * makes things easier to follow, without running it through objdump
634 * These are the normal instructions which cause change of flow, which
635 * would be at the source of the trace buffer
636 */
637void decode_instruction(unsigned short *address)
638{
639 unsigned short opcode;
640
641 if (get_instruction(&opcode, address)) {
642 if (opcode == 0x0010)
643 printk("RTS");
644 else if (opcode == 0x0011)
645 printk("RTI");
646 else if (opcode == 0x0012)
647 printk("RTX");
648 else if (opcode >= 0x0050 && opcode <= 0x0057)
649 printk("JUMP (P%i)", opcode & 7);
650 else if (opcode >= 0x0060 && opcode <= 0x0067)
651 printk("CALL (P%i)", opcode & 7);
652 else if (opcode >= 0x0070 && opcode <= 0x0077)
653 printk("CALL (PC+P%i)", opcode & 7);
654 else if (opcode >= 0x0080 && opcode <= 0x0087)
655 printk("JUMP (PC+P%i)", opcode & 7);
656 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
657 printk("IF !CC JUMP");
658 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
659 printk("IF CC JUMP");
660 else if (opcode >= 0x2000 && opcode <= 0x2fff)
661 printk("JUMP.S");
662 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
663 printk("LSETUP");
664 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
665 printk("JUMP.L");
666 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
667 printk("CALL pcrel");
668 else
669 printk("0x%04x", opcode);
670 }
671
672}
673
Bryan Wu1394f032007-05-06 14:50:22 -0700674void dump_bfin_trace_buffer(void)
675{
Robin Getz518039b2007-07-25 11:03:28 +0800676#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
677 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800678 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800679 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800680#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
681 int j, index;
682#endif
683
Bryan Wu1394f032007-05-06 14:50:22 -0700684 trace_buffer_save(tflags);
685
Robin Getz226eb1e2007-10-29 17:59:07 +0800686 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800687
Robin Getzd3d0ac22008-08-06 17:49:27 +0800688#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
689 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
690#endif
691
Bryan Wu1394f032007-05-06 14:50:22 -0700692 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800693 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800694 decode_address(buf, (unsigned long)bfin_read_TBUF());
695 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800696 addr = (unsigned short *)bfin_read_TBUF();
697 decode_address(buf, (unsigned long)addr);
698 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800699 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800700 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700701 }
702 }
703
Robin Getz518039b2007-07-25 11:03:28 +0800704#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
705 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800706 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800707 else
708 index = EXPAND_LEN;
709
710 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
711 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800712 decode_address(buf, software_trace_buff[index]);
713 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800714 index -= 1;
715 if (index < 0 )
716 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800717 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800718 printk(KERN_NOTICE " Source : %s ", buf);
719 decode_instruction((unsigned short *)software_trace_buff[index]);
720 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800721 index -= 1;
722 if (index < 0)
723 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800724 j--;
725 i++;
726 }
727#endif
728
Bryan Wu1394f032007-05-06 14:50:22 -0700729 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800730#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700731}
732EXPORT_SYMBOL(dump_bfin_trace_buffer);
733
Robin Getzf09630b2008-07-26 19:45:46 +0800734/*
735 * Checks to see if the address pointed to is either a
736 * 16-bit CALL instruction, or a 32-bit CALL instruction
737 */
738bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700739{
Robin Getzf09630b2008-07-26 19:45:46 +0800740 unsigned short opcode = 0, *ins_addr;
741 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700742
Robin Getzf09630b2008-07-26 19:45:46 +0800743 if (!get_instruction(&opcode, ins_addr))
744 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700745
Robin Getzf09630b2008-07-26 19:45:46 +0800746 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
747 (opcode >= 0x0070 && opcode <= 0x0077))
748 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700749
Robin Getzf09630b2008-07-26 19:45:46 +0800750 ins_addr--;
751 if (!get_instruction(&opcode, ins_addr))
752 return false;
753
754 if (opcode >= 0xE300 && opcode <= 0xE3FF)
755 return true;
756
757 return false;
758
Bryan Wu1394f032007-05-06 14:50:22 -0700759}
Bryan Wu1394f032007-05-06 14:50:22 -0700760void show_stack(struct task_struct *task, unsigned long *stack)
761{
Robin Getzf09630b2008-07-26 19:45:46 +0800762 unsigned int *addr, *endstack, *fp = 0, *frame;
763 unsigned short *ins_addr;
764 char buf[150];
765 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700766
Robin Getzf09630b2008-07-26 19:45:46 +0800767 /*
768 * If we have been passed a specific stack, use that one otherwise
769 * if we have been passed a task structure, use that, otherwise
770 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700771 */
772
Robin Getzf09630b2008-07-26 19:45:46 +0800773 if (stack == NULL) {
774 if (task) {
775 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700776 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800777 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
778 } else {
779 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700780 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800781 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
782 }
783 } else
784 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
785
786 decode_address(buf, (unsigned int)stack);
787 printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
788 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
789
790 /* First thing is to look for a frame pointer */
791 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
792 addr < endstack; addr++, i++) {
793 if (*addr & 0x1)
794 continue;
795 ins_addr = (unsigned short *)*addr;
796 ins_addr--;
797 if (is_bfin_call(ins_addr))
798 fp = addr - 1;
799
800 if (fp) {
801 /* Let's check to see if it is a frame pointer */
802 while (fp >= (addr - 1) && fp < endstack && fp)
803 fp = (unsigned int *)*fp;
804 if (fp == 0 || fp == endstack) {
805 fp = addr - 1;
806 break;
807 }
808 fp = 0;
809 }
810 }
811 if (fp) {
812 frame = fp;
813 printk(" FP: (0x%p)\n", fp);
814 } else
815 frame = 0;
816
817 /*
818 * Now that we think we know where things are, we
819 * walk the stack again, this time printing things out
820 * incase there is no frame pointer, we still look for
821 * valid return addresses
822 */
823
824 /* First time print out data, next time, print out symbols */
825 for (j = 0; j <= 1; j++) {
826 if (j)
827 printk(KERN_NOTICE "Return addresses in stack:\n");
828 else
829 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
830
831 fp = frame;
832 frame_no = 0;
833
834 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
835 addr <= endstack; addr++, i++) {
836
837 ret_addr = 0;
838 if (!j && i % 8 == 0)
839 printk("\n" KERN_NOTICE "%p:",addr);
840
841 /* if it is an odd address, or zero, just skip it */
842 if (*addr & 0x1 || !*addr)
843 goto print;
844
845 ins_addr = (unsigned short *)*addr;
846
847 /* Go back one instruction, and see if it is a CALL */
848 ins_addr--;
849 ret_addr = is_bfin_call(ins_addr);
850 print:
851 if (!j && stack == (unsigned long *)addr)
852 printk("[%08x]", *addr);
853 else if (ret_addr)
854 if (j) {
855 decode_address(buf, (unsigned int)*addr);
856 if (frame == addr) {
857 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
858 continue;
859 }
860 printk(KERN_NOTICE " address : %s\n", buf);
861 } else
862 printk("<%08x>", *addr);
863 else if (fp == addr) {
864 if (j)
865 frame = addr+1;
866 else
867 printk("(%08x)", *addr);
868
869 fp = (unsigned int *)*addr;
870 frame_no++;
871
872 } else if (!j)
873 printk(" %08x ", *addr);
874 }
875 if (!j)
876 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700877 }
878
Bryan Wu1394f032007-05-06 14:50:22 -0700879}
880
881void dump_stack(void)
882{
883 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800884#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700885 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800886#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700887 trace_buffer_save(tflags);
888 dump_bfin_trace_buffer();
889 show_stack(current, &stack);
890 trace_buffer_restore(tflags);
891}
Bryan Wu1394f032007-05-06 14:50:22 -0700892EXPORT_SYMBOL(dump_stack);
893
Mike Frysinger49dce912007-11-21 16:46:49 +0800894void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700895{
Mike Frysinger49dce912007-11-21 16:46:49 +0800896 /* We should be able to look at fp->ipend, but we don't push it on the
897 * stack all the time, so do this until we fix that */
898 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800899
Mike Frysinger49dce912007-11-21 16:46:49 +0800900 if (oops_in_progress)
901 printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800902
Robin Getzb03b08b2007-12-23 22:57:01 +0800903 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
904 printk(KERN_NOTICE "HW Error context\n");
905 else if (context & 0x0020)
Mike Frysingera3acf522008-02-02 15:45:27 +0800906 printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800907 else if (context & 0x3FC0)
908 printk(KERN_NOTICE "Interrupt context\n");
909 else if (context & 0x4000)
910 printk(KERN_NOTICE "Deferred Interrupt context\n");
911 else if (context & 0x8000)
912 printk(KERN_NOTICE "Kernel process context\n");
913
Robin Getz9a62ca42008-03-26 09:15:58 +0800914 /* Because we are crashing, and pointers could be bad, we check things
915 * pretty closely before we use them
916 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800917 if ((unsigned long)current >= FIXED_CODE_START &&
918 !((unsigned long)current & 0x3) && current->pid) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800919 printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800920 if (current->comm >= (char *)FIXED_CODE_START)
921 printk(KERN_NOTICE "COMM=%s PID=%d\n",
922 current->comm, current->pid);
923 else
924 printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800925
Robin Getz9a62ca42008-03-26 09:15:58 +0800926 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
927 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
928 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
929 KERN_NOTICE "\n",
930 (void *)current->mm->start_code,
931 (void *)current->mm->end_code,
932 (void *)current->mm->start_data,
933 (void *)current->mm->end_data,
934 (void *)current->mm->end_data,
935 (void *)current->mm->brk,
936 (void *)current->mm->start_stack);
937 else
938 printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800939 } else
940 printk(KERN_NOTICE "\n" KERN_NOTICE
941 "No Valid process in current context\n");
942}
943
Robin Getzb03b08b2007-12-23 22:57:01 +0800944void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +0800945{
Robin Getzb03b08b2007-12-23 22:57:01 +0800946 unsigned short *addr, *erraddr, val = 0, err = 0;
947 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -0700948
Bernd Schmidt5d750b92008-04-25 05:02:33 +0800949 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +0800950
Robin Getzb03b08b2007-12-23 22:57:01 +0800951 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
952
953 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
954 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
955 addr++) {
956 if (!((unsigned long)addr & 0xF))
957 printk("\n" KERN_NOTICE "0x%p: ", addr);
958
Robin Getzf09630b2008-07-26 19:45:46 +0800959 if (get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +0800960 val = 0;
961 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +0800962 } else
963 sprintf(buf, "%04x", val);
964
965 if (addr == erraddr) {
966 printk("[%s]", buf);
967 err = val;
968 } else
969 printk(" %s ", buf);
970
971 /* Do any previous instructions turn on interrupts? */
972 if (addr <= erraddr && /* in the past */
973 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
974 val == 0x017b)) /* [SP++] = RETI */
975 sti = 1;
976 }
977
978 printk("\n");
979
980 /* Hardware error interrupts can be deferred */
981 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
982 oops_in_progress)){
983 printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700984#ifndef CONFIG_DEBUG_HWERR
Robin Getzb03b08b2007-12-23 22:57:01 +0800985 printk(KERN_NOTICE "The remaining message may be meaningless\n"
986 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
987 " better idea where it came from\n");
988#else
989 /* If we are handling only one peripheral interrupt
990 * and current mm and pid are valid, and the last error
991 * was in that user space process's text area
992 * print it out - because that is where the problem exists
993 */
994 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
995 (current->pid && current->mm)) {
996 /* And the last RETI points to the current userspace context */
997 if ((fp + 1)->pc >= current->mm->start_code &&
998 (fp + 1)->pc <= current->mm->end_code) {
999 printk(KERN_NOTICE "It might be better to look around here : \n");
1000 printk(KERN_NOTICE "-------------------------------------------\n");
1001 show_regs(fp + 1);
1002 printk(KERN_NOTICE "-------------------------------------------\n");
1003 }
Bryan Wu1394f032007-05-06 14:50:22 -07001004 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001005#endif
1006 }
Mike Frysinger49dce912007-11-21 16:46:49 +08001007}
1008
1009void show_regs(struct pt_regs *fp)
1010{
1011 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001012 struct irqaction *action;
1013 unsigned int i;
1014 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -07001015
Robin Getzaee3a292008-01-11 16:53:00 +08001016 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
Robin Getz226eb1e2007-10-29 17:59:07 +08001017 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1018 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz13fe24f2008-01-27 15:38:56 +08001019 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1020 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1021 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1022 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getzd8f66c82007-12-24 15:27:56 +08001023 for (i = 6; i <= 15 ; i++) {
1024 if (fp->ipend & (1 << i)) {
1025 decode_address(buf, bfin_read32(EVT0 + 4*i));
1026 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1027 }
1028 }
1029
1030 /* if no interrupts are going off, don't print this out */
1031 if (fp->ipend & ~0x3F) {
1032 for (i = 0; i < (NR_IRQS - 1); i++) {
1033 spin_lock_irqsave(&irq_desc[i].lock, flags);
1034 action = irq_desc[i].action;
1035 if (!action)
1036 goto unlock;
1037
1038 decode_address(buf, (unsigned int)action->handler);
1039 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1040 for (action = action->next; action; action = action->next) {
1041 decode_address(buf, (unsigned int)action->handler);
1042 printk(", %s", buf);
1043 }
1044 printk("\n");
1045unlock:
1046 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1047 }
1048 }
Bryan Wu1394f032007-05-06 14:50:22 -07001049
Robin Getz226eb1e2007-10-29 17:59:07 +08001050 decode_address(buf, fp->rete);
1051 printk(KERN_NOTICE " RETE: %s\n", buf);
1052 decode_address(buf, fp->retn);
1053 printk(KERN_NOTICE " RETN: %s\n", buf);
1054 decode_address(buf, fp->retx);
1055 printk(KERN_NOTICE " RETX: %s\n", buf);
1056 decode_address(buf, fp->rets);
1057 printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001058 decode_address(buf, fp->pc);
Robin Getz13fe24f2008-01-27 15:38:56 +08001059 printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001060
Robin Getz13fe24f2008-01-27 15:38:56 +08001061 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1062 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001063 decode_address(buf, saved_dcplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001064 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001065 decode_address(buf, saved_icplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001066 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001067 }
1068
Robin Getz226eb1e2007-10-29 17:59:07 +08001069 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1070 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1071 fp->r0, fp->r1, fp->r2, fp->r3);
1072 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1073 fp->r4, fp->r5, fp->r6, fp->r7);
1074 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1075 fp->p0, fp->p1, fp->p2, fp->p3);
1076 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1077 fp->p4, fp->p5, fp->fp, (long)fp);
1078 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1079 fp->lb0, fp->lt0, fp->lc0);
1080 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1081 fp->lb1, fp->lt1, fp->lc1);
1082 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1083 fp->b0, fp->l0, fp->m0, fp->i0);
1084 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1085 fp->b1, fp->l1, fp->m1, fp->i1);
1086 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1087 fp->b2, fp->l2, fp->m2, fp->i2);
1088 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1089 fp->b3, fp->l3, fp->m3, fp->i3);
1090 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1091 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1092
1093 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1094 rdusp(), fp->astat);
1095
1096 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001097}
1098
1099#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1100asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1101#endif
1102
1103asmlinkage int sys_bfin_spinlock(int *spinlock)
1104{
1105 int ret = 0;
1106 int tmp = 0;
1107
1108 local_irq_disable();
1109 ret = get_user(tmp, spinlock);
1110 if (ret == 0) {
1111 if (tmp)
1112 ret = 1;
1113 tmp = 1;
1114 put_user(tmp, spinlock);
1115 }
1116 local_irq_enable();
1117 return ret;
1118}
1119
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001120int bfin_request_exception(unsigned int exception, void (*handler)(void))
1121{
1122 void (*curr_handler)(void);
1123
1124 if (exception > 0x3F)
1125 return -EINVAL;
1126
1127 curr_handler = ex_table[exception];
1128
1129 if (curr_handler != ex_replaceable)
1130 return -EBUSY;
1131
1132 ex_table[exception] = handler;
1133
1134 return 0;
1135}
1136EXPORT_SYMBOL(bfin_request_exception);
1137
1138int bfin_free_exception(unsigned int exception, void (*handler)(void))
1139{
1140 void (*curr_handler)(void);
1141
1142 if (exception > 0x3F)
1143 return -EINVAL;
1144
1145 curr_handler = ex_table[exception];
1146
1147 if (curr_handler != handler)
1148 return -EBUSY;
1149
1150 ex_table[exception] = ex_replaceable;
1151
1152 return 0;
1153}
1154EXPORT_SYMBOL(bfin_free_exception);
1155
Bryan Wu1394f032007-05-06 14:50:22 -07001156void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1157{
1158 switch (cplb_panic) {
1159 case CPLB_NO_UNLOCKED:
1160 printk(KERN_EMERG "All CPLBs are locked\n");
1161 break;
1162 case CPLB_PROT_VIOL:
1163 return;
1164 case CPLB_NO_ADDR_MATCH:
1165 return;
1166 case CPLB_UNKNOWN_ERR:
1167 printk(KERN_EMERG "Unknown CPLB Exception\n");
1168 break;
1169 }
1170
Robin Getz226eb1e2007-10-29 17:59:07 +08001171 oops_in_progress = 1;
1172
Mike Frysinger49dce912007-11-21 16:46:49 +08001173 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001174 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001175 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001176 dump_stack();
1177 panic("Unrecoverable event\n");
1178}