2 * linux/arch/arm26/kernel/traps.c
4 * Copyright (C) 1995-2002 Russell King
5 * Fragments that appear the same as linux/arch/i386/kernel/traps.c (C) Linus Torvalds
6 * Copyright (C) 2003 Ian Molton (ARM26)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * 'traps.c' handles hardware exceptions after we have saved some state in
13 * 'linux/arch/arm26/lib/traps.S'. Mostly a debugging aid, but will probably
14 * kill the offending process.
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
20 #include <linux/signal.h>
21 #include <linux/sched.h>
23 #include <linux/spinlock.h>
24 #include <linux/personality.h>
25 #include <linux/ptrace.h>
26 #include <linux/elf.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
30 #include <asm/atomic.h>
32 #include <asm/pgtable.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
35 #include <asm/unistd.h>
36 #include <linux/mutex.h>
40 extern void c_backtrace (unsigned long fp
, int pmode
);
41 extern void show_pte(struct mm_struct
*mm
, unsigned long addr
);
43 const char *processor_modes
[] = { "USER_26", "FIQ_26" , "IRQ_26" , "SVC_26" };
45 static const char *handler
[]= { "prefetch abort", "data abort", "address exception", "interrupt" "*bad reason*"};
48 * Stack pointers should always be within the kernels view of
49 * physical memory. If it is not there, then we can't dump
50 * out any information relating to the stack.
52 static int verify_stack(unsigned long sp
)
54 if (sp
< PAGE_OFFSET
|| (sp
> (unsigned long)high_memory
&& high_memory
!= 0))
61 * Dump out the contents of some memory nicely...
63 static void dump_mem(const char *str
, unsigned long bottom
, unsigned long top
)
65 unsigned long p
= bottom
& ~31;
70 * We need to switch to kernel mode so that we can use __get_user
71 * to safely read from kernel space. Note that we now dump the
72 * code first, just in case the backtrace kills us.
78 printk("(0x%08lx to 0x%08lx)\n", bottom
, top
);
80 for (p
= bottom
& ~31; p
< top
;) {
81 printk("%04lx: ", p
& 0xffff);
83 for (i
= 0; i
< 8; i
++, p
+= 4) {
86 if (p
< bottom
|| p
>= top
)
89 __get_user(val
, (unsigned long *)p
);
99 static void dump_instr(struct pt_regs
*regs
)
101 unsigned long addr
= instruction_pointer(regs
);
107 * We need to switch to kernel mode so that we can use __get_user
108 * to safely read from kernel space. Note that we now dump the
109 * code first, just in case the backtrace kills us.
115 for (i
= -4; i
< 1; i
++) {
116 unsigned int val
, bad
;
118 bad
= __get_user(val
, &((u32
*)addr
)[i
]);
121 printk(i
== 0 ? "(%0*x) " : "%0*x ", width
, val
);
123 printk("bad PC value.");
132 /*static*/ void __dump_stack(struct task_struct
*tsk
, unsigned long sp
)
134 dump_mem("Stack: ", sp
, 8192+(unsigned long)task_stack_page(tsk
));
137 void dump_stack(void)
139 #ifdef CONFIG_DEBUG_ERRORS
144 EXPORT_SYMBOL(dump_stack
);
146 //FIXME - was a static fn
147 void dump_backtrace(struct pt_regs
*regs
, struct task_struct
*tsk
)
152 printk("Backtrace: ");
155 printk("no frame pointer");
157 } else if (verify_stack(fp
)) {
158 printk("invalid frame pointer 0x%08x", fp
);
160 } else if (fp
< (unsigned long)end_of_stack(tsk
))
161 printk("frame pointer underflow");
165 c_backtrace(fp
, processor_mode(regs
));
168 /* FIXME - this is probably wrong.. */
169 void show_stack(struct task_struct
*task
, unsigned long *sp
) {
170 dump_mem("Stack: ", (unsigned long)sp
, 8192+(unsigned long)task_stack_page(task
));
173 DEFINE_SPINLOCK(die_lock
);
176 * This function is protected against re-entrancy.
178 NORET_TYPE
void die(const char *str
, struct pt_regs
*regs
, int err
)
180 struct task_struct
*tsk
= current
;
183 spin_lock_irq(&die_lock
);
185 printk("Internal error: %s: %x\n", str
, err
);
186 printk("CPU: %d\n", smp_processor_id());
188 printk("Process %s (pid: %d, stack limit = 0x%p)\n",
189 current
->comm
, current
->pid
, end_of_stack(tsk
));
191 if (!user_mode(regs
) || in_interrupt()) {
192 __dump_stack(tsk
, (unsigned long)(regs
+ 1));
193 dump_backtrace(regs
, tsk
);
197 spin_unlock_irq(&die_lock
);
201 void die_if_kernel(const char *str
, struct pt_regs
*regs
, int err
)
209 static DEFINE_MUTEX(undef_mutex
);
210 static int (*undef_hook
)(struct pt_regs
*);
212 int request_undef_hook(int (*fn
)(struct pt_regs
*))
216 mutex_lock(&undef_mutex
);
217 if (undef_hook
== NULL
) {
221 mutex_unlock(&undef_mutex
);
226 int release_undef_hook(int (*fn
)(struct pt_regs
*))
230 mutex_lock(&undef_mutex
);
231 if (undef_hook
== fn
) {
235 mutex_unlock(&undef_mutex
);
240 static int undefined_extension(struct pt_regs
*regs
, unsigned int op
)
243 case 1: /* 0xde01 / 0x?7f001f0 */
244 ptrace_break(current
, regs
);
250 asmlinkage
void do_undefinstr(struct pt_regs
*regs
)
257 pc
= (unsigned long *)instruction_pointer(regs
); /* strip PSR */
259 if (user_mode(regs
)) {
262 get_user(instr
, (u32
*)pc
);
264 if ((instr
& 0x0fff00ff) == 0x07f000f0 &&
265 undefined_extension(regs
, (instr
>> 8) & 255) == 0) {
270 if (undef_hook
&& undef_hook(regs
) == 0) {
276 #ifdef CONFIG_DEBUG_USER
277 printk(KERN_INFO
"%s (%d): undefined instruction: pc=%p\n",
278 current
->comm
, current
->pid
, pc
);
282 current
->thread
.error_code
= 0;
283 current
->thread
.trap_no
= 6;
285 info
.si_signo
= SIGILL
;
287 info
.si_code
= ILL_ILLOPC
;
290 force_sig_info(SIGILL
, &info
, current
);
292 die_if_kernel("Oops - undefined instruction", regs
, 0);
295 asmlinkage
void do_excpt(unsigned long address
, struct pt_regs
*regs
, int mode
)
299 #ifdef CONFIG_DEBUG_USER
300 printk(KERN_INFO
"%s (%d): address exception: pc=%08lx\n",
301 current
->comm
, current
->pid
, instruction_pointer(regs
));
305 current
->thread
.error_code
= 0;
306 current
->thread
.trap_no
= 11;
308 info
.si_signo
= SIGBUS
;
310 info
.si_code
= BUS_ADRERR
;
311 info
.si_addr
= (void *)address
;
313 force_sig_info(SIGBUS
, &info
, current
);
315 die_if_kernel("Oops - address exception", regs
, mode
);
318 asmlinkage
void do_unexp_fiq (struct pt_regs
*regs
)
320 #ifndef CONFIG_IGNORE_FIQ
321 printk("Hmm. Unexpected FIQ received, but trying to continue\n");
322 printk("You may have a hardware problem...\n");
327 * bad_mode handles the impossible case in the vectors. If you see one of
328 * these, then it's extremely serious, and could mean you have buggy hardware.
329 * It never returns, and never tries to sync. We hope that we can at least
330 * dump out some state information...
332 asmlinkage
void bad_mode(struct pt_regs
*regs
, int reason
, int proc_mode
)
334 unsigned int vectors
= vectors_base();
338 printk(KERN_CRIT
"Bad mode in %s handler detected: mode %s\n",
339 handler
[reason
<5?reason
:4], processor_modes
[proc_mode
]);
342 * Dump out the vectors and stub routines. Maybe a better solution
343 * would be to dump them out only if we detect that they are corrupted.
345 dump_mem(KERN_CRIT
"Vectors: ", vectors
, vectors
+ 0x40);
346 dump_mem(KERN_CRIT
"Stubs: ", vectors
+ 0x200, vectors
+ 0x4b8);
348 die("Oops", regs
, 0);
353 static int bad_syscall(int n
, struct pt_regs
*regs
)
355 struct thread_info
*thread
= current_thread_info();
358 if (current
->personality
!= PER_LINUX
&& thread
->exec_domain
->handler
) {
359 thread
->exec_domain
->handler(n
, regs
);
363 #ifdef CONFIG_DEBUG_USER
364 printk(KERN_ERR
"[%d] %s: obsolete system call %08x.\n",
365 current
->pid
, current
->comm
, n
);
369 info
.si_signo
= SIGILL
;
371 info
.si_code
= ILL_ILLTRP
;
372 info
.si_addr
= (void *)instruction_pointer(regs
) - 4;
374 force_sig_info(SIGILL
, &info
, current
);
375 die_if_kernel("Oops", regs
, n
);
380 do_cache_op(unsigned long start
, unsigned long end
, int flags
)
382 struct vm_area_struct
*vma
;
387 vma
= find_vma(current
->active_mm
, start
);
388 if (vma
&& vma
->vm_start
< end
) {
389 if (start
< vma
->vm_start
)
390 start
= vma
->vm_start
;
391 if (end
> vma
->vm_end
)
397 * Handle all unrecognised system calls.
398 * 0x9f0000 - 0x9fffff are some more esoteric system calls
400 #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)
401 asmlinkage
int arm_syscall(int no
, struct pt_regs
*regs
)
405 if ((no
>> 16) != 0x9f)
406 return bad_syscall(no
, regs
);
408 switch (no
& 0xffff) {
409 case 0: /* branch through 0 */
410 info
.si_signo
= SIGSEGV
;
412 info
.si_code
= SEGV_MAPERR
;
415 force_sig_info(SIGSEGV
, &info
, current
);
417 die_if_kernel("branch through zero", regs
, 0);
420 case NR(breakpoint
): /* SWI BREAK_POINT */
421 ptrace_break(current
, regs
);
431 /* Calls 9f00xx..9f07ff are defined to return -ENOSYS
432 if not implemented, rather than raising SIGILL. This
433 way the calling program can gracefully determine whether
434 a feature is supported. */
439 #ifdef CONFIG_DEBUG_USER
441 * experience shows that these seem to indicate that
442 * something catastrophic has happened
444 printk("[%d] %s: arm syscall %d\n", current
->pid
, current
->comm
, no
);
446 if (user_mode(regs
)) {
448 c_backtrace(regs
->ARM_fp
, processor_mode(regs
));
451 info
.si_signo
= SIGILL
;
453 info
.si_code
= ILL_ILLTRP
;
454 info
.si_addr
= (void *)instruction_pointer(regs
) - 4;
456 force_sig_info(SIGILL
, &info
, current
);
457 die_if_kernel("Oops", regs
, no
);
461 void __bad_xchg(volatile void *ptr
, int size
)
463 printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",
464 __builtin_return_address(0), ptr
, size
);
469 * A data abort trap was taken, but we did not handle the instruction.
470 * Try to abort the user program, or panic if it was the kernel.
473 baddataabort(int code
, unsigned long instr
, struct pt_regs
*regs
)
475 unsigned long addr
= instruction_pointer(regs
);
478 #ifdef CONFIG_DEBUG_USER
479 printk(KERN_ERR
"[%d] %s: bad data abort: code %d instr 0x%08lx\n",
480 current
->pid
, current
->comm
, code
, instr
);
482 show_pte(current
->mm
, addr
);
485 info
.si_signo
= SIGILL
;
487 info
.si_code
= ILL_ILLOPC
;
488 info
.si_addr
= (void *)addr
;
490 force_sig_info(SIGILL
, &info
, current
);
491 die_if_kernel("unknown data abort code", regs
, instr
);
494 volatile void __bug(const char *file
, int line
, void *data
)
496 printk(KERN_CRIT
"kernel BUG at %s:%d!", file
, line
);
498 printk(KERN_CRIT
" - extra data = %p", data
);
503 void __readwrite_bug(const char *fn
)
505 printk("%s called, but not implemented", fn
);
509 void __pte_error(const char *file
, int line
, unsigned long val
)
511 printk("%s:%d: bad pte %08lx.\n", file
, line
, val
);
514 void __pmd_error(const char *file
, int line
, unsigned long val
)
516 printk("%s:%d: bad pmd %08lx.\n", file
, line
, val
);
519 void __pgd_error(const char *file
, int line
, unsigned long val
)
521 printk("%s:%d: bad pgd %08lx.\n", file
, line
, val
);
524 asmlinkage
void __div0(void)
526 printk("Division by zero in kernel.\n");
534 /* if that doesn't kill us, halt */
535 panic("Oops failed to kill thread");
538 void __init
trap_init(void)
540 extern void __trap_init(unsigned long);
541 unsigned long base
= vectors_base();
545 printk(KERN_DEBUG
"Relocating machine vectors to 0x%08lx\n",