blob: 17d8e4172896c6dabfe3e48eb122b6e517d0435f [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/kernel/traps.c
3 * Based on:
4 * Author: Hamish Macdonald
5 *
6 * Created:
7 * Description: uses S/W interrupt 15 for the system calls
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080030#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -070031#include <linux/interrupt.h>
32#include <linux/module.h>
33#include <linux/kallsyms.h>
Bryan Wud31c5ab2007-08-10 13:00:42 -070034#include <linux/fs.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080035#include <asm/traps.h>
36#include <asm/cacheflush.h>
Mike Frysingerf4585a02008-10-13 14:45:21 +080037#include <asm/cplb.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080038#include <asm/blackfin.h>
39#include <asm/irq_handler.h>
Robin Getzd8f66c82007-12-24 15:27:56 +080040#include <linux/irq.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080041#include <asm/trace.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080042#include <asm/fixed_code.h>
Bryan Wu1394f032007-05-06 14:50:22 -070043
44#ifdef CONFIG_KGDB
Bryan Wu1394f032007-05-06 14:50:22 -070045# include <linux/kgdb.h>
Robin Getz226eb1e2007-10-29 17:59:07 +080046
47# define CHK_DEBUGGER_TRAP() \
48 do { \
Sonic Zhanga5ac0122008-10-13 14:07:19 +080049 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
Robin Getz226eb1e2007-10-29 17:59:07 +080050 } while (0)
51# define CHK_DEBUGGER_TRAP_MAYBE() \
52 do { \
53 if (kgdb_connected) \
54 CHK_DEBUGGER_TRAP(); \
55 } while (0)
56#else
57# define CHK_DEBUGGER_TRAP() do { } while (0)
58# define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070059#endif
60
Robin Getz9f06c382008-10-10 18:13:21 +080061
Robin Getz4ee1c452008-10-28 11:36:11 +080062#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +080063#define verbose_printk(fmt, arg...) \
64 printk(fmt, ##arg)
65#else
66#define verbose_printk(fmt, arg...) \
67 ({ if (0) printk(fmt, ##arg); 0; })
68#endif
69
Bryan Wu1394f032007-05-06 14:50:22 -070070/* Initiate the event table handler */
71void __init trap_init(void)
72{
73 CSYNC();
74 bfin_write_EVT3(trap);
75 CSYNC();
76}
77
Robin Getz226eb1e2007-10-29 17:59:07 +080078static void decode_address(char *buf, unsigned long address)
Bryan Wu1394f032007-05-06 14:50:22 -070079{
Robin Getz9f06c382008-10-10 18:13:21 +080080#ifdef CONFIG_DEBUG_VERBOSE
Bryan Wu1394f032007-05-06 14:50:22 -070081 struct vm_list_struct *vml;
82 struct task_struct *p;
83 struct mm_struct *mm;
Robin Getz885be032007-10-29 17:20:41 +080084 unsigned long flags, offset;
Robin Getz904656c2008-03-26 09:17:43 +080085 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
Bryan Wu1394f032007-05-06 14:50:22 -070086
87#ifdef CONFIG_KALLSYMS
Mike Frysinger8a0e6652007-05-21 18:09:19 +080088 unsigned long symsize;
Bryan Wu1394f032007-05-06 14:50:22 -070089 const char *symname;
90 char *modname;
91 char *delim = ":";
92 char namebuf[128];
93
94 /* look up the address and see if we are in kernel space */
95 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
96
97 if (symname) {
98 /* yeah! kernel space! */
99 if (!modname)
100 modname = delim = "";
Robin Getz226eb1e2007-10-29 17:59:07 +0800101 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800102 (void *)address, delim, modname, delim, symname,
Bryan Wu1394f032007-05-06 14:50:22 -0700103 (unsigned long)offset);
Robin Getz885be032007-10-29 17:20:41 +0800104 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700105
106 }
107#endif
108
Robin Getz226eb1e2007-10-29 17:59:07 +0800109 /* Problem in fixed code section? */
110 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
111 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
112 return;
113 }
114
115 /* Problem somewhere before the kernel start address */
116 if (address < CONFIG_BOOT_LOAD) {
117 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
118 return;
119 }
120
Bryan Wu1394f032007-05-06 14:50:22 -0700121 /* looks like we're off in user-land, so let's walk all the
122 * mappings of all our processes and see if we can't be a whee
123 * bit more specific
124 */
Robin Getz885be032007-10-29 17:20:41 +0800125 write_lock_irqsave(&tasklist_lock, flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700126 for_each_process(p) {
Robin Getz904656c2008-03-26 09:17:43 +0800127 mm = (in_atomic ? p->mm : get_task_mm(p));
Bryan Wu1394f032007-05-06 14:50:22 -0700128 if (!mm)
129 continue;
130
131 vml = mm->context.vmlist;
132 while (vml) {
133 struct vm_area_struct *vma = vml->vma;
134
135 if (address >= vma->vm_start && address < vma->vm_end) {
Jan Blunckcf28b482008-02-14 19:38:44 -0800136 char _tmpbuf[256];
Bryan Wu1394f032007-05-06 14:50:22 -0700137 char *name = p->comm;
138 struct file *file = vma->vm_file;
Jan Blunckcf28b482008-02-14 19:38:44 -0800139
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800140 if (file) {
141 char *d_name = d_path(&file->f_path, _tmpbuf,
Jan Blunckcf28b482008-02-14 19:38:44 -0800142 sizeof(_tmpbuf));
Tim Pepper6a0bfff2008-10-27 12:18:36 +0800143 if (!IS_ERR(d_name))
144 name = d_name;
145 }
Bryan Wu1394f032007-05-06 14:50:22 -0700146
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800147 /* FLAT does not have its text aligned to the start of
148 * the map while FDPIC ELF does ...
149 */
Mike Frysinger8a0e6652007-05-21 18:09:19 +0800150
Robin Getz7f1c9062008-04-25 03:36:31 +0800151 /* before we can check flat/fdpic, we need to
152 * make sure current is valid
153 */
154 if ((unsigned long)current >= FIXED_CODE_START &&
155 !((unsigned long)current & 0x3)) {
156 if (current->mm &&
157 (address > current->mm->start_code) &&
158 (address < current->mm->end_code))
159 offset = address - current->mm->start_code;
160 else
161 offset = (address - vma->vm_start) +
162 (vma->vm_pgoff << PAGE_SHIFT);
163
164 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
165 (void *)address, name, offset);
166 } else
167 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
168 (void *)address, name,
169 vma->vm_start, vma->vm_end);
170
Robin Getz904656c2008-03-26 09:17:43 +0800171 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800172 mmput(mm);
Robin Getz7f1c9062008-04-25 03:36:31 +0800173
Robin Getzf09630b2008-07-26 19:45:46 +0800174 if (!strlen(buf))
175 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
176
Robin Getz885be032007-10-29 17:20:41 +0800177 goto done;
Bryan Wu1394f032007-05-06 14:50:22 -0700178 }
179
180 vml = vml->next;
181 }
Robin Getz904656c2008-03-26 09:17:43 +0800182 if (!in_atomic)
Robin Getz885be032007-10-29 17:20:41 +0800183 mmput(mm);
Bryan Wu1394f032007-05-06 14:50:22 -0700184 }
Bryan Wu1394f032007-05-06 14:50:22 -0700185
186 /* we were unable to find this address anywhere */
Robin Getzf09630b2008-07-26 19:45:46 +0800187 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
Robin Getz885be032007-10-29 17:20:41 +0800188
189done:
190 write_unlock_irqrestore(&tasklist_lock, flags);
Robin Getz9f06c382008-10-10 18:13:21 +0800191#else
192 sprintf(buf, " ");
193#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700194}
195
Robin Getz2ebcade2007-10-09 17:24:30 +0800196asmlinkage void double_fault_c(struct pt_regs *fp)
197{
Robin Getz226eb1e2007-10-29 17:59:07 +0800198 console_verbose();
199 oops_in_progress = 1;
Robin Getz9f06c382008-10-10 18:13:21 +0800200#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz2ebcade2007-10-09 17:24:30 +0800201 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
Robin Getz0c7a6b22008-10-08 16:27:12 +0800202#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
203 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
Graf Yang8f658732008-11-18 17:48:22 +0800204 unsigned int cpu = smp_processor_id();
Robin Getz0c7a6b22008-10-08 16:27:12 +0800205 char buf[150];
Graf Yang8f658732008-11-18 17:48:22 +0800206 decode_address(buf, cpu_pda[cpu].retx);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800207 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
Graf Yang8f658732008-11-18 17:48:22 +0800208 (unsigned int)cpu_pda[cpu].seqstat & SEQSTAT_EXCAUSE, buf);
209 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800210 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +0800211 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800212 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
213
214 decode_address(buf, fp->retx);
Graf Yang8f658732008-11-18 17:48:22 +0800215 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
Robin Getz0c7a6b22008-10-08 16:27:12 +0800216 } else
217#endif
218 {
219 dump_bfin_process(fp);
220 dump_bfin_mem(fp);
221 show_regs(fp);
222 }
Robin Getz9f06c382008-10-10 18:13:21 +0800223#endif
Robin Getz2ebcade2007-10-09 17:24:30 +0800224 panic("Double Fault - unrecoverable event\n");
225
226}
227
Bryan Wu1394f032007-05-06 14:50:22 -0700228asmlinkage void trap_c(struct pt_regs *fp)
229{
Robin Getz518039b2007-07-25 11:03:28 +0800230#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
231 int j;
232#endif
Graf Yang8f658732008-11-18 17:48:22 +0800233#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
234 unsigned int cpu = smp_processor_id();
235#endif
Robin Getz518039b2007-07-25 11:03:28 +0800236 int sig = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700237 siginfo_t info;
238 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
239
Bryan Wu1394f032007-05-06 14:50:22 -0700240 trace_buffer_save(j);
241
Robin Getz226eb1e2007-10-29 17:59:07 +0800242 /* Important - be very careful dereferncing pointers - will lead to
243 * double faults if the stack has become corrupt
244 */
245
246 /* If the fault was caused by a kernel thread, or interrupt handler
247 * we will kernel panic, so the system reboots.
248 * If KGDB is enabled, don't set this for kernel breakpoints
249 */
Robin Getzb03b08b2007-12-23 22:57:01 +0800250
251 /* TODO: check to see if we are in some sort of deferred HWERR
252 * that we should be able to recover from, not kernel panic
253 */
Robin Getz6b5eace2008-01-10 17:57:56 +0800254 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
Robin Getz226eb1e2007-10-29 17:59:07 +0800255#ifdef CONFIG_KGDB
Robin Getz6b5eace2008-01-10 17:57:56 +0800256 && (trapnr != VEC_EXCPT02)
Robin Getz226eb1e2007-10-29 17:59:07 +0800257#endif
258 ){
259 console_verbose();
260 oops_in_progress = 1;
261 } else if (current) {
262 if (current->mm == NULL) {
263 console_verbose();
264 oops_in_progress = 1;
265 }
266 }
267
Bryan Wu1394f032007-05-06 14:50:22 -0700268 /* trap_c() will be called for exceptions. During exceptions
269 * processing, the pc value should be set with retx value.
270 * With this change we can cleanup some code in signal.c- TODO
271 */
272 fp->orig_pc = fp->retx;
273 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
274 trapnr, fp->ipend, fp->pc, fp->retx); */
275
276 /* send the appropriate signal to the user program */
277 switch (trapnr) {
278
279 /* This table works in conjuction with the one in ./mach-common/entry.S
280 * Some exceptions are handled there (in assembly, in exception space)
281 * Some are handled here, (in C, in interrupt space)
282 * Some, like CPLB, are handled in both, where the normal path is
283 * handled in assembly/exception space, and the error path is handled
284 * here
285 */
286
287 /* 0x00 - Linux Syscall, getting here is an error */
288 /* 0x01 - userspace gdb breakpoint, handled here */
289 case VEC_EXCPT01:
290 info.si_code = TRAP_ILLTRAP;
291 sig = SIGTRAP;
292 CHK_DEBUGGER_TRAP_MAYBE();
293 /* Check if this is a breakpoint in kernel space */
294 if (fp->ipend & 0xffc0)
295 return;
296 else
297 break;
Mike Frysinger9401e612007-07-12 11:50:43 +0800298 /* 0x03 - User Defined, userspace stack overflow */
Bryan Wu1394f032007-05-06 14:50:22 -0700299 case VEC_EXCPT03:
300 info.si_code = SEGV_STACKFLOW;
301 sig = SIGSEGV;
Robin Getz9f06c382008-10-10 18:13:21 +0800302 verbose_printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800303 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700304 break;
Sonic Zhang27707d32008-10-09 14:04:41 +0800305 /* 0x02 - KGDB initial connection and break signal trap */
306 case VEC_EXCPT02:
307#ifdef CONFIG_KGDB
308 info.si_code = TRAP_ILLTRAP;
309 sig = SIGTRAP;
310 CHK_DEBUGGER_TRAP();
311 return;
312#endif
Robin Getz5c64e0d2008-10-08 14:43:47 +0800313 /* 0x04 - User Defined */
314 /* 0x05 - User Defined */
315 /* 0x06 - User Defined */
316 /* 0x07 - User Defined */
317 /* 0x08 - User Defined */
318 /* 0x09 - User Defined */
319 /* 0x0A - User Defined */
320 /* 0x0B - User Defined */
321 /* 0x0C - User Defined */
322 /* 0x0D - User Defined */
323 /* 0x0E - User Defined */
324 /* 0x0F - User Defined */
Sonic Zhang27707d32008-10-09 14:04:41 +0800325 /* If we got here, it is most likely that someone was trying to use a
Robin Getz5c64e0d2008-10-08 14:43:47 +0800326 * custom exception handler, and it is not actually installed properly
327 */
328 case VEC_EXCPT04 ... VEC_EXCPT15:
329 info.si_code = ILL_ILLPARAOP;
330 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800331 verbose_printk(KERN_NOTICE EXC_0x04(KERN_NOTICE));
Robin Getz5c64e0d2008-10-08 14:43:47 +0800332 CHK_DEBUGGER_TRAP_MAYBE();
333 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700334 /* 0x10 HW Single step, handled here */
335 case VEC_STEP:
336 info.si_code = TRAP_STEP;
337 sig = SIGTRAP;
338 CHK_DEBUGGER_TRAP_MAYBE();
339 /* Check if this is a single step in kernel space */
340 if (fp->ipend & 0xffc0)
341 return;
342 else
343 break;
344 /* 0x11 - Trace Buffer Full, handled here */
345 case VEC_OVFLOW:
346 info.si_code = TRAP_TRACEFLOW;
347 sig = SIGTRAP;
Robin Getz9f06c382008-10-10 18:13:21 +0800348 verbose_printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800349 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700350 break;
351 /* 0x12 - Reserved, Caught by default */
352 /* 0x13 - Reserved, Caught by default */
353 /* 0x14 - Reserved, Caught by default */
354 /* 0x15 - Reserved, Caught by default */
355 /* 0x16 - Reserved, Caught by default */
356 /* 0x17 - Reserved, Caught by default */
357 /* 0x18 - Reserved, Caught by default */
358 /* 0x19 - Reserved, Caught by default */
359 /* 0x1A - Reserved, Caught by default */
360 /* 0x1B - Reserved, Caught by default */
361 /* 0x1C - Reserved, Caught by default */
362 /* 0x1D - Reserved, Caught by default */
363 /* 0x1E - Reserved, Caught by default */
364 /* 0x1F - Reserved, Caught by default */
365 /* 0x20 - Reserved, Caught by default */
366 /* 0x21 - Undefined Instruction, handled here */
367 case VEC_UNDEF_I:
368 info.si_code = ILL_ILLOPC;
369 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800370 verbose_printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800371 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700372 break;
373 /* 0x22 - Illegal Instruction Combination, handled here */
374 case VEC_ILGAL_I:
375 info.si_code = ILL_ILLPARAOP;
376 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800377 verbose_printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800378 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700379 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800380 /* 0x23 - Data CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700381 case VEC_CPLB_VL:
382 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800383 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800384 verbose_printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800385 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700386 break;
387 /* 0x24 - Data access misaligned, handled here */
388 case VEC_MISALI_D:
389 info.si_code = BUS_ADRALN;
390 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800391 verbose_printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800392 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700393 break;
394 /* 0x25 - Unrecoverable Event, handled here */
395 case VEC_UNCOV:
396 info.si_code = ILL_ILLEXCPT;
397 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800398 verbose_printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800399 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700400 break;
401 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
402 error case is handled here */
403 case VEC_CPLB_M:
404 info.si_code = BUS_ADRALN;
405 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800406 verbose_printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700407 break;
408 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
409 case VEC_CPLB_MHIT:
410 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700411 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800412#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800413 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +0800414 verbose_printk(KERN_NOTICE "NULL pointer access\n");
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800415 else
Bryan Wu1394f032007-05-06 14:50:22 -0700416#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800417 verbose_printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800418 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700419 break;
420 /* 0x28 - Emulation Watchpoint, handled here */
421 case VEC_WATCH:
422 info.si_code = TRAP_WATCHPT;
423 sig = SIGTRAP;
Robin Getz569a50c2007-11-21 16:35:57 +0800424 pr_debug(EXC_0x28(KERN_DEBUG));
Bryan Wu1394f032007-05-06 14:50:22 -0700425 CHK_DEBUGGER_TRAP_MAYBE();
426 /* Check if this is a watchpoint in kernel space */
427 if (fp->ipend & 0xffc0)
428 return;
429 else
430 break;
431#ifdef CONFIG_BF535
432 /* 0x29 - Instruction fetch access error (535 only) */
433 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
434 info.si_code = BUS_OPFETCH;
435 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800436 verbose_printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800437 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700438 break;
439#else
440 /* 0x29 - Reserved, Caught by default */
441#endif
442 /* 0x2A - Instruction fetch misaligned, handled here */
443 case VEC_MISALI_I:
444 info.si_code = BUS_ADRALN;
445 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800446 verbose_printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800447 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700448 break;
Robin Getzf26fbc42007-11-12 22:21:30 +0800449 /* 0x2B - Instruction CPLB protection violation, handled here */
Bryan Wu1394f032007-05-06 14:50:22 -0700450 case VEC_CPLB_I_VL:
451 info.si_code = ILL_CPLB_VI;
Robin Getzf26fbc42007-11-12 22:21:30 +0800452 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800453 verbose_printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800454 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700455 break;
456 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
457 case VEC_CPLB_I_M:
458 info.si_code = ILL_CPLB_MISS;
459 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800460 verbose_printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
Bryan Wu1394f032007-05-06 14:50:22 -0700461 break;
462 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
463 case VEC_CPLB_I_MHIT:
464 info.si_code = ILL_CPLB_MULHIT;
Bryan Wu1394f032007-05-06 14:50:22 -0700465 sig = SIGSEGV;
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800466#ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
Graf Yang8f658732008-11-18 17:48:22 +0800467 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +0800468 verbose_printk(KERN_NOTICE "Jump to NULL address\n");
Mike Frysingerc6c6f752008-05-17 16:18:08 +0800469 else
Bryan Wu1394f032007-05-06 14:50:22 -0700470#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800471 verbose_printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800472 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700473 break;
474 /* 0x2E - Illegal use of Supervisor Resource, handled here */
475 case VEC_ILL_RES:
476 info.si_code = ILL_PRVOPC;
477 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800478 verbose_printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800479 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700480 break;
481 /* 0x2F - Reserved, Caught by default */
482 /* 0x30 - Reserved, Caught by default */
483 /* 0x31 - Reserved, Caught by default */
484 /* 0x32 - Reserved, Caught by default */
485 /* 0x33 - Reserved, Caught by default */
486 /* 0x34 - Reserved, Caught by default */
487 /* 0x35 - Reserved, Caught by default */
488 /* 0x36 - Reserved, Caught by default */
489 /* 0x37 - Reserved, Caught by default */
490 /* 0x38 - Reserved, Caught by default */
491 /* 0x39 - Reserved, Caught by default */
492 /* 0x3A - Reserved, Caught by default */
493 /* 0x3B - Reserved, Caught by default */
494 /* 0x3C - Reserved, Caught by default */
495 /* 0x3D - Reserved, Caught by default */
496 /* 0x3E - Reserved, Caught by default */
497 /* 0x3F - Reserved, Caught by default */
Robin Getz13fe24f2008-01-27 15:38:56 +0800498 case VEC_HWERR:
499 info.si_code = BUS_ADRALN;
500 sig = SIGBUS;
501 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
502 /* System MMR Error */
503 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
504 info.si_code = BUS_ADRALN;
505 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800506 verbose_printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
Robin Getz13fe24f2008-01-27 15:38:56 +0800507 break;
508 /* External Memory Addressing Error */
509 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
510 info.si_code = BUS_ADRERR;
511 sig = SIGBUS;
Robin Getz9f06c382008-10-10 18:13:21 +0800512 verbose_printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
Robin Getz13fe24f2008-01-27 15:38:56 +0800513 break;
514 /* Performance Monitor Overflow */
515 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
Robin Getz9f06c382008-10-10 18:13:21 +0800516 verbose_printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
Robin Getz13fe24f2008-01-27 15:38:56 +0800517 break;
518 /* RAISE 5 instruction */
519 case (SEQSTAT_HWERRCAUSE_RAISE_5):
520 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
521 break;
522 default: /* Reserved */
523 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
524 break;
525 }
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800526 CHK_DEBUGGER_TRAP_MAYBE();
Robin Getz13fe24f2008-01-27 15:38:56 +0800527 break;
Robin Getz5c64e0d2008-10-08 14:43:47 +0800528 /*
529 * We should be handling all known exception types above,
530 * if we get here we hit a reserved one, so panic
531 */
Bryan Wu1394f032007-05-06 14:50:22 -0700532 default:
Robin Getz5c64e0d2008-10-08 14:43:47 +0800533 oops_in_progress = 1;
534 info.si_code = ILL_ILLPARAOP;
535 sig = SIGILL;
Robin Getz9f06c382008-10-10 18:13:21 +0800536 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700537 (fp->seqstat & SEQSTAT_EXCAUSE));
Sonic Zhanga5ac0122008-10-13 14:07:19 +0800538 CHK_DEBUGGER_TRAP_MAYBE();
Bryan Wu1394f032007-05-06 14:50:22 -0700539 break;
540 }
541
Robin Getz226eb1e2007-10-29 17:59:07 +0800542 BUG_ON(sig == 0);
543
544 if (sig != SIGTRAP) {
Mike Frysinger49dce912007-11-21 16:46:49 +0800545 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +0800546 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +0800547 show_regs(fp);
Robin Getz226eb1e2007-10-29 17:59:07 +0800548
549 /* Print out the trace buffer if it makes sense */
550#ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
551 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
Robin Getz9f06c382008-10-10 18:13:21 +0800552 verbose_printk(KERN_NOTICE "No trace since you do not have "
Robin Getz226eb1e2007-10-29 17:59:07 +0800553 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
554 KERN_NOTICE "\n");
555 else
556#endif
557 dump_bfin_trace_buffer();
Robin Getzf09630b2008-07-26 19:45:46 +0800558
Robin Getz226eb1e2007-10-29 17:59:07 +0800559 if (oops_in_progress) {
Robin Getzf09630b2008-07-26 19:45:46 +0800560 /* Dump the current kernel stack */
Robin Getz9f06c382008-10-10 18:13:21 +0800561 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800562 show_stack(current, NULL);
Robin Getzaee3a292008-01-11 16:53:00 +0800563 print_modules();
Robin Getz226eb1e2007-10-29 17:59:07 +0800564#ifndef CONFIG_ACCESS_CHECK
Robin Getz9f06c382008-10-10 18:13:21 +0800565 verbose_printk(KERN_EMERG "Please turn on "
Robin Getz90c7f462007-11-18 00:35:33 +0800566 "CONFIG_ACCESS_CHECK\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800567#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700568 panic("Kernel exception");
Robin Getzf09630b2008-07-26 19:45:46 +0800569 } else {
Robin Getz4ee1c452008-10-28 11:36:11 +0800570#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz9f06c382008-10-10 18:13:21 +0800571 unsigned long *stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800572 /* Dump the user space stack */
573 stack = (unsigned long *)rdusp();
Robin Getz9f06c382008-10-10 18:13:21 +0800574 verbose_printk(KERN_NOTICE "Userspace Stack\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800575 show_stack(NULL, stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800576#endif
Robin Getz226eb1e2007-10-29 17:59:07 +0800577 }
Bryan Wu1394f032007-05-06 14:50:22 -0700578 }
Robin Getzfb322912007-11-21 16:38:05 +0800579
Yi Li6a01f232009-01-07 23:14:39 +0800580#ifdef CONFIG_IPIPE
581 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
582#endif
583 {
584 info.si_signo = sig;
585 info.si_errno = 0;
586 info.si_addr = (void __user *)fp->pc;
587 force_sig_info(sig, &info, current);
588 }
Bryan Wu1394f032007-05-06 14:50:22 -0700589
Bryan Wu1394f032007-05-06 14:50:22 -0700590 trace_buffer_restore(j);
591 return;
592}
593
594/* Typical exception handling routines */
595
Robin Getz518039b2007-07-25 11:03:28 +0800596#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
597
Robin Getzf09630b2008-07-26 19:45:46 +0800598/*
599 * Similar to get_user, do some address checking, then dereference
600 * Return true on sucess, false on bad address
601 */
Robin Getz9f06c382008-10-10 18:13:21 +0800602static bool get_instruction(unsigned short *val, unsigned short *address)
Robin Getzf09630b2008-07-26 19:45:46 +0800603{
604
605 unsigned long addr;
606
607 addr = (unsigned long)address;
608
609 /* Check for odd addresses */
610 if (addr & 0x1)
611 return false;
612
613 /* Check that things do not wrap around */
614 if (addr > (addr + 2))
615 return false;
616
617 /*
618 * Since we are in exception context, we need to do a little address checking
619 * We need to make sure we are only accessing valid memory, and
620 * we don't read something in the async space that can hang forever
621 */
622 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800623#if L2_LENGTH != 0
Robin Getzf09630b2008-07-26 19:45:46 +0800624 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
625#endif
626 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
627#if L1_DATA_A_LENGTH != 0
628 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
629#endif
630#if L1_DATA_B_LENGTH != 0
631 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
632#endif
633 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
634 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
635 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
636 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
637 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
638 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
639 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
640 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
641 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
642 *val = *address;
643 return true;
644 }
645
646#if L1_CODE_LENGTH != 0
647 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
Robin Getz9df10282008-10-08 18:03:33 +0800648 isram_memcpy(val, address, 2);
Robin Getzf09630b2008-07-26 19:45:46 +0800649 return true;
650 }
651#endif
652
653
654 return false;
655}
656
Mike Frysinger36f649a2008-11-18 17:48:22 +0800657/*
Robin Getzd3d0ac22008-08-06 17:49:27 +0800658 * decode the instruction if we are printing out the trace, as it
659 * makes things easier to follow, without running it through objdump
660 * These are the normal instructions which cause change of flow, which
661 * would be at the source of the trace buffer
662 */
Mike Frysinger36f649a2008-11-18 17:48:22 +0800663#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BFIN_HWTRACE_ON)
Robin Getz9f06c382008-10-10 18:13:21 +0800664static void decode_instruction(unsigned short *address)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800665{
666 unsigned short opcode;
667
668 if (get_instruction(&opcode, address)) {
669 if (opcode == 0x0010)
Robin Getz9f06c382008-10-10 18:13:21 +0800670 verbose_printk("RTS");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800671 else if (opcode == 0x0011)
Robin Getz9f06c382008-10-10 18:13:21 +0800672 verbose_printk("RTI");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800673 else if (opcode == 0x0012)
Robin Getz9f06c382008-10-10 18:13:21 +0800674 verbose_printk("RTX");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800675 else if (opcode >= 0x0050 && opcode <= 0x0057)
Robin Getz9f06c382008-10-10 18:13:21 +0800676 verbose_printk("JUMP (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800677 else if (opcode >= 0x0060 && opcode <= 0x0067)
Robin Getz9f06c382008-10-10 18:13:21 +0800678 verbose_printk("CALL (P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800679 else if (opcode >= 0x0070 && opcode <= 0x0077)
Robin Getz9f06c382008-10-10 18:13:21 +0800680 verbose_printk("CALL (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800681 else if (opcode >= 0x0080 && opcode <= 0x0087)
Robin Getz9f06c382008-10-10 18:13:21 +0800682 verbose_printk("JUMP (PC+P%i)", opcode & 7);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800683 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
Robin Getz9f06c382008-10-10 18:13:21 +0800684 verbose_printk("IF !CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800685 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
Robin Getz9f06c382008-10-10 18:13:21 +0800686 verbose_printk("IF CC JUMP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800687 else if (opcode >= 0x2000 && opcode <= 0x2fff)
Robin Getz9f06c382008-10-10 18:13:21 +0800688 verbose_printk("JUMP.S");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800689 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800690 verbose_printk("LSETUP");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800691 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800692 verbose_printk("JUMP.L");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800693 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
Robin Getz9f06c382008-10-10 18:13:21 +0800694 verbose_printk("CALL pcrel");
Robin Getzd3d0ac22008-08-06 17:49:27 +0800695 else
Robin Getz9f06c382008-10-10 18:13:21 +0800696 verbose_printk("0x%04x", opcode);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800697 }
698
699}
Robin Getz9f06c382008-10-10 18:13:21 +0800700#endif
Robin Getzd3d0ac22008-08-06 17:49:27 +0800701
Bryan Wu1394f032007-05-06 14:50:22 -0700702void dump_bfin_trace_buffer(void)
703{
Robin Getz9f06c382008-10-10 18:13:21 +0800704#ifdef CONFIG_DEBUG_VERBOSE
Robin Getz518039b2007-07-25 11:03:28 +0800705#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
706 int tflags, i = 0;
Robin Getz226eb1e2007-10-29 17:59:07 +0800707 char buf[150];
Robin Getzd3d0ac22008-08-06 17:49:27 +0800708 unsigned short *addr;
Robin Getz518039b2007-07-25 11:03:28 +0800709#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
710 int j, index;
711#endif
712
Bryan Wu1394f032007-05-06 14:50:22 -0700713 trace_buffer_save(tflags);
714
Robin Getz226eb1e2007-10-29 17:59:07 +0800715 printk(KERN_NOTICE "Hardware Trace:\n");
Robin Getz518039b2007-07-25 11:03:28 +0800716
Robin Getzd3d0ac22008-08-06 17:49:27 +0800717#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
718 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
719#endif
720
Bryan Wu1394f032007-05-06 14:50:22 -0700721 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
Robin Getz518039b2007-07-25 11:03:28 +0800722 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800723 decode_address(buf, (unsigned long)bfin_read_TBUF());
724 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getzf09630b2008-07-26 19:45:46 +0800725 addr = (unsigned short *)bfin_read_TBUF();
726 decode_address(buf, (unsigned long)addr);
727 printk(KERN_NOTICE " Source : %s ", buf);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800728 decode_instruction(addr);
Robin Getzf09630b2008-07-26 19:45:46 +0800729 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700730 }
731 }
732
Robin Getz518039b2007-07-25 11:03:28 +0800733#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
734 if (trace_buff_offset)
Robin Getzd3d0ac22008-08-06 17:49:27 +0800735 index = trace_buff_offset / 4;
Robin Getz518039b2007-07-25 11:03:28 +0800736 else
737 index = EXPAND_LEN;
738
739 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
740 while (j) {
Robin Getz226eb1e2007-10-29 17:59:07 +0800741 decode_address(buf, software_trace_buff[index]);
742 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
Robin Getz518039b2007-07-25 11:03:28 +0800743 index -= 1;
744 if (index < 0 )
745 index = EXPAND_LEN;
Robin Getz226eb1e2007-10-29 17:59:07 +0800746 decode_address(buf, software_trace_buff[index]);
Robin Getzd3d0ac22008-08-06 17:49:27 +0800747 printk(KERN_NOTICE " Source : %s ", buf);
748 decode_instruction((unsigned short *)software_trace_buff[index]);
749 printk("\n");
Robin Getz518039b2007-07-25 11:03:28 +0800750 index -= 1;
751 if (index < 0)
752 index = EXPAND_LEN;
Robin Getz518039b2007-07-25 11:03:28 +0800753 j--;
754 i++;
755 }
756#endif
757
Bryan Wu1394f032007-05-06 14:50:22 -0700758 trace_buffer_restore(tflags);
Robin Getz518039b2007-07-25 11:03:28 +0800759#endif
Robin Getz9f06c382008-10-10 18:13:21 +0800760#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700761}
762EXPORT_SYMBOL(dump_bfin_trace_buffer);
763
Robin Getzf09630b2008-07-26 19:45:46 +0800764/*
765 * Checks to see if the address pointed to is either a
766 * 16-bit CALL instruction, or a 32-bit CALL instruction
767 */
Robin Getz9f06c382008-10-10 18:13:21 +0800768static bool is_bfin_call(unsigned short *addr)
Bryan Wu1394f032007-05-06 14:50:22 -0700769{
Robin Getzf09630b2008-07-26 19:45:46 +0800770 unsigned short opcode = 0, *ins_addr;
771 ins_addr = (unsigned short *)addr;
Bryan Wu1394f032007-05-06 14:50:22 -0700772
Robin Getzf09630b2008-07-26 19:45:46 +0800773 if (!get_instruction(&opcode, ins_addr))
774 return false;
Bryan Wu1394f032007-05-06 14:50:22 -0700775
Robin Getzf09630b2008-07-26 19:45:46 +0800776 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
777 (opcode >= 0x0070 && opcode <= 0x0077))
778 return true;
Bryan Wu1394f032007-05-06 14:50:22 -0700779
Robin Getzf09630b2008-07-26 19:45:46 +0800780 ins_addr--;
781 if (!get_instruction(&opcode, ins_addr))
782 return false;
783
784 if (opcode >= 0xE300 && opcode <= 0xE3FF)
785 return true;
786
787 return false;
788
Bryan Wu1394f032007-05-06 14:50:22 -0700789}
Robin Getz9f06c382008-10-10 18:13:21 +0800790
Bryan Wu1394f032007-05-06 14:50:22 -0700791void show_stack(struct task_struct *task, unsigned long *stack)
792{
Robin Getz9f06c382008-10-10 18:13:21 +0800793#ifdef CONFIG_PRINTK
Robin Getzf09630b2008-07-26 19:45:46 +0800794 unsigned int *addr, *endstack, *fp = 0, *frame;
795 unsigned short *ins_addr;
796 char buf[150];
797 unsigned int i, j, ret_addr, frame_no = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700798
Robin Getzf09630b2008-07-26 19:45:46 +0800799 /*
800 * If we have been passed a specific stack, use that one otherwise
801 * if we have been passed a task structure, use that, otherwise
802 * use the stack of where the variable "stack" exists
Bryan Wu1394f032007-05-06 14:50:22 -0700803 */
804
Robin Getzf09630b2008-07-26 19:45:46 +0800805 if (stack == NULL) {
806 if (task) {
807 /* We know this is a kernel stack, so this is the start/end */
Bryan Wu1394f032007-05-06 14:50:22 -0700808 stack = (unsigned long *)task->thread.ksp;
Robin Getzf09630b2008-07-26 19:45:46 +0800809 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
810 } else {
811 /* print out the existing stack info */
Bryan Wu1394f032007-05-06 14:50:22 -0700812 stack = (unsigned long *)&stack;
Robin Getzf09630b2008-07-26 19:45:46 +0800813 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
814 }
815 } else
816 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
817
Robin Getz9f06c382008-10-10 18:13:21 +0800818 printk(KERN_NOTICE "Stack info:\n");
Robin Getzf09630b2008-07-26 19:45:46 +0800819 decode_address(buf, (unsigned int)stack);
Robin Getz9f06c382008-10-10 18:13:21 +0800820 printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
821
Robin Getzf09630b2008-07-26 19:45:46 +0800822 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
823
824 /* First thing is to look for a frame pointer */
825 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
826 addr < endstack; addr++, i++) {
827 if (*addr & 0x1)
828 continue;
829 ins_addr = (unsigned short *)*addr;
830 ins_addr--;
831 if (is_bfin_call(ins_addr))
832 fp = addr - 1;
833
834 if (fp) {
835 /* Let's check to see if it is a frame pointer */
836 while (fp >= (addr - 1) && fp < endstack && fp)
837 fp = (unsigned int *)*fp;
838 if (fp == 0 || fp == endstack) {
839 fp = addr - 1;
840 break;
841 }
842 fp = 0;
843 }
844 }
845 if (fp) {
846 frame = fp;
Jie Zhangb339dc72009-01-07 23:14:39 +0800847 printk(KERN_NOTICE " FP: (0x%p)\n", fp);
Robin Getzf09630b2008-07-26 19:45:46 +0800848 } else
849 frame = 0;
850
851 /*
852 * Now that we think we know where things are, we
853 * walk the stack again, this time printing things out
854 * incase there is no frame pointer, we still look for
855 * valid return addresses
856 */
857
858 /* First time print out data, next time, print out symbols */
859 for (j = 0; j <= 1; j++) {
860 if (j)
861 printk(KERN_NOTICE "Return addresses in stack:\n");
862 else
863 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
864
865 fp = frame;
866 frame_no = 0;
867
868 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
869 addr <= endstack; addr++, i++) {
870
871 ret_addr = 0;
872 if (!j && i % 8 == 0)
873 printk("\n" KERN_NOTICE "%p:",addr);
874
875 /* if it is an odd address, or zero, just skip it */
876 if (*addr & 0x1 || !*addr)
877 goto print;
878
879 ins_addr = (unsigned short *)*addr;
880
881 /* Go back one instruction, and see if it is a CALL */
882 ins_addr--;
883 ret_addr = is_bfin_call(ins_addr);
884 print:
885 if (!j && stack == (unsigned long *)addr)
886 printk("[%08x]", *addr);
887 else if (ret_addr)
888 if (j) {
889 decode_address(buf, (unsigned int)*addr);
890 if (frame == addr) {
891 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
892 continue;
893 }
894 printk(KERN_NOTICE " address : %s\n", buf);
895 } else
896 printk("<%08x>", *addr);
897 else if (fp == addr) {
898 if (j)
899 frame = addr+1;
900 else
901 printk("(%08x)", *addr);
902
903 fp = (unsigned int *)*addr;
904 frame_no++;
905
906 } else if (!j)
907 printk(" %08x ", *addr);
908 }
909 if (!j)
910 printk("\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700911 }
Robin Getz9f06c382008-10-10 18:13:21 +0800912#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700913}
914
915void dump_stack(void)
916{
917 unsigned long stack;
Robin Getz518039b2007-07-25 11:03:28 +0800918#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
Bryan Wu1394f032007-05-06 14:50:22 -0700919 int tflags;
Robin Getz518039b2007-07-25 11:03:28 +0800920#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700921 trace_buffer_save(tflags);
922 dump_bfin_trace_buffer();
923 show_stack(current, &stack);
924 trace_buffer_restore(tflags);
925}
Bryan Wu1394f032007-05-06 14:50:22 -0700926EXPORT_SYMBOL(dump_stack);
927
Mike Frysinger49dce912007-11-21 16:46:49 +0800928void dump_bfin_process(struct pt_regs *fp)
Bryan Wu1394f032007-05-06 14:50:22 -0700929{
Robin Getz9f06c382008-10-10 18:13:21 +0800930#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +0800931 /* We should be able to look at fp->ipend, but we don't push it on the
932 * stack all the time, so do this until we fix that */
933 unsigned int context = bfin_read_IPEND();
Robin Getz226eb1e2007-10-29 17:59:07 +0800934
Mike Frysinger49dce912007-11-21 16:46:49 +0800935 if (oops_in_progress)
Robin Getz9f06c382008-10-10 18:13:21 +0800936 verbose_printk(KERN_EMERG "Kernel OOPS in progress\n");
Robin Getz226eb1e2007-10-29 17:59:07 +0800937
Robin Getzb03b08b2007-12-23 22:57:01 +0800938 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
Robin Getz9f06c382008-10-10 18:13:21 +0800939 verbose_printk(KERN_NOTICE "HW Error context\n");
Robin Getzb03b08b2007-12-23 22:57:01 +0800940 else if (context & 0x0020)
Robin Getz9f06c382008-10-10 18:13:21 +0800941 verbose_printk(KERN_NOTICE "Deferred Exception context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800942 else if (context & 0x3FC0)
Robin Getz9f06c382008-10-10 18:13:21 +0800943 verbose_printk(KERN_NOTICE "Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800944 else if (context & 0x4000)
Robin Getz9f06c382008-10-10 18:13:21 +0800945 verbose_printk(KERN_NOTICE "Deferred Interrupt context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800946 else if (context & 0x8000)
Robin Getz9f06c382008-10-10 18:13:21 +0800947 verbose_printk(KERN_NOTICE "Kernel process context\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800948
Robin Getz9a62ca42008-03-26 09:15:58 +0800949 /* Because we are crashing, and pointers could be bad, we check things
950 * pretty closely before we use them
951 */
Robin Getz7f1c9062008-04-25 03:36:31 +0800952 if ((unsigned long)current >= FIXED_CODE_START &&
953 !((unsigned long)current & 0x3) && current->pid) {
Robin Getz9f06c382008-10-10 18:13:21 +0800954 verbose_printk(KERN_NOTICE "CURRENT PROCESS:\n");
Robin Getz9a62ca42008-03-26 09:15:58 +0800955 if (current->comm >= (char *)FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +0800956 verbose_printk(KERN_NOTICE "COMM=%s PID=%d\n",
Robin Getz9a62ca42008-03-26 09:15:58 +0800957 current->comm, current->pid);
958 else
Robin Getz9f06c382008-10-10 18:13:21 +0800959 verbose_printk(KERN_NOTICE "COMM= invalid\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800960
Graf Yang8f658732008-11-18 17:48:22 +0800961 printk(KERN_NOTICE "CPU = %d\n", current_thread_info()->cpu);
Robin Getz9a62ca42008-03-26 09:15:58 +0800962 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
Robin Getz9f06c382008-10-10 18:13:21 +0800963 verbose_printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
Robin Getz9a62ca42008-03-26 09:15:58 +0800964 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
965 KERN_NOTICE "\n",
966 (void *)current->mm->start_code,
967 (void *)current->mm->end_code,
968 (void *)current->mm->start_data,
969 (void *)current->mm->end_data,
970 (void *)current->mm->end_data,
971 (void *)current->mm->brk,
972 (void *)current->mm->start_stack);
973 else
Robin Getz9f06c382008-10-10 18:13:21 +0800974 verbose_printk(KERN_NOTICE "invalid mm\n");
Mike Frysinger49dce912007-11-21 16:46:49 +0800975 } else
Robin Getz9f06c382008-10-10 18:13:21 +0800976 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE
Mike Frysinger49dce912007-11-21 16:46:49 +0800977 "No Valid process in current context\n");
Robin Getz9f06c382008-10-10 18:13:21 +0800978#endif
Mike Frysinger49dce912007-11-21 16:46:49 +0800979}
980
Robin Getzb03b08b2007-12-23 22:57:01 +0800981void dump_bfin_mem(struct pt_regs *fp)
Mike Frysinger49dce912007-11-21 16:46:49 +0800982{
Robin Getz9f06c382008-10-10 18:13:21 +0800983#ifdef CONFIG_DEBUG_VERBOSE
Robin Getzb03b08b2007-12-23 22:57:01 +0800984 unsigned short *addr, *erraddr, val = 0, err = 0;
985 char sti = 0, buf[6];
Bryan Wu1394f032007-05-06 14:50:22 -0700986
Bernd Schmidt5d750b92008-04-25 05:02:33 +0800987 erraddr = (void *)fp->pc;
Robin Getzc5d88d92007-06-21 11:34:16 +0800988
Robin Getz9f06c382008-10-10 18:13:21 +0800989 verbose_printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
Robin Getzb03b08b2007-12-23 22:57:01 +0800990
991 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
992 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
993 addr++) {
994 if (!((unsigned long)addr & 0xF))
Robin Getz9f06c382008-10-10 18:13:21 +0800995 verbose_printk("\n" KERN_NOTICE "0x%p: ", addr);
Robin Getzb03b08b2007-12-23 22:57:01 +0800996
Robin Getz7d98c882008-10-08 16:29:01 +0800997 if (!get_instruction(&val, addr)) {
Robin Getzb03b08b2007-12-23 22:57:01 +0800998 val = 0;
999 sprintf(buf, "????");
Robin Getzb03b08b2007-12-23 22:57:01 +08001000 } else
1001 sprintf(buf, "%04x", val);
1002
1003 if (addr == erraddr) {
Robin Getz9f06c382008-10-10 18:13:21 +08001004 verbose_printk("[%s]", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001005 err = val;
1006 } else
Robin Getz9f06c382008-10-10 18:13:21 +08001007 verbose_printk(" %s ", buf);
Robin Getzb03b08b2007-12-23 22:57:01 +08001008
1009 /* Do any previous instructions turn on interrupts? */
1010 if (addr <= erraddr && /* in the past */
1011 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
1012 val == 0x017b)) /* [SP++] = RETI */
1013 sti = 1;
1014 }
1015
Robin Getz9f06c382008-10-10 18:13:21 +08001016 verbose_printk("\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001017
1018 /* Hardware error interrupts can be deferred */
1019 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
1020 oops_in_progress)){
Robin Getz9f06c382008-10-10 18:13:21 +08001021 verbose_printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001022#ifndef CONFIG_DEBUG_HWERR
Robin Getz9f06c382008-10-10 18:13:21 +08001023 verbose_printk(KERN_NOTICE "The remaining message may be meaningless\n"
Robin Getzb03b08b2007-12-23 22:57:01 +08001024 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
1025 " better idea where it came from\n");
1026#else
1027 /* If we are handling only one peripheral interrupt
1028 * and current mm and pid are valid, and the last error
1029 * was in that user space process's text area
1030 * print it out - because that is where the problem exists
1031 */
1032 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
1033 (current->pid && current->mm)) {
1034 /* And the last RETI points to the current userspace context */
1035 if ((fp + 1)->pc >= current->mm->start_code &&
1036 (fp + 1)->pc <= current->mm->end_code) {
Robin Getz9f06c382008-10-10 18:13:21 +08001037 verbose_printk(KERN_NOTICE "It might be better to look around here : \n");
1038 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001039 show_regs(fp + 1);
Robin Getz9f06c382008-10-10 18:13:21 +08001040 verbose_printk(KERN_NOTICE "-------------------------------------------\n");
Robin Getzb03b08b2007-12-23 22:57:01 +08001041 }
Bryan Wu1394f032007-05-06 14:50:22 -07001042 }
Robin Getzb03b08b2007-12-23 22:57:01 +08001043#endif
1044 }
Robin Getz9f06c382008-10-10 18:13:21 +08001045#endif
Mike Frysinger49dce912007-11-21 16:46:49 +08001046}
1047
1048void show_regs(struct pt_regs *fp)
1049{
Robin Getz9f06c382008-10-10 18:13:21 +08001050#ifdef CONFIG_DEBUG_VERBOSE
Mike Frysinger49dce912007-11-21 16:46:49 +08001051 char buf [150];
Robin Getzd8f66c82007-12-24 15:27:56 +08001052 struct irqaction *action;
1053 unsigned int i;
1054 unsigned long flags;
Graf Yang8f658732008-11-18 17:48:22 +08001055 unsigned int cpu = smp_processor_id();
Bryan Wu1394f032007-05-06 14:50:22 -07001056
Robin Getz9f06c382008-10-10 18:13:21 +08001057 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
1058 verbose_printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001059 (long)fp->seqstat, fp->ipend, fp->syscfg);
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001060 if ((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001061 verbose_printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001062 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1063#ifdef EBIU_ERRMST
1064 /* If the error was from the EBIU, print it out */
1065 if (bfin_read_EBIU_ERRMST() & CORE_ERROR) {
Robin Getz9f06c382008-10-10 18:13:21 +08001066 verbose_printk(KERN_NOTICE " EBIU Error Reason : 0x%04x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001067 bfin_read_EBIU_ERRMST());
Robin Getz9f06c382008-10-10 18:13:21 +08001068 verbose_printk(KERN_NOTICE " EBIU Error Address : 0x%08x\n",
Robin Getz1d5ff7e2008-10-09 17:06:32 +08001069 bfin_read_EBIU_ERRADD());
1070 }
1071#endif
1072 }
Robin Getz9f06c382008-10-10 18:13:21 +08001073 verbose_printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
Robin Getz13fe24f2008-01-27 15:38:56 +08001074 fp->seqstat & SEQSTAT_EXCAUSE);
Robin Getzd8f66c82007-12-24 15:27:56 +08001075 for (i = 6; i <= 15 ; i++) {
1076 if (fp->ipend & (1 << i)) {
1077 decode_address(buf, bfin_read32(EVT0 + 4*i));
Robin Getz9f06c382008-10-10 18:13:21 +08001078 verbose_printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001079 }
1080 }
1081
1082 /* if no interrupts are going off, don't print this out */
1083 if (fp->ipend & ~0x3F) {
1084 for (i = 0; i < (NR_IRQS - 1); i++) {
1085 spin_lock_irqsave(&irq_desc[i].lock, flags);
1086 action = irq_desc[i].action;
1087 if (!action)
1088 goto unlock;
1089
1090 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001091 verbose_printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001092 for (action = action->next; action; action = action->next) {
1093 decode_address(buf, (unsigned int)action->handler);
Robin Getz9f06c382008-10-10 18:13:21 +08001094 verbose_printk(", %s", buf);
Robin Getzd8f66c82007-12-24 15:27:56 +08001095 }
Robin Getz9f06c382008-10-10 18:13:21 +08001096 verbose_printk("\n");
Robin Getzd8f66c82007-12-24 15:27:56 +08001097unlock:
1098 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1099 }
1100 }
Bryan Wu1394f032007-05-06 14:50:22 -07001101
Robin Getz226eb1e2007-10-29 17:59:07 +08001102 decode_address(buf, fp->rete);
Robin Getz9f06c382008-10-10 18:13:21 +08001103 verbose_printk(KERN_NOTICE " RETE: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001104 decode_address(buf, fp->retn);
Robin Getz9f06c382008-10-10 18:13:21 +08001105 verbose_printk(KERN_NOTICE " RETN: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001106 decode_address(buf, fp->retx);
Robin Getz9f06c382008-10-10 18:13:21 +08001107 verbose_printk(KERN_NOTICE " RETX: %s\n", buf);
Robin Getz226eb1e2007-10-29 17:59:07 +08001108 decode_address(buf, fp->rets);
Robin Getz9f06c382008-10-10 18:13:21 +08001109 verbose_printk(KERN_NOTICE " RETS: %s\n", buf);
Mike Frysinger49dce912007-11-21 16:46:49 +08001110 decode_address(buf, fp->pc);
Robin Getz9f06c382008-10-10 18:13:21 +08001111 verbose_printk(KERN_NOTICE " PC : %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001112
Robin Getz13fe24f2008-01-27 15:38:56 +08001113 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1114 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
Graf Yang8f658732008-11-18 17:48:22 +08001115 decode_address(buf, cpu_pda[cpu].dcplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001116 verbose_printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
Graf Yang8f658732008-11-18 17:48:22 +08001117 decode_address(buf, cpu_pda[cpu].icplb_fault_addr);
Robin Getz9f06c382008-10-10 18:13:21 +08001118 verbose_printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
Bryan Wu1394f032007-05-06 14:50:22 -07001119 }
1120
Robin Getz9f06c382008-10-10 18:13:21 +08001121 verbose_printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1122 verbose_printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001123 fp->r0, fp->r1, fp->r2, fp->r3);
Robin Getz9f06c382008-10-10 18:13:21 +08001124 verbose_printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001125 fp->r4, fp->r5, fp->r6, fp->r7);
Robin Getz9f06c382008-10-10 18:13:21 +08001126 verbose_printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001127 fp->p0, fp->p1, fp->p2, fp->p3);
Robin Getz9f06c382008-10-10 18:13:21 +08001128 verbose_printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001129 fp->p4, fp->p5, fp->fp, (long)fp);
Robin Getz9f06c382008-10-10 18:13:21 +08001130 verbose_printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001131 fp->lb0, fp->lt0, fp->lc0);
Robin Getz9f06c382008-10-10 18:13:21 +08001132 verbose_printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001133 fp->lb1, fp->lt1, fp->lc1);
Robin Getz9f06c382008-10-10 18:13:21 +08001134 verbose_printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001135 fp->b0, fp->l0, fp->m0, fp->i0);
Robin Getz9f06c382008-10-10 18:13:21 +08001136 verbose_printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001137 fp->b1, fp->l1, fp->m1, fp->i1);
Robin Getz9f06c382008-10-10 18:13:21 +08001138 verbose_printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001139 fp->b2, fp->l2, fp->m2, fp->i2);
Robin Getz9f06c382008-10-10 18:13:21 +08001140 verbose_printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001141 fp->b3, fp->l3, fp->m3, fp->i3);
Robin Getz9f06c382008-10-10 18:13:21 +08001142 verbose_printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001143 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1144
Robin Getz9f06c382008-10-10 18:13:21 +08001145 verbose_printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
Robin Getz226eb1e2007-10-29 17:59:07 +08001146 rdusp(), fp->astat);
1147
Robin Getz9f06c382008-10-10 18:13:21 +08001148 verbose_printk(KERN_NOTICE "\n");
1149#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001150}
1151
1152#ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1153asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1154#endif
1155
Graf Yang8f658732008-11-18 17:48:22 +08001156static DEFINE_SPINLOCK(bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001157
Graf Yang8f658732008-11-18 17:48:22 +08001158asmlinkage int sys_bfin_spinlock(int *p)
1159{
1160 int ret, tmp = 0;
1161
1162 spin_lock(&bfin_spinlock_lock); /* This would also hold kernel preemption. */
1163 ret = get_user(tmp, p);
1164 if (likely(ret == 0)) {
1165 if (unlikely(tmp))
Bryan Wu1394f032007-05-06 14:50:22 -07001166 ret = 1;
Graf Yang8f658732008-11-18 17:48:22 +08001167 else
1168 put_user(1, p);
Bryan Wu1394f032007-05-06 14:50:22 -07001169 }
Graf Yang8f658732008-11-18 17:48:22 +08001170 spin_unlock(&bfin_spinlock_lock);
Bryan Wu1394f032007-05-06 14:50:22 -07001171 return ret;
1172}
1173
Mike Frysinger1ffe6642007-08-05 17:14:04 +08001174int bfin_request_exception(unsigned int exception, void (*handler)(void))
1175{
1176 void (*curr_handler)(void);
1177
1178 if (exception > 0x3F)
1179 return -EINVAL;
1180
1181 curr_handler = ex_table[exception];
1182
1183 if (curr_handler != ex_replaceable)
1184 return -EBUSY;
1185
1186 ex_table[exception] = handler;
1187
1188 return 0;
1189}
1190EXPORT_SYMBOL(bfin_request_exception);
1191
1192int bfin_free_exception(unsigned int exception, void (*handler)(void))
1193{
1194 void (*curr_handler)(void);
1195
1196 if (exception > 0x3F)
1197 return -EINVAL;
1198
1199 curr_handler = ex_table[exception];
1200
1201 if (curr_handler != handler)
1202 return -EBUSY;
1203
1204 ex_table[exception] = ex_replaceable;
1205
1206 return 0;
1207}
1208EXPORT_SYMBOL(bfin_free_exception);
1209
Bryan Wu1394f032007-05-06 14:50:22 -07001210void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1211{
1212 switch (cplb_panic) {
1213 case CPLB_NO_UNLOCKED:
1214 printk(KERN_EMERG "All CPLBs are locked\n");
1215 break;
1216 case CPLB_PROT_VIOL:
1217 return;
1218 case CPLB_NO_ADDR_MATCH:
1219 return;
1220 case CPLB_UNKNOWN_ERR:
1221 printk(KERN_EMERG "Unknown CPLB Exception\n");
1222 break;
1223 }
1224
Robin Getz226eb1e2007-10-29 17:59:07 +08001225 oops_in_progress = 1;
1226
Mike Frysinger49dce912007-11-21 16:46:49 +08001227 dump_bfin_process(fp);
Robin Getzb03b08b2007-12-23 22:57:01 +08001228 dump_bfin_mem(fp);
Mike Frysinger49dce912007-11-21 16:46:49 +08001229 show_regs(fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001230 dump_stack();
1231 panic("Unrecoverable event\n");
1232}