traps.c 20 KB

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