blob: 8eeb457ce5d5fc6cc6541a174be1c6989113328a [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 Frysinger70f12562009-06-07 17:18:25 -040030#include <linux/bug.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080031#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -070032#include <linux/interrupt.h>
33#include <linux/module.h>
34#include <linux/kallsyms.h>
Bryan Wud31c5ab2007-08-10 13:00:42 -070035#include <linux/fs.h>
David Howells8feae132009-01-08 12:04:47 +000036#include <linux/rbtree.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080037#include <asm/traps.h>
38#include <asm/cacheflush.h>
Mike Frysingerf4585a02008-10-13 14:45:21 +080039#include <asm/cplb.h>
Mike Frysingere56e03b2009-06-07 16:31:52 -040040#include <asm/dma.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080041#include <asm/blackfin.h>
42#include <asm/irq_handler.h>
Robin Getzd8f66c82007-12-24 15:27:56 +080043#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080044#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080045#include <asm/fixed_code.h>
Bryan Wu1394f032007-05-06 14:50:22 -070046
47#ifdef CONFIG_KGDB
Bryan Wu1394f032007-05-06 14:50:22 -070048# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080049
50# define CHK_DEBUGGER_TRAP() \
51 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080052 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080053 } while (0)
54# define CHK_DEBUGGER_TRAP_MAYBE() \
55 do { \
56 if (kgdb_connected) \
57 CHK_DEBUGGER_TRAP(); \
58 } while (0)
59#else
60# define CHK_DEBUGGER_TRAP() do { } while (0)
61# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070062#endif
63
Robin Getz9f06c382008-10-10 18:13:21 +080064
Robin Getz4ee1c452008-10-28 11:36:11 +080065#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +080066#define verbose_printk(fmt, arg...) \
67 printk(fmt, ##arg)
68#else
69#define verbose_printk(fmt, arg...) \
70 ({ if (0) printk(fmt, ##arg); 0; })
71#endif
72
Robin Getz81f7f452009-06-03 18:58:26 +000073#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
74u32 last_seqstat;
75#ifdef CONFIG_DEBUG_MMRS_MODULE
76EXPORT_SYMBOL(last_seqstat);
77#endif
78#endif
79
Bryan Wu1394f032007-05-06 14:50:22 -070080/* Initiate the event table handler */
81void __init trap_init(void)
82{
83 CSYNC();
84 bfin_write_EVT3(trap);
85 CSYNC();
86}
87
Robin Getz226eb1e2007-10-29 17:59:07 +080088static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070089{
Robin Getz9f06c382008-10-10 18:13:21 +080090#ifdef CONFIG_DEBUG_VERBOSE
Bryan Wu1394f032007-05-06 14:50:22 -070091 struct task_struct *p;
92 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080093 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080094 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
David Howells8feae132009-01-08 12:04:47 +000095 struct rb_node *n;
Bryan Wu1394f032007-05-06 14:50:22 -070096
97#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080098 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070099 const char *symname;
100 char *modname;
101 char *delim = ":";
102 char namebuf[128];
103
104 /* look up the address and see if we are in kernel space */
105 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
106
107 if (symname) {
108 /* yeah! kernel space! */
109 if (!modname)
110 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +0800111 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800112 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -0700113 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +0800114 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700115
116 }
117#endif
118
Robin Getz226eb1e2007-10-29 17:59:07 +0800119 /* Problem in fixed code section? */
120 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
121 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
122 return;
123 }
124
125 /* Problem somewhere before the kernel start address */
126 if (address < CONFIG_BOOT_LOAD) {
127 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
128 return;
129 }
130
Bryan Wu1394f032007-05-06 14:50:22 -0700131 /* looks like we're off in user-land, so let's walk all the
132 * mappings of all our processes and see if we can't be a whee
133 * bit more specific
134 */
Robin Getz885be032007-10-29 17:20:41 +0800135 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700136 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800137 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700138 if (!mm)
139 continue;
140
David Howells8feae132009-01-08 12:04:47 +0000141 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
142 struct vm_area_struct *vma;
143
144 vma = rb_entry(n, struct vm_area_struct, vm_rb);
Bryan Wu1394f032007-05-06 14:50:22 -0700145
146 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800147 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700148 char *name = p->comm;
149 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800150
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800151 if (file) {
152 char *d_name = d_path(&file->f_path, _tmpbuf,
Jan Blunckcf28b482008-02-14 19:38:44 -0800153 sizeof(_tmpbuf));
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800154 if (!IS_ERR(d_name))
155 name = d_name;
156 }
Bryan Wu1394f032007-05-06 14:50:22 -0700157
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800158 /* FLAT does not have its text aligned to the start of
159 * the map while FDPIC ELF does ...
160 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800161
Robin Getz7f1c9062008-04-25 03:36:31 +0800162 /* before we can check flat/fdpic, we need to
163 * make sure current is valid
164 */
165 if ((unsigned long)current >= FIXED_CODE_START &&
166 !((unsigned long)current & 0x3)) {
167 if (current->mm &&
168 (address > current->mm->start_code) &&
169 (address < current->mm->end_code))
170 offset = address - current->mm->start_code;
171 else
172 offset = (address - vma->vm_start) +
173 (vma->vm_pgoff << PAGE_SHIFT);
174
175 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
176 (void *)address, name, offset);
177 } else
178 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
179 (void *)address, name,
180 vma->vm_start, vma->vm_end);
181
Robin Getz904656c2008-03-26 09:17:43 +0800182 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800183 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800184
Robin Getzf09630b2008-07-26 19:45:46 +0800185 if (!strlen(buf))
186 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
187
Robin Getz885be032007-10-29 17:20:41 +0800188 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700189 }
Bryan Wu1394f032007-05-06 14:50:22 -0700190 }
Robin Getz904656c2008-03-26 09:17:43 +0800191 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800192 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700193 }
Bryan Wu1394f032007-05-06 14:50:22 -0700194
195 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800196 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800197
198done:
199 write_unlock_irqrestore(&tasklist_lock, flags);
Robin Getz9f06c382008-10-10 18:13:21 +0800200#else
201 sprintf(buf, " ");
202#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700203}
204
Robin Getz2ebcade2007-10-09 17:24:30 +0800205asmlinkage void double_fault_c(struct pt_regs *fp)
206{
Robin Getza0cab652009-05-11 18:34:41 +0000207#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
208 int j;
209 trace_buffer_save(j);
210#endif
211
Robin Getz226eb1e2007-10-29 17:59:07 +0800212 console_verbose();
213 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800214#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz2ebcade2007-10-09 17:24:30 +0800215 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800216#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
217 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
Graf Yang8f658732008-11-18 17:48:22 +0800218 unsigned int cpu = smp_processor_id();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800219 char buf[150];
Graf Yang8f658732008-11-18 17:48:22 +0800220 decode_address(buf, cpu_pda[cpu].retx);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800221 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
Graf Yang8f658732008-11-18 17:48:22 +0800222 (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
223 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800224 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +0800225 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800226 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
227
228 decode_address(buf, fp->retx);
Graf Yang8f658732008-11-18 17:48:22 +0800229 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800230 } else
231#endif
232 {
233 dump_bfin_process(fp);
234 dump_bfin_mem(fp);
235 show_regs(fp);
Robin Getza0cab652009-05-11 18:34:41 +0000236 dump_bfin_trace_buffer();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800237 }
Robin Getz9f06c382008-10-10 18:13:21 +0800238#endif
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000239 panic("Double Fault - unrecoverable event");
Robin Getz2ebcade2007-10-09 17:24:30 +0800240
241}
242
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400243static int kernel_mode_regs(struct pt_regs *regs)
244{
245 return regs->ipend & 0xffc0;
246}
247
Bryan Wu1394f032007-05-06 14:50:22 -0700248asmlinkage void trap_c(struct pt_regs *fp)
249{
Robin Getz518039b2007-07-25 11:03:28 +0800250#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
251 int j;
252#endif
Graf Yang8f658732008-11-18 17:48:22 +0800253#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
254 unsigned int cpu = smp_processor_id();
255#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400256 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +0800257 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700258 siginfo_t info;
259 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
260
Bryan Wu1394f032007-05-06 14:50:22 -0700261 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +0000262#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
263 last_seqstat = (u32)fp->seqstat;
264#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700265
Robin Getz226eb1e2007-10-29 17:59:07 +0800266 /* Important - be very careful dereferncing pointers - will lead to
267 * double faults if the stack has become corrupt
268 */
269
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400270#ifndef CONFIG_KGDB
271 /* IPEND is skipped if KGDB isn't enabled (see entry code) */
272 fp->ipend = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800273#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800274
Bryan Wu1394f032007-05-06 14:50:22 -0700275 /* trap_c() will be called for exceptions. During exceptions
276 * processing, the pc value should be set with retx value.
277 * With this change we can cleanup some code in signal.c- TODO
278 */
279 fp->orig_pc = fp->retx;
280 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
281 trapnr, fp->ipend, fp->pc, fp->retx); */
282
283 /* send the appropriate signal to the user program */
284 switch (trapnr) {
285
286 /* This table works in conjuction with the one in ./mach-common/entry.S
287 * Some exceptions are handled there (in assembly, in exception space)
288 * Some are handled here, (in C, in interrupt space)
289 * Some, like CPLB, are handled in both, where the normal path is
290 * handled in assembly/exception space, and the error path is handled
291 * here
292 */
293
294 /* 0x00 - Linux Syscall, getting here is an error */
295 /* 0x01 - userspace gdb breakpoint, handled here */
296 case VEC_EXCPT01:
297 info.si_code = TRAP_ILLTRAP;
298 sig = SIGTRAP;
299 CHK_DEBUGGER_TRAP_MAYBE();
300 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400301 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400302 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700303 else
304 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800305 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700306 case VEC_EXCPT03:
307 info.si_code = SEGV_STACKFLOW;
308 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400309 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800310 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700311 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800312 /* 0x02 - KGDB initial connection and break signal trap */
313 case VEC_EXCPT02:
314#ifdef CONFIG_KGDB
315 info.si_code = TRAP_ILLTRAP;
316 sig = SIGTRAP;
317 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400318 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800319#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800320 /* 0x04 - User Defined */
321 /* 0x05 - User Defined */
322 /* 0x06 - User Defined */
323 /* 0x07 - User Defined */
324 /* 0x08 - User Defined */
325 /* 0x09 - User Defined */
326 /* 0x0A - User Defined */
327 /* 0x0B - User Defined */
328 /* 0x0C - User Defined */
329 /* 0x0D - User Defined */
330 /* 0x0E - User Defined */
331 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800332 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800333 * custom exception handler, and it is not actually installed properly
334 */
335 case VEC_EXCPT04 ... VEC_EXCPT15:
336 info.si_code = ILL_ILLPARAOP;
337 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400338 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800339 CHK_DEBUGGER_TRAP_MAYBE();
340 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700341 /* 0x10 HW Single step, handled here */
342 case VEC_STEP:
343 info.si_code = TRAP_STEP;
344 sig = SIGTRAP;
345 CHK_DEBUGGER_TRAP_MAYBE();
346 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400347 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400348 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700349 else
350 break;
351 /* 0x11 - Trace Buffer Full, handled here */
352 case VEC_OVFLOW:
353 info.si_code = TRAP_TRACEFLOW;
354 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400355 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800356 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700357 break;
358 /* 0x12 - Reserved, Caught by default */
359 /* 0x13 - Reserved, Caught by default */
360 /* 0x14 - Reserved, Caught by default */
361 /* 0x15 - Reserved, Caught by default */
362 /* 0x16 - Reserved, Caught by default */
363 /* 0x17 - Reserved, Caught by default */
364 /* 0x18 - Reserved, Caught by default */
365 /* 0x19 - Reserved, Caught by default */
366 /* 0x1A - Reserved, Caught by default */
367 /* 0x1B - Reserved, Caught by default */
368 /* 0x1C - Reserved, Caught by default */
369 /* 0x1D - Reserved, Caught by default */
370 /* 0x1E - Reserved, Caught by default */
371 /* 0x1F - Reserved, Caught by default */
372 /* 0x20 - Reserved, Caught by default */
373 /* 0x21 - Undefined Instruction, handled here */
374 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400375#ifdef CONFIG_BUG
376 if (kernel_mode_regs(fp)) {
377 switch (report_bug(fp->pc, fp)) {
378 case BUG_TRAP_TYPE_NONE:
379 break;
380 case BUG_TRAP_TYPE_WARN:
381 dump_bfin_trace_buffer();
382 fp->pc += 2;
383 goto traps_done;
384 case BUG_TRAP_TYPE_BUG:
385 /* call to panic() will dump trace, and it is
386 * off at this point, so it won't be clobbered
387 */
388 panic("BUG()");
389 }
390 }
391#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700392 info.si_code = ILL_ILLOPC;
393 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400394 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800395 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700396 break;
397 /* 0x22 - Illegal Instruction Combination, handled here */
398 case VEC_ILGAL_I:
399 info.si_code = ILL_ILLPARAOP;
400 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400401 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800402 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700403 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800404 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700405 case VEC_CPLB_VL:
406 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800407 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400408 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800409 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700410 break;
411 /* 0x24 - Data access misaligned, handled here */
412 case VEC_MISALI_D:
413 info.si_code = BUS_ADRALN;
414 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400415 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800416 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700417 break;
418 /* 0x25 - Unrecoverable Event, handled here */
419 case VEC_UNCOV:
420 info.si_code = ILL_ILLEXCPT;
421 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400422 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800423 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700424 break;
425 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
426 error case is handled here */
427 case VEC_CPLB_M:
428 info.si_code = BUS_ADRALN;
429 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400430 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700431 break;
432 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
433 case VEC_CPLB_MHIT:
434 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700435 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800436#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800437 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400438 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800439 else
Bryan Wu1394f032007-05-06 14:50:22 -0700440#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400441 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800442 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700443 break;
444 /* 0x28 - Emulation Watchpoint, handled here */
445 case VEC_WATCH:
446 info.si_code = TRAP_WATCHPT;
447 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800448 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700449 CHK_DEBUGGER_TRAP_MAYBE();
450 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400451 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400452 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700453 else
454 break;
455#ifdef CONFIG_BF535
456 /* 0x29 - Instruction fetch access error (535 only) */
457 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
458 info.si_code = BUS_OPFETCH;
459 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400460 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800461 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700462 break;
463#else
464 /* 0x29 - Reserved, Caught by default */
465#endif
466 /* 0x2A - Instruction fetch misaligned, handled here */
467 case VEC_MISALI_I:
468 info.si_code = BUS_ADRALN;
469 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400470 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800471 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700472 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800473 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700474 case VEC_CPLB_I_VL:
475 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800476 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400477 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800478 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700479 break;
480 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
481 case VEC_CPLB_I_M:
482 info.si_code = ILL_CPLB_MISS;
483 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400484 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700485 break;
486 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
487 case VEC_CPLB_I_MHIT:
488 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700489 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800490#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800491 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400492 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800493 else
Bryan Wu1394f032007-05-06 14:50:22 -0700494#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400495 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800496 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700497 break;
498 /* 0x2E - Illegal use of Supervisor Resource, handled here */
499 case VEC_ILL_RES:
500 info.si_code = ILL_PRVOPC;
501 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400502 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800503 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700504 break;
505 /* 0x2F - Reserved, Caught by default */
506 /* 0x30 - Reserved, Caught by default */
507 /* 0x31 - Reserved, Caught by default */
508 /* 0x32 - Reserved, Caught by default */
509 /* 0x33 - Reserved, Caught by default */
510 /* 0x34 - Reserved, Caught by default */
511 /* 0x35 - Reserved, Caught by default */
512 /* 0x36 - Reserved, Caught by default */
513 /* 0x37 - Reserved, Caught by default */
514 /* 0x38 - Reserved, Caught by default */
515 /* 0x39 - Reserved, Caught by default */
516 /* 0x3A - Reserved, Caught by default */
517 /* 0x3B - Reserved, Caught by default */
518 /* 0x3C - Reserved, Caught by default */
519 /* 0x3D - Reserved, Caught by default */
520 /* 0x3E - Reserved, Caught by default */
521 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800522 case VEC_HWERR:
523 info.si_code = BUS_ADRALN;
524 sig = SIGBUS;
525 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
526 /* System MMR Error */
527 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
528 info.si_code = BUS_ADRALN;
529 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400530 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800531 break;
532 /* External Memory Addressing Error */
533 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
534 info.si_code = BUS_ADRERR;
535 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400536 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800537 break;
538 /* Performance Monitor Overflow */
539 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400540 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800541 break;
542 /* RAISE 5 instruction */
543 case (SEQSTAT_HWERRCAUSE_RAISE_5):
544 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
545 break;
546 default: /* Reserved */
547 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
548 break;
549 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800550 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800551 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800552 /*
553 * We should be handling all known exception types above,
554 * if we get here we hit a reserved one, so panic
555 */
Bryan Wu1394f032007-05-06 14:50:22 -0700556 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800557 info.si_code = ILL_ILLPARAOP;
558 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800559 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700560 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800561 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700562 break;
563 }
564
Robin Getz226eb1e2007-10-29 17:59:07 +0800565 BUG_ON(sig == 0);
566
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400567 /* If the fault was caused by a kernel thread, or interrupt handler
568 * we will kernel panic, so the system reboots.
569 */
570 if (kernel_mode_regs(fp) || (current && !current->mm)) {
571 console_verbose();
572 oops_in_progress = 1;
573 if (strerror)
574 verbose_printk(strerror);
575 }
576
Robin Getz226eb1e2007-10-29 17:59:07 +0800577 if (sig != SIGTRAP) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800578 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800579 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800580 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800581
582 /* Print out the trace buffer if it makes sense */
583#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
584 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800585 verbose_printk(KERN_NOTICE "No trace since you do not have "
Robin Getz226eb1e2007-10-29 17:59:07 +0800586 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
587 KERN_NOTICE "\n");
588 else
589#endif
590 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800591
Robin Getz226eb1e2007-10-29 17:59:07 +0800592 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800593 /* Dump the current kernel stack */
Robin Getz9f06c382008-10-10 18:13:21 +0800594 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800595 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800596 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800597#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800598 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800599 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800600#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700601 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800602 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800603#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800604 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800605 /* Dump the user space stack */
606 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800607 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800608 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800609#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800610 }
Bryan Wu1394f032007-05-06 14:50:22 -0700611 }
Robin Getzfb322912007-11-21 16:38:05 +0800612
Yi Li6a01f232009-01-07 23:14:39 +0800613#ifdef CONFIG_IPIPE
614 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
615#endif
616 {
617 info.si_signo = sig;
618 info.si_errno = 0;
619 info.si_addr = (void __user *)fp->pc;
620 force_sig_info(sig, &info, current);
621 }
Bryan Wu1394f032007-05-06 14:50:22 -0700622
Robin Getz0acad8d2009-05-11 18:55:16 +0000623 if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
624 fp->pc = SAFE_USER_INSTRUCTION;
625
Mike Frysinger6510a202009-06-07 15:07:25 -0400626 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700627 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700628}
629
630/* Typical exception handling routines */
631
Robin Getz518039b2007-07-25 11:03:28 +0800632#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
633
Robin Getzf09630b2008-07-26 19:45:46 +0800634/*
635 * Similar to get_user, do some address checking, then dereference
636 * Return true on sucess, false on bad address
637 */
Robin Getz9f06c382008-10-10 18:13:21 +0800638static bool get_instruction(unsigned short *val, unsigned short *address)
Robin Getzf09630b2008-07-26 19:45:46 +0800639{
Mike Frysingere56e03b2009-06-07 16:31:52 -0400640 unsigned long addr = (unsigned long)address;
Robin Getzf09630b2008-07-26 19:45:46 +0800641
642 /* Check for odd addresses */
643 if (addr & 0x1)
644 return false;
645
Mike Frysingere56e03b2009-06-07 16:31:52 -0400646 /* MMR region will never have instructions */
647 if (addr >= SYSMMR_BASE)
Robin Getzf09630b2008-07-26 19:45:46 +0800648 return false;
649
Mike Frysingere56e03b2009-06-07 16:31:52 -0400650 switch (bfin_mem_access_type(addr, 2)) {
651 case BFIN_MEM_ACCESS_CORE:
652 case BFIN_MEM_ACCESS_CORE_ONLY:
653 *val = *address;
654 return true;
655 case BFIN_MEM_ACCESS_DMA:
656 dma_memcpy(val, address, 2);
657 return true;
658 case BFIN_MEM_ACCESS_ITEST:
659 isram_memcpy(val, address, 2);
660 return true;
661 default: /* invalid access */
662 return false;
Robin Getzf09630b2008-07-26 19:45:46 +0800663 }
Robin Getzf09630b2008-07-26 19:45:46 +0800664}
665
Mike Frysinger36f649a2008-11-18 17:48:22 +0800666/*
Robin Getzd3d0ac22008-08-06 17:49:27 +0800667 * decode the instruction if we are printing out the trace, as it
668 * makes things easier to follow, without running it through objdump
669 * These are the normal instructions which cause change of flow, which
670 * would be at the source of the trace buffer
671 */
Mike Frysinger36f649a2008-11-18 17:48:22 +0800672#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
Robin Getz9f06c382008-10-10 18:13:21 +0800673static void decode_instruction(unsigned short *address)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800674{
675 unsigned short opcode;
676
677 if (get_instruction(&opcode, address)) {
678 if (opcode == 0x0010)
Robin Getz9f06c382008-10-10 18:13:21 +0800679 verbose_printk("RTS");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800680 else if (opcode == 0x0011)
Robin Getz9f06c382008-10-10 18:13:21 +0800681 verbose_printk("RTI");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800682 else if (opcode == 0x0012)
Robin Getz9f06c382008-10-10 18:13:21 +0800683 verbose_printk("RTX");
Robin Getz0be58932009-02-04 16:49:45 +0800684 else if (opcode == 0x0013)
685 verbose_printk("RTN");
686 else if (opcode == 0x0014)
687 verbose_printk("RTE");
688 else if (opcode == 0x0025)
689 verbose_printk("EMUEXCPT");
690 else if (opcode == 0x0040 && opcode <= 0x0047)
691 verbose_printk("STI R%i", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800692 else if (opcode >= 0x0050 && opcode <= 0x0057)
Robin Getz9f06c382008-10-10 18:13:21 +0800693 verbose_printk("JUMP (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800694 else if (opcode >= 0x0060 && opcode <= 0x0067)
Robin Getz9f06c382008-10-10 18:13:21 +0800695 verbose_printk("CALL (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800696 else if (opcode >= 0x0070 && opcode <= 0x0077)
Robin Getz9f06c382008-10-10 18:13:21 +0800697 verbose_printk("CALL (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800698 else if (opcode >= 0x0080 && opcode <= 0x0087)
Robin Getz9f06c382008-10-10 18:13:21 +0800699 verbose_printk("JUMP (PC+P%i)", opcode & 7);
Robin Getz0be58932009-02-04 16:49:45 +0800700 else if (opcode >= 0x0090 && opcode <= 0x009F)
701 verbose_printk("RAISE 0x%x", opcode & 0xF);
702 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
703 verbose_printk("EXCPT 0x%x", opcode & 0xF);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800704 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
Robin Getz9f06c382008-10-10 18:13:21 +0800705 verbose_printk("IF !CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800706 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
Robin Getz9f06c382008-10-10 18:13:21 +0800707 verbose_printk("IF CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800708 else if (opcode >= 0x2000 && opcode <= 0x2fff)
Robin Getz9f06c382008-10-10 18:13:21 +0800709 verbose_printk("JUMP.S");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800710 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800711 verbose_printk("LSETUP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800712 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800713 verbose_printk("JUMP.L");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800714 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800715 verbose_printk("CALL pcrel");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800716 else
Robin Getz9f06c382008-10-10 18:13:21 +0800717 verbose_printk("0x%04x", opcode);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800718 }
719
720}
Robin Getz9f06c382008-10-10 18:13:21 +0800721#endif
Robin Getzd3d0ac22008-08-06 17:49:27 +0800722
Bryan Wu1394f032007-05-06 14:50:22 -0700723void dump_bfin_trace_buffer(void)
724{
Robin Getz9f06c382008-10-10 18:13:21 +0800725#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz518039b2007-07-25 11:03:28 +0800726#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
727 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800728 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800729 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800730#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
731 int j, index;
732#endif
733
Bryan Wu1394f032007-05-06 14:50:22 -0700734 trace_buffer_save(tflags);
735
Robin Getz226eb1e2007-10-29 17:59:07 +0800736 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800737
Robin Getzd3d0ac22008-08-06 17:49:27 +0800738#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
739 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
740#endif
741
Bryan Wu1394f032007-05-06 14:50:22 -0700742 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800743 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800744 decode_address(buf, (unsigned long)bfin_read_TBUF());
745 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800746 addr = (unsigned short *)bfin_read_TBUF();
747 decode_address(buf, (unsigned long)addr);
748 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800749 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800750 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700751 }
752 }
753
Robin Getz518039b2007-07-25 11:03:28 +0800754#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
755 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800756 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800757 else
758 index = EXPAND_LEN;
759
760 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
761 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800762 decode_address(buf, software_trace_buff[index]);
763 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800764 index -= 1;
765 if (index < 0 )
766 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800767 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800768 printk(KERN_NOTICE " Source : %s ", buf);
769 decode_instruction((unsigned short *)software_trace_buff[index]);
770 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800771 index -= 1;
772 if (index < 0)
773 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800774 j--;
775 i++;
776 }
777#endif
778
Bryan Wu1394f032007-05-06 14:50:22 -0700779 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800780#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800781#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700782}
783EXPORT_SYMBOL(dump_bfin_trace_buffer);
784
Mike Frysinger70f12562009-06-07 17:18:25 -0400785#ifdef CONFIG_BUG
786int is_valid_bugaddr(unsigned long addr)
787{
788 unsigned short opcode;
789
790 if (!get_instruction(&opcode, (unsigned short *)addr))
791 return 0;
792
793 return opcode == BFIN_BUG_OPCODE;
794}
795#endif
796
Robin Getzf09630b2008-07-26 19:45:46 +0800797/*
798 * Checks to see if the address pointed to is either a
799 * 16-bit CALL instruction, or a 32-bit CALL instruction
800 */
Robin Getz9f06c382008-10-10 18:13:21 +0800801static bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700802{
Robin Getzf09630b2008-07-26 19:45:46 +0800803 unsigned short opcode = 0, *ins_addr;
804 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700805
Robin Getzf09630b2008-07-26 19:45:46 +0800806 if (!get_instruction(&opcode, ins_addr))
807 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700808
Robin Getzf09630b2008-07-26 19:45:46 +0800809 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
810 (opcode >= 0x0070 && opcode <= 0x0077))
811 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700812
Robin Getzf09630b2008-07-26 19:45:46 +0800813 ins_addr--;
814 if (!get_instruction(&opcode, ins_addr))
815 return false;
816
817 if (opcode >= 0xE300 && opcode <= 0xE3FF)
818 return true;
819
820 return false;
821
Bryan Wu1394f032007-05-06 14:50:22 -0700822}
Robin Getz9f06c382008-10-10 18:13:21 +0800823
Bryan Wu1394f032007-05-06 14:50:22 -0700824void show_stack(struct task_struct *task, unsigned long *stack)
825{
Robin Getz9f06c382008-10-10 18:13:21 +0800826#ifdef CONFIG_PRINTK
Robin Getzf09630b2008-07-26 19:45:46 +0800827 unsigned int *addr, *endstack, *fp = 0, *frame;
828 unsigned short *ins_addr;
829 char buf[150];
830 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700831
Robin Getzf09630b2008-07-26 19:45:46 +0800832 /*
833 * If we have been passed a specific stack, use that one otherwise
834 * if we have been passed a task structure, use that, otherwise
835 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700836 */
837
Robin Getzf09630b2008-07-26 19:45:46 +0800838 if (stack == NULL) {
839 if (task) {
840 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700841 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800842 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
843 } else {
844 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700845 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800846 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
847 }
848 } else
849 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
850
Robin Getz9f06c382008-10-10 18:13:21 +0800851 printk(KERN_NOTICE "Stack info:\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800852 decode_address(buf, (unsigned int)stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800853 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
854
Robin Getza0cab652009-05-11 18:34:41 +0000855 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
856 printk(KERN_NOTICE "Invalid stack pointer\n");
857 return;
858 }
859
Robin Getzf09630b2008-07-26 19:45:46 +0800860 /* First thing is to look for a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800861 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800862 if (*addr & 0x1)
863 continue;
864 ins_addr = (unsigned short *)*addr;
865 ins_addr--;
866 if (is_bfin_call(ins_addr))
867 fp = addr - 1;
868
869 if (fp) {
870 /* Let's check to see if it is a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800871 while (fp >= (addr - 1) && fp < endstack
872 && fp && ((unsigned int) fp & 0x3) == 0)
Robin Getzf09630b2008-07-26 19:45:46 +0800873 fp = (unsigned int *)*fp;
874 if (fp == 0 || fp == endstack) {
875 fp = addr - 1;
876 break;
877 }
878 fp = 0;
879 }
880 }
881 if (fp) {
882 frame = fp;
Jie Zhangb339dc72009-01-07 23:14:39 +0800883 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
Robin Getzf09630b2008-07-26 19:45:46 +0800884 } else
885 frame = 0;
886
887 /*
888 * Now that we think we know where things are, we
889 * walk the stack again, this time printing things out
890 * incase there is no frame pointer, we still look for
891 * valid return addresses
892 */
893
894 /* First time print out data, next time, print out symbols */
895 for (j = 0; j <= 1; j++) {
896 if (j)
897 printk(KERN_NOTICE "Return addresses in stack:\n");
898 else
899 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
900
901 fp = frame;
902 frame_no = 0;
903
904 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
905 addr <= endstack; addr++, i++) {
906
907 ret_addr = 0;
908 if (!j && i % 8 == 0)
909 printk("\n" KERN_NOTICE "%p:",addr);
910
911 /* if it is an odd address, or zero, just skip it */
912 if (*addr & 0x1 || !*addr)
913 goto print;
914
915 ins_addr = (unsigned short *)*addr;
916
917 /* Go back one instruction, and see if it is a CALL */
918 ins_addr--;
919 ret_addr = is_bfin_call(ins_addr);
920 print:
921 if (!j && stack == (unsigned long *)addr)
922 printk("[%08x]", *addr);
923 else if (ret_addr)
924 if (j) {
925 decode_address(buf, (unsigned int)*addr);
926 if (frame == addr) {
927 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
928 continue;
929 }
930 printk(KERN_NOTICE " address : %s\n", buf);
931 } else
932 printk("<%08x>", *addr);
933 else if (fp == addr) {
934 if (j)
935 frame = addr+1;
936 else
937 printk("(%08x)", *addr);
938
939 fp = (unsigned int *)*addr;
940 frame_no++;
941
942 } else if (!j)
943 printk(" %08x ", *addr);
944 }
945 if (!j)
946 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700947 }
Robin Getz9f06c382008-10-10 18:13:21 +0800948#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700949}
950
951void dump_stack(void)
952{
953 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800954#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700955 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800956#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700957 trace_buffer_save(tflags);
958 dump_bfin_trace_buffer();
959 show_stack(current, &stack);
960 trace_buffer_restore(tflags);
961}
Bryan Wu1394f032007-05-06 14:50:22 -0700962EXPORT_SYMBOL(dump_stack);
963
Mike Frysinger49dce912007-11-21 16:46:49 +0800964void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700965{
Robin Getz9f06c382008-10-10 18:13:21 +0800966#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +0800967 /* We should be able to look at fp->ipend, but we don't push it on the
968 * stack all the time, so do this until we fix that */
969 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800970
Mike Frysinger49dce912007-11-21 16:46:49 +0800971 if (oops_in_progress)
Robin Getz9f06c382008-10-10 18:13:21 +0800972 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800973
Robin Getzb03b08b2007-12-23 22:57:01 +0800974 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
Robin Getz9f06c382008-10-10 18:13:21 +0800975 verbose_printk(KERN_NOTICE "HW Error context\n");
Robin Getzb03b08b2007-12-23 22:57:01 +0800976 else if (context & 0x0020)
Robin Getz9f06c382008-10-10 18:13:21 +0800977 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800978 else if (context & 0x3FC0)
Robin Getz9f06c382008-10-10 18:13:21 +0800979 verbose_printk(KERN_NOTICE "Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800980 else if (context & 0x4000)
Robin Getz9f06c382008-10-10 18:13:21 +0800981 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800982 else if (context & 0x8000)
Robin Getz9f06c382008-10-10 18:13:21 +0800983 verbose_printk(KERN_NOTICE "Kernel process context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800984
Robin Getz9a62ca42008-03-26 09:15:58 +0800985 /* Because we are crashing, and pointers could be bad, we check things
986 * pretty closely before we use them
987 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800988 if ((unsigned long)current >= FIXED_CODE_START &&
989 !((unsigned long)current & 0x3) && current->pid) {
Robin Getz9f06c382008-10-10 18:13:21 +0800990 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800991 if (current->comm >= (char *)FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +0800992 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
Robin Getz9a62ca42008-03-26 09:15:58 +0800993 current->comm, current->pid);
994 else
Robin Getz9f06c382008-10-10 18:13:21 +0800995 verbose_printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800996
Graf Yang8f658732008-11-18 17:48:22 +0800997 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
Robin Getz9a62ca42008-03-26 09:15:58 +0800998 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +0800999 verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
Robin Getz9a62ca42008-03-26 09:15:58 +08001000 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
1001 KERN_NOTICE "\n",
1002 (void *)current->mm->start_code,
1003 (void *)current->mm->end_code,
1004 (void *)current->mm->start_data,
1005 (void *)current->mm->end_data,
1006 (void *)current->mm->end_data,
1007 (void *)current->mm->brk,
1008 (void *)current->mm->start_stack);
1009 else
Robin Getz9f06c382008-10-10 18:13:21 +08001010 verbose_printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001011 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001012 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
Mike Frysinger49dce912007-11-21 16:46:49 +08001013 "No Valid process in current context\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001014#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001015}
1016
Robin Getzb03b08b2007-12-23 22:57:01 +08001017void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +08001018{
Robin Getz9f06c382008-10-10 18:13:21 +08001019#ifdef CONFIG_DEBUG_VERBOSE
Robin Getzb03b08b2007-12-23 22:57:01 +08001020 unsigned short *addr, *erraddr, val = 0, err = 0;
1021 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -07001022
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001023 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +08001024
Robin Getz9f06c382008-10-10 18:13:21 +08001025 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001026
1027 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1028 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1029 addr++) {
1030 if (!((unsigned long)addr & 0xF))
Robin Getz9f06c382008-10-10 18:13:21 +08001031 verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001032
Robin Getz7d98c882008-10-08 16:29:01 +08001033 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +08001034 val = 0;
1035 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +08001036 } else
1037 sprintf(buf, "%04x", val);
1038
1039 if (addr == erraddr) {
Robin Getz9f06c382008-10-10 18:13:21 +08001040 verbose_printk("[%s]", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001041 err = val;
1042 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001043 verbose_printk(" %s ", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001044
1045 /* Do any previous instructions turn on interrupts? */
1046 if (addr <= erraddr && /* in the past */
1047 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1048 val == 0x017b)) /* [SP++] = RETI */
1049 sti = 1;
1050 }
1051
Robin Getz9f06c382008-10-10 18:13:21 +08001052 verbose_printk("\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001053
1054 /* Hardware error interrupts can be deferred */
1055 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1056 oops_in_progress)){
Robin Getz9f06c382008-10-10 18:13:21 +08001057 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001058#ifndef CONFIG_DEBUG_HWERR
Robin Getz9f06c382008-10-10 18:13:21 +08001059 verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
Robin Getzb03b08b2007-12-23 22:57:01 +08001060 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
1061 " better idea where it came from\n");
1062#else
1063 /* If we are handling only one peripheral interrupt
1064 * and current mm and pid are valid, and the last error
1065 * was in that user space process's text area
1066 * print it out - because that is where the problem exists
1067 */
1068 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1069 (current->pid && current->mm)) {
1070 /* And the last RETI points to the current userspace context */
1071 if ((fp + 1)->pc >= current->mm->start_code &&
1072 (fp + 1)->pc <= current->mm->end_code) {
Robin Getz9f06c382008-10-10 18:13:21 +08001073 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1074 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001075 show_regs(fp + 1);
Robin Getz9f06c382008-10-10 18:13:21 +08001076 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001077 }
Bryan Wu1394f032007-05-06 14:50:22 -07001078 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001079#endif
1080 }
Robin Getz9f06c382008-10-10 18:13:21 +08001081#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001082}
1083
1084void show_regs(struct pt_regs *fp)
1085{
Robin Getz9f06c382008-10-10 18:13:21 +08001086#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001087 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001088 struct irqaction *action;
1089 unsigned int i;
Robin Getz2f95d5b2009-02-04 16:49:45 +08001090 unsigned long flags = 0;
Graf Yang8f658732008-11-18 17:48:22 +08001091 unsigned int cpu = smp_processor_id();
Robin Getz2f95d5b2009-02-04 16:49:45 +08001092 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -07001093
Robin Getz9ba3c242009-05-20 21:19:21 +00001094 verbose_printk(KERN_NOTICE "\n");
1095 if (CPUID != bfin_cpuid())
1096 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1097 "but running on:0x%04x (Rev %d)\n",
1098 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1099
1100 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1101 CPU, bfin_compiled_revid());
1102
1103 if (bfin_compiled_revid() != bfin_revid())
1104 verbose_printk("(Detected 0.%d)", bfin_revid());
1105
1106 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1107 get_cclk()/1000000, get_sclk()/1000000,
1108#ifdef CONFIG_MPU
1109 "mpu on"
1110#else
1111 "mpu off"
1112#endif
1113 );
1114
1115 verbose_printk(KERN_NOTICE "%s", linux_banner);
1116
Robin Getz9f06c382008-10-10 18:13:21 +08001117 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
1118 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001119 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001120 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001121 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001122 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1123#ifdef EBIU_ERRMST
1124 /* If the error was from the EBIU, print it out */
1125 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001126 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001127 bfin_read_EBIU_ERRMST());
Robin Getz9f06c382008-10-10 18:13:21 +08001128 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001129 bfin_read_EBIU_ERRADD());
1130 }
1131#endif
1132 }
Robin Getz9f06c382008-10-10 18:13:21 +08001133 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
Robin Getz13fe24f2008-01-27 15:38:56 +08001134 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getz2f95d5b2009-02-04 16:49:45 +08001135 for (i = 2; i <= 15 ; i++) {
Robin Getzd8f66c82007-12-24 15:27:56 +08001136 if (fp->ipend & (1 << i)) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001137 if (i != 4) {
1138 decode_address(buf, bfin_read32(EVT0 + 4*i));
1139 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1140 } else
1141 verbose_printk(KERN_NOTICE " interrupts disabled\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001142 }
1143 }
1144
1145 /* if no interrupts are going off, don't print this out */
1146 if (fp->ipend & ~0x3F) {
1147 for (i = 0; i < (NR_IRQS - 1); i++) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001148 if (!in_atomic)
1149 spin_lock_irqsave(&irq_desc[i].lock, flags);
1150
Robin Getzd8f66c82007-12-24 15:27:56 +08001151 action = irq_desc[i].action;
1152 if (!action)
1153 goto unlock;
1154
1155 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001156 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001157 for (action = action->next; action; action = action->next) {
1158 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001159 verbose_printk(", %s", buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001160 }
Robin Getz9f06c382008-10-10 18:13:21 +08001161 verbose_printk("\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001162unlock:
Robin Getz2f95d5b2009-02-04 16:49:45 +08001163 if (!in_atomic)
1164 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Robin Getzd8f66c82007-12-24 15:27:56 +08001165 }
1166 }
Bryan Wu1394f032007-05-06 14:50:22 -07001167
Robin Getz226eb1e2007-10-29 17:59:07 +08001168 decode_address(buf, fp->rete);
Robin Getz9f06c382008-10-10 18:13:21 +08001169 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001170 decode_address(buf, fp->retn);
Robin Getz9f06c382008-10-10 18:13:21 +08001171 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001172 decode_address(buf, fp->retx);
Robin Getz9f06c382008-10-10 18:13:21 +08001173 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001174 decode_address(buf, fp->rets);
Robin Getz9f06c382008-10-10 18:13:21 +08001175 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001176 decode_address(buf, fp->pc);
Robin Getz9f06c382008-10-10 18:13:21 +08001177 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001178
Robin Getz13fe24f2008-01-27 15:38:56 +08001179 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1180 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Graf Yang8f658732008-11-18 17:48:22 +08001181 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001182 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +08001183 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001184 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001185 }
1186
Robin Getz9f06c382008-10-10 18:13:21 +08001187 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1188 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001189 fp->r0, fp->r1, fp->r2, fp->r3);
Robin Getz9f06c382008-10-10 18:13:21 +08001190 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001191 fp->r4, fp->r5, fp->r6, fp->r7);
Robin Getz9f06c382008-10-10 18:13:21 +08001192 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001193 fp->p0, fp->p1, fp->p2, fp->p3);
Robin Getz9f06c382008-10-10 18:13:21 +08001194 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001195 fp->p4, fp->p5, fp->fp, (long)fp);
Robin Getz9f06c382008-10-10 18:13:21 +08001196 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001197 fp->lb0, fp->lt0, fp->lc0);
Robin Getz9f06c382008-10-10 18:13:21 +08001198 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001199 fp->lb1, fp->lt1, fp->lc1);
Robin Getz9f06c382008-10-10 18:13:21 +08001200 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001201 fp->b0, fp->l0, fp->m0, fp->i0);
Robin Getz9f06c382008-10-10 18:13:21 +08001202 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001203 fp->b1, fp->l1, fp->m1, fp->i1);
Robin Getz9f06c382008-10-10 18:13:21 +08001204 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001205 fp->b2, fp->l2, fp->m2, fp->i2);
Robin Getz9f06c382008-10-10 18:13:21 +08001206 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001207 fp->b3, fp->l3, fp->m3, fp->i3);
Robin Getz9f06c382008-10-10 18:13:21 +08001208 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001209 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1210
Robin Getz9f06c382008-10-10 18:13:21 +08001211 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001212 rdusp(), fp->astat);
1213
Robin Getz9f06c382008-10-10 18:13:21 +08001214 verbose_printk(KERN_NOTICE "\n");
1215#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001216}
1217
1218#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1219asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1220#endif
1221
Graf Yang8f658732008-11-18 17:48:22 +08001222static DEFINE_SPINLOCK(bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001223
Graf Yang8f658732008-11-18 17:48:22 +08001224asmlinkage int sys_bfin_spinlock(int *p)
1225{
1226 int ret, tmp = 0;
1227
1228 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1229 ret = get_user(tmp, p);
1230 if (likely(ret == 0)) {
1231 if (unlikely(tmp))
Bryan Wu1394f032007-05-06 14:50:22 -07001232 ret = 1;
Graf Yang8f658732008-11-18 17:48:22 +08001233 else
1234 put_user(1, p);
Bryan Wu1394f032007-05-06 14:50:22 -07001235 }
Graf Yang8f658732008-11-18 17:48:22 +08001236 spin_unlock(&bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001237 return ret;
1238}
1239
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001240int bfin_request_exception(unsigned int exception, void (*handler)(void))
1241{
1242 void (*curr_handler)(void);
1243
1244 if (exception > 0x3F)
1245 return -EINVAL;
1246
1247 curr_handler = ex_table[exception];
1248
1249 if (curr_handler != ex_replaceable)
1250 return -EBUSY;
1251
1252 ex_table[exception] = handler;
1253
1254 return 0;
1255}
1256EXPORT_SYMBOL(bfin_request_exception);
1257
1258int bfin_free_exception(unsigned int exception, void (*handler)(void))
1259{
1260 void (*curr_handler)(void);
1261
1262 if (exception > 0x3F)
1263 return -EINVAL;
1264
1265 curr_handler = ex_table[exception];
1266
1267 if (curr_handler != handler)
1268 return -EBUSY;
1269
1270 ex_table[exception] = ex_replaceable;
1271
1272 return 0;
1273}
1274EXPORT_SYMBOL(bfin_free_exception);
1275
Bryan Wu1394f032007-05-06 14:50:22 -07001276void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1277{
1278 switch (cplb_panic) {
1279 case CPLB_NO_UNLOCKED:
1280 printk(KERN_EMERG "All CPLBs are locked\n");
1281 break;
1282 case CPLB_PROT_VIOL:
1283 return;
1284 case CPLB_NO_ADDR_MATCH:
1285 return;
1286 case CPLB_UNKNOWN_ERR:
1287 printk(KERN_EMERG "Unknown CPLB Exception\n");
1288 break;
1289 }
1290
Robin Getz226eb1e2007-10-29 17:59:07 +08001291 oops_in_progress = 1;
1292
Mike Frysinger49dce912007-11-21 16:46:49 +08001293 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001294 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001295 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001296 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +00001297 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -07001298}