Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
| 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 Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 30 | #include <linux/uaccess.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/kallsyms.h> |
Bryan Wu | d31c5ab | 2007-08-10 13:00:42 -0700 | [diff] [blame] | 34 | #include <linux/fs.h> |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 35 | #include <asm/traps.h> |
| 36 | #include <asm/cacheflush.h> |
Mike Frysinger | f4585a0 | 2008-10-13 14:45:21 +0800 | [diff] [blame] | 37 | #include <asm/cplb.h> |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 38 | #include <asm/blackfin.h> |
| 39 | #include <asm/irq_handler.h> |
Robin Getz | d8f66c8 | 2007-12-24 15:27:56 +0800 | [diff] [blame] | 40 | #include <linux/irq.h> |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 41 | #include <asm/trace.h> |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 42 | #include <asm/fixed_code.h> |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 43 | #include <asm/dma.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 44 | |
| 45 | #ifdef CONFIG_KGDB |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 46 | # include <linux/kgdb.h> |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 47 | |
| 48 | # define CHK_DEBUGGER_TRAP() \ |
| 49 | do { \ |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 50 | kgdb_handle_exception(trapnr, sig, info.si_code, fp); \ |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 51 | } while (0) |
| 52 | # define CHK_DEBUGGER_TRAP_MAYBE() \ |
| 53 | do { \ |
| 54 | if (kgdb_connected) \ |
| 55 | CHK_DEBUGGER_TRAP(); \ |
| 56 | } while (0) |
| 57 | #else |
| 58 | # define CHK_DEBUGGER_TRAP() do { } while (0) |
| 59 | # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | /* Initiate the event table handler */ |
| 63 | void __init trap_init(void) |
| 64 | { |
| 65 | CSYNC(); |
| 66 | bfin_write_EVT3(trap); |
| 67 | CSYNC(); |
| 68 | } |
| 69 | |
Robin Getz | 0c7a6b2 | 2008-10-08 16:27:12 +0800 | [diff] [blame] | 70 | /* |
| 71 | * Used to save the RETX, SEQSTAT, I/D CPLB FAULT ADDR |
| 72 | * values across the transition from exception to IRQ5. |
| 73 | * We put these in L1, so they are going to be in a valid |
| 74 | * location during exception context |
| 75 | */ |
| 76 | __attribute__((l1_data)) |
| 77 | unsigned long saved_retx, saved_seqstat, |
| 78 | saved_icplb_fault_addr, saved_dcplb_fault_addr; |
Bernd Schmidt | 5d750b9 | 2008-04-25 05:02:33 +0800 | [diff] [blame] | 79 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 80 | static void decode_address(char *buf, unsigned long address) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 81 | { |
| 82 | struct vm_list_struct *vml; |
| 83 | struct task_struct *p; |
| 84 | struct mm_struct *mm; |
Robin Getz | 885be03 | 2007-10-29 17:20:41 +0800 | [diff] [blame] | 85 | unsigned long flags, offset; |
Robin Getz | 904656c | 2008-03-26 09:17:43 +0800 | [diff] [blame] | 86 | unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 87 | |
| 88 | #ifdef CONFIG_KALLSYMS |
Mike Frysinger | 8a0e665 | 2007-05-21 18:09:19 +0800 | [diff] [blame] | 89 | unsigned long symsize; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 90 | const char *symname; |
| 91 | char *modname; |
| 92 | char *delim = ":"; |
| 93 | char namebuf[128]; |
| 94 | |
| 95 | /* look up the address and see if we are in kernel space */ |
| 96 | symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf); |
| 97 | |
| 98 | if (symname) { |
| 99 | /* yeah! kernel space! */ |
| 100 | if (!modname) |
| 101 | modname = delim = ""; |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 102 | sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }", |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 103 | (void *)address, delim, modname, delim, symname, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 104 | (unsigned long)offset); |
Robin Getz | 885be03 | 2007-10-29 17:20:41 +0800 | [diff] [blame] | 105 | return; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 106 | |
| 107 | } |
| 108 | #endif |
| 109 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 110 | /* Problem in fixed code section? */ |
| 111 | if (address >= FIXED_CODE_START && address < FIXED_CODE_END) { |
| 112 | sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | /* Problem somewhere before the kernel start address */ |
| 117 | if (address < CONFIG_BOOT_LOAD) { |
| 118 | sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address); |
| 119 | return; |
| 120 | } |
| 121 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 122 | /* looks like we're off in user-land, so let's walk all the |
| 123 | * mappings of all our processes and see if we can't be a whee |
| 124 | * bit more specific |
| 125 | */ |
Robin Getz | 885be03 | 2007-10-29 17:20:41 +0800 | [diff] [blame] | 126 | write_lock_irqsave(&tasklist_lock, flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 127 | for_each_process(p) { |
Robin Getz | 904656c | 2008-03-26 09:17:43 +0800 | [diff] [blame] | 128 | mm = (in_atomic ? p->mm : get_task_mm(p)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 129 | if (!mm) |
| 130 | continue; |
| 131 | |
| 132 | vml = mm->context.vmlist; |
| 133 | while (vml) { |
| 134 | struct vm_area_struct *vma = vml->vma; |
| 135 | |
| 136 | if (address >= vma->vm_start && address < vma->vm_end) { |
Jan Blunck | cf28b48 | 2008-02-14 19:38:44 -0800 | [diff] [blame] | 137 | char _tmpbuf[256]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 138 | char *name = p->comm; |
| 139 | struct file *file = vma->vm_file; |
Jan Blunck | cf28b48 | 2008-02-14 19:38:44 -0800 | [diff] [blame] | 140 | |
| 141 | if (file) |
| 142 | name = d_path(&file->f_path, _tmpbuf, |
| 143 | sizeof(_tmpbuf)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 144 | |
Mike Frysinger | 8a0e665 | 2007-05-21 18:09:19 +0800 | [diff] [blame] | 145 | /* FLAT does not have its text aligned to the start of |
| 146 | * the map while FDPIC ELF does ... |
| 147 | */ |
Mike Frysinger | 8a0e665 | 2007-05-21 18:09:19 +0800 | [diff] [blame] | 148 | |
Robin Getz | 7f1c906 | 2008-04-25 03:36:31 +0800 | [diff] [blame] | 149 | /* before we can check flat/fdpic, we need to |
| 150 | * make sure current is valid |
| 151 | */ |
| 152 | if ((unsigned long)current >= FIXED_CODE_START && |
| 153 | !((unsigned long)current & 0x3)) { |
| 154 | if (current->mm && |
| 155 | (address > current->mm->start_code) && |
| 156 | (address < current->mm->end_code)) |
| 157 | offset = address - current->mm->start_code; |
| 158 | else |
| 159 | offset = (address - vma->vm_start) + |
| 160 | (vma->vm_pgoff << PAGE_SHIFT); |
| 161 | |
| 162 | sprintf(buf, "<0x%p> [ %s + 0x%lx ]", |
| 163 | (void *)address, name, offset); |
| 164 | } else |
| 165 | sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]", |
| 166 | (void *)address, name, |
| 167 | vma->vm_start, vma->vm_end); |
| 168 | |
Robin Getz | 904656c | 2008-03-26 09:17:43 +0800 | [diff] [blame] | 169 | if (!in_atomic) |
Robin Getz | 885be03 | 2007-10-29 17:20:41 +0800 | [diff] [blame] | 170 | mmput(mm); |
Robin Getz | 7f1c906 | 2008-04-25 03:36:31 +0800 | [diff] [blame] | 171 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 172 | if (!strlen(buf)) |
| 173 | sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name); |
| 174 | |
Robin Getz | 885be03 | 2007-10-29 17:20:41 +0800 | [diff] [blame] | 175 | goto done; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | vml = vml->next; |
| 179 | } |
Robin Getz | 904656c | 2008-03-26 09:17:43 +0800 | [diff] [blame] | 180 | if (!in_atomic) |
Robin Getz | 885be03 | 2007-10-29 17:20:41 +0800 | [diff] [blame] | 181 | mmput(mm); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 182 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 183 | |
| 184 | /* we were unable to find this address anywhere */ |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 185 | sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address); |
Robin Getz | 885be03 | 2007-10-29 17:20:41 +0800 | [diff] [blame] | 186 | |
| 187 | done: |
| 188 | write_unlock_irqrestore(&tasklist_lock, flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Robin Getz | 2ebcade | 2007-10-09 17:24:30 +0800 | [diff] [blame] | 191 | asmlinkage void double_fault_c(struct pt_regs *fp) |
| 192 | { |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 193 | console_verbose(); |
| 194 | oops_in_progress = 1; |
Robin Getz | 2ebcade | 2007-10-09 17:24:30 +0800 | [diff] [blame] | 195 | printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n"); |
Robin Getz | 0c7a6b2 | 2008-10-08 16:27:12 +0800 | [diff] [blame] | 196 | #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT |
| 197 | if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) { |
| 198 | char buf[150]; |
| 199 | decode_address(buf, saved_retx); |
| 200 | printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n", |
| 201 | (int)saved_seqstat & SEQSTAT_EXCAUSE, buf); |
| 202 | decode_address(buf, saved_dcplb_fault_addr); |
| 203 | printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf); |
| 204 | decode_address(buf, saved_icplb_fault_addr); |
| 205 | printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf); |
| 206 | |
| 207 | decode_address(buf, fp->retx); |
| 208 | printk(KERN_NOTICE "The instruction at %s caused a double exception\n", |
| 209 | buf); |
| 210 | } else |
| 211 | #endif |
| 212 | { |
| 213 | dump_bfin_process(fp); |
| 214 | dump_bfin_mem(fp); |
| 215 | show_regs(fp); |
| 216 | } |
Robin Getz | 2ebcade | 2007-10-09 17:24:30 +0800 | [diff] [blame] | 217 | panic("Double Fault - unrecoverable event\n"); |
| 218 | |
| 219 | } |
| 220 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 221 | asmlinkage void trap_c(struct pt_regs *fp) |
| 222 | { |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 223 | #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON |
| 224 | int j; |
| 225 | #endif |
| 226 | int sig = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 227 | siginfo_t info; |
| 228 | unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE; |
| 229 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 230 | trace_buffer_save(j); |
| 231 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 232 | /* Important - be very careful dereferncing pointers - will lead to |
| 233 | * double faults if the stack has become corrupt |
| 234 | */ |
| 235 | |
| 236 | /* If the fault was caused by a kernel thread, or interrupt handler |
| 237 | * we will kernel panic, so the system reboots. |
| 238 | * If KGDB is enabled, don't set this for kernel breakpoints |
| 239 | */ |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 240 | |
| 241 | /* TODO: check to see if we are in some sort of deferred HWERR |
| 242 | * that we should be able to recover from, not kernel panic |
| 243 | */ |
Robin Getz | 6b5eace | 2008-01-10 17:57:56 +0800 | [diff] [blame] | 244 | if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP) |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 245 | #ifdef CONFIG_KGDB |
Robin Getz | 6b5eace | 2008-01-10 17:57:56 +0800 | [diff] [blame] | 246 | && (trapnr != VEC_EXCPT02) |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 247 | #endif |
| 248 | ){ |
| 249 | console_verbose(); |
| 250 | oops_in_progress = 1; |
| 251 | } else if (current) { |
| 252 | if (current->mm == NULL) { |
| 253 | console_verbose(); |
| 254 | oops_in_progress = 1; |
| 255 | } |
| 256 | } |
| 257 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 258 | /* trap_c() will be called for exceptions. During exceptions |
| 259 | * processing, the pc value should be set with retx value. |
| 260 | * With this change we can cleanup some code in signal.c- TODO |
| 261 | */ |
| 262 | fp->orig_pc = fp->retx; |
| 263 | /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n", |
| 264 | trapnr, fp->ipend, fp->pc, fp->retx); */ |
| 265 | |
| 266 | /* send the appropriate signal to the user program */ |
| 267 | switch (trapnr) { |
| 268 | |
| 269 | /* This table works in conjuction with the one in ./mach-common/entry.S |
| 270 | * Some exceptions are handled there (in assembly, in exception space) |
| 271 | * Some are handled here, (in C, in interrupt space) |
| 272 | * Some, like CPLB, are handled in both, where the normal path is |
| 273 | * handled in assembly/exception space, and the error path is handled |
| 274 | * here |
| 275 | */ |
| 276 | |
| 277 | /* 0x00 - Linux Syscall, getting here is an error */ |
| 278 | /* 0x01 - userspace gdb breakpoint, handled here */ |
| 279 | case VEC_EXCPT01: |
| 280 | info.si_code = TRAP_ILLTRAP; |
| 281 | sig = SIGTRAP; |
| 282 | CHK_DEBUGGER_TRAP_MAYBE(); |
| 283 | /* Check if this is a breakpoint in kernel space */ |
| 284 | if (fp->ipend & 0xffc0) |
| 285 | return; |
| 286 | else |
| 287 | break; |
| 288 | #ifdef CONFIG_KGDB |
| 289 | case VEC_EXCPT02 : /* gdb connection */ |
| 290 | info.si_code = TRAP_ILLTRAP; |
| 291 | sig = SIGTRAP; |
| 292 | CHK_DEBUGGER_TRAP(); |
| 293 | return; |
| 294 | #else |
| 295 | /* 0x02 - User Defined, Caught by default */ |
| 296 | #endif |
Mike Frysinger | 9401e61 | 2007-07-12 11:50:43 +0800 | [diff] [blame] | 297 | /* 0x03 - User Defined, userspace stack overflow */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 298 | case VEC_EXCPT03: |
| 299 | info.si_code = SEGV_STACKFLOW; |
| 300 | sig = SIGSEGV; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 301 | printk(KERN_NOTICE EXC_0x03(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 302 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 303 | break; |
Robin Getz | 5c64e0d | 2008-10-08 14:43:47 +0800 | [diff] [blame^] | 304 | /* 0x04 - User Defined */ |
| 305 | /* 0x05 - User Defined */ |
| 306 | /* 0x06 - User Defined */ |
| 307 | /* 0x07 - User Defined */ |
| 308 | /* 0x08 - User Defined */ |
| 309 | /* 0x09 - User Defined */ |
| 310 | /* 0x0A - User Defined */ |
| 311 | /* 0x0B - User Defined */ |
| 312 | /* 0x0C - User Defined */ |
| 313 | /* 0x0D - User Defined */ |
| 314 | /* 0x0E - User Defined */ |
| 315 | /* 0x0F - User Defined */ |
| 316 | /* |
| 317 | * If we got here, it is most likely that someone was trying to use a |
| 318 | * custom exception handler, and it is not actually installed properly |
| 319 | */ |
| 320 | case VEC_EXCPT04 ... VEC_EXCPT15: |
| 321 | info.si_code = ILL_ILLPARAOP; |
| 322 | sig = SIGILL; |
| 323 | printk(KERN_NOTICE EXC_0x04(KERN_NOTICE)); |
| 324 | CHK_DEBUGGER_TRAP_MAYBE(); |
| 325 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 326 | /* 0x10 HW Single step, handled here */ |
| 327 | case VEC_STEP: |
| 328 | info.si_code = TRAP_STEP; |
| 329 | sig = SIGTRAP; |
| 330 | CHK_DEBUGGER_TRAP_MAYBE(); |
| 331 | /* Check if this is a single step in kernel space */ |
| 332 | if (fp->ipend & 0xffc0) |
| 333 | return; |
| 334 | else |
| 335 | break; |
| 336 | /* 0x11 - Trace Buffer Full, handled here */ |
| 337 | case VEC_OVFLOW: |
| 338 | info.si_code = TRAP_TRACEFLOW; |
| 339 | sig = SIGTRAP; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 340 | printk(KERN_NOTICE EXC_0x11(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 341 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 342 | break; |
| 343 | /* 0x12 - Reserved, Caught by default */ |
| 344 | /* 0x13 - Reserved, Caught by default */ |
| 345 | /* 0x14 - Reserved, Caught by default */ |
| 346 | /* 0x15 - Reserved, Caught by default */ |
| 347 | /* 0x16 - Reserved, Caught by default */ |
| 348 | /* 0x17 - Reserved, Caught by default */ |
| 349 | /* 0x18 - Reserved, Caught by default */ |
| 350 | /* 0x19 - Reserved, Caught by default */ |
| 351 | /* 0x1A - Reserved, Caught by default */ |
| 352 | /* 0x1B - Reserved, Caught by default */ |
| 353 | /* 0x1C - Reserved, Caught by default */ |
| 354 | /* 0x1D - Reserved, Caught by default */ |
| 355 | /* 0x1E - Reserved, Caught by default */ |
| 356 | /* 0x1F - Reserved, Caught by default */ |
| 357 | /* 0x20 - Reserved, Caught by default */ |
| 358 | /* 0x21 - Undefined Instruction, handled here */ |
| 359 | case VEC_UNDEF_I: |
| 360 | info.si_code = ILL_ILLOPC; |
| 361 | sig = SIGILL; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 362 | printk(KERN_NOTICE EXC_0x21(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 363 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 364 | break; |
| 365 | /* 0x22 - Illegal Instruction Combination, handled here */ |
| 366 | case VEC_ILGAL_I: |
| 367 | info.si_code = ILL_ILLPARAOP; |
| 368 | sig = SIGILL; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 369 | printk(KERN_NOTICE EXC_0x22(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 370 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 371 | break; |
Robin Getz | f26fbc4 | 2007-11-12 22:21:30 +0800 | [diff] [blame] | 372 | /* 0x23 - Data CPLB protection violation, handled here */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 373 | case VEC_CPLB_VL: |
| 374 | info.si_code = ILL_CPLB_VI; |
Robin Getz | f26fbc4 | 2007-11-12 22:21:30 +0800 | [diff] [blame] | 375 | sig = SIGBUS; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 376 | printk(KERN_NOTICE EXC_0x23(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 377 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 378 | break; |
| 379 | /* 0x24 - Data access misaligned, handled here */ |
| 380 | case VEC_MISALI_D: |
| 381 | info.si_code = BUS_ADRALN; |
| 382 | sig = SIGBUS; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 383 | printk(KERN_NOTICE EXC_0x24(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 384 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 385 | break; |
| 386 | /* 0x25 - Unrecoverable Event, handled here */ |
| 387 | case VEC_UNCOV: |
| 388 | info.si_code = ILL_ILLEXCPT; |
| 389 | sig = SIGILL; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 390 | printk(KERN_NOTICE EXC_0x25(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 391 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 392 | break; |
| 393 | /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr, |
| 394 | error case is handled here */ |
| 395 | case VEC_CPLB_M: |
| 396 | info.si_code = BUS_ADRALN; |
| 397 | sig = SIGBUS; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 398 | printk(KERN_NOTICE EXC_0x26(KERN_NOTICE)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 399 | break; |
| 400 | /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */ |
| 401 | case VEC_CPLB_MHIT: |
| 402 | info.si_code = ILL_CPLB_MULHIT; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 403 | sig = SIGSEGV; |
Mike Frysinger | c6c6f75 | 2008-05-17 16:18:08 +0800 | [diff] [blame] | 404 | #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO |
Mike Frysinger | bd628bd | 2008-06-03 12:23:45 +0800 | [diff] [blame] | 405 | if (saved_dcplb_fault_addr < FIXED_CODE_START) |
Mike Frysinger | c6c6f75 | 2008-05-17 16:18:08 +0800 | [diff] [blame] | 406 | printk(KERN_NOTICE "NULL pointer access\n"); |
| 407 | else |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 408 | #endif |
Mike Frysinger | c6c6f75 | 2008-05-17 16:18:08 +0800 | [diff] [blame] | 409 | printk(KERN_NOTICE EXC_0x27(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 410 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 411 | break; |
| 412 | /* 0x28 - Emulation Watchpoint, handled here */ |
| 413 | case VEC_WATCH: |
| 414 | info.si_code = TRAP_WATCHPT; |
| 415 | sig = SIGTRAP; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 416 | pr_debug(EXC_0x28(KERN_DEBUG)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 417 | CHK_DEBUGGER_TRAP_MAYBE(); |
| 418 | /* Check if this is a watchpoint in kernel space */ |
| 419 | if (fp->ipend & 0xffc0) |
| 420 | return; |
| 421 | else |
| 422 | break; |
| 423 | #ifdef CONFIG_BF535 |
| 424 | /* 0x29 - Instruction fetch access error (535 only) */ |
| 425 | case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */ |
| 426 | info.si_code = BUS_OPFETCH; |
| 427 | sig = SIGBUS; |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 428 | printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n"); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 429 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 430 | break; |
| 431 | #else |
| 432 | /* 0x29 - Reserved, Caught by default */ |
| 433 | #endif |
| 434 | /* 0x2A - Instruction fetch misaligned, handled here */ |
| 435 | case VEC_MISALI_I: |
| 436 | info.si_code = BUS_ADRALN; |
| 437 | sig = SIGBUS; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 438 | printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 439 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 440 | break; |
Robin Getz | f26fbc4 | 2007-11-12 22:21:30 +0800 | [diff] [blame] | 441 | /* 0x2B - Instruction CPLB protection violation, handled here */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 442 | case VEC_CPLB_I_VL: |
| 443 | info.si_code = ILL_CPLB_VI; |
Robin Getz | f26fbc4 | 2007-11-12 22:21:30 +0800 | [diff] [blame] | 444 | sig = SIGBUS; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 445 | printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 446 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 447 | break; |
| 448 | /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */ |
| 449 | case VEC_CPLB_I_M: |
| 450 | info.si_code = ILL_CPLB_MISS; |
| 451 | sig = SIGBUS; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 452 | printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 453 | break; |
| 454 | /* 0x2D - Instruction CPLB Multiple Hits, handled here */ |
| 455 | case VEC_CPLB_I_MHIT: |
| 456 | info.si_code = ILL_CPLB_MULHIT; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 457 | sig = SIGSEGV; |
Mike Frysinger | c6c6f75 | 2008-05-17 16:18:08 +0800 | [diff] [blame] | 458 | #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO |
Mike Frysinger | bd628bd | 2008-06-03 12:23:45 +0800 | [diff] [blame] | 459 | if (saved_icplb_fault_addr < FIXED_CODE_START) |
Mike Frysinger | c6c6f75 | 2008-05-17 16:18:08 +0800 | [diff] [blame] | 460 | printk(KERN_NOTICE "Jump to NULL address\n"); |
| 461 | else |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 462 | #endif |
Mike Frysinger | c6c6f75 | 2008-05-17 16:18:08 +0800 | [diff] [blame] | 463 | printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 464 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 465 | break; |
| 466 | /* 0x2E - Illegal use of Supervisor Resource, handled here */ |
| 467 | case VEC_ILL_RES: |
| 468 | info.si_code = ILL_PRVOPC; |
| 469 | sig = SIGILL; |
Robin Getz | 569a50c | 2007-11-21 16:35:57 +0800 | [diff] [blame] | 470 | printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 471 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 472 | break; |
| 473 | /* 0x2F - Reserved, Caught by default */ |
| 474 | /* 0x30 - Reserved, Caught by default */ |
| 475 | /* 0x31 - Reserved, Caught by default */ |
| 476 | /* 0x32 - Reserved, Caught by default */ |
| 477 | /* 0x33 - Reserved, Caught by default */ |
| 478 | /* 0x34 - Reserved, Caught by default */ |
| 479 | /* 0x35 - Reserved, Caught by default */ |
| 480 | /* 0x36 - Reserved, Caught by default */ |
| 481 | /* 0x37 - Reserved, Caught by default */ |
| 482 | /* 0x38 - Reserved, Caught by default */ |
| 483 | /* 0x39 - Reserved, Caught by default */ |
| 484 | /* 0x3A - Reserved, Caught by default */ |
| 485 | /* 0x3B - Reserved, Caught by default */ |
| 486 | /* 0x3C - Reserved, Caught by default */ |
| 487 | /* 0x3D - Reserved, Caught by default */ |
| 488 | /* 0x3E - Reserved, Caught by default */ |
| 489 | /* 0x3F - Reserved, Caught by default */ |
Robin Getz | 13fe24f | 2008-01-27 15:38:56 +0800 | [diff] [blame] | 490 | case VEC_HWERR: |
| 491 | info.si_code = BUS_ADRALN; |
| 492 | sig = SIGBUS; |
| 493 | switch (fp->seqstat & SEQSTAT_HWERRCAUSE) { |
| 494 | /* System MMR Error */ |
| 495 | case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR): |
| 496 | info.si_code = BUS_ADRALN; |
| 497 | sig = SIGBUS; |
| 498 | printk(KERN_NOTICE HWC_x2(KERN_NOTICE)); |
| 499 | break; |
| 500 | /* External Memory Addressing Error */ |
| 501 | case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR): |
| 502 | info.si_code = BUS_ADRERR; |
| 503 | sig = SIGBUS; |
| 504 | printk(KERN_NOTICE HWC_x3(KERN_NOTICE)); |
| 505 | break; |
| 506 | /* Performance Monitor Overflow */ |
| 507 | case (SEQSTAT_HWERRCAUSE_PERF_FLOW): |
| 508 | printk(KERN_NOTICE HWC_x12(KERN_NOTICE)); |
| 509 | break; |
| 510 | /* RAISE 5 instruction */ |
| 511 | case (SEQSTAT_HWERRCAUSE_RAISE_5): |
| 512 | printk(KERN_NOTICE HWC_x18(KERN_NOTICE)); |
| 513 | break; |
| 514 | default: /* Reserved */ |
| 515 | printk(KERN_NOTICE HWC_default(KERN_NOTICE)); |
| 516 | break; |
| 517 | } |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 518 | CHK_DEBUGGER_TRAP_MAYBE(); |
Robin Getz | 13fe24f | 2008-01-27 15:38:56 +0800 | [diff] [blame] | 519 | break; |
Robin Getz | 5c64e0d | 2008-10-08 14:43:47 +0800 | [diff] [blame^] | 520 | /* |
| 521 | * We should be handling all known exception types above, |
| 522 | * if we get here we hit a reserved one, so panic |
| 523 | */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 524 | default: |
Robin Getz | 5c64e0d | 2008-10-08 14:43:47 +0800 | [diff] [blame^] | 525 | oops_in_progress = 1; |
| 526 | info.si_code = ILL_ILLPARAOP; |
| 527 | sig = SIGILL; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 528 | printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n", |
| 529 | (fp->seqstat & SEQSTAT_EXCAUSE)); |
Sonic Zhang | a5ac012 | 2008-10-13 14:07:19 +0800 | [diff] [blame] | 530 | CHK_DEBUGGER_TRAP_MAYBE(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 531 | break; |
| 532 | } |
| 533 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 534 | BUG_ON(sig == 0); |
| 535 | |
| 536 | if (sig != SIGTRAP) { |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 537 | unsigned long *stack; |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 538 | dump_bfin_process(fp); |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 539 | dump_bfin_mem(fp); |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 540 | show_regs(fp); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 541 | |
| 542 | /* Print out the trace buffer if it makes sense */ |
| 543 | #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE |
| 544 | if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M) |
| 545 | printk(KERN_NOTICE "No trace since you do not have " |
| 546 | "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n" |
| 547 | KERN_NOTICE "\n"); |
| 548 | else |
| 549 | #endif |
| 550 | dump_bfin_trace_buffer(); |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 551 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 552 | if (oops_in_progress) { |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 553 | /* Dump the current kernel stack */ |
| 554 | printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n"); |
| 555 | show_stack(current, NULL); |
| 556 | |
Robin Getz | aee3a29 | 2008-01-11 16:53:00 +0800 | [diff] [blame] | 557 | print_modules(); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 558 | #ifndef CONFIG_ACCESS_CHECK |
Robin Getz | 90c7f46 | 2007-11-18 00:35:33 +0800 | [diff] [blame] | 559 | printk(KERN_EMERG "Please turn on " |
| 560 | "CONFIG_ACCESS_CHECK\n"); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 561 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 562 | panic("Kernel exception"); |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 563 | } else { |
| 564 | /* Dump the user space stack */ |
| 565 | stack = (unsigned long *)rdusp(); |
| 566 | printk(KERN_NOTICE "Userspace Stack\n"); |
| 567 | show_stack(NULL, stack); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 568 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 569 | } |
Robin Getz | fb32291 | 2007-11-21 16:38:05 +0800 | [diff] [blame] | 570 | |
Robin Getz | ce3afa1 | 2007-10-09 17:28:36 +0800 | [diff] [blame] | 571 | info.si_signo = sig; |
| 572 | info.si_errno = 0; |
Mike Frysinger | 0ddeeca | 2008-03-07 02:37:41 +0800 | [diff] [blame] | 573 | info.si_addr = (void __user *)fp->pc; |
Robin Getz | ce3afa1 | 2007-10-09 17:28:36 +0800 | [diff] [blame] | 574 | force_sig_info(sig, &info, current); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 575 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 576 | trace_buffer_restore(j); |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | /* Typical exception handling routines */ |
| 581 | |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 582 | #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1) |
| 583 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 584 | /* |
| 585 | * Similar to get_user, do some address checking, then dereference |
| 586 | * Return true on sucess, false on bad address |
| 587 | */ |
| 588 | bool get_instruction(unsigned short *val, unsigned short *address) |
| 589 | { |
| 590 | |
| 591 | unsigned long addr; |
| 592 | |
| 593 | addr = (unsigned long)address; |
| 594 | |
| 595 | /* Check for odd addresses */ |
| 596 | if (addr & 0x1) |
| 597 | return false; |
| 598 | |
| 599 | /* Check that things do not wrap around */ |
| 600 | if (addr > (addr + 2)) |
| 601 | return false; |
| 602 | |
| 603 | /* |
| 604 | * Since we are in exception context, we need to do a little address checking |
| 605 | * We need to make sure we are only accessing valid memory, and |
| 606 | * we don't read something in the async space that can hang forever |
| 607 | */ |
| 608 | if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) || |
Mike Frysinger | 07aa7be | 2008-08-13 16:16:11 +0800 | [diff] [blame] | 609 | #if L2_LENGTH != 0 |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 610 | (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) || |
| 611 | #endif |
| 612 | (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) || |
| 613 | #if L1_DATA_A_LENGTH != 0 |
| 614 | (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) || |
| 615 | #endif |
| 616 | #if L1_DATA_B_LENGTH != 0 |
| 617 | (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) || |
| 618 | #endif |
| 619 | (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) || |
| 620 | (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) && |
| 621 | addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) || |
| 622 | (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) && |
| 623 | addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) || |
| 624 | (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) && |
| 625 | addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) || |
| 626 | (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) && |
| 627 | addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) { |
| 628 | *val = *address; |
| 629 | return true; |
| 630 | } |
| 631 | |
| 632 | #if L1_CODE_LENGTH != 0 |
| 633 | if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) { |
| 634 | dma_memcpy(val, address, 2); |
| 635 | return true; |
| 636 | } |
| 637 | #endif |
| 638 | |
| 639 | |
| 640 | return false; |
| 641 | } |
| 642 | |
Robin Getz | d3d0ac2 | 2008-08-06 17:49:27 +0800 | [diff] [blame] | 643 | /* |
| 644 | * decode the instruction if we are printing out the trace, as it |
| 645 | * makes things easier to follow, without running it through objdump |
| 646 | * These are the normal instructions which cause change of flow, which |
| 647 | * would be at the source of the trace buffer |
| 648 | */ |
| 649 | void decode_instruction(unsigned short *address) |
| 650 | { |
| 651 | unsigned short opcode; |
| 652 | |
| 653 | if (get_instruction(&opcode, address)) { |
| 654 | if (opcode == 0x0010) |
| 655 | printk("RTS"); |
| 656 | else if (opcode == 0x0011) |
| 657 | printk("RTI"); |
| 658 | else if (opcode == 0x0012) |
| 659 | printk("RTX"); |
| 660 | else if (opcode >= 0x0050 && opcode <= 0x0057) |
| 661 | printk("JUMP (P%i)", opcode & 7); |
| 662 | else if (opcode >= 0x0060 && opcode <= 0x0067) |
| 663 | printk("CALL (P%i)", opcode & 7); |
| 664 | else if (opcode >= 0x0070 && opcode <= 0x0077) |
| 665 | printk("CALL (PC+P%i)", opcode & 7); |
| 666 | else if (opcode >= 0x0080 && opcode <= 0x0087) |
| 667 | printk("JUMP (PC+P%i)", opcode & 7); |
| 668 | else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF)) |
| 669 | printk("IF !CC JUMP"); |
| 670 | else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff)) |
| 671 | printk("IF CC JUMP"); |
| 672 | else if (opcode >= 0x2000 && opcode <= 0x2fff) |
| 673 | printk("JUMP.S"); |
| 674 | else if (opcode >= 0xe080 && opcode <= 0xe0ff) |
| 675 | printk("LSETUP"); |
| 676 | else if (opcode >= 0xe200 && opcode <= 0xe2ff) |
| 677 | printk("JUMP.L"); |
| 678 | else if (opcode >= 0xe300 && opcode <= 0xe3ff) |
| 679 | printk("CALL pcrel"); |
| 680 | else |
| 681 | printk("0x%04x", opcode); |
| 682 | } |
| 683 | |
| 684 | } |
| 685 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 686 | void dump_bfin_trace_buffer(void) |
| 687 | { |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 688 | #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON |
| 689 | int tflags, i = 0; |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 690 | char buf[150]; |
Robin Getz | d3d0ac2 | 2008-08-06 17:49:27 +0800 | [diff] [blame] | 691 | unsigned short *addr; |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 692 | #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND |
| 693 | int j, index; |
| 694 | #endif |
| 695 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 696 | trace_buffer_save(tflags); |
| 697 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 698 | printk(KERN_NOTICE "Hardware Trace:\n"); |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 699 | |
Robin Getz | d3d0ac2 | 2008-08-06 17:49:27 +0800 | [diff] [blame] | 700 | #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND |
| 701 | printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n"); |
| 702 | #endif |
| 703 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 704 | if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) { |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 705 | for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) { |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 706 | decode_address(buf, (unsigned long)bfin_read_TBUF()); |
| 707 | printk(KERN_NOTICE "%4i Target : %s\n", i, buf); |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 708 | addr = (unsigned short *)bfin_read_TBUF(); |
| 709 | decode_address(buf, (unsigned long)addr); |
| 710 | printk(KERN_NOTICE " Source : %s ", buf); |
Robin Getz | d3d0ac2 | 2008-08-06 17:49:27 +0800 | [diff] [blame] | 711 | decode_instruction(addr); |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 712 | printk("\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 716 | #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND |
| 717 | if (trace_buff_offset) |
Robin Getz | d3d0ac2 | 2008-08-06 17:49:27 +0800 | [diff] [blame] | 718 | index = trace_buff_offset / 4; |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 719 | else |
| 720 | index = EXPAND_LEN; |
| 721 | |
| 722 | j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128; |
| 723 | while (j) { |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 724 | decode_address(buf, software_trace_buff[index]); |
| 725 | printk(KERN_NOTICE "%4i Target : %s\n", i, buf); |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 726 | index -= 1; |
| 727 | if (index < 0 ) |
| 728 | index = EXPAND_LEN; |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 729 | decode_address(buf, software_trace_buff[index]); |
Robin Getz | d3d0ac2 | 2008-08-06 17:49:27 +0800 | [diff] [blame] | 730 | printk(KERN_NOTICE " Source : %s ", buf); |
| 731 | decode_instruction((unsigned short *)software_trace_buff[index]); |
| 732 | printk("\n"); |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 733 | index -= 1; |
| 734 | if (index < 0) |
| 735 | index = EXPAND_LEN; |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 736 | j--; |
| 737 | i++; |
| 738 | } |
| 739 | #endif |
| 740 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 741 | trace_buffer_restore(tflags); |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 742 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 743 | } |
| 744 | EXPORT_SYMBOL(dump_bfin_trace_buffer); |
| 745 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 746 | /* |
| 747 | * Checks to see if the address pointed to is either a |
| 748 | * 16-bit CALL instruction, or a 32-bit CALL instruction |
| 749 | */ |
| 750 | bool is_bfin_call(unsigned short *addr) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 751 | { |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 752 | unsigned short opcode = 0, *ins_addr; |
| 753 | ins_addr = (unsigned short *)addr; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 754 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 755 | if (!get_instruction(&opcode, ins_addr)) |
| 756 | return false; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 757 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 758 | if ((opcode >= 0x0060 && opcode <= 0x0067) || |
| 759 | (opcode >= 0x0070 && opcode <= 0x0077)) |
| 760 | return true; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 761 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 762 | ins_addr--; |
| 763 | if (!get_instruction(&opcode, ins_addr)) |
| 764 | return false; |
| 765 | |
| 766 | if (opcode >= 0xE300 && opcode <= 0xE3FF) |
| 767 | return true; |
| 768 | |
| 769 | return false; |
| 770 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 771 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 772 | void show_stack(struct task_struct *task, unsigned long *stack) |
| 773 | { |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 774 | unsigned int *addr, *endstack, *fp = 0, *frame; |
| 775 | unsigned short *ins_addr; |
| 776 | char buf[150]; |
| 777 | unsigned int i, j, ret_addr, frame_no = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 778 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 779 | /* |
| 780 | * If we have been passed a specific stack, use that one otherwise |
| 781 | * if we have been passed a task structure, use that, otherwise |
| 782 | * use the stack of where the variable "stack" exists |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 783 | */ |
| 784 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 785 | if (stack == NULL) { |
| 786 | if (task) { |
| 787 | /* We know this is a kernel stack, so this is the start/end */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 788 | stack = (unsigned long *)task->thread.ksp; |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 789 | endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE); |
| 790 | } else { |
| 791 | /* print out the existing stack info */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 792 | stack = (unsigned long *)&stack; |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 793 | endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack); |
| 794 | } |
| 795 | } else |
| 796 | endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack); |
| 797 | |
| 798 | decode_address(buf, (unsigned int)stack); |
| 799 | printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf); |
| 800 | addr = (unsigned int *)((unsigned int)stack & ~0x3F); |
| 801 | |
| 802 | /* First thing is to look for a frame pointer */ |
| 803 | for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0; |
| 804 | addr < endstack; addr++, i++) { |
| 805 | if (*addr & 0x1) |
| 806 | continue; |
| 807 | ins_addr = (unsigned short *)*addr; |
| 808 | ins_addr--; |
| 809 | if (is_bfin_call(ins_addr)) |
| 810 | fp = addr - 1; |
| 811 | |
| 812 | if (fp) { |
| 813 | /* Let's check to see if it is a frame pointer */ |
| 814 | while (fp >= (addr - 1) && fp < endstack && fp) |
| 815 | fp = (unsigned int *)*fp; |
| 816 | if (fp == 0 || fp == endstack) { |
| 817 | fp = addr - 1; |
| 818 | break; |
| 819 | } |
| 820 | fp = 0; |
| 821 | } |
| 822 | } |
| 823 | if (fp) { |
| 824 | frame = fp; |
| 825 | printk(" FP: (0x%p)\n", fp); |
| 826 | } else |
| 827 | frame = 0; |
| 828 | |
| 829 | /* |
| 830 | * Now that we think we know where things are, we |
| 831 | * walk the stack again, this time printing things out |
| 832 | * incase there is no frame pointer, we still look for |
| 833 | * valid return addresses |
| 834 | */ |
| 835 | |
| 836 | /* First time print out data, next time, print out symbols */ |
| 837 | for (j = 0; j <= 1; j++) { |
| 838 | if (j) |
| 839 | printk(KERN_NOTICE "Return addresses in stack:\n"); |
| 840 | else |
| 841 | printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack); |
| 842 | |
| 843 | fp = frame; |
| 844 | frame_no = 0; |
| 845 | |
| 846 | for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0; |
| 847 | addr <= endstack; addr++, i++) { |
| 848 | |
| 849 | ret_addr = 0; |
| 850 | if (!j && i % 8 == 0) |
| 851 | printk("\n" KERN_NOTICE "%p:",addr); |
| 852 | |
| 853 | /* if it is an odd address, or zero, just skip it */ |
| 854 | if (*addr & 0x1 || !*addr) |
| 855 | goto print; |
| 856 | |
| 857 | ins_addr = (unsigned short *)*addr; |
| 858 | |
| 859 | /* Go back one instruction, and see if it is a CALL */ |
| 860 | ins_addr--; |
| 861 | ret_addr = is_bfin_call(ins_addr); |
| 862 | print: |
| 863 | if (!j && stack == (unsigned long *)addr) |
| 864 | printk("[%08x]", *addr); |
| 865 | else if (ret_addr) |
| 866 | if (j) { |
| 867 | decode_address(buf, (unsigned int)*addr); |
| 868 | if (frame == addr) { |
| 869 | printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf); |
| 870 | continue; |
| 871 | } |
| 872 | printk(KERN_NOTICE " address : %s\n", buf); |
| 873 | } else |
| 874 | printk("<%08x>", *addr); |
| 875 | else if (fp == addr) { |
| 876 | if (j) |
| 877 | frame = addr+1; |
| 878 | else |
| 879 | printk("(%08x)", *addr); |
| 880 | |
| 881 | fp = (unsigned int *)*addr; |
| 882 | frame_no++; |
| 883 | |
| 884 | } else if (!j) |
| 885 | printk(" %08x ", *addr); |
| 886 | } |
| 887 | if (!j) |
| 888 | printk("\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | void dump_stack(void) |
| 894 | { |
| 895 | unsigned long stack; |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 896 | #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 897 | int tflags; |
Robin Getz | 518039b | 2007-07-25 11:03:28 +0800 | [diff] [blame] | 898 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 899 | trace_buffer_save(tflags); |
| 900 | dump_bfin_trace_buffer(); |
| 901 | show_stack(current, &stack); |
| 902 | trace_buffer_restore(tflags); |
| 903 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 904 | EXPORT_SYMBOL(dump_stack); |
| 905 | |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 906 | void dump_bfin_process(struct pt_regs *fp) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 907 | { |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 908 | /* We should be able to look at fp->ipend, but we don't push it on the |
| 909 | * stack all the time, so do this until we fix that */ |
| 910 | unsigned int context = bfin_read_IPEND(); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 911 | |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 912 | if (oops_in_progress) |
| 913 | printk(KERN_EMERG "Kernel OOPS in progress\n"); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 914 | |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 915 | if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR) |
| 916 | printk(KERN_NOTICE "HW Error context\n"); |
| 917 | else if (context & 0x0020) |
Mike Frysinger | a3acf52 | 2008-02-02 15:45:27 +0800 | [diff] [blame] | 918 | printk(KERN_NOTICE "Deferred Exception context\n"); |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 919 | else if (context & 0x3FC0) |
| 920 | printk(KERN_NOTICE "Interrupt context\n"); |
| 921 | else if (context & 0x4000) |
| 922 | printk(KERN_NOTICE "Deferred Interrupt context\n"); |
| 923 | else if (context & 0x8000) |
| 924 | printk(KERN_NOTICE "Kernel process context\n"); |
| 925 | |
Robin Getz | 9a62ca4 | 2008-03-26 09:15:58 +0800 | [diff] [blame] | 926 | /* Because we are crashing, and pointers could be bad, we check things |
| 927 | * pretty closely before we use them |
| 928 | */ |
Robin Getz | 7f1c906 | 2008-04-25 03:36:31 +0800 | [diff] [blame] | 929 | if ((unsigned long)current >= FIXED_CODE_START && |
| 930 | !((unsigned long)current & 0x3) && current->pid) { |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 931 | printk(KERN_NOTICE "CURRENT PROCESS:\n"); |
Robin Getz | 9a62ca4 | 2008-03-26 09:15:58 +0800 | [diff] [blame] | 932 | if (current->comm >= (char *)FIXED_CODE_START) |
| 933 | printk(KERN_NOTICE "COMM=%s PID=%d\n", |
| 934 | current->comm, current->pid); |
| 935 | else |
| 936 | printk(KERN_NOTICE "COMM= invalid\n"); |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 937 | |
Robin Getz | 9a62ca4 | 2008-03-26 09:15:58 +0800 | [diff] [blame] | 938 | if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START) |
| 939 | printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n" |
| 940 | KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n" |
| 941 | KERN_NOTICE "\n", |
| 942 | (void *)current->mm->start_code, |
| 943 | (void *)current->mm->end_code, |
| 944 | (void *)current->mm->start_data, |
| 945 | (void *)current->mm->end_data, |
| 946 | (void *)current->mm->end_data, |
| 947 | (void *)current->mm->brk, |
| 948 | (void *)current->mm->start_stack); |
| 949 | else |
| 950 | printk(KERN_NOTICE "invalid mm\n"); |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 951 | } else |
| 952 | printk(KERN_NOTICE "\n" KERN_NOTICE |
| 953 | "No Valid process in current context\n"); |
| 954 | } |
| 955 | |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 956 | void dump_bfin_mem(struct pt_regs *fp) |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 957 | { |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 958 | unsigned short *addr, *erraddr, val = 0, err = 0; |
| 959 | char sti = 0, buf[6]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 960 | |
Bernd Schmidt | 5d750b9 | 2008-04-25 05:02:33 +0800 | [diff] [blame] | 961 | erraddr = (void *)fp->pc; |
Robin Getz | c5d88d9 | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 962 | |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 963 | printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr); |
| 964 | |
| 965 | for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10; |
| 966 | addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10; |
| 967 | addr++) { |
| 968 | if (!((unsigned long)addr & 0xF)) |
| 969 | printk("\n" KERN_NOTICE "0x%p: ", addr); |
| 970 | |
Robin Getz | f09630b | 2008-07-26 19:45:46 +0800 | [diff] [blame] | 971 | if (get_instruction(&val, addr)) { |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 972 | val = 0; |
| 973 | sprintf(buf, "????"); |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 974 | } else |
| 975 | sprintf(buf, "%04x", val); |
| 976 | |
| 977 | if (addr == erraddr) { |
| 978 | printk("[%s]", buf); |
| 979 | err = val; |
| 980 | } else |
| 981 | printk(" %s ", buf); |
| 982 | |
| 983 | /* Do any previous instructions turn on interrupts? */ |
| 984 | if (addr <= erraddr && /* in the past */ |
| 985 | ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */ |
| 986 | val == 0x017b)) /* [SP++] = RETI */ |
| 987 | sti = 1; |
| 988 | } |
| 989 | |
| 990 | printk("\n"); |
| 991 | |
| 992 | /* Hardware error interrupts can be deferred */ |
| 993 | if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR && |
| 994 | oops_in_progress)){ |
| 995 | printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 996 | #ifndef CONFIG_DEBUG_HWERR |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 997 | printk(KERN_NOTICE "The remaining message may be meaningless\n" |
| 998 | KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a" |
| 999 | " better idea where it came from\n"); |
| 1000 | #else |
| 1001 | /* If we are handling only one peripheral interrupt |
| 1002 | * and current mm and pid are valid, and the last error |
| 1003 | * was in that user space process's text area |
| 1004 | * print it out - because that is where the problem exists |
| 1005 | */ |
| 1006 | if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) && |
| 1007 | (current->pid && current->mm)) { |
| 1008 | /* And the last RETI points to the current userspace context */ |
| 1009 | if ((fp + 1)->pc >= current->mm->start_code && |
| 1010 | (fp + 1)->pc <= current->mm->end_code) { |
| 1011 | printk(KERN_NOTICE "It might be better to look around here : \n"); |
| 1012 | printk(KERN_NOTICE "-------------------------------------------\n"); |
| 1013 | show_regs(fp + 1); |
| 1014 | printk(KERN_NOTICE "-------------------------------------------\n"); |
| 1015 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1016 | } |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 1017 | #endif |
| 1018 | } |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | void show_regs(struct pt_regs *fp) |
| 1022 | { |
| 1023 | char buf [150]; |
Robin Getz | d8f66c8 | 2007-12-24 15:27:56 +0800 | [diff] [blame] | 1024 | struct irqaction *action; |
| 1025 | unsigned int i; |
| 1026 | unsigned long flags; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1027 | |
Robin Getz | aee3a29 | 2008-01-11 16:53:00 +0800 | [diff] [blame] | 1028 | printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted()); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 1029 | printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n", |
| 1030 | (long)fp->seqstat, fp->ipend, fp->syscfg); |
Robin Getz | 13fe24f | 2008-01-27 15:38:56 +0800 | [diff] [blame] | 1031 | printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n", |
| 1032 | (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14); |
| 1033 | printk(KERN_NOTICE " EXCAUSE : 0x%lx\n", |
| 1034 | fp->seqstat & SEQSTAT_EXCAUSE); |
Robin Getz | d8f66c8 | 2007-12-24 15:27:56 +0800 | [diff] [blame] | 1035 | for (i = 6; i <= 15 ; i++) { |
| 1036 | if (fp->ipend & (1 << i)) { |
| 1037 | decode_address(buf, bfin_read32(EVT0 + 4*i)); |
| 1038 | printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | /* if no interrupts are going off, don't print this out */ |
| 1043 | if (fp->ipend & ~0x3F) { |
| 1044 | for (i = 0; i < (NR_IRQS - 1); i++) { |
| 1045 | spin_lock_irqsave(&irq_desc[i].lock, flags); |
| 1046 | action = irq_desc[i].action; |
| 1047 | if (!action) |
| 1048 | goto unlock; |
| 1049 | |
| 1050 | decode_address(buf, (unsigned int)action->handler); |
| 1051 | printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf); |
| 1052 | for (action = action->next; action; action = action->next) { |
| 1053 | decode_address(buf, (unsigned int)action->handler); |
| 1054 | printk(", %s", buf); |
| 1055 | } |
| 1056 | printk("\n"); |
| 1057 | unlock: |
| 1058 | spin_unlock_irqrestore(&irq_desc[i].lock, flags); |
| 1059 | } |
| 1060 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1061 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 1062 | decode_address(buf, fp->rete); |
| 1063 | printk(KERN_NOTICE " RETE: %s\n", buf); |
| 1064 | decode_address(buf, fp->retn); |
| 1065 | printk(KERN_NOTICE " RETN: %s\n", buf); |
| 1066 | decode_address(buf, fp->retx); |
| 1067 | printk(KERN_NOTICE " RETX: %s\n", buf); |
| 1068 | decode_address(buf, fp->rets); |
| 1069 | printk(KERN_NOTICE " RETS: %s\n", buf); |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 1070 | decode_address(buf, fp->pc); |
Robin Getz | 13fe24f | 2008-01-27 15:38:56 +0800 | [diff] [blame] | 1071 | printk(KERN_NOTICE " PC : %s\n", buf); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1072 | |
Robin Getz | 13fe24f | 2008-01-27 15:38:56 +0800 | [diff] [blame] | 1073 | if (((long)fp->seqstat & SEQSTAT_EXCAUSE) && |
| 1074 | (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) { |
Bernd Schmidt | 5d750b9 | 2008-04-25 05:02:33 +0800 | [diff] [blame] | 1075 | decode_address(buf, saved_dcplb_fault_addr); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 1076 | printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf); |
Bernd Schmidt | 5d750b9 | 2008-04-25 05:02:33 +0800 | [diff] [blame] | 1077 | decode_address(buf, saved_icplb_fault_addr); |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 1078 | printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 1081 | printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n"); |
| 1082 | printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n", |
| 1083 | fp->r0, fp->r1, fp->r2, fp->r3); |
| 1084 | printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n", |
| 1085 | fp->r4, fp->r5, fp->r6, fp->r7); |
| 1086 | printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n", |
| 1087 | fp->p0, fp->p1, fp->p2, fp->p3); |
| 1088 | printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n", |
| 1089 | fp->p4, fp->p5, fp->fp, (long)fp); |
| 1090 | printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n", |
| 1091 | fp->lb0, fp->lt0, fp->lc0); |
| 1092 | printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n", |
| 1093 | fp->lb1, fp->lt1, fp->lc1); |
| 1094 | printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n", |
| 1095 | fp->b0, fp->l0, fp->m0, fp->i0); |
| 1096 | printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n", |
| 1097 | fp->b1, fp->l1, fp->m1, fp->i1); |
| 1098 | printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n", |
| 1099 | fp->b2, fp->l2, fp->m2, fp->i2); |
| 1100 | printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n", |
| 1101 | fp->b3, fp->l3, fp->m3, fp->i3); |
| 1102 | printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n", |
| 1103 | fp->a0w, fp->a0x, fp->a1w, fp->a1x); |
| 1104 | |
| 1105 | printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n", |
| 1106 | rdusp(), fp->astat); |
| 1107 | |
| 1108 | printk(KERN_NOTICE "\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1 |
| 1112 | asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text)); |
| 1113 | #endif |
| 1114 | |
| 1115 | asmlinkage int sys_bfin_spinlock(int *spinlock) |
| 1116 | { |
| 1117 | int ret = 0; |
| 1118 | int tmp = 0; |
| 1119 | |
| 1120 | local_irq_disable(); |
| 1121 | ret = get_user(tmp, spinlock); |
| 1122 | if (ret == 0) { |
| 1123 | if (tmp) |
| 1124 | ret = 1; |
| 1125 | tmp = 1; |
| 1126 | put_user(tmp, spinlock); |
| 1127 | } |
| 1128 | local_irq_enable(); |
| 1129 | return ret; |
| 1130 | } |
| 1131 | |
Mike Frysinger | 1ffe664 | 2007-08-05 17:14:04 +0800 | [diff] [blame] | 1132 | int bfin_request_exception(unsigned int exception, void (*handler)(void)) |
| 1133 | { |
| 1134 | void (*curr_handler)(void); |
| 1135 | |
| 1136 | if (exception > 0x3F) |
| 1137 | return -EINVAL; |
| 1138 | |
| 1139 | curr_handler = ex_table[exception]; |
| 1140 | |
| 1141 | if (curr_handler != ex_replaceable) |
| 1142 | return -EBUSY; |
| 1143 | |
| 1144 | ex_table[exception] = handler; |
| 1145 | |
| 1146 | return 0; |
| 1147 | } |
| 1148 | EXPORT_SYMBOL(bfin_request_exception); |
| 1149 | |
| 1150 | int bfin_free_exception(unsigned int exception, void (*handler)(void)) |
| 1151 | { |
| 1152 | void (*curr_handler)(void); |
| 1153 | |
| 1154 | if (exception > 0x3F) |
| 1155 | return -EINVAL; |
| 1156 | |
| 1157 | curr_handler = ex_table[exception]; |
| 1158 | |
| 1159 | if (curr_handler != handler) |
| 1160 | return -EBUSY; |
| 1161 | |
| 1162 | ex_table[exception] = ex_replaceable; |
| 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | EXPORT_SYMBOL(bfin_free_exception); |
| 1167 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1168 | void panic_cplb_error(int cplb_panic, struct pt_regs *fp) |
| 1169 | { |
| 1170 | switch (cplb_panic) { |
| 1171 | case CPLB_NO_UNLOCKED: |
| 1172 | printk(KERN_EMERG "All CPLBs are locked\n"); |
| 1173 | break; |
| 1174 | case CPLB_PROT_VIOL: |
| 1175 | return; |
| 1176 | case CPLB_NO_ADDR_MATCH: |
| 1177 | return; |
| 1178 | case CPLB_UNKNOWN_ERR: |
| 1179 | printk(KERN_EMERG "Unknown CPLB Exception\n"); |
| 1180 | break; |
| 1181 | } |
| 1182 | |
Robin Getz | 226eb1e | 2007-10-29 17:59:07 +0800 | [diff] [blame] | 1183 | oops_in_progress = 1; |
| 1184 | |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 1185 | dump_bfin_process(fp); |
Robin Getz | b03b08b | 2007-12-23 22:57:01 +0800 | [diff] [blame] | 1186 | dump_bfin_mem(fp); |
Mike Frysinger | 49dce91 | 2007-11-21 16:46:49 +0800 | [diff] [blame] | 1187 | show_regs(fp); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1188 | dump_stack(); |
| 1189 | panic("Unrecoverable event\n"); |
| 1190 | } |