Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/traps.c |
| 3 | * |
Russell King | ab72b00 | 2009-10-25 15:39:37 +0000 | [diff] [blame] | 4 | * Copyright (C) 1995-2009 Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Fragments that appear the same as linux/arch/i386/kernel/traps.c (C) Linus Torvalds |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * 'traps.c' handles hardware exceptions after we have saved some state in |
| 12 | * 'linux/arch/arm/lib/traps.S'. Mostly a debugging aid, but will probably |
| 13 | * kill the offending process. |
| 14 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/personality.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/kallsyms.h> |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 18 | #include <linux/spinlock.h> |
Russell King | 33fa9b1 | 2008-09-06 11:35:55 +0100 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 20 | #include <linux/hardirq.h> |
| 21 | #include <linux/kdebug.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/kexec.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/atomic.h> |
| 28 | #include <asm/cacheflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/unistd.h> |
| 31 | #include <asm/traps.h> |
Catalin Marinas | bff595c | 2009-02-16 11:41:36 +0100 | [diff] [blame] | 32 | #include <asm/unwind.h> |
Tony Lindgren | f159f4e | 2010-07-05 14:53:10 +0100 | [diff] [blame] | 33 | #include <asm/tls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include "ptrace.h" |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 36 | #include "signal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static const char *handler[]= { "prefetch abort", "data abort", "address exception", "interrupt" }; |
| 39 | |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame^] | 40 | void *vectors_page; |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_DEBUG_USER |
| 43 | unsigned int user_debug; |
| 44 | |
| 45 | static int __init user_debug_setup(char *str) |
| 46 | { |
| 47 | get_option(&str, &user_debug); |
| 48 | return 1; |
| 49 | } |
| 50 | __setup("user_debug=", user_debug_setup); |
| 51 | #endif |
| 52 | |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 53 | static void dump_mem(const char *, const char *, unsigned long, unsigned long); |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 54 | |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 55 | void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
| 57 | #ifdef CONFIG_KALLSYMS |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 58 | char sym1[KSYM_SYMBOL_LEN], sym2[KSYM_SYMBOL_LEN]; |
| 59 | sprint_symbol(sym1, where); |
| 60 | sprint_symbol(sym2, from); |
| 61 | printk("[<%08lx>] (%s) from [<%08lx>] (%s)\n", where, sym1, from, sym2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #else |
| 63 | printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from); |
| 64 | #endif |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 65 | |
| 66 | if (in_exception_text(where)) |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 67 | dump_mem("", "Exception stack", frame + 4, frame + 4 + sizeof(struct pt_regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Catalin Marinas | bff595c | 2009-02-16 11:41:36 +0100 | [diff] [blame] | 70 | #ifndef CONFIG_ARM_UNWIND |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Stack pointers should always be within the kernels view of |
| 73 | * physical memory. If it is not there, then we can't dump |
| 74 | * out any information relating to the stack. |
| 75 | */ |
| 76 | static int verify_stack(unsigned long sp) |
| 77 | { |
Russell King | 09d9bae | 2008-09-05 14:08:44 +0100 | [diff] [blame] | 78 | if (sp < PAGE_OFFSET || |
| 79 | (sp > (unsigned long)high_memory && high_memory != NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return -EFAULT; |
| 81 | |
| 82 | return 0; |
| 83 | } |
Catalin Marinas | bff595c | 2009-02-16 11:41:36 +0100 | [diff] [blame] | 84 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * Dump out the contents of some memory nicely... |
| 88 | */ |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 89 | static void dump_mem(const char *lvl, const char *str, unsigned long bottom, |
| 90 | unsigned long top) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 92 | unsigned long first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | mm_segment_t fs; |
| 94 | int i; |
| 95 | |
| 96 | /* |
| 97 | * We need to switch to kernel mode so that we can use __get_user |
| 98 | * to safely read from kernel space. Note that we now dump the |
| 99 | * code first, just in case the backtrace kills us. |
| 100 | */ |
| 101 | fs = get_fs(); |
| 102 | set_fs(KERNEL_DS); |
| 103 | |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 104 | printk("%s%s(0x%08lx to 0x%08lx)\n", lvl, str, bottom, top); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 106 | for (first = bottom & ~31; first < top; first += 32) { |
| 107 | unsigned long p; |
| 108 | char str[sizeof(" 12345678") * 8 + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 110 | memset(str, ' ', sizeof(str)); |
| 111 | str[sizeof(str) - 1] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 113 | for (p = first, i = 0; i < 8 && p < top; i++, p += 4) { |
| 114 | if (p >= bottom && p < top) { |
| 115 | unsigned long val; |
| 116 | if (__get_user(val, (unsigned long *)p) == 0) |
| 117 | sprintf(str + i * 9, " %08lx", val); |
| 118 | else |
| 119 | sprintf(str + i * 9, " ????????"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 122 | printk("%s%04lx:%s\n", lvl, first & 0xffff, str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | set_fs(fs); |
| 126 | } |
| 127 | |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 128 | static void dump_instr(const char *lvl, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | unsigned long addr = instruction_pointer(regs); |
| 131 | const int thumb = thumb_mode(regs); |
| 132 | const int width = thumb ? 4 : 8; |
| 133 | mm_segment_t fs; |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 134 | char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | int i; |
| 136 | |
| 137 | /* |
| 138 | * We need to switch to kernel mode so that we can use __get_user |
| 139 | * to safely read from kernel space. Note that we now dump the |
| 140 | * code first, just in case the backtrace kills us. |
| 141 | */ |
| 142 | fs = get_fs(); |
| 143 | set_fs(KERNEL_DS); |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | for (i = -4; i < 1; i++) { |
| 146 | unsigned int val, bad; |
| 147 | |
| 148 | if (thumb) |
| 149 | bad = __get_user(val, &((u16 *)addr)[i]); |
| 150 | else |
| 151 | bad = __get_user(val, &((u32 *)addr)[i]); |
| 152 | |
| 153 | if (!bad) |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 154 | p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ", |
| 155 | width, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | else { |
Russell King | d191fe0 | 2009-10-11 15:03:11 +0100 | [diff] [blame] | 157 | p += sprintf(p, "bad PC value"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | break; |
| 159 | } |
| 160 | } |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 161 | printk("%sCode: %s\n", lvl, str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | set_fs(fs); |
| 164 | } |
| 165 | |
Catalin Marinas | bff595c | 2009-02-16 11:41:36 +0100 | [diff] [blame] | 166 | #ifdef CONFIG_ARM_UNWIND |
| 167 | static inline void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) |
| 168 | { |
| 169 | unwind_backtrace(regs, tsk); |
| 170 | } |
| 171 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) |
| 173 | { |
Catalin Marinas | 67a94c2 | 2009-02-11 13:06:53 +0100 | [diff] [blame] | 174 | unsigned int fp, mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | int ok = 1; |
| 176 | |
| 177 | printk("Backtrace: "); |
Catalin Marinas | 67a94c2 | 2009-02-11 13:06:53 +0100 | [diff] [blame] | 178 | |
| 179 | if (!tsk) |
| 180 | tsk = current; |
| 181 | |
| 182 | if (regs) { |
| 183 | fp = regs->ARM_fp; |
| 184 | mode = processor_mode(regs); |
| 185 | } else if (tsk != current) { |
| 186 | fp = thread_saved_fp(tsk); |
| 187 | mode = 0x10; |
| 188 | } else { |
| 189 | asm("mov %0, fp" : "=r" (fp) : : "cc"); |
| 190 | mode = 0x10; |
| 191 | } |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | if (!fp) { |
| 194 | printk("no frame pointer"); |
| 195 | ok = 0; |
| 196 | } else if (verify_stack(fp)) { |
| 197 | printk("invalid frame pointer 0x%08x", fp); |
| 198 | ok = 0; |
Al Viro | 5520582 | 2006-01-12 01:05:57 -0800 | [diff] [blame] | 199 | } else if (fp < (unsigned long)end_of_stack(tsk)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | printk("frame pointer underflow"); |
| 201 | printk("\n"); |
| 202 | |
| 203 | if (ok) |
Catalin Marinas | 67a94c2 | 2009-02-11 13:06:53 +0100 | [diff] [blame] | 204 | c_backtrace(fp, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
Catalin Marinas | bff595c | 2009-02-16 11:41:36 +0100 | [diff] [blame] | 206 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | void dump_stack(void) |
| 209 | { |
Catalin Marinas | 67a94c2 | 2009-02-11 13:06:53 +0100 | [diff] [blame] | 210 | dump_backtrace(NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | EXPORT_SYMBOL(dump_stack); |
| 214 | |
| 215 | void show_stack(struct task_struct *tsk, unsigned long *sp) |
| 216 | { |
Catalin Marinas | 67a94c2 | 2009-02-11 13:06:53 +0100 | [diff] [blame] | 217 | dump_backtrace(NULL, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | barrier(); |
| 219 | } |
| 220 | |
Russell King | d920242 | 2007-06-17 13:38:27 +0100 | [diff] [blame] | 221 | #ifdef CONFIG_PREEMPT |
| 222 | #define S_PREEMPT " PREEMPT" |
| 223 | #else |
| 224 | #define S_PREEMPT "" |
| 225 | #endif |
| 226 | #ifdef CONFIG_SMP |
| 227 | #define S_SMP " SMP" |
| 228 | #else |
| 229 | #define S_SMP "" |
| 230 | #endif |
| 231 | |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 232 | static int __die(const char *str, int err, struct thread_info *thread, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Russell King | d362979 | 2005-10-30 19:01:43 +0000 | [diff] [blame] | 234 | struct task_struct *tsk = thread->task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | static int die_counter; |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 236 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 238 | printk(KERN_EMERG "Internal error: %s: %x [#%d]" S_PREEMPT S_SMP "\n", |
Russell King | d920242 | 2007-06-17 13:38:27 +0100 | [diff] [blame] | 239 | str, err, ++die_counter); |
Russell King | 03a6e5b | 2009-10-11 15:25:05 +0100 | [diff] [blame] | 240 | sysfs_printk_last_file(); |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 241 | |
| 242 | /* trap and error numbers are mostly meaningless on ARM */ |
| 243 | ret = notify_die(DIE_OOPS, str, regs, err, tsk->thread.trap_no, SIGSEGV); |
| 244 | if (ret == NOTIFY_STOP) |
| 245 | return ret; |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | print_modules(); |
Russell King | 652a12e | 2005-04-17 15:50:36 +0100 | [diff] [blame] | 248 | __show_regs(regs); |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 249 | printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n", |
| 250 | TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | if (!user_mode(regs) || in_interrupt()) { |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 253 | dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp, |
Al Viro | 32d39a9 | 2006-01-12 01:05:58 -0800 | [diff] [blame] | 254 | THREAD_SIZE + (unsigned long)task_stack_page(tsk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | dump_backtrace(regs, tsk); |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 256 | dump_instr(KERN_EMERG, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 258 | |
| 259 | return ret; |
Russell King | d362979 | 2005-10-30 19:01:43 +0000 | [diff] [blame] | 260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Russell King | d362979 | 2005-10-30 19:01:43 +0000 | [diff] [blame] | 262 | DEFINE_SPINLOCK(die_lock); |
| 263 | |
| 264 | /* |
| 265 | * This function is protected against re-entrancy. |
| 266 | */ |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 267 | void die(const char *str, struct pt_regs *regs, int err) |
Russell King | d362979 | 2005-10-30 19:01:43 +0000 | [diff] [blame] | 268 | { |
| 269 | struct thread_info *thread = current_thread_info(); |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 270 | int ret; |
Russell King | d362979 | 2005-10-30 19:01:43 +0000 | [diff] [blame] | 271 | |
Russell King | d920242 | 2007-06-17 13:38:27 +0100 | [diff] [blame] | 272 | oops_enter(); |
| 273 | |
Russell King | d362979 | 2005-10-30 19:01:43 +0000 | [diff] [blame] | 274 | spin_lock_irq(&die_lock); |
Russell King | 03a6e5b | 2009-10-11 15:25:05 +0100 | [diff] [blame] | 275 | console_verbose(); |
Russell King | d362979 | 2005-10-30 19:01:43 +0000 | [diff] [blame] | 276 | bust_spinlocks(1); |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 277 | ret = __die(str, err, thread, regs); |
| 278 | |
| 279 | if (regs && kexec_should_crash(thread->task)) |
| 280 | crash_kexec(regs); |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | bust_spinlocks(0); |
Pavel Emelianov | bcdcd8e | 2007-07-17 04:03:42 -0700 | [diff] [blame] | 283 | add_taint(TAINT_DIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | spin_unlock_irq(&die_lock); |
Russell King | 03a6e5b | 2009-10-11 15:25:05 +0100 | [diff] [blame] | 285 | oops_exit(); |
Russell King | 3186749 | 2006-02-19 19:53:56 +0000 | [diff] [blame] | 286 | |
Russell King | d920242 | 2007-06-17 13:38:27 +0100 | [diff] [blame] | 287 | if (in_interrupt()) |
| 288 | panic("Fatal exception in interrupt"); |
Horms | cea6a4b | 2006-07-30 03:03:34 -0700 | [diff] [blame] | 289 | if (panic_on_oops) |
Horms | 012c437 | 2006-08-13 23:24:22 -0700 | [diff] [blame] | 290 | panic("Fatal exception"); |
Russell King | a9221de | 2010-01-20 17:02:54 +0000 | [diff] [blame] | 291 | if (ret != NOTIFY_STOP) |
| 292 | do_exit(SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 295 | void arm_notify_die(const char *str, struct pt_regs *regs, |
| 296 | struct siginfo *info, unsigned long err, unsigned long trap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
| 298 | if (user_mode(regs)) { |
| 299 | current->thread.error_code = err; |
| 300 | current->thread.trap_no = trap; |
| 301 | |
| 302 | force_sig_info(info->si_signo, info, current); |
| 303 | } else { |
| 304 | die(str, regs, err); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | static LIST_HEAD(undef_hook); |
| 309 | static DEFINE_SPINLOCK(undef_lock); |
| 310 | |
| 311 | void register_undef_hook(struct undef_hook *hook) |
| 312 | { |
Russell King | 109d89c | 2005-07-16 16:43:33 +0100 | [diff] [blame] | 313 | unsigned long flags; |
| 314 | |
| 315 | spin_lock_irqsave(&undef_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | list_add(&hook->node, &undef_hook); |
Russell King | 109d89c | 2005-07-16 16:43:33 +0100 | [diff] [blame] | 317 | spin_unlock_irqrestore(&undef_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void unregister_undef_hook(struct undef_hook *hook) |
| 321 | { |
Russell King | 109d89c | 2005-07-16 16:43:33 +0100 | [diff] [blame] | 322 | unsigned long flags; |
| 323 | |
| 324 | spin_lock_irqsave(&undef_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | list_del(&hook->node); |
Russell King | 109d89c | 2005-07-16 16:43:33 +0100 | [diff] [blame] | 326 | spin_unlock_irqrestore(&undef_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Russell King | b03a5b7 | 2008-08-11 12:27:16 +0100 | [diff] [blame] | 329 | static int call_undef_hook(struct pt_regs *regs, unsigned int instr) |
| 330 | { |
| 331 | struct undef_hook *hook; |
| 332 | unsigned long flags; |
| 333 | int (*fn)(struct pt_regs *regs, unsigned int instr) = NULL; |
| 334 | |
| 335 | spin_lock_irqsave(&undef_lock, flags); |
| 336 | list_for_each_entry(hook, &undef_hook, node) |
| 337 | if ((instr & hook->instr_mask) == hook->instr_val && |
| 338 | (regs->ARM_cpsr & hook->cpsr_mask) == hook->cpsr_val) |
| 339 | fn = hook->fn; |
| 340 | spin_unlock_irqrestore(&undef_lock, flags); |
| 341 | |
| 342 | return fn ? fn(regs, instr) : 1; |
| 343 | } |
| 344 | |
Russell King | 7ab3f8d | 2007-03-02 15:01:36 +0000 | [diff] [blame] | 345 | asmlinkage void __exception do_undefinstr(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
| 347 | unsigned int correction = thumb_mode(regs) ? 2 : 4; |
| 348 | unsigned int instr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | siginfo_t info; |
| 350 | void __user *pc; |
| 351 | |
| 352 | /* |
| 353 | * According to the ARM ARM, PC is 2 or 4 bytes ahead, |
| 354 | * depending whether we're in Thumb mode or not. |
| 355 | * Correct this offset. |
| 356 | */ |
| 357 | regs->ARM_pc -= correction; |
| 358 | |
| 359 | pc = (void __user *)instruction_pointer(regs); |
Dan Williams | dfc544c | 2007-02-13 17:11:34 +0100 | [diff] [blame] | 360 | |
| 361 | if (processor_mode(regs) == SVC_MODE) { |
| 362 | instr = *(u32 *) pc; |
| 363 | } else if (thumb_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | get_user(instr, (u16 __user *)pc); |
| 365 | } else { |
| 366 | get_user(instr, (u32 __user *)pc); |
| 367 | } |
| 368 | |
Russell King | b03a5b7 | 2008-08-11 12:27:16 +0100 | [diff] [blame] | 369 | if (call_undef_hook(regs, instr) == 0) |
| 370 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | #ifdef CONFIG_DEBUG_USER |
| 373 | if (user_debug & UDBG_UNDEFINED) { |
| 374 | printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 375 | current->comm, task_pid_nr(current), pc); |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 376 | dump_instr(KERN_INFO, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | #endif |
| 379 | |
| 380 | info.si_signo = SIGILL; |
| 381 | info.si_errno = 0; |
| 382 | info.si_code = ILL_ILLOPC; |
| 383 | info.si_addr = pc; |
| 384 | |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 385 | arm_notify_die("Oops - undefined instruction", regs, &info, 0, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | asmlinkage void do_unexp_fiq (struct pt_regs *regs) |
| 389 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | printk("Hmm. Unexpected FIQ received, but trying to continue\n"); |
| 391 | printk("You may have a hardware problem...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* |
| 395 | * bad_mode handles the impossible case in the vectors. If you see one of |
| 396 | * these, then it's extremely serious, and could mean you have buggy hardware. |
| 397 | * It never returns, and never tries to sync. We hope that we can at least |
| 398 | * dump out some state information... |
| 399 | */ |
Russell King | ae0a846 | 2007-01-09 12:57:37 +0000 | [diff] [blame] | 400 | asmlinkage void bad_mode(struct pt_regs *regs, int reason) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 402 | console_verbose(); |
| 403 | |
Russell King | ae0a846 | 2007-01-09 12:57:37 +0000 | [diff] [blame] | 404 | printk(KERN_CRIT "Bad mode in %s handler detected\n", handler[reason]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | die("Oops - bad mode", regs, 0); |
| 407 | local_irq_disable(); |
| 408 | panic("bad mode"); |
| 409 | } |
| 410 | |
| 411 | static int bad_syscall(int n, struct pt_regs *regs) |
| 412 | { |
| 413 | struct thread_info *thread = current_thread_info(); |
| 414 | siginfo_t info; |
| 415 | |
Nicolas Pitre | a999cb0 | 2005-10-28 16:35:46 +0100 | [diff] [blame] | 416 | if (current->personality != PER_LINUX && |
| 417 | current->personality != PER_LINUX_32BIT && |
| 418 | thread->exec_domain->handler) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | thread->exec_domain->handler(n, regs); |
| 420 | return regs->ARM_r0; |
| 421 | } |
| 422 | |
| 423 | #ifdef CONFIG_DEBUG_USER |
| 424 | if (user_debug & UDBG_SYSCALL) { |
| 425 | printk(KERN_ERR "[%d] %s: obsolete system call %08x.\n", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 426 | task_pid_nr(current), current->comm, n); |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 427 | dump_instr(KERN_ERR, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | #endif |
| 430 | |
| 431 | info.si_signo = SIGILL; |
| 432 | info.si_errno = 0; |
| 433 | info.si_code = ILL_ILLTRP; |
| 434 | info.si_addr = (void __user *)instruction_pointer(regs) - |
| 435 | (thumb_mode(regs) ? 2 : 4); |
| 436 | |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 437 | arm_notify_die("Oops - bad syscall", regs, &info, n, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | return regs->ARM_r0; |
| 440 | } |
| 441 | |
| 442 | static inline void |
| 443 | do_cache_op(unsigned long start, unsigned long end, int flags) |
| 444 | { |
Russell King | aa45ee8f | 2009-09-28 11:41:51 +0100 | [diff] [blame] | 445 | struct mm_struct *mm = current->active_mm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | struct vm_area_struct *vma; |
| 447 | |
| 448 | if (end < start || flags) |
| 449 | return; |
| 450 | |
Russell King | aa45ee8f | 2009-09-28 11:41:51 +0100 | [diff] [blame] | 451 | down_read(&mm->mmap_sem); |
| 452 | vma = find_vma(mm, start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (vma && vma->vm_start < end) { |
| 454 | if (start < vma->vm_start) |
| 455 | start = vma->vm_start; |
| 456 | if (end > vma->vm_end) |
| 457 | end = vma->vm_end; |
| 458 | |
| 459 | flush_cache_user_range(vma, start, end); |
| 460 | } |
Russell King | aa45ee8f | 2009-09-28 11:41:51 +0100 | [diff] [blame] | 461 | up_read(&mm->mmap_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Handle all unrecognised system calls. |
| 466 | * 0x9f0000 - 0x9fffff are some more esoteric system calls |
| 467 | */ |
| 468 | #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE) |
| 469 | asmlinkage int arm_syscall(int no, struct pt_regs *regs) |
| 470 | { |
| 471 | struct thread_info *thread = current_thread_info(); |
| 472 | siginfo_t info; |
| 473 | |
Nicolas Pitre | 3f2829a | 2006-01-14 16:31:29 +0000 | [diff] [blame] | 474 | if ((no >> 16) != (__ARM_NR_BASE>> 16)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return bad_syscall(no, regs); |
| 476 | |
| 477 | switch (no & 0xffff) { |
| 478 | case 0: /* branch through 0 */ |
| 479 | info.si_signo = SIGSEGV; |
| 480 | info.si_errno = 0; |
| 481 | info.si_code = SEGV_MAPERR; |
| 482 | info.si_addr = NULL; |
| 483 | |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 484 | arm_notify_die("branch through zero", regs, &info, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | return 0; |
| 486 | |
| 487 | case NR(breakpoint): /* SWI BREAK_POINT */ |
| 488 | regs->ARM_pc -= thumb_mode(regs) ? 2 : 4; |
| 489 | ptrace_break(current, regs); |
| 490 | return regs->ARM_r0; |
| 491 | |
| 492 | /* |
| 493 | * Flush a region from virtual address 'r0' to virtual address 'r1' |
| 494 | * _exclusive_. There is no alignment requirement on either address; |
| 495 | * user space does not need to know the hardware cache layout. |
| 496 | * |
| 497 | * r2 contains flags. It should ALWAYS be passed as ZERO until it |
| 498 | * is defined to be something else. For now we ignore it, but may |
| 499 | * the fires of hell burn in your belly if you break this rule. ;) |
| 500 | * |
| 501 | * (at a later date, we may want to allow this call to not flush |
| 502 | * various aspects of the cache. Passing '0' will guarantee that |
| 503 | * everything necessary gets flushed to maintain consistency in |
| 504 | * the specified region). |
| 505 | */ |
| 506 | case NR(cacheflush): |
| 507 | do_cache_op(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2); |
| 508 | return 0; |
| 509 | |
| 510 | case NR(usr26): |
| 511 | if (!(elf_hwcap & HWCAP_26BIT)) |
| 512 | break; |
| 513 | regs->ARM_cpsr &= ~MODE32_BIT; |
| 514 | return regs->ARM_r0; |
| 515 | |
| 516 | case NR(usr32): |
| 517 | if (!(elf_hwcap & HWCAP_26BIT)) |
| 518 | break; |
| 519 | regs->ARM_cpsr |= MODE32_BIT; |
| 520 | return regs->ARM_r0; |
| 521 | |
| 522 | case NR(set_tls): |
| 523 | thread->tp_value = regs->ARM_r0; |
Tony Lindgren | f159f4e | 2010-07-05 14:53:10 +0100 | [diff] [blame] | 524 | if (tls_emu) |
| 525 | return 0; |
| 526 | if (has_tls_reg) { |
| 527 | asm ("mcr p15, 0, %0, c13, c0, 3" |
| 528 | : : "r" (regs->ARM_r0)); |
| 529 | } else { |
| 530 | /* |
| 531 | * User space must never try to access this directly. |
| 532 | * Expect your app to break eventually if you do so. |
| 533 | * The user helper at 0xffff0fe0 must be used instead. |
| 534 | * (see entry-armv.S for details) |
| 535 | */ |
| 536 | *((unsigned int *)0xffff0ff0) = regs->ARM_r0; |
| 537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return 0; |
| 539 | |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 540 | #ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG |
| 541 | /* |
| 542 | * Atomically store r1 in *r2 if *r2 is equal to r0 for user space. |
| 543 | * Return zero in r0 if *MEM was changed or non-zero if no exchange |
| 544 | * happened. Also set the user C flag accordingly. |
| 545 | * If access permissions have to be fixed up then non-zero is |
| 546 | * returned and the operation has to be re-attempted. |
| 547 | * |
| 548 | * *NOTE*: This is a ghost syscall private to the kernel. Only the |
| 549 | * __kuser_cmpxchg code in entry-armv.S should be aware of its |
| 550 | * existence. Don't ever use this from user code. |
| 551 | */ |
Russell King | cc20d42 | 2009-11-09 23:53:29 +0000 | [diff] [blame] | 552 | case NR(cmpxchg): |
Nicolas Pitre | b49c0f2 | 2007-11-20 17:20:29 +0100 | [diff] [blame] | 553 | for (;;) { |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 554 | extern void do_DataAbort(unsigned long addr, unsigned int fsr, |
| 555 | struct pt_regs *regs); |
| 556 | unsigned long val; |
| 557 | unsigned long addr = regs->ARM_r2; |
| 558 | struct mm_struct *mm = current->mm; |
| 559 | pgd_t *pgd; pmd_t *pmd; pte_t *pte; |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 560 | spinlock_t *ptl; |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 561 | |
| 562 | regs->ARM_cpsr &= ~PSR_C_BIT; |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 563 | down_read(&mm->mmap_sem); |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 564 | pgd = pgd_offset(mm, addr); |
| 565 | if (!pgd_present(*pgd)) |
| 566 | goto bad_access; |
| 567 | pmd = pmd_offset(pgd, addr); |
| 568 | if (!pmd_present(*pmd)) |
| 569 | goto bad_access; |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 570 | pte = pte_offset_map_lock(mm, pmd, addr, &ptl); |
Nicolas Pitre | 2ce9804 | 2006-03-25 22:44:05 +0000 | [diff] [blame] | 571 | if (!pte_present(*pte) || !pte_dirty(*pte)) { |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 572 | pte_unmap_unlock(pte, ptl); |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 573 | goto bad_access; |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 574 | } |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 575 | val = *(unsigned long *)addr; |
| 576 | val -= regs->ARM_r0; |
| 577 | if (val == 0) { |
| 578 | *(unsigned long *)addr = regs->ARM_r1; |
| 579 | regs->ARM_cpsr |= PSR_C_BIT; |
| 580 | } |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 581 | pte_unmap_unlock(pte, ptl); |
| 582 | up_read(&mm->mmap_sem); |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 583 | return val; |
| 584 | |
| 585 | bad_access: |
Hugh Dickins | 69b0475 | 2005-10-29 18:16:36 -0700 | [diff] [blame] | 586 | up_read(&mm->mmap_sem); |
Nicolas Pitre | 74f8849 | 2005-10-04 23:17:52 +0100 | [diff] [blame] | 587 | /* simulate a write access fault */ |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 588 | do_DataAbort(addr, 15 + (1 << 11), regs); |
Nicolas Pitre | dcef1f6 | 2005-06-08 19:00:47 +0100 | [diff] [blame] | 589 | } |
| 590 | #endif |
| 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | default: |
| 593 | /* Calls 9f00xx..9f07ff are defined to return -ENOSYS |
| 594 | if not implemented, rather than raising SIGILL. This |
| 595 | way the calling program can gracefully determine whether |
| 596 | a feature is supported. */ |
Russell King | bfd2e29 | 2009-11-08 20:05:28 +0000 | [diff] [blame] | 597 | if ((no & 0xffff) <= 0x7ff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | return -ENOSYS; |
| 599 | break; |
| 600 | } |
| 601 | #ifdef CONFIG_DEBUG_USER |
| 602 | /* |
| 603 | * experience shows that these seem to indicate that |
| 604 | * something catastrophic has happened |
| 605 | */ |
| 606 | if (user_debug & UDBG_SYSCALL) { |
| 607 | printk("[%d] %s: arm syscall %d\n", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 608 | task_pid_nr(current), current->comm, no); |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 609 | dump_instr("", regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | if (user_mode(regs)) { |
Russell King | 652a12e | 2005-04-17 15:50:36 +0100 | [diff] [blame] | 611 | __show_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | c_backtrace(regs->ARM_fp, processor_mode(regs)); |
| 613 | } |
| 614 | } |
| 615 | #endif |
| 616 | info.si_signo = SIGILL; |
| 617 | info.si_errno = 0; |
| 618 | info.si_code = ILL_ILLTRP; |
| 619 | info.si_addr = (void __user *)instruction_pointer(regs) - |
| 620 | (thumb_mode(regs) ? 2 : 4); |
| 621 | |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 622 | arm_notify_die("Oops - bad syscall(2)", regs, &info, no, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return 0; |
| 624 | } |
| 625 | |
Nicolas Pitre | 4b0e07a | 2005-05-05 23:24:45 +0100 | [diff] [blame] | 626 | #ifdef CONFIG_TLS_REG_EMUL |
Nicolas Pitre | 2d2669b | 2005-04-29 22:08:33 +0100 | [diff] [blame] | 627 | |
| 628 | /* |
| 629 | * We might be running on an ARMv6+ processor which should have the TLS |
Nicolas Pitre | 4b0e07a | 2005-05-05 23:24:45 +0100 | [diff] [blame] | 630 | * register but for some reason we can't use it, or maybe an SMP system |
| 631 | * using a pre-ARMv6 processor (there are apparently a few prototypes like |
| 632 | * that in existence) and therefore access to that register must be |
| 633 | * emulated. |
Nicolas Pitre | 2d2669b | 2005-04-29 22:08:33 +0100 | [diff] [blame] | 634 | */ |
| 635 | |
| 636 | static int get_tp_trap(struct pt_regs *regs, unsigned int instr) |
| 637 | { |
| 638 | int reg = (instr >> 12) & 15; |
| 639 | if (reg == 15) |
| 640 | return 1; |
| 641 | regs->uregs[reg] = current_thread_info()->tp_value; |
| 642 | regs->ARM_pc += 4; |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | static struct undef_hook arm_mrc_hook = { |
| 647 | .instr_mask = 0x0fff0fff, |
| 648 | .instr_val = 0x0e1d0f70, |
| 649 | .cpsr_mask = PSR_T_BIT, |
| 650 | .cpsr_val = 0, |
| 651 | .fn = get_tp_trap, |
| 652 | }; |
| 653 | |
| 654 | static int __init arm_mrc_hook_init(void) |
| 655 | { |
| 656 | register_undef_hook(&arm_mrc_hook); |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | late_initcall(arm_mrc_hook_init); |
| 661 | |
| 662 | #endif |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | void __bad_xchg(volatile void *ptr, int size) |
| 665 | { |
| 666 | printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n", |
| 667 | __builtin_return_address(0), ptr, size); |
| 668 | BUG(); |
| 669 | } |
| 670 | EXPORT_SYMBOL(__bad_xchg); |
| 671 | |
| 672 | /* |
| 673 | * A data abort trap was taken, but we did not handle the instruction. |
| 674 | * Try to abort the user program, or panic if it was the kernel. |
| 675 | */ |
| 676 | asmlinkage void |
| 677 | baddataabort(int code, unsigned long instr, struct pt_regs *regs) |
| 678 | { |
| 679 | unsigned long addr = instruction_pointer(regs); |
| 680 | siginfo_t info; |
| 681 | |
| 682 | #ifdef CONFIG_DEBUG_USER |
| 683 | if (user_debug & UDBG_BADABORT) { |
| 684 | printk(KERN_ERR "[%d] %s: bad data abort: code %d instr 0x%08lx\n", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 685 | task_pid_nr(current), current->comm, code, instr); |
Russell King | e40c2ec | 2009-10-11 15:17:53 +0100 | [diff] [blame] | 686 | dump_instr(KERN_ERR, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | show_pte(current->mm, addr); |
| 688 | } |
| 689 | #endif |
| 690 | |
| 691 | info.si_signo = SIGILL; |
| 692 | info.si_errno = 0; |
| 693 | info.si_code = ILL_ILLOPC; |
| 694 | info.si_addr = (void __user *)addr; |
| 695 | |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 696 | arm_notify_die("unknown data abort code", regs, &info, instr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Nicolas Pitre | 7174d85 | 2006-12-07 19:09:20 +0100 | [diff] [blame] | 699 | void __attribute__((noreturn)) __bug(const char *file, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | { |
Nicolas Pitre | 7174d85 | 2006-12-07 19:09:20 +0100 | [diff] [blame] | 701 | printk(KERN_CRIT"kernel BUG at %s:%d!\n", file, line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | *(int *)0 = 0; |
Catalin Marinas | 6a1ced5 | 2005-09-21 22:14:05 +0100 | [diff] [blame] | 703 | |
| 704 | /* Avoid "noreturn function does return" */ |
| 705 | for (;;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | EXPORT_SYMBOL(__bug); |
| 708 | |
| 709 | void __readwrite_bug(const char *fn) |
| 710 | { |
| 711 | printk("%s called, but not implemented\n", fn); |
| 712 | BUG(); |
| 713 | } |
| 714 | EXPORT_SYMBOL(__readwrite_bug); |
| 715 | |
| 716 | void __pte_error(const char *file, int line, unsigned long val) |
| 717 | { |
| 718 | printk("%s:%d: bad pte %08lx.\n", file, line, val); |
| 719 | } |
| 720 | |
| 721 | void __pmd_error(const char *file, int line, unsigned long val) |
| 722 | { |
| 723 | printk("%s:%d: bad pmd %08lx.\n", file, line, val); |
| 724 | } |
| 725 | |
| 726 | void __pgd_error(const char *file, int line, unsigned long val) |
| 727 | { |
| 728 | printk("%s:%d: bad pgd %08lx.\n", file, line, val); |
| 729 | } |
| 730 | |
| 731 | asmlinkage void __div0(void) |
| 732 | { |
| 733 | printk("Division by zero in kernel.\n"); |
| 734 | dump_stack(); |
| 735 | } |
| 736 | EXPORT_SYMBOL(__div0); |
| 737 | |
| 738 | void abort(void) |
| 739 | { |
| 740 | BUG(); |
| 741 | |
| 742 | /* if that doesn't kill us, halt */ |
| 743 | panic("Oops failed to kill thread"); |
| 744 | } |
| 745 | EXPORT_SYMBOL(abort); |
| 746 | |
| 747 | void __init trap_init(void) |
| 748 | { |
Jason Wessel | 5cbad0e | 2008-02-20 13:33:40 -0600 | [diff] [blame] | 749 | return; |
| 750 | } |
| 751 | |
Tony Lindgren | f159f4e | 2010-07-05 14:53:10 +0100 | [diff] [blame] | 752 | static void __init kuser_get_tls_init(unsigned long vectors) |
| 753 | { |
| 754 | /* |
| 755 | * vectors + 0xfe0 = __kuser_get_tls |
| 756 | * vectors + 0xfe8 = hardware TLS instruction at 0xffff0fe8 |
| 757 | */ |
| 758 | if (tls_emu || has_tls_reg) |
| 759 | memcpy((void *)vectors + 0xfe0, (void *)vectors + 0xfe8, 4); |
| 760 | } |
| 761 | |
Jason Wessel | 5cbad0e | 2008-02-20 13:33:40 -0600 | [diff] [blame] | 762 | void __init early_trap_init(void) |
| 763 | { |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame^] | 764 | #if defined(CONFIG_CPU_USE_DOMAINS) |
Hyok S. Choi | c760fc1 | 2006-03-27 15:18:50 +0100 | [diff] [blame] | 765 | unsigned long vectors = CONFIG_VECTORS_BASE; |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame^] | 766 | #else |
| 767 | unsigned long vectors = (unsigned long)vectors_page; |
| 768 | #endif |
Russell King | 7933523 | 2005-04-26 15:17:42 +0100 | [diff] [blame] | 769 | extern char __stubs_start[], __stubs_end[]; |
| 770 | extern char __vectors_start[], __vectors_end[]; |
Nicolas Pitre | 2d2669b | 2005-04-29 22:08:33 +0100 | [diff] [blame] | 771 | extern char __kuser_helper_start[], __kuser_helper_end[]; |
| 772 | int kuser_sz = __kuser_helper_end - __kuser_helper_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Russell King | 7933523 | 2005-04-26 15:17:42 +0100 | [diff] [blame] | 774 | /* |
Nicolas Pitre | 2d2669b | 2005-04-29 22:08:33 +0100 | [diff] [blame] | 775 | * Copy the vectors, stubs and kuser helpers (in entry-armv.S) |
| 776 | * into the vector page, mapped at 0xffff0000, and ensure these |
| 777 | * are visible to the instruction stream. |
Russell King | 7933523 | 2005-04-26 15:17:42 +0100 | [diff] [blame] | 778 | */ |
Hyok S. Choi | c760fc1 | 2006-03-27 15:18:50 +0100 | [diff] [blame] | 779 | memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start); |
| 780 | memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start); |
| 781 | memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz); |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 782 | |
| 783 | /* |
Tony Lindgren | f159f4e | 2010-07-05 14:53:10 +0100 | [diff] [blame] | 784 | * Do processor specific fixups for the kuser helpers |
| 785 | */ |
| 786 | kuser_get_tls_init(vectors); |
| 787 | |
| 788 | /* |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 789 | * Copy signal return handlers into the vector page, and |
| 790 | * set sigreturn to be a pointer to these. |
| 791 | */ |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame^] | 792 | memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE), |
| 793 | sigreturn_codes, sizeof(sigreturn_codes)); |
| 794 | memcpy((void *)(vectors + KERN_RESTART_CODE - CONFIG_VECTORS_BASE), |
| 795 | syscall_restart_code, sizeof(syscall_restart_code)); |
Russell King | e00d349 | 2005-06-22 20:26:05 +0100 | [diff] [blame] | 796 | |
Hyok S. Choi | c760fc1 | 2006-03-27 15:18:50 +0100 | [diff] [blame] | 797 | flush_icache_range(vectors, vectors + PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | modify_domain(DOMAIN_USER, DOMAIN_CLIENT); |
| 799 | } |