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