traps.c 20 KB

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