blob: 0112ba407f63f27a7aa4367c5b19fca6c4aa629f [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
Bryan Wu1394f032007-05-06 14:50:22 -070046# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080047
48# define CHK_DEBUGGER_TRAP() \
49 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080050 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080051 } 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
Robin Getz0c7a6b22008-10-08 16:27:12 +080070/*
71 * Used to save the RETX, SEQSTAT, I/D CPLB FAULT ADDR
72 * values across the transition from exception to IRQ5.
73 * We put these in L1, so they are going to be in a valid
74 * location during exception context
75 */
76__attribute__((l1_data))
77unsigned long saved_retx, saved_seqstat,
78 saved_icplb_fault_addr, saved_dcplb_fault_addr;
Bernd Schmidt5d750b92008-04-25 05:02:33 +080079
Robin Getz226eb1e2007-10-29 17:59:07 +080080static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070081{
82 struct vm_list_struct *vml;
83 struct task_struct *p;
84 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080085 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080086 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -070087
88#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080089 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070090 const char *symname;
91 char *modname;
92 char *delim = ":";
93 char namebuf[128];
94
95 /* look up the address and see if we are in kernel space */
96 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
97
98 if (symname) {
99 /* yeah! kernel space! */
100 if (!modname)
101 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +0800102 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800103 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -0700104 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +0800105 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700106
107 }
108#endif
109
Robin Getz226eb1e2007-10-29 17:59:07 +0800110 /* Problem in fixed code section? */
111 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
112 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
113 return;
114 }
115
116 /* Problem somewhere before the kernel start address */
117 if (address < CONFIG_BOOT_LOAD) {
118 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
119 return;
120 }
121
Bryan Wu1394f032007-05-06 14:50:22 -0700122 /* looks like we're off in user-land, so let's walk all the
123 * mappings of all our processes and see if we can't be a whee
124 * bit more specific
125 */
Robin Getz885be032007-10-29 17:20:41 +0800126 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700127 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800128 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700129 if (!mm)
130 continue;
131
132 vml = mm->context.vmlist;
133 while (vml) {
134 struct vm_area_struct *vma = vml->vma;
135
136 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800137 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700138 char *name = p->comm;
139 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800140
141 if (file)
142 name = d_path(&file->f_path, _tmpbuf,
143 sizeof(_tmpbuf));
Bryan Wu1394f032007-05-06 14:50:22 -0700144
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800145 /* FLAT does not have its text aligned to the start of
146 * the map while FDPIC ELF does ...
147 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800148
Robin Getz7f1c9062008-04-25 03:36:31 +0800149 /* before we can check flat/fdpic, we need to
150 * make sure current is valid
151 */
152 if ((unsigned long)current >= FIXED_CODE_START &&
153 !((unsigned long)current & 0x3)) {
154 if (current->mm &&
155 (address > current->mm->start_code) &&
156 (address < current->mm->end_code))
157 offset = address - current->mm->start_code;
158 else
159 offset = (address - vma->vm_start) +
160 (vma->vm_pgoff << PAGE_SHIFT);
161
162 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
163 (void *)address, name, offset);
164 } else
165 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
166 (void *)address, name,
167 vma->vm_start, vma->vm_end);
168
Robin Getz904656c2008-03-26 09:17:43 +0800169 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800170 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800171
Robin Getzf09630b2008-07-26 19:45:46 +0800172 if (!strlen(buf))
173 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
174
Robin Getz885be032007-10-29 17:20:41 +0800175 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700176 }
177
178 vml = vml->next;
179 }
Robin Getz904656c2008-03-26 09:17:43 +0800180 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800181 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700182 }
Bryan Wu1394f032007-05-06 14:50:22 -0700183
184 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800185 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800186
187done:
188 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700189}
190
Robin Getz2ebcade2007-10-09 17:24:30 +0800191asmlinkage void double_fault_c(struct pt_regs *fp)
192{
Robin Getz226eb1e2007-10-29 17:59:07 +0800193 console_verbose();
194 oops_in_progress = 1;
Robin Getz2ebcade2007-10-09 17:24:30 +0800195 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800196#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
197 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
198 char buf[150];
199 decode_address(buf, saved_retx);
200 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
201 (int)saved_seqstat & SEQSTAT_EXCAUSE, buf);
202 decode_address(buf, saved_dcplb_fault_addr);
203 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
204 decode_address(buf, saved_icplb_fault_addr);
205 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
206
207 decode_address(buf, fp->retx);
208 printk(KERN_NOTICE "The instruction at %s caused a double exception\n",
209 buf);
210 } else
211#endif
212 {
213 dump_bfin_process(fp);
214 dump_bfin_mem(fp);
215 show_regs(fp);
216 }
Robin Getz2ebcade2007-10-09 17:24:30 +0800217 panic("Double Fault - unrecoverable event\n");
218
219}
220
Bryan Wu1394f032007-05-06 14:50:22 -0700221asmlinkage void trap_c(struct pt_regs *fp)
222{
Robin Getz518039b2007-07-25 11:03:28 +0800223#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
224 int j;
225#endif
226 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700227 siginfo_t info;
228 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
229
Bryan Wu1394f032007-05-06 14:50:22 -0700230 trace_buffer_save(j);
231
Robin Getz226eb1e2007-10-29 17:59:07 +0800232 /* Important - be very careful dereferncing pointers - will lead to
233 * double faults if the stack has become corrupt
234 */
235
236 /* If the fault was caused by a kernel thread, or interrupt handler
237 * we will kernel panic, so the system reboots.
238 * If KGDB is enabled, don't set this for kernel breakpoints
239 */
Robin Getzb03b08b2007-12-23 22:57:01 +0800240
241 /* TODO: check to see if we are in some sort of deferred HWERR
242 * that we should be able to recover from, not kernel panic
243 */
Robin Getz6b5eace2008-01-10 17:57:56 +0800244 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
Robin Getz226eb1e2007-10-29 17:59:07 +0800245#ifdef CONFIG_KGDB
Robin Getz6b5eace2008-01-10 17:57:56 +0800246 && (trapnr != VEC_EXCPT02)
Robin Getz226eb1e2007-10-29 17:59:07 +0800247#endif
248 ){
249 console_verbose();
250 oops_in_progress = 1;
251 } else if (current) {
252 if (current->mm == NULL) {
253 console_verbose();
254 oops_in_progress = 1;
255 }
256 }
257
Bryan Wu1394f032007-05-06 14:50:22 -0700258 /* trap_c() will be called for exceptions. During exceptions
259 * processing, the pc value should be set with retx value.
260 * With this change we can cleanup some code in signal.c- TODO
261 */
262 fp->orig_pc = fp->retx;
263 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
264 trapnr, fp->ipend, fp->pc, fp->retx); */
265
266 /* send the appropriate signal to the user program */
267 switch (trapnr) {
268
269 /* This table works in conjuction with the one in ./mach-common/entry.S
270 * Some exceptions are handled there (in assembly, in exception space)
271 * Some are handled here, (in C, in interrupt space)
272 * Some, like CPLB, are handled in both, where the normal path is
273 * handled in assembly/exception space, and the error path is handled
274 * here
275 */
276
277 /* 0x00 - Linux Syscall, getting here is an error */
278 /* 0x01 - userspace gdb breakpoint, handled here */
279 case VEC_EXCPT01:
280 info.si_code = TRAP_ILLTRAP;
281 sig = SIGTRAP;
282 CHK_DEBUGGER_TRAP_MAYBE();
283 /* Check if this is a breakpoint in kernel space */
284 if (fp->ipend & 0xffc0)
285 return;
286 else
287 break;
288#ifdef CONFIG_KGDB
289 case VEC_EXCPT02 : /* gdb connection */
290 info.si_code = TRAP_ILLTRAP;
291 sig = SIGTRAP;
292 CHK_DEBUGGER_TRAP();
293 return;
294#else
295 /* 0x02 - User Defined, Caught by default */
296#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800297 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700298 case VEC_EXCPT03:
299 info.si_code = SEGV_STACKFLOW;
300 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800301 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800302 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700303 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800304 /* 0x04 - User Defined */
305 /* 0x05 - User Defined */
306 /* 0x06 - User Defined */
307 /* 0x07 - User Defined */
308 /* 0x08 - User Defined */
309 /* 0x09 - User Defined */
310 /* 0x0A - User Defined */
311 /* 0x0B - User Defined */
312 /* 0x0C - User Defined */
313 /* 0x0D - User Defined */
314 /* 0x0E - User Defined */
315 /* 0x0F - User Defined */
316 /*
317 * If we got here, it is most likely that someone was trying to use a
318 * custom exception handler, and it is not actually installed properly
319 */
Robin Getz7d98c882008-10-08 16:29:01 +0800320 case VEC_EXCPT02:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800321 case VEC_EXCPT04 ... VEC_EXCPT15:
322 info.si_code = ILL_ILLPARAOP;
323 sig = SIGILL;
324 printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
325 CHK_DEBUGGER_TRAP_MAYBE();
326 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700327 /* 0x10 HW Single step, handled here */
328 case VEC_STEP:
329 info.si_code = TRAP_STEP;
330 sig = SIGTRAP;
331 CHK_DEBUGGER_TRAP_MAYBE();
332 /* Check if this is a single step in kernel space */
333 if (fp->ipend & 0xffc0)
334 return;
335 else
336 break;
337 /* 0x11 - Trace Buffer Full, handled here */
338 case VEC_OVFLOW:
339 info.si_code = TRAP_TRACEFLOW;
340 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800341 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800342 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700343 break;
344 /* 0x12 - Reserved, Caught by default */
345 /* 0x13 - Reserved, Caught by default */
346 /* 0x14 - Reserved, Caught by default */
347 /* 0x15 - Reserved, Caught by default */
348 /* 0x16 - Reserved, Caught by default */
349 /* 0x17 - Reserved, Caught by default */
350 /* 0x18 - Reserved, Caught by default */
351 /* 0x19 - Reserved, Caught by default */
352 /* 0x1A - Reserved, Caught by default */
353 /* 0x1B - Reserved, Caught by default */
354 /* 0x1C - Reserved, Caught by default */
355 /* 0x1D - Reserved, Caught by default */
356 /* 0x1E - Reserved, Caught by default */
357 /* 0x1F - Reserved, Caught by default */
358 /* 0x20 - Reserved, Caught by default */
359 /* 0x21 - Undefined Instruction, handled here */
360 case VEC_UNDEF_I:
361 info.si_code = ILL_ILLOPC;
362 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800363 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800364 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700365 break;
366 /* 0x22 - Illegal Instruction Combination, handled here */
367 case VEC_ILGAL_I:
368 info.si_code = ILL_ILLPARAOP;
369 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800370 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800371 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700372 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800373 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700374 case VEC_CPLB_VL:
375 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800376 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800377 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800378 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700379 break;
380 /* 0x24 - Data access misaligned, handled here */
381 case VEC_MISALI_D:
382 info.si_code = BUS_ADRALN;
383 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800384 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800385 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700386 break;
387 /* 0x25 - Unrecoverable Event, handled here */
388 case VEC_UNCOV:
389 info.si_code = ILL_ILLEXCPT;
390 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800391 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800392 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700393 break;
394 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
395 error case is handled here */
396 case VEC_CPLB_M:
397 info.si_code = BUS_ADRALN;
398 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800399 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700400 break;
401 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
402 case VEC_CPLB_MHIT:
403 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700404 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800405#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800406 if (saved_dcplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800407 printk(KERN_NOTICE "NULL pointer access\n");
408 else
Bryan Wu1394f032007-05-06 14:50:22 -0700409#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800410 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800411 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700412 break;
413 /* 0x28 - Emulation Watchpoint, handled here */
414 case VEC_WATCH:
415 info.si_code = TRAP_WATCHPT;
416 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800417 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700418 CHK_DEBUGGER_TRAP_MAYBE();
419 /* Check if this is a watchpoint in kernel space */
420 if (fp->ipend & 0xffc0)
421 return;
422 else
423 break;
424#ifdef CONFIG_BF535
425 /* 0x29 - Instruction fetch access error (535 only) */
426 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
427 info.si_code = BUS_OPFETCH;
428 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800429 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800430 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700431 break;
432#else
433 /* 0x29 - Reserved, Caught by default */
434#endif
435 /* 0x2A - Instruction fetch misaligned, handled here */
436 case VEC_MISALI_I:
437 info.si_code = BUS_ADRALN;
438 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800439 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800440 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700441 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800442 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700443 case VEC_CPLB_I_VL:
444 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800445 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800446 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800447 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700448 break;
449 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
450 case VEC_CPLB_I_M:
451 info.si_code = ILL_CPLB_MISS;
452 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800453 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700454 break;
455 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
456 case VEC_CPLB_I_MHIT:
457 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700458 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800459#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800460 if (saved_icplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800461 printk(KERN_NOTICE "Jump to NULL address\n");
462 else
Bryan Wu1394f032007-05-06 14:50:22 -0700463#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800464 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800465 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700466 break;
467 /* 0x2E - Illegal use of Supervisor Resource, handled here */
468 case VEC_ILL_RES:
469 info.si_code = ILL_PRVOPC;
470 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800471 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800472 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700473 break;
474 /* 0x2F - Reserved, Caught by default */
475 /* 0x30 - Reserved, Caught by default */
476 /* 0x31 - Reserved, Caught by default */
477 /* 0x32 - Reserved, Caught by default */
478 /* 0x33 - Reserved, Caught by default */
479 /* 0x34 - Reserved, Caught by default */
480 /* 0x35 - Reserved, Caught by default */
481 /* 0x36 - Reserved, Caught by default */
482 /* 0x37 - Reserved, Caught by default */
483 /* 0x38 - Reserved, Caught by default */
484 /* 0x39 - Reserved, Caught by default */
485 /* 0x3A - Reserved, Caught by default */
486 /* 0x3B - Reserved, Caught by default */
487 /* 0x3C - Reserved, Caught by default */
488 /* 0x3D - Reserved, Caught by default */
489 /* 0x3E - Reserved, Caught by default */
490 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800491 case VEC_HWERR:
492 info.si_code = BUS_ADRALN;
493 sig = SIGBUS;
494 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
495 /* System MMR Error */
496 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
497 info.si_code = BUS_ADRALN;
498 sig = SIGBUS;
499 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
500 break;
501 /* External Memory Addressing Error */
502 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
503 info.si_code = BUS_ADRERR;
504 sig = SIGBUS;
505 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
506 break;
507 /* Performance Monitor Overflow */
508 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
509 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
510 break;
511 /* RAISE 5 instruction */
512 case (SEQSTAT_HWERRCAUSE_RAISE_5):
513 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
514 break;
515 default: /* Reserved */
516 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
517 break;
518 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800519 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800520 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800521 /*
522 * We should be handling all known exception types above,
523 * if we get here we hit a reserved one, so panic
524 */
Bryan Wu1394f032007-05-06 14:50:22 -0700525 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800526 oops_in_progress = 1;
527 info.si_code = ILL_ILLPARAOP;
528 sig = SIGILL;
Bryan Wu1394f032007-05-06 14:50:22 -0700529 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
530 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800531 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700532 break;
533 }
534
Robin Getz226eb1e2007-10-29 17:59:07 +0800535 BUG_ON(sig == 0);
536
537 if (sig != SIGTRAP) {
Robin Getzf09630b2008-07-26 19:45:46 +0800538 unsigned long *stack;
Mike Frysinger49dce912007-11-21 16:46:49 +0800539 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800540 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800541 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800542
543 /* Print out the trace buffer if it makes sense */
544#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
545 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
546 printk(KERN_NOTICE "No trace since you do not have "
547 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
548 KERN_NOTICE "\n");
549 else
550#endif
551 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800552
Robin Getz226eb1e2007-10-29 17:59:07 +0800553 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800554 /* Dump the current kernel stack */
555 printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
556 show_stack(current, NULL);
557
Robin Getzaee3a292008-01-11 16:53:00 +0800558 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800559#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800560 printk(KERN_EMERG "Please turn on "
561 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800562#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700563 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800564 } else {
565 /* Dump the user space stack */
566 stack = (unsigned long *)rdusp();
567 printk(KERN_NOTICE "Userspace Stack\n");
568 show_stack(NULL, stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800569 }
Bryan Wu1394f032007-05-06 14:50:22 -0700570 }
Robin Getzfb322912007-11-21 16:38:05 +0800571
Robin Getzce3afa12007-10-09 17:28:36 +0800572 info.si_signo = sig;
573 info.si_errno = 0;
Mike Frysinger0ddeeca2008-03-07 02:37:41 +0800574 info.si_addr = (void __user *)fp->pc;
Robin Getzce3afa12007-10-09 17:28:36 +0800575 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700576
Bryan Wu1394f032007-05-06 14:50:22 -0700577 trace_buffer_restore(j);
578 return;
579}
580
581/* Typical exception handling routines */
582
Robin Getz518039b2007-07-25 11:03:28 +0800583#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
584
Robin Getzf09630b2008-07-26 19:45:46 +0800585/*
586 * Similar to get_user, do some address checking, then dereference
587 * Return true on sucess, false on bad address
588 */
589bool get_instruction(unsigned short *val, unsigned short *address)
590{
591
592 unsigned long addr;
593
594 addr = (unsigned long)address;
595
596 /* Check for odd addresses */
597 if (addr & 0x1)
598 return false;
599
600 /* Check that things do not wrap around */
601 if (addr > (addr + 2))
602 return false;
603
604 /*
605 * Since we are in exception context, we need to do a little address checking
606 * We need to make sure we are only accessing valid memory, and
607 * we don't read something in the async space that can hang forever
608 */
609 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800610#if L2_LENGTH != 0
Robin Getzf09630b2008-07-26 19:45:46 +0800611 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
612#endif
613 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
614#if L1_DATA_A_LENGTH != 0
615 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
616#endif
617#if L1_DATA_B_LENGTH != 0
618 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
619#endif
620 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
621 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
622 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
623 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
624 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
625 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
626 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
627 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
628 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
629 *val = *address;
630 return true;
631 }
632
633#if L1_CODE_LENGTH != 0
634 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
635 dma_memcpy(val, address, 2);
636 return true;
637 }
638#endif
639
640
641 return false;
642}
643
Robin Getzd3d0ac22008-08-06 17:49:27 +0800644/*
645 * decode the instruction if we are printing out the trace, as it
646 * makes things easier to follow, without running it through objdump
647 * These are the normal instructions which cause change of flow, which
648 * would be at the source of the trace buffer
649 */
650void decode_instruction(unsigned short *address)
651{
652 unsigned short opcode;
653
654 if (get_instruction(&opcode, address)) {
655 if (opcode == 0x0010)
656 printk("RTS");
657 else if (opcode == 0x0011)
658 printk("RTI");
659 else if (opcode == 0x0012)
660 printk("RTX");
661 else if (opcode >= 0x0050 && opcode <= 0x0057)
662 printk("JUMP (P%i)", opcode & 7);
663 else if (opcode >= 0x0060 && opcode <= 0x0067)
664 printk("CALL (P%i)", opcode & 7);
665 else if (opcode >= 0x0070 && opcode <= 0x0077)
666 printk("CALL (PC+P%i)", opcode & 7);
667 else if (opcode >= 0x0080 && opcode <= 0x0087)
668 printk("JUMP (PC+P%i)", opcode & 7);
669 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
670 printk("IF !CC JUMP");
671 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
672 printk("IF CC JUMP");
673 else if (opcode >= 0x2000 && opcode <= 0x2fff)
674 printk("JUMP.S");
675 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
676 printk("LSETUP");
677 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
678 printk("JUMP.L");
679 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
680 printk("CALL pcrel");
681 else
682 printk("0x%04x", opcode);
683 }
684
685}
686
Bryan Wu1394f032007-05-06 14:50:22 -0700687void dump_bfin_trace_buffer(void)
688{
Robin Getz518039b2007-07-25 11:03:28 +0800689#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
690 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800691 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800692 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800693#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
694 int j, index;
695#endif
696
Bryan Wu1394f032007-05-06 14:50:22 -0700697 trace_buffer_save(tflags);
698
Robin Getz226eb1e2007-10-29 17:59:07 +0800699 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800700
Robin Getzd3d0ac22008-08-06 17:49:27 +0800701#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
702 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
703#endif
704
Bryan Wu1394f032007-05-06 14:50:22 -0700705 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800706 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800707 decode_address(buf, (unsigned long)bfin_read_TBUF());
708 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800709 addr = (unsigned short *)bfin_read_TBUF();
710 decode_address(buf, (unsigned long)addr);
711 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800712 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800713 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700714 }
715 }
716
Robin Getz518039b2007-07-25 11:03:28 +0800717#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
718 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800719 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800720 else
721 index = EXPAND_LEN;
722
723 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
724 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800725 decode_address(buf, software_trace_buff[index]);
726 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800727 index -= 1;
728 if (index < 0 )
729 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800730 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800731 printk(KERN_NOTICE " Source : %s ", buf);
732 decode_instruction((unsigned short *)software_trace_buff[index]);
733 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800734 index -= 1;
735 if (index < 0)
736 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800737 j--;
738 i++;
739 }
740#endif
741
Bryan Wu1394f032007-05-06 14:50:22 -0700742 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800743#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700744}
745EXPORT_SYMBOL(dump_bfin_trace_buffer);
746
Robin Getzf09630b2008-07-26 19:45:46 +0800747/*
748 * Checks to see if the address pointed to is either a
749 * 16-bit CALL instruction, or a 32-bit CALL instruction
750 */
751bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700752{
Robin Getzf09630b2008-07-26 19:45:46 +0800753 unsigned short opcode = 0, *ins_addr;
754 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700755
Robin Getzf09630b2008-07-26 19:45:46 +0800756 if (!get_instruction(&opcode, ins_addr))
757 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700758
Robin Getzf09630b2008-07-26 19:45:46 +0800759 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
760 (opcode >= 0x0070 && opcode <= 0x0077))
761 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700762
Robin Getzf09630b2008-07-26 19:45:46 +0800763 ins_addr--;
764 if (!get_instruction(&opcode, ins_addr))
765 return false;
766
767 if (opcode >= 0xE300 && opcode <= 0xE3FF)
768 return true;
769
770 return false;
771
Bryan Wu1394f032007-05-06 14:50:22 -0700772}
Bryan Wu1394f032007-05-06 14:50:22 -0700773void show_stack(struct task_struct *task, unsigned long *stack)
774{
Robin Getzf09630b2008-07-26 19:45:46 +0800775 unsigned int *addr, *endstack, *fp = 0, *frame;
776 unsigned short *ins_addr;
777 char buf[150];
778 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700779
Robin Getzf09630b2008-07-26 19:45:46 +0800780 /*
781 * If we have been passed a specific stack, use that one otherwise
782 * if we have been passed a task structure, use that, otherwise
783 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700784 */
785
Robin Getzf09630b2008-07-26 19:45:46 +0800786 if (stack == NULL) {
787 if (task) {
788 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700789 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800790 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
791 } else {
792 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700793 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800794 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
795 }
796 } else
797 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
798
799 decode_address(buf, (unsigned int)stack);
800 printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
801 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
802
803 /* First thing is to look for a frame pointer */
804 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
805 addr < endstack; addr++, i++) {
806 if (*addr & 0x1)
807 continue;
808 ins_addr = (unsigned short *)*addr;
809 ins_addr--;
810 if (is_bfin_call(ins_addr))
811 fp = addr - 1;
812
813 if (fp) {
814 /* Let's check to see if it is a frame pointer */
815 while (fp >= (addr - 1) && fp < endstack && fp)
816 fp = (unsigned int *)*fp;
817 if (fp == 0 || fp == endstack) {
818 fp = addr - 1;
819 break;
820 }
821 fp = 0;
822 }
823 }
824 if (fp) {
825 frame = fp;
826 printk(" FP: (0x%p)\n", fp);
827 } else
828 frame = 0;
829
830 /*
831 * Now that we think we know where things are, we
832 * walk the stack again, this time printing things out
833 * incase there is no frame pointer, we still look for
834 * valid return addresses
835 */
836
837 /* First time print out data, next time, print out symbols */
838 for (j = 0; j <= 1; j++) {
839 if (j)
840 printk(KERN_NOTICE "Return addresses in stack:\n");
841 else
842 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
843
844 fp = frame;
845 frame_no = 0;
846
847 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
848 addr <= endstack; addr++, i++) {
849
850 ret_addr = 0;
851 if (!j && i % 8 == 0)
852 printk("\n" KERN_NOTICE "%p:",addr);
853
854 /* if it is an odd address, or zero, just skip it */
855 if (*addr & 0x1 || !*addr)
856 goto print;
857
858 ins_addr = (unsigned short *)*addr;
859
860 /* Go back one instruction, and see if it is a CALL */
861 ins_addr--;
862 ret_addr = is_bfin_call(ins_addr);
863 print:
864 if (!j && stack == (unsigned long *)addr)
865 printk("[%08x]", *addr);
866 else if (ret_addr)
867 if (j) {
868 decode_address(buf, (unsigned int)*addr);
869 if (frame == addr) {
870 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
871 continue;
872 }
873 printk(KERN_NOTICE " address : %s\n", buf);
874 } else
875 printk("<%08x>", *addr);
876 else if (fp == addr) {
877 if (j)
878 frame = addr+1;
879 else
880 printk("(%08x)", *addr);
881
882 fp = (unsigned int *)*addr;
883 frame_no++;
884
885 } else if (!j)
886 printk(" %08x ", *addr);
887 }
888 if (!j)
889 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700890 }
891
Bryan Wu1394f032007-05-06 14:50:22 -0700892}
893
894void dump_stack(void)
895{
896 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800897#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700898 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800899#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700900 trace_buffer_save(tflags);
901 dump_bfin_trace_buffer();
902 show_stack(current, &stack);
903 trace_buffer_restore(tflags);
904}
Bryan Wu1394f032007-05-06 14:50:22 -0700905EXPORT_SYMBOL(dump_stack);
906
Mike Frysinger49dce912007-11-21 16:46:49 +0800907void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700908{
Mike Frysinger49dce912007-11-21 16:46:49 +0800909 /* We should be able to look at fp->ipend, but we don't push it on the
910 * stack all the time, so do this until we fix that */
911 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800912
Mike Frysinger49dce912007-11-21 16:46:49 +0800913 if (oops_in_progress)
914 printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800915
Robin Getzb03b08b2007-12-23 22:57:01 +0800916 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
917 printk(KERN_NOTICE "HW Error context\n");
918 else if (context & 0x0020)
Mike Frysingera3acf522008-02-02 15:45:27 +0800919 printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800920 else if (context & 0x3FC0)
921 printk(KERN_NOTICE "Interrupt context\n");
922 else if (context & 0x4000)
923 printk(KERN_NOTICE "Deferred Interrupt context\n");
924 else if (context & 0x8000)
925 printk(KERN_NOTICE "Kernel process context\n");
926
Robin Getz9a62ca42008-03-26 09:15:58 +0800927 /* Because we are crashing, and pointers could be bad, we check things
928 * pretty closely before we use them
929 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800930 if ((unsigned long)current >= FIXED_CODE_START &&
931 !((unsigned long)current & 0x3) && current->pid) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800932 printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800933 if (current->comm >= (char *)FIXED_CODE_START)
934 printk(KERN_NOTICE "COMM=%s PID=%d\n",
935 current->comm, current->pid);
936 else
937 printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800938
Robin Getz9a62ca42008-03-26 09:15:58 +0800939 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
940 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
941 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
942 KERN_NOTICE "\n",
943 (void *)current->mm->start_code,
944 (void *)current->mm->end_code,
945 (void *)current->mm->start_data,
946 (void *)current->mm->end_data,
947 (void *)current->mm->end_data,
948 (void *)current->mm->brk,
949 (void *)current->mm->start_stack);
950 else
951 printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800952 } else
953 printk(KERN_NOTICE "\n" KERN_NOTICE
954 "No Valid process in current context\n");
955}
956
Robin Getzb03b08b2007-12-23 22:57:01 +0800957void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +0800958{
Robin Getzb03b08b2007-12-23 22:57:01 +0800959 unsigned short *addr, *erraddr, val = 0, err = 0;
960 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -0700961
Bernd Schmidt5d750b92008-04-25 05:02:33 +0800962 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +0800963
Robin Getzb03b08b2007-12-23 22:57:01 +0800964 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
965
966 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
967 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
968 addr++) {
969 if (!((unsigned long)addr & 0xF))
970 printk("\n" KERN_NOTICE "0x%p: ", addr);
971
Robin Getz7d98c882008-10-08 16:29:01 +0800972 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +0800973 val = 0;
974 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +0800975 } else
976 sprintf(buf, "%04x", val);
977
978 if (addr == erraddr) {
979 printk("[%s]", buf);
980 err = val;
981 } else
982 printk(" %s ", buf);
983
984 /* Do any previous instructions turn on interrupts? */
985 if (addr <= erraddr && /* in the past */
986 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
987 val == 0x017b)) /* [SP++] = RETI */
988 sti = 1;
989 }
990
991 printk("\n");
992
993 /* Hardware error interrupts can be deferred */
994 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
995 oops_in_progress)){
996 printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700997#ifndef CONFIG_DEBUG_HWERR
Robin Getzb03b08b2007-12-23 22:57:01 +0800998 printk(KERN_NOTICE "The remaining message may be meaningless\n"
999 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
1000 " better idea where it came from\n");
1001#else
1002 /* If we are handling only one peripheral interrupt
1003 * and current mm and pid are valid, and the last error
1004 * was in that user space process's text area
1005 * print it out - because that is where the problem exists
1006 */
1007 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1008 (current->pid && current->mm)) {
1009 /* And the last RETI points to the current userspace context */
1010 if ((fp + 1)->pc >= current->mm->start_code &&
1011 (fp + 1)->pc <= current->mm->end_code) {
1012 printk(KERN_NOTICE "It might be better to look around here : \n");
1013 printk(KERN_NOTICE "-------------------------------------------\n");
1014 show_regs(fp + 1);
1015 printk(KERN_NOTICE "-------------------------------------------\n");
1016 }
Bryan Wu1394f032007-05-06 14:50:22 -07001017 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001018#endif
1019 }
Mike Frysinger49dce912007-11-21 16:46:49 +08001020}
1021
1022void show_regs(struct pt_regs *fp)
1023{
1024 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001025 struct irqaction *action;
1026 unsigned int i;
1027 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -07001028
Robin Getzaee3a292008-01-11 16:53:00 +08001029 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
Robin Getz226eb1e2007-10-29 17:59:07 +08001030 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1031 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz13fe24f2008-01-27 15:38:56 +08001032 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1033 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1034 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1035 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getzd8f66c82007-12-24 15:27:56 +08001036 for (i = 6; i <= 15 ; i++) {
1037 if (fp->ipend & (1 << i)) {
1038 decode_address(buf, bfin_read32(EVT0 + 4*i));
1039 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1040 }
1041 }
1042
1043 /* if no interrupts are going off, don't print this out */
1044 if (fp->ipend & ~0x3F) {
1045 for (i = 0; i < (NR_IRQS - 1); i++) {
1046 spin_lock_irqsave(&irq_desc[i].lock, flags);
1047 action = irq_desc[i].action;
1048 if (!action)
1049 goto unlock;
1050
1051 decode_address(buf, (unsigned int)action->handler);
1052 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1053 for (action = action->next; action; action = action->next) {
1054 decode_address(buf, (unsigned int)action->handler);
1055 printk(", %s", buf);
1056 }
1057 printk("\n");
1058unlock:
1059 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1060 }
1061 }
Bryan Wu1394f032007-05-06 14:50:22 -07001062
Robin Getz226eb1e2007-10-29 17:59:07 +08001063 decode_address(buf, fp->rete);
1064 printk(KERN_NOTICE " RETE: %s\n", buf);
1065 decode_address(buf, fp->retn);
1066 printk(KERN_NOTICE " RETN: %s\n", buf);
1067 decode_address(buf, fp->retx);
1068 printk(KERN_NOTICE " RETX: %s\n", buf);
1069 decode_address(buf, fp->rets);
1070 printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001071 decode_address(buf, fp->pc);
Robin Getz13fe24f2008-01-27 15:38:56 +08001072 printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001073
Robin Getz13fe24f2008-01-27 15:38:56 +08001074 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1075 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001076 decode_address(buf, saved_dcplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001077 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001078 decode_address(buf, saved_icplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001079 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001080 }
1081
Robin Getz226eb1e2007-10-29 17:59:07 +08001082 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1083 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1084 fp->r0, fp->r1, fp->r2, fp->r3);
1085 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1086 fp->r4, fp->r5, fp->r6, fp->r7);
1087 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1088 fp->p0, fp->p1, fp->p2, fp->p3);
1089 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1090 fp->p4, fp->p5, fp->fp, (long)fp);
1091 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1092 fp->lb0, fp->lt0, fp->lc0);
1093 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1094 fp->lb1, fp->lt1, fp->lc1);
1095 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1096 fp->b0, fp->l0, fp->m0, fp->i0);
1097 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1098 fp->b1, fp->l1, fp->m1, fp->i1);
1099 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1100 fp->b2, fp->l2, fp->m2, fp->i2);
1101 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1102 fp->b3, fp->l3, fp->m3, fp->i3);
1103 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1104 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1105
1106 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1107 rdusp(), fp->astat);
1108
1109 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001110}
1111
1112#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1113asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1114#endif
1115
1116asmlinkage int sys_bfin_spinlock(int *spinlock)
1117{
1118 int ret = 0;
1119 int tmp = 0;
1120
1121 local_irq_disable();
1122 ret = get_user(tmp, spinlock);
1123 if (ret == 0) {
1124 if (tmp)
1125 ret = 1;
1126 tmp = 1;
1127 put_user(tmp, spinlock);
1128 }
1129 local_irq_enable();
1130 return ret;
1131}
1132
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001133int bfin_request_exception(unsigned int exception, void (*handler)(void))
1134{
1135 void (*curr_handler)(void);
1136
1137 if (exception > 0x3F)
1138 return -EINVAL;
1139
1140 curr_handler = ex_table[exception];
1141
1142 if (curr_handler != ex_replaceable)
1143 return -EBUSY;
1144
1145 ex_table[exception] = handler;
1146
1147 return 0;
1148}
1149EXPORT_SYMBOL(bfin_request_exception);
1150
1151int bfin_free_exception(unsigned int exception, void (*handler)(void))
1152{
1153 void (*curr_handler)(void);
1154
1155 if (exception > 0x3F)
1156 return -EINVAL;
1157
1158 curr_handler = ex_table[exception];
1159
1160 if (curr_handler != handler)
1161 return -EBUSY;
1162
1163 ex_table[exception] = ex_replaceable;
1164
1165 return 0;
1166}
1167EXPORT_SYMBOL(bfin_free_exception);
1168
Bryan Wu1394f032007-05-06 14:50:22 -07001169void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1170{
1171 switch (cplb_panic) {
1172 case CPLB_NO_UNLOCKED:
1173 printk(KERN_EMERG "All CPLBs are locked\n");
1174 break;
1175 case CPLB_PROT_VIOL:
1176 return;
1177 case CPLB_NO_ADDR_MATCH:
1178 return;
1179 case CPLB_UNKNOWN_ERR:
1180 printk(KERN_EMERG "Unknown CPLB Exception\n");
1181 break;
1182 }
1183
Robin Getz226eb1e2007-10-29 17:59:07 +08001184 oops_in_progress = 1;
1185
Mike Frysinger49dce912007-11-21 16:46:49 +08001186 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001187 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001188 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001189 dump_stack();
1190 panic("Unrecoverable event\n");
1191}