blob: d88098c58bfa053ff2c2405c11f0a5d4e1bde5d9 [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");
172 dump_bfin_regs(fp, (void *)fp->retx);
173 panic("Double Fault - unrecoverable event\n");
174
175}
176
Bryan Wu1394f032007-05-06 14:50:22 -0700177asmlinkage void trap_c(struct pt_regs *fp)
178{
Robin Getz518039b2007-07-25 11:03:28 +0800179#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
180 int j;
181#endif
182 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700183 siginfo_t info;
184 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
185
Bryan Wu1394f032007-05-06 14:50:22 -0700186 trace_buffer_save(j);
187
Robin Getz226eb1e2007-10-29 17:59:07 +0800188 /* Important - be very careful dereferncing pointers - will lead to
189 * double faults if the stack has become corrupt
190 */
191
192 /* If the fault was caused by a kernel thread, or interrupt handler
193 * we will kernel panic, so the system reboots.
194 * If KGDB is enabled, don't set this for kernel breakpoints
195 */
196 if ((bfin_read_IPEND() & 0xFFC0)
197#ifdef CONFIG_KGDB
198 && trapnr != VEC_EXCPT02
199#endif
200 ){
201 console_verbose();
202 oops_in_progress = 1;
203 } else if (current) {
204 if (current->mm == NULL) {
205 console_verbose();
206 oops_in_progress = 1;
207 }
208 }
209
Bryan Wu1394f032007-05-06 14:50:22 -0700210 /* trap_c() will be called for exceptions. During exceptions
211 * processing, the pc value should be set with retx value.
212 * With this change we can cleanup some code in signal.c- TODO
213 */
214 fp->orig_pc = fp->retx;
215 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
216 trapnr, fp->ipend, fp->pc, fp->retx); */
217
218 /* send the appropriate signal to the user program */
219 switch (trapnr) {
220
221 /* This table works in conjuction with the one in ./mach-common/entry.S
222 * Some exceptions are handled there (in assembly, in exception space)
223 * Some are handled here, (in C, in interrupt space)
224 * Some, like CPLB, are handled in both, where the normal path is
225 * handled in assembly/exception space, and the error path is handled
226 * here
227 */
228
229 /* 0x00 - Linux Syscall, getting here is an error */
230 /* 0x01 - userspace gdb breakpoint, handled here */
231 case VEC_EXCPT01:
232 info.si_code = TRAP_ILLTRAP;
233 sig = SIGTRAP;
234 CHK_DEBUGGER_TRAP_MAYBE();
235 /* Check if this is a breakpoint in kernel space */
236 if (fp->ipend & 0xffc0)
237 return;
238 else
239 break;
240#ifdef CONFIG_KGDB
241 case VEC_EXCPT02 : /* gdb connection */
242 info.si_code = TRAP_ILLTRAP;
243 sig = SIGTRAP;
244 CHK_DEBUGGER_TRAP();
245 return;
246#else
247 /* 0x02 - User Defined, Caught by default */
248#endif
Mike Frysinger9401e612007-07-12 11:50:43 +0800249 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700250 case VEC_EXCPT03:
251 info.si_code = SEGV_STACKFLOW;
252 sig = SIGSEGV;
Robin Getz569a50c2007-11-21 16:35:57 +0800253 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700254 CHK_DEBUGGER_TRAP();
255 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800256 /* 0x04 - User Defined, Caught by default */
Bryan Wu1394f032007-05-06 14:50:22 -0700257 /* 0x05 - User Defined, Caught by default */
258 /* 0x06 - User Defined, Caught by default */
259 /* 0x07 - User Defined, Caught by default */
260 /* 0x08 - User Defined, Caught by default */
261 /* 0x09 - User Defined, Caught by default */
262 /* 0x0A - User Defined, Caught by default */
263 /* 0x0B - User Defined, Caught by default */
264 /* 0x0C - User Defined, Caught by default */
265 /* 0x0D - User Defined, Caught by default */
266 /* 0x0E - User Defined, Caught by default */
267 /* 0x0F - User Defined, Caught by default */
268 /* 0x10 HW Single step, handled here */
269 case VEC_STEP:
270 info.si_code = TRAP_STEP;
271 sig = SIGTRAP;
272 CHK_DEBUGGER_TRAP_MAYBE();
273 /* Check if this is a single step in kernel space */
274 if (fp->ipend & 0xffc0)
275 return;
276 else
277 break;
278 /* 0x11 - Trace Buffer Full, handled here */
279 case VEC_OVFLOW:
280 info.si_code = TRAP_TRACEFLOW;
281 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800282 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700283 CHK_DEBUGGER_TRAP();
284 break;
285 /* 0x12 - Reserved, Caught by default */
286 /* 0x13 - Reserved, Caught by default */
287 /* 0x14 - Reserved, Caught by default */
288 /* 0x15 - Reserved, Caught by default */
289 /* 0x16 - Reserved, Caught by default */
290 /* 0x17 - Reserved, Caught by default */
291 /* 0x18 - Reserved, Caught by default */
292 /* 0x19 - Reserved, Caught by default */
293 /* 0x1A - Reserved, Caught by default */
294 /* 0x1B - Reserved, Caught by default */
295 /* 0x1C - Reserved, Caught by default */
296 /* 0x1D - Reserved, Caught by default */
297 /* 0x1E - Reserved, Caught by default */
298 /* 0x1F - Reserved, Caught by default */
299 /* 0x20 - Reserved, Caught by default */
300 /* 0x21 - Undefined Instruction, handled here */
301 case VEC_UNDEF_I:
302 info.si_code = ILL_ILLOPC;
303 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800304 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700305 CHK_DEBUGGER_TRAP();
306 break;
307 /* 0x22 - Illegal Instruction Combination, handled here */
308 case VEC_ILGAL_I:
309 info.si_code = ILL_ILLPARAOP;
310 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800311 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700312 CHK_DEBUGGER_TRAP();
313 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800314 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700315 case VEC_CPLB_VL:
316 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800317 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800318 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700319 CHK_DEBUGGER_TRAP();
320 break;
321 /* 0x24 - Data access misaligned, handled here */
322 case VEC_MISALI_D:
323 info.si_code = BUS_ADRALN;
324 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800325 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700326 CHK_DEBUGGER_TRAP();
327 break;
328 /* 0x25 - Unrecoverable Event, handled here */
329 case VEC_UNCOV:
330 info.si_code = ILL_ILLEXCPT;
331 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800332 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700333 CHK_DEBUGGER_TRAP();
334 break;
335 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
336 error case is handled here */
337 case VEC_CPLB_M:
338 info.si_code = BUS_ADRALN;
339 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800340 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700341 CHK_DEBUGGER_TRAP();
342 break;
343 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
344 case VEC_CPLB_MHIT:
345 info.si_code = ILL_CPLB_MULHIT;
346#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
347 sig = SIGSEGV;
Robin Getz226eb1e2007-10-29 17:59:07 +0800348 printk(KERN_NOTICE "NULL pointer access (probably)\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700349#else
350 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800351 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700352#endif
353 CHK_DEBUGGER_TRAP();
354 break;
355 /* 0x28 - Emulation Watchpoint, handled here */
356 case VEC_WATCH:
357 info.si_code = TRAP_WATCHPT;
358 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800359 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700360 CHK_DEBUGGER_TRAP_MAYBE();
361 /* Check if this is a watchpoint in kernel space */
362 if (fp->ipend & 0xffc0)
363 return;
364 else
365 break;
366#ifdef CONFIG_BF535
367 /* 0x29 - Instruction fetch access error (535 only) */
368 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
369 info.si_code = BUS_OPFETCH;
370 sig = SIGBUS;
Robin Getz226eb1e2007-10-29 17:59:07 +0800371 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700372 CHK_DEBUGGER_TRAP();
373 break;
374#else
375 /* 0x29 - Reserved, Caught by default */
376#endif
377 /* 0x2A - Instruction fetch misaligned, handled here */
378 case VEC_MISALI_I:
379 info.si_code = BUS_ADRALN;
380 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800381 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700382 CHK_DEBUGGER_TRAP();
383 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800384 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700385 case VEC_CPLB_I_VL:
386 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800387 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800388 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700389 CHK_DEBUGGER_TRAP();
390 break;
391 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
392 case VEC_CPLB_I_M:
393 info.si_code = ILL_CPLB_MISS;
394 sig = SIGBUS;
Robin Getz569a50c2007-11-21 16:35:57 +0800395 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700396 CHK_DEBUGGER_TRAP();
397 break;
398 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
399 case VEC_CPLB_I_MHIT:
400 info.si_code = ILL_CPLB_MULHIT;
401#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
402 sig = SIGSEGV;
Robin Getz226eb1e2007-10-29 17:59:07 +0800403 printk(KERN_NOTICE "Jump to address 0 - 0x0fff\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700404#else
405 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800406 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700407#endif
408 CHK_DEBUGGER_TRAP();
409 break;
410 /* 0x2E - Illegal use of Supervisor Resource, handled here */
411 case VEC_ILL_RES:
412 info.si_code = ILL_PRVOPC;
413 sig = SIGILL;
Robin Getz569a50c2007-11-21 16:35:57 +0800414 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700415 CHK_DEBUGGER_TRAP();
416 break;
417 /* 0x2F - Reserved, Caught by default */
418 /* 0x30 - Reserved, Caught by default */
419 /* 0x31 - Reserved, Caught by default */
420 /* 0x32 - Reserved, Caught by default */
421 /* 0x33 - Reserved, Caught by default */
422 /* 0x34 - Reserved, Caught by default */
423 /* 0x35 - Reserved, Caught by default */
424 /* 0x36 - Reserved, Caught by default */
425 /* 0x37 - Reserved, Caught by default */
426 /* 0x38 - Reserved, Caught by default */
427 /* 0x39 - Reserved, Caught by default */
428 /* 0x3A - Reserved, Caught by default */
429 /* 0x3B - Reserved, Caught by default */
430 /* 0x3C - Reserved, Caught by default */
431 /* 0x3D - Reserved, Caught by default */
432 /* 0x3E - Reserved, Caught by default */
433 /* 0x3F - Reserved, Caught by default */
434 default:
435 info.si_code = TRAP_ILLTRAP;
436 sig = SIGTRAP;
437 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
438 (fp->seqstat & SEQSTAT_EXCAUSE));
439 CHK_DEBUGGER_TRAP();
440 break;
441 }
442
Robin Getz226eb1e2007-10-29 17:59:07 +0800443 BUG_ON(sig == 0);
444
445 if (sig != SIGTRAP) {
Bryan Wu1394f032007-05-06 14:50:22 -0700446 unsigned long stack;
447 dump_bfin_regs(fp, (void *)fp->retx);
Robin Getz226eb1e2007-10-29 17:59:07 +0800448
449 /* Print out the trace buffer if it makes sense */
450#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
451 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
452 printk(KERN_NOTICE "No trace since you do not have "
453 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
454 KERN_NOTICE "\n");
455 else
456#endif
457 dump_bfin_trace_buffer();
Bryan Wu1394f032007-05-06 14:50:22 -0700458 show_stack(current, &stack);
Robin Getz226eb1e2007-10-29 17:59:07 +0800459 if (oops_in_progress) {
460#ifndef CONFIG_ACCESS_CHECK
Robin Getz90c7f462007-11-18 00:35:33 +0800461 printk(KERN_EMERG "Please turn on "
462 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800463#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700464 panic("Kernel exception");
Robin Getz226eb1e2007-10-29 17:59:07 +0800465 }
466
467 /* Ensure that bad return addresses don't end up in an infinite
468 * loop, due to speculative loads/reads
469 */
Robin Getz4a589e12007-11-12 22:46:46 +0800470 if (trapnr == VEC_CPLB_I_M)
471 fp->pc = SAFE_USER_INSTRUCTION;
Bryan Wu1394f032007-05-06 14:50:22 -0700472 }
Robin Getzce3afa12007-10-09 17:28:36 +0800473 info.si_signo = sig;
474 info.si_errno = 0;
475 info.si_addr = (void *)fp->pc;
476 force_sig_info(sig, &info, current);
Bryan Wu1394f032007-05-06 14:50:22 -0700477
Bryan Wu1394f032007-05-06 14:50:22 -0700478 trace_buffer_restore(j);
479 return;
480}
481
482/* Typical exception handling routines */
483
Robin Getz518039b2007-07-25 11:03:28 +0800484#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
485
Bryan Wu1394f032007-05-06 14:50:22 -0700486void dump_bfin_trace_buffer(void)
487{
Robin Getz518039b2007-07-25 11:03:28 +0800488#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
489 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800490 char buf[150];
Robin Getz518039b2007-07-25 11:03:28 +0800491#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
492 int j, index;
493#endif
494
Bryan Wu1394f032007-05-06 14:50:22 -0700495 trace_buffer_save(tflags);
496
Robin Getz226eb1e2007-10-29 17:59:07 +0800497 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800498
Bryan Wu1394f032007-05-06 14:50:22 -0700499 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800500 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800501 decode_address(buf, (unsigned long)bfin_read_TBUF());
502 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
503 decode_address(buf, (unsigned long)bfin_read_TBUF());
504 printk(KERN_NOTICE " Source : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700505 }
506 }
507
Robin Getz518039b2007-07-25 11:03:28 +0800508#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
509 if (trace_buff_offset)
510 index = trace_buff_offset/4 - 1;
511 else
512 index = EXPAND_LEN;
513
514 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
515 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800516 decode_address(buf, software_trace_buff[index]);
517 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800518 index -= 1;
519 if (index < 0 )
520 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800521 decode_address(buf, software_trace_buff[index]);
522 printk(KERN_NOTICE " Source : %s\n", buf);
Robin Getz518039b2007-07-25 11:03:28 +0800523 index -= 1;
524 if (index < 0)
525 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800526 j--;
527 i++;
528 }
529#endif
530
Bryan Wu1394f032007-05-06 14:50:22 -0700531 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800532#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700533}
534EXPORT_SYMBOL(dump_bfin_trace_buffer);
535
536static void show_trace(struct task_struct *tsk, unsigned long *sp)
537{
538 unsigned long addr;
539
Robin Getz226eb1e2007-10-29 17:59:07 +0800540 printk(KERN_NOTICE "\n" KERN_NOTICE "Call Trace:\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700541
542 while (!kstack_end(sp)) {
543 addr = *sp++;
544 /*
545 * If the address is either in the text segment of the
546 * kernel, or in the region which contains vmalloc'ed
547 * memory, it *may* be the address of a calling
548 * routine; if so, print it so that someone tracing
549 * down the cause of the crash will be able to figure
550 * out the call path that was taken.
551 */
552 if (kernel_text_address(addr))
553 print_ip_sym(addr);
554 }
555
Robin Getz226eb1e2007-10-29 17:59:07 +0800556 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700557}
558
559void show_stack(struct task_struct *task, unsigned long *stack)
560{
561 unsigned long *endstack, addr;
562 int i;
563
564 /* Cannot call dump_bfin_trace_buffer() here as show_stack() is
565 * called externally in some places in the kernel.
566 */
567
568 if (!stack) {
569 if (task)
570 stack = (unsigned long *)task->thread.ksp;
571 else
572 stack = (unsigned long *)&stack;
573 }
574
575 addr = (unsigned long)stack;
576 endstack = (unsigned long *)PAGE_ALIGN(addr);
577
Robin Getz226eb1e2007-10-29 17:59:07 +0800578 printk(KERN_NOTICE "Stack from %08lx:", (unsigned long)stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700579 for (i = 0; i < kstack_depth_to_print; i++) {
580 if (stack + 1 > endstack)
581 break;
582 if (i % 8 == 0)
Robin Getz226eb1e2007-10-29 17:59:07 +0800583 printk("\n" KERN_NOTICE " ");
Bryan Wu1394f032007-05-06 14:50:22 -0700584 printk(" %08lx", *stack++);
585 }
Robin Getz226eb1e2007-10-29 17:59:07 +0800586 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700587
588 show_trace(task, stack);
589}
590
591void dump_stack(void)
592{
593 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800594#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700595 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800596#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700597 trace_buffer_save(tflags);
598 dump_bfin_trace_buffer();
599 show_stack(current, &stack);
600 trace_buffer_restore(tflags);
601}
602
603EXPORT_SYMBOL(dump_stack);
604
605void dump_bfin_regs(struct pt_regs *fp, void *retaddr)
606{
Robin Getz226eb1e2007-10-29 17:59:07 +0800607 char buf [150];
608
609 if (!oops_in_progress) {
610 if (current->pid && current->mm) {
611 printk(KERN_NOTICE "\n" KERN_NOTICE "CURRENT PROCESS:\n");
612 printk(KERN_NOTICE "COMM=%s PID=%d\n",
613 current->comm, current->pid);
614
615 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
616 KERN_NOTICE "BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
617 KERN_NOTICE "\n",
618 (void *)current->mm->start_code,
619 (void *)current->mm->end_code,
620 (void *)current->mm->start_data,
621 (void *)current->mm->end_data,
622 (void *)current->mm->end_data,
623 (void *)current->mm->brk,
624 (void *)current->mm->start_stack);
625 } else {
626 printk (KERN_NOTICE "\n" KERN_NOTICE
627 "No Valid pid - Either things are really messed up,"
628 " or you are in the kernel\n");
629 }
Bryan Wu1394f032007-05-06 14:50:22 -0700630 } else {
Robin Getz226eb1e2007-10-29 17:59:07 +0800631 printk(KERN_NOTICE "Kernel or interrupt exception\n");
Robin Getz4c26c6c2007-11-18 00:20:49 +0800632 print_modules();
Bryan Wu1394f032007-05-06 14:50:22 -0700633 }
634
Robin Getz226eb1e2007-10-29 17:59:07 +0800635 if (retaddr >= (void *)FIXED_CODE_START && retaddr < (void *)physical_mem_end
Bryan Wu1394f032007-05-06 14:50:22 -0700636#if L1_CODE_LENGTH != 0
637 /* FIXME: Copy the code out of L1 Instruction SRAM through dma
638 memcpy. */
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800639 && !(retaddr >= (void *)L1_CODE_START
640 && retaddr < (void *)(L1_CODE_START + L1_CODE_LENGTH))
Bryan Wu1394f032007-05-06 14:50:22 -0700641#endif
642 ) {
Robin Getzc5d88d92007-06-21 11:34:16 +0800643 int i = ((unsigned int)retaddr & 0xFFFFFFF0) - 32;
Bryan Wu1394f032007-05-06 14:50:22 -0700644 unsigned short x = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800645 printk(KERN_NOTICE "return address: [0x%p]; contents of:", retaddr);
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800646 for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
647 if (!(i & 0xF))
Robin Getz226eb1e2007-10-29 17:59:07 +0800648 printk("\n" KERN_NOTICE "0x%08x: ", i);
Robin Getzc5d88d92007-06-21 11:34:16 +0800649
650 if (get_user(x, (unsigned short *)i))
Bryan Wu1394f032007-05-06 14:50:22 -0700651 break;
652#ifndef CONFIG_DEBUG_HWERR
653 /* If one of the last few instructions was a STI
Simon Arlottd2d50aa2007-06-11 15:31:30 +0800654 * it is likely that the error occured awhile ago
Robin Getz226eb1e2007-10-29 17:59:07 +0800655 * and we just noticed. This only happens in kernel
656 * context, which should mean an oops is happening
Bryan Wu1394f032007-05-06 14:50:22 -0700657 */
Robin Getz226eb1e2007-10-29 17:59:07 +0800658 if (oops_in_progress && x >= 0x0040 && x <= 0x0047 && i <= 0)
Robin Getzc5d88d92007-06-21 11:34:16 +0800659 panic("\n\nWARNING : You should reconfigure"
660 " the kernel to turn on\n"
661 " 'Hardware error interrupt"
662 " debugging'\n"
663 " The rest of this error"
664 " is meanless\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700665#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800666 if (i == (unsigned int)retaddr)
Robin Getzc5d88d92007-06-21 11:34:16 +0800667 printk("[%04x]", x);
668 else
669 printk(" %04x ", x);
Bryan Wu1394f032007-05-06 14:50:22 -0700670 }
Robin Getz226eb1e2007-10-29 17:59:07 +0800671 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700672 } else
Robin Getz226eb1e2007-10-29 17:59:07 +0800673 printk("\n" KERN_NOTICE
Robin Getz6a3f0b42007-11-15 15:10:48 +0800674 "Cannot look at the [PC] <%p> for it is"
675 " in unreadable memory - sorry\n", retaddr);
Bryan Wu1394f032007-05-06 14:50:22 -0700676
Robin Getz226eb1e2007-10-29 17:59:07 +0800677 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\n");
678 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
679 (long)fp->seqstat, fp->ipend, fp->syscfg);
Bryan Wu1394f032007-05-06 14:50:22 -0700680
Robin Getz226eb1e2007-10-29 17:59:07 +0800681 decode_address(buf, fp->rete);
682 printk(KERN_NOTICE " RETE: %s\n", buf);
683 decode_address(buf, fp->retn);
684 printk(KERN_NOTICE " RETN: %s\n", buf);
685 decode_address(buf, fp->retx);
686 printk(KERN_NOTICE " RETX: %s\n", buf);
687 decode_address(buf, fp->rets);
688 printk(KERN_NOTICE " RETS: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700689
Bryan Wu1394f032007-05-06 14:50:22 -0700690 if ((long)fp->seqstat & SEQSTAT_EXCAUSE) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800691 decode_address(buf, bfin_read_DCPLB_FAULT_ADDR());
692 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
693 decode_address(buf, bfin_read_ICPLB_FAULT_ADDR());
694 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700695 }
696
Robin Getz226eb1e2007-10-29 17:59:07 +0800697 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
698 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
699 fp->r0, fp->r1, fp->r2, fp->r3);
700 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
701 fp->r4, fp->r5, fp->r6, fp->r7);
702 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
703 fp->p0, fp->p1, fp->p2, fp->p3);
704 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
705 fp->p4, fp->p5, fp->fp, (long)fp);
706 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
707 fp->lb0, fp->lt0, fp->lc0);
708 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
709 fp->lb1, fp->lt1, fp->lc1);
710 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
711 fp->b0, fp->l0, fp->m0, fp->i0);
712 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
713 fp->b1, fp->l1, fp->m1, fp->i1);
714 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
715 fp->b2, fp->l2, fp->m2, fp->i2);
716 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
717 fp->b3, fp->l3, fp->m3, fp->i3);
718 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
719 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
720
721 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
722 rdusp(), fp->astat);
723
724 printk(KERN_NOTICE "\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700725}
726
727#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
728asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
729#endif
730
731asmlinkage int sys_bfin_spinlock(int *spinlock)
732{
733 int ret = 0;
734 int tmp = 0;
735
736 local_irq_disable();
737 ret = get_user(tmp, spinlock);
738 if (ret == 0) {
739 if (tmp)
740 ret = 1;
741 tmp = 1;
742 put_user(tmp, spinlock);
743 }
744 local_irq_enable();
745 return ret;
746}
747
Mike Frysinger1ffe6642007-08-05 17:14:04 +0800748int bfin_request_exception(unsigned int exception, void (*handler)(void))
749{
750 void (*curr_handler)(void);
751
752 if (exception > 0x3F)
753 return -EINVAL;
754
755 curr_handler = ex_table[exception];
756
757 if (curr_handler != ex_replaceable)
758 return -EBUSY;
759
760 ex_table[exception] = handler;
761
762 return 0;
763}
764EXPORT_SYMBOL(bfin_request_exception);
765
766int bfin_free_exception(unsigned int exception, void (*handler)(void))
767{
768 void (*curr_handler)(void);
769
770 if (exception > 0x3F)
771 return -EINVAL;
772
773 curr_handler = ex_table[exception];
774
775 if (curr_handler != handler)
776 return -EBUSY;
777
778 ex_table[exception] = ex_replaceable;
779
780 return 0;
781}
782EXPORT_SYMBOL(bfin_free_exception);
783
Bryan Wu1394f032007-05-06 14:50:22 -0700784void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
785{
786 switch (cplb_panic) {
787 case CPLB_NO_UNLOCKED:
788 printk(KERN_EMERG "All CPLBs are locked\n");
789 break;
790 case CPLB_PROT_VIOL:
791 return;
792 case CPLB_NO_ADDR_MATCH:
793 return;
794 case CPLB_UNKNOWN_ERR:
795 printk(KERN_EMERG "Unknown CPLB Exception\n");
796 break;
797 }
798
Robin Getz226eb1e2007-10-29 17:59:07 +0800799 oops_in_progress = 1;
800
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800801 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR());
802 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR());
Bryan Wu1394f032007-05-06 14:50:22 -0700803 dump_bfin_regs(fp, (void *)fp->retx);
804 dump_stack();
805 panic("Unrecoverable event\n");
806}