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> |
Russell King | ba84be2 | 2009-01-06 14:41:07 -0800 | [diff] [blame] | 16 | #include <linux/hardirq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/spinlock.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/kallsyms.h> |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 21 | #include <linux/io.h> |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 22 | #include <linux/bug.h> |
Paul Mundt | 9b8c90e | 2006-12-06 11:07:51 +0900 | [diff] [blame] | 23 | #include <linux/debug_locks.h> |
Paul Mundt | b118ca5 | 2007-05-09 10:55:38 +0900 | [diff] [blame] | 24 | #include <linux/kdebug.h> |
Paul Mundt | e113276 | 2007-05-15 08:36:36 +0900 | [diff] [blame] | 25 | #include <linux/kexec.h> |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 26 | #include <linux/limits.h> |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 27 | #include <linux/proc_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/system.h> |
| 29 | #include <asm/uaccess.h> |
Andrew Morton | fad0f90 | 2008-04-16 02:03:51 +0900 | [diff] [blame] | 30 | #include <asm/fpu.h> |
Chris Smith | d39f545 | 2008-09-05 17:15:39 +0900 | [diff] [blame] | 31 | #include <asm/kprobes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_CPU_SH2 |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 34 | # define TRAP_RESERVED_INST 4 |
| 35 | # define TRAP_ILLEGAL_SLOT_INST 6 |
| 36 | # define TRAP_ADDRESS_ERROR 9 |
| 37 | # ifdef CONFIG_CPU_SH2A |
Peter Griffin | cd89436 | 2009-05-08 15:51:51 +0100 | [diff] [blame] | 38 | # define TRAP_UBC 12 |
Yoshinori Sato | 6e80f5e | 2008-07-10 01:20:03 +0900 | [diff] [blame] | 39 | # define TRAP_FPU_ERROR 13 |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 40 | # define TRAP_DIVZERO_ERROR 17 |
| 41 | # define TRAP_DIVOVF_ERROR 18 |
| 42 | # endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #else |
| 44 | #define TRAP_RESERVED_INST 12 |
| 45 | #define TRAP_ILLEGAL_SLOT_INST 13 |
| 46 | #endif |
| 47 | |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 48 | static unsigned long se_user; |
| 49 | static unsigned long se_sys; |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 50 | static unsigned long se_half; |
| 51 | static unsigned long se_word; |
| 52 | static unsigned long se_dword; |
| 53 | static unsigned long se_multi; |
| 54 | /* bitfield: 1: warn 2: fixup 4: signal -> combinations 2|4 && 1|2|4 are not |
| 55 | valid! */ |
| 56 | static int se_usermode = 3; |
| 57 | /* 0: no warning 1: print a warning message */ |
| 58 | static int se_kernmode_warn = 1; |
| 59 | |
| 60 | #ifdef CONFIG_PROC_FS |
| 61 | static const char *se_usermode_action[] = { |
| 62 | "ignored", |
| 63 | "warn", |
| 64 | "fixup", |
| 65 | "fixup+warn", |
| 66 | "signal", |
| 67 | "signal+warn" |
| 68 | }; |
| 69 | |
| 70 | static int |
| 71 | proc_alignment_read(char *page, char **start, off_t off, int count, int *eof, |
| 72 | void *data) |
| 73 | { |
| 74 | char *p = page; |
| 75 | int len; |
| 76 | |
| 77 | p += sprintf(p, "User:\t\t%lu\n", se_user); |
| 78 | p += sprintf(p, "System:\t\t%lu\n", se_sys); |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 79 | p += sprintf(p, "Half:\t\t%lu\n", se_half); |
| 80 | p += sprintf(p, "Word:\t\t%lu\n", se_word); |
| 81 | p += sprintf(p, "DWord:\t\t%lu\n", se_dword); |
| 82 | p += sprintf(p, "Multi:\t\t%lu\n", se_multi); |
| 83 | p += sprintf(p, "User faults:\t%i (%s)\n", se_usermode, |
| 84 | se_usermode_action[se_usermode]); |
| 85 | p += sprintf(p, "Kernel faults:\t%i (fixup%s)\n", se_kernmode_warn, |
| 86 | se_kernmode_warn ? "+warn" : ""); |
| 87 | |
| 88 | len = (p - page) - off; |
| 89 | if (len < 0) |
| 90 | len = 0; |
| 91 | |
| 92 | *eof = (len <= count) ? 1 : 0; |
| 93 | *start = page + off; |
| 94 | |
| 95 | return len; |
| 96 | } |
| 97 | |
| 98 | static int proc_alignment_write(struct file *file, const char __user *buffer, |
| 99 | unsigned long count, void *data) |
| 100 | { |
| 101 | char mode; |
| 102 | |
| 103 | if (count > 0) { |
| 104 | if (get_user(mode, buffer)) |
| 105 | return -EFAULT; |
| 106 | if (mode >= '0' && mode <= '5') |
| 107 | se_usermode = mode - '0'; |
| 108 | } |
| 109 | return count; |
| 110 | } |
| 111 | |
| 112 | static int proc_alignment_kern_write(struct file *file, const char __user *buffer, |
| 113 | unsigned long count, void *data) |
| 114 | { |
| 115 | char mode; |
| 116 | |
| 117 | if (count > 0) { |
| 118 | if (get_user(mode, buffer)) |
| 119 | return -EFAULT; |
| 120 | if (mode >= '0' && mode <= '1') |
| 121 | se_kernmode_warn = mode - '0'; |
| 122 | } |
| 123 | return count; |
| 124 | } |
| 125 | #endif |
| 126 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 127 | static void dump_mem(const char *str, unsigned long bottom, unsigned long top) |
| 128 | { |
| 129 | unsigned long p; |
| 130 | int i; |
| 131 | |
| 132 | printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top); |
| 133 | |
| 134 | for (p = bottom & ~31; p < top; ) { |
| 135 | printk("%04lx: ", p & 0xffff); |
| 136 | |
| 137 | for (i = 0; i < 8; i++, p += 4) { |
| 138 | unsigned int val; |
| 139 | |
| 140 | if (p < bottom || p >= top) |
| 141 | printk(" "); |
| 142 | else { |
| 143 | if (__get_user(val, (unsigned int __user *)p)) { |
| 144 | printk("\n"); |
| 145 | return; |
| 146 | } |
| 147 | printk("%08x ", val); |
| 148 | } |
| 149 | } |
| 150 | printk("\n"); |
| 151 | } |
| 152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Paul Mundt | 3a2e117 | 2007-05-01 16:33:10 +0900 | [diff] [blame] | 154 | static DEFINE_SPINLOCK(die_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | void die(const char * str, struct pt_regs * regs, long err) |
| 157 | { |
| 158 | static int die_counter; |
| 159 | |
Paul Mundt | 5527398 | 2007-06-18 18:57:13 +0900 | [diff] [blame] | 160 | oops_enter(); |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | console_verbose(); |
| 163 | spin_lock_irq(&die_lock); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 164 | bust_spinlocks(1); |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 167 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 168 | print_modules(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | show_regs(regs); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 170 | |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 171 | printk("Process: %s (pid: %d, stack limit = %p)\n", current->comm, |
| 172 | task_pid_nr(current), task_stack_page(current) + 1); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 173 | |
| 174 | if (!user_mode(regs) || in_interrupt()) |
| 175 | dump_mem("Stack: ", regs->regs[15], THREAD_SIZE + |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 176 | (unsigned long)task_stack_page(current)); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 177 | |
Paul Mundt | c9306f0 | 2008-10-21 18:33:36 +0900 | [diff] [blame] | 178 | notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV); |
| 179 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 180 | bust_spinlocks(0); |
Pavel Emelianov | bcdcd8e | 2007-07-17 04:03:42 -0700 | [diff] [blame] | 181 | add_taint(TAINT_DIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | spin_unlock_irq(&die_lock); |
Paul Mundt | e113276 | 2007-05-15 08:36:36 +0900 | [diff] [blame] | 183 | |
| 184 | if (kexec_should_crash(current)) |
| 185 | crash_kexec(regs); |
| 186 | |
| 187 | if (in_interrupt()) |
| 188 | panic("Fatal exception in interrupt"); |
| 189 | |
| 190 | if (panic_on_oops) |
| 191 | panic("Fatal exception"); |
| 192 | |
Paul Mundt | 5527398 | 2007-06-18 18:57:13 +0900 | [diff] [blame] | 193 | oops_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | do_exit(SIGSEGV); |
| 195 | } |
| 196 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 197 | static inline void die_if_kernel(const char *str, struct pt_regs *regs, |
| 198 | long err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | if (!user_mode(regs)) |
| 201 | die(str, regs, err); |
| 202 | } |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | /* |
| 205 | * try and fix up kernelspace address errors |
| 206 | * - userspace errors just cause EFAULT to be returned, resulting in SEGV |
| 207 | * - kernel/userspace interfaces cause a jump to an appropriate handler |
| 208 | * - other kernel errors are bad |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | */ |
SUGIOKA Toshinobu | 2afb447 | 2009-01-21 09:42:10 +0900 | [diff] [blame] | 210 | static void die_if_no_fixup(const char * str, struct pt_regs * regs, long err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 212 | if (!user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | const struct exception_table_entry *fixup; |
| 214 | fixup = search_exception_tables(regs->pc); |
| 215 | if (fixup) { |
| 216 | regs->pc = fixup->fixup; |
SUGIOKA Toshinobu | 2afb447 | 2009-01-21 09:42:10 +0900 | [diff] [blame] | 217 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
Matt Fleming | b344e24a | 2009-08-16 21:54:48 +0100 | [diff] [blame] | 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | die(str, regs, err); |
| 221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 224 | static inline void sign_extend(unsigned int count, unsigned char *dst) |
| 225 | { |
| 226 | #ifdef __LITTLE_ENDIAN__ |
Magnus Damm | 4252c65 | 2008-02-07 19:58:46 +0900 | [diff] [blame] | 227 | if ((count == 1) && dst[0] & 0x80) { |
| 228 | dst[1] = 0xff; |
| 229 | dst[2] = 0xff; |
| 230 | dst[3] = 0xff; |
| 231 | } |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 232 | if ((count == 2) && dst[1] & 0x80) { |
| 233 | dst[2] = 0xff; |
| 234 | dst[3] = 0xff; |
| 235 | } |
| 236 | #else |
Magnus Damm | 4252c65 | 2008-02-07 19:58:46 +0900 | [diff] [blame] | 237 | if ((count == 1) && dst[3] & 0x80) { |
| 238 | dst[2] = 0xff; |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 239 | dst[1] = 0xff; |
Magnus Damm | 4252c65 | 2008-02-07 19:58:46 +0900 | [diff] [blame] | 240 | dst[0] = 0xff; |
| 241 | } |
| 242 | if ((count == 2) && dst[2] & 0x80) { |
| 243 | dst[1] = 0xff; |
| 244 | dst[0] = 0xff; |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 245 | } |
| 246 | #endif |
| 247 | } |
| 248 | |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 249 | static struct mem_access user_mem_access = { |
| 250 | copy_from_user, |
| 251 | copy_to_user, |
| 252 | }; |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* |
| 255 | * handle an instruction that does an unaligned memory access by emulating the |
| 256 | * desired behaviour |
| 257 | * - note that PC _may not_ point to the faulting instruction |
| 258 | * (if that instruction is in a branch delay slot) |
| 259 | * - return 0 if emulation okay, -EFAULT on existential error |
| 260 | */ |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 261 | static int handle_unaligned_ins(insn_size_t instruction, struct pt_regs *regs, |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 262 | struct mem_access *ma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
| 264 | int ret, index, count; |
| 265 | unsigned long *rm, *rn; |
| 266 | unsigned char *src, *dst; |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 267 | unsigned char __user *srcu, *dstu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | index = (instruction>>8)&15; /* 0x0F00 */ |
| 270 | rn = ®s->regs[index]; |
| 271 | |
| 272 | index = (instruction>>4)&15; /* 0x00F0 */ |
| 273 | rm = ®s->regs[index]; |
| 274 | |
| 275 | count = 1<<(instruction&3); |
| 276 | |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 277 | switch (count) { |
| 278 | case 1: se_half += 1; break; |
| 279 | case 2: se_word += 1; break; |
| 280 | case 4: se_dword += 1; break; |
| 281 | case 8: se_multi += 1; break; /* ??? */ |
| 282 | } |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | ret = -EFAULT; |
| 285 | switch (instruction>>12) { |
| 286 | case 0: /* mov.[bwl] to/from memory via r0+rn */ |
| 287 | if (instruction & 8) { |
| 288 | /* from memory */ |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 289 | srcu = (unsigned char __user *)*rm; |
| 290 | srcu += regs->regs[0]; |
| 291 | dst = (unsigned char *)rn; |
| 292 | *(unsigned long *)dst = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 294 | #if !defined(__LITTLE_ENDIAN__) |
| 295 | dst += 4-count; |
| 296 | #endif |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 297 | if (ma->from(dst, srcu, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | goto fetch_fault; |
| 299 | |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 300 | sign_extend(count, dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } else { |
| 302 | /* to memory */ |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 303 | src = (unsigned char *)rm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | #if !defined(__LITTLE_ENDIAN__) |
| 305 | src += 4-count; |
| 306 | #endif |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 307 | dstu = (unsigned char __user *)*rn; |
| 308 | dstu += regs->regs[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 310 | if (ma->to(dstu, src, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | goto fetch_fault; |
| 312 | } |
| 313 | ret = 0; |
| 314 | break; |
| 315 | |
| 316 | case 1: /* mov.l Rm,@(disp,Rn) */ |
| 317 | src = (unsigned char*) rm; |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 318 | dstu = (unsigned char __user *)*rn; |
| 319 | dstu += (instruction&0x000F)<<2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 321 | if (ma->to(dstu, src, 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | goto fetch_fault; |
| 323 | ret = 0; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 324 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | case 2: /* mov.[bwl] to memory, possibly with pre-decrement */ |
| 327 | if (instruction & 4) |
| 328 | *rn -= count; |
| 329 | src = (unsigned char*) rm; |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 330 | dstu = (unsigned char __user *)*rn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | #if !defined(__LITTLE_ENDIAN__) |
| 332 | src += 4-count; |
| 333 | #endif |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 334 | if (ma->to(dstu, src, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | goto fetch_fault; |
| 336 | ret = 0; |
| 337 | break; |
| 338 | |
| 339 | case 5: /* mov.l @(disp,Rm),Rn */ |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 340 | srcu = (unsigned char __user *)*rm; |
| 341 | srcu += (instruction & 0x000F) << 2; |
| 342 | dst = (unsigned char *)rn; |
| 343 | *(unsigned long *)dst = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 345 | if (ma->from(dst, srcu, 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | goto fetch_fault; |
| 347 | ret = 0; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 348 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | case 6: /* mov.[bwl] from memory, possibly with post-increment */ |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 351 | srcu = (unsigned char __user *)*rm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | if (instruction & 4) |
| 353 | *rm += count; |
| 354 | dst = (unsigned char*) rn; |
| 355 | *(unsigned long*)dst = 0; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 356 | |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 357 | #if !defined(__LITTLE_ENDIAN__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | dst += 4-count; |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 359 | #endif |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 360 | if (ma->from(dst, srcu, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | goto fetch_fault; |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 362 | sign_extend(count, dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | ret = 0; |
| 364 | break; |
| 365 | |
| 366 | case 8: |
| 367 | switch ((instruction&0xFF00)>>8) { |
| 368 | case 0x81: /* mov.w R0,@(disp,Rn) */ |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 369 | src = (unsigned char *) ®s->regs[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | #if !defined(__LITTLE_ENDIAN__) |
| 371 | src += 2; |
| 372 | #endif |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 373 | dstu = (unsigned char __user *)*rm; /* called Rn in the spec */ |
| 374 | dstu += (instruction & 0x000F) << 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 376 | if (ma->to(dstu, src, 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | goto fetch_fault; |
| 378 | ret = 0; |
| 379 | break; |
| 380 | |
| 381 | case 0x85: /* mov.w @(disp,Rm),R0 */ |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 382 | srcu = (unsigned char __user *)*rm; |
| 383 | srcu += (instruction & 0x000F) << 1; |
| 384 | dst = (unsigned char *) ®s->regs[0]; |
| 385 | *(unsigned long *)dst = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | #if !defined(__LITTLE_ENDIAN__) |
| 388 | dst += 2; |
| 389 | #endif |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 390 | if (ma->from(dst, srcu, 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | goto fetch_fault; |
Magnus Damm | 86c0179 | 2008-02-07 00:02:50 +0900 | [diff] [blame] | 392 | sign_extend(2, dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | ret = 0; |
| 394 | break; |
| 395 | } |
| 396 | break; |
| 397 | } |
| 398 | return ret; |
| 399 | |
| 400 | fetch_fault: |
| 401 | /* Argh. Address not only misaligned but also non-existent. |
| 402 | * Raise an EFAULT and see if it's trapped |
| 403 | */ |
SUGIOKA Toshinobu | 2afb447 | 2009-01-21 09:42:10 +0900 | [diff] [blame] | 404 | die_if_no_fixup("Fault in unaligned fixup", regs, 0); |
| 405 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /* |
| 409 | * emulate the instruction in the delay slot |
| 410 | * - fetches the instruction from PC+2 |
| 411 | */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 412 | static inline int handle_delayslot(struct pt_regs *regs, |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 413 | insn_size_t old_instruction, |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 414 | struct mem_access *ma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 416 | insn_size_t instruction; |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 417 | void __user *addr = (void __user *)(regs->pc + |
| 418 | instruction_size(old_instruction)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Magnus Damm | 4b5a9ef | 2008-02-07 20:04:12 +0900 | [diff] [blame] | 420 | if (copy_from_user(&instruction, addr, sizeof(instruction))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* the instruction-fetch faulted */ |
| 422 | if (user_mode(regs)) |
| 423 | return -EFAULT; |
| 424 | |
| 425 | /* kernel */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 426 | die("delay-slot-insn faulting in handle_unaligned_delayslot", |
| 427 | regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 430 | return handle_unaligned_ins(instruction, regs, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
| 434 | * handle an instruction that does an unaligned memory access |
| 435 | * - have to be careful of branch delay-slot instructions that fault |
| 436 | * SH3: |
| 437 | * - if the branch would be taken PC points to the branch |
| 438 | * - if the branch would not be taken, PC points to delay-slot |
| 439 | * SH4: |
| 440 | * - PC always points to delayed branch |
| 441 | * - return 0 if handled, -EFAULT if failed (may not return if in kernel) |
| 442 | */ |
| 443 | |
| 444 | /* Macros to determine offset from current PC for branch instructions */ |
| 445 | /* Explicit type coercion is used to force sign extension where needed */ |
| 446 | #define SH_PC_8BIT_OFFSET(instr) ((((signed char)(instr))*2) + 4) |
| 447 | #define SH_PC_12BIT_OFFSET(instr) ((((signed short)(instr<<4))>>3) + 4) |
| 448 | |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 449 | int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs, |
Matt Fleming | 4aa5ac4 | 2009-08-28 21:37:20 +0000 | [diff] [blame] | 450 | struct mem_access *ma, int expected) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | { |
| 452 | u_int rm; |
| 453 | int ret, index; |
| 454 | |
Paul Mundt | 23c4c82 | 2009-09-24 17:38:18 +0900 | [diff] [blame] | 455 | /* |
| 456 | * XXX: We can't handle mixed 16/32-bit instructions yet |
| 457 | */ |
| 458 | if (instruction_size(instruction) != 2) |
| 459 | return -EINVAL; |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | index = (instruction>>8)&15; /* 0x0F00 */ |
| 462 | rm = regs->regs[index]; |
| 463 | |
Andre Draszik | 9a4af02 | 2009-08-24 14:38:27 +0900 | [diff] [blame] | 464 | /* shout about fixups */ |
Matt Fleming | 4aa5ac4 | 2009-08-28 21:37:20 +0000 | [diff] [blame] | 465 | if (!expected && printk_ratelimit()) |
Andre Draszik | 9a4af02 | 2009-08-24 14:38:27 +0900 | [diff] [blame] | 466 | printk(KERN_NOTICE "Fixing up unaligned %s access " |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 467 | "in \"%s\" pid=%d pc=0x%p ins=0x%04hx\n", |
Andre Draszik | 9a4af02 | 2009-08-24 14:38:27 +0900 | [diff] [blame] | 468 | user_mode(regs) ? "userspace" : "kernel", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 469 | current->comm, task_pid_nr(current), |
Magnus Damm | 4b5a9ef | 2008-02-07 20:04:12 +0900 | [diff] [blame] | 470 | (void *)regs->pc, instruction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | ret = -EFAULT; |
| 473 | switch (instruction&0xF000) { |
| 474 | case 0x0000: |
| 475 | if (instruction==0x000B) { |
| 476 | /* rts */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 477 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | if (ret==0) |
| 479 | regs->pc = regs->pr; |
| 480 | } |
| 481 | else if ((instruction&0x00FF)==0x0023) { |
| 482 | /* braf @Rm */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 483 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | if (ret==0) |
| 485 | regs->pc += rm + 4; |
| 486 | } |
| 487 | else if ((instruction&0x00FF)==0x0003) { |
| 488 | /* bsrf @Rm */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 489 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (ret==0) { |
| 491 | regs->pr = regs->pc + 4; |
| 492 | regs->pc += rm + 4; |
| 493 | } |
| 494 | } |
| 495 | else { |
| 496 | /* mov.[bwl] to/from memory via r0+rn */ |
| 497 | goto simple; |
| 498 | } |
| 499 | break; |
| 500 | |
| 501 | case 0x1000: /* mov.l Rm,@(disp,Rn) */ |
| 502 | goto simple; |
| 503 | |
| 504 | case 0x2000: /* mov.[bwl] to memory, possibly with pre-decrement */ |
| 505 | goto simple; |
| 506 | |
| 507 | case 0x4000: |
| 508 | if ((instruction&0x00FF)==0x002B) { |
| 509 | /* jmp @Rm */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 510 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (ret==0) |
| 512 | regs->pc = rm; |
| 513 | } |
| 514 | else if ((instruction&0x00FF)==0x000B) { |
| 515 | /* jsr @Rm */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 516 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (ret==0) { |
| 518 | regs->pr = regs->pc + 4; |
| 519 | regs->pc = rm; |
| 520 | } |
| 521 | } |
| 522 | else { |
| 523 | /* mov.[bwl] to/from memory via r0+rn */ |
| 524 | goto simple; |
| 525 | } |
| 526 | break; |
| 527 | |
| 528 | case 0x5000: /* mov.l @(disp,Rm),Rn */ |
| 529 | goto simple; |
| 530 | |
| 531 | case 0x6000: /* mov.[bwl] from memory, possibly with post-increment */ |
| 532 | goto simple; |
| 533 | |
| 534 | case 0x8000: /* bf lab, bf/s lab, bt lab, bt/s lab */ |
| 535 | switch (instruction&0x0F00) { |
| 536 | case 0x0100: /* mov.w R0,@(disp,Rm) */ |
| 537 | goto simple; |
| 538 | case 0x0500: /* mov.w @(disp,Rm),R0 */ |
| 539 | goto simple; |
| 540 | case 0x0B00: /* bf lab - no delayslot*/ |
| 541 | break; |
| 542 | case 0x0F00: /* bf/s lab */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 543 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | if (ret==0) { |
| 545 | #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB) |
| 546 | if ((regs->sr & 0x00000001) != 0) |
| 547 | regs->pc += 4; /* next after slot */ |
| 548 | else |
| 549 | #endif |
| 550 | regs->pc += SH_PC_8BIT_OFFSET(instruction); |
| 551 | } |
| 552 | break; |
| 553 | case 0x0900: /* bt lab - no delayslot */ |
| 554 | break; |
| 555 | case 0x0D00: /* bt/s lab */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 556 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | if (ret==0) { |
| 558 | #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB) |
| 559 | if ((regs->sr & 0x00000001) == 0) |
| 560 | regs->pc += 4; /* next after slot */ |
| 561 | else |
| 562 | #endif |
| 563 | regs->pc += SH_PC_8BIT_OFFSET(instruction); |
| 564 | } |
| 565 | break; |
| 566 | } |
| 567 | break; |
| 568 | |
| 569 | case 0xA000: /* bra label */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 570 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | if (ret==0) |
| 572 | regs->pc += SH_PC_12BIT_OFFSET(instruction); |
| 573 | break; |
| 574 | |
| 575 | case 0xB000: /* bsr label */ |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 576 | ret = handle_delayslot(regs, instruction, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | if (ret==0) { |
| 578 | regs->pr = regs->pc + 4; |
| 579 | regs->pc += SH_PC_12BIT_OFFSET(instruction); |
| 580 | } |
| 581 | break; |
| 582 | } |
| 583 | return ret; |
| 584 | |
| 585 | /* handle non-delay-slot instruction */ |
| 586 | simple: |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 587 | ret = handle_unaligned_ins(instruction, regs, ma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | if (ret==0) |
Paul Mundt | 53f983a | 2007-05-08 15:31:48 +0900 | [diff] [blame] | 589 | regs->pc += instruction_size(instruction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | /* |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 594 | * Handle various address error exceptions: |
| 595 | * - instruction address error: |
| 596 | * misaligned PC |
| 597 | * PC >= 0x80000000 in user mode |
| 598 | * - data address error (read and write) |
| 599 | * misaligned data access |
| 600 | * access to >= 0x80000000 is user mode |
| 601 | * Unfortuntaly we can't distinguish between instruction address error |
Simon Arlott | e868d61 | 2007-05-14 08:15:10 +0900 | [diff] [blame] | 602 | * and data address errors caused by read accesses. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | */ |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 604 | asmlinkage void do_address_error(struct pt_regs *regs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | unsigned long writeaccess, |
| 606 | unsigned long address) |
| 607 | { |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 608 | unsigned long error_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | mm_segment_t oldfs; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 610 | siginfo_t info; |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 611 | insn_size_t instruction; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | int tmp; |
| 613 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 614 | /* Intentional ifdef */ |
| 615 | #ifdef CONFIG_CPU_HAS_SR_RB |
Paul Mundt | 4c59e29 | 2008-09-21 12:00:23 +0900 | [diff] [blame] | 616 | error_code = lookup_exception_vector(); |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 617 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | oldfs = get_fs(); |
| 620 | |
| 621 | if (user_mode(regs)) { |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 622 | int si_code = BUS_ADRERR; |
| 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | local_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 626 | se_user += 1; |
| 627 | |
Andre Draszik | 5a0ab35 | 2009-08-24 15:01:10 +0900 | [diff] [blame] | 628 | set_fs(USER_DS); |
Paul Mundt | 23c4c82 | 2009-09-24 17:38:18 +0900 | [diff] [blame] | 629 | if (copy_from_user(&instruction, (insn_size_t *)(regs->pc & ~1), |
| 630 | sizeof(instruction))) { |
Andre Draszik | 5a0ab35 | 2009-08-24 15:01:10 +0900 | [diff] [blame] | 631 | set_fs(oldfs); |
| 632 | goto uspace_segv; |
| 633 | } |
| 634 | set_fs(oldfs); |
| 635 | |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 636 | /* shout about userspace fixups */ |
| 637 | if (se_usermode & 1) |
| 638 | printk(KERN_NOTICE "Unaligned userspace access " |
| 639 | "in \"%s\" pid=%d pc=0x%p ins=0x%04hx\n", |
| 640 | current->comm, current->pid, (void *)regs->pc, |
| 641 | instruction); |
| 642 | |
| 643 | if (se_usermode & 2) |
| 644 | goto fixup; |
| 645 | |
| 646 | if (se_usermode & 4) |
| 647 | goto uspace_segv; |
| 648 | else { |
| 649 | /* ignore */ |
Andre Draszik | 5a0ab35 | 2009-08-24 15:01:10 +0900 | [diff] [blame] | 650 | regs->pc += instruction_size(instruction); |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 651 | return; |
| 652 | } |
| 653 | |
| 654 | fixup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | /* bad PC is not something we can fix */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 656 | if (regs->pc & 1) { |
| 657 | si_code = BUS_ADRALN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | goto uspace_segv; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | set_fs(USER_DS); |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 662 | tmp = handle_unaligned_access(instruction, regs, |
Matt Fleming | 4aa5ac4 | 2009-08-28 21:37:20 +0000 | [diff] [blame] | 663 | &user_mem_access, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | set_fs(oldfs); |
| 665 | |
| 666 | if (tmp==0) |
| 667 | return; /* sorted */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 668 | uspace_segv: |
| 669 | printk(KERN_NOTICE "Sending SIGBUS to \"%s\" due to unaligned " |
| 670 | "access (PC %lx PR %lx)\n", current->comm, regs->pc, |
| 671 | regs->pr); |
| 672 | |
| 673 | info.si_signo = SIGBUS; |
| 674 | info.si_errno = 0; |
| 675 | info.si_code = si_code; |
Paul Mundt | e08f457 | 2007-05-14 12:52:56 +0900 | [diff] [blame] | 676 | info.si_addr = (void __user *)address; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 677 | force_sig_info(SIGBUS, &info, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } else { |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 679 | se_sys += 1; |
| 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | if (regs->pc & 1) |
| 682 | die("unaligned program counter", regs, error_code); |
| 683 | |
| 684 | set_fs(KERNEL_DS); |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 685 | if (copy_from_user(&instruction, (void __user *)(regs->pc), |
Magnus Damm | 4b5a9ef | 2008-02-07 20:04:12 +0900 | [diff] [blame] | 686 | sizeof(instruction))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | /* Argh. Fault on the instruction itself. |
| 688 | This should never happen non-SMP |
| 689 | */ |
| 690 | set_fs(oldfs); |
| 691 | die("insn faulting in do_address_error", regs, 0); |
| 692 | } |
| 693 | |
Paul Mundt | 40258ee | 2009-09-24 17:48:15 +0900 | [diff] [blame^] | 694 | if (se_kernmode_warn) |
| 695 | printk(KERN_NOTICE "Unaligned kernel access " |
| 696 | "on behalf of \"%s\" pid=%d pc=0x%p ins=0x%04hx\n", |
| 697 | current->comm, current->pid, (void *)regs->pc, |
| 698 | instruction); |
| 699 | |
Matt Fleming | 4aa5ac4 | 2009-08-28 21:37:20 +0000 | [diff] [blame] | 700 | handle_unaligned_access(instruction, regs, |
| 701 | &user_mem_access, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | set_fs(oldfs); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | #ifdef CONFIG_SH_DSP |
| 707 | /* |
| 708 | * SH-DSP support gerg@snapgear.com. |
| 709 | */ |
| 710 | int is_dsp_inst(struct pt_regs *regs) |
| 711 | { |
Paul Mundt | 882c12c | 2007-05-14 17:26:34 +0900 | [diff] [blame] | 712 | unsigned short inst = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 714 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | * Safe guard if DSP mode is already enabled or we're lacking |
| 716 | * the DSP altogether. |
| 717 | */ |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 718 | if (!(current_cpu_data.flags & CPU_HAS_DSP) || (regs->sr & SR_DSP)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | return 0; |
| 720 | |
| 721 | get_user(inst, ((unsigned short *) regs->pc)); |
| 722 | |
| 723 | inst &= 0xf000; |
| 724 | |
| 725 | /* Check for any type of DSP or support instruction */ |
| 726 | if ((inst == 0xf000) || (inst == 0x4000)) |
| 727 | return 1; |
| 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | #else |
| 732 | #define is_dsp_inst(regs) (0) |
| 733 | #endif /* CONFIG_SH_DSP */ |
| 734 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 735 | #ifdef CONFIG_CPU_SH2A |
| 736 | asmlinkage void do_divide_error(unsigned long r4, unsigned long r5, |
| 737 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 738 | struct pt_regs __regs) |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 739 | { |
| 740 | siginfo_t info; |
| 741 | |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 742 | switch (r4) { |
| 743 | case TRAP_DIVZERO_ERROR: |
| 744 | info.si_code = FPE_INTDIV; |
| 745 | break; |
| 746 | case TRAP_DIVOVF_ERROR: |
| 747 | info.si_code = FPE_INTOVF; |
| 748 | break; |
| 749 | } |
| 750 | |
| 751 | force_sig_info(SIGFPE, &info, current); |
| 752 | } |
| 753 | #endif |
| 754 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 755 | asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5, |
| 756 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 757 | struct pt_regs __regs) |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 758 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 759 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 760 | unsigned long error_code; |
| 761 | struct task_struct *tsk = current; |
| 762 | |
| 763 | #ifdef CONFIG_SH_FPU_EMU |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 764 | unsigned short inst = 0; |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 765 | int err; |
| 766 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 767 | get_user(inst, (unsigned short*)regs->pc); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 768 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 769 | err = do_fpu_inst(inst, regs); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 770 | if (!err) { |
Paul Mundt | 53f983a | 2007-05-08 15:31:48 +0900 | [diff] [blame] | 771 | regs->pc += instruction_size(inst); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | /* not a FPU inst. */ |
| 775 | #endif |
| 776 | |
| 777 | #ifdef CONFIG_SH_DSP |
| 778 | /* Check if it's a DSP instruction */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 779 | if (is_dsp_inst(regs)) { |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 780 | /* Enable DSP mode, and restart instruction. */ |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 781 | regs->sr |= SR_DSP; |
Michael Trimarchi | 01ab103 | 2009-04-03 17:32:33 +0000 | [diff] [blame] | 782 | /* Save DSP mode */ |
| 783 | tsk->thread.dsp_status.status |= SR_DSP; |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 784 | return; |
| 785 | } |
| 786 | #endif |
| 787 | |
Paul Mundt | 4c59e29 | 2008-09-21 12:00:23 +0900 | [diff] [blame] | 788 | error_code = lookup_exception_vector(); |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 789 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 790 | local_irq_enable(); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 791 | force_sig(SIGILL, tsk); |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 792 | die_if_no_fixup("reserved instruction", regs, error_code); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | #ifdef CONFIG_SH_FPU_EMU |
Paul Mundt | edfd6da | 2008-11-26 13:06:04 +0900 | [diff] [blame] | 796 | static int emulate_branch(unsigned short inst, struct pt_regs *regs) |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 797 | { |
| 798 | /* |
| 799 | * bfs: 8fxx: PC+=d*2+4; |
| 800 | * bts: 8dxx: PC+=d*2+4; |
| 801 | * bra: axxx: PC+=D*2+4; |
| 802 | * bsr: bxxx: PC+=D*2+4 after PR=PC+4; |
| 803 | * braf:0x23: PC+=Rn*2+4; |
| 804 | * bsrf:0x03: PC+=Rn*2+4 after PR=PC+4; |
| 805 | * jmp: 4x2b: PC=Rn; |
| 806 | * jsr: 4x0b: PC=Rn after PR=PC+4; |
| 807 | * rts: 000b: PC=PR; |
| 808 | */ |
Paul Mundt | edfd6da | 2008-11-26 13:06:04 +0900 | [diff] [blame] | 809 | if (((inst & 0xf000) == 0xb000) || /* bsr */ |
| 810 | ((inst & 0xf0ff) == 0x0003) || /* bsrf */ |
| 811 | ((inst & 0xf0ff) == 0x400b)) /* jsr */ |
| 812 | regs->pr = regs->pc + 4; |
| 813 | |
| 814 | if ((inst & 0xfd00) == 0x8d00) { /* bfs, bts */ |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 815 | regs->pc += SH_PC_8BIT_OFFSET(inst); |
| 816 | return 0; |
| 817 | } |
| 818 | |
Paul Mundt | edfd6da | 2008-11-26 13:06:04 +0900 | [diff] [blame] | 819 | if ((inst & 0xe000) == 0xa000) { /* bra, bsr */ |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 820 | regs->pc += SH_PC_12BIT_OFFSET(inst); |
| 821 | return 0; |
| 822 | } |
| 823 | |
Paul Mundt | edfd6da | 2008-11-26 13:06:04 +0900 | [diff] [blame] | 824 | if ((inst & 0xf0df) == 0x0003) { /* braf, bsrf */ |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 825 | regs->pc += regs->regs[(inst & 0x0f00) >> 8] + 4; |
| 826 | return 0; |
| 827 | } |
| 828 | |
Paul Mundt | edfd6da | 2008-11-26 13:06:04 +0900 | [diff] [blame] | 829 | if ((inst & 0xf0df) == 0x400b) { /* jmp, jsr */ |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 830 | regs->pc = regs->regs[(inst & 0x0f00) >> 8]; |
| 831 | return 0; |
| 832 | } |
| 833 | |
Paul Mundt | edfd6da | 2008-11-26 13:06:04 +0900 | [diff] [blame] | 834 | if ((inst & 0xffff) == 0x000b) { /* rts */ |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 835 | regs->pc = regs->pr; |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | return 1; |
| 840 | } |
| 841 | #endif |
| 842 | |
| 843 | asmlinkage void do_illegal_slot_inst(unsigned long r4, unsigned long r5, |
| 844 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 845 | struct pt_regs __regs) |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 846 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 847 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Paul Mundt | b3d765f | 2008-09-17 23:12:11 +0900 | [diff] [blame] | 848 | unsigned long inst; |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 849 | struct task_struct *tsk = current; |
Chris Smith | d39f545 | 2008-09-05 17:15:39 +0900 | [diff] [blame] | 850 | |
| 851 | if (kprobe_handle_illslot(regs->pc) == 0) |
| 852 | return; |
| 853 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 854 | #ifdef CONFIG_SH_FPU_EMU |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 855 | get_user(inst, (unsigned short *)regs->pc + 1); |
| 856 | if (!do_fpu_inst(inst, regs)) { |
| 857 | get_user(inst, (unsigned short *)regs->pc); |
| 858 | if (!emulate_branch(inst, regs)) |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 859 | return; |
| 860 | /* fault in branch.*/ |
| 861 | } |
| 862 | /* not a FPU inst. */ |
| 863 | #endif |
| 864 | |
Paul Mundt | 4c59e29 | 2008-09-21 12:00:23 +0900 | [diff] [blame] | 865 | inst = lookup_exception_vector(); |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 866 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 867 | local_irq_enable(); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 868 | force_sig(SIGILL, tsk); |
Paul Mundt | b3d765f | 2008-09-17 23:12:11 +0900 | [diff] [blame] | 869 | die_if_no_fixup("illegal slot instruction", regs, inst); |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 870 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
| 872 | asmlinkage void do_exception_error(unsigned long r4, unsigned long r5, |
| 873 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 874 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 876 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | long ex; |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 878 | |
Paul Mundt | 4c59e29 | 2008-09-21 12:00:23 +0900 | [diff] [blame] | 879 | ex = lookup_exception_vector(); |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 880 | die_if_kernel("exception", regs, ex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | #if defined(CONFIG_SH_STANDARD_BIOS) |
| 884 | void *gdb_vbr_vector; |
| 885 | |
| 886 | static inline void __init gdb_vbr_init(void) |
| 887 | { |
| 888 | register unsigned long vbr; |
| 889 | |
| 890 | /* |
| 891 | * Read the old value of the VBR register to initialise |
| 892 | * the vector through which debug and BIOS traps are |
| 893 | * delegated by the Linux trap handler. |
| 894 | */ |
| 895 | asm volatile("stc vbr, %0" : "=r" (vbr)); |
| 896 | |
| 897 | gdb_vbr_vector = (void *)(vbr + 0x100); |
| 898 | printk("Setting GDB trap vector to 0x%08lx\n", |
| 899 | (unsigned long)gdb_vbr_vector); |
| 900 | } |
| 901 | #endif |
| 902 | |
Paul Mundt | aba1030 | 2007-09-21 18:32:32 +0900 | [diff] [blame] | 903 | void __cpuinit per_cpu_trap_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
| 905 | extern void *vbr_base; |
| 906 | |
| 907 | #ifdef CONFIG_SH_STANDARD_BIOS |
Paul Mundt | aba1030 | 2007-09-21 18:32:32 +0900 | [diff] [blame] | 908 | if (raw_smp_processor_id() == 0) |
| 909 | gdb_vbr_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | #endif |
| 911 | |
| 912 | /* NOTE: The VBR value should be at P1 |
| 913 | (or P2, virtural "fixed" address space). |
| 914 | It's definitely should not in physical address. */ |
| 915 | |
| 916 | asm volatile("ldc %0, vbr" |
| 917 | : /* no output */ |
| 918 | : "r" (&vbr_base) |
| 919 | : "memory"); |
| 920 | } |
| 921 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 922 | void *set_exception_table_vec(unsigned int vec, void *handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
| 924 | extern void *exception_handling_table[]; |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 925 | void *old_handler; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 926 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 927 | old_handler = exception_handling_table[vec]; |
| 928 | exception_handling_table[vec] = handler; |
| 929 | return old_handler; |
| 930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 932 | void __init trap_init(void) |
| 933 | { |
| 934 | set_exception_table_vec(TRAP_RESERVED_INST, do_reserved_inst); |
| 935 | set_exception_table_vec(TRAP_ILLEGAL_SLOT_INST, do_illegal_slot_inst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Takashi YOSHII | 4b56568 | 2006-09-27 17:15:32 +0900 | [diff] [blame] | 937 | #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_FPU) || \ |
| 938 | defined(CONFIG_SH_FPU_EMU) |
| 939 | /* |
| 940 | * For SH-4 lacking an FPU, treat floating point instructions as |
| 941 | * reserved. They'll be handled in the math-emu case, or faulted on |
| 942 | * otherwise. |
| 943 | */ |
Paul Mundt | 1f66658 | 2006-10-19 16:20:25 +0900 | [diff] [blame] | 944 | set_exception_table_evt(0x800, do_reserved_inst); |
| 945 | set_exception_table_evt(0x820, do_illegal_slot_inst); |
| 946 | #elif defined(CONFIG_SH_FPU) |
Paul Mundt | e0a3647 | 2007-08-01 16:55:07 +0900 | [diff] [blame] | 947 | #ifdef CONFIG_CPU_SUBTYPE_SHX3 |
Paul Mundt | 74d99a5 | 2007-11-26 20:38:36 +0900 | [diff] [blame] | 948 | set_exception_table_evt(0xd80, fpu_state_restore_trap_handler); |
| 949 | set_exception_table_evt(0xda0, fpu_state_restore_trap_handler); |
Paul Mundt | e0a3647 | 2007-08-01 16:55:07 +0900 | [diff] [blame] | 950 | #else |
Paul Mundt | 74d99a5 | 2007-11-26 20:38:36 +0900 | [diff] [blame] | 951 | set_exception_table_evt(0x800, fpu_state_restore_trap_handler); |
| 952 | set_exception_table_evt(0x820, fpu_state_restore_trap_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | #endif |
Paul Mundt | e0a3647 | 2007-08-01 16:55:07 +0900 | [diff] [blame] | 954 | #endif |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 955 | |
| 956 | #ifdef CONFIG_CPU_SH2 |
Paul Mundt | 5a4f7c6 | 2007-11-20 18:08:06 +0900 | [diff] [blame] | 957 | set_exception_table_vec(TRAP_ADDRESS_ERROR, address_error_trap_handler); |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 958 | #endif |
| 959 | #ifdef CONFIG_CPU_SH2A |
| 960 | set_exception_table_vec(TRAP_DIVZERO_ERROR, do_divide_error); |
| 961 | set_exception_table_vec(TRAP_DIVOVF_ERROR, do_divide_error); |
Yoshinori Sato | 6e80f5e | 2008-07-10 01:20:03 +0900 | [diff] [blame] | 962 | #ifdef CONFIG_SH_FPU |
| 963 | set_exception_table_vec(TRAP_FPU_ERROR, fpu_error_trap_handler); |
| 964 | #endif |
Yoshinori Sato | 0983b31 | 2006-11-05 15:58:47 +0900 | [diff] [blame] | 965 | #endif |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 966 | |
Peter Griffin | cd89436 | 2009-05-08 15:51:51 +0100 | [diff] [blame] | 967 | #ifdef TRAP_UBC |
| 968 | set_exception_table_vec(TRAP_UBC, break_point_trap); |
| 969 | #endif |
| 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | /* Setup VBR for boot cpu */ |
| 972 | per_cpu_trap_init(); |
| 973 | } |
| 974 | |
| 975 | void show_stack(struct task_struct *tsk, unsigned long *sp) |
| 976 | { |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 977 | unsigned long stack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 979 | if (!tsk) |
| 980 | tsk = current; |
| 981 | if (tsk == current) |
| 982 | sp = (unsigned long *)current_stack_pointer; |
| 983 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | sp = (unsigned long *)tsk->thread.sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 986 | stack = (unsigned long)sp; |
| 987 | dump_mem("Stack: ", stack, THREAD_SIZE + |
| 988 | (unsigned long)task_stack_page(tsk)); |
| 989 | show_trace(tsk, sp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | void dump_stack(void) |
| 993 | { |
| 994 | show_stack(NULL, NULL); |
| 995 | } |
| 996 | EXPORT_SYMBOL(dump_stack); |
Andre Draszik | 7436cde | 2009-08-24 14:53:46 +0900 | [diff] [blame] | 997 | |
| 998 | #ifdef CONFIG_PROC_FS |
| 999 | /* |
| 1000 | * This needs to be done after sysctl_init, otherwise sys/ will be |
| 1001 | * overwritten. Actually, this shouldn't be in sys/ at all since |
| 1002 | * it isn't a sysctl, and it doesn't contain sysctl information. |
| 1003 | * We now locate it in /proc/cpu/alignment instead. |
| 1004 | */ |
| 1005 | static int __init alignment_init(void) |
| 1006 | { |
| 1007 | struct proc_dir_entry *dir, *res; |
| 1008 | |
| 1009 | dir = proc_mkdir("cpu", NULL); |
| 1010 | if (!dir) |
| 1011 | return -ENOMEM; |
| 1012 | |
| 1013 | res = create_proc_entry("alignment", S_IWUSR | S_IRUGO, dir); |
| 1014 | if (!res) |
| 1015 | return -ENOMEM; |
| 1016 | |
| 1017 | res->read_proc = proc_alignment_read; |
| 1018 | res->write_proc = proc_alignment_write; |
| 1019 | |
| 1020 | res = create_proc_entry("kernel_alignment", S_IWUSR | S_IRUGO, dir); |
| 1021 | if (!res) |
| 1022 | return -ENOMEM; |
| 1023 | |
| 1024 | res->read_proc = proc_alignment_read; |
| 1025 | res->write_proc = proc_alignment_kern_write; |
| 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | fs_initcall(alignment_init); |
| 1031 | #endif |