blob: 1a3c4daf557a8f10bc79051e68be1ab638a6b7d9 [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>
Bryan Wu1394f032007-05-06 14:50:22 -070043
44#ifdef CONFIG_KGDB
Bryan Wu1394f032007-05-06 14:50:22 -070045# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080046
47# define CHK_DEBUGGER_TRAP() \
48 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080049 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080050 } while (0)
51# define CHK_DEBUGGER_TRAP_MAYBE() \
52 do { \
53 if (kgdb_connected) \
54 CHK_DEBUGGER_TRAP(); \
55 } while (0)
56#else
57# define CHK_DEBUGGER_TRAP() do { } while (0)
58# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070059#endif
60
61/* Initiate the event table handler */
62void __init trap_init(void)
63{
64 CSYNC();
65 bfin_write_EVT3(trap);
66 CSYNC();
67}
68
Robin Getz0c7a6b22008-10-08 16:27:12 +080069/*
70 * Used to save the RETX, SEQSTAT, I/D CPLB FAULT ADDR
71 * values across the transition from exception to IRQ5.
72 * We put these in L1, so they are going to be in a valid
73 * location during exception context
74 */
75__attribute__((l1_data))
76unsigned long saved_retx, saved_seqstat,
77 saved_icplb_fault_addr, saved_dcplb_fault_addr;
Bernd Schmidt5d750b92008-04-25 05:02:33 +080078
Robin Getz226eb1e2007-10-29 17:59:07 +080079static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070080{
81 struct vm_list_struct *vml;
82 struct task_struct *p;
83 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080084 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080085 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -070086
87#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080088 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070089 const char *symname;
90 char *modname;
91 char *delim = ":";
92 char namebuf[128];
93
94 /* look up the address and see if we are in kernel space */
95 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
96
97 if (symname) {
98 /* yeah! kernel space! */
99 if (!modname)
100 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +0800101 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800102 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -0700103 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +0800104 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700105
106 }
107#endif
108
Robin Getz226eb1e2007-10-29 17:59:07 +0800109 /* Problem in fixed code section? */
110 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
111 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
112 return;
113 }
114
115 /* Problem somewhere before the kernel start address */
116 if (address < CONFIG_BOOT_LOAD) {
117 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
118 return;
119 }
120
Bryan Wu1394f032007-05-06 14:50:22 -0700121 /* looks like we're off in user-land, so let's walk all the
122 * mappings of all our processes and see if we can't be a whee
123 * bit more specific
124 */
Robin Getz885be032007-10-29 17:20:41 +0800125 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700126 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800127 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700128 if (!mm)
129 continue;
130
131 vml = mm->context.vmlist;
132 while (vml) {
133 struct vm_area_struct *vma = vml->vma;
134
135 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800136 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700137 char *name = p->comm;
138 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800139
140 if (file)
141 name = d_path(&file->f_path, _tmpbuf,
142 sizeof(_tmpbuf));
Bryan Wu1394f032007-05-06 14:50:22 -0700143
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800144 /* FLAT does not have its text aligned to the start of
145 * the map while FDPIC ELF does ...
146 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800147
Robin Getz7f1c9062008-04-25 03:36:31 +0800148 /* before we can check flat/fdpic, we need to
149 * make sure current is valid
150 */
151 if ((unsigned long)current >= FIXED_CODE_START &&
152 !((unsigned long)current & 0x3)) {
153 if (current->mm &&
154 (address > current->mm->start_code) &&
155 (address < current->mm->end_code))
156 offset = address - current->mm->start_code;
157 else
158 offset = (address - vma->vm_start) +
159 (vma->vm_pgoff << PAGE_SHIFT);
160
161 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
162 (void *)address, name, offset);
163 } else
164 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
165 (void *)address, name,
166 vma->vm_start, vma->vm_end);
167
Robin Getz904656c2008-03-26 09:17:43 +0800168 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800169 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800170
Robin Getzf09630b2008-07-26 19:45:46 +0800171 if (!strlen(buf))
172 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
173
Robin Getz885be032007-10-29 17:20:41 +0800174 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700175 }
176
177 vml = vml->next;
178 }
Robin Getz904656c2008-03-26 09:17:43 +0800179 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800180 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700181 }
Bryan Wu1394f032007-05-06 14:50:22 -0700182
183 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800184 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800185
186done:
187 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700188}
189
Robin Getz2ebcade2007-10-09 17:24:30 +0800190asmlinkage void double_fault_c(struct pt_regs *fp)
191{
Robin Getz226eb1e2007-10-29 17:59:07 +0800192 console_verbose();
193 oops_in_progress = 1;
Robin Getz2ebcade2007-10-09 17:24:30 +0800194 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800195#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
196 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
197 char buf[150];
198 decode_address(buf, saved_retx);
199 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
200 (int)saved_seqstat & SEQSTAT_EXCAUSE, buf);
201 decode_address(buf, saved_dcplb_fault_addr);
202 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
203 decode_address(buf, saved_icplb_fault_addr);
204 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
205
206 decode_address(buf, fp->retx);
207 printk(KERN_NOTICE "The instruction at %s caused a double exception\n",
208 buf);
209 } else
210#endif
211 {
212 dump_bfin_process(fp);
213 dump_bfin_mem(fp);
214 show_regs(fp);
215 }
Robin Getz2ebcade2007-10-09 17:24:30 +0800216 panic("Double Fault - unrecoverable event\n");
217
218}
219
Bryan Wu1394f032007-05-06 14:50:22 -0700220asmlinkage void trap_c(struct pt_regs *fp)
221{
Robin Getz518039b2007-07-25 11:03:28 +0800222#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
223 int j;
224#endif
225 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700226 siginfo_t info;
227 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
228
Bryan Wu1394f032007-05-06 14:50:22 -0700229 trace_buffer_save(j);
230
Robin Getz226eb1e2007-10-29 17:59:07 +0800231 /* Important - be very careful dereferncing pointers - will lead to
232 * double faults if the stack has become corrupt
233 */
234
235 /* If the fault was caused by a kernel thread, or interrupt handler
236 * we will kernel panic, so the system reboots.
237 * If KGDB is enabled, don't set this for kernel breakpoints
238 */
Robin Getzb03b08b2007-12-23 22:57:01 +0800239
240 /* TODO: check to see if we are in some sort of deferred HWERR
241 * that we should be able to recover from, not kernel panic
242 */
Robin Getz6b5eace2008-01-10 17:57:56 +0800243 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
Robin Getz226eb1e2007-10-29 17:59:07 +0800244#ifdef CONFIG_KGDB
Robin Getz6b5eace2008-01-10 17:57:56 +0800245 && (trapnr != VEC_EXCPT02)
Robin Getz226eb1e2007-10-29 17:59:07 +0800246#endif
247 ){
248 console_verbose();
249 oops_in_progress = 1;
250 } else if (current) {
251 if (current->mm == NULL) {
252 console_verbose();
253 oops_in_progress = 1;
254 }
255 }
256
Bryan Wu1394f032007-05-06 14:50:22 -0700257 /* trap_c() will be called for exceptions. During exceptions
258 * processing, the pc value should be set with retx value.
259 * With this change we can cleanup some code in signal.c- TODO
260 */
261 fp->orig_pc = fp->retx;
262 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
263 trapnr, fp->ipend, fp->pc, fp->retx); */
264
265 /* send the appropriate signal to the user program */
266 switch (trapnr) {
267
268 /* This table works in conjuction with the one in ./mach-common/entry.S
269 * Some exceptions are handled there (in assembly, in exception space)
270 * Some are handled here, (in C, in interrupt space)
271 * Some, like CPLB, are handled in both, where the normal path is
272 * handled in assembly/exception space, and the error path is handled
273 * here
274 */
275
276 /* 0x00 - Linux Syscall, getting here is an error */
277 /* 0x01 - userspace gdb breakpoint, handled here */
278 case VEC_EXCPT01:
279 info.si_code = TRAP_ILLTRAP;
280 sig = SIGTRAP;
281 CHK_DEBUGGER_TRAP_MAYBE();
282 /* Check if this is a breakpoint in kernel space */
283 if (fp->ipend & 0xffc0)
284 return;
285 else
286 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800287 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700288 case VEC_EXCPT03:
289 info.si_code = SEGV_STACKFLOW;
290 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800291 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800292 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700293 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800294 /* 0x02 - KGDB initial connection and break signal trap */
295 case VEC_EXCPT02:
296#ifdef CONFIG_KGDB
297 info.si_code = TRAP_ILLTRAP;
298 sig = SIGTRAP;
299 CHK_DEBUGGER_TRAP();
300 return;
301#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800302 /* 0x04 - User Defined */
303 /* 0x05 - User Defined */
304 /* 0x06 - User Defined */
305 /* 0x07 - User Defined */
306 /* 0x08 - User Defined */
307 /* 0x09 - User Defined */
308 /* 0x0A - User Defined */
309 /* 0x0B - User Defined */
310 /* 0x0C - User Defined */
311 /* 0x0D - User Defined */
312 /* 0x0E - User Defined */
313 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800314 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800315 * custom exception handler, and it is not actually installed properly
316 */
317 case VEC_EXCPT04 ... VEC_EXCPT15:
318 info.si_code = ILL_ILLPARAOP;
319 sig = SIGILL;
320 printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
321 CHK_DEBUGGER_TRAP_MAYBE();
322 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700323 /* 0x10 HW Single step, handled here */
324 case VEC_STEP:
325 info.si_code = TRAP_STEP;
326 sig = SIGTRAP;
327 CHK_DEBUGGER_TRAP_MAYBE();
328 /* Check if this is a single step in kernel space */
329 if (fp->ipend & 0xffc0)
330 return;
331 else
332 break;
333 /* 0x11 - Trace Buffer Full, handled here */
334 case VEC_OVFLOW:
335 info.si_code = TRAP_TRACEFLOW;
336 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800337 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800338 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700339 break;
340 /* 0x12 - Reserved, Caught by default */
341 /* 0x13 - Reserved, Caught by default */
342 /* 0x14 - Reserved, Caught by default */
343 /* 0x15 - Reserved, Caught by default */
344 /* 0x16 - Reserved, Caught by default */
345 /* 0x17 - Reserved, Caught by default */
346 /* 0x18 - Reserved, Caught by default */
347 /* 0x19 - Reserved, Caught by default */
348 /* 0x1A - Reserved, Caught by default */
349 /* 0x1B - Reserved, Caught by default */
350 /* 0x1C - Reserved, Caught by default */
351 /* 0x1D - Reserved, Caught by default */
352 /* 0x1E - Reserved, Caught by default */
353 /* 0x1F - Reserved, Caught by default */
354 /* 0x20 - Reserved, Caught by default */
355 /* 0x21 - Undefined Instruction, handled here */
356 case VEC_UNDEF_I:
357 info.si_code = ILL_ILLOPC;
358 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800359 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800360 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700361 break;
362 /* 0x22 - Illegal Instruction Combination, handled here */
363 case VEC_ILGAL_I:
364 info.si_code = ILL_ILLPARAOP;
365 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800366 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800367 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700368 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800369 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700370 case VEC_CPLB_VL:
371 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800372 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800373 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800374 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700375 break;
376 /* 0x24 - Data access misaligned, handled here */
377 case VEC_MISALI_D:
378 info.si_code = BUS_ADRALN;
379 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800380 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800381 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700382 break;
383 /* 0x25 - Unrecoverable Event, handled here */
384 case VEC_UNCOV:
385 info.si_code = ILL_ILLEXCPT;
386 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800387 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800388 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700389 break;
390 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
391 error case is handled here */
392 case VEC_CPLB_M:
393 info.si_code = BUS_ADRALN;
394 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800395 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700396 break;
397 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
398 case VEC_CPLB_MHIT:
399 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700400 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800401#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800402 if (saved_dcplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800403 printk(KERN_NOTICE "NULL pointer access\n");
404 else
Bryan Wu1394f032007-05-06 14:50:22 -0700405#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800406 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800407 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700408 break;
409 /* 0x28 - Emulation Watchpoint, handled here */
410 case VEC_WATCH:
411 info.si_code = TRAP_WATCHPT;
412 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800413 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700414 CHK_DEBUGGER_TRAP_MAYBE();
415 /* Check if this is a watchpoint in kernel space */
416 if (fp->ipend & 0xffc0)
417 return;
418 else
419 break;
420#ifdef CONFIG_BF535
421 /* 0x29 - Instruction fetch access error (535 only) */
422 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
423 info.si_code = BUS_OPFETCH;
424 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800425 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800426 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700427 break;
428#else
429 /* 0x29 - Reserved, Caught by default */
430#endif
431 /* 0x2A - Instruction fetch misaligned, handled here */
432 case VEC_MISALI_I:
433 info.si_code = BUS_ADRALN;
434 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800435 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800436 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700437 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800438 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700439 case VEC_CPLB_I_VL:
440 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800441 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800442 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800443 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700444 break;
445 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
446 case VEC_CPLB_I_M:
447 info.si_code = ILL_CPLB_MISS;
448 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800449 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700450 break;
451 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
452 case VEC_CPLB_I_MHIT:
453 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700454 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800455#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Mike Frysingerbd628bd2008-06-03 12:23:45 +0800456 if (saved_icplb_fault_addr < FIXED_CODE_START)
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800457 printk(KERN_NOTICE "Jump to NULL address\n");
458 else
Bryan Wu1394f032007-05-06 14:50:22 -0700459#endif
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800460 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800461 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700462 break;
463 /* 0x2E - Illegal use of Supervisor Resource, handled here */
464 case VEC_ILL_RES:
465 info.si_code = ILL_PRVOPC;
466 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800467 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800468 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700469 break;
470 /* 0x2F - Reserved, Caught by default */
471 /* 0x30 - Reserved, Caught by default */
472 /* 0x31 - Reserved, Caught by default */
473 /* 0x32 - Reserved, Caught by default */
474 /* 0x33 - Reserved, Caught by default */
475 /* 0x34 - Reserved, Caught by default */
476 /* 0x35 - Reserved, Caught by default */
477 /* 0x36 - Reserved, Caught by default */
478 /* 0x37 - Reserved, Caught by default */
479 /* 0x38 - Reserved, Caught by default */
480 /* 0x39 - Reserved, Caught by default */
481 /* 0x3A - Reserved, Caught by default */
482 /* 0x3B - Reserved, Caught by default */
483 /* 0x3C - Reserved, Caught by default */
484 /* 0x3D - Reserved, Caught by default */
485 /* 0x3E - Reserved, Caught by default */
486 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800487 case VEC_HWERR:
488 info.si_code = BUS_ADRALN;
489 sig = SIGBUS;
490 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
491 /* System MMR Error */
492 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
493 info.si_code = BUS_ADRALN;
494 sig = SIGBUS;
495 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
496 break;
497 /* External Memory Addressing Error */
498 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
499 info.si_code = BUS_ADRERR;
500 sig = SIGBUS;
501 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
502 break;
503 /* Performance Monitor Overflow */
504 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
505 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
506 break;
507 /* RAISE 5 instruction */
508 case (SEQSTAT_HWERRCAUSE_RAISE_5):
509 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
510 break;
511 default: /* Reserved */
512 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
513 break;
514 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800515 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800516 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800517 /*
518 * We should be handling all known exception types above,
519 * if we get here we hit a reserved one, so panic
520 */
Bryan Wu1394f032007-05-06 14:50:22 -0700521 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800522 oops_in_progress = 1;
523 info.si_code = ILL_ILLPARAOP;
524 sig = SIGILL;
Bryan Wu1394f032007-05-06 14:50:22 -0700525 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
526 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800527 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700528 break;
529 }
530
Robin Getz226eb1e2007-10-29 17:59:07 +0800531 BUG_ON(sig == 0);
532
533 if (sig != SIGTRAP) {
Robin Getzf09630b2008-07-26 19:45:46 +0800534 unsigned long *stack;
Mike Frysinger49dce912007-11-21 16:46:49 +0800535 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800536 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800537 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800538
539 /* Print out the trace buffer if it makes sense */
540#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
541 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
542 printk(KERN_NOTICE "No trace since you do not have "
543 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
544 KERN_NOTICE "\n");
545 else
546#endif
547 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800548
Robin Getz226eb1e2007-10-29 17:59:07 +0800549 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800550 /* Dump the current kernel stack */
551 printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
552 show_stack(current, NULL);
553
Robin Getzaee3a292008-01-11 16:53:00 +0800554 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800555#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800556 printk(KERN_EMERG "Please turn on "
557 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800558#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700559 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800560 } else {
561 /* Dump the user space stack */
562 stack = (unsigned long *)rdusp();
563 printk(KERN_NOTICE "Userspace Stack\n");
564 show_stack(NULL, stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800565 }
Bryan Wu1394f032007-05-06 14:50:22 -0700566 }
Robin Getzfb322912007-11-21 16:38:05 +0800567
Robin Getzce3afa12007-10-09 17:28:36 +0800568 info.si_signo = sig;
569 info.si_errno = 0;
Mike Frysinger0ddeeca2008-03-07 02:37:41 +0800570 info.si_addr = (void __user *)fp->pc;
Robin Getzce3afa12007-10-09 17:28:36 +0800571 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700572
Bryan Wu1394f032007-05-06 14:50:22 -0700573 trace_buffer_restore(j);
574 return;
575}
576
577/* Typical exception handling routines */
578
Robin Getz518039b2007-07-25 11:03:28 +0800579#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
580
Robin Getzf09630b2008-07-26 19:45:46 +0800581/*
582 * Similar to get_user, do some address checking, then dereference
583 * Return true on sucess, false on bad address
584 */
585bool get_instruction(unsigned short *val, unsigned short *address)
586{
587
588 unsigned long addr;
589
590 addr = (unsigned long)address;
591
592 /* Check for odd addresses */
593 if (addr & 0x1)
594 return false;
595
596 /* Check that things do not wrap around */
597 if (addr > (addr + 2))
598 return false;
599
600 /*
601 * Since we are in exception context, we need to do a little address checking
602 * We need to make sure we are only accessing valid memory, and
603 * we don't read something in the async space that can hang forever
604 */
605 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800606#if L2_LENGTH != 0
Robin Getzf09630b2008-07-26 19:45:46 +0800607 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
608#endif
609 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
610#if L1_DATA_A_LENGTH != 0
611 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
612#endif
613#if L1_DATA_B_LENGTH != 0
614 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
615#endif
616 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
617 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
618 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
619 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
620 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
621 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
622 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
623 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
624 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
625 *val = *address;
626 return true;
627 }
628
629#if L1_CODE_LENGTH != 0
630 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
Robin Getz9df10282008-10-08 18:03:33 +0800631 isram_memcpy(val, address, 2);
Robin Getzf09630b2008-07-26 19:45:46 +0800632 return true;
633 }
634#endif
635
636
637 return false;
638}
639
Robin Getzd3d0ac22008-08-06 17:49:27 +0800640/*
641 * decode the instruction if we are printing out the trace, as it
642 * makes things easier to follow, without running it through objdump
643 * These are the normal instructions which cause change of flow, which
644 * would be at the source of the trace buffer
645 */
646void decode_instruction(unsigned short *address)
647{
648 unsigned short opcode;
649
650 if (get_instruction(&opcode, address)) {
651 if (opcode == 0x0010)
652 printk("RTS");
653 else if (opcode == 0x0011)
654 printk("RTI");
655 else if (opcode == 0x0012)
656 printk("RTX");
657 else if (opcode >= 0x0050 && opcode <= 0x0057)
658 printk("JUMP (P%i)", opcode & 7);
659 else if (opcode >= 0x0060 && opcode <= 0x0067)
660 printk("CALL (P%i)", opcode & 7);
661 else if (opcode >= 0x0070 && opcode <= 0x0077)
662 printk("CALL (PC+P%i)", opcode & 7);
663 else if (opcode >= 0x0080 && opcode <= 0x0087)
664 printk("JUMP (PC+P%i)", opcode & 7);
665 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
666 printk("IF !CC JUMP");
667 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
668 printk("IF CC JUMP");
669 else if (opcode >= 0x2000 && opcode <= 0x2fff)
670 printk("JUMP.S");
671 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
672 printk("LSETUP");
673 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
674 printk("JUMP.L");
675 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
676 printk("CALL pcrel");
677 else
678 printk("0x%04x", opcode);
679 }
680
681}
682
Bryan Wu1394f032007-05-06 14:50:22 -0700683void dump_bfin_trace_buffer(void)
684{
Robin Getz518039b2007-07-25 11:03:28 +0800685#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
686 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800687 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800688 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800689#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
690 int j, index;
691#endif
692
Bryan Wu1394f032007-05-06 14:50:22 -0700693 trace_buffer_save(tflags);
694
Robin Getz226eb1e2007-10-29 17:59:07 +0800695 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800696
Robin Getzd3d0ac22008-08-06 17:49:27 +0800697#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
698 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
699#endif
700
Bryan Wu1394f032007-05-06 14:50:22 -0700701 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800702 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800703 decode_address(buf, (unsigned long)bfin_read_TBUF());
704 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800705 addr = (unsigned short *)bfin_read_TBUF();
706 decode_address(buf, (unsigned long)addr);
707 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800708 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800709 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700710 }
711 }
712
Robin Getz518039b2007-07-25 11:03:28 +0800713#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
714 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800715 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800716 else
717 index = EXPAND_LEN;
718
719 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
720 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800721 decode_address(buf, software_trace_buff[index]);
722 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800723 index -= 1;
724 if (index < 0 )
725 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800726 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800727 printk(KERN_NOTICE " Source : %s ", buf);
728 decode_instruction((unsigned short *)software_trace_buff[index]);
729 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800730 index -= 1;
731 if (index < 0)
732 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800733 j--;
734 i++;
735 }
736#endif
737
Bryan Wu1394f032007-05-06 14:50:22 -0700738 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800739#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700740}
741EXPORT_SYMBOL(dump_bfin_trace_buffer);
742
Robin Getzf09630b2008-07-26 19:45:46 +0800743/*
744 * Checks to see if the address pointed to is either a
745 * 16-bit CALL instruction, or a 32-bit CALL instruction
746 */
747bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700748{
Robin Getzf09630b2008-07-26 19:45:46 +0800749 unsigned short opcode = 0, *ins_addr;
750 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700751
Robin Getzf09630b2008-07-26 19:45:46 +0800752 if (!get_instruction(&opcode, ins_addr))
753 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700754
Robin Getzf09630b2008-07-26 19:45:46 +0800755 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
756 (opcode >= 0x0070 && opcode <= 0x0077))
757 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700758
Robin Getzf09630b2008-07-26 19:45:46 +0800759 ins_addr--;
760 if (!get_instruction(&opcode, ins_addr))
761 return false;
762
763 if (opcode >= 0xE300 && opcode <= 0xE3FF)
764 return true;
765
766 return false;
767
Bryan Wu1394f032007-05-06 14:50:22 -0700768}
Bryan Wu1394f032007-05-06 14:50:22 -0700769void show_stack(struct task_struct *task, unsigned long *stack)
770{
Robin Getzf09630b2008-07-26 19:45:46 +0800771 unsigned int *addr, *endstack, *fp = 0, *frame;
772 unsigned short *ins_addr;
773 char buf[150];
774 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700775
Robin Getzf09630b2008-07-26 19:45:46 +0800776 /*
777 * If we have been passed a specific stack, use that one otherwise
778 * if we have been passed a task structure, use that, otherwise
779 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700780 */
781
Robin Getzf09630b2008-07-26 19:45:46 +0800782 if (stack == NULL) {
783 if (task) {
784 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700785 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800786 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
787 } else {
788 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700789 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800790 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
791 }
792 } else
793 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
794
795 decode_address(buf, (unsigned int)stack);
796 printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
797 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
798
799 /* First thing is to look for a frame pointer */
800 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
801 addr < endstack; addr++, i++) {
802 if (*addr & 0x1)
803 continue;
804 ins_addr = (unsigned short *)*addr;
805 ins_addr--;
806 if (is_bfin_call(ins_addr))
807 fp = addr - 1;
808
809 if (fp) {
810 /* Let's check to see if it is a frame pointer */
811 while (fp >= (addr - 1) && fp < endstack && fp)
812 fp = (unsigned int *)*fp;
813 if (fp == 0 || fp == endstack) {
814 fp = addr - 1;
815 break;
816 }
817 fp = 0;
818 }
819 }
820 if (fp) {
821 frame = fp;
822 printk(" FP: (0x%p)\n", fp);
823 } else
824 frame = 0;
825
826 /*
827 * Now that we think we know where things are, we
828 * walk the stack again, this time printing things out
829 * incase there is no frame pointer, we still look for
830 * valid return addresses
831 */
832
833 /* First time print out data, next time, print out symbols */
834 for (j = 0; j <= 1; j++) {
835 if (j)
836 printk(KERN_NOTICE "Return addresses in stack:\n");
837 else
838 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
839
840 fp = frame;
841 frame_no = 0;
842
843 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
844 addr <= endstack; addr++, i++) {
845
846 ret_addr = 0;
847 if (!j && i % 8 == 0)
848 printk("\n" KERN_NOTICE "%p:",addr);
849
850 /* if it is an odd address, or zero, just skip it */
851 if (*addr & 0x1 || !*addr)
852 goto print;
853
854 ins_addr = (unsigned short *)*addr;
855
856 /* Go back one instruction, and see if it is a CALL */
857 ins_addr--;
858 ret_addr = is_bfin_call(ins_addr);
859 print:
860 if (!j && stack == (unsigned long *)addr)
861 printk("[%08x]", *addr);
862 else if (ret_addr)
863 if (j) {
864 decode_address(buf, (unsigned int)*addr);
865 if (frame == addr) {
866 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
867 continue;
868 }
869 printk(KERN_NOTICE " address : %s\n", buf);
870 } else
871 printk("<%08x>", *addr);
872 else if (fp == addr) {
873 if (j)
874 frame = addr+1;
875 else
876 printk("(%08x)", *addr);
877
878 fp = (unsigned int *)*addr;
879 frame_no++;
880
881 } else if (!j)
882 printk(" %08x ", *addr);
883 }
884 if (!j)
885 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700886 }
887
Bryan Wu1394f032007-05-06 14:50:22 -0700888}
889
890void dump_stack(void)
891{
892 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800893#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700894 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800895#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700896 trace_buffer_save(tflags);
897 dump_bfin_trace_buffer();
898 show_stack(current, &stack);
899 trace_buffer_restore(tflags);
900}
Bryan Wu1394f032007-05-06 14:50:22 -0700901EXPORT_SYMBOL(dump_stack);
902
Mike Frysinger49dce912007-11-21 16:46:49 +0800903void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700904{
Mike Frysinger49dce912007-11-21 16:46:49 +0800905 /* We should be able to look at fp->ipend, but we don't push it on the
906 * stack all the time, so do this until we fix that */
907 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800908
Mike Frysinger49dce912007-11-21 16:46:49 +0800909 if (oops_in_progress)
910 printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800911
Robin Getzb03b08b2007-12-23 22:57:01 +0800912 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
913 printk(KERN_NOTICE "HW Error context\n");
914 else if (context & 0x0020)
Mike Frysingera3acf522008-02-02 15:45:27 +0800915 printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800916 else if (context & 0x3FC0)
917 printk(KERN_NOTICE "Interrupt context\n");
918 else if (context & 0x4000)
919 printk(KERN_NOTICE "Deferred Interrupt context\n");
920 else if (context & 0x8000)
921 printk(KERN_NOTICE "Kernel process context\n");
922
Robin Getz9a62ca42008-03-26 09:15:58 +0800923 /* Because we are crashing, and pointers could be bad, we check things
924 * pretty closely before we use them
925 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800926 if ((unsigned long)current >= FIXED_CODE_START &&
927 !((unsigned long)current & 0x3) && current->pid) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800928 printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800929 if (current->comm >= (char *)FIXED_CODE_START)
930 printk(KERN_NOTICE "COMM=%s PID=%d\n",
931 current->comm, current->pid);
932 else
933 printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800934
Robin Getz9a62ca42008-03-26 09:15:58 +0800935 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
936 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
937 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
938 KERN_NOTICE "\n",
939 (void *)current->mm->start_code,
940 (void *)current->mm->end_code,
941 (void *)current->mm->start_data,
942 (void *)current->mm->end_data,
943 (void *)current->mm->end_data,
944 (void *)current->mm->brk,
945 (void *)current->mm->start_stack);
946 else
947 printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800948 } else
949 printk(KERN_NOTICE "\n" KERN_NOTICE
950 "No Valid process in current context\n");
951}
952
Robin Getzb03b08b2007-12-23 22:57:01 +0800953void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +0800954{
Robin Getzb03b08b2007-12-23 22:57:01 +0800955 unsigned short *addr, *erraddr, val = 0, err = 0;
956 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -0700957
Bernd Schmidt5d750b92008-04-25 05:02:33 +0800958 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +0800959
Robin Getzb03b08b2007-12-23 22:57:01 +0800960 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
961
962 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
963 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
964 addr++) {
965 if (!((unsigned long)addr & 0xF))
966 printk("\n" KERN_NOTICE "0x%p: ", addr);
967
Robin Getz7d98c882008-10-08 16:29:01 +0800968 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +0800969 val = 0;
970 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +0800971 } else
972 sprintf(buf, "%04x", val);
973
974 if (addr == erraddr) {
975 printk("[%s]", buf);
976 err = val;
977 } else
978 printk(" %s ", buf);
979
980 /* Do any previous instructions turn on interrupts? */
981 if (addr <= erraddr && /* in the past */
982 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
983 val == 0x017b)) /* [SP++] = RETI */
984 sti = 1;
985 }
986
987 printk("\n");
988
989 /* Hardware error interrupts can be deferred */
990 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
991 oops_in_progress)){
992 printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700993#ifndef CONFIG_DEBUG_HWERR
Robin Getzb03b08b2007-12-23 22:57:01 +0800994 printk(KERN_NOTICE "The remaining message may be meaningless\n"
995 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
996 " better idea where it came from\n");
997#else
998 /* If we are handling only one peripheral interrupt
999 * and current mm and pid are valid, and the last error
1000 * was in that user space process's text area
1001 * print it out - because that is where the problem exists
1002 */
1003 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1004 (current->pid && current->mm)) {
1005 /* And the last RETI points to the current userspace context */
1006 if ((fp + 1)->pc >= current->mm->start_code &&
1007 (fp + 1)->pc <= current->mm->end_code) {
1008 printk(KERN_NOTICE "It might be better to look around here : \n");
1009 printk(KERN_NOTICE "-------------------------------------------\n");
1010 show_regs(fp + 1);
1011 printk(KERN_NOTICE "-------------------------------------------\n");
1012 }
Bryan Wu1394f032007-05-06 14:50:22 -07001013 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001014#endif
1015 }
Mike Frysinger49dce912007-11-21 16:46:49 +08001016}
1017
1018void show_regs(struct pt_regs *fp)
1019{
1020 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001021 struct irqaction *action;
1022 unsigned int i;
1023 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -07001024
Robin Getzaee3a292008-01-11 16:53:00 +08001025 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
Robin Getz226eb1e2007-10-29 17:59:07 +08001026 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1027 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz13fe24f2008-01-27 15:38:56 +08001028 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1029 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1030 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1031 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getzd8f66c82007-12-24 15:27:56 +08001032 for (i = 6; i <= 15 ; i++) {
1033 if (fp->ipend & (1 << i)) {
1034 decode_address(buf, bfin_read32(EVT0 + 4*i));
1035 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1036 }
1037 }
1038
1039 /* if no interrupts are going off, don't print this out */
1040 if (fp->ipend & ~0x3F) {
1041 for (i = 0; i < (NR_IRQS - 1); i++) {
1042 spin_lock_irqsave(&irq_desc[i].lock, flags);
1043 action = irq_desc[i].action;
1044 if (!action)
1045 goto unlock;
1046
1047 decode_address(buf, (unsigned int)action->handler);
1048 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1049 for (action = action->next; action; action = action->next) {
1050 decode_address(buf, (unsigned int)action->handler);
1051 printk(", %s", buf);
1052 }
1053 printk("\n");
1054unlock:
1055 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1056 }
1057 }
Bryan Wu1394f032007-05-06 14:50:22 -07001058
Robin Getz226eb1e2007-10-29 17:59:07 +08001059 decode_address(buf, fp->rete);
1060 printk(KERN_NOTICE " RETE: %s\n", buf);
1061 decode_address(buf, fp->retn);
1062 printk(KERN_NOTICE " RETN: %s\n", buf);
1063 decode_address(buf, fp->retx);
1064 printk(KERN_NOTICE " RETX: %s\n", buf);
1065 decode_address(buf, fp->rets);
1066 printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001067 decode_address(buf, fp->pc);
Robin Getz13fe24f2008-01-27 15:38:56 +08001068 printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001069
Robin Getz13fe24f2008-01-27 15:38:56 +08001070 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1071 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001072 decode_address(buf, saved_dcplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001073 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001074 decode_address(buf, saved_icplb_fault_addr);
Robin Getz226eb1e2007-10-29 17:59:07 +08001075 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001076 }
1077
Robin Getz226eb1e2007-10-29 17:59:07 +08001078 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1079 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1080 fp->r0, fp->r1, fp->r2, fp->r3);
1081 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1082 fp->r4, fp->r5, fp->r6, fp->r7);
1083 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1084 fp->p0, fp->p1, fp->p2, fp->p3);
1085 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1086 fp->p4, fp->p5, fp->fp, (long)fp);
1087 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1088 fp->lb0, fp->lt0, fp->lc0);
1089 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1090 fp->lb1, fp->lt1, fp->lc1);
1091 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1092 fp->b0, fp->l0, fp->m0, fp->i0);
1093 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1094 fp->b1, fp->l1, fp->m1, fp->i1);
1095 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1096 fp->b2, fp->l2, fp->m2, fp->i2);
1097 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1098 fp->b3, fp->l3, fp->m3, fp->i3);
1099 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1100 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1101
1102 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1103 rdusp(), fp->astat);
1104
1105 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001106}
1107
1108#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1109asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1110#endif
1111
1112asmlinkage int sys_bfin_spinlock(int *spinlock)
1113{
1114 int ret = 0;
1115 int tmp = 0;
1116
1117 local_irq_disable();
1118 ret = get_user(tmp, spinlock);
1119 if (ret == 0) {
1120 if (tmp)
1121 ret = 1;
1122 tmp = 1;
1123 put_user(tmp, spinlock);
1124 }
1125 local_irq_enable();
1126 return ret;
1127}
1128
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001129int bfin_request_exception(unsigned int exception, void (*handler)(void))
1130{
1131 void (*curr_handler)(void);
1132
1133 if (exception > 0x3F)
1134 return -EINVAL;
1135
1136 curr_handler = ex_table[exception];
1137
1138 if (curr_handler != ex_replaceable)
1139 return -EBUSY;
1140
1141 ex_table[exception] = handler;
1142
1143 return 0;
1144}
1145EXPORT_SYMBOL(bfin_request_exception);
1146
1147int bfin_free_exception(unsigned int exception, void (*handler)(void))
1148{
1149 void (*curr_handler)(void);
1150
1151 if (exception > 0x3F)
1152 return -EINVAL;
1153
1154 curr_handler = ex_table[exception];
1155
1156 if (curr_handler != handler)
1157 return -EBUSY;
1158
1159 ex_table[exception] = ex_replaceable;
1160
1161 return 0;
1162}
1163EXPORT_SYMBOL(bfin_free_exception);
1164
Bryan Wu1394f032007-05-06 14:50:22 -07001165void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1166{
1167 switch (cplb_panic) {
1168 case CPLB_NO_UNLOCKED:
1169 printk(KERN_EMERG "All CPLBs are locked\n");
1170 break;
1171 case CPLB_PROT_VIOL:
1172 return;
1173 case CPLB_NO_ADDR_MATCH:
1174 return;
1175 case CPLB_UNKNOWN_ERR:
1176 printk(KERN_EMERG "Unknown CPLB Exception\n");
1177 break;
1178 }
1179
Robin Getz226eb1e2007-10-29 17:59:07 +08001180 oops_in_progress = 1;
1181
Mike Frysinger49dce912007-11-21 16:46:49 +08001182 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001183 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001184 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001185 dump_stack();
1186 panic("Unrecoverable event\n");
1187}