blob: 18c6cd4150f82df3636508f10d0f73e23382e597 [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];
Mike Frysinger18070dd2009-06-23 20:17:21 +0000103#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700104
Mike Frysinger18070dd2009-06-23 20:17:21 +0000105 buf += sprintf(buf, "<0x%08lx> ", address);
106
107#ifdef CONFIG_KALLSYMS
Bryan Wu1394f032007-05-06 14:50:22 -0700108 /* look up the address and see if we are in kernel space */
109 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
110
111 if (symname) {
112 /* yeah! kernel space! */
113 if (!modname)
114 modname = delim = "";
Mike Frysinger18070dd2009-06-23 20:17:21 +0000115 sprintf(buf, "{ %s%s%s%s + 0x%lx }",
116 delim, modname, delim, symname,
117 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +0800118 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700119 }
120#endif
121
Robin Getz226eb1e2007-10-29 17:59:07 +0800122 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
Mike Frysinger18070dd2009-06-23 20:17:21 +0000123 /* Problem in fixed code section? */
124 strcat(buf, "/* Maybe fixed code section */");
Robin Getz226eb1e2007-10-29 17:59:07 +0800125 return;
Robin Getz226eb1e2007-10-29 17:59:07 +0800126
Mike Frysinger18070dd2009-06-23 20:17:21 +0000127 } else if (address < CONFIG_BOOT_LOAD) {
128 /* Problem somewhere before the kernel start address */
129 strcat(buf, "/* Maybe null pointer? */");
130 return;
131
132 } else if (address >= COREMMR_BASE) {
133 strcat(buf, "/* core mmrs */");
134 return;
135
136 } else if (address >= SYSMMR_BASE) {
137 strcat(buf, "/* system mmrs */");
138 return;
139
140 } else if (address >= L1_ROM_START && address < L1_ROM_START + L1_ROM_LENGTH) {
141 strcat(buf, "/* on-chip L1 ROM */");
Robin Getz226eb1e2007-10-29 17:59:07 +0800142 return;
143 }
144
Bryan Wu1394f032007-05-06 14:50:22 -0700145 /* looks like we're off in user-land, so let's walk all the
146 * mappings of all our processes and see if we can't be a whee
147 * bit more specific
148 */
Robin Getz885be032007-10-29 17:20:41 +0800149 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700150 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800151 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700152 if (!mm)
153 continue;
154
David Howells8feae132009-01-08 12:04:47 +0000155 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
156 struct vm_area_struct *vma;
157
158 vma = rb_entry(n, struct vm_area_struct, vm_rb);
Bryan Wu1394f032007-05-06 14:50:22 -0700159
160 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800161 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700162 char *name = p->comm;
163 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800164
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800165 if (file) {
166 char *d_name = d_path(&file->f_path, _tmpbuf,
Jan Blunckcf28b482008-02-14 19:38:44 -0800167 sizeof(_tmpbuf));
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800168 if (!IS_ERR(d_name))
169 name = d_name;
170 }
Bryan Wu1394f032007-05-06 14:50:22 -0700171
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800172 /* FLAT does not have its text aligned to the start of
173 * the map while FDPIC ELF does ...
174 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800175
Robin Getz7f1c9062008-04-25 03:36:31 +0800176 /* before we can check flat/fdpic, we need to
177 * make sure current is valid
178 */
179 if ((unsigned long)current >= FIXED_CODE_START &&
180 !((unsigned long)current & 0x3)) {
181 if (current->mm &&
182 (address > current->mm->start_code) &&
183 (address < current->mm->end_code))
184 offset = address - current->mm->start_code;
185 else
186 offset = (address - vma->vm_start) +
187 (vma->vm_pgoff << PAGE_SHIFT);
188
Mike Frysinger18070dd2009-06-23 20:17:21 +0000189 sprintf(buf, "[ %s + 0x%lx ]", name, offset);
Robin Getz7f1c9062008-04-25 03:36:31 +0800190 } else
Mike Frysinger18070dd2009-06-23 20:17:21 +0000191 sprintf(buf, "[ %s vma:0x%lx-0x%lx]",
192 name, vma->vm_start, vma->vm_end);
Robin Getz7f1c9062008-04-25 03:36:31 +0800193
Robin Getz904656c2008-03-26 09:17:43 +0800194 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800195 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800196
Mike Frysinger18070dd2009-06-23 20:17:21 +0000197 if (buf[0] == '\0')
198 sprintf(buf, "[ %s ] dynamic memory", name);
Robin Getzf09630b2008-07-26 19:45:46 +0800199
Robin Getz885be032007-10-29 17:20:41 +0800200 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700201 }
Bryan Wu1394f032007-05-06 14:50:22 -0700202 }
Robin Getz904656c2008-03-26 09:17:43 +0800203 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800204 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700205 }
Bryan Wu1394f032007-05-06 14:50:22 -0700206
207 /* we were unable to find this address anywhere */
Mike Frysinger18070dd2009-06-23 20:17:21 +0000208 sprintf(buf, "/* kernel dynamic memory */");
Robin Getz885be032007-10-29 17:20:41 +0800209
210done:
211 write_unlock_irqrestore(&tasklist_lock, flags);
Robin Getz9f06c382008-10-10 18:13:21 +0800212#else
213 sprintf(buf, " ");
214#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700215}
216
Robin Getz2ebcade2007-10-09 17:24:30 +0800217asmlinkage void double_fault_c(struct pt_regs *fp)
218{
Robin Getza0cab652009-05-11 18:34:41 +0000219#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
220 int j;
221 trace_buffer_save(j);
222#endif
223
Robin Getz226eb1e2007-10-29 17:59:07 +0800224 console_verbose();
225 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800226#ifdef CONFIG_DEBUG_VERBOSE
Joe Perchesad361c92009-07-06 13:05:40 -0700227 printk(KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800228#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
229 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
Graf Yang8f658732008-11-18 17:48:22 +0800230 unsigned int cpu = smp_processor_id();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800231 char buf[150];
Graf Yang8f658732008-11-18 17:48:22 +0800232 decode_address(buf, cpu_pda[cpu].retx);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800233 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
Graf Yang8f658732008-11-18 17:48:22 +0800234 (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
235 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800236 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +0800237 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800238 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
239
240 decode_address(buf, fp->retx);
Graf Yang8f658732008-11-18 17:48:22 +0800241 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800242 } else
243#endif
244 {
245 dump_bfin_process(fp);
246 dump_bfin_mem(fp);
247 show_regs(fp);
Robin Getza0cab652009-05-11 18:34:41 +0000248 dump_bfin_trace_buffer();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800249 }
Robin Getz9f06c382008-10-10 18:13:21 +0800250#endif
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000251 panic("Double Fault - unrecoverable event");
Robin Getz2ebcade2007-10-09 17:24:30 +0800252
253}
254
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400255static int kernel_mode_regs(struct pt_regs *regs)
256{
257 return regs->ipend & 0xffc0;
258}
259
Bryan Wu1394f032007-05-06 14:50:22 -0700260asmlinkage void trap_c(struct pt_regs *fp)
261{
Robin Getz518039b2007-07-25 11:03:28 +0800262#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
263 int j;
264#endif
Graf Yang8f658732008-11-18 17:48:22 +0800265#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
266 unsigned int cpu = smp_processor_id();
267#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400268 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +0800269 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700270 siginfo_t info;
271 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
272
Bryan Wu1394f032007-05-06 14:50:22 -0700273 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +0000274#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
275 last_seqstat = (u32)fp->seqstat;
276#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700277
Robin Getz226eb1e2007-10-29 17:59:07 +0800278 /* Important - be very careful dereferncing pointers - will lead to
279 * double faults if the stack has become corrupt
280 */
281
Bryan Wu1394f032007-05-06 14:50:22 -0700282 /* trap_c() will be called for exceptions. During exceptions
283 * processing, the pc value should be set with retx value.
284 * With this change we can cleanup some code in signal.c- TODO
285 */
286 fp->orig_pc = fp->retx;
287 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
288 trapnr, fp->ipend, fp->pc, fp->retx); */
289
290 /* send the appropriate signal to the user program */
291 switch (trapnr) {
292
293 /* This table works in conjuction with the one in ./mach-common/entry.S
294 * Some exceptions are handled there (in assembly, in exception space)
295 * Some are handled here, (in C, in interrupt space)
296 * Some, like CPLB, are handled in both, where the normal path is
297 * handled in assembly/exception space, and the error path is handled
298 * here
299 */
300
301 /* 0x00 - Linux Syscall, getting here is an error */
302 /* 0x01 - userspace gdb breakpoint, handled here */
303 case VEC_EXCPT01:
304 info.si_code = TRAP_ILLTRAP;
305 sig = SIGTRAP;
306 CHK_DEBUGGER_TRAP_MAYBE();
307 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400308 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400309 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700310 else
311 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800312 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700313 case VEC_EXCPT03:
314 info.si_code = SEGV_STACKFLOW;
315 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400316 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800317 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700318 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800319 /* 0x02 - KGDB initial connection and break signal trap */
320 case VEC_EXCPT02:
321#ifdef CONFIG_KGDB
322 info.si_code = TRAP_ILLTRAP;
323 sig = SIGTRAP;
324 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400325 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800326#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800327 /* 0x04 - User Defined */
328 /* 0x05 - User Defined */
329 /* 0x06 - User Defined */
330 /* 0x07 - User Defined */
331 /* 0x08 - User Defined */
332 /* 0x09 - User Defined */
333 /* 0x0A - User Defined */
334 /* 0x0B - User Defined */
335 /* 0x0C - User Defined */
336 /* 0x0D - User Defined */
337 /* 0x0E - User Defined */
338 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800339 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800340 * custom exception handler, and it is not actually installed properly
341 */
342 case VEC_EXCPT04 ... VEC_EXCPT15:
343 info.si_code = ILL_ILLPARAOP;
344 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400345 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800346 CHK_DEBUGGER_TRAP_MAYBE();
347 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700348 /* 0x10 HW Single step, handled here */
349 case VEC_STEP:
350 info.si_code = TRAP_STEP;
351 sig = SIGTRAP;
352 CHK_DEBUGGER_TRAP_MAYBE();
353 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400354 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400355 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700356 else
357 break;
358 /* 0x11 - Trace Buffer Full, handled here */
359 case VEC_OVFLOW:
360 info.si_code = TRAP_TRACEFLOW;
361 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400362 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800363 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700364 break;
365 /* 0x12 - Reserved, Caught by default */
366 /* 0x13 - Reserved, Caught by default */
367 /* 0x14 - Reserved, Caught by default */
368 /* 0x15 - Reserved, Caught by default */
369 /* 0x16 - Reserved, Caught by default */
370 /* 0x17 - Reserved, Caught by default */
371 /* 0x18 - Reserved, Caught by default */
372 /* 0x19 - Reserved, Caught by default */
373 /* 0x1A - Reserved, Caught by default */
374 /* 0x1B - Reserved, Caught by default */
375 /* 0x1C - Reserved, Caught by default */
376 /* 0x1D - Reserved, Caught by default */
377 /* 0x1E - Reserved, Caught by default */
378 /* 0x1F - Reserved, Caught by default */
379 /* 0x20 - Reserved, Caught by default */
380 /* 0x21 - Undefined Instruction, handled here */
381 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400382#ifdef CONFIG_BUG
383 if (kernel_mode_regs(fp)) {
384 switch (report_bug(fp->pc, fp)) {
385 case BUG_TRAP_TYPE_NONE:
386 break;
387 case BUG_TRAP_TYPE_WARN:
388 dump_bfin_trace_buffer();
389 fp->pc += 2;
390 goto traps_done;
391 case BUG_TRAP_TYPE_BUG:
392 /* call to panic() will dump trace, and it is
393 * off at this point, so it won't be clobbered
394 */
395 panic("BUG()");
396 }
397 }
398#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700399 info.si_code = ILL_ILLOPC;
400 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400401 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800402 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700403 break;
404 /* 0x22 - Illegal Instruction Combination, handled here */
405 case VEC_ILGAL_I:
406 info.si_code = ILL_ILLPARAOP;
407 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400408 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800409 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700410 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800411 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700412 case VEC_CPLB_VL:
413 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800414 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400415 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800416 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700417 break;
418 /* 0x24 - Data access misaligned, handled here */
419 case VEC_MISALI_D:
420 info.si_code = BUS_ADRALN;
421 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400422 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800423 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700424 break;
425 /* 0x25 - Unrecoverable Event, handled here */
426 case VEC_UNCOV:
427 info.si_code = ILL_ILLEXCPT;
428 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400429 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800430 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700431 break;
432 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
433 error case is handled here */
434 case VEC_CPLB_M:
435 info.si_code = BUS_ADRALN;
436 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400437 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700438 break;
439 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
440 case VEC_CPLB_MHIT:
441 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700442 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800443#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800444 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400445 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800446 else
Bryan Wu1394f032007-05-06 14:50:22 -0700447#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400448 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800449 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700450 break;
451 /* 0x28 - Emulation Watchpoint, handled here */
452 case VEC_WATCH:
453 info.si_code = TRAP_WATCHPT;
454 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800455 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700456 CHK_DEBUGGER_TRAP_MAYBE();
457 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400458 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400459 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700460 else
461 break;
462#ifdef CONFIG_BF535
463 /* 0x29 - Instruction fetch access error (535 only) */
464 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
465 info.si_code = BUS_OPFETCH;
466 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400467 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800468 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700469 break;
470#else
471 /* 0x29 - Reserved, Caught by default */
472#endif
473 /* 0x2A - Instruction fetch misaligned, handled here */
474 case VEC_MISALI_I:
475 info.si_code = BUS_ADRALN;
476 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400477 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800478 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700479 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800480 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700481 case VEC_CPLB_I_VL:
482 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800483 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400484 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800485 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700486 break;
487 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
488 case VEC_CPLB_I_M:
489 info.si_code = ILL_CPLB_MISS;
490 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400491 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700492 break;
493 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
494 case VEC_CPLB_I_MHIT:
495 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700496 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800497#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800498 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400499 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800500 else
Bryan Wu1394f032007-05-06 14:50:22 -0700501#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400502 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800503 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700504 break;
505 /* 0x2E - Illegal use of Supervisor Resource, handled here */
506 case VEC_ILL_RES:
507 info.si_code = ILL_PRVOPC;
508 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400509 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800510 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700511 break;
512 /* 0x2F - Reserved, Caught by default */
513 /* 0x30 - Reserved, Caught by default */
514 /* 0x31 - Reserved, Caught by default */
515 /* 0x32 - Reserved, Caught by default */
516 /* 0x33 - Reserved, Caught by default */
517 /* 0x34 - Reserved, Caught by default */
518 /* 0x35 - Reserved, Caught by default */
519 /* 0x36 - Reserved, Caught by default */
520 /* 0x37 - Reserved, Caught by default */
521 /* 0x38 - Reserved, Caught by default */
522 /* 0x39 - Reserved, Caught by default */
523 /* 0x3A - Reserved, Caught by default */
524 /* 0x3B - Reserved, Caught by default */
525 /* 0x3C - Reserved, Caught by default */
526 /* 0x3D - Reserved, Caught by default */
527 /* 0x3E - Reserved, Caught by default */
528 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800529 case VEC_HWERR:
530 info.si_code = BUS_ADRALN;
531 sig = SIGBUS;
532 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
533 /* System MMR Error */
534 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
535 info.si_code = BUS_ADRALN;
536 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400537 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800538 break;
539 /* External Memory Addressing Error */
540 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
541 info.si_code = BUS_ADRERR;
542 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400543 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800544 break;
545 /* Performance Monitor Overflow */
546 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400547 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800548 break;
549 /* RAISE 5 instruction */
550 case (SEQSTAT_HWERRCAUSE_RAISE_5):
551 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
552 break;
553 default: /* Reserved */
554 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
555 break;
556 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800557 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800558 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800559 /*
560 * We should be handling all known exception types above,
561 * if we get here we hit a reserved one, so panic
562 */
Bryan Wu1394f032007-05-06 14:50:22 -0700563 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800564 info.si_code = ILL_ILLPARAOP;
565 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800566 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700567 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800568 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700569 break;
570 }
571
Robin Getz226eb1e2007-10-29 17:59:07 +0800572 BUG_ON(sig == 0);
573
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400574 /* If the fault was caused by a kernel thread, or interrupt handler
575 * we will kernel panic, so the system reboots.
576 */
577 if (kernel_mode_regs(fp) || (current && !current->mm)) {
578 console_verbose();
579 oops_in_progress = 1;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400580 }
581
Robin Getz226eb1e2007-10-29 17:59:07 +0800582 if (sig != SIGTRAP) {
Mike Frysinger15627bd2009-06-23 11:21:34 +0000583 if (strerror)
584 verbose_printk(strerror);
585
Mike Frysinger49dce912007-11-21 16:46:49 +0800586 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800587 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800588 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800589
590 /* Print out the trace buffer if it makes sense */
591#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
592 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800593 verbose_printk(KERN_NOTICE "No trace since you do not have "
Joe Perchesad361c92009-07-06 13:05:40 -0700594 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800595 else
596#endif
597 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800598
Robin Getz226eb1e2007-10-29 17:59:07 +0800599 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800600 /* Dump the current kernel stack */
Joe Perchesad361c92009-07-06 13:05:40 -0700601 verbose_printk(KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800602 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800603 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800604#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800605 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800606 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800607#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700608 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800609 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800610#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800611 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800612 /* Dump the user space stack */
613 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800614 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800615 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800616#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800617 }
Bryan Wu1394f032007-05-06 14:50:22 -0700618 }
Robin Getzfb322912007-11-21 16:38:05 +0800619
Yi Li6a01f232009-01-07 23:14:39 +0800620#ifdef CONFIG_IPIPE
621 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
622#endif
623 {
624 info.si_signo = sig;
625 info.si_errno = 0;
626 info.si_addr = (void __user *)fp->pc;
627 force_sig_info(sig, &info, current);
628 }
Bryan Wu1394f032007-05-06 14:50:22 -0700629
Robin Getz0e4edcf2009-06-22 20:23:48 +0000630 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
Robin Getzf574a762009-07-09 15:11:52 +0000631 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
632 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
Robin Getz0acad8d2009-05-11 18:55:16 +0000633 fp->pc = SAFE_USER_INSTRUCTION;
634
Mike Frysinger6510a202009-06-07 15:07:25 -0400635 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700636 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700637}
638
639/* Typical exception handling routines */
640
Robin Getz518039b2007-07-25 11:03:28 +0800641#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
642
Robin Getzf09630b2008-07-26 19:45:46 +0800643/*
644 * Similar to get_user, do some address checking, then dereference
645 * Return true on sucess, false on bad address
646 */
Robin Getz9f06c382008-10-10 18:13:21 +0800647static bool get_instruction(unsigned short *val, unsigned short *address)
Robin Getzf09630b2008-07-26 19:45:46 +0800648{
Mike Frysingere56e03b2009-06-07 16:31:52 -0400649 unsigned long addr = (unsigned long)address;
Robin Getzf09630b2008-07-26 19:45:46 +0800650
651 /* Check for odd addresses */
652 if (addr & 0x1)
653 return false;
654
Mike Frysingere56e03b2009-06-07 16:31:52 -0400655 /* MMR region will never have instructions */
656 if (addr >= SYSMMR_BASE)
Robin Getzf09630b2008-07-26 19:45:46 +0800657 return false;
658
Mike Frysingere56e03b2009-06-07 16:31:52 -0400659 switch (bfin_mem_access_type(addr, 2)) {
660 case BFIN_MEM_ACCESS_CORE:
661 case BFIN_MEM_ACCESS_CORE_ONLY:
662 *val = *address;
663 return true;
664 case BFIN_MEM_ACCESS_DMA:
665 dma_memcpy(val, address, 2);
666 return true;
667 case BFIN_MEM_ACCESS_ITEST:
668 isram_memcpy(val, address, 2);
669 return true;
670 default: /* invalid access */
671 return false;
Robin Getzf09630b2008-07-26 19:45:46 +0800672 }
Robin Getzf09630b2008-07-26 19:45:46 +0800673}
674
Mike Frysinger36f649a2008-11-18 17:48:22 +0800675/*
Robin Getzd3d0ac22008-08-06 17:49:27 +0800676 * decode the instruction if we are printing out the trace, as it
677 * makes things easier to follow, without running it through objdump
678 * These are the normal instructions which cause change of flow, which
679 * would be at the source of the trace buffer
680 */
Mike Frysinger36f649a2008-11-18 17:48:22 +0800681#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
Robin Getz9f06c382008-10-10 18:13:21 +0800682static void decode_instruction(unsigned short *address)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800683{
684 unsigned short opcode;
685
686 if (get_instruction(&opcode, address)) {
687 if (opcode == 0x0010)
Robin Getz9f06c382008-10-10 18:13:21 +0800688 verbose_printk("RTS");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800689 else if (opcode == 0x0011)
Robin Getz9f06c382008-10-10 18:13:21 +0800690 verbose_printk("RTI");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800691 else if (opcode == 0x0012)
Robin Getz9f06c382008-10-10 18:13:21 +0800692 verbose_printk("RTX");
Robin Getz0be58932009-02-04 16:49:45 +0800693 else if (opcode == 0x0013)
694 verbose_printk("RTN");
695 else if (opcode == 0x0014)
696 verbose_printk("RTE");
697 else if (opcode == 0x0025)
698 verbose_printk("EMUEXCPT");
699 else if (opcode == 0x0040 && opcode <= 0x0047)
700 verbose_printk("STI R%i", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800701 else if (opcode >= 0x0050 && opcode <= 0x0057)
Robin Getz9f06c382008-10-10 18:13:21 +0800702 verbose_printk("JUMP (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800703 else if (opcode >= 0x0060 && opcode <= 0x0067)
Robin Getz9f06c382008-10-10 18:13:21 +0800704 verbose_printk("CALL (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800705 else if (opcode >= 0x0070 && opcode <= 0x0077)
Robin Getz9f06c382008-10-10 18:13:21 +0800706 verbose_printk("CALL (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800707 else if (opcode >= 0x0080 && opcode <= 0x0087)
Robin Getz9f06c382008-10-10 18:13:21 +0800708 verbose_printk("JUMP (PC+P%i)", opcode & 7);
Robin Getz0be58932009-02-04 16:49:45 +0800709 else if (opcode >= 0x0090 && opcode <= 0x009F)
710 verbose_printk("RAISE 0x%x", opcode & 0xF);
711 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
712 verbose_printk("EXCPT 0x%x", opcode & 0xF);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800713 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
Robin Getz9f06c382008-10-10 18:13:21 +0800714 verbose_printk("IF !CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800715 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
Robin Getz9f06c382008-10-10 18:13:21 +0800716 verbose_printk("IF CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800717 else if (opcode >= 0x2000 && opcode <= 0x2fff)
Robin Getz9f06c382008-10-10 18:13:21 +0800718 verbose_printk("JUMP.S");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800719 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800720 verbose_printk("LSETUP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800721 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800722 verbose_printk("JUMP.L");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800723 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800724 verbose_printk("CALL pcrel");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800725 else
Robin Getz9f06c382008-10-10 18:13:21 +0800726 verbose_printk("0x%04x", opcode);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800727 }
728
729}
Robin Getz9f06c382008-10-10 18:13:21 +0800730#endif
Robin Getzd3d0ac22008-08-06 17:49:27 +0800731
Bryan Wu1394f032007-05-06 14:50:22 -0700732void dump_bfin_trace_buffer(void)
733{
Robin Getz9f06c382008-10-10 18:13:21 +0800734#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz518039b2007-07-25 11:03:28 +0800735#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
736 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800737 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800738 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800739#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
740 int j, index;
741#endif
742
Bryan Wu1394f032007-05-06 14:50:22 -0700743 trace_buffer_save(tflags);
744
Robin Getz226eb1e2007-10-29 17:59:07 +0800745 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800746
Robin Getzd3d0ac22008-08-06 17:49:27 +0800747#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
748 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
749#endif
750
Bryan Wu1394f032007-05-06 14:50:22 -0700751 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800752 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800753 decode_address(buf, (unsigned long)bfin_read_TBUF());
754 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800755 addr = (unsigned short *)bfin_read_TBUF();
756 decode_address(buf, (unsigned long)addr);
757 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800758 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800759 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700760 }
761 }
762
Robin Getz518039b2007-07-25 11:03:28 +0800763#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
764 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800765 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800766 else
767 index = EXPAND_LEN;
768
769 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
770 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800771 decode_address(buf, software_trace_buff[index]);
772 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800773 index -= 1;
774 if (index < 0 )
775 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800776 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800777 printk(KERN_NOTICE " Source : %s ", buf);
778 decode_instruction((unsigned short *)software_trace_buff[index]);
779 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800780 index -= 1;
781 if (index < 0)
782 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800783 j--;
784 i++;
785 }
786#endif
787
Bryan Wu1394f032007-05-06 14:50:22 -0700788 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800789#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800790#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700791}
792EXPORT_SYMBOL(dump_bfin_trace_buffer);
793
Mike Frysinger70f12562009-06-07 17:18:25 -0400794#ifdef CONFIG_BUG
795int is_valid_bugaddr(unsigned long addr)
796{
797 unsigned short opcode;
798
799 if (!get_instruction(&opcode, (unsigned short *)addr))
800 return 0;
801
802 return opcode == BFIN_BUG_OPCODE;
803}
804#endif
805
Robin Getzf09630b2008-07-26 19:45:46 +0800806/*
807 * Checks to see if the address pointed to is either a
808 * 16-bit CALL instruction, or a 32-bit CALL instruction
809 */
Robin Getz9f06c382008-10-10 18:13:21 +0800810static bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700811{
Robin Getzf09630b2008-07-26 19:45:46 +0800812 unsigned short opcode = 0, *ins_addr;
813 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700814
Robin Getzf09630b2008-07-26 19:45:46 +0800815 if (!get_instruction(&opcode, ins_addr))
816 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700817
Robin Getzf09630b2008-07-26 19:45:46 +0800818 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
819 (opcode >= 0x0070 && opcode <= 0x0077))
820 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700821
Robin Getzf09630b2008-07-26 19:45:46 +0800822 ins_addr--;
823 if (!get_instruction(&opcode, ins_addr))
824 return false;
825
826 if (opcode >= 0xE300 && opcode <= 0xE3FF)
827 return true;
828
829 return false;
830
Bryan Wu1394f032007-05-06 14:50:22 -0700831}
Robin Getz9f06c382008-10-10 18:13:21 +0800832
Bryan Wu1394f032007-05-06 14:50:22 -0700833void show_stack(struct task_struct *task, unsigned long *stack)
834{
Robin Getz9f06c382008-10-10 18:13:21 +0800835#ifdef CONFIG_PRINTK
Robin Getzf09630b2008-07-26 19:45:46 +0800836 unsigned int *addr, *endstack, *fp = 0, *frame;
837 unsigned short *ins_addr;
838 char buf[150];
839 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700840
Robin Getzf09630b2008-07-26 19:45:46 +0800841 /*
842 * If we have been passed a specific stack, use that one otherwise
843 * if we have been passed a task structure, use that, otherwise
844 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700845 */
846
Robin Getzf09630b2008-07-26 19:45:46 +0800847 if (stack == NULL) {
848 if (task) {
849 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700850 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800851 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
852 } else {
853 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700854 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800855 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
856 }
857 } else
858 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
859
Robin Getz9f06c382008-10-10 18:13:21 +0800860 printk(KERN_NOTICE "Stack info:\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800861 decode_address(buf, (unsigned int)stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800862 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
863
Robin Getza0cab652009-05-11 18:34:41 +0000864 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
865 printk(KERN_NOTICE "Invalid stack pointer\n");
866 return;
867 }
868
Robin Getzf09630b2008-07-26 19:45:46 +0800869 /* First thing is to look for a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800870 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800871 if (*addr & 0x1)
872 continue;
873 ins_addr = (unsigned short *)*addr;
874 ins_addr--;
875 if (is_bfin_call(ins_addr))
876 fp = addr - 1;
877
878 if (fp) {
879 /* Let's check to see if it is a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800880 while (fp >= (addr - 1) && fp < endstack
881 && fp && ((unsigned int) fp & 0x3) == 0)
Robin Getzf09630b2008-07-26 19:45:46 +0800882 fp = (unsigned int *)*fp;
883 if (fp == 0 || fp == endstack) {
884 fp = addr - 1;
885 break;
886 }
887 fp = 0;
888 }
889 }
890 if (fp) {
891 frame = fp;
Jie Zhangb339dc72009-01-07 23:14:39 +0800892 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
Robin Getzf09630b2008-07-26 19:45:46 +0800893 } else
894 frame = 0;
895
896 /*
897 * Now that we think we know where things are, we
898 * walk the stack again, this time printing things out
899 * incase there is no frame pointer, we still look for
900 * valid return addresses
901 */
902
903 /* First time print out data, next time, print out symbols */
904 for (j = 0; j <= 1; j++) {
905 if (j)
906 printk(KERN_NOTICE "Return addresses in stack:\n");
907 else
908 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
909
910 fp = frame;
911 frame_no = 0;
912
913 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
Sonic Zhang407505d2009-07-16 10:36:35 +0000914 addr < endstack; addr++, i++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800915
916 ret_addr = 0;
917 if (!j && i % 8 == 0)
Joe Perchesad361c92009-07-06 13:05:40 -0700918 printk(KERN_NOTICE "%p:",addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800919
920 /* if it is an odd address, or zero, just skip it */
921 if (*addr & 0x1 || !*addr)
922 goto print;
923
924 ins_addr = (unsigned short *)*addr;
925
926 /* Go back one instruction, and see if it is a CALL */
927 ins_addr--;
928 ret_addr = is_bfin_call(ins_addr);
929 print:
930 if (!j && stack == (unsigned long *)addr)
931 printk("[%08x]", *addr);
932 else if (ret_addr)
933 if (j) {
934 decode_address(buf, (unsigned int)*addr);
935 if (frame == addr) {
936 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
937 continue;
938 }
939 printk(KERN_NOTICE " address : %s\n", buf);
940 } else
941 printk("<%08x>", *addr);
942 else if (fp == addr) {
943 if (j)
944 frame = addr+1;
945 else
946 printk("(%08x)", *addr);
947
948 fp = (unsigned int *)*addr;
949 frame_no++;
950
951 } else if (!j)
952 printk(" %08x ", *addr);
953 }
954 if (!j)
955 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700956 }
Robin Getz9f06c382008-10-10 18:13:21 +0800957#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700958}
Philippe Gerumbc569f12009-06-22 18:23:12 +0200959EXPORT_SYMBOL(show_stack);
Bryan Wu1394f032007-05-06 14:50:22 -0700960
961void dump_stack(void)
962{
963 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800964#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700965 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800966#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700967 trace_buffer_save(tflags);
968 dump_bfin_trace_buffer();
969 show_stack(current, &stack);
970 trace_buffer_restore(tflags);
971}
Bryan Wu1394f032007-05-06 14:50:22 -0700972EXPORT_SYMBOL(dump_stack);
973
Mike Frysinger49dce912007-11-21 16:46:49 +0800974void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700975{
Robin Getz9f06c382008-10-10 18:13:21 +0800976#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +0800977 /* We should be able to look at fp->ipend, but we don't push it on the
978 * stack all the time, so do this until we fix that */
979 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800980
Mike Frysinger49dce912007-11-21 16:46:49 +0800981 if (oops_in_progress)
Robin Getz9f06c382008-10-10 18:13:21 +0800982 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800983
Robin Getzb03b08b2007-12-23 22:57:01 +0800984 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
Robin Getz9f06c382008-10-10 18:13:21 +0800985 verbose_printk(KERN_NOTICE "HW Error context\n");
Robin Getzb03b08b2007-12-23 22:57:01 +0800986 else if (context & 0x0020)
Robin Getz9f06c382008-10-10 18:13:21 +0800987 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800988 else if (context & 0x3FC0)
Robin Getz9f06c382008-10-10 18:13:21 +0800989 verbose_printk(KERN_NOTICE "Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800990 else if (context & 0x4000)
Robin Getz9f06c382008-10-10 18:13:21 +0800991 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800992 else if (context & 0x8000)
Robin Getz9f06c382008-10-10 18:13:21 +0800993 verbose_printk(KERN_NOTICE "Kernel process context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800994
Robin Getz9a62ca42008-03-26 09:15:58 +0800995 /* Because we are crashing, and pointers could be bad, we check things
996 * pretty closely before we use them
997 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800998 if ((unsigned long)current >= FIXED_CODE_START &&
999 !((unsigned long)current & 0x3) && current->pid) {
Robin Getz9f06c382008-10-10 18:13:21 +08001000 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +08001001 if (current->comm >= (char *)FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +08001002 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
Robin Getz9a62ca42008-03-26 09:15:58 +08001003 current->comm, current->pid);
1004 else
Robin Getz9f06c382008-10-10 18:13:21 +08001005 verbose_printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001006
Graf Yang8f658732008-11-18 17:48:22 +08001007 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
Robin Getz9a62ca42008-03-26 09:15:58 +08001008 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
Joe Perchesad361c92009-07-06 13:05:40 -07001009 verbose_printk(KERN_NOTICE
1010 "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
1011 " BSS = 0x%p-0x%p USER-STACK = 0x%p\n\n",
Robin Getz9a62ca42008-03-26 09:15:58 +08001012 (void *)current->mm->start_code,
1013 (void *)current->mm->end_code,
1014 (void *)current->mm->start_data,
1015 (void *)current->mm->end_data,
1016 (void *)current->mm->end_data,
1017 (void *)current->mm->brk,
1018 (void *)current->mm->start_stack);
1019 else
Robin Getz9f06c382008-10-10 18:13:21 +08001020 verbose_printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001021 } else
Joe Perchesad361c92009-07-06 13:05:40 -07001022 verbose_printk(KERN_NOTICE
1023 "No Valid process in current context\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001024#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001025}
1026
Robin Getzb03b08b2007-12-23 22:57:01 +08001027void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +08001028{
Robin Getz9f06c382008-10-10 18:13:21 +08001029#ifdef CONFIG_DEBUG_VERBOSE
Robin Getzb03b08b2007-12-23 22:57:01 +08001030 unsigned short *addr, *erraddr, val = 0, err = 0;
1031 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -07001032
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001033 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +08001034
Robin Getz9f06c382008-10-10 18:13:21 +08001035 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001036
1037 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1038 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1039 addr++) {
1040 if (!((unsigned long)addr & 0xF))
Joe Perchesad361c92009-07-06 13:05:40 -07001041 verbose_printk(KERN_NOTICE "0x%p: ", addr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001042
Robin Getz7d98c882008-10-08 16:29:01 +08001043 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +08001044 val = 0;
1045 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +08001046 } else
1047 sprintf(buf, "%04x", val);
1048
1049 if (addr == erraddr) {
Robin Getz9f06c382008-10-10 18:13:21 +08001050 verbose_printk("[%s]", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001051 err = val;
1052 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001053 verbose_printk(" %s ", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001054
1055 /* Do any previous instructions turn on interrupts? */
1056 if (addr <= erraddr && /* in the past */
1057 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1058 val == 0x017b)) /* [SP++] = RETI */
1059 sti = 1;
1060 }
1061
Robin Getz9f06c382008-10-10 18:13:21 +08001062 verbose_printk("\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001063
1064 /* Hardware error interrupts can be deferred */
1065 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1066 oops_in_progress)){
Robin Getz9f06c382008-10-10 18:13:21 +08001067 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001068#ifndef CONFIG_DEBUG_HWERR
Joe Perchesad361c92009-07-06 13:05:40 -07001069 verbose_printk(KERN_NOTICE
1070"The remaining message may be meaningless\n"
1071"You should enable CONFIG_DEBUG_HWERR to get a better idea where it came from\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001072#else
1073 /* If we are handling only one peripheral interrupt
1074 * and current mm and pid are valid, and the last error
1075 * was in that user space process's text area
1076 * print it out - because that is where the problem exists
1077 */
1078 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1079 (current->pid && current->mm)) {
1080 /* And the last RETI points to the current userspace context */
1081 if ((fp + 1)->pc >= current->mm->start_code &&
1082 (fp + 1)->pc <= current->mm->end_code) {
Robin Getz9f06c382008-10-10 18:13:21 +08001083 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1084 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001085 show_regs(fp + 1);
Robin Getz9f06c382008-10-10 18:13:21 +08001086 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001087 }
Bryan Wu1394f032007-05-06 14:50:22 -07001088 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001089#endif
1090 }
Robin Getz9f06c382008-10-10 18:13:21 +08001091#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001092}
1093
1094void show_regs(struct pt_regs *fp)
1095{
Robin Getz9f06c382008-10-10 18:13:21 +08001096#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001097 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001098 struct irqaction *action;
1099 unsigned int i;
Robin Getz2f95d5b2009-02-04 16:49:45 +08001100 unsigned long flags = 0;
Graf Yang8f658732008-11-18 17:48:22 +08001101 unsigned int cpu = smp_processor_id();
Robin Getz2f95d5b2009-02-04 16:49:45 +08001102 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -07001103
Robin Getz9ba3c242009-05-20 21:19:21 +00001104 verbose_printk(KERN_NOTICE "\n");
1105 if (CPUID != bfin_cpuid())
1106 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1107 "but running on:0x%04x (Rev %d)\n",
1108 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1109
1110 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1111 CPU, bfin_compiled_revid());
1112
1113 if (bfin_compiled_revid() != bfin_revid())
1114 verbose_printk("(Detected 0.%d)", bfin_revid());
1115
1116 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1117 get_cclk()/1000000, get_sclk()/1000000,
1118#ifdef CONFIG_MPU
1119 "mpu on"
1120#else
1121 "mpu off"
1122#endif
1123 );
1124
1125 verbose_printk(KERN_NOTICE "%s", linux_banner);
1126
Robin Getzae4f0732009-06-22 02:02:16 +00001127 verbose_printk(KERN_NOTICE "\nSEQUENCER STATUS:\t\t%s\n", print_tainted());
1128 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx IMASK: %04lx SYSCFG: %04lx\n",
1129 (long)fp->seqstat, fp->ipend, cpu_pda[smp_processor_id()].ex_imask, fp->syscfg);
1130 if (fp->ipend & EVT_IRPTEN)
1131 verbose_printk(KERN_NOTICE " Global Interrupts Disabled (IPEND[4])\n");
1132 if (!(cpu_pda[smp_processor_id()].ex_imask & (EVT_IVG13 | EVT_IVG12 | EVT_IVG11 |
1133 EVT_IVG10 | EVT_IVG9 | EVT_IVG8 | EVT_IVG7 | EVT_IVTMR)))
1134 verbose_printk(KERN_NOTICE " Peripheral interrupts masked off\n");
1135 if (!(cpu_pda[smp_processor_id()].ex_imask & (EVT_IVG15 | EVT_IVG14)))
1136 verbose_printk(KERN_NOTICE " Kernel interrupts masked off\n");
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001137 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001138 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001139 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1140#ifdef EBIU_ERRMST
1141 /* If the error was from the EBIU, print it out */
1142 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001143 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001144 bfin_read_EBIU_ERRMST());
Robin Getz9f06c382008-10-10 18:13:21 +08001145 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001146 bfin_read_EBIU_ERRADD());
1147 }
1148#endif
1149 }
Robin Getz9f06c382008-10-10 18:13:21 +08001150 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
Robin Getz13fe24f2008-01-27 15:38:56 +08001151 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getz2f95d5b2009-02-04 16:49:45 +08001152 for (i = 2; i <= 15 ; i++) {
Robin Getzd8f66c82007-12-24 15:27:56 +08001153 if (fp->ipend & (1 << i)) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001154 if (i != 4) {
1155 decode_address(buf, bfin_read32(EVT0 + 4*i));
1156 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1157 } else
1158 verbose_printk(KERN_NOTICE " interrupts disabled\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001159 }
1160 }
1161
1162 /* if no interrupts are going off, don't print this out */
1163 if (fp->ipend & ~0x3F) {
1164 for (i = 0; i < (NR_IRQS - 1); i++) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001165 if (!in_atomic)
1166 spin_lock_irqsave(&irq_desc[i].lock, flags);
1167
Robin Getzd8f66c82007-12-24 15:27:56 +08001168 action = irq_desc[i].action;
1169 if (!action)
1170 goto unlock;
1171
1172 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001173 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001174 for (action = action->next; action; action = action->next) {
1175 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001176 verbose_printk(", %s", buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001177 }
Robin Getz9f06c382008-10-10 18:13:21 +08001178 verbose_printk("\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001179unlock:
Robin Getz2f95d5b2009-02-04 16:49:45 +08001180 if (!in_atomic)
1181 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Robin Getzd8f66c82007-12-24 15:27:56 +08001182 }
1183 }
Bryan Wu1394f032007-05-06 14:50:22 -07001184
Robin Getz226eb1e2007-10-29 17:59:07 +08001185 decode_address(buf, fp->rete);
Robin Getz9f06c382008-10-10 18:13:21 +08001186 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001187 decode_address(buf, fp->retn);
Robin Getz9f06c382008-10-10 18:13:21 +08001188 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001189 decode_address(buf, fp->retx);
Robin Getz9f06c382008-10-10 18:13:21 +08001190 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001191 decode_address(buf, fp->rets);
Robin Getz9f06c382008-10-10 18:13:21 +08001192 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001193 decode_address(buf, fp->pc);
Robin Getz9f06c382008-10-10 18:13:21 +08001194 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001195
Robin Getz13fe24f2008-01-27 15:38:56 +08001196 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1197 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Graf Yang8f658732008-11-18 17:48:22 +08001198 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001199 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +08001200 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001201 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001202 }
1203
Joe Perchesad361c92009-07-06 13:05:40 -07001204 verbose_printk(KERN_NOTICE "PROCESSOR STATE:\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001205 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001206 fp->r0, fp->r1, fp->r2, fp->r3);
Robin Getz9f06c382008-10-10 18:13:21 +08001207 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001208 fp->r4, fp->r5, fp->r6, fp->r7);
Robin Getz9f06c382008-10-10 18:13:21 +08001209 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001210 fp->p0, fp->p1, fp->p2, fp->p3);
Robin Getz9f06c382008-10-10 18:13:21 +08001211 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001212 fp->p4, fp->p5, fp->fp, (long)fp);
Robin Getz9f06c382008-10-10 18:13:21 +08001213 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001214 fp->lb0, fp->lt0, fp->lc0);
Robin Getz9f06c382008-10-10 18:13:21 +08001215 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001216 fp->lb1, fp->lt1, fp->lc1);
Robin Getz9f06c382008-10-10 18:13:21 +08001217 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001218 fp->b0, fp->l0, fp->m0, fp->i0);
Robin Getz9f06c382008-10-10 18:13:21 +08001219 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001220 fp->b1, fp->l1, fp->m1, fp->i1);
Robin Getz9f06c382008-10-10 18:13:21 +08001221 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001222 fp->b2, fp->l2, fp->m2, fp->i2);
Robin Getz9f06c382008-10-10 18:13:21 +08001223 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001224 fp->b3, fp->l3, fp->m3, fp->i3);
Robin Getz9f06c382008-10-10 18:13:21 +08001225 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001226 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1227
Robin Getz9f06c382008-10-10 18:13:21 +08001228 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001229 rdusp(), fp->astat);
1230
Robin Getz9f06c382008-10-10 18:13:21 +08001231 verbose_printk(KERN_NOTICE "\n");
1232#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001233}
1234
1235#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1236asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1237#endif
1238
Graf Yang8f658732008-11-18 17:48:22 +08001239static DEFINE_SPINLOCK(bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001240
Graf Yang8f658732008-11-18 17:48:22 +08001241asmlinkage int sys_bfin_spinlock(int *p)
1242{
1243 int ret, tmp = 0;
1244
1245 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1246 ret = get_user(tmp, p);
1247 if (likely(ret == 0)) {
1248 if (unlikely(tmp))
Bryan Wu1394f032007-05-06 14:50:22 -07001249 ret = 1;
Graf Yang8f658732008-11-18 17:48:22 +08001250 else
1251 put_user(1, p);
Bryan Wu1394f032007-05-06 14:50:22 -07001252 }
Graf Yang8f658732008-11-18 17:48:22 +08001253 spin_unlock(&bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001254 return ret;
1255}
1256
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001257int bfin_request_exception(unsigned int exception, void (*handler)(void))
1258{
1259 void (*curr_handler)(void);
1260
1261 if (exception > 0x3F)
1262 return -EINVAL;
1263
1264 curr_handler = ex_table[exception];
1265
1266 if (curr_handler != ex_replaceable)
1267 return -EBUSY;
1268
1269 ex_table[exception] = handler;
1270
1271 return 0;
1272}
1273EXPORT_SYMBOL(bfin_request_exception);
1274
1275int bfin_free_exception(unsigned int exception, void (*handler)(void))
1276{
1277 void (*curr_handler)(void);
1278
1279 if (exception > 0x3F)
1280 return -EINVAL;
1281
1282 curr_handler = ex_table[exception];
1283
1284 if (curr_handler != handler)
1285 return -EBUSY;
1286
1287 ex_table[exception] = ex_replaceable;
1288
1289 return 0;
1290}
1291EXPORT_SYMBOL(bfin_free_exception);
1292
Bryan Wu1394f032007-05-06 14:50:22 -07001293void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1294{
1295 switch (cplb_panic) {
1296 case CPLB_NO_UNLOCKED:
1297 printk(KERN_EMERG "All CPLBs are locked\n");
1298 break;
1299 case CPLB_PROT_VIOL:
1300 return;
1301 case CPLB_NO_ADDR_MATCH:
1302 return;
1303 case CPLB_UNKNOWN_ERR:
1304 printk(KERN_EMERG "Unknown CPLB Exception\n");
1305 break;
1306 }
1307
Robin Getz226eb1e2007-10-29 17:59:07 +08001308 oops_in_progress = 1;
1309
Mike Frysinger49dce912007-11-21 16:46:49 +08001310 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001311 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001312 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001313 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +00001314 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -07001315}