traps.c 20 KB

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