btrfs: fix lockdep splat in btrfs_alloc_subvolume_writers
[linux/fpc-iii.git] / arch / nios2 / kernel / traps.c
blob8184e7d6b3857d3a9588b556e89f76b5a6d42c6a
1 /*
2 * Hardware exception handling
4 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
5 * Copyright (C) 2004 Microtronix Datacom Ltd.
6 * Copyright (C) 2001 Vic Phillips
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of this
10 * archive for more details.
13 #include <linux/sched.h>
14 #include <linux/sched/debug.h>
15 #include <linux/kernel.h>
16 #include <linux/signal.h>
17 #include <linux/export.h>
18 #include <linux/mm.h>
19 #include <linux/ptrace.h>
21 #include <asm/traps.h>
22 #include <asm/sections.h>
23 #include <linux/uaccess.h>
25 static DEFINE_SPINLOCK(die_lock);
27 static void _send_sig(int signo, int code, unsigned long addr)
29 siginfo_t info;
31 info.si_signo = signo;
32 info.si_errno = 0;
33 info.si_code = code;
34 info.si_addr = (void __user *) addr;
35 force_sig_info(signo, &info, current);
38 void die(const char *str, struct pt_regs *regs, long err)
40 console_verbose();
41 spin_lock_irq(&die_lock);
42 pr_warn("Oops: %s, sig: %ld\n", str, err);
43 show_regs(regs);
44 spin_unlock_irq(&die_lock);
46 * do_exit() should take care of panic'ing from an interrupt
47 * context so we don't handle it here
49 do_exit(err);
52 void _exception(int signo, struct pt_regs *regs, int code, unsigned long addr)
54 if (!user_mode(regs))
55 die("Exception in kernel mode", regs, signo);
57 _send_sig(signo, code, addr);
61 * The show_stack is an external API which we do not use ourselves.
64 int kstack_depth_to_print = 48;
66 void show_stack(struct task_struct *task, unsigned long *stack)
68 unsigned long *endstack, addr;
69 int i;
71 if (!stack) {
72 if (task)
73 stack = (unsigned long *)task->thread.ksp;
74 else
75 stack = (unsigned long *)&stack;
78 addr = (unsigned long) stack;
79 endstack = (unsigned long *) PAGE_ALIGN(addr);
81 pr_emerg("Stack from %08lx:", (unsigned long)stack);
82 for (i = 0; i < kstack_depth_to_print; i++) {
83 if (stack + 1 > endstack)
84 break;
85 if (i % 8 == 0)
86 pr_emerg("\n ");
87 pr_emerg(" %08lx", *stack++);
90 pr_emerg("\nCall Trace:");
91 i = 0;
92 while (stack + 1 <= endstack) {
93 addr = *stack++;
95 * If the address is either in the text segment of the
96 * kernel, or in the region which contains vmalloc'ed
97 * memory, it *may* be the address of a calling
98 * routine; if so, print it so that someone tracing
99 * down the cause of the crash will be able to figure
100 * out the call path that was taken.
102 if (((addr >= (unsigned long) _stext) &&
103 (addr <= (unsigned long) _etext))) {
104 if (i % 4 == 0)
105 pr_emerg("\n ");
106 pr_emerg(" [<%08lx>]", addr);
107 i++;
110 pr_emerg("\n");
113 void __init trap_init(void)
115 /* Nothing to do here */
118 /* Breakpoint handler */
119 asmlinkage void breakpoint_c(struct pt_regs *fp)
122 * The breakpoint entry code has moved the PC on by 4 bytes, so we must
123 * move it back. This could be done on the host but we do it here
124 * because monitor.S of JTAG gdbserver does it too.
126 fp->ea -= 4;
127 _exception(SIGTRAP, fp, TRAP_BRKPT, fp->ea);
130 #ifndef CONFIG_NIOS2_ALIGNMENT_TRAP
131 /* Alignment exception handler */
132 asmlinkage void handle_unaligned_c(struct pt_regs *fp, int cause)
134 unsigned long addr = RDCTL(CTL_BADADDR);
136 cause >>= 2;
137 fp->ea -= 4;
139 if (fixup_exception(fp))
140 return;
142 if (!user_mode(fp)) {
143 pr_alert("Unaligned access from kernel mode, this might be a hardware\n");
144 pr_alert("problem, dump registers and restart the instruction\n");
145 pr_alert(" BADADDR 0x%08lx\n", addr);
146 pr_alert(" cause %d\n", cause);
147 pr_alert(" op-code 0x%08lx\n", *(unsigned long *)(fp->ea));
148 show_regs(fp);
149 return;
152 _exception(SIGBUS, fp, BUS_ADRALN, addr);
154 #endif /* CONFIG_NIOS2_ALIGNMENT_TRAP */
156 /* Illegal instruction handler */
157 asmlinkage void handle_illegal_c(struct pt_regs *fp)
159 fp->ea -= 4;
160 _exception(SIGILL, fp, ILL_ILLOPC, fp->ea);
163 /* Supervisor instruction handler */
164 asmlinkage void handle_supervisor_instr(struct pt_regs *fp)
166 fp->ea -= 4;
167 _exception(SIGILL, fp, ILL_PRVOPC, fp->ea);
170 /* Division error handler */
171 asmlinkage void handle_diverror_c(struct pt_regs *fp)
173 fp->ea -= 4;
174 _exception(SIGFPE, fp, FPE_INTDIV, fp->ea);
177 /* Unhandled exception handler */
178 asmlinkage void unhandled_exception(struct pt_regs *regs, int cause)
180 unsigned long addr = RDCTL(CTL_BADADDR);
182 cause /= 4;
184 pr_emerg("Unhandled exception #%d in %s mode (badaddr=0x%08lx)\n",
185 cause, user_mode(regs) ? "user" : "kernel", addr);
187 regs->ea -= 4;
188 show_regs(regs);
190 pr_emerg("opcode: 0x%08lx\n", *(unsigned long *)(regs->ea));
193 asmlinkage void handle_trap_1_c(struct pt_regs *fp)
195 _send_sig(SIGUSR1, 0, fp->ea);
198 asmlinkage void handle_trap_2_c(struct pt_regs *fp)
200 _send_sig(SIGUSR2, 0, fp->ea);
203 asmlinkage void handle_trap_3_c(struct pt_regs *fp)
205 _send_sig(SIGILL, ILL_ILLTRP, fp->ea);