blob: d279552fe9b01633738880454872ce4e581dc03f [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 Frysinger1f83b8f2007-07-12 22:58:21 +080040#include <asm/blackfin.h>
41#include <asm/irq_handler.h>
Robin Getzd8f66c82007-12-24 15:27:56 +080042#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080043#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080044#include <asm/fixed_code.h>
Bryan Wu1394f032007-05-06 14:50:22 -070045
46#ifdef CONFIG_KGDB
Bryan Wu1394f032007-05-06 14:50:22 -070047# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080048
49# define CHK_DEBUGGER_TRAP() \
50 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080051 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080052 } while (0)
53# define CHK_DEBUGGER_TRAP_MAYBE() \
54 do { \
55 if (kgdb_connected) \
56 CHK_DEBUGGER_TRAP(); \
57 } while (0)
58#else
59# define CHK_DEBUGGER_TRAP() do { } while (0)
60# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070061#endif
62
Robin Getz9f06c382008-10-10 18:13:21 +080063
Robin Getz4ee1c452008-10-28 11:36:11 +080064#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +080065#define verbose_printk(fmt, arg...) \
66 printk(fmt, ##arg)
67#else
68#define verbose_printk(fmt, arg...) \
69 ({ if (0) printk(fmt, ##arg); 0; })
70#endif
71
Robin Getz81f7f452009-06-03 18:58:26 +000072#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
73u32 last_seqstat;
74#ifdef CONFIG_DEBUG_MMRS_MODULE
75EXPORT_SYMBOL(last_seqstat);
76#endif
77#endif
78
Bryan Wu1394f032007-05-06 14:50:22 -070079/* Initiate the event table handler */
80void __init trap_init(void)
81{
82 CSYNC();
83 bfin_write_EVT3(trap);
84 CSYNC();
85}
86
Robin Getz226eb1e2007-10-29 17:59:07 +080087static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070088{
Robin Getz9f06c382008-10-10 18:13:21 +080089#ifdef CONFIG_DEBUG_VERBOSE
Bryan Wu1394f032007-05-06 14:50:22 -070090 struct task_struct *p;
91 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080092 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080093 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
David Howells8feae132009-01-08 12:04:47 +000094 struct rb_node *n;
Bryan Wu1394f032007-05-06 14:50:22 -070095
96#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080097 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070098 const char *symname;
99 char *modname;
100 char *delim = ":";
101 char namebuf[128];
102
103 /* look up the address and see if we are in kernel space */
104 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
105
106 if (symname) {
107 /* yeah! kernel space! */
108 if (!modname)
109 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +0800110 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800111 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -0700112 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +0800113 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700114
115 }
116#endif
117
Robin Getz226eb1e2007-10-29 17:59:07 +0800118 /* Problem in fixed code section? */
119 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
120 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
121 return;
122 }
123
124 /* Problem somewhere before the kernel start address */
125 if (address < CONFIG_BOOT_LOAD) {
126 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
127 return;
128 }
129
Bryan Wu1394f032007-05-06 14:50:22 -0700130 /* looks like we're off in user-land, so let's walk all the
131 * mappings of all our processes and see if we can't be a whee
132 * bit more specific
133 */
Robin Getz885be032007-10-29 17:20:41 +0800134 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700135 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800136 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700137 if (!mm)
138 continue;
139
David Howells8feae132009-01-08 12:04:47 +0000140 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
141 struct vm_area_struct *vma;
142
143 vma = rb_entry(n, struct vm_area_struct, vm_rb);
Bryan Wu1394f032007-05-06 14:50:22 -0700144
145 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800146 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700147 char *name = p->comm;
148 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800149
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800150 if (file) {
151 char *d_name = d_path(&file->f_path, _tmpbuf,
Jan Blunckcf28b482008-02-14 19:38:44 -0800152 sizeof(_tmpbuf));
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800153 if (!IS_ERR(d_name))
154 name = d_name;
155 }
Bryan Wu1394f032007-05-06 14:50:22 -0700156
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800157 /* FLAT does not have its text aligned to the start of
158 * the map while FDPIC ELF does ...
159 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800160
Robin Getz7f1c9062008-04-25 03:36:31 +0800161 /* before we can check flat/fdpic, we need to
162 * make sure current is valid
163 */
164 if ((unsigned long)current >= FIXED_CODE_START &&
165 !((unsigned long)current & 0x3)) {
166 if (current->mm &&
167 (address > current->mm->start_code) &&
168 (address < current->mm->end_code))
169 offset = address - current->mm->start_code;
170 else
171 offset = (address - vma->vm_start) +
172 (vma->vm_pgoff << PAGE_SHIFT);
173
174 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
175 (void *)address, name, offset);
176 } else
177 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
178 (void *)address, name,
179 vma->vm_start, vma->vm_end);
180
Robin Getz904656c2008-03-26 09:17:43 +0800181 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800182 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800183
Robin Getzf09630b2008-07-26 19:45:46 +0800184 if (!strlen(buf))
185 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
186
Robin Getz885be032007-10-29 17:20:41 +0800187 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700188 }
Bryan Wu1394f032007-05-06 14:50:22 -0700189 }
Robin Getz904656c2008-03-26 09:17:43 +0800190 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800191 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700192 }
Bryan Wu1394f032007-05-06 14:50:22 -0700193
194 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800195 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800196
197done:
198 write_unlock_irqrestore(&tasklist_lock, flags);
Robin Getz9f06c382008-10-10 18:13:21 +0800199#else
200 sprintf(buf, " ");
201#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700202}
203
Robin Getz2ebcade2007-10-09 17:24:30 +0800204asmlinkage void double_fault_c(struct pt_regs *fp)
205{
Robin Getza0cab652009-05-11 18:34:41 +0000206#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
207 int j;
208 trace_buffer_save(j);
209#endif
210
Robin Getz226eb1e2007-10-29 17:59:07 +0800211 console_verbose();
212 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800213#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz2ebcade2007-10-09 17:24:30 +0800214 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800215#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
216 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
Graf Yang8f658732008-11-18 17:48:22 +0800217 unsigned int cpu = smp_processor_id();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800218 char buf[150];
Graf Yang8f658732008-11-18 17:48:22 +0800219 decode_address(buf, cpu_pda[cpu].retx);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800220 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
Graf Yang8f658732008-11-18 17:48:22 +0800221 (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
222 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800223 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +0800224 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800225 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
226
227 decode_address(buf, fp->retx);
Graf Yang8f658732008-11-18 17:48:22 +0800228 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800229 } else
230#endif
231 {
232 dump_bfin_process(fp);
233 dump_bfin_mem(fp);
234 show_regs(fp);
Robin Getza0cab652009-05-11 18:34:41 +0000235 dump_bfin_trace_buffer();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800236 }
Robin Getz9f06c382008-10-10 18:13:21 +0800237#endif
Mike Frysingerd8804ad2009-04-29 06:26:46 +0000238 panic("Double Fault - unrecoverable event");
Robin Getz2ebcade2007-10-09 17:24:30 +0800239
240}
241
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400242static int kernel_mode_regs(struct pt_regs *regs)
243{
244 return regs->ipend & 0xffc0;
245}
246
Bryan Wu1394f032007-05-06 14:50:22 -0700247asmlinkage void trap_c(struct pt_regs *fp)
248{
Robin Getz518039b2007-07-25 11:03:28 +0800249#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
250 int j;
251#endif
Graf Yang8f658732008-11-18 17:48:22 +0800252#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
253 unsigned int cpu = smp_processor_id();
254#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400255 const char *strerror = NULL;
Robin Getz518039b2007-07-25 11:03:28 +0800256 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700257 siginfo_t info;
258 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
259
Bryan Wu1394f032007-05-06 14:50:22 -0700260 trace_buffer_save(j);
Robin Getz81f7f452009-06-03 18:58:26 +0000261#if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
262 last_seqstat = (u32)fp->seqstat;
263#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700264
Robin Getz226eb1e2007-10-29 17:59:07 +0800265 /* Important - be very careful dereferncing pointers - will lead to
266 * double faults if the stack has become corrupt
267 */
268
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400269#ifndef CONFIG_KGDB
270 /* IPEND is skipped if KGDB isn't enabled (see entry code) */
271 fp->ipend = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800272#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800273
Bryan Wu1394f032007-05-06 14:50:22 -0700274 /* trap_c() will be called for exceptions. During exceptions
275 * processing, the pc value should be set with retx value.
276 * With this change we can cleanup some code in signal.c- TODO
277 */
278 fp->orig_pc = fp->retx;
279 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
280 trapnr, fp->ipend, fp->pc, fp->retx); */
281
282 /* send the appropriate signal to the user program */
283 switch (trapnr) {
284
285 /* This table works in conjuction with the one in ./mach-common/entry.S
286 * Some exceptions are handled there (in assembly, in exception space)
287 * Some are handled here, (in C, in interrupt space)
288 * Some, like CPLB, are handled in both, where the normal path is
289 * handled in assembly/exception space, and the error path is handled
290 * here
291 */
292
293 /* 0x00 - Linux Syscall, getting here is an error */
294 /* 0x01 - userspace gdb breakpoint, handled here */
295 case VEC_EXCPT01:
296 info.si_code = TRAP_ILLTRAP;
297 sig = SIGTRAP;
298 CHK_DEBUGGER_TRAP_MAYBE();
299 /* Check if this is a breakpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400300 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400301 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700302 else
303 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800304 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700305 case VEC_EXCPT03:
306 info.si_code = SEGV_STACKFLOW;
307 sig = SIGSEGV;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400308 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800309 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700310 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800311 /* 0x02 - KGDB initial connection and break signal trap */
312 case VEC_EXCPT02:
313#ifdef CONFIG_KGDB
314 info.si_code = TRAP_ILLTRAP;
315 sig = SIGTRAP;
316 CHK_DEBUGGER_TRAP();
Mike Frysinger6510a202009-06-07 15:07:25 -0400317 goto traps_done;
Sonic Zhang27707d32008-10-09 14:04:41 +0800318#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800319 /* 0x04 - User Defined */
320 /* 0x05 - User Defined */
321 /* 0x06 - User Defined */
322 /* 0x07 - User Defined */
323 /* 0x08 - User Defined */
324 /* 0x09 - User Defined */
325 /* 0x0A - User Defined */
326 /* 0x0B - User Defined */
327 /* 0x0C - User Defined */
328 /* 0x0D - User Defined */
329 /* 0x0E - User Defined */
330 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800331 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800332 * custom exception handler, and it is not actually installed properly
333 */
334 case VEC_EXCPT04 ... VEC_EXCPT15:
335 info.si_code = ILL_ILLPARAOP;
336 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400337 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
Robin Getz5c64e0d2008-10-08 14:43:47 +0800338 CHK_DEBUGGER_TRAP_MAYBE();
339 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700340 /* 0x10 HW Single step, handled here */
341 case VEC_STEP:
342 info.si_code = TRAP_STEP;
343 sig = SIGTRAP;
344 CHK_DEBUGGER_TRAP_MAYBE();
345 /* Check if this is a single step in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400346 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400347 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700348 else
349 break;
350 /* 0x11 - Trace Buffer Full, handled here */
351 case VEC_OVFLOW:
352 info.si_code = TRAP_TRACEFLOW;
353 sig = SIGTRAP;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400354 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800355 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700356 break;
357 /* 0x12 - Reserved, Caught by default */
358 /* 0x13 - Reserved, Caught by default */
359 /* 0x14 - Reserved, Caught by default */
360 /* 0x15 - Reserved, Caught by default */
361 /* 0x16 - Reserved, Caught by default */
362 /* 0x17 - Reserved, Caught by default */
363 /* 0x18 - Reserved, Caught by default */
364 /* 0x19 - Reserved, Caught by default */
365 /* 0x1A - Reserved, Caught by default */
366 /* 0x1B - Reserved, Caught by default */
367 /* 0x1C - Reserved, Caught by default */
368 /* 0x1D - Reserved, Caught by default */
369 /* 0x1E - Reserved, Caught by default */
370 /* 0x1F - Reserved, Caught by default */
371 /* 0x20 - Reserved, Caught by default */
372 /* 0x21 - Undefined Instruction, handled here */
373 case VEC_UNDEF_I:
Mike Frysinger70f12562009-06-07 17:18:25 -0400374#ifdef CONFIG_BUG
375 if (kernel_mode_regs(fp)) {
376 switch (report_bug(fp->pc, fp)) {
377 case BUG_TRAP_TYPE_NONE:
378 break;
379 case BUG_TRAP_TYPE_WARN:
380 dump_bfin_trace_buffer();
381 fp->pc += 2;
382 goto traps_done;
383 case BUG_TRAP_TYPE_BUG:
384 /* call to panic() will dump trace, and it is
385 * off at this point, so it won't be clobbered
386 */
387 panic("BUG()");
388 }
389 }
390#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700391 info.si_code = ILL_ILLOPC;
392 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400393 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800394 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700395 break;
396 /* 0x22 - Illegal Instruction Combination, handled here */
397 case VEC_ILGAL_I:
398 info.si_code = ILL_ILLPARAOP;
399 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400400 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800401 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700402 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800403 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700404 case VEC_CPLB_VL:
405 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800406 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400407 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800408 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700409 break;
410 /* 0x24 - Data access misaligned, handled here */
411 case VEC_MISALI_D:
412 info.si_code = BUS_ADRALN;
413 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400414 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800415 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700416 break;
417 /* 0x25 - Unrecoverable Event, handled here */
418 case VEC_UNCOV:
419 info.si_code = ILL_ILLEXCPT;
420 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400421 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800422 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700423 break;
424 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
425 error case is handled here */
426 case VEC_CPLB_M:
427 info.si_code = BUS_ADRALN;
428 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400429 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700430 break;
431 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
432 case VEC_CPLB_MHIT:
433 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700434 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800435#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800436 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400437 strerror = KERN_NOTICE "NULL pointer access\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800438 else
Bryan Wu1394f032007-05-06 14:50:22 -0700439#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400440 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800441 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700442 break;
443 /* 0x28 - Emulation Watchpoint, handled here */
444 case VEC_WATCH:
445 info.si_code = TRAP_WATCHPT;
446 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800447 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700448 CHK_DEBUGGER_TRAP_MAYBE();
449 /* Check if this is a watchpoint in kernel space */
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400450 if (kernel_mode_regs(fp))
Mike Frysinger6510a202009-06-07 15:07:25 -0400451 goto traps_done;
Bryan Wu1394f032007-05-06 14:50:22 -0700452 else
453 break;
454#ifdef CONFIG_BF535
455 /* 0x29 - Instruction fetch access error (535 only) */
456 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
457 info.si_code = BUS_OPFETCH;
458 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400459 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800460 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700461 break;
462#else
463 /* 0x29 - Reserved, Caught by default */
464#endif
465 /* 0x2A - Instruction fetch misaligned, handled here */
466 case VEC_MISALI_I:
467 info.si_code = BUS_ADRALN;
468 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400469 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800470 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700471 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800472 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700473 case VEC_CPLB_I_VL:
474 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800475 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400476 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800477 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700478 break;
479 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
480 case VEC_CPLB_I_M:
481 info.si_code = ILL_CPLB_MISS;
482 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400483 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
Bryan Wu1394f032007-05-06 14:50:22 -0700484 break;
485 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
486 case VEC_CPLB_I_MHIT:
487 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700488 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800489#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800490 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400491 strerror = KERN_NOTICE "Jump to NULL address\n";
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800492 else
Bryan Wu1394f032007-05-06 14:50:22 -0700493#endif
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400494 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800495 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700496 break;
497 /* 0x2E - Illegal use of Supervisor Resource, handled here */
498 case VEC_ILL_RES:
499 info.si_code = ILL_PRVOPC;
500 sig = SIGILL;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400501 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800502 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700503 break;
504 /* 0x2F - Reserved, Caught by default */
505 /* 0x30 - Reserved, Caught by default */
506 /* 0x31 - Reserved, Caught by default */
507 /* 0x32 - Reserved, Caught by default */
508 /* 0x33 - Reserved, Caught by default */
509 /* 0x34 - Reserved, Caught by default */
510 /* 0x35 - Reserved, Caught by default */
511 /* 0x36 - Reserved, Caught by default */
512 /* 0x37 - Reserved, Caught by default */
513 /* 0x38 - Reserved, Caught by default */
514 /* 0x39 - Reserved, Caught by default */
515 /* 0x3A - Reserved, Caught by default */
516 /* 0x3B - Reserved, Caught by default */
517 /* 0x3C - Reserved, Caught by default */
518 /* 0x3D - Reserved, Caught by default */
519 /* 0x3E - Reserved, Caught by default */
520 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800521 case VEC_HWERR:
522 info.si_code = BUS_ADRALN;
523 sig = SIGBUS;
524 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
525 /* System MMR Error */
526 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
527 info.si_code = BUS_ADRALN;
528 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400529 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800530 break;
531 /* External Memory Addressing Error */
532 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
533 info.si_code = BUS_ADRERR;
534 sig = SIGBUS;
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400535 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800536 break;
537 /* Performance Monitor Overflow */
538 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400539 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
Robin Getz13fe24f2008-01-27 15:38:56 +0800540 break;
541 /* RAISE 5 instruction */
542 case (SEQSTAT_HWERRCAUSE_RAISE_5):
543 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
544 break;
545 default: /* Reserved */
546 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
547 break;
548 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800549 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800550 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800551 /*
552 * We should be handling all known exception types above,
553 * if we get here we hit a reserved one, so panic
554 */
Bryan Wu1394f032007-05-06 14:50:22 -0700555 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800556 info.si_code = ILL_ILLPARAOP;
557 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800558 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700559 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800560 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700561 break;
562 }
563
Robin Getz226eb1e2007-10-29 17:59:07 +0800564 BUG_ON(sig == 0);
565
Mike Frysinger82bd1d72009-06-07 17:08:28 -0400566 /* If the fault was caused by a kernel thread, or interrupt handler
567 * we will kernel panic, so the system reboots.
568 */
569 if (kernel_mode_regs(fp) || (current && !current->mm)) {
570 console_verbose();
571 oops_in_progress = 1;
572 if (strerror)
573 verbose_printk(strerror);
574 }
575
Robin Getz226eb1e2007-10-29 17:59:07 +0800576 if (sig != SIGTRAP) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800577 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800578 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800579 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800580
581 /* Print out the trace buffer if it makes sense */
582#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
583 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800584 verbose_printk(KERN_NOTICE "No trace since you do not have "
Robin Getz226eb1e2007-10-29 17:59:07 +0800585 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
586 KERN_NOTICE "\n");
587 else
588#endif
589 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800590
Robin Getz226eb1e2007-10-29 17:59:07 +0800591 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800592 /* Dump the current kernel stack */
Robin Getz9f06c382008-10-10 18:13:21 +0800593 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800594 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800595 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800596#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800597 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800598 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800599#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700600 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800601 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800602#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800603 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800604 /* Dump the user space stack */
605 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800606 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800607 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800608#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800609 }
Bryan Wu1394f032007-05-06 14:50:22 -0700610 }
Robin Getzfb322912007-11-21 16:38:05 +0800611
Yi Li6a01f232009-01-07 23:14:39 +0800612#ifdef CONFIG_IPIPE
613 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
614#endif
615 {
616 info.si_signo = sig;
617 info.si_errno = 0;
618 info.si_addr = (void __user *)fp->pc;
619 force_sig_info(sig, &info, current);
620 }
Bryan Wu1394f032007-05-06 14:50:22 -0700621
Robin Getz0acad8d2009-05-11 18:55:16 +0000622 if (ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8))
623 fp->pc = SAFE_USER_INSTRUCTION;
624
Mike Frysinger6510a202009-06-07 15:07:25 -0400625 traps_done:
Bryan Wu1394f032007-05-06 14:50:22 -0700626 trace_buffer_restore(j);
Bryan Wu1394f032007-05-06 14:50:22 -0700627}
628
629/* Typical exception handling routines */
630
Robin Getz518039b2007-07-25 11:03:28 +0800631#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
632
Robin Getzf09630b2008-07-26 19:45:46 +0800633/*
634 * Similar to get_user, do some address checking, then dereference
635 * Return true on sucess, false on bad address
636 */
Robin Getz9f06c382008-10-10 18:13:21 +0800637static bool get_instruction(unsigned short *val, unsigned short *address)
Robin Getzf09630b2008-07-26 19:45:46 +0800638{
639
640 unsigned long addr;
641
642 addr = (unsigned long)address;
643
644 /* Check for odd addresses */
645 if (addr & 0x1)
646 return false;
647
648 /* Check that things do not wrap around */
649 if (addr > (addr + 2))
650 return false;
651
652 /*
653 * Since we are in exception context, we need to do a little address checking
654 * We need to make sure we are only accessing valid memory, and
655 * we don't read something in the async space that can hang forever
656 */
657 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800658#if L2_LENGTH != 0
Robin Getzf09630b2008-07-26 19:45:46 +0800659 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
660#endif
661 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
662#if L1_DATA_A_LENGTH != 0
663 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
664#endif
665#if L1_DATA_B_LENGTH != 0
666 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
667#endif
668 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
669 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
670 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
671 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
672 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
673 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
674 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
675 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
676 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
677 *val = *address;
678 return true;
679 }
680
681#if L1_CODE_LENGTH != 0
682 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
Robin Getz9df10282008-10-08 18:03:33 +0800683 isram_memcpy(val, address, 2);
Robin Getzf09630b2008-07-26 19:45:46 +0800684 return true;
685 }
686#endif
687
688
689 return false;
690}
691
Mike Frysinger36f649a2008-11-18 17:48:22 +0800692/*
Robin Getzd3d0ac22008-08-06 17:49:27 +0800693 * decode the instruction if we are printing out the trace, as it
694 * makes things easier to follow, without running it through objdump
695 * These are the normal instructions which cause change of flow, which
696 * would be at the source of the trace buffer
697 */
Mike Frysinger36f649a2008-11-18 17:48:22 +0800698#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
Robin Getz9f06c382008-10-10 18:13:21 +0800699static void decode_instruction(unsigned short *address)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800700{
701 unsigned short opcode;
702
703 if (get_instruction(&opcode, address)) {
704 if (opcode == 0x0010)
Robin Getz9f06c382008-10-10 18:13:21 +0800705 verbose_printk("RTS");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800706 else if (opcode == 0x0011)
Robin Getz9f06c382008-10-10 18:13:21 +0800707 verbose_printk("RTI");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800708 else if (opcode == 0x0012)
Robin Getz9f06c382008-10-10 18:13:21 +0800709 verbose_printk("RTX");
Robin Getz0be58932009-02-04 16:49:45 +0800710 else if (opcode == 0x0013)
711 verbose_printk("RTN");
712 else if (opcode == 0x0014)
713 verbose_printk("RTE");
714 else if (opcode == 0x0025)
715 verbose_printk("EMUEXCPT");
716 else if (opcode == 0x0040 && opcode <= 0x0047)
717 verbose_printk("STI R%i", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800718 else if (opcode >= 0x0050 && opcode <= 0x0057)
Robin Getz9f06c382008-10-10 18:13:21 +0800719 verbose_printk("JUMP (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800720 else if (opcode >= 0x0060 && opcode <= 0x0067)
Robin Getz9f06c382008-10-10 18:13:21 +0800721 verbose_printk("CALL (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800722 else if (opcode >= 0x0070 && opcode <= 0x0077)
Robin Getz9f06c382008-10-10 18:13:21 +0800723 verbose_printk("CALL (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800724 else if (opcode >= 0x0080 && opcode <= 0x0087)
Robin Getz9f06c382008-10-10 18:13:21 +0800725 verbose_printk("JUMP (PC+P%i)", opcode & 7);
Robin Getz0be58932009-02-04 16:49:45 +0800726 else if (opcode >= 0x0090 && opcode <= 0x009F)
727 verbose_printk("RAISE 0x%x", opcode & 0xF);
728 else if (opcode >= 0x00A0 && opcode <= 0x00AF)
729 verbose_printk("EXCPT 0x%x", opcode & 0xF);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800730 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
Robin Getz9f06c382008-10-10 18:13:21 +0800731 verbose_printk("IF !CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800732 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
Robin Getz9f06c382008-10-10 18:13:21 +0800733 verbose_printk("IF CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800734 else if (opcode >= 0x2000 && opcode <= 0x2fff)
Robin Getz9f06c382008-10-10 18:13:21 +0800735 verbose_printk("JUMP.S");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800736 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800737 verbose_printk("LSETUP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800738 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800739 verbose_printk("JUMP.L");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800740 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800741 verbose_printk("CALL pcrel");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800742 else
Robin Getz9f06c382008-10-10 18:13:21 +0800743 verbose_printk("0x%04x", opcode);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800744 }
745
746}
Robin Getz9f06c382008-10-10 18:13:21 +0800747#endif
Robin Getzd3d0ac22008-08-06 17:49:27 +0800748
Bryan Wu1394f032007-05-06 14:50:22 -0700749void dump_bfin_trace_buffer(void)
750{
Robin Getz9f06c382008-10-10 18:13:21 +0800751#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz518039b2007-07-25 11:03:28 +0800752#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
753 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800754 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800755 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800756#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
757 int j, index;
758#endif
759
Bryan Wu1394f032007-05-06 14:50:22 -0700760 trace_buffer_save(tflags);
761
Robin Getz226eb1e2007-10-29 17:59:07 +0800762 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800763
Robin Getzd3d0ac22008-08-06 17:49:27 +0800764#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
765 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
766#endif
767
Bryan Wu1394f032007-05-06 14:50:22 -0700768 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800769 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800770 decode_address(buf, (unsigned long)bfin_read_TBUF());
771 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800772 addr = (unsigned short *)bfin_read_TBUF();
773 decode_address(buf, (unsigned long)addr);
774 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800775 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800776 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700777 }
778 }
779
Robin Getz518039b2007-07-25 11:03:28 +0800780#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
781 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800782 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800783 else
784 index = EXPAND_LEN;
785
786 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
787 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800788 decode_address(buf, software_trace_buff[index]);
789 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800790 index -= 1;
791 if (index < 0 )
792 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800793 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800794 printk(KERN_NOTICE " Source : %s ", buf);
795 decode_instruction((unsigned short *)software_trace_buff[index]);
796 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800797 index -= 1;
798 if (index < 0)
799 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800800 j--;
801 i++;
802 }
803#endif
804
Bryan Wu1394f032007-05-06 14:50:22 -0700805 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800806#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800807#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700808}
809EXPORT_SYMBOL(dump_bfin_trace_buffer);
810
Mike Frysinger70f12562009-06-07 17:18:25 -0400811#ifdef CONFIG_BUG
812int is_valid_bugaddr(unsigned long addr)
813{
814 unsigned short opcode;
815
816 if (!get_instruction(&opcode, (unsigned short *)addr))
817 return 0;
818
819 return opcode == BFIN_BUG_OPCODE;
820}
821#endif
822
Robin Getzf09630b2008-07-26 19:45:46 +0800823/*
824 * Checks to see if the address pointed to is either a
825 * 16-bit CALL instruction, or a 32-bit CALL instruction
826 */
Robin Getz9f06c382008-10-10 18:13:21 +0800827static bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700828{
Robin Getzf09630b2008-07-26 19:45:46 +0800829 unsigned short opcode = 0, *ins_addr;
830 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700831
Robin Getzf09630b2008-07-26 19:45:46 +0800832 if (!get_instruction(&opcode, ins_addr))
833 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700834
Robin Getzf09630b2008-07-26 19:45:46 +0800835 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
836 (opcode >= 0x0070 && opcode <= 0x0077))
837 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700838
Robin Getzf09630b2008-07-26 19:45:46 +0800839 ins_addr--;
840 if (!get_instruction(&opcode, ins_addr))
841 return false;
842
843 if (opcode >= 0xE300 && opcode <= 0xE3FF)
844 return true;
845
846 return false;
847
Bryan Wu1394f032007-05-06 14:50:22 -0700848}
Robin Getz9f06c382008-10-10 18:13:21 +0800849
Bryan Wu1394f032007-05-06 14:50:22 -0700850void show_stack(struct task_struct *task, unsigned long *stack)
851{
Robin Getz9f06c382008-10-10 18:13:21 +0800852#ifdef CONFIG_PRINTK
Robin Getzf09630b2008-07-26 19:45:46 +0800853 unsigned int *addr, *endstack, *fp = 0, *frame;
854 unsigned short *ins_addr;
855 char buf[150];
856 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700857
Robin Getzf09630b2008-07-26 19:45:46 +0800858 /*
859 * If we have been passed a specific stack, use that one otherwise
860 * if we have been passed a task structure, use that, otherwise
861 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700862 */
863
Robin Getzf09630b2008-07-26 19:45:46 +0800864 if (stack == NULL) {
865 if (task) {
866 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700867 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800868 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
869 } else {
870 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700871 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800872 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
873 }
874 } else
875 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
876
Robin Getz9f06c382008-10-10 18:13:21 +0800877 printk(KERN_NOTICE "Stack info:\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800878 decode_address(buf, (unsigned int)stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800879 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
880
Robin Getza0cab652009-05-11 18:34:41 +0000881 if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
882 printk(KERN_NOTICE "Invalid stack pointer\n");
883 return;
884 }
885
Robin Getzf09630b2008-07-26 19:45:46 +0800886 /* First thing is to look for a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800887 for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
Robin Getzf09630b2008-07-26 19:45:46 +0800888 if (*addr & 0x1)
889 continue;
890 ins_addr = (unsigned short *)*addr;
891 ins_addr--;
892 if (is_bfin_call(ins_addr))
893 fp = addr - 1;
894
895 if (fp) {
896 /* Let's check to see if it is a frame pointer */
Jie Zhang881eb622009-02-04 16:49:45 +0800897 while (fp >= (addr - 1) && fp < endstack
898 && fp && ((unsigned int) fp & 0x3) == 0)
Robin Getzf09630b2008-07-26 19:45:46 +0800899 fp = (unsigned int *)*fp;
900 if (fp == 0 || fp == endstack) {
901 fp = addr - 1;
902 break;
903 }
904 fp = 0;
905 }
906 }
907 if (fp) {
908 frame = fp;
Jie Zhangb339dc72009-01-07 23:14:39 +0800909 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
Robin Getzf09630b2008-07-26 19:45:46 +0800910 } else
911 frame = 0;
912
913 /*
914 * Now that we think we know where things are, we
915 * walk the stack again, this time printing things out
916 * incase there is no frame pointer, we still look for
917 * valid return addresses
918 */
919
920 /* First time print out data, next time, print out symbols */
921 for (j = 0; j <= 1; j++) {
922 if (j)
923 printk(KERN_NOTICE "Return addresses in stack:\n");
924 else
925 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
926
927 fp = frame;
928 frame_no = 0;
929
930 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
931 addr <= endstack; addr++, i++) {
932
933 ret_addr = 0;
934 if (!j && i % 8 == 0)
935 printk("\n" KERN_NOTICE "%p:",addr);
936
937 /* if it is an odd address, or zero, just skip it */
938 if (*addr & 0x1 || !*addr)
939 goto print;
940
941 ins_addr = (unsigned short *)*addr;
942
943 /* Go back one instruction, and see if it is a CALL */
944 ins_addr--;
945 ret_addr = is_bfin_call(ins_addr);
946 print:
947 if (!j && stack == (unsigned long *)addr)
948 printk("[%08x]", *addr);
949 else if (ret_addr)
950 if (j) {
951 decode_address(buf, (unsigned int)*addr);
952 if (frame == addr) {
953 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
954 continue;
955 }
956 printk(KERN_NOTICE " address : %s\n", buf);
957 } else
958 printk("<%08x>", *addr);
959 else if (fp == addr) {
960 if (j)
961 frame = addr+1;
962 else
963 printk("(%08x)", *addr);
964
965 fp = (unsigned int *)*addr;
966 frame_no++;
967
968 } else if (!j)
969 printk(" %08x ", *addr);
970 }
971 if (!j)
972 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700973 }
Robin Getz9f06c382008-10-10 18:13:21 +0800974#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700975}
976
977void dump_stack(void)
978{
979 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800980#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700981 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800982#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700983 trace_buffer_save(tflags);
984 dump_bfin_trace_buffer();
985 show_stack(current, &stack);
986 trace_buffer_restore(tflags);
987}
Bryan Wu1394f032007-05-06 14:50:22 -0700988EXPORT_SYMBOL(dump_stack);
989
Mike Frysinger49dce912007-11-21 16:46:49 +0800990void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700991{
Robin Getz9f06c382008-10-10 18:13:21 +0800992#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +0800993 /* We should be able to look at fp->ipend, but we don't push it on the
994 * stack all the time, so do this until we fix that */
995 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800996
Mike Frysinger49dce912007-11-21 16:46:49 +0800997 if (oops_in_progress)
Robin Getz9f06c382008-10-10 18:13:21 +0800998 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800999
Robin Getzb03b08b2007-12-23 22:57:01 +08001000 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
Robin Getz9f06c382008-10-10 18:13:21 +08001001 verbose_printk(KERN_NOTICE "HW Error context\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001002 else if (context & 0x0020)
Robin Getz9f06c382008-10-10 18:13:21 +08001003 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001004 else if (context & 0x3FC0)
Robin Getz9f06c382008-10-10 18:13:21 +08001005 verbose_printk(KERN_NOTICE "Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001006 else if (context & 0x4000)
Robin Getz9f06c382008-10-10 18:13:21 +08001007 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001008 else if (context & 0x8000)
Robin Getz9f06c382008-10-10 18:13:21 +08001009 verbose_printk(KERN_NOTICE "Kernel process context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001010
Robin Getz9a62ca42008-03-26 09:15:58 +08001011 /* Because we are crashing, and pointers could be bad, we check things
1012 * pretty closely before we use them
1013 */
Robin Getz7f1c9062008-04-25 03:36:31 +08001014 if ((unsigned long)current >= FIXED_CODE_START &&
1015 !((unsigned long)current & 0x3) && current->pid) {
Robin Getz9f06c382008-10-10 18:13:21 +08001016 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +08001017 if (current->comm >= (char *)FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +08001018 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
Robin Getz9a62ca42008-03-26 09:15:58 +08001019 current->comm, current->pid);
1020 else
Robin Getz9f06c382008-10-10 18:13:21 +08001021 verbose_printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001022
Graf Yang8f658732008-11-18 17:48:22 +08001023 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
Robin Getz9a62ca42008-03-26 09:15:58 +08001024 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +08001025 verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
Robin Getz9a62ca42008-03-26 09:15:58 +08001026 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
1027 KERN_NOTICE "\n",
1028 (void *)current->mm->start_code,
1029 (void *)current->mm->end_code,
1030 (void *)current->mm->start_data,
1031 (void *)current->mm->end_data,
1032 (void *)current->mm->end_data,
1033 (void *)current->mm->brk,
1034 (void *)current->mm->start_stack);
1035 else
Robin Getz9f06c382008-10-10 18:13:21 +08001036 verbose_printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +08001037 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001038 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
Mike Frysinger49dce912007-11-21 16:46:49 +08001039 "No Valid process in current context\n");
Robin Getz9f06c382008-10-10 18:13:21 +08001040#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001041}
1042
Robin Getzb03b08b2007-12-23 22:57:01 +08001043void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +08001044{
Robin Getz9f06c382008-10-10 18:13:21 +08001045#ifdef CONFIG_DEBUG_VERBOSE
Robin Getzb03b08b2007-12-23 22:57:01 +08001046 unsigned short *addr, *erraddr, val = 0, err = 0;
1047 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -07001048
Bernd Schmidt5d750b92008-04-25 05:02:33 +08001049 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +08001050
Robin Getz9f06c382008-10-10 18:13:21 +08001051 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001052
1053 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
1054 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
1055 addr++) {
1056 if (!((unsigned long)addr & 0xF))
Robin Getz9f06c382008-10-10 18:13:21 +08001057 verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
Robin Getzb03b08b2007-12-23 22:57:01 +08001058
Robin Getz7d98c882008-10-08 16:29:01 +08001059 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +08001060 val = 0;
1061 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +08001062 } else
1063 sprintf(buf, "%04x", val);
1064
1065 if (addr == erraddr) {
Robin Getz9f06c382008-10-10 18:13:21 +08001066 verbose_printk("[%s]", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001067 err = val;
1068 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001069 verbose_printk(" %s ", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001070
1071 /* Do any previous instructions turn on interrupts? */
1072 if (addr <= erraddr && /* in the past */
1073 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1074 val == 0x017b)) /* [SP++] = RETI */
1075 sti = 1;
1076 }
1077
Robin Getz9f06c382008-10-10 18:13:21 +08001078 verbose_printk("\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001079
1080 /* Hardware error interrupts can be deferred */
1081 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1082 oops_in_progress)){
Robin Getz9f06c382008-10-10 18:13:21 +08001083 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001084#ifndef CONFIG_DEBUG_HWERR
Robin Getz9f06c382008-10-10 18:13:21 +08001085 verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
Robin Getzb03b08b2007-12-23 22:57:01 +08001086 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
1087 " better idea where it came from\n");
1088#else
1089 /* If we are handling only one peripheral interrupt
1090 * and current mm and pid are valid, and the last error
1091 * was in that user space process's text area
1092 * print it out - because that is where the problem exists
1093 */
1094 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1095 (current->pid && current->mm)) {
1096 /* And the last RETI points to the current userspace context */
1097 if ((fp + 1)->pc >= current->mm->start_code &&
1098 (fp + 1)->pc <= current->mm->end_code) {
Robin Getz9f06c382008-10-10 18:13:21 +08001099 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1100 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001101 show_regs(fp + 1);
Robin Getz9f06c382008-10-10 18:13:21 +08001102 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001103 }
Bryan Wu1394f032007-05-06 14:50:22 -07001104 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001105#endif
1106 }
Robin Getz9f06c382008-10-10 18:13:21 +08001107#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001108}
1109
1110void show_regs(struct pt_regs *fp)
1111{
Robin Getz9f06c382008-10-10 18:13:21 +08001112#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001113 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001114 struct irqaction *action;
1115 unsigned int i;
Robin Getz2f95d5b2009-02-04 16:49:45 +08001116 unsigned long flags = 0;
Graf Yang8f658732008-11-18 17:48:22 +08001117 unsigned int cpu = smp_processor_id();
Robin Getz2f95d5b2009-02-04 16:49:45 +08001118 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -07001119
Robin Getz9ba3c242009-05-20 21:19:21 +00001120 verbose_printk(KERN_NOTICE "\n");
1121 if (CPUID != bfin_cpuid())
1122 verbose_printk(KERN_NOTICE "Compiled for cpu family 0x%04x (Rev %d), "
1123 "but running on:0x%04x (Rev %d)\n",
1124 CPUID, bfin_compiled_revid(), bfin_cpuid(), bfin_revid());
1125
1126 verbose_printk(KERN_NOTICE "ADSP-%s-0.%d",
1127 CPU, bfin_compiled_revid());
1128
1129 if (bfin_compiled_revid() != bfin_revid())
1130 verbose_printk("(Detected 0.%d)", bfin_revid());
1131
1132 verbose_printk(" %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n",
1133 get_cclk()/1000000, get_sclk()/1000000,
1134#ifdef CONFIG_MPU
1135 "mpu on"
1136#else
1137 "mpu off"
1138#endif
1139 );
1140
1141 verbose_printk(KERN_NOTICE "%s", linux_banner);
1142
Robin Getz9f06c382008-10-10 18:13:21 +08001143 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
1144 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001145 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001146 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001147 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001148 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1149#ifdef EBIU_ERRMST
1150 /* If the error was from the EBIU, print it out */
1151 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001152 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001153 bfin_read_EBIU_ERRMST());
Robin Getz9f06c382008-10-10 18:13:21 +08001154 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001155 bfin_read_EBIU_ERRADD());
1156 }
1157#endif
1158 }
Robin Getz9f06c382008-10-10 18:13:21 +08001159 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
Robin Getz13fe24f2008-01-27 15:38:56 +08001160 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getz2f95d5b2009-02-04 16:49:45 +08001161 for (i = 2; i <= 15 ; i++) {
Robin Getzd8f66c82007-12-24 15:27:56 +08001162 if (fp->ipend & (1 << i)) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001163 if (i != 4) {
1164 decode_address(buf, bfin_read32(EVT0 + 4*i));
1165 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1166 } else
1167 verbose_printk(KERN_NOTICE " interrupts disabled\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001168 }
1169 }
1170
1171 /* if no interrupts are going off, don't print this out */
1172 if (fp->ipend & ~0x3F) {
1173 for (i = 0; i < (NR_IRQS - 1); i++) {
Robin Getz2f95d5b2009-02-04 16:49:45 +08001174 if (!in_atomic)
1175 spin_lock_irqsave(&irq_desc[i].lock, flags);
1176
Robin Getzd8f66c82007-12-24 15:27:56 +08001177 action = irq_desc[i].action;
1178 if (!action)
1179 goto unlock;
1180
1181 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001182 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001183 for (action = action->next; action; action = action->next) {
1184 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001185 verbose_printk(", %s", buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001186 }
Robin Getz9f06c382008-10-10 18:13:21 +08001187 verbose_printk("\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001188unlock:
Robin Getz2f95d5b2009-02-04 16:49:45 +08001189 if (!in_atomic)
1190 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Robin Getzd8f66c82007-12-24 15:27:56 +08001191 }
1192 }
Bryan Wu1394f032007-05-06 14:50:22 -07001193
Robin Getz226eb1e2007-10-29 17:59:07 +08001194 decode_address(buf, fp->rete);
Robin Getz9f06c382008-10-10 18:13:21 +08001195 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001196 decode_address(buf, fp->retn);
Robin Getz9f06c382008-10-10 18:13:21 +08001197 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001198 decode_address(buf, fp->retx);
Robin Getz9f06c382008-10-10 18:13:21 +08001199 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001200 decode_address(buf, fp->rets);
Robin Getz9f06c382008-10-10 18:13:21 +08001201 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001202 decode_address(buf, fp->pc);
Robin Getz9f06c382008-10-10 18:13:21 +08001203 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001204
Robin Getz13fe24f2008-01-27 15:38:56 +08001205 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1206 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Graf Yang8f658732008-11-18 17:48:22 +08001207 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001208 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +08001209 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001210 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001211 }
1212
Robin Getz9f06c382008-10-10 18:13:21 +08001213 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1214 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001215 fp->r0, fp->r1, fp->r2, fp->r3);
Robin Getz9f06c382008-10-10 18:13:21 +08001216 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001217 fp->r4, fp->r5, fp->r6, fp->r7);
Robin Getz9f06c382008-10-10 18:13:21 +08001218 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001219 fp->p0, fp->p1, fp->p2, fp->p3);
Robin Getz9f06c382008-10-10 18:13:21 +08001220 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001221 fp->p4, fp->p5, fp->fp, (long)fp);
Robin Getz9f06c382008-10-10 18:13:21 +08001222 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001223 fp->lb0, fp->lt0, fp->lc0);
Robin Getz9f06c382008-10-10 18:13:21 +08001224 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001225 fp->lb1, fp->lt1, fp->lc1);
Robin Getz9f06c382008-10-10 18:13:21 +08001226 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001227 fp->b0, fp->l0, fp->m0, fp->i0);
Robin Getz9f06c382008-10-10 18:13:21 +08001228 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001229 fp->b1, fp->l1, fp->m1, fp->i1);
Robin Getz9f06c382008-10-10 18:13:21 +08001230 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001231 fp->b2, fp->l2, fp->m2, fp->i2);
Robin Getz9f06c382008-10-10 18:13:21 +08001232 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001233 fp->b3, fp->l3, fp->m3, fp->i3);
Robin Getz9f06c382008-10-10 18:13:21 +08001234 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001235 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1236
Robin Getz9f06c382008-10-10 18:13:21 +08001237 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001238 rdusp(), fp->astat);
1239
Robin Getz9f06c382008-10-10 18:13:21 +08001240 verbose_printk(KERN_NOTICE "\n");
1241#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001242}
1243
1244#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1245asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1246#endif
1247
Graf Yang8f658732008-11-18 17:48:22 +08001248static DEFINE_SPINLOCK(bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001249
Graf Yang8f658732008-11-18 17:48:22 +08001250asmlinkage int sys_bfin_spinlock(int *p)
1251{
1252 int ret, tmp = 0;
1253
1254 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1255 ret = get_user(tmp, p);
1256 if (likely(ret == 0)) {
1257 if (unlikely(tmp))
Bryan Wu1394f032007-05-06 14:50:22 -07001258 ret = 1;
Graf Yang8f658732008-11-18 17:48:22 +08001259 else
1260 put_user(1, p);
Bryan Wu1394f032007-05-06 14:50:22 -07001261 }
Graf Yang8f658732008-11-18 17:48:22 +08001262 spin_unlock(&bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001263 return ret;
1264}
1265
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001266int bfin_request_exception(unsigned int exception, void (*handler)(void))
1267{
1268 void (*curr_handler)(void);
1269
1270 if (exception > 0x3F)
1271 return -EINVAL;
1272
1273 curr_handler = ex_table[exception];
1274
1275 if (curr_handler != ex_replaceable)
1276 return -EBUSY;
1277
1278 ex_table[exception] = handler;
1279
1280 return 0;
1281}
1282EXPORT_SYMBOL(bfin_request_exception);
1283
1284int bfin_free_exception(unsigned int exception, void (*handler)(void))
1285{
1286 void (*curr_handler)(void);
1287
1288 if (exception > 0x3F)
1289 return -EINVAL;
1290
1291 curr_handler = ex_table[exception];
1292
1293 if (curr_handler != handler)
1294 return -EBUSY;
1295
1296 ex_table[exception] = ex_replaceable;
1297
1298 return 0;
1299}
1300EXPORT_SYMBOL(bfin_free_exception);
1301
Bryan Wu1394f032007-05-06 14:50:22 -07001302void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1303{
1304 switch (cplb_panic) {
1305 case CPLB_NO_UNLOCKED:
1306 printk(KERN_EMERG "All CPLBs are locked\n");
1307 break;
1308 case CPLB_PROT_VIOL:
1309 return;
1310 case CPLB_NO_ADDR_MATCH:
1311 return;
1312 case CPLB_UNKNOWN_ERR:
1313 printk(KERN_EMERG "Unknown CPLB Exception\n");
1314 break;
1315 }
1316
Robin Getz226eb1e2007-10-29 17:59:07 +08001317 oops_in_progress = 1;
1318
Mike Frysinger49dce912007-11-21 16:46:49 +08001319 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001320 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001321 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001322 dump_stack();
Mike Frysingerd8804ad2009-04-29 06:26:46 +00001323 panic("Unrecoverable event");
Bryan Wu1394f032007-05-06 14:50:22 -07001324}