blob: 4be5ff0be60f75ce6679481563ee1e12173cf48b [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/kernel/traps.c
3 * Based on:
4 * Author: Hamish Macdonald
5 *
6 * Created:
7 * Description: uses S/W interrupt 15 for the system calls
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080030#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -070031#include <linux/interrupt.h>
32#include <linux/module.h>
33#include <linux/kallsyms.h>
Bryan Wud31c5ab2007-08-10 13:00:42 -070034#include <linux/fs.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080035#include <asm/traps.h>
36#include <asm/cacheflush.h>
37#include <asm/blackfin.h>
38#include <asm/irq_handler.h>
39#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080040#include <asm/fixed_code.h>
Bryan Wu1394f032007-05-06 14:50:22 -070041
42#ifdef CONFIG_KGDB
43# include <linux/debugger.h>
44# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080045
46# define CHK_DEBUGGER_TRAP() \
47 do { \
48 CHK_DEBUGGER(trapnr, sig, info.si_code, fp, ); \
49 } while (0)
50# define CHK_DEBUGGER_TRAP_MAYBE() \
51 do { \
52 if (kgdb_connected) \
53 CHK_DEBUGGER_TRAP(); \
54 } while (0)
55#else
56# define CHK_DEBUGGER_TRAP() do { } while (0)
57# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070058#endif
59
60/* Initiate the event table handler */
61void __init trap_init(void)
62{
63 CSYNC();
64 bfin_write_EVT3(trap);
65 CSYNC();
66}
67
Bryan Wu1394f032007-05-06 14:50:22 -070068int kstack_depth_to_print = 48;
69
Robin Getz226eb1e2007-10-29 17:59:07 +080070static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070071{
72 struct vm_list_struct *vml;
73 struct task_struct *p;
74 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080075 unsigned long flags, offset;
76 unsigned int in_exception = bfin_read_IPEND() & 0x10;
Bryan Wu1394f032007-05-06 14:50:22 -070077
78#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080079 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070080 const char *symname;
81 char *modname;
82 char *delim = ":";
83 char namebuf[128];
84
85 /* look up the address and see if we are in kernel space */
86 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
87
88 if (symname) {
89 /* yeah! kernel space! */
90 if (!modname)
91 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +080092 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080093 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -070094 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +080095 return;
Bryan Wu1394f032007-05-06 14:50:22 -070096
97 }
98#endif
99
Robin Getz226eb1e2007-10-29 17:59:07 +0800100 /* Problem in fixed code section? */
101 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
102 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
103 return;
104 }
105
106 /* Problem somewhere before the kernel start address */
107 if (address < CONFIG_BOOT_LOAD) {
108 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
109 return;
110 }
111
Bryan Wu1394f032007-05-06 14:50:22 -0700112 /* looks like we're off in user-land, so let's walk all the
113 * mappings of all our processes and see if we can't be a whee
114 * bit more specific
115 */
Robin Getz885be032007-10-29 17:20:41 +0800116 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700117 for_each_process(p) {
Robin Getz885be032007-10-29 17:20:41 +0800118 mm = (in_exception ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700119 if (!mm)
120 continue;
121
122 vml = mm->context.vmlist;
123 while (vml) {
124 struct vm_area_struct *vma = vml->vma;
125
126 if (address >= vma->vm_start && address < vma->vm_end) {
127 char *name = p->comm;
128 struct file *file = vma->vm_file;
129 if (file) {
130 char _tmpbuf[256];
131 name = d_path(file->f_dentry,
132 file->f_vfsmnt,
133 _tmpbuf,
134 sizeof(_tmpbuf));
135 }
136
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800137 /* FLAT does not have its text aligned to the start of
138 * the map while FDPIC ELF does ...
139 */
140 if (current->mm &&
141 (address > current->mm->start_code) &&
142 (address < current->mm->end_code))
143 offset = address - current->mm->start_code;
144 else
145 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
146
Robin Getz226eb1e2007-10-29 17:59:07 +0800147 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
Robin Getz885be032007-10-29 17:20:41 +0800148 (void *)address, name, offset);
149 if (!in_exception)
150 mmput(mm);
151 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700152 }
153
154 vml = vml->next;
155 }
Robin Getz885be032007-10-29 17:20:41 +0800156 if (!in_exception)
157 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700158 }
Bryan Wu1394f032007-05-06 14:50:22 -0700159
160 /* we were unable to find this address anywhere */
Robin Getz4a589e12007-11-12 22:46:46 +0800161 sprintf(buf, "<0x%p> /* unknown address */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800162
163done:
164 write_unlock_irqrestore(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700165}
166
Robin Getz2ebcade2007-10-09 17:24:30 +0800167asmlinkage void double_fault_c(struct pt_regs *fp)
168{
Robin Getz226eb1e2007-10-29 17:59:07 +0800169 console_verbose();
170 oops_in_progress = 1;
Robin Getz2ebcade2007-10-09 17:24:30 +0800171 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800172 dump_bfin_process(fp);
173 dump_bfin_mem((void *)fp->retx);
174 show_regs(fp);
Robin Getz2ebcade2007-10-09 17:24:30 +0800175 panic("Double Fault - unrecoverable event\n");
176
177}
178
Bryan Wu1394f032007-05-06 14:50:22 -0700179asmlinkage void trap_c(struct pt_regs *fp)
180{
Robin Getz518039b2007-07-25 11:03:28 +0800181#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
182 int j;
183#endif
184 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700185 siginfo_t info;
186 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
187
Bryan Wu1394f032007-05-06 14:50:22 -0700188 trace_buffer_save(j);
189
Robin Getz226eb1e2007-10-29 17:59:07 +0800190 /* Important - be very careful dereferncing pointers - will lead to
191 * double faults if the stack has become corrupt
192 */
193
194 /* If the fault was caused by a kernel thread, or interrupt handler
195 * we will kernel panic, so the system reboots.
196 * If KGDB is enabled, don't set this for kernel breakpoints
197 */
198 if ((bfin_read_IPEND() & 0xFFC0)
199#ifdef CONFIG_KGDB
200 && trapnr != VEC_EXCPT02
201#endif
202 ){
203 console_verbose();
204 oops_in_progress = 1;
205 } else if (current) {
206 if (current->mm == NULL) {
207 console_verbose();
208 oops_in_progress = 1;
209 }
210 }
211
Bryan Wu1394f032007-05-06 14:50:22 -0700212 /* trap_c() will be called for exceptions. During exceptions
213 * processing, the pc value should be set with retx value.
214 * With this change we can cleanup some code in signal.c- TODO
215 */
216 fp->orig_pc = fp->retx;
217 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
218 trapnr, fp->ipend, fp->pc, fp->retx); */
219
220 /* send the appropriate signal to the user program */
221 switch (trapnr) {
222
223 /* This table works in conjuction with the one in ./mach-common/entry.S
224 * Some exceptions are handled there (in assembly, in exception space)
225 * Some are handled here, (in C, in interrupt space)
226 * Some, like CPLB, are handled in both, where the normal path is
227 * handled in assembly/exception space, and the error path is handled
228 * here
229 */
230
231 /* 0x00 - Linux Syscall, getting here is an error */
232 /* 0x01 - userspace gdb breakpoint, handled here */
233 case VEC_EXCPT01:
234 info.si_code = TRAP_ILLTRAP;
235 sig = SIGTRAP;
236 CHK_DEBUGGER_TRAP_MAYBE();
237 /* Check if this is a breakpoint in kernel space */
238 if (fp->ipend & 0xffc0)
239 return;
240 else
241 break;
242#ifdef CONFIG_KGDB
243 case VEC_EXCPT02 : /* gdb connection */
244 info.si_code = TRAP_ILLTRAP;
245 sig = SIGTRAP;
246 CHK_DEBUGGER_TRAP();
247 return;
248#else
249 /* 0x02 - User Defined, Caught by default */
250#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800251 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700252 case VEC_EXCPT03:
253 info.si_code = SEGV_STACKFLOW;
254 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800255 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700256 CHK_DEBUGGER_TRAP();
257 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800258 /* 0x04 - User Defined, Caught by default */
Bryan Wu1394f032007-05-06 14:50:22 -0700259 /* 0x05 - User Defined, Caught by default */
260 /* 0x06 - User Defined, Caught by default */
261 /* 0x07 - User Defined, Caught by default */
262 /* 0x08 - User Defined, Caught by default */
263 /* 0x09 - User Defined, Caught by default */
264 /* 0x0A - User Defined, Caught by default */
265 /* 0x0B - User Defined, Caught by default */
266 /* 0x0C - User Defined, Caught by default */
267 /* 0x0D - User Defined, Caught by default */
268 /* 0x0E - User Defined, Caught by default */
269 /* 0x0F - User Defined, Caught by default */
270 /* 0x10 HW Single step, handled here */
271 case VEC_STEP:
272 info.si_code = TRAP_STEP;
273 sig = SIGTRAP;
274 CHK_DEBUGGER_TRAP_MAYBE();
275 /* Check if this is a single step in kernel space */
276 if (fp->ipend & 0xffc0)
277 return;
278 else
279 break;
280 /* 0x11 - Trace Buffer Full, handled here */
281 case VEC_OVFLOW:
282 info.si_code = TRAP_TRACEFLOW;
283 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800284 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700285 CHK_DEBUGGER_TRAP();
286 break;
287 /* 0x12 - Reserved, Caught by default */
288 /* 0x13 - Reserved, Caught by default */
289 /* 0x14 - Reserved, Caught by default */
290 /* 0x15 - Reserved, Caught by default */
291 /* 0x16 - Reserved, Caught by default */
292 /* 0x17 - Reserved, Caught by default */
293 /* 0x18 - Reserved, Caught by default */
294 /* 0x19 - Reserved, Caught by default */
295 /* 0x1A - Reserved, Caught by default */
296 /* 0x1B - Reserved, Caught by default */
297 /* 0x1C - Reserved, Caught by default */
298 /* 0x1D - Reserved, Caught by default */
299 /* 0x1E - Reserved, Caught by default */
300 /* 0x1F - Reserved, Caught by default */
301 /* 0x20 - Reserved, Caught by default */
302 /* 0x21 - Undefined Instruction, handled here */
303 case VEC_UNDEF_I:
304 info.si_code = ILL_ILLOPC;
305 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800306 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700307 CHK_DEBUGGER_TRAP();
308 break;
309 /* 0x22 - Illegal Instruction Combination, handled here */
310 case VEC_ILGAL_I:
311 info.si_code = ILL_ILLPARAOP;
312 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800313 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700314 CHK_DEBUGGER_TRAP();
315 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800316 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700317 case VEC_CPLB_VL:
318 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800319 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800320 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700321 CHK_DEBUGGER_TRAP();
322 break;
323 /* 0x24 - Data access misaligned, handled here */
324 case VEC_MISALI_D:
325 info.si_code = BUS_ADRALN;
326 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800327 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700328 CHK_DEBUGGER_TRAP();
329 break;
330 /* 0x25 - Unrecoverable Event, handled here */
331 case VEC_UNCOV:
332 info.si_code = ILL_ILLEXCPT;
333 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800334 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700335 CHK_DEBUGGER_TRAP();
336 break;
337 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
338 error case is handled here */
339 case VEC_CPLB_M:
340 info.si_code = BUS_ADRALN;
341 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800342 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700343 CHK_DEBUGGER_TRAP();
344 break;
345 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
346 case VEC_CPLB_MHIT:
347 info.si_code = ILL_CPLB_MULHIT;
348#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
349 sig = SIGSEGV;
Robin Getz226eb1e2007-10-29 17:59:07 +0800350 printk(KERN_NOTICE "NULL pointer access (probably)\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700351#else
352 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800353 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700354#endif
355 CHK_DEBUGGER_TRAP();
356 break;
357 /* 0x28 - Emulation Watchpoint, handled here */
358 case VEC_WATCH:
359 info.si_code = TRAP_WATCHPT;
360 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800361 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700362 CHK_DEBUGGER_TRAP_MAYBE();
363 /* Check if this is a watchpoint in kernel space */
364 if (fp->ipend & 0xffc0)
365 return;
366 else
367 break;
368#ifdef CONFIG_BF535
369 /* 0x29 - Instruction fetch access error (535 only) */
370 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
371 info.si_code = BUS_OPFETCH;
372 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800373 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700374 CHK_DEBUGGER_TRAP();
375 break;
376#else
377 /* 0x29 - Reserved, Caught by default */
378#endif
379 /* 0x2A - Instruction fetch misaligned, handled here */
380 case VEC_MISALI_I:
381 info.si_code = BUS_ADRALN;
382 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800383 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700384 CHK_DEBUGGER_TRAP();
385 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800386 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700387 case VEC_CPLB_I_VL:
388 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800389 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800390 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700391 CHK_DEBUGGER_TRAP();
392 break;
393 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
394 case VEC_CPLB_I_M:
395 info.si_code = ILL_CPLB_MISS;
396 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800397 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700398 CHK_DEBUGGER_TRAP();
399 break;
400 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
401 case VEC_CPLB_I_MHIT:
402 info.si_code = ILL_CPLB_MULHIT;
403#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
404 sig = SIGSEGV;
Robin Getz226eb1e2007-10-29 17:59:07 +0800405 printk(KERN_NOTICE "Jump to address 0 - 0x0fff\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700406#else
407 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800408 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700409#endif
410 CHK_DEBUGGER_TRAP();
411 break;
412 /* 0x2E - Illegal use of Supervisor Resource, handled here */
413 case VEC_ILL_RES:
414 info.si_code = ILL_PRVOPC;
415 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800416 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700417 CHK_DEBUGGER_TRAP();
418 break;
419 /* 0x2F - Reserved, Caught by default */
420 /* 0x30 - Reserved, Caught by default */
421 /* 0x31 - Reserved, Caught by default */
422 /* 0x32 - Reserved, Caught by default */
423 /* 0x33 - Reserved, Caught by default */
424 /* 0x34 - Reserved, Caught by default */
425 /* 0x35 - Reserved, Caught by default */
426 /* 0x36 - Reserved, Caught by default */
427 /* 0x37 - Reserved, Caught by default */
428 /* 0x38 - Reserved, Caught by default */
429 /* 0x39 - Reserved, Caught by default */
430 /* 0x3A - Reserved, Caught by default */
431 /* 0x3B - Reserved, Caught by default */
432 /* 0x3C - Reserved, Caught by default */
433 /* 0x3D - Reserved, Caught by default */
434 /* 0x3E - Reserved, Caught by default */
435 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800436 case VEC_HWERR:
437 info.si_code = BUS_ADRALN;
438 sig = SIGBUS;
439 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
440 /* System MMR Error */
441 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
442 info.si_code = BUS_ADRALN;
443 sig = SIGBUS;
444 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
445 break;
446 /* External Memory Addressing Error */
447 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
448 info.si_code = BUS_ADRERR;
449 sig = SIGBUS;
450 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
451 break;
452 /* Performance Monitor Overflow */
453 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
454 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
455 break;
456 /* RAISE 5 instruction */
457 case (SEQSTAT_HWERRCAUSE_RAISE_5):
458 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
459 break;
460 default: /* Reserved */
461 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
462 break;
463 }
464 CHK_DEBUGGER_TRAP();
465 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700466 default:
467 info.si_code = TRAP_ILLTRAP;
468 sig = SIGTRAP;
469 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
470 (fp->seqstat & SEQSTAT_EXCAUSE));
471 CHK_DEBUGGER_TRAP();
472 break;
473 }
474
Robin Getz226eb1e2007-10-29 17:59:07 +0800475 BUG_ON(sig == 0);
476
477 if (sig != SIGTRAP) {
Bryan Wu1394f032007-05-06 14:50:22 -0700478 unsigned long stack;
Mike Frysinger49dce912007-11-21 16:46:49 +0800479 dump_bfin_process(fp);
Robin Getz13fe24f2008-01-27 15:38:56 +0800480 /* Is it an interrupt, or an exception? */
481 if (trapnr == VEC_HWERR)
482 dump_bfin_mem((void *)fp->pc);
483 else
484 dump_bfin_mem((void *)fp->retx);
Mike Frysinger49dce912007-11-21 16:46:49 +0800485 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800486
487 /* Print out the trace buffer if it makes sense */
488#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
489 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
490 printk(KERN_NOTICE "No trace since you do not have "
491 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
492 KERN_NOTICE "\n");
493 else
494#endif
495 dump_bfin_trace_buffer();
Bryan Wu1394f032007-05-06 14:50:22 -0700496 show_stack(current, &stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800497 if (oops_in_progress) {
498#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800499 printk(KERN_EMERG "Please turn on "
500 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800501#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700502 panic("Kernel exception");
Robin Getz226eb1e2007-10-29 17:59:07 +0800503 }
Bryan Wu1394f032007-05-06 14:50:22 -0700504 }
Robin Getzfb322912007-11-21 16:38:05 +0800505
Robin Getzce3afa12007-10-09 17:28:36 +0800506 info.si_signo = sig;
507 info.si_errno = 0;
508 info.si_addr = (void *)fp->pc;
509 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700510
Robin Getzfb322912007-11-21 16:38:05 +0800511 /* Ensure that bad return addresses don't end up in an infinite
512 * loop, due to speculative loads/reads. This needs to be done after
513 * the signal has been sent.
514 */
515 if (trapnr == VEC_CPLB_I_M && sig != SIGTRAP)
516 fp->pc = SAFE_USER_INSTRUCTION;
517
Bryan Wu1394f032007-05-06 14:50:22 -0700518 trace_buffer_restore(j);
519 return;
520}
521
522/* Typical exception handling routines */
523
Robin Getz518039b2007-07-25 11:03:28 +0800524#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
525
Bryan Wu1394f032007-05-06 14:50:22 -0700526void dump_bfin_trace_buffer(void)
527{
Robin Getz518039b2007-07-25 11:03:28 +0800528#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
529 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800530 char buf[150];
Robin Getz518039b2007-07-25 11:03:28 +0800531#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
532 int j, index;
533#endif
534
Bryan Wu1394f032007-05-06 14:50:22 -0700535 trace_buffer_save(tflags);
536
Robin Getz226eb1e2007-10-29 17:59:07 +0800537 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800538
Bryan Wu1394f032007-05-06 14:50:22 -0700539 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800540 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800541 decode_address(buf, (unsigned long)bfin_read_TBUF());
542 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
543 decode_address(buf, (unsigned long)bfin_read_TBUF());
544 printk(KERN_NOTICE " Source : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700545 }
546 }
547
Robin Getz518039b2007-07-25 11:03:28 +0800548#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
549 if (trace_buff_offset)
550 index = trace_buff_offset/4 - 1;
551 else
552 index = EXPAND_LEN;
553
554 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
555 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800556 decode_address(buf, software_trace_buff[index]);
557 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800558 index -= 1;
559 if (index < 0 )
560 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800561 decode_address(buf, software_trace_buff[index]);
562 printk(KERN_NOTICE " Source : %s\n", buf);
Robin Getz518039b2007-07-25 11:03:28 +0800563 index -= 1;
564 if (index < 0)
565 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800566 j--;
567 i++;
568 }
569#endif
570
Bryan Wu1394f032007-05-06 14:50:22 -0700571 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800572#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700573}
574EXPORT_SYMBOL(dump_bfin_trace_buffer);
575
576static void show_trace(struct task_struct *tsk, unsigned long *sp)
577{
578 unsigned long addr;
579
Robin Getz226eb1e2007-10-29 17:59:07 +0800580 printk(KERN_NOTICE "\n" KERN_NOTICE "Call Trace:\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700581
582 while (!kstack_end(sp)) {
583 addr = *sp++;
584 /*
585 * If the address is either in the text segment of the
586 * kernel, or in the region which contains vmalloc'ed
587 * memory, it *may* be the address of a calling
588 * routine; if so, print it so that someone tracing
589 * down the cause of the crash will be able to figure
590 * out the call path that was taken.
591 */
592 if (kernel_text_address(addr))
593 print_ip_sym(addr);
594 }
595
Robin Getz226eb1e2007-10-29 17:59:07 +0800596 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700597}
598
599void show_stack(struct task_struct *task, unsigned long *stack)
600{
601 unsigned long *endstack, addr;
602 int i;
603
604 /* Cannot call dump_bfin_trace_buffer() here as show_stack() is
605 * called externally in some places in the kernel.
606 */
607
608 if (!stack) {
609 if (task)
610 stack = (unsigned long *)task->thread.ksp;
611 else
612 stack = (unsigned long *)&stack;
613 }
614
615 addr = (unsigned long)stack;
616 endstack = (unsigned long *)PAGE_ALIGN(addr);
617
Robin Getz226eb1e2007-10-29 17:59:07 +0800618 printk(KERN_NOTICE "Stack from %08lx:", (unsigned long)stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700619 for (i = 0; i < kstack_depth_to_print; i++) {
620 if (stack + 1 > endstack)
621 break;
622 if (i % 8 == 0)
Robin Getz226eb1e2007-10-29 17:59:07 +0800623 printk("\n" KERN_NOTICE " ");
Bryan Wu1394f032007-05-06 14:50:22 -0700624 printk(" %08lx", *stack++);
625 }
Robin Getz226eb1e2007-10-29 17:59:07 +0800626 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700627
628 show_trace(task, stack);
629}
630
631void dump_stack(void)
632{
633 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800634#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700635 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800636#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700637 trace_buffer_save(tflags);
638 dump_bfin_trace_buffer();
639 show_stack(current, &stack);
640 trace_buffer_restore(tflags);
641}
Bryan Wu1394f032007-05-06 14:50:22 -0700642EXPORT_SYMBOL(dump_stack);
643
Mike Frysinger49dce912007-11-21 16:46:49 +0800644void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700645{
Mike Frysinger49dce912007-11-21 16:46:49 +0800646 /* We should be able to look at fp->ipend, but we don't push it on the
647 * stack all the time, so do this until we fix that */
648 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800649
Mike Frysinger49dce912007-11-21 16:46:49 +0800650 if (oops_in_progress)
651 printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800652
Mike Frysinger49dce912007-11-21 16:46:49 +0800653 if (context & 0x0020)
654 printk(KERN_NOTICE "Deferred excecption or HW Error context\n");
655 else if (context & 0x3FC0)
656 printk(KERN_NOTICE "Interrupt context\n");
657 else if (context & 0x4000)
658 printk(KERN_NOTICE "Deferred Interrupt context\n");
659 else if (context & 0x8000)
660 printk(KERN_NOTICE "Kernel process context\n");
661
662 if (current->pid && current->mm) {
663 printk(KERN_NOTICE "CURRENT PROCESS:\n");
664 printk(KERN_NOTICE "COMM=%s PID=%d\n",
665 current->comm, current->pid);
666
667 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
668 KERN_NOTICE "BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
669 KERN_NOTICE "\n",
670 (void *)current->mm->start_code,
671 (void *)current->mm->end_code,
672 (void *)current->mm->start_data,
673 (void *)current->mm->end_data,
674 (void *)current->mm->end_data,
675 (void *)current->mm->brk,
676 (void *)current->mm->start_stack);
677 } else
678 printk(KERN_NOTICE "\n" KERN_NOTICE
679 "No Valid process in current context\n");
680}
681
682void dump_bfin_mem(void *retaddr)
683{
Bryan Wu1394f032007-05-06 14:50:22 -0700684
Robin Getz226eb1e2007-10-29 17:59:07 +0800685 if (retaddr >= (void *)FIXED_CODE_START && retaddr < (void *)physical_mem_end
Bryan Wu1394f032007-05-06 14:50:22 -0700686#if L1_CODE_LENGTH != 0
687 /* FIXME: Copy the code out of L1 Instruction SRAM through dma
688 memcpy. */
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800689 && !(retaddr >= (void *)L1_CODE_START
690 && retaddr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
Bryan Wu1394f032007-05-06 14:50:22 -0700691#endif
692 ) {
Robin Getzc5d88d92007-06-21 11:34:16 +0800693 int i = ((unsigned int)retaddr & 0xFFFFFFF0) - 32;
Bryan Wu1394f032007-05-06 14:50:22 -0700694 unsigned short x = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800695 printk(KERN_NOTICE "return address: [0x%p]; contents of:", retaddr);
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800696 for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
697 if (!(i & 0xF))
Robin Getz226eb1e2007-10-29 17:59:07 +0800698 printk("\n" KERN_NOTICE "0x%08x: ", i);
Robin Getzc5d88d92007-06-21 11:34:16 +0800699
700 if (get_user(x, (unsigned short *)i))
Bryan Wu1394f032007-05-06 14:50:22 -0700701 break;
702#ifndef CONFIG_DEBUG_HWERR
703 /* If one of the last few instructions was a STI
Simon Arlottd2d50aa2007-06-11 15:31:30 +0800704 * it is likely that the error occured awhile ago
Robin Getz226eb1e2007-10-29 17:59:07 +0800705 * and we just noticed. This only happens in kernel
706 * context, which should mean an oops is happening
Bryan Wu1394f032007-05-06 14:50:22 -0700707 */
Robin Getz226eb1e2007-10-29 17:59:07 +0800708 if (oops_in_progress && x >= 0x0040 && x <= 0x0047 && i <= 0)
Robin Getz13fe24f2008-01-27 15:38:56 +0800709 printk(KERN_EMERG "\n"
710 KERN_EMERG "WARNING : You should reconfigure"
Robin Getzc5d88d92007-06-21 11:34:16 +0800711 " the kernel to turn on\n"
Robin Getz13fe24f2008-01-27 15:38:56 +0800712 KERN_EMERG " 'Hardware error interrupt debugging'\n"
713 KERN_EMERG " The rest of this error is meanless\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700714#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800715 if (i == (unsigned int)retaddr)
Robin Getzc5d88d92007-06-21 11:34:16 +0800716 printk("[%04x]", x);
717 else
718 printk(" %04x ", x);
Bryan Wu1394f032007-05-06 14:50:22 -0700719 }
Robin Getz226eb1e2007-10-29 17:59:07 +0800720 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700721 } else
Robin Getz226eb1e2007-10-29 17:59:07 +0800722 printk("\n" KERN_NOTICE
Robin Getz6a3f0b42007-11-15 15:10:48 +0800723 "Cannot look at the [PC] <%p> for it is"
724 " in unreadable memory - sorry\n", retaddr);
Mike Frysinger49dce912007-11-21 16:46:49 +0800725}
726
727void show_regs(struct pt_regs *fp)
728{
729 char buf [150];
Bryan Wu1394f032007-05-06 14:50:22 -0700730
Robin Getz226eb1e2007-10-29 17:59:07 +0800731 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\n");
732 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
733 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz13fe24f2008-01-27 15:38:56 +0800734 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
735 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
736 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
737 fp->seqstat & SEQSTAT_EXCAUSE);
Bryan Wu1394f032007-05-06 14:50:22 -0700738
Robin Getz226eb1e2007-10-29 17:59:07 +0800739 decode_address(buf, fp->rete);
740 printk(KERN_NOTICE " RETE: %s\n", buf);
741 decode_address(buf, fp->retn);
742 printk(KERN_NOTICE " RETN: %s\n", buf);
743 decode_address(buf, fp->retx);
744 printk(KERN_NOTICE " RETX: %s\n", buf);
745 decode_address(buf, fp->rets);
746 printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +0800747 decode_address(buf, fp->pc);
Robin Getz13fe24f2008-01-27 15:38:56 +0800748 printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700749
Robin Getz13fe24f2008-01-27 15:38:56 +0800750 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
751 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800752 decode_address(buf, bfin_read_DCPLB_FAULT_ADDR());
753 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
754 decode_address(buf, bfin_read_ICPLB_FAULT_ADDR());
755 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700756 }
757
Robin Getz226eb1e2007-10-29 17:59:07 +0800758 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
759 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
760 fp->r0, fp->r1, fp->r2, fp->r3);
761 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
762 fp->r4, fp->r5, fp->r6, fp->r7);
763 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
764 fp->p0, fp->p1, fp->p2, fp->p3);
765 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
766 fp->p4, fp->p5, fp->fp, (long)fp);
767 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
768 fp->lb0, fp->lt0, fp->lc0);
769 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
770 fp->lb1, fp->lt1, fp->lc1);
771 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
772 fp->b0, fp->l0, fp->m0, fp->i0);
773 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
774 fp->b1, fp->l1, fp->m1, fp->i1);
775 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
776 fp->b2, fp->l2, fp->m2, fp->i2);
777 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
778 fp->b3, fp->l3, fp->m3, fp->i3);
779 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
780 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
781
782 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
783 rdusp(), fp->astat);
784
785 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700786}
787
788#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
789asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
790#endif
791
792asmlinkage int sys_bfin_spinlock(int *spinlock)
793{
794 int ret = 0;
795 int tmp = 0;
796
797 local_irq_disable();
798 ret = get_user(tmp, spinlock);
799 if (ret == 0) {
800 if (tmp)
801 ret = 1;
802 tmp = 1;
803 put_user(tmp, spinlock);
804 }
805 local_irq_enable();
806 return ret;
807}
808
Mike Frysinger1ffe6642007-08-05 17:14:04 +0800809int bfin_request_exception(unsigned int exception, void (*handler)(void))
810{
811 void (*curr_handler)(void);
812
813 if (exception > 0x3F)
814 return -EINVAL;
815
816 curr_handler = ex_table[exception];
817
818 if (curr_handler != ex_replaceable)
819 return -EBUSY;
820
821 ex_table[exception] = handler;
822
823 return 0;
824}
825EXPORT_SYMBOL(bfin_request_exception);
826
827int bfin_free_exception(unsigned int exception, void (*handler)(void))
828{
829 void (*curr_handler)(void);
830
831 if (exception > 0x3F)
832 return -EINVAL;
833
834 curr_handler = ex_table[exception];
835
836 if (curr_handler != handler)
837 return -EBUSY;
838
839 ex_table[exception] = ex_replaceable;
840
841 return 0;
842}
843EXPORT_SYMBOL(bfin_free_exception);
844
Bryan Wu1394f032007-05-06 14:50:22 -0700845void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
846{
847 switch (cplb_panic) {
848 case CPLB_NO_UNLOCKED:
849 printk(KERN_EMERG "All CPLBs are locked\n");
850 break;
851 case CPLB_PROT_VIOL:
852 return;
853 case CPLB_NO_ADDR_MATCH:
854 return;
855 case CPLB_UNKNOWN_ERR:
856 printk(KERN_EMERG "Unknown CPLB Exception\n");
857 break;
858 }
859
Robin Getz226eb1e2007-10-29 17:59:07 +0800860 oops_in_progress = 1;
861
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800862 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR());
863 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR());
Mike Frysinger49dce912007-11-21 16:46:49 +0800864 dump_bfin_process(fp);
865 dump_bfin_mem((void *)fp->retx);
866 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -0700867 dump_stack();
868 panic("Unrecoverable event\n");
869}