blob: 57e6874d0b809a21a27afe21d436fa8dca9046e9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/kernel/traps.c
3 *
4 * Copyright (C) 1995-2002 Russell King
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 Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
16#include <linux/signal.h>
17#include <linux/spinlock.h>
18#include <linux/personality.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/kallsyms.h>
Russell King31867492006-02-19 19:53:56 +000020#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
Russell King33fa9b12008-09-06 11:35:55 +010022#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include <asm/atomic.h>
25#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/unistd.h>
28#include <asm/traps.h>
29
30#include "ptrace.h"
Russell Kinge00d3492005-06-22 20:26:05 +010031#include "signal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static const char *handler[]= { "prefetch abort", "data abort", "address exception", "interrupt" };
34
35#ifdef CONFIG_DEBUG_USER
36unsigned int user_debug;
37
38static int __init user_debug_setup(char *str)
39{
40 get_option(&str, &user_debug);
41 return 1;
42}
43__setup("user_debug=", user_debug_setup);
44#endif
45
Russell King7ab3f8d2007-03-02 15:01:36 +000046static void dump_mem(const char *str, unsigned long bottom, unsigned long top);
47
Russell King7ab3f8d2007-03-02 15:01:36 +000048void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50#ifdef CONFIG_KALLSYMS
51 printk("[<%08lx>] ", where);
52 print_symbol("(%s) ", where);
53 printk("from [<%08lx>] ", from);
54 print_symbol("(%s)\n", from);
55#else
56 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
57#endif
Russell King7ab3f8d2007-03-02 15:01:36 +000058
59 if (in_exception_text(where))
60 dump_mem("Exception stack", frame + 4, frame + 4 + sizeof(struct pt_regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
63/*
64 * Stack pointers should always be within the kernels view of
65 * physical memory. If it is not there, then we can't dump
66 * out any information relating to the stack.
67 */
68static int verify_stack(unsigned long sp)
69{
Russell King09d9bae2008-09-05 14:08:44 +010070 if (sp < PAGE_OFFSET ||
71 (sp > (unsigned long)high_memory && high_memory != NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 return -EFAULT;
73
74 return 0;
75}
76
77/*
78 * Dump out the contents of some memory nicely...
79 */
80static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
81{
82 unsigned long p = bottom & ~31;
83 mm_segment_t fs;
84 int i;
85
86 /*
87 * We need to switch to kernel mode so that we can use __get_user
88 * to safely read from kernel space. Note that we now dump the
89 * code first, just in case the backtrace kills us.
90 */
91 fs = get_fs();
92 set_fs(KERNEL_DS);
93
94 printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
95
96 for (p = bottom & ~31; p < top;) {
97 printk("%04lx: ", p & 0xffff);
98
99 for (i = 0; i < 8; i++, p += 4) {
100 unsigned int val;
101
102 if (p < bottom || p >= top)
103 printk(" ");
104 else {
105 __get_user(val, (unsigned long *)p);
106 printk("%08x ", val);
107 }
108 }
109 printk ("\n");
110 }
111
112 set_fs(fs);
113}
114
115static void dump_instr(struct pt_regs *regs)
116{
117 unsigned long addr = instruction_pointer(regs);
118 const int thumb = thumb_mode(regs);
119 const int width = thumb ? 4 : 8;
120 mm_segment_t fs;
121 int i;
122
123 /*
124 * We need to switch to kernel mode so that we can use __get_user
125 * to safely read from kernel space. Note that we now dump the
126 * code first, just in case the backtrace kills us.
127 */
128 fs = get_fs();
129 set_fs(KERNEL_DS);
130
131 printk("Code: ");
132 for (i = -4; i < 1; i++) {
133 unsigned int val, bad;
134
135 if (thumb)
136 bad = __get_user(val, &((u16 *)addr)[i]);
137 else
138 bad = __get_user(val, &((u32 *)addr)[i]);
139
140 if (!bad)
141 printk(i == 0 ? "(%0*x) " : "%0*x ", width, val);
142 else {
143 printk("bad PC value.");
144 break;
145 }
146 }
147 printk("\n");
148
149 set_fs(fs);
150}
151
152static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
153{
154 unsigned int fp;
155 int ok = 1;
156
157 printk("Backtrace: ");
158 fp = regs->ARM_fp;
159 if (!fp) {
160 printk("no frame pointer");
161 ok = 0;
162 } else if (verify_stack(fp)) {
163 printk("invalid frame pointer 0x%08x", fp);
164 ok = 0;
Al Viro55205822006-01-12 01:05:57 -0800165 } else if (fp < (unsigned long)end_of_stack(tsk))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 printk("frame pointer underflow");
167 printk("\n");
168
169 if (ok)
170 c_backtrace(fp, processor_mode(regs));
171}
172
173void dump_stack(void)
174{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 __backtrace();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
178EXPORT_SYMBOL(dump_stack);
179
180void show_stack(struct task_struct *tsk, unsigned long *sp)
181{
182 unsigned long fp;
183
184 if (!tsk)
185 tsk = current;
186
187 if (tsk != current)
188 fp = thread_saved_fp(tsk);
189 else
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100190 asm("mov %0, fp" : "=r" (fp) : : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 c_backtrace(fp, 0x10);
193 barrier();
194}
195
Russell Kingd9202422007-06-17 13:38:27 +0100196#ifdef CONFIG_PREEMPT
197#define S_PREEMPT " PREEMPT"
198#else
199#define S_PREEMPT ""
200#endif
201#ifdef CONFIG_SMP
202#define S_SMP " SMP"
203#else
204#define S_SMP ""
205#endif
206
Russell Kingd3629792005-10-30 19:01:43 +0000207static void __die(const char *str, int err, struct thread_info *thread, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Russell Kingd3629792005-10-30 19:01:43 +0000209 struct task_struct *tsk = thread->task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 static int die_counter;
211
Russell Kingd9202422007-06-17 13:38:27 +0100212 printk("Internal error: %s: %x [#%d]" S_PREEMPT S_SMP "\n",
213 str, err, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 print_modules();
Russell King652a12e2005-04-17 15:50:36 +0100215 __show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 printk("Process %s (pid: %d, stack limit = 0x%p)\n",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700217 tsk->comm, task_pid_nr(tsk), thread + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 if (!user_mode(regs) || in_interrupt()) {
Russell King4f7a1812005-05-05 13:11:00 +0100220 dump_mem("Stack: ", regs->ARM_sp,
Al Viro32d39a92006-01-12 01:05:58 -0800221 THREAD_SIZE + (unsigned long)task_stack_page(tsk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 dump_backtrace(regs, tsk);
223 dump_instr(regs);
224 }
Russell Kingd3629792005-10-30 19:01:43 +0000225}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Russell Kingd3629792005-10-30 19:01:43 +0000227DEFINE_SPINLOCK(die_lock);
228
229/*
230 * This function is protected against re-entrancy.
231 */
232NORET_TYPE void die(const char *str, struct pt_regs *regs, int err)
233{
234 struct thread_info *thread = current_thread_info();
235
Russell Kingd9202422007-06-17 13:38:27 +0100236 oops_enter();
237
Russell Kingd3629792005-10-30 19:01:43 +0000238 console_verbose();
239 spin_lock_irq(&die_lock);
240 bust_spinlocks(1);
241 __die(str, err, thread, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 bust_spinlocks(0);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700243 add_taint(TAINT_DIE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 spin_unlock_irq(&die_lock);
Russell King31867492006-02-19 19:53:56 +0000245
Russell Kingd9202422007-06-17 13:38:27 +0100246 if (in_interrupt())
247 panic("Fatal exception in interrupt");
248
Hormscea6a4b2006-07-30 03:03:34 -0700249 if (panic_on_oops)
Horms012c4372006-08-13 23:24:22 -0700250 panic("Fatal exception");
Russell King31867492006-02-19 19:53:56 +0000251
Russell Kingd9202422007-06-17 13:38:27 +0100252 oops_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 do_exit(SIGSEGV);
254}
255
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -0700256void arm_notify_die(const char *str, struct pt_regs *regs,
257 struct siginfo *info, unsigned long err, unsigned long trap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 if (user_mode(regs)) {
260 current->thread.error_code = err;
261 current->thread.trap_no = trap;
262
263 force_sig_info(info->si_signo, info, current);
264 } else {
265 die(str, regs, err);
266 }
267}
268
269static LIST_HEAD(undef_hook);
270static DEFINE_SPINLOCK(undef_lock);
271
272void register_undef_hook(struct undef_hook *hook)
273{
Russell King109d89c2005-07-16 16:43:33 +0100274 unsigned long flags;
275
276 spin_lock_irqsave(&undef_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 list_add(&hook->node, &undef_hook);
Russell King109d89c2005-07-16 16:43:33 +0100278 spin_unlock_irqrestore(&undef_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
281void unregister_undef_hook(struct undef_hook *hook)
282{
Russell King109d89c2005-07-16 16:43:33 +0100283 unsigned long flags;
284
285 spin_lock_irqsave(&undef_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 list_del(&hook->node);
Russell King109d89c2005-07-16 16:43:33 +0100287 spin_unlock_irqrestore(&undef_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
Russell Kingb03a5b72008-08-11 12:27:16 +0100290static int call_undef_hook(struct pt_regs *regs, unsigned int instr)
291{
292 struct undef_hook *hook;
293 unsigned long flags;
294 int (*fn)(struct pt_regs *regs, unsigned int instr) = NULL;
295
296 spin_lock_irqsave(&undef_lock, flags);
297 list_for_each_entry(hook, &undef_hook, node)
298 if ((instr & hook->instr_mask) == hook->instr_val &&
299 (regs->ARM_cpsr & hook->cpsr_mask) == hook->cpsr_val)
300 fn = hook->fn;
301 spin_unlock_irqrestore(&undef_lock, flags);
302
303 return fn ? fn(regs, instr) : 1;
304}
305
Russell King7ab3f8d2007-03-02 15:01:36 +0000306asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
308 unsigned int correction = thumb_mode(regs) ? 2 : 4;
309 unsigned int instr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 siginfo_t info;
311 void __user *pc;
312
313 /*
314 * According to the ARM ARM, PC is 2 or 4 bytes ahead,
315 * depending whether we're in Thumb mode or not.
316 * Correct this offset.
317 */
318 regs->ARM_pc -= correction;
319
320 pc = (void __user *)instruction_pointer(regs);
Dan Williamsdfc544c2007-02-13 17:11:34 +0100321
322 if (processor_mode(regs) == SVC_MODE) {
323 instr = *(u32 *) pc;
324 } else if (thumb_mode(regs)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 get_user(instr, (u16 __user *)pc);
326 } else {
327 get_user(instr, (u32 __user *)pc);
328 }
329
Russell Kingb03a5b72008-08-11 12:27:16 +0100330 if (call_undef_hook(regs, instr) == 0)
331 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333#ifdef CONFIG_DEBUG_USER
334 if (user_debug & UDBG_UNDEFINED) {
335 printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700336 current->comm, task_pid_nr(current), pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 dump_instr(regs);
338 }
339#endif
340
341 info.si_signo = SIGILL;
342 info.si_errno = 0;
343 info.si_code = ILL_ILLOPC;
344 info.si_addr = pc;
345
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -0700346 arm_notify_die("Oops - undefined instruction", regs, &info, 0, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
349asmlinkage void do_unexp_fiq (struct pt_regs *regs)
350{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 printk("Hmm. Unexpected FIQ received, but trying to continue\n");
352 printk("You may have a hardware problem...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355/*
356 * bad_mode handles the impossible case in the vectors. If you see one of
357 * these, then it's extremely serious, and could mean you have buggy hardware.
358 * It never returns, and never tries to sync. We hope that we can at least
359 * dump out some state information...
360 */
Russell Kingae0a8462007-01-09 12:57:37 +0000361asmlinkage void bad_mode(struct pt_regs *regs, int reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
363 console_verbose();
364
Russell Kingae0a8462007-01-09 12:57:37 +0000365 printk(KERN_CRIT "Bad mode in %s handler detected\n", handler[reason]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 die("Oops - bad mode", regs, 0);
368 local_irq_disable();
369 panic("bad mode");
370}
371
372static int bad_syscall(int n, struct pt_regs *regs)
373{
374 struct thread_info *thread = current_thread_info();
375 siginfo_t info;
376
Nicolas Pitrea999cb042005-10-28 16:35:46 +0100377 if (current->personality != PER_LINUX &&
378 current->personality != PER_LINUX_32BIT &&
379 thread->exec_domain->handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 thread->exec_domain->handler(n, regs);
381 return regs->ARM_r0;
382 }
383
384#ifdef CONFIG_DEBUG_USER
385 if (user_debug & UDBG_SYSCALL) {
386 printk(KERN_ERR "[%d] %s: obsolete system call %08x.\n",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700387 task_pid_nr(current), current->comm, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 dump_instr(regs);
389 }
390#endif
391
392 info.si_signo = SIGILL;
393 info.si_errno = 0;
394 info.si_code = ILL_ILLTRP;
395 info.si_addr = (void __user *)instruction_pointer(regs) -
396 (thumb_mode(regs) ? 2 : 4);
397
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -0700398 arm_notify_die("Oops - bad syscall", regs, &info, n, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 return regs->ARM_r0;
401}
402
403static inline void
404do_cache_op(unsigned long start, unsigned long end, int flags)
405{
406 struct vm_area_struct *vma;
407
408 if (end < start || flags)
409 return;
410
411 vma = find_vma(current->active_mm, start);
412 if (vma && vma->vm_start < end) {
413 if (start < vma->vm_start)
414 start = vma->vm_start;
415 if (end > vma->vm_end)
416 end = vma->vm_end;
417
418 flush_cache_user_range(vma, start, end);
419 }
420}
421
422/*
423 * Handle all unrecognised system calls.
424 * 0x9f0000 - 0x9fffff are some more esoteric system calls
425 */
426#define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)
427asmlinkage int arm_syscall(int no, struct pt_regs *regs)
428{
429 struct thread_info *thread = current_thread_info();
430 siginfo_t info;
431
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000432 if ((no >> 16) != (__ARM_NR_BASE>> 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return bad_syscall(no, regs);
434
435 switch (no & 0xffff) {
436 case 0: /* branch through 0 */
437 info.si_signo = SIGSEGV;
438 info.si_errno = 0;
439 info.si_code = SEGV_MAPERR;
440 info.si_addr = NULL;
441
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -0700442 arm_notify_die("branch through zero", regs, &info, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return 0;
444
445 case NR(breakpoint): /* SWI BREAK_POINT */
446 regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
447 ptrace_break(current, regs);
448 return regs->ARM_r0;
449
450 /*
451 * Flush a region from virtual address 'r0' to virtual address 'r1'
452 * _exclusive_. There is no alignment requirement on either address;
453 * user space does not need to know the hardware cache layout.
454 *
455 * r2 contains flags. It should ALWAYS be passed as ZERO until it
456 * is defined to be something else. For now we ignore it, but may
457 * the fires of hell burn in your belly if you break this rule. ;)
458 *
459 * (at a later date, we may want to allow this call to not flush
460 * various aspects of the cache. Passing '0' will guarantee that
461 * everything necessary gets flushed to maintain consistency in
462 * the specified region).
463 */
464 case NR(cacheflush):
465 do_cache_op(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2);
466 return 0;
467
468 case NR(usr26):
469 if (!(elf_hwcap & HWCAP_26BIT))
470 break;
471 regs->ARM_cpsr &= ~MODE32_BIT;
472 return regs->ARM_r0;
473
474 case NR(usr32):
475 if (!(elf_hwcap & HWCAP_26BIT))
476 break;
477 regs->ARM_cpsr |= MODE32_BIT;
478 return regs->ARM_r0;
479
480 case NR(set_tls):
481 thread->tp_value = regs->ARM_r0;
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100482#if defined(CONFIG_HAS_TLS_REG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100483 asm ("mcr p15, 0, %0, c13, c0, 3" : : "r" (regs->ARM_r0) );
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100484#elif !defined(CONFIG_TLS_REG_EMUL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /*
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100486 * User space must never try to access this directly.
487 * Expect your app to break eventually if you do so.
488 * The user helper at 0xffff0fe0 must be used instead.
489 * (see entry-armv.S for details)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 */
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100491 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
492#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 return 0;
494
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100495#ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG
496 /*
497 * Atomically store r1 in *r2 if *r2 is equal to r0 for user space.
498 * Return zero in r0 if *MEM was changed or non-zero if no exchange
499 * happened. Also set the user C flag accordingly.
500 * If access permissions have to be fixed up then non-zero is
501 * returned and the operation has to be re-attempted.
502 *
503 * *NOTE*: This is a ghost syscall private to the kernel. Only the
504 * __kuser_cmpxchg code in entry-armv.S should be aware of its
505 * existence. Don't ever use this from user code.
506 */
507 case 0xfff0:
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100508 for (;;) {
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100509 extern void do_DataAbort(unsigned long addr, unsigned int fsr,
510 struct pt_regs *regs);
511 unsigned long val;
512 unsigned long addr = regs->ARM_r2;
513 struct mm_struct *mm = current->mm;
514 pgd_t *pgd; pmd_t *pmd; pte_t *pte;
Hugh Dickins69b04752005-10-29 18:16:36 -0700515 spinlock_t *ptl;
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100516
517 regs->ARM_cpsr &= ~PSR_C_BIT;
Hugh Dickins69b04752005-10-29 18:16:36 -0700518 down_read(&mm->mmap_sem);
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100519 pgd = pgd_offset(mm, addr);
520 if (!pgd_present(*pgd))
521 goto bad_access;
522 pmd = pmd_offset(pgd, addr);
523 if (!pmd_present(*pmd))
524 goto bad_access;
Hugh Dickins69b04752005-10-29 18:16:36 -0700525 pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
Nicolas Pitre2ce98042006-03-25 22:44:05 +0000526 if (!pte_present(*pte) || !pte_dirty(*pte)) {
Hugh Dickins69b04752005-10-29 18:16:36 -0700527 pte_unmap_unlock(pte, ptl);
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100528 goto bad_access;
Hugh Dickins69b04752005-10-29 18:16:36 -0700529 }
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100530 val = *(unsigned long *)addr;
531 val -= regs->ARM_r0;
532 if (val == 0) {
533 *(unsigned long *)addr = regs->ARM_r1;
534 regs->ARM_cpsr |= PSR_C_BIT;
535 }
Hugh Dickins69b04752005-10-29 18:16:36 -0700536 pte_unmap_unlock(pte, ptl);
537 up_read(&mm->mmap_sem);
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100538 return val;
539
540 bad_access:
Hugh Dickins69b04752005-10-29 18:16:36 -0700541 up_read(&mm->mmap_sem);
Nicolas Pitre74f88492005-10-04 23:17:52 +0100542 /* simulate a write access fault */
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100543 do_DataAbort(addr, 15 + (1 << 11), regs);
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100544 }
545#endif
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 default:
548 /* Calls 9f00xx..9f07ff are defined to return -ENOSYS
549 if not implemented, rather than raising SIGILL. This
550 way the calling program can gracefully determine whether
551 a feature is supported. */
552 if (no <= 0x7ff)
553 return -ENOSYS;
554 break;
555 }
556#ifdef CONFIG_DEBUG_USER
557 /*
558 * experience shows that these seem to indicate that
559 * something catastrophic has happened
560 */
561 if (user_debug & UDBG_SYSCALL) {
562 printk("[%d] %s: arm syscall %d\n",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700563 task_pid_nr(current), current->comm, no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 dump_instr(regs);
565 if (user_mode(regs)) {
Russell King652a12e2005-04-17 15:50:36 +0100566 __show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 c_backtrace(regs->ARM_fp, processor_mode(regs));
568 }
569 }
570#endif
571 info.si_signo = SIGILL;
572 info.si_errno = 0;
573 info.si_code = ILL_ILLTRP;
574 info.si_addr = (void __user *)instruction_pointer(regs) -
575 (thumb_mode(regs) ? 2 : 4);
576
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -0700577 arm_notify_die("Oops - bad syscall(2)", regs, &info, no, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 return 0;
579}
580
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100581#ifdef CONFIG_TLS_REG_EMUL
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100582
583/*
584 * We might be running on an ARMv6+ processor which should have the TLS
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100585 * register but for some reason we can't use it, or maybe an SMP system
586 * using a pre-ARMv6 processor (there are apparently a few prototypes like
587 * that in existence) and therefore access to that register must be
588 * emulated.
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100589 */
590
591static int get_tp_trap(struct pt_regs *regs, unsigned int instr)
592{
593 int reg = (instr >> 12) & 15;
594 if (reg == 15)
595 return 1;
596 regs->uregs[reg] = current_thread_info()->tp_value;
597 regs->ARM_pc += 4;
598 return 0;
599}
600
601static struct undef_hook arm_mrc_hook = {
602 .instr_mask = 0x0fff0fff,
603 .instr_val = 0x0e1d0f70,
604 .cpsr_mask = PSR_T_BIT,
605 .cpsr_val = 0,
606 .fn = get_tp_trap,
607};
608
609static int __init arm_mrc_hook_init(void)
610{
611 register_undef_hook(&arm_mrc_hook);
612 return 0;
613}
614
615late_initcall(arm_mrc_hook_init);
616
617#endif
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619void __bad_xchg(volatile void *ptr, int size)
620{
621 printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",
622 __builtin_return_address(0), ptr, size);
623 BUG();
624}
625EXPORT_SYMBOL(__bad_xchg);
626
627/*
628 * A data abort trap was taken, but we did not handle the instruction.
629 * Try to abort the user program, or panic if it was the kernel.
630 */
631asmlinkage void
632baddataabort(int code, unsigned long instr, struct pt_regs *regs)
633{
634 unsigned long addr = instruction_pointer(regs);
635 siginfo_t info;
636
637#ifdef CONFIG_DEBUG_USER
638 if (user_debug & UDBG_BADABORT) {
639 printk(KERN_ERR "[%d] %s: bad data abort: code %d instr 0x%08lx\n",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700640 task_pid_nr(current), current->comm, code, instr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 dump_instr(regs);
642 show_pte(current->mm, addr);
643 }
644#endif
645
646 info.si_signo = SIGILL;
647 info.si_errno = 0;
648 info.si_code = ILL_ILLOPC;
649 info.si_addr = (void __user *)addr;
650
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -0700651 arm_notify_die("unknown data abort code", regs, &info, instr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
Nicolas Pitre7174d852006-12-07 19:09:20 +0100654void __attribute__((noreturn)) __bug(const char *file, int line)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Nicolas Pitre7174d852006-12-07 19:09:20 +0100656 printk(KERN_CRIT"kernel BUG at %s:%d!\n", file, line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 *(int *)0 = 0;
Catalin Marinas6a1ced52005-09-21 22:14:05 +0100658
659 /* Avoid "noreturn function does return" */
660 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662EXPORT_SYMBOL(__bug);
663
664void __readwrite_bug(const char *fn)
665{
666 printk("%s called, but not implemented\n", fn);
667 BUG();
668}
669EXPORT_SYMBOL(__readwrite_bug);
670
671void __pte_error(const char *file, int line, unsigned long val)
672{
673 printk("%s:%d: bad pte %08lx.\n", file, line, val);
674}
675
676void __pmd_error(const char *file, int line, unsigned long val)
677{
678 printk("%s:%d: bad pmd %08lx.\n", file, line, val);
679}
680
681void __pgd_error(const char *file, int line, unsigned long val)
682{
683 printk("%s:%d: bad pgd %08lx.\n", file, line, val);
684}
685
686asmlinkage void __div0(void)
687{
688 printk("Division by zero in kernel.\n");
689 dump_stack();
690}
691EXPORT_SYMBOL(__div0);
692
693void abort(void)
694{
695 BUG();
696
697 /* if that doesn't kill us, halt */
698 panic("Oops failed to kill thread");
699}
700EXPORT_SYMBOL(abort);
701
702void __init trap_init(void)
703{
Jason Wessel5cbad0e2008-02-20 13:33:40 -0600704 return;
705}
706
707void __init early_trap_init(void)
708{
Hyok S. Choic760fc12006-03-27 15:18:50 +0100709 unsigned long vectors = CONFIG_VECTORS_BASE;
Russell King79335232005-04-26 15:17:42 +0100710 extern char __stubs_start[], __stubs_end[];
711 extern char __vectors_start[], __vectors_end[];
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100712 extern char __kuser_helper_start[], __kuser_helper_end[];
713 int kuser_sz = __kuser_helper_end - __kuser_helper_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Russell King79335232005-04-26 15:17:42 +0100715 /*
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100716 * Copy the vectors, stubs and kuser helpers (in entry-armv.S)
717 * into the vector page, mapped at 0xffff0000, and ensure these
718 * are visible to the instruction stream.
Russell King79335232005-04-26 15:17:42 +0100719 */
Hyok S. Choic760fc12006-03-27 15:18:50 +0100720 memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
721 memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);
722 memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
Russell Kinge00d3492005-06-22 20:26:05 +0100723
724 /*
725 * Copy signal return handlers into the vector page, and
726 * set sigreturn to be a pointer to these.
727 */
728 memcpy((void *)KERN_SIGRETURN_CODE, sigreturn_codes,
729 sizeof(sigreturn_codes));
730
Hyok S. Choic760fc12006-03-27 15:18:50 +0100731 flush_icache_range(vectors, vectors + PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
733}