blob: 9a9d5083acfdde5e2cae73830c79b9dcdf478030 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/kernel/traps.c
3 * Based on:
4 * Author: Hamish Macdonald
5 *
6 * Created:
7 * Description: uses S/W interrupt 15 for the system calls
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080030#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -070031#include <linux/interrupt.h>
32#include <linux/module.h>
33#include <linux/kallsyms.h>
Bryan Wud31c5ab2007-08-10 13:00:42 -070034#include <linux/fs.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080035#include <asm/traps.h>
36#include <asm/cacheflush.h>
37#include <asm/blackfin.h>
38#include <asm/irq_handler.h>
Robin Getzd8f66c82007-12-24 15:27:56 +080039#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080040#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080041#include <asm/fixed_code.h>
Robin Getzb03b08b2007-12-23 22:57:01 +080042#include <asm/dma.h>
Bryan Wu1394f032007-05-06 14:50:22 -070043
44#ifdef CONFIG_KGDB
45# include <linux/debugger.h>
46# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080047
48# define CHK_DEBUGGER_TRAP() \
49 do { \
50 CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \
51 } while (0)
52# define CHK_DEBUGGER_TRAP_MAYBE() \
53 do { \
54 if (kgdb_connected) \
55 CHK_DEBUGGER_TRAP(); \
56 } while (0)
57#else
58# define CHK_DEBUGGER_TRAP() do { } while (0)
59# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070060#endif
61
62/* Initiate the event table handler */
63void __init trap_init(void)
64{
65 CSYNC();
66 bfin_write_EVT3(trap);
67 CSYNC();
68}
69
Mike Frysingerbd628bd2008-06-03 12:23:45 +080070unsigned long saved_icplb_fault_addr, saved_dcplb_fault_addr;
Bernd Schmidt5d750b92008-04-25 05:02:33 +080071
Robin Getz226eb1e2007-10-29 17:59:07 +080072static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070073{
74 struct vm_list_struct *vml;
75 struct task_struct *p;
76 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080077 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080078 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -070079
80#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080081 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070082 const char *symname;
83 char *modname;
84 char *delim = ":";
85 char namebuf[128];
86
87 /* look up the address and see if we are in kernel space */
88 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
89
90 if (symname) {
91 /* yeah! kernel space! */
92 if (!modname)
93 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +080094 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080095 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -070096 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +080097 return;
Bryan Wu1394f032007-05-06 14:50:22 -070098
99 }
100#endif
101
Robin Getz226eb1e2007-10-29 17:59:07 +0800102 /* Problem in fixed code section? */
103 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
104 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
105 return;
106 }
107
108 /* Problem somewhere before the kernel start address */
109 if (address < CONFIG_BOOT_LOAD) {
110 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
111 return;
112 }
113
Bryan Wu1394f032007-05-06 14:50:22 -0700114 /* looks like we're off in user-land, so let's walk all the
115 * mappings of all our processes and see if we can't be a whee
116 * bit more specific
117 */
Robin Getz885be032007-10-29 17:20:41 +0800118 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700119 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800120 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700121 if (!mm)
122 continue;
123
124 vml = mm->context.vmlist;
125 while (vml) {
126 struct vm_area_struct *vma = vml->vma;
127
128 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800129 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700130 char *name = p->comm;
131 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800132
133 if (file)
134 name = d_path(&file->f_path, _tmpbuf,
135 sizeof(_tmpbuf));
Bryan Wu1394f032007-05-06 14:50:22 -0700136
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800137 /* FLAT does not have its text aligned to the start of
138 * the map while FDPIC ELF does ...
139 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800140
Robin Getz7f1c9062008-04-25 03:36:31 +0800141 /* before we can check flat/fdpic, we need to
142 * make sure current is valid
143 */
144 if ((unsigned long)current >= FIXED_CODE_START &&
145 !((unsigned long)current & 0x3)) {
146 if (current->mm &&
147 (address > current->mm->start_code) &&
148 (address < current->mm->end_code))
149 offset = address - current->mm->start_code;
150 else
151 offset = (address - vma->vm_start) +
152 (vma->vm_pgoff << PAGE_SHIFT);
153
154 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
155 (void *)address, name, offset);
156 } else
157 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
158 (void *)address, name,
159 vma->vm_start, vma->vm_end);
160
Robin Getz904656c2008-03-26 09:17:43 +0800161 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800162 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800163
Robin Getzf09630b2008-07-26 19:45:46 +0800164 if (!strlen(buf))
165 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
166
Robin Getz885be032007-10-29 17:20:41 +0800167 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700168 }
169
170 vml = vml->next;
171 }
Robin Getz904656c2008-03-26 09:17:43 +0800172 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800173 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700174 }
Bryan Wu1394f032007-05-06 14:50:22 -0700175
176 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800177 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800178
179done:
180 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700181}
182
Robin Getz2ebcade2007-10-09 17:24:30 +0800183asmlinkage void double_fault_c(struct pt_regs *fp)
184{
Robin Getz226eb1e2007-10-29 17:59:07 +0800185 console_verbose();
186 oops_in_progress = 1;
Robin Getz2ebcade2007-10-09 17:24:30 +0800187 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800188 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800189 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800190 show_regs(fp);
Robin Getz2ebcade2007-10-09 17:24:30 +0800191 panic("Double Fault - unrecoverable event\n");
192
193}
194
Bryan Wu1394f032007-05-06 14:50:22 -0700195asmlinkage void trap_c(struct pt_regs *fp)
196{
Robin Getz518039b2007-07-25 11:03:28 +0800197#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
198 int j;
199#endif
200 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700201 siginfo_t info;
202 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
203
Bryan Wu1394f032007-05-06 14:50:22 -0700204 trace_buffer_save(j);
205
Robin Getz226eb1e2007-10-29 17:59:07 +0800206 /* Important - be very careful dereferncing pointers - will lead to
207 * double faults if the stack has become corrupt
208 */
209
210 /* If the fault was caused by a kernel thread, or interrupt handler
211 * we will kernel panic, so the system reboots.
212 * If KGDB is enabled, don't set this for kernel breakpoints
213 */
Robin Getzb03b08b2007-12-23 22:57:01 +0800214
215 /* TODO: check to see if we are in some sort of deferred HWERR
216 * that we should be able to recover from, not kernel panic
217 */
Robin Getz6b5eace2008-01-10 17:57:56 +0800218 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
Robin Getz226eb1e2007-10-29 17:59:07 +0800219#ifdef CONFIG_KGDB
Robin Getz6b5eace2008-01-10 17:57:56 +0800220 && (trapnr != VEC_EXCPT02)
Robin Getz226eb1e2007-10-29 17:59:07 +0800221#endif
222 ){
223 console_verbose();
224 oops_in_progress = 1;
225 } else if (current) {
226 if (current->mm == NULL) {
227 console_verbose();
228 oops_in_progress = 1;
229 }
230 }
231
Bryan Wu1394f032007-05-06 14:50:22 -0700232 /* trap_c() will be called for exceptions. During exceptions
233 * processing, the pc value should be set with retx value.
234 * With this change we can cleanup some code in signal.c- TODO
235 */
236 fp->orig_pc = fp->retx;
237 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
238 trapnr, fp->ipend, fp->pc, fp->retx); */
239
240 /* send the appropriate signal to the user program */
241 switch (trapnr) {
242
243 /* This table works in conjuction with the one in ./mach-common/entry.S
244 * Some exceptions are handled there (in assembly, in exception space)
245 * Some are handled here, (in C, in interrupt space)
246 * Some, like CPLB, are handled in both, where the normal path is
247 * handled in assembly/exception space, and the error path is handled
248 * here
249 */
250
251 /* 0x00 - Linux Syscall, getting here is an error */
252 /* 0x01 - userspace gdb breakpoint, handled here */
253 case VEC_EXCPT01:
254 info.si_code = TRAP_ILLTRAP;
255 sig = SIGTRAP;
256 CHK_DEBUGGER_TRAP_MAYBE();
257 /* Check if this is a breakpoint in kernel space */
258 if (fp->ipend & 0xffc0)
259 return;
260 else
261 break;
262#ifdef CONFIG_KGDB
263 case VEC_EXCPT02 : /* gdb connection */
264 info.si_code = TRAP_ILLTRAP;
265 sig = SIGTRAP;
266 CHK_DEBUGGER_TRAP();
267 return;
268#else
269 /* 0x02 - User Defined, Caught by default */
270#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800271 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700272 case VEC_EXCPT03:
273 info.si_code = SEGV_STACKFLOW;
274 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800275 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700276 CHK_DEBUGGER_TRAP();
277 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800278 /* 0x04 - User Defined, Caught by default */
Bryan Wu1394f032007-05-06 14:50:22 -0700279 /* 0x05 - User Defined, Caught by default */
280 /* 0x06 - User Defined, Caught by default */
281 /* 0x07 - User Defined, Caught by default */
282 /* 0x08 - User Defined, Caught by default */
283 /* 0x09 - User Defined, Caught by default */
284 /* 0x0A - User Defined, Caught by default */
285 /* 0x0B - User Defined, Caught by default */
286 /* 0x0C - User Defined, Caught by default */
287 /* 0x0D - User Defined, Caught by default */
288 /* 0x0E - User Defined, Caught by default */
289 /* 0x0F - User Defined, Caught by default */
290 /* 0x10 HW Single step, handled here */
291 case VEC_STEP:
292 info.si_code = TRAP_STEP;
293 sig = SIGTRAP;
294 CHK_DEBUGGER_TRAP_MAYBE();
295 /* Check if this is a single step in kernel space */
296 if (fp->ipend & 0xffc0)
297 return;
298 else
299 break;
300 /* 0x11 - Trace Buffer Full, handled here */
301 case VEC_OVFLOW:
302 info.si_code = TRAP_TRACEFLOW;
303 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800304 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700305 CHK_DEBUGGER_TRAP();
306 break;
307 /* 0x12 - Reserved, Caught by default */
308 /* 0x13 - Reserved, Caught by default */
309 /* 0x14 - Reserved, Caught by default */
310 /* 0x15 - Reserved, Caught by default */
311 /* 0x16 - Reserved, Caught by default */
312 /* 0x17 - Reserved, Caught by default */
313 /* 0x18 - Reserved, Caught by default */
314 /* 0x19 - Reserved, Caught by default */
315 /* 0x1A - Reserved, Caught by default */
316 /* 0x1B - Reserved, Caught by default */
317 /* 0x1C - Reserved, Caught by default */
318 /* 0x1D - Reserved, Caught by default */
319 /* 0x1E - Reserved, Caught by default */
320 /* 0x1F - Reserved, Caught by default */
321 /* 0x20 - Reserved, Caught by default */
322 /* 0x21 - Undefined Instruction, handled here */
323 case VEC_UNDEF_I:
324 info.si_code = ILL_ILLOPC;
325 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800326 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700327 CHK_DEBUGGER_TRAP();
328 break;
329 /* 0x22 - Illegal Instruction Combination, handled here */
330 case VEC_ILGAL_I:
331 info.si_code = ILL_ILLPARAOP;
332 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800333 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700334 CHK_DEBUGGER_TRAP();
335 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800336 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700337 case VEC_CPLB_VL:
338 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800339 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800340 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700341 CHK_DEBUGGER_TRAP();
342 break;
343 /* 0x24 - Data access misaligned, handled here */
344 case VEC_MISALI_D:
345 info.si_code = BUS_ADRALN;
346 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800347 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700348 CHK_DEBUGGER_TRAP();
349 break;
350 /* 0x25 - Unrecoverable Event, handled here */
351 case VEC_UNCOV:
352 info.si_code = ILL_ILLEXCPT;
353 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800354 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700355 CHK_DEBUGGER_TRAP();
356 break;
357 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
358 error case is handled here */
359 case VEC_CPLB_M:
360 info.si_code = BUS_ADRALN;
361 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800362 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700363 CHK_DEBUGGER_TRAP();
364 break;
365 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
366 case VEC_CPLB_MHIT:
367 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700368 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800369#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800370 if (saved_dcplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800371 printk(KERN_NOTICE "NULL pointer access\n");
372 else
Bryan Wu1394f032007-05-06 14:50:22 -0700373#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800374 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700375 CHK_DEBUGGER_TRAP();
376 break;
377 /* 0x28 - Emulation Watchpoint, handled here */
378 case VEC_WATCH:
379 info.si_code = TRAP_WATCHPT;
380 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800381 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700382 CHK_DEBUGGER_TRAP_MAYBE();
383 /* Check if this is a watchpoint in kernel space */
384 if (fp->ipend & 0xffc0)
385 return;
386 else
387 break;
388#ifdef CONFIG_BF535
389 /* 0x29 - Instruction fetch access error (535 only) */
390 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
391 info.si_code = BUS_OPFETCH;
392 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800393 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700394 CHK_DEBUGGER_TRAP();
395 break;
396#else
397 /* 0x29 - Reserved, Caught by default */
398#endif
399 /* 0x2A - Instruction fetch misaligned, handled here */
400 case VEC_MISALI_I:
401 info.si_code = BUS_ADRALN;
402 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800403 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700404 CHK_DEBUGGER_TRAP();
405 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800406 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700407 case VEC_CPLB_I_VL:
408 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800409 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800410 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700411 CHK_DEBUGGER_TRAP();
412 break;
413 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
414 case VEC_CPLB_I_M:
415 info.si_code = ILL_CPLB_MISS;
416 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800417 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700418 CHK_DEBUGGER_TRAP();
419 break;
420 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
421 case VEC_CPLB_I_MHIT:
422 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700423 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800424#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800425 if (saved_icplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800426 printk(KERN_NOTICE "Jump to NULL address\n");
427 else
Bryan Wu1394f032007-05-06 14:50:22 -0700428#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800429 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700430 CHK_DEBUGGER_TRAP();
431 break;
432 /* 0x2E - Illegal use of Supervisor Resource, handled here */
433 case VEC_ILL_RES:
434 info.si_code = ILL_PRVOPC;
435 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800436 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700437 CHK_DEBUGGER_TRAP();
438 break;
439 /* 0x2F - Reserved, Caught by default */
440 /* 0x30 - Reserved, Caught by default */
441 /* 0x31 - Reserved, Caught by default */
442 /* 0x32 - Reserved, Caught by default */
443 /* 0x33 - Reserved, Caught by default */
444 /* 0x34 - Reserved, Caught by default */
445 /* 0x35 - Reserved, Caught by default */
446 /* 0x36 - Reserved, Caught by default */
447 /* 0x37 - Reserved, Caught by default */
448 /* 0x38 - Reserved, Caught by default */
449 /* 0x39 - Reserved, Caught by default */
450 /* 0x3A - Reserved, Caught by default */
451 /* 0x3B - Reserved, Caught by default */
452 /* 0x3C - Reserved, Caught by default */
453 /* 0x3D - Reserved, Caught by default */
454 /* 0x3E - Reserved, Caught by default */
455 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800456 case VEC_HWERR:
457 info.si_code = BUS_ADRALN;
458 sig = SIGBUS;
459 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
460 /* System MMR Error */
461 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
462 info.si_code = BUS_ADRALN;
463 sig = SIGBUS;
464 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
465 break;
466 /* External Memory Addressing Error */
467 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
468 info.si_code = BUS_ADRERR;
469 sig = SIGBUS;
470 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
471 break;
472 /* Performance Monitor Overflow */
473 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
474 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
475 break;
476 /* RAISE 5 instruction */
477 case (SEQSTAT_HWERRCAUSE_RAISE_5):
478 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
479 break;
480 default: /* Reserved */
481 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
482 break;
483 }
484 CHK_DEBUGGER_TRAP();
485 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700486 default:
487 info.si_code = TRAP_ILLTRAP;
488 sig = SIGTRAP;
489 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
490 (fp->seqstat & SEQSTAT_EXCAUSE));
491 CHK_DEBUGGER_TRAP();
492 break;
493 }
494
Robin Getz226eb1e2007-10-29 17:59:07 +0800495 BUG_ON(sig == 0);
496
497 if (sig != SIGTRAP) {
Robin Getzf09630b2008-07-26 19:45:46 +0800498 unsigned long *stack;
Mike Frysinger49dce912007-11-21 16:46:49 +0800499 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800500 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800501 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800502
503 /* Print out the trace buffer if it makes sense */
504#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
505 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
506 printk(KERN_NOTICE "No trace since you do not have "
507 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
508 KERN_NOTICE "\n");
509 else
510#endif
511 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800512
Robin Getz226eb1e2007-10-29 17:59:07 +0800513 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800514 /* Dump the current kernel stack */
515 printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
516 show_stack(current, NULL);
517
Robin Getzaee3a292008-01-11 16:53:00 +0800518 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800519#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800520 printk(KERN_EMERG "Please turn on "
521 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800522#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700523 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800524 } else {
525 /* Dump the user space stack */
526 stack = (unsigned long *)rdusp();
527 printk(KERN_NOTICE "Userspace Stack\n");
528 show_stack(NULL, stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800529 }
Bryan Wu1394f032007-05-06 14:50:22 -0700530 }
Robin Getzfb322912007-11-21 16:38:05 +0800531
Robin Getzce3afa12007-10-09 17:28:36 +0800532 info.si_signo = sig;
533 info.si_errno = 0;
Mike Frysinger0ddeeca2008-03-07 02:37:41 +0800534 info.si_addr = (void __user *)fp->pc;
Robin Getzce3afa12007-10-09 17:28:36 +0800535 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700536
Bryan Wu1394f032007-05-06 14:50:22 -0700537 trace_buffer_restore(j);
538 return;
539}
540
541/* Typical exception handling routines */
542
Robin Getz518039b2007-07-25 11:03:28 +0800543#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
544
Robin Getzf09630b2008-07-26 19:45:46 +0800545/*
546 * Similar to get_user, do some address checking, then dereference
547 * Return true on sucess, false on bad address
548 */
549bool get_instruction(unsigned short *val, unsigned short *address)
550{
551
552 unsigned long addr;
553
554 addr = (unsigned long)address;
555
556 /* Check for odd addresses */
557 if (addr & 0x1)
558 return false;
559
560 /* Check that things do not wrap around */
561 if (addr > (addr + 2))
562 return false;
563
564 /*
565 * Since we are in exception context, we need to do a little address checking
566 * We need to make sure we are only accessing valid memory, and
567 * we don't read something in the async space that can hang forever
568 */
569 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800570#if L2_LENGTH != 0
Robin Getzf09630b2008-07-26 19:45:46 +0800571 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
572#endif
573 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
574#if L1_DATA_A_LENGTH != 0
575 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
576#endif
577#if L1_DATA_B_LENGTH != 0
578 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
579#endif
580 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
581 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
582 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
583 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
584 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
585 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
586 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
587 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
588 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
589 *val = *address;
590 return true;
591 }
592
593#if L1_CODE_LENGTH != 0
594 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
595 dma_memcpy(val, address, 2);
596 return true;
597 }
598#endif
599
600
601 return false;
602}
603
Robin Getzd3d0ac22008-08-06 17:49:27 +0800604/*
605 * decode the instruction if we are printing out the trace, as it
606 * makes things easier to follow, without running it through objdump
607 * These are the normal instructions which cause change of flow, which
608 * would be at the source of the trace buffer
609 */
610void decode_instruction(unsigned short *address)
611{
612 unsigned short opcode;
613
614 if (get_instruction(&opcode, address)) {
615 if (opcode == 0x0010)
616 printk("RTS");
617 else if (opcode == 0x0011)
618 printk("RTI");
619 else if (opcode == 0x0012)
620 printk("RTX");
621 else if (opcode >= 0x0050 && opcode <= 0x0057)
622 printk("JUMP (P%i)", opcode & 7);
623 else if (opcode >= 0x0060 && opcode <= 0x0067)
624 printk("CALL (P%i)", opcode & 7);
625 else if (opcode >= 0x0070 && opcode <= 0x0077)
626 printk("CALL (PC+P%i)", opcode & 7);
627 else if (opcode >= 0x0080 && opcode <= 0x0087)
628 printk("JUMP (PC+P%i)", opcode & 7);
629 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
630 printk("IF !CC JUMP");
631 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
632 printk("IF CC JUMP");
633 else if (opcode >= 0x2000 && opcode <= 0x2fff)
634 printk("JUMP.S");
635 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
636 printk("LSETUP");
637 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
638 printk("JUMP.L");
639 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
640 printk("CALL pcrel");
641 else
642 printk("0x%04x", opcode);
643 }
644
645}
646
Bryan Wu1394f032007-05-06 14:50:22 -0700647void dump_bfin_trace_buffer(void)
648{
Robin Getz518039b2007-07-25 11:03:28 +0800649#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
650 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800651 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800652 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800653#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
654 int j, index;
655#endif
656
Bryan Wu1394f032007-05-06 14:50:22 -0700657 trace_buffer_save(tflags);
658
Robin Getz226eb1e2007-10-29 17:59:07 +0800659 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800660
Robin Getzd3d0ac22008-08-06 17:49:27 +0800661#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
662 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
663#endif
664
Bryan Wu1394f032007-05-06 14:50:22 -0700665 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800666 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800667 decode_address(buf, (unsigned long)bfin_read_TBUF());
668 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800669 addr = (unsigned short *)bfin_read_TBUF();
670 decode_address(buf, (unsigned long)addr);
671 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800672 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800673 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700674 }
675 }
676
Robin Getz518039b2007-07-25 11:03:28 +0800677#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
678 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800679 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800680 else
681 index = EXPAND_LEN;
682
683 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
684 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800685 decode_address(buf, software_trace_buff[index]);
686 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800687 index -= 1;
688 if (index < 0 )
689 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800690 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800691 printk(KERN_NOTICE " Source : %s ", buf);
692 decode_instruction((unsigned short *)software_trace_buff[index]);
693 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800694 index -= 1;
695 if (index < 0)
696 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800697 j--;
698 i++;
699 }
700#endif
701
Bryan Wu1394f032007-05-06 14:50:22 -0700702 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800703#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700704}
705EXPORT_SYMBOL(dump_bfin_trace_buffer);
706
Robin Getzf09630b2008-07-26 19:45:46 +0800707/*
708 * Checks to see if the address pointed to is either a
709 * 16-bit CALL instruction, or a 32-bit CALL instruction
710 */
711bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700712{
Robin Getzf09630b2008-07-26 19:45:46 +0800713 unsigned short opcode = 0, *ins_addr;
714 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700715
Robin Getzf09630b2008-07-26 19:45:46 +0800716 if (!get_instruction(&opcode, ins_addr))
717 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700718
Robin Getzf09630b2008-07-26 19:45:46 +0800719 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
720 (opcode >= 0x0070 && opcode <= 0x0077))
721 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700722
Robin Getzf09630b2008-07-26 19:45:46 +0800723 ins_addr--;
724 if (!get_instruction(&opcode, ins_addr))
725 return false;
726
727 if (opcode >= 0xE300 && opcode <= 0xE3FF)
728 return true;
729
730 return false;
731
Bryan Wu1394f032007-05-06 14:50:22 -0700732}
Bryan Wu1394f032007-05-06 14:50:22 -0700733void show_stack(struct task_struct *task, unsigned long *stack)
734{
Robin Getzf09630b2008-07-26 19:45:46 +0800735 unsigned int *addr, *endstack, *fp = 0, *frame;
736 unsigned short *ins_addr;
737 char buf[150];
738 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700739
Robin Getzf09630b2008-07-26 19:45:46 +0800740 /*
741 * If we have been passed a specific stack, use that one otherwise
742 * if we have been passed a task structure, use that, otherwise
743 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700744 */
745
Robin Getzf09630b2008-07-26 19:45:46 +0800746 if (stack == NULL) {
747 if (task) {
748 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700749 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800750 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
751 } else {
752 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700753 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800754 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
755 }
756 } else
757 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
758
759 decode_address(buf, (unsigned int)stack);
760 printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
761 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
762
763 /* First thing is to look for a frame pointer */
764 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
765 addr < endstack; addr++, i++) {
766 if (*addr & 0x1)
767 continue;
768 ins_addr = (unsigned short *)*addr;
769 ins_addr--;
770 if (is_bfin_call(ins_addr))
771 fp = addr - 1;
772
773 if (fp) {
774 /* Let's check to see if it is a frame pointer */
775 while (fp >= (addr - 1) && fp < endstack && fp)
776 fp = (unsigned int *)*fp;
777 if (fp == 0 || fp == endstack) {
778 fp = addr - 1;
779 break;
780 }
781 fp = 0;
782 }
783 }
784 if (fp) {
785 frame = fp;
786 printk(" FP: (0x%p)\n", fp);
787 } else
788 frame = 0;
789
790 /*
791 * Now that we think we know where things are, we
792 * walk the stack again, this time printing things out
793 * incase there is no frame pointer, we still look for
794 * valid return addresses
795 */
796
797 /* First time print out data, next time, print out symbols */
798 for (j = 0; j <= 1; j++) {
799 if (j)
800 printk(KERN_NOTICE "Return addresses in stack:\n");
801 else
802 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
803
804 fp = frame;
805 frame_no = 0;
806
807 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
808 addr <= endstack; addr++, i++) {
809
810 ret_addr = 0;
811 if (!j && i % 8 == 0)
812 printk("\n" KERN_NOTICE "%p:",addr);
813
814 /* if it is an odd address, or zero, just skip it */
815 if (*addr & 0x1 || !*addr)
816 goto print;
817
818 ins_addr = (unsigned short *)*addr;
819
820 /* Go back one instruction, and see if it is a CALL */
821 ins_addr--;
822 ret_addr = is_bfin_call(ins_addr);
823 print:
824 if (!j && stack == (unsigned long *)addr)
825 printk("[%08x]", *addr);
826 else if (ret_addr)
827 if (j) {
828 decode_address(buf, (unsigned int)*addr);
829 if (frame == addr) {
830 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
831 continue;
832 }
833 printk(KERN_NOTICE " address : %s\n", buf);
834 } else
835 printk("<%08x>", *addr);
836 else if (fp == addr) {
837 if (j)
838 frame = addr+1;
839 else
840 printk("(%08x)", *addr);
841
842 fp = (unsigned int *)*addr;
843 frame_no++;
844
845 } else if (!j)
846 printk(" %08x ", *addr);
847 }
848 if (!j)
849 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700850 }
851
Bryan Wu1394f032007-05-06 14:50:22 -0700852}
853
854void dump_stack(void)
855{
856 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800857#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700858 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800859#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700860 trace_buffer_save(tflags);
861 dump_bfin_trace_buffer();
862 show_stack(current, &stack);
863 trace_buffer_restore(tflags);
864}
Bryan Wu1394f032007-05-06 14:50:22 -0700865EXPORT_SYMBOL(dump_stack);
866
Mike Frysinger49dce912007-11-21 16:46:49 +0800867void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700868{
Mike Frysinger49dce912007-11-21 16:46:49 +0800869 /* We should be able to look at fp->ipend, but we don't push it on the
870 * stack all the time, so do this until we fix that */
871 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800872
Mike Frysinger49dce912007-11-21 16:46:49 +0800873 if (oops_in_progress)
874 printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800875
Robin Getzb03b08b2007-12-23 22:57:01 +0800876 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
877 printk(KERN_NOTICE "HW Error context\n");
878 else if (context & 0x0020)
Mike Frysingera3acf522008-02-02 15:45:27 +0800879 printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800880 else if (context & 0x3FC0)
881 printk(KERN_NOTICE "Interrupt context\n");
882 else if (context & 0x4000)
883 printk(KERN_NOTICE "Deferred Interrupt context\n");
884 else if (context & 0x8000)
885 printk(KERN_NOTICE "Kernel process context\n");
886
Robin Getz9a62ca42008-03-26 09:15:58 +0800887 /* Because we are crashing, and pointers could be bad, we check things
888 * pretty closely before we use them
889 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800890 if ((unsigned long)current >= FIXED_CODE_START &&
891 !((unsigned long)current & 0x3) && current->pid) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800892 printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800893 if (current->comm >= (char *)FIXED_CODE_START)
894 printk(KERN_NOTICE "COMM=%s PID=%d\n",
895 current->comm, current->pid);
896 else
897 printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800898
Robin Getz9a62ca42008-03-26 09:15:58 +0800899 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
900 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
901 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
902 KERN_NOTICE "\n",
903 (void *)current->mm->start_code,
904 (void *)current->mm->end_code,
905 (void *)current->mm->start_data,
906 (void *)current->mm->end_data,
907 (void *)current->mm->end_data,
908 (void *)current->mm->brk,
909 (void *)current->mm->start_stack);
910 else
911 printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800912 } else
913 printk(KERN_NOTICE "\n" KERN_NOTICE
914 "No Valid process in current context\n");
915}
916
Robin Getzb03b08b2007-12-23 22:57:01 +0800917void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +0800918{
Robin Getzb03b08b2007-12-23 22:57:01 +0800919 unsigned short *addr, *erraddr, val = 0, err = 0;
920 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -0700921
Bernd Schmidt5d750b92008-04-25 05:02:33 +0800922 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +0800923
Robin Getzb03b08b2007-12-23 22:57:01 +0800924 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
925
926 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
927 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
928 addr++) {
929 if (!((unsigned long)addr & 0xF))
930 printk("\n" KERN_NOTICE "0x%p: ", addr);
931
Robin Getzf09630b2008-07-26 19:45:46 +0800932 if (get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +0800933 val = 0;
934 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +0800935 } else
936 sprintf(buf, "%04x", val);
937
938 if (addr == erraddr) {
939 printk("[%s]", buf);
940 err = val;
941 } else
942 printk(" %s ", buf);
943
944 /* Do any previous instructions turn on interrupts? */
945 if (addr <= erraddr && /* in the past */
946 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
947 val == 0x017b)) /* [SP++] = RETI */
948 sti = 1;
949 }
950
951 printk("\n");
952
953 /* Hardware error interrupts can be deferred */
954 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
955 oops_in_progress)){
956 printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700957#ifndef CONFIG_DEBUG_HWERR
Robin Getzb03b08b2007-12-23 22:57:01 +0800958 printk(KERN_NOTICE "The remaining message may be meaningless\n"
959 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
960 " better idea where it came from\n");
961#else
962 /* If we are handling only one peripheral interrupt
963 * and current mm and pid are valid, and the last error
964 * was in that user space process's text area
965 * print it out - because that is where the problem exists
966 */
967 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
968 (current->pid && current->mm)) {
969 /* And the last RETI points to the current userspace context */
970 if ((fp + 1)->pc >= current->mm->start_code &&
971 (fp + 1)->pc <= current->mm->end_code) {
972 printk(KERN_NOTICE "It might be better to look around here : \n");
973 printk(KERN_NOTICE "-------------------------------------------\n");
974 show_regs(fp + 1);
975 printk(KERN_NOTICE "-------------------------------------------\n");
976 }
Bryan Wu1394f032007-05-06 14:50:22 -0700977 }
Robin Getzb03b08b2007-12-23 22:57:01 +0800978#endif
979 }
Mike Frysinger49dce912007-11-21 16:46:49 +0800980}
981
982void show_regs(struct pt_regs *fp)
983{
984 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +0800985 struct irqaction *action;
986 unsigned int i;
987 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700988
Robin Getzaee3a292008-01-11 16:53:00 +0800989 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
Robin Getz226eb1e2007-10-29 17:59:07 +0800990 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
991 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz13fe24f2008-01-27 15:38:56 +0800992 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
993 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
994 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
995 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getzd8f66c82007-12-24 15:27:56 +0800996 for (i = 6; i <= 15 ; i++) {
997 if (fp->ipend & (1 << i)) {
998 decode_address(buf, bfin_read32(EVT0 + 4*i));
999 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1000 }
1001 }
1002
1003 /* if no interrupts are going off, don't print this out */
1004 if (fp->ipend & ~0x3F) {
1005 for (i = 0; i < (NR_IRQS - 1); i++) {
1006 spin_lock_irqsave(&irq_desc[i].lock, flags);
1007 action = irq_desc[i].action;
1008 if (!action)
1009 goto unlock;
1010
1011 decode_address(buf, (unsigned int)action->handler);
1012 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1013 for (action = action->next; action; action = action->next) {
1014 decode_address(buf, (unsigned int)action->handler);
1015 printk(", %s", buf);
1016 }
1017 printk("\n");
1018unlock:
1019 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1020 }
1021 }
Bryan Wu1394f032007-05-06 14:50:22 -07001022
Robin Getz226eb1e2007-10-29 17:59:07 +08001023 decode_address(buf, fp->rete);
1024 printk(KERN_NOTICE " RETE: %s\n", buf);
1025 decode_address(buf, fp->retn);
1026 printk(KERN_NOTICE " RETN: %s\n", buf);
1027 decode_address(buf, fp->retx);
1028 printk(KERN_NOTICE " RETX: %s\n", buf);
1029 decode_address(buf, fp->rets);
1030 printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001031 decode_address(buf, fp->pc);
Robin Getz13fe24f2008-01-27 15:38:56 +08001032 printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001033
Robin Getz13fe24f2008-01-27 15:38:56 +08001034 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1035 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001036 decode_address(buf, saved_dcplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001037 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001038 decode_address(buf, saved_icplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001039 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001040 }
1041
Robin Getz226eb1e2007-10-29 17:59:07 +08001042 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1043 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1044 fp->r0, fp->r1, fp->r2, fp->r3);
1045 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1046 fp->r4, fp->r5, fp->r6, fp->r7);
1047 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1048 fp->p0, fp->p1, fp->p2, fp->p3);
1049 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1050 fp->p4, fp->p5, fp->fp, (long)fp);
1051 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1052 fp->lb0, fp->lt0, fp->lc0);
1053 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1054 fp->lb1, fp->lt1, fp->lc1);
1055 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1056 fp->b0, fp->l0, fp->m0, fp->i0);
1057 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1058 fp->b1, fp->l1, fp->m1, fp->i1);
1059 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1060 fp->b2, fp->l2, fp->m2, fp->i2);
1061 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1062 fp->b3, fp->l3, fp->m3, fp->i3);
1063 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1064 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1065
1066 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1067 rdusp(), fp->astat);
1068
1069 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001070}
1071
1072#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1073asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1074#endif
1075
1076asmlinkage int sys_bfin_spinlock(int *spinlock)
1077{
1078 int ret = 0;
1079 int tmp = 0;
1080
1081 local_irq_disable();
1082 ret = get_user(tmp, spinlock);
1083 if (ret == 0) {
1084 if (tmp)
1085 ret = 1;
1086 tmp = 1;
1087 put_user(tmp, spinlock);
1088 }
1089 local_irq_enable();
1090 return ret;
1091}
1092
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001093int bfin_request_exception(unsigned int exception, void (*handler)(void))
1094{
1095 void (*curr_handler)(void);
1096
1097 if (exception > 0x3F)
1098 return -EINVAL;
1099
1100 curr_handler = ex_table[exception];
1101
1102 if (curr_handler != ex_replaceable)
1103 return -EBUSY;
1104
1105 ex_table[exception] = handler;
1106
1107 return 0;
1108}
1109EXPORT_SYMBOL(bfin_request_exception);
1110
1111int bfin_free_exception(unsigned int exception, void (*handler)(void))
1112{
1113 void (*curr_handler)(void);
1114
1115 if (exception > 0x3F)
1116 return -EINVAL;
1117
1118 curr_handler = ex_table[exception];
1119
1120 if (curr_handler != handler)
1121 return -EBUSY;
1122
1123 ex_table[exception] = ex_replaceable;
1124
1125 return 0;
1126}
1127EXPORT_SYMBOL(bfin_free_exception);
1128
Bryan Wu1394f032007-05-06 14:50:22 -07001129void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1130{
1131 switch (cplb_panic) {
1132 case CPLB_NO_UNLOCKED:
1133 printk(KERN_EMERG "All CPLBs are locked\n");
1134 break;
1135 case CPLB_PROT_VIOL:
1136 return;
1137 case CPLB_NO_ADDR_MATCH:
1138 return;
1139 case CPLB_UNKNOWN_ERR:
1140 printk(KERN_EMERG "Unknown CPLB Exception\n");
1141 break;
1142 }
1143
Robin Getz226eb1e2007-10-29 17:59:07 +08001144 oops_in_progress = 1;
1145
Mike Frysinger49dce912007-11-21 16:46:49 +08001146 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001147 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001148 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001149 dump_stack();
1150 panic("Unrecoverable event\n");
1151}