Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 1 | /* |
| 2 | * 'traps.c' handles hardware traps and faults after we have saved some |
| 3 | * state in 'entry.S'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * SuperH version: Copyright (C) 1999 Niibe Yutaka |
| 6 | * Copyright (C) 2000 Philipp Rumpf |
| 7 | * Copyright (C) 2000 David Howells |
Paul Mundt | 3a2e117 | 2007-05-01 16:33:10 +0900 | [diff] [blame] | 8 | * Copyright (C) 2002 - 2007 Paul Mundt |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General Public |
| 11 | * License. See the file "COPYING" in the main directory of this archive |
| 12 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/kallsyms.h> |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 20 | #include <linux/io.h> |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 21 | #include <linux/bug.h> |
Paul Mundt | 9b8c90e | 2006-12-06 11:07:51 +0900 | [diff] [blame] | 22 | #include <linux/debug_locks.h> |
Paul Mundt | b118ca5 | 2007-05-09 10:55:38 +0900 | [diff] [blame^] | 23 | #include <linux/kdebug.h> |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 24 | #include <linux/limits.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/system.h> |
| 26 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #ifdef CONFIG_SH_KGDB |
| 29 | #include <asm/kgdb.h> |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 30 | #define CHK_REMOTE_DEBUG(regs) \ |
| 31 | { \ |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 32 | if (kgdb_debug_hook && !user_mode(regs))\ |
| 33 | (*kgdb_debug_hook)(regs); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } |
| 35 | #else |
| 36 | #define CHK_REMOTE_DEBUG(regs) |
| 37 | #endif |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #ifdef CONFIG_CPU_SH2 |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 40 | # define TRAP_RESERVED_INST 4 |
| 41 | # define TRAP_ILLEGAL_SLOT_INST 6 |
| 42 | # define TRAP_ADDRESS_ERROR 9 |
| 43 | # ifdef CONFIG_CPU_SH2A |
| 44 | # define TRAP_DIVZERO_ERROR 17 |
| 45 | # define TRAP_DIVOVF_ERROR 18 |
| 46 | # endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #else |
| 48 | #define TRAP_RESERVED_INST 12 |
| 49 | #define TRAP_ILLEGAL_SLOT_INST 13 |
| 50 | #endif |
| 51 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 52 | static void dump_mem(const char *str, unsigned long bottom, unsigned long top) |
| 53 | { |
| 54 | unsigned long p; |
| 55 | int i; |
| 56 | |
| 57 | printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top); |
| 58 | |
| 59 | for (p = bottom & ~31; p < top; ) { |
| 60 | printk("%04lx: ", p & 0xffff); |
| 61 | |
| 62 | for (i = 0; i < 8; i++, p += 4) { |
| 63 | unsigned int val; |
| 64 | |
| 65 | if (p < bottom || p >= top) |
| 66 | printk(" "); |
| 67 | else { |
| 68 | if (__get_user(val, (unsigned int __user *)p)) { |
| 69 | printk("\n"); |
| 70 | return; |
| 71 | } |
| 72 | printk("%08x ", val); |
| 73 | } |
| 74 | } |
| 75 | printk("\n"); |
| 76 | } |
| 77 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Paul Mundt | 3a2e117 | 2007-05-01 16:33:10 +0900 | [diff] [blame] | 79 | static DEFINE_SPINLOCK(die_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | void die(const char * str, struct pt_regs * regs, long err) |
| 82 | { |
| 83 | static int die_counter; |
| 84 | |
| 85 | console_verbose(); |
| 86 | spin_lock_irq(&die_lock); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 87 | bust_spinlocks(1); |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | CHK_REMOTE_DEBUG(regs); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 92 | print_modules(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | show_regs(regs); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 94 | |
| 95 | printk("Process: %s (pid: %d, stack limit = %p)\n", |
| 96 | current->comm, current->pid, task_stack_page(current) + 1); |
| 97 | |
| 98 | if (!user_mode(regs) || in_interrupt()) |
| 99 | dump_mem("Stack: ", regs->regs[15], THREAD_SIZE + |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 100 | (unsigned long)task_stack_page(current)); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 101 | |
| 102 | bust_spinlocks(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | spin_unlock_irq(&die_lock); |
| 104 | do_exit(SIGSEGV); |
| 105 | } |
| 106 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 107 | static inline void die_if_kernel(const char *str, struct pt_regs *regs, |
| 108 | long err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
| 110 | if (!user_mode(regs)) |
| 111 | die(str, regs, err); |
| 112 | } |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* |
| 115 | * try and fix up kernelspace address errors |
| 116 | * - userspace errors just cause EFAULT to be returned, resulting in SEGV |
| 117 | * - kernel/userspace interfaces cause a jump to an appropriate handler |
| 118 | * - other kernel errors are bad |
| 119 | * - return 0 if fixed-up, -EFAULT if non-fatal (to the kernel) fault |
| 120 | */ |
| 121 | static int die_if_no_fixup(const char * str, struct pt_regs * regs, long err) |
| 122 | { |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 123 | if (!user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | const struct exception_table_entry *fixup; |
| 125 | fixup = search_exception_tables(regs->pc); |
| 126 | if (fixup) { |
| 127 | regs->pc = fixup->fixup; |
| 128 | return 0; |
| 129 | } |
| 130 | die(str, regs, err); |
| 131 | } |
| 132 | return -EFAULT; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * handle an instruction that does an unaligned memory access by emulating the |
| 137 | * desired behaviour |
| 138 | * - note that PC _may not_ point to the faulting instruction |
| 139 | * (if that instruction is in a branch delay slot) |
| 140 | * - return 0 if emulation okay, -EFAULT on existential error |
| 141 | */ |
| 142 | static int handle_unaligned_ins(u16 instruction, struct pt_regs *regs) |
| 143 | { |
| 144 | int ret, index, count; |
| 145 | unsigned long *rm, *rn; |
| 146 | unsigned char *src, *dst; |
| 147 | |
| 148 | index = (instruction>>8)&15; /* 0x0F00 */ |
| 149 | rn = ®s->regs[index]; |
| 150 | |
| 151 | index = (instruction>>4)&15; /* 0x00F0 */ |
| 152 | rm = ®s->regs[index]; |
| 153 | |
| 154 | count = 1<<(instruction&3); |
| 155 | |
| 156 | ret = -EFAULT; |
| 157 | switch (instruction>>12) { |
| 158 | case 0: /* mov.[bwl] to/from memory via r0+rn */ |
| 159 | if (instruction & 8) { |
| 160 | /* from memory */ |
| 161 | src = (unsigned char*) *rm; |
| 162 | src += regs->regs[0]; |
| 163 | dst = (unsigned char*) rn; |
| 164 | *(unsigned long*)dst = 0; |
| 165 | |
| 166 | #ifdef __LITTLE_ENDIAN__ |
| 167 | if (copy_from_user(dst, src, count)) |
| 168 | goto fetch_fault; |
| 169 | |
| 170 | if ((count == 2) && dst[1] & 0x80) { |
| 171 | dst[2] = 0xff; |
| 172 | dst[3] = 0xff; |
| 173 | } |
| 174 | #else |
| 175 | dst += 4-count; |
| 176 | |
| 177 | if (__copy_user(dst, src, count)) |
| 178 | goto fetch_fault; |
| 179 | |
| 180 | if ((count == 2) && dst[2] & 0x80) { |
| 181 | dst[0] = 0xff; |
| 182 | dst[1] = 0xff; |
| 183 | } |
| 184 | #endif |
| 185 | } else { |
| 186 | /* to memory */ |
| 187 | src = (unsigned char*) rm; |
| 188 | #if !defined(__LITTLE_ENDIAN__) |
| 189 | src += 4-count; |
| 190 | #endif |
| 191 | dst = (unsigned char*) *rn; |
| 192 | dst += regs->regs[0]; |
| 193 | |
| 194 | if (copy_to_user(dst, src, count)) |
| 195 | goto fetch_fault; |
| 196 | } |
| 197 | ret = 0; |
| 198 | break; |
| 199 | |
| 200 | case 1: /* mov.l Rm,@(disp,Rn) */ |
| 201 | src = (unsigned char*) rm; |
| 202 | dst = (unsigned char*) *rn; |
| 203 | dst += (instruction&0x000F)<<2; |
| 204 | |
| 205 | if (copy_to_user(dst,src,4)) |
| 206 | goto fetch_fault; |
| 207 | ret = 0; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 208 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | case 2: /* mov.[bwl] to memory, possibly with pre-decrement */ |
| 211 | if (instruction & 4) |
| 212 | *rn -= count; |
| 213 | src = (unsigned char*) rm; |
| 214 | dst = (unsigned char*) *rn; |
| 215 | #if !defined(__LITTLE_ENDIAN__) |
| 216 | src += 4-count; |
| 217 | #endif |
| 218 | if (copy_to_user(dst, src, count)) |
| 219 | goto fetch_fault; |
| 220 | ret = 0; |
| 221 | break; |
| 222 | |
| 223 | case 5: /* mov.l @(disp,Rm),Rn */ |
| 224 | src = (unsigned char*) *rm; |
| 225 | src += (instruction&0x000F)<<2; |
| 226 | dst = (unsigned char*) rn; |
| 227 | *(unsigned long*)dst = 0; |
| 228 | |
| 229 | if (copy_from_user(dst,src,4)) |
| 230 | goto fetch_fault; |
| 231 | ret = 0; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 232 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | case 6: /* mov.[bwl] from memory, possibly with post-increment */ |
| 235 | src = (unsigned char*) *rm; |
| 236 | if (instruction & 4) |
| 237 | *rm += count; |
| 238 | dst = (unsigned char*) rn; |
| 239 | *(unsigned long*)dst = 0; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | #ifdef __LITTLE_ENDIAN__ |
| 242 | if (copy_from_user(dst, src, count)) |
| 243 | goto fetch_fault; |
| 244 | |
| 245 | if ((count == 2) && dst[1] & 0x80) { |
| 246 | dst[2] = 0xff; |
| 247 | dst[3] = 0xff; |
| 248 | } |
| 249 | #else |
| 250 | dst += 4-count; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | if (copy_from_user(dst, src, count)) |
| 253 | goto fetch_fault; |
| 254 | |
| 255 | if ((count == 2) && dst[2] & 0x80) { |
| 256 | dst[0] = 0xff; |
| 257 | dst[1] = 0xff; |
| 258 | } |
| 259 | #endif |
| 260 | ret = 0; |
| 261 | break; |
| 262 | |
| 263 | case 8: |
| 264 | switch ((instruction&0xFF00)>>8) { |
| 265 | case 0x81: /* mov.w R0,@(disp,Rn) */ |
| 266 | src = (unsigned char*) ®s->regs[0]; |
| 267 | #if !defined(__LITTLE_ENDIAN__) |
| 268 | src += 2; |
| 269 | #endif |
| 270 | dst = (unsigned char*) *rm; /* called Rn in the spec */ |
| 271 | dst += (instruction&0x000F)<<1; |
| 272 | |
| 273 | if (copy_to_user(dst, src, 2)) |
| 274 | goto fetch_fault; |
| 275 | ret = 0; |
| 276 | break; |
| 277 | |
| 278 | case 0x85: /* mov.w @(disp,Rm),R0 */ |
| 279 | src = (unsigned char*) *rm; |
| 280 | src += (instruction&0x000F)<<1; |
| 281 | dst = (unsigned char*) ®s->regs[0]; |
| 282 | *(unsigned long*)dst = 0; |
| 283 | |
| 284 | #if !defined(__LITTLE_ENDIAN__) |
| 285 | dst += 2; |
| 286 | #endif |
| 287 | |
| 288 | if (copy_from_user(dst, src, 2)) |
| 289 | goto fetch_fault; |
| 290 | |
| 291 | #ifdef __LITTLE_ENDIAN__ |
| 292 | if (dst[1] & 0x80) { |
| 293 | dst[2] = 0xff; |
| 294 | dst[3] = 0xff; |
| 295 | } |
| 296 | #else |
| 297 | if (dst[2] & 0x80) { |
| 298 | dst[0] = 0xff; |
| 299 | dst[1] = 0xff; |
| 300 | } |
| 301 | #endif |
| 302 | ret = 0; |
| 303 | break; |
| 304 | } |
| 305 | break; |
| 306 | } |
| 307 | return ret; |
| 308 | |
| 309 | fetch_fault: |
| 310 | /* Argh. Address not only misaligned but also non-existent. |
| 311 | * Raise an EFAULT and see if it's trapped |
| 312 | */ |
| 313 | return die_if_no_fixup("Fault in unaligned fixup", regs, 0); |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * emulate the instruction in the delay slot |
| 318 | * - fetches the instruction from PC+2 |
| 319 | */ |
| 320 | static inline int handle_unaligned_delayslot(struct pt_regs *regs) |
| 321 | { |
| 322 | u16 instruction; |
| 323 | |
| 324 | if (copy_from_user(&instruction, (u16 *)(regs->pc+2), 2)) { |
| 325 | /* the instruction-fetch faulted */ |
| 326 | if (user_mode(regs)) |
| 327 | return -EFAULT; |
| 328 | |
| 329 | /* kernel */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 330 | die("delay-slot-insn faulting in handle_unaligned_delayslot", |
| 331 | regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | return handle_unaligned_ins(instruction,regs); |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * handle an instruction that does an unaligned memory access |
| 339 | * - have to be careful of branch delay-slot instructions that fault |
| 340 | * SH3: |
| 341 | * - if the branch would be taken PC points to the branch |
| 342 | * - if the branch would not be taken, PC points to delay-slot |
| 343 | * SH4: |
| 344 | * - PC always points to delayed branch |
| 345 | * - return 0 if handled, -EFAULT if failed (may not return if in kernel) |
| 346 | */ |
| 347 | |
| 348 | /* Macros to determine offset from current PC for branch instructions */ |
| 349 | /* Explicit type coercion is used to force sign extension where needed */ |
| 350 | #define SH_PC_8BIT_OFFSET(instr) ((((signed char)(instr))*2) + 4) |
| 351 | #define SH_PC_12BIT_OFFSET(instr) ((((signed short)(instr<<4))>>3) + 4) |
| 352 | |
Paul Mundt | 710ee0c | 2006-11-05 16:48:42 +0900 | [diff] [blame] | 353 | /* |
| 354 | * XXX: SH-2A needs this too, but it needs an overhaul thanks to mixed 32-bit |
| 355 | * opcodes.. |
| 356 | */ |
| 357 | #ifndef CONFIG_CPU_SH2A |
| 358 | static int handle_unaligned_notify_count = 10; |
| 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | static int handle_unaligned_access(u16 instruction, struct pt_regs *regs) |
| 361 | { |
| 362 | u_int rm; |
| 363 | int ret, index; |
| 364 | |
| 365 | index = (instruction>>8)&15; /* 0x0F00 */ |
| 366 | rm = regs->regs[index]; |
| 367 | |
| 368 | /* shout about the first ten userspace fixups */ |
| 369 | if (user_mode(regs) && handle_unaligned_notify_count>0) { |
| 370 | handle_unaligned_notify_count--; |
| 371 | |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 372 | printk(KERN_NOTICE "Fixing up unaligned userspace access " |
| 373 | "in \"%s\" pid=%d pc=0x%p ins=0x%04hx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | current->comm,current->pid,(u16*)regs->pc,instruction); |
| 375 | } |
| 376 | |
| 377 | ret = -EFAULT; |
| 378 | switch (instruction&0xF000) { |
| 379 | case 0x0000: |
| 380 | if (instruction==0x000B) { |
| 381 | /* rts */ |
| 382 | ret = handle_unaligned_delayslot(regs); |
| 383 | if (ret==0) |
| 384 | regs->pc = regs->pr; |
| 385 | } |
| 386 | else if ((instruction&0x00FF)==0x0023) { |
| 387 | /* braf @Rm */ |
| 388 | ret = handle_unaligned_delayslot(regs); |
| 389 | if (ret==0) |
| 390 | regs->pc += rm + 4; |
| 391 | } |
| 392 | else if ((instruction&0x00FF)==0x0003) { |
| 393 | /* bsrf @Rm */ |
| 394 | ret = handle_unaligned_delayslot(regs); |
| 395 | if (ret==0) { |
| 396 | regs->pr = regs->pc + 4; |
| 397 | regs->pc += rm + 4; |
| 398 | } |
| 399 | } |
| 400 | else { |
| 401 | /* mov.[bwl] to/from memory via r0+rn */ |
| 402 | goto simple; |
| 403 | } |
| 404 | break; |
| 405 | |
| 406 | case 0x1000: /* mov.l Rm,@(disp,Rn) */ |
| 407 | goto simple; |
| 408 | |
| 409 | case 0x2000: /* mov.[bwl] to memory, possibly with pre-decrement */ |
| 410 | goto simple; |
| 411 | |
| 412 | case 0x4000: |
| 413 | if ((instruction&0x00FF)==0x002B) { |
| 414 | /* jmp @Rm */ |
| 415 | ret = handle_unaligned_delayslot(regs); |
| 416 | if (ret==0) |
| 417 | regs->pc = rm; |
| 418 | } |
| 419 | else if ((instruction&0x00FF)==0x000B) { |
| 420 | /* jsr @Rm */ |
| 421 | ret = handle_unaligned_delayslot(regs); |
| 422 | if (ret==0) { |
| 423 | regs->pr = regs->pc + 4; |
| 424 | regs->pc = rm; |
| 425 | } |
| 426 | } |
| 427 | else { |
| 428 | /* mov.[bwl] to/from memory via r0+rn */ |
| 429 | goto simple; |
| 430 | } |
| 431 | break; |
| 432 | |
| 433 | case 0x5000: /* mov.l @(disp,Rm),Rn */ |
| 434 | goto simple; |
| 435 | |
| 436 | case 0x6000: /* mov.[bwl] from memory, possibly with post-increment */ |
| 437 | goto simple; |
| 438 | |
| 439 | case 0x8000: /* bf lab, bf/s lab, bt lab, bt/s lab */ |
| 440 | switch (instruction&0x0F00) { |
| 441 | case 0x0100: /* mov.w R0,@(disp,Rm) */ |
| 442 | goto simple; |
| 443 | case 0x0500: /* mov.w @(disp,Rm),R0 */ |
| 444 | goto simple; |
| 445 | case 0x0B00: /* bf lab - no delayslot*/ |
| 446 | break; |
| 447 | case 0x0F00: /* bf/s lab */ |
| 448 | ret = handle_unaligned_delayslot(regs); |
| 449 | if (ret==0) { |
| 450 | #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB) |
| 451 | if ((regs->sr & 0x00000001) != 0) |
| 452 | regs->pc += 4; /* next after slot */ |
| 453 | else |
| 454 | #endif |
| 455 | regs->pc += SH_PC_8BIT_OFFSET(instruction); |
| 456 | } |
| 457 | break; |
| 458 | case 0x0900: /* bt lab - no delayslot */ |
| 459 | break; |
| 460 | case 0x0D00: /* bt/s lab */ |
| 461 | ret = handle_unaligned_delayslot(regs); |
| 462 | if (ret==0) { |
| 463 | #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB) |
| 464 | if ((regs->sr & 0x00000001) == 0) |
| 465 | regs->pc += 4; /* next after slot */ |
| 466 | else |
| 467 | #endif |
| 468 | regs->pc += SH_PC_8BIT_OFFSET(instruction); |
| 469 | } |
| 470 | break; |
| 471 | } |
| 472 | break; |
| 473 | |
| 474 | case 0xA000: /* bra label */ |
| 475 | ret = handle_unaligned_delayslot(regs); |
| 476 | if (ret==0) |
| 477 | regs->pc += SH_PC_12BIT_OFFSET(instruction); |
| 478 | break; |
| 479 | |
| 480 | case 0xB000: /* bsr label */ |
| 481 | ret = handle_unaligned_delayslot(regs); |
| 482 | if (ret==0) { |
| 483 | regs->pr = regs->pc + 4; |
| 484 | regs->pc += SH_PC_12BIT_OFFSET(instruction); |
| 485 | } |
| 486 | break; |
| 487 | } |
| 488 | return ret; |
| 489 | |
| 490 | /* handle non-delay-slot instruction */ |
| 491 | simple: |
| 492 | ret = handle_unaligned_ins(instruction,regs); |
| 493 | if (ret==0) |
Paul Mundt | 53f983a | 2007-05-08 15:31:48 +0900 | [diff] [blame] | 494 | regs->pc += instruction_size(instruction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | return ret; |
| 496 | } |
Paul Mundt | 710ee0c | 2006-11-05 16:48:42 +0900 | [diff] [blame] | 497 | #endif /* CONFIG_CPU_SH2A */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 499 | #ifdef CONFIG_CPU_HAS_SR_RB |
| 500 | #define lookup_exception_vector(x) \ |
| 501 | __asm__ __volatile__ ("stc r2_bank, %0\n\t" : "=r" ((x))) |
| 502 | #else |
| 503 | #define lookup_exception_vector(x) \ |
| 504 | __asm__ __volatile__ ("mov r4, %0\n\t" : "=r" ((x))) |
| 505 | #endif |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 508 | * Handle various address error exceptions: |
| 509 | * - instruction address error: |
| 510 | * misaligned PC |
| 511 | * PC >= 0x80000000 in user mode |
| 512 | * - data address error (read and write) |
| 513 | * misaligned data access |
| 514 | * access to >= 0x80000000 is user mode |
| 515 | * Unfortuntaly we can't distinguish between instruction address error |
| 516 | * and data address errors caused by read acceses. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | */ |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 518 | asmlinkage void do_address_error(struct pt_regs *regs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | unsigned long writeaccess, |
| 520 | unsigned long address) |
| 521 | { |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 522 | unsigned long error_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | mm_segment_t oldfs; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 524 | siginfo_t info; |
Paul Mundt | 710ee0c | 2006-11-05 16:48:42 +0900 | [diff] [blame] | 525 | #ifndef CONFIG_CPU_SH2A |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | u16 instruction; |
| 527 | int tmp; |
Paul Mundt | 710ee0c | 2006-11-05 16:48:42 +0900 | [diff] [blame] | 528 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 530 | /* Intentional ifdef */ |
| 531 | #ifdef CONFIG_CPU_HAS_SR_RB |
| 532 | lookup_exception_vector(error_code); |
| 533 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | oldfs = get_fs(); |
| 536 | |
| 537 | if (user_mode(regs)) { |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 538 | int si_code = BUS_ADRERR; |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | local_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | /* bad PC is not something we can fix */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 543 | if (regs->pc & 1) { |
| 544 | si_code = BUS_ADRALN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | goto uspace_segv; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 548 | #ifndef CONFIG_CPU_SH2A |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | set_fs(USER_DS); |
| 550 | if (copy_from_user(&instruction, (u16 *)(regs->pc), 2)) { |
| 551 | /* Argh. Fault on the instruction itself. |
| 552 | This should never happen non-SMP |
| 553 | */ |
| 554 | set_fs(oldfs); |
| 555 | goto uspace_segv; |
| 556 | } |
| 557 | |
| 558 | tmp = handle_unaligned_access(instruction, regs); |
| 559 | set_fs(oldfs); |
| 560 | |
| 561 | if (tmp==0) |
| 562 | return; /* sorted */ |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 563 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 565 | uspace_segv: |
| 566 | printk(KERN_NOTICE "Sending SIGBUS to \"%s\" due to unaligned " |
| 567 | "access (PC %lx PR %lx)\n", current->comm, regs->pc, |
| 568 | regs->pr); |
| 569 | |
| 570 | info.si_signo = SIGBUS; |
| 571 | info.si_errno = 0; |
| 572 | info.si_code = si_code; |
| 573 | info.si_addr = (void *) address; |
| 574 | force_sig_info(SIGBUS, &info, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } else { |
| 576 | if (regs->pc & 1) |
| 577 | die("unaligned program counter", regs, error_code); |
| 578 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 579 | #ifndef CONFIG_CPU_SH2A |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | set_fs(KERNEL_DS); |
| 581 | if (copy_from_user(&instruction, (u16 *)(regs->pc), 2)) { |
| 582 | /* Argh. Fault on the instruction itself. |
| 583 | This should never happen non-SMP |
| 584 | */ |
| 585 | set_fs(oldfs); |
| 586 | die("insn faulting in do_address_error", regs, 0); |
| 587 | } |
| 588 | |
| 589 | handle_unaligned_access(instruction, regs); |
| 590 | set_fs(oldfs); |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 591 | #else |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 592 | printk(KERN_NOTICE "Killing process \"%s\" due to unaligned " |
| 593 | "access\n", current->comm); |
| 594 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 595 | force_sig(SIGSEGV, current); |
| 596 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
| 600 | #ifdef CONFIG_SH_DSP |
| 601 | /* |
| 602 | * SH-DSP support gerg@snapgear.com. |
| 603 | */ |
| 604 | int is_dsp_inst(struct pt_regs *regs) |
| 605 | { |
| 606 | unsigned short inst; |
| 607 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 608 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | * Safe guard if DSP mode is already enabled or we're lacking |
| 610 | * the DSP altogether. |
| 611 | */ |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 612 | if (!(current_cpu_data.flags & CPU_HAS_DSP) || (regs->sr & SR_DSP)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | return 0; |
| 614 | |
| 615 | get_user(inst, ((unsigned short *) regs->pc)); |
| 616 | |
| 617 | inst &= 0xf000; |
| 618 | |
| 619 | /* Check for any type of DSP or support instruction */ |
| 620 | if ((inst == 0xf000) || (inst == 0x4000)) |
| 621 | return 1; |
| 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | #else |
| 626 | #define is_dsp_inst(regs) (0) |
| 627 | #endif /* CONFIG_SH_DSP */ |
| 628 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 629 | #ifdef CONFIG_CPU_SH2A |
| 630 | asmlinkage void do_divide_error(unsigned long r4, unsigned long r5, |
| 631 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 632 | struct pt_regs __regs) |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 633 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 634 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 635 | siginfo_t info; |
| 636 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 637 | switch (r4) { |
| 638 | case TRAP_DIVZERO_ERROR: |
| 639 | info.si_code = FPE_INTDIV; |
| 640 | break; |
| 641 | case TRAP_DIVOVF_ERROR: |
| 642 | info.si_code = FPE_INTOVF; |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | force_sig_info(SIGFPE, &info, current); |
| 647 | } |
| 648 | #endif |
| 649 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 650 | /* arch/sh/kernel/cpu/sh4/fpu.c */ |
| 651 | extern int do_fpu_inst(unsigned short, struct pt_regs *); |
| 652 | extern asmlinkage void do_fpu_state_restore(unsigned long r4, unsigned long r5, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 653 | unsigned long r6, unsigned long r7, struct pt_regs __regs); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 654 | |
| 655 | asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5, |
| 656 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 657 | struct pt_regs __regs) |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 658 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 659 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 660 | unsigned long error_code; |
| 661 | struct task_struct *tsk = current; |
| 662 | |
| 663 | #ifdef CONFIG_SH_FPU_EMU |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 664 | unsigned short inst = 0; |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 665 | int err; |
| 666 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 667 | get_user(inst, (unsigned short*)regs->pc); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 668 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 669 | err = do_fpu_inst(inst, regs); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 670 | if (!err) { |
Paul Mundt | 53f983a | 2007-05-08 15:31:48 +0900 | [diff] [blame] | 671 | regs->pc += instruction_size(inst); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 672 | return; |
| 673 | } |
| 674 | /* not a FPU inst. */ |
| 675 | #endif |
| 676 | |
| 677 | #ifdef CONFIG_SH_DSP |
| 678 | /* Check if it's a DSP instruction */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 679 | if (is_dsp_inst(regs)) { |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 680 | /* Enable DSP mode, and restart instruction. */ |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 681 | regs->sr |= SR_DSP; |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | #endif |
| 685 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 686 | lookup_exception_vector(error_code); |
| 687 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 688 | local_irq_enable(); |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 689 | CHK_REMOTE_DEBUG(regs); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 690 | force_sig(SIGILL, tsk); |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 691 | die_if_no_fixup("reserved instruction", regs, error_code); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | #ifdef CONFIG_SH_FPU_EMU |
| 695 | static int emulate_branch(unsigned short inst, struct pt_regs* regs) |
| 696 | { |
| 697 | /* |
| 698 | * bfs: 8fxx: PC+=d*2+4; |
| 699 | * bts: 8dxx: PC+=d*2+4; |
| 700 | * bra: axxx: PC+=D*2+4; |
| 701 | * bsr: bxxx: PC+=D*2+4 after PR=PC+4; |
| 702 | * braf:0x23: PC+=Rn*2+4; |
| 703 | * bsrf:0x03: PC+=Rn*2+4 after PR=PC+4; |
| 704 | * jmp: 4x2b: PC=Rn; |
| 705 | * jsr: 4x0b: PC=Rn after PR=PC+4; |
| 706 | * rts: 000b: PC=PR; |
| 707 | */ |
| 708 | if ((inst & 0xfd00) == 0x8d00) { |
| 709 | regs->pc += SH_PC_8BIT_OFFSET(inst); |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | if ((inst & 0xe000) == 0xa000) { |
| 714 | regs->pc += SH_PC_12BIT_OFFSET(inst); |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | if ((inst & 0xf0df) == 0x0003) { |
| 719 | regs->pc += regs->regs[(inst & 0x0f00) >> 8] + 4; |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | if ((inst & 0xf0df) == 0x400b) { |
| 724 | regs->pc = regs->regs[(inst & 0x0f00) >> 8]; |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | if ((inst & 0xffff) == 0x000b) { |
| 729 | regs->pc = regs->pr; |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | return 1; |
| 734 | } |
| 735 | #endif |
| 736 | |
| 737 | asmlinkage void do_illegal_slot_inst(unsigned long r4, unsigned long r5, |
| 738 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 739 | struct pt_regs __regs) |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 740 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 741 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 742 | unsigned long error_code; |
| 743 | struct task_struct *tsk = current; |
| 744 | #ifdef CONFIG_SH_FPU_EMU |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 745 | unsigned short inst = 0; |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 746 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 747 | get_user(inst, (unsigned short *)regs->pc + 1); |
| 748 | if (!do_fpu_inst(inst, regs)) { |
| 749 | get_user(inst, (unsigned short *)regs->pc); |
| 750 | if (!emulate_branch(inst, regs)) |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 751 | return; |
| 752 | /* fault in branch.*/ |
| 753 | } |
| 754 | /* not a FPU inst. */ |
| 755 | #endif |
| 756 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 757 | lookup_exception_vector(error_code); |
| 758 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 759 | local_irq_enable(); |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 760 | CHK_REMOTE_DEBUG(regs); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 761 | force_sig(SIGILL, tsk); |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 762 | die_if_no_fixup("illegal slot instruction", regs, error_code); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | asmlinkage void do_exception_error(unsigned long r4, unsigned long r5, |
| 766 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 767 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 769 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | long ex; |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 771 | |
| 772 | lookup_exception_vector(ex); |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 773 | die_if_kernel("exception", regs, ex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | #if defined(CONFIG_SH_STANDARD_BIOS) |
| 777 | void *gdb_vbr_vector; |
| 778 | |
| 779 | static inline void __init gdb_vbr_init(void) |
| 780 | { |
| 781 | register unsigned long vbr; |
| 782 | |
| 783 | /* |
| 784 | * Read the old value of the VBR register to initialise |
| 785 | * the vector through which debug and BIOS traps are |
| 786 | * delegated by the Linux trap handler. |
| 787 | */ |
| 788 | asm volatile("stc vbr, %0" : "=r" (vbr)); |
| 789 | |
| 790 | gdb_vbr_vector = (void *)(vbr + 0x100); |
| 791 | printk("Setting GDB trap vector to 0x%08lx\n", |
| 792 | (unsigned long)gdb_vbr_vector); |
| 793 | } |
| 794 | #endif |
| 795 | |
| 796 | void __init per_cpu_trap_init(void) |
| 797 | { |
| 798 | extern void *vbr_base; |
| 799 | |
| 800 | #ifdef CONFIG_SH_STANDARD_BIOS |
| 801 | gdb_vbr_init(); |
| 802 | #endif |
| 803 | |
| 804 | /* NOTE: The VBR value should be at P1 |
| 805 | (or P2, virtural "fixed" address space). |
| 806 | It's definitely should not in physical address. */ |
| 807 | |
| 808 | asm volatile("ldc %0, vbr" |
| 809 | : /* no output */ |
| 810 | : "r" (&vbr_base) |
| 811 | : "memory"); |
| 812 | } |
| 813 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 814 | void *set_exception_table_vec(unsigned int vec, void *handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
| 816 | extern void *exception_handling_table[]; |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 817 | void *old_handler; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 818 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 819 | old_handler = exception_handling_table[vec]; |
| 820 | exception_handling_table[vec] = handler; |
| 821 | return old_handler; |
| 822 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 824 | extern asmlinkage void address_error_handler(unsigned long r4, unsigned long r5, |
| 825 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 826 | struct pt_regs __regs); |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 827 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 828 | void __init trap_init(void) |
| 829 | { |
| 830 | set_exception_table_vec(TRAP_RESERVED_INST, do_reserved_inst); |
| 831 | set_exception_table_vec(TRAP_ILLEGAL_SLOT_INST, do_illegal_slot_inst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 833 | #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_FPU) || \ |
| 834 | defined(CONFIG_SH_FPU_EMU) |
| 835 | /* |
| 836 | * For SH-4 lacking an FPU, treat floating point instructions as |
| 837 | * reserved. They'll be handled in the math-emu case, or faulted on |
| 838 | * otherwise. |
| 839 | */ |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 840 | set_exception_table_evt(0x800, do_reserved_inst); |
| 841 | set_exception_table_evt(0x820, do_illegal_slot_inst); |
| 842 | #elif defined(CONFIG_SH_FPU) |
| 843 | set_exception_table_evt(0x800, do_fpu_state_restore); |
| 844 | set_exception_table_evt(0x820, do_fpu_state_restore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | #endif |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 846 | |
| 847 | #ifdef CONFIG_CPU_SH2 |
| 848 | set_exception_table_vec(TRAP_ADDRESS_ERROR, address_error_handler); |
| 849 | #endif |
| 850 | #ifdef CONFIG_CPU_SH2A |
| 851 | set_exception_table_vec(TRAP_DIVZERO_ERROR, do_divide_error); |
| 852 | set_exception_table_vec(TRAP_DIVOVF_ERROR, do_divide_error); |
| 853 | #endif |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | /* Setup VBR for boot cpu */ |
| 856 | per_cpu_trap_init(); |
| 857 | } |
| 858 | |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 859 | #ifdef CONFIG_BUG |
| 860 | void handle_BUG(struct pt_regs *regs) |
| 861 | { |
| 862 | enum bug_trap_type tt; |
| 863 | tt = report_bug(regs->pc); |
| 864 | if (tt == BUG_TRAP_TYPE_WARN) { |
| 865 | regs->pc += 2; |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff); |
| 870 | } |
| 871 | |
| 872 | int is_valid_bugaddr(unsigned long addr) |
| 873 | { |
| 874 | return addr >= PAGE_OFFSET; |
| 875 | } |
| 876 | #endif |
| 877 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 878 | void show_trace(struct task_struct *tsk, unsigned long *sp, |
| 879 | struct pt_regs *regs) |
| 880 | { |
| 881 | unsigned long addr; |
| 882 | |
| 883 | if (regs && user_mode(regs)) |
| 884 | return; |
| 885 | |
| 886 | printk("\nCall trace: "); |
| 887 | #ifdef CONFIG_KALLSYMS |
| 888 | printk("\n"); |
| 889 | #endif |
| 890 | |
| 891 | while (!kstack_end(sp)) { |
| 892 | addr = *sp++; |
| 893 | if (kernel_text_address(addr)) |
| 894 | print_ip_sym(addr); |
| 895 | } |
| 896 | |
| 897 | printk("\n"); |
Paul Mundt | 9b8c90e | 2006-12-06 11:07:51 +0900 | [diff] [blame] | 898 | |
| 899 | if (!tsk) |
| 900 | tsk = current; |
| 901 | |
| 902 | debug_show_held_locks(tsk); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 903 | } |
| 904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | void show_stack(struct task_struct *tsk, unsigned long *sp) |
| 906 | { |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 907 | unsigned long stack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 909 | if (!tsk) |
| 910 | tsk = current; |
| 911 | if (tsk == current) |
| 912 | sp = (unsigned long *)current_stack_pointer; |
| 913 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | sp = (unsigned long *)tsk->thread.sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 916 | stack = (unsigned long)sp; |
| 917 | dump_mem("Stack: ", stack, THREAD_SIZE + |
| 918 | (unsigned long)task_stack_page(tsk)); |
| 919 | show_trace(tsk, sp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | void dump_stack(void) |
| 923 | { |
| 924 | show_stack(NULL, NULL); |
| 925 | } |
| 926 | EXPORT_SYMBOL(dump_stack); |