]>
Commit | Line | Data |
---|---|---|
5f97f7f9 HS |
1 | /* |
2 | * Copyright (C) 2004-2006 Atmel Corporation | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License version 2 as | |
6 | * published by the Free Software Foundation. | |
7 | */ | |
623b0355 HS |
8 | |
9 | #include <linux/bug.h> | |
5f97f7f9 | 10 | #include <linux/init.h> |
5f97f7f9 | 11 | #include <linux/kallsyms.h> |
e7ba176b | 12 | #include <linux/kdebug.h> |
623b0355 | 13 | #include <linux/module.h> |
5f97f7f9 | 14 | #include <linux/notifier.h> |
623b0355 HS |
15 | #include <linux/sched.h> |
16 | #include <linux/uaccess.h> | |
5f97f7f9 | 17 | |
5f97f7f9 | 18 | #include <asm/addrspace.h> |
5f97f7f9 | 19 | #include <asm/mmu_context.h> |
623b0355 HS |
20 | #include <asm/ocd.h> |
21 | #include <asm/sysreg.h> | |
22 | #include <asm/traps.h> | |
5f97f7f9 | 23 | |
5f97f7f9 HS |
24 | static DEFINE_SPINLOCK(die_lock); |
25 | ||
623b0355 | 26 | void NORET_TYPE die(const char *str, struct pt_regs *regs, long err) |
5f97f7f9 | 27 | { |
5f97f7f9 HS |
28 | static int die_counter; |
29 | ||
30 | console_verbose(); | |
31 | spin_lock_irq(&die_lock); | |
32 | bust_spinlocks(1); | |
33 | ||
623b0355 HS |
34 | printk(KERN_ALERT "Oops: %s, sig: %ld [#%d]\n" KERN_EMERG, |
35 | str, err, ++die_counter); | |
36 | #ifdef CONFIG_PREEMPT | |
37 | printk("PREEMPT "); | |
38 | #endif | |
39 | #ifdef CONFIG_FRAME_POINTER | |
40 | printk("FRAME_POINTER "); | |
41 | #endif | |
42 | if (current_cpu_data.features & AVR32_FEATURE_OCD) { | |
8dfe8f29 | 43 | unsigned long did = ocd_read(DID); |
623b0355 HS |
44 | printk("chip: 0x%03lx:0x%04lx rev %lu\n", |
45 | (did >> 1) & 0x7ff, | |
46 | (did >> 12) & 0x7fff, | |
47 | (did >> 28) & 0xf); | |
48 | } else { | |
49 | printk("cpu: arch %u r%u / core %u r%u\n", | |
50 | current_cpu_data.arch_type, | |
51 | current_cpu_data.arch_revision, | |
52 | current_cpu_data.cpu_type, | |
53 | current_cpu_data.cpu_revision); | |
5f97f7f9 HS |
54 | } |
55 | ||
623b0355 HS |
56 | print_modules(); |
57 | show_regs_log_lvl(regs, KERN_EMERG); | |
58 | show_stack_log_lvl(current, regs->sp, regs, KERN_EMERG); | |
5f97f7f9 | 59 | bust_spinlocks(0); |
bcdcd8e7 | 60 | add_taint(TAINT_DIE); |
5f97f7f9 | 61 | spin_unlock_irq(&die_lock); |
623b0355 HS |
62 | |
63 | if (in_interrupt()) | |
64 | panic("Fatal exception in interrupt"); | |
65 | ||
66 | if (panic_on_oops) | |
67 | panic("Fatal exception"); | |
68 | ||
69 | do_exit(err); | |
5f97f7f9 HS |
70 | } |
71 | ||
623b0355 HS |
72 | void _exception(long signr, struct pt_regs *regs, int code, |
73 | unsigned long addr) | |
5f97f7f9 | 74 | { |
623b0355 HS |
75 | siginfo_t info; |
76 | ||
5f97f7f9 | 77 | if (!user_mode(regs)) |
623b0355 HS |
78 | die("Unhandled exception in kernel mode", regs, signr); |
79 | ||
80 | memset(&info, 0, sizeof(info)); | |
81 | info.si_signo = signr; | |
82 | info.si_code = code; | |
83 | info.si_addr = (void __user *)addr; | |
84 | force_sig_info(signr, &info, current); | |
5f97f7f9 | 85 | |
5f97f7f9 | 86 | /* |
623b0355 HS |
87 | * Init gets no signals that it doesn't have a handler for. |
88 | * That's all very well, but if it has caused a synchronous | |
89 | * exception and we ignore the resulting signal, it will just | |
90 | * generate the same exception over and over again and we get | |
91 | * nowhere. Better to kill it and let the kernel panic. | |
5f97f7f9 | 92 | */ |
b460cbc5 | 93 | if (is_global_init(current)) { |
623b0355 HS |
94 | __sighandler_t handler; |
95 | ||
96 | spin_lock_irq(¤t->sighand->siglock); | |
97 | handler = current->sighand->action[signr-1].sa.sa_handler; | |
98 | spin_unlock_irq(¤t->sighand->siglock); | |
99 | if (handler == SIG_DFL) { | |
100 | /* init has generated a synchronous exception | |
101 | and it doesn't have a handler for the signal */ | |
102 | printk(KERN_CRIT "init has generated signal %ld " | |
103 | "but has no handler for it\n", signr); | |
104 | do_exit(signr); | |
105 | } | |
106 | } | |
107 | } | |
5f97f7f9 | 108 | |
623b0355 HS |
109 | asmlinkage void do_nmi(unsigned long ecr, struct pt_regs *regs) |
110 | { | |
e7ba176b HS |
111 | int ret; |
112 | ||
113 | nmi_enter(); | |
114 | ||
115 | ret = notify_die(DIE_NMI, "NMI", regs, 0, ecr, SIGINT); | |
116 | switch (ret) { | |
117 | case NOTIFY_OK: | |
118 | case NOTIFY_STOP: | |
3d431a74 | 119 | break; |
e7ba176b HS |
120 | case NOTIFY_BAD: |
121 | die("Fatal Non-Maskable Interrupt", regs, SIGINT); | |
122 | default: | |
3d431a74 MS |
123 | printk(KERN_ALERT "Got NMI, but nobody cared. Disabling...\n"); |
124 | nmi_disable(); | |
e7ba176b HS |
125 | break; |
126 | } | |
3d431a74 | 127 | nmi_exit(); |
5f97f7f9 HS |
128 | } |
129 | ||
130 | asmlinkage void do_critical_exception(unsigned long ecr, struct pt_regs *regs) | |
131 | { | |
623b0355 | 132 | die("Critical exception", regs, SIGKILL); |
5f97f7f9 HS |
133 | } |
134 | ||
135 | asmlinkage void do_address_exception(unsigned long ecr, struct pt_regs *regs) | |
136 | { | |
623b0355 | 137 | _exception(SIGBUS, regs, BUS_ADRALN, regs->pc); |
5f97f7f9 HS |
138 | } |
139 | ||
140 | /* This way of handling undefined instructions is stolen from ARM */ | |
141 | static LIST_HEAD(undef_hook); | |
e89b064a | 142 | static DEFINE_SPINLOCK(undef_lock); |
5f97f7f9 HS |
143 | |
144 | void register_undef_hook(struct undef_hook *hook) | |
145 | { | |
146 | spin_lock_irq(&undef_lock); | |
147 | list_add(&hook->node, &undef_hook); | |
148 | spin_unlock_irq(&undef_lock); | |
149 | } | |
150 | ||
151 | void unregister_undef_hook(struct undef_hook *hook) | |
152 | { | |
153 | spin_lock_irq(&undef_lock); | |
154 | list_del(&hook->node); | |
155 | spin_unlock_irq(&undef_lock); | |
156 | } | |
157 | ||
158 | static int do_cop_absent(u32 insn) | |
159 | { | |
160 | int cop_nr; | |
161 | u32 cpucr; | |
623b0355 HS |
162 | |
163 | if ((insn & 0xfdf00000) == 0xf1900000) | |
5f97f7f9 HS |
164 | /* LDC0 */ |
165 | cop_nr = 0; | |
166 | else | |
167 | cop_nr = (insn >> 13) & 0x7; | |
168 | ||
169 | /* Try enabling the coprocessor */ | |
170 | cpucr = sysreg_read(CPUCR); | |
171 | cpucr |= (1 << (24 + cop_nr)); | |
172 | sysreg_write(CPUCR, cpucr); | |
173 | ||
174 | cpucr = sysreg_read(CPUCR); | |
623b0355 HS |
175 | if (!(cpucr & (1 << (24 + cop_nr)))) |
176 | return -ENODEV; | |
5f97f7f9 HS |
177 | |
178 | return 0; | |
179 | } | |
180 | ||
957ecd7d | 181 | #ifdef CONFIG_BUG |
623b0355 | 182 | int is_valid_bugaddr(unsigned long pc) |
5f97f7f9 | 183 | { |
623b0355 HS |
184 | unsigned short opcode; |
185 | ||
186 | if (pc < PAGE_OFFSET) | |
187 | return 0; | |
188 | if (probe_kernel_address((u16 *)pc, opcode)) | |
189 | return 0; | |
5f97f7f9 | 190 | |
623b0355 | 191 | return opcode == AVR32_BUG_OPCODE; |
5f97f7f9 | 192 | } |
957ecd7d | 193 | #endif |
5f97f7f9 HS |
194 | |
195 | asmlinkage void do_illegal_opcode(unsigned long ecr, struct pt_regs *regs) | |
196 | { | |
197 | u32 insn; | |
198 | struct undef_hook *hook; | |
5f97f7f9 | 199 | void __user *pc; |
623b0355 | 200 | long code; |
5f97f7f9 | 201 | |
957ecd7d | 202 | #ifdef CONFIG_BUG |
623b0355 HS |
203 | if (!user_mode(regs) && (ecr == ECR_ILLEGAL_OPCODE)) { |
204 | enum bug_trap_type type; | |
205 | ||
608e2619 | 206 | type = report_bug(regs->pc, regs); |
623b0355 HS |
207 | switch (type) { |
208 | case BUG_TRAP_TYPE_NONE: | |
209 | break; | |
210 | case BUG_TRAP_TYPE_WARN: | |
211 | regs->pc += 2; | |
212 | return; | |
213 | case BUG_TRAP_TYPE_BUG: | |
214 | die("Kernel BUG", regs, SIGKILL); | |
215 | } | |
216 | } | |
957ecd7d | 217 | #endif |
5f97f7f9 HS |
218 | |
219 | local_irq_enable(); | |
220 | ||
623b0355 HS |
221 | if (user_mode(regs)) { |
222 | pc = (void __user *)instruction_pointer(regs); | |
223 | if (get_user(insn, (u32 __user *)pc)) | |
224 | goto invalid_area; | |
5f97f7f9 | 225 | |
623b0355 | 226 | if (ecr == ECR_COPROC_ABSENT && !do_cop_absent(insn)) |
5f97f7f9 | 227 | return; |
5f97f7f9 | 228 | |
623b0355 HS |
229 | spin_lock_irq(&undef_lock); |
230 | list_for_each_entry(hook, &undef_hook, node) { | |
231 | if ((insn & hook->insn_mask) == hook->insn_val) { | |
232 | if (hook->fn(regs, insn) == 0) { | |
233 | spin_unlock_irq(&undef_lock); | |
234 | return; | |
235 | } | |
5f97f7f9 HS |
236 | } |
237 | } | |
623b0355 | 238 | spin_unlock_irq(&undef_lock); |
5f97f7f9 | 239 | } |
5f97f7f9 | 240 | |
5f97f7f9 | 241 | switch (ecr) { |
5f97f7f9 | 242 | case ECR_PRIVILEGE_VIOLATION: |
623b0355 | 243 | code = ILL_PRVOPC; |
5f97f7f9 HS |
244 | break; |
245 | case ECR_COPROC_ABSENT: | |
623b0355 | 246 | code = ILL_COPROC; |
5f97f7f9 HS |
247 | break; |
248 | default: | |
623b0355 HS |
249 | code = ILL_ILLOPC; |
250 | break; | |
5f97f7f9 HS |
251 | } |
252 | ||
623b0355 | 253 | _exception(SIGILL, regs, code, regs->pc); |
5f97f7f9 HS |
254 | return; |
255 | ||
623b0355 HS |
256 | invalid_area: |
257 | _exception(SIGSEGV, regs, SEGV_MAPERR, regs->pc); | |
5f97f7f9 HS |
258 | } |
259 | ||
260 | asmlinkage void do_fpe(unsigned long ecr, struct pt_regs *regs) | |
261 | { | |
623b0355 HS |
262 | /* We have no FPU yet */ |
263 | _exception(SIGILL, regs, ILL_COPROC, regs->pc); | |
5f97f7f9 HS |
264 | } |
265 | ||
266 | ||
267 | void __init trap_init(void) | |
268 | { | |
269 | ||
270 | } |