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