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