15 #include <linux/signal.h>
16 #include <linux/personality.h>
22 #include <linux/module.h>
23 #include <linux/kexec.h>
27 #include <linux/sched.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>
36 #include <asm/system_misc.h>
40 static const char *handler[]= {
"prefetch abort",
"data abort",
"address exception",
"interrupt" };
44 #ifdef CONFIG_DEBUG_USER
47 static int __init user_debug_setup(
char *
str)
52 __setup(
"user_debug=", user_debug_setup);
55 static void dump_mem(
const char *,
const char *,
unsigned long,
unsigned long);
59 #ifdef CONFIG_KALLSYMS
60 printk(
"[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (
void *)where, from, (
void *)from);
62 printk(
"Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
65 if (in_exception_text(where))
66 dump_mem(
"",
"Exception stack", frame + 4, frame + 4 +
sizeof(
struct pt_regs));
69 #ifndef CONFIG_ARM_UNWIND
75 static int verify_stack(
unsigned long sp)
78 (sp > (
unsigned long)high_memory && high_memory !=
NULL))
88 static void dump_mem(
const char *lvl,
const char *
str,
unsigned long bottom,
103 printk(
"%s%s(0x%08lx to 0x%08lx)\n", lvl, str, bottom, top);
105 for (first = bottom & ~31; first <
top; first += 32) {
107 char str[
sizeof(
" 12345678") * 8 + 1];
109 memset(str,
' ',
sizeof(str));
110 str[
sizeof(
str) - 1] =
'\0';
112 for (p = first, i = 0; i < 8 && p <
top; i++, p += 4) {
113 if (p >= bottom && p < top) {
116 sprintf(str + i * 9,
" %08lx", val);
118 sprintf(str + i * 9,
" ????????");
121 printk(
"%s%04lx:%s\n", lvl, first & 0xffff, str);
127 static void dump_instr(
const char *lvl,
struct pt_regs *
regs)
131 const int width = thumb ? 4 : 8;
133 char str[
sizeof(
"00000000 ") * 5 + 2 + 1], *p = str;
144 for (i = -4; i < 1 + !!thumb; i++) {
153 p +=
sprintf(p, i == 0 ?
"(%0*x) " :
"%0*x ",
156 p +=
sprintf(p,
"bad PC value");
160 printk(
"%sCode: %s\n", lvl, str);
165 #ifdef CONFIG_ARM_UNWIND
185 fp = thread_saved_fp(tsk);
188 asm(
"mov %0, fp" :
"=r" (
fp) : :
"cc");
193 printk(
"no frame pointer");
195 }
else if (verify_stack(fp)) {
196 printk(
"invalid frame pointer 0x%08x", fp);
199 printk(
"frame pointer underflow");
216 dump_backtrace(
NULL, tsk);
220 #ifdef CONFIG_PREEMPT
221 #define S_PREEMPT " PREEMPT"
230 #ifdef CONFIG_THUMB2_KERNEL
231 #define S_ISA " THUMB2"
236 static int __die(
const char *str,
int err,
struct pt_regs *regs)
239 static int die_counter;
243 S_ISA "\n", str, err, ++die_counter);
247 if (ret == NOTIFY_STOP)
258 dump_backtrace(regs, tsk);
266 static int die_owner = -1;
267 static unsigned int die_nest_count;
269 static unsigned long oops_begin(
void)
280 if (cpu == die_owner)
292 static void oops_end(
unsigned long flags,
struct pt_regs *regs,
int signr)
308 panic(
"Fatal exception in interrupt");
310 panic(
"Fatal exception");
321 unsigned long flags = oops_begin();
329 if (__die(str, err, regs))
332 oops_end(flags, regs, sig);
348 #ifdef CONFIG_GENERIC_BUG
352 #ifdef CONFIG_THUMB2_KERNEL
361 return bkpt == BUG_INSTR_VALUE;
387 static int call_undef_hook(
struct pt_regs *regs,
unsigned int instr)
395 if ((instr & hook->instr_mask) == hook->instr_val &&
396 (regs->
ARM_cpsr & hook->cpsr_mask) == hook->cpsr_val)
400 return fn ? fn(regs, instr) : 1;
412 #ifdef CONFIG_THUMB2_KERNEL
414 instr = ((
u16 *)pc)[0];
417 instr |= ((
u16 *)pc)[1];
436 if (call_undef_hook(regs, instr) == 0)
440 #ifdef CONFIG_DEBUG_USER
453 arm_notify_die(
"Oops - undefined instruction", regs, &info, 0, 6);
458 printk(
"Hmm. Unexpected FIQ received, but trying to continue\n");
459 printk(
"You may have a hardware problem...\n");
472 printk(
KERN_CRIT "Bad mode in %s handler detected\n", handler[reason]);
474 die(
"Oops - bad mode", regs, 0);
479 static int bad_syscall(
int n,
struct pt_regs *regs)
490 #ifdef CONFIG_DEBUG_USER
510 do_cache_op(
unsigned long start,
unsigned long end,
int flags)
515 if (end < start || flags)
537 #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)
544 return bad_syscall(no, regs);
546 switch (no & 0xffff) {
576 return do_cache_op(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2);
595 asm (
"mcr p15, 0, %0, c13, c0, 3"
596 : :
"r" (regs->ARM_r0));
604 *((
unsigned int *)0xffff0ff0) = regs->ARM_r0;
608 #ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG
622 extern void do_DataAbort(
unsigned long addr,
unsigned int fsr,
625 unsigned long addr = regs->ARM_r2;
638 pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
640 pte_unmap_unlock(pte, ptl);
643 val = *(
unsigned long *)addr;
646 *(
unsigned long *)addr = regs->ARM_r1;
649 pte_unmap_unlock(pte, ptl);
665 if ((no & 0xffff) <= 0x7ff)
669 #ifdef CONFIG_DEBUG_USER
675 printk(
"[%d] %s: arm syscall %d\n",
677 dump_instr(
"", regs);
694 #ifdef CONFIG_TLS_REG_EMUL
704 static int get_tp_trap(
struct pt_regs *regs,
unsigned int instr)
706 int reg = (instr >> 12) & 15;
716 .instr_val = 0x0e1d0f70,
722 static int __init arm_mrc_hook_init(
void)
734 printk(
"xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",
735 __builtin_return_address(0), ptr, size);
750 #ifdef CONFIG_DEBUG_USER
752 printk(
KERN_ERR "[%d] %s: bad data abort: code %d instr 0x%08lx\n",
762 info.si_addr = (
void __user *)addr;
769 printk(
"%s called, but not implemented\n", fn);
776 printk(
"%s:%d: bad pte %08llx.\n", file, line, (
long long)
pte_val(pte));
781 printk(
"%s:%d: bad pmd %08llx.\n", file, line, (
long long)
pmd_val(pmd));
786 printk(
"%s:%d: bad pgd %08llx.\n", file, line, (
long long)
pgd_val(pgd));
791 printk(
"Division by zero in kernel.\n");
801 panic(
"Oops failed to kill thread");
817 memcpy((
void *)vectors + 0xfe0, (
void *)vectors + 0xfe8, 4);
822 unsigned long vectors = (
unsigned long)vectors_base;
825 extern char __kuser_helper_start[], __kuser_helper_end[];
826 int kuser_sz = __kuser_helper_end - __kuser_helper_start;
835 memcpy((
void *)vectors, __vectors_start, __vectors_end - __vectors_start);
836 memcpy((
void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);
837 memcpy((
void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
842 kuser_get_tls_init(vectors);