traps.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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/delay.h>
  25. #include <linux/init.h>
  26. #include <asm/atomic.h>
  27. #include <asm/cacheflush.h>
  28. #include <asm/system.h>
  29. #include <asm/unistd.h>
  30. #include <asm/traps.h>
  31. #include <asm/unwind.h>
  32. #include "ptrace.h"
  33. #include "signal.h"
  34. static const char *handler[]= { "prefetch abort", "data abort", "address exception", "interrupt" };
  35. #ifdef CONFIG_DEBUG_USER
  36. unsigned int user_debug;
  37. static int __init user_debug_setup(char *str)
  38. {
  39. get_option(&str, &user_debug);
  40. return 1;
  41. }
  42. __setup("user_debug=", user_debug_setup);
  43. #endif
  44. static void dump_mem(const char *, const char *, unsigned long, unsigned long);
  45. void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
  46. {
  47. #ifdef CONFIG_KALLSYMS
  48. char sym1[KSYM_SYMBOL_LEN], sym2[KSYM_SYMBOL_LEN];
  49. sprint_symbol(sym1, where);
  50. sprint_symbol(sym2, from);
  51. printk("[<%08lx>] (%s) from [<%08lx>] (%s)\n", where, sym1, from, sym2);
  52. #else
  53. printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
  54. #endif
  55. if (in_exception_text(where))
  56. dump_mem("", "Exception stack", frame + 4, frame + 4 + sizeof(struct pt_regs));
  57. }
  58. #ifndef CONFIG_ARM_UNWIND
  59. /*
  60. * Stack pointers should always be within the kernels view of
  61. * physical memory. If it is not there, then we can't dump
  62. * out any information relating to the stack.
  63. */
  64. static int verify_stack(unsigned long sp)
  65. {
  66. if (sp < PAGE_OFFSET ||
  67. (sp > (unsigned long)high_memory && high_memory != NULL))
  68. return -EFAULT;
  69. return 0;
  70. }
  71. #endif
  72. /*
  73. * Dump out the contents of some memory nicely...
  74. */
  75. static void dump_mem(const char *lvl, const char *str, unsigned long bottom,
  76. unsigned long top)
  77. {
  78. unsigned long first;
  79. mm_segment_t fs;
  80. int i;
  81. /*
  82. * We need to switch to kernel mode so that we can use __get_user
  83. * to safely read from kernel space. Note that we now dump the
  84. * code first, just in case the backtrace kills us.
  85. */
  86. fs = get_fs();
  87. set_fs(KERNEL_DS);
  88. printk("%s%s(0x%08lx to 0x%08lx)\n", lvl, str, bottom, top);
  89. for (first = bottom & ~31; first < top; first += 32) {
  90. unsigned long p;
  91. char str[sizeof(" 12345678") * 8 + 1];
  92. memset(str, ' ', sizeof(str));
  93. str[sizeof(str) - 1] = '\0';
  94. for (p = first, i = 0; i < 8 && p < top; i++, p += 4) {
  95. if (p >= bottom && p < top) {
  96. unsigned long val;
  97. if (__get_user(val, (unsigned long *)p) == 0)
  98. sprintf(str + i * 9, " %08lx", val);
  99. else
  100. sprintf(str + i * 9, " ????????");
  101. }
  102. }
  103. printk("%s%04lx:%s\n", lvl, first & 0xffff, str);
  104. }
  105. set_fs(fs);
  106. }
  107. static void dump_instr(const char *lvl, struct pt_regs *regs)
  108. {
  109. unsigned long addr = instruction_pointer(regs);
  110. const int thumb = thumb_mode(regs);
  111. const int width = thumb ? 4 : 8;
  112. mm_segment_t fs;
  113. char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str;
  114. int i;
  115. /*
  116. * We need to switch to kernel mode so that we can use __get_user
  117. * to safely read from kernel space. Note that we now dump the
  118. * code first, just in case the backtrace kills us.
  119. */
  120. fs = get_fs();
  121. set_fs(KERNEL_DS);
  122. for (i = -4; i < 1; i++) {
  123. unsigned int val, bad;
  124. if (thumb)
  125. bad = __get_user(val, &((u16 *)addr)[i]);
  126. else
  127. bad = __get_user(val, &((u32 *)addr)[i]);
  128. if (!bad)
  129. p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ",
  130. width, val);
  131. else {
  132. p += sprintf(p, "bad PC value");
  133. break;
  134. }
  135. }
  136. printk("%sCode: %s\n", lvl, str);
  137. set_fs(fs);
  138. }
  139. #ifdef CONFIG_ARM_UNWIND
  140. static inline void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
  141. {
  142. unwind_backtrace(regs, tsk);
  143. }
  144. #else
  145. static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
  146. {
  147. unsigned int fp, mode;
  148. int ok = 1;
  149. printk("Backtrace: ");
  150. if (!tsk)
  151. tsk = current;
  152. if (regs) {
  153. fp = regs->ARM_fp;
  154. mode = processor_mode(regs);
  155. } else if (tsk != current) {
  156. fp = thread_saved_fp(tsk);
  157. mode = 0x10;
  158. } else {
  159. asm("mov %0, fp" : "=r" (fp) : : "cc");
  160. mode = 0x10;
  161. }
  162. if (!fp) {
  163. printk("no frame pointer");
  164. ok = 0;
  165. } else if (verify_stack(fp)) {
  166. printk("invalid frame pointer 0x%08x", fp);
  167. ok = 0;
  168. } else if (fp < (unsigned long)end_of_stack(tsk))
  169. printk("frame pointer underflow");
  170. printk("\n");
  171. if (ok)
  172. c_backtrace(fp, mode);
  173. }
  174. #endif
  175. void dump_stack(void)
  176. {
  177. dump_backtrace(NULL, NULL);
  178. }
  179. EXPORT_SYMBOL(dump_stack);
  180. void show_stack(struct task_struct *tsk, unsigned long *sp)
  181. {
  182. dump_backtrace(NULL, tsk);
  183. barrier();
  184. }
  185. #ifdef CONFIG_PREEMPT
  186. #define S_PREEMPT " PREEMPT"
  187. #else
  188. #define S_PREEMPT ""
  189. #endif
  190. #ifdef CONFIG_SMP
  191. #define S_SMP " SMP"
  192. #else
  193. #define S_SMP ""
  194. #endif
  195. static int __die(const char *str, int err, struct thread_info *thread, struct pt_regs *regs)
  196. {
  197. struct task_struct *tsk = thread->task;
  198. static int die_counter;
  199. int ret;
  200. printk(KERN_EMERG "Internal error: %s: %x [#%d]" S_PREEMPT S_SMP "\n",
  201. str, err, ++die_counter);
  202. sysfs_printk_last_file();
  203. /* trap and error numbers are mostly meaningless on ARM */
  204. ret = notify_die(DIE_OOPS, str, regs, err, tsk->thread.trap_no, SIGSEGV);
  205. if (ret == NOTIFY_STOP)
  206. return ret;
  207. print_modules();
  208. __show_regs(regs);
  209. printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
  210. TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
  211. if (!user_mode(regs) || in_interrupt()) {
  212. dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
  213. THREAD_SIZE + (unsigned long)task_stack_page(tsk));
  214. dump_backtrace(regs, tsk);
  215. dump_instr(KERN_EMERG, regs);
  216. }
  217. return ret;
  218. }
  219. DEFINE_SPINLOCK(die_lock);
  220. /*
  221. * This function is protected against re-entrancy.
  222. */
  223. void die(const char *str, struct pt_regs *regs, int err)
  224. {
  225. struct thread_info *thread = current_thread_info();
  226. int ret;
  227. oops_enter();
  228. spin_lock_irq(&die_lock);
  229. console_verbose();
  230. bust_spinlocks(1);
  231. ret = __die(str, err, thread, regs);
  232. if (regs && kexec_should_crash(thread->task))
  233. crash_kexec(regs);
  234. bust_spinlocks(0);
  235. add_taint(TAINT_DIE);
  236. spin_unlock_irq(&die_lock);
  237. oops_exit();
  238. if (in_interrupt())
  239. panic("Fatal exception in interrupt");
  240. if (panic_on_oops)
  241. panic("Fatal exception");
  242. if (ret != NOTIFY_STOP)
  243. do_exit(SIGSEGV);
  244. }
  245. void arm_notify_die(const char *str, struct pt_regs *regs,
  246. struct siginfo *info, unsigned long err, unsigned long trap)
  247. {
  248. if (user_mode(regs)) {
  249. current->thread.error_code = err;
  250. current->thread.trap_no = trap;
  251. force_sig_info(info->si_signo, info, current);
  252. } else {
  253. die(str, regs, err);
  254. }
  255. }
  256. static LIST_HEAD(undef_hook);
  257. static DEFINE_SPINLOCK(undef_lock);
  258. void register_undef_hook(struct undef_hook *hook)
  259. {
  260. unsigned long flags;
  261. spin_lock_irqsave(&undef_lock, flags);
  262. list_add(&hook->node, &undef_hook);
  263. spin_unlock_irqrestore(&undef_lock, flags);
  264. }
  265. void unregister_undef_hook(struct undef_hook *hook)
  266. {
  267. unsigned long flags;
  268. spin_lock_irqsave(&undef_lock, flags);
  269. list_del(&hook->node);
  270. spin_unlock_irqrestore(&undef_lock, flags);
  271. }
  272. static int call_undef_hook(struct pt_regs *regs, unsigned int instr)
  273. {
  274. struct undef_hook *hook;
  275. unsigned long flags;
  276. int (*fn)(struct pt_regs *regs, unsigned int instr) = NULL;
  277. spin_lock_irqsave(&undef_lock, flags);
  278. list_for_each_entry(hook, &undef_hook, node)
  279. if ((instr & hook->instr_mask) == hook->instr_val &&
  280. (regs->ARM_cpsr & hook->cpsr_mask) == hook->cpsr_val)
  281. fn = hook->fn;
  282. spin_unlock_irqrestore(&undef_lock, flags);
  283. return fn ? fn(regs, instr) : 1;
  284. }
  285. asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
  286. {
  287. unsigned int correction = thumb_mode(regs) ? 2 : 4;
  288. unsigned int instr;
  289. siginfo_t info;
  290. void __user *pc;
  291. /*
  292. * According to the ARM ARM, PC is 2 or 4 bytes ahead,
  293. * depending whether we're in Thumb mode or not.
  294. * Correct this offset.
  295. */
  296. regs->ARM_pc -= correction;
  297. pc = (void __user *)instruction_pointer(regs);
  298. if (processor_mode(regs) == SVC_MODE) {
  299. instr = *(u32 *) pc;
  300. } else if (thumb_mode(regs)) {
  301. get_user(instr, (u16 __user *)pc);
  302. } else {
  303. get_user(instr, (u32 __user *)pc);
  304. }
  305. if (call_undef_hook(regs, instr) == 0)
  306. return;
  307. #ifdef CONFIG_DEBUG_USER
  308. if (user_debug & UDBG_UNDEFINED) {
  309. printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n",
  310. current->comm, task_pid_nr(current), pc);
  311. dump_instr(KERN_INFO, regs);
  312. }
  313. #endif
  314. info.si_signo = SIGILL;
  315. info.si_errno = 0;
  316. info.si_code = ILL_ILLOPC;
  317. info.si_addr = pc;
  318. arm_notify_die("Oops - undefined instruction", regs, &info, 0, 6);
  319. }
  320. asmlinkage void do_unexp_fiq (struct pt_regs *regs)
  321. {
  322. printk("Hmm. Unexpected FIQ received, but trying to continue\n");
  323. printk("You may have a hardware problem...\n");
  324. }
  325. /*
  326. * bad_mode handles the impossible case in the vectors. If you see one of
  327. * these, then it's extremely serious, and could mean you have buggy hardware.
  328. * It never returns, and never tries to sync. We hope that we can at least
  329. * dump out some state information...
  330. */
  331. asmlinkage void bad_mode(struct pt_regs *regs, int reason)
  332. {
  333. console_verbose();
  334. printk(KERN_CRIT "Bad mode in %s handler detected\n", handler[reason]);
  335. die("Oops - bad mode", regs, 0);
  336. local_irq_disable();
  337. panic("bad mode");
  338. }
  339. static int bad_syscall(int n, struct pt_regs *regs)
  340. {
  341. struct thread_info *thread = current_thread_info();
  342. siginfo_t info;
  343. if (current->personality != PER_LINUX &&
  344. current->personality != PER_LINUX_32BIT &&
  345. thread->exec_domain->handler) {
  346. thread->exec_domain->handler(n, regs);
  347. return regs->ARM_r0;
  348. }
  349. #ifdef CONFIG_DEBUG_USER
  350. if (user_debug & UDBG_SYSCALL) {
  351. printk(KERN_ERR "[%d] %s: obsolete system call %08x.\n",
  352. task_pid_nr(current), current->comm, n);
  353. dump_instr(KERN_ERR, regs);
  354. }
  355. #endif
  356. info.si_signo = SIGILL;
  357. info.si_errno = 0;
  358. info.si_code = ILL_ILLTRP;
  359. info.si_addr = (void __user *)instruction_pointer(regs) -
  360. (thumb_mode(regs) ? 2 : 4);
  361. arm_notify_die("Oops - bad syscall", regs, &info, n, 0);
  362. return regs->ARM_r0;
  363. }
  364. static inline void
  365. do_cache_op(unsigned long start, unsigned long end, int flags)
  366. {
  367. struct mm_struct *mm = current->active_mm;
  368. struct vm_area_struct *vma;
  369. if (end < start || flags)
  370. return;
  371. down_read(&mm->mmap_sem);
  372. vma = find_vma(mm, start);
  373. if (vma && vma->vm_start < end) {
  374. if (start < vma->vm_start)
  375. start = vma->vm_start;
  376. if (end > vma->vm_end)
  377. end = vma->vm_end;
  378. flush_cache_user_range(vma, start, end);
  379. }
  380. up_read(&mm->mmap_sem);
  381. }
  382. /*
  383. * Handle all unrecognised system calls.
  384. * 0x9f0000 - 0x9fffff are some more esoteric system calls
  385. */
  386. #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)
  387. asmlinkage int arm_syscall(int no, struct pt_regs *regs)
  388. {
  389. struct thread_info *thread = current_thread_info();
  390. siginfo_t info;
  391. if ((no >> 16) != (__ARM_NR_BASE>> 16))
  392. return bad_syscall(no, regs);
  393. switch (no & 0xffff) {
  394. case 0: /* branch through 0 */
  395. info.si_signo = SIGSEGV;
  396. info.si_errno = 0;
  397. info.si_code = SEGV_MAPERR;
  398. info.si_addr = NULL;
  399. arm_notify_die("branch through zero", regs, &info, 0, 0);
  400. return 0;
  401. case NR(breakpoint): /* SWI BREAK_POINT */
  402. regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
  403. ptrace_break(current, regs);
  404. return regs->ARM_r0;
  405. /*
  406. * Flush a region from virtual address 'r0' to virtual address 'r1'
  407. * _exclusive_. There is no alignment requirement on either address;
  408. * user space does not need to know the hardware cache layout.
  409. *
  410. * r2 contains flags. It should ALWAYS be passed as ZERO until it
  411. * is defined to be something else. For now we ignore it, but may
  412. * the fires of hell burn in your belly if you break this rule. ;)
  413. *
  414. * (at a later date, we may want to allow this call to not flush
  415. * various aspects of the cache. Passing '0' will guarantee that
  416. * everything necessary gets flushed to maintain consistency in
  417. * the specified region).
  418. */
  419. case NR(cacheflush):
  420. do_cache_op(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2);
  421. return 0;
  422. case NR(usr26):
  423. if (!(elf_hwcap & HWCAP_26BIT))
  424. break;
  425. regs->ARM_cpsr &= ~MODE32_BIT;
  426. return regs->ARM_r0;
  427. case NR(usr32):
  428. if (!(elf_hwcap & HWCAP_26BIT))
  429. break;
  430. regs->ARM_cpsr |= MODE32_BIT;
  431. return regs->ARM_r0;
  432. case NR(set_tls):
  433. thread->tp_value = regs->ARM_r0;
  434. #if defined(CONFIG_HAS_TLS_REG)
  435. asm ("mcr p15, 0, %0, c13, c0, 3" : : "r" (regs->ARM_r0) );
  436. #elif !defined(CONFIG_TLS_REG_EMUL)
  437. /*
  438. * User space must never try to access this directly.
  439. * Expect your app to break eventually if you do so.
  440. * The user helper at 0xffff0fe0 must be used instead.
  441. * (see entry-armv.S for details)
  442. */
  443. *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
  444. #endif
  445. return 0;
  446. #ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG
  447. /*
  448. * Atomically store r1 in *r2 if *r2 is equal to r0 for user space.
  449. * Return zero in r0 if *MEM was changed or non-zero if no exchange
  450. * happened. Also set the user C flag accordingly.
  451. * If access permissions have to be fixed up then non-zero is
  452. * returned and the operation has to be re-attempted.
  453. *
  454. * *NOTE*: This is a ghost syscall private to the kernel. Only the
  455. * __kuser_cmpxchg code in entry-armv.S should be aware of its
  456. * existence. Don't ever use this from user code.
  457. */
  458. case NR(cmpxchg):
  459. for (;;) {
  460. extern void do_DataAbort(unsigned long addr, unsigned int fsr,
  461. struct pt_regs *regs);
  462. unsigned long val;
  463. unsigned long addr = regs->ARM_r2;
  464. struct mm_struct *mm = current->mm;
  465. pgd_t *pgd; pmd_t *pmd; pte_t *pte;
  466. spinlock_t *ptl;
  467. regs->ARM_cpsr &= ~PSR_C_BIT;
  468. down_read(&mm->mmap_sem);
  469. pgd = pgd_offset(mm, addr);
  470. if (!pgd_present(*pgd))
  471. goto bad_access;
  472. pmd = pmd_offset(pgd, addr);
  473. if (!pmd_present(*pmd))
  474. goto bad_access;
  475. pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
  476. if (!pte_present(*pte) || !pte_dirty(*pte)) {
  477. pte_unmap_unlock(pte, ptl);
  478. goto bad_access;
  479. }
  480. val = *(unsigned long *)addr;
  481. val -= regs->ARM_r0;
  482. if (val == 0) {
  483. *(unsigned long *)addr = regs->ARM_r1;
  484. regs->ARM_cpsr |= PSR_C_BIT;
  485. }
  486. pte_unmap_unlock(pte, ptl);
  487. up_read(&mm->mmap_sem);
  488. return val;
  489. bad_access:
  490. up_read(&mm->mmap_sem);
  491. /* simulate a write access fault */
  492. do_DataAbort(addr, 15 + (1 << 11), regs);
  493. }
  494. #endif
  495. default:
  496. /* Calls 9f00xx..9f07ff are defined to return -ENOSYS
  497. if not implemented, rather than raising SIGILL. This
  498. way the calling program can gracefully determine whether
  499. a feature is supported. */
  500. if ((no & 0xffff) <= 0x7ff)
  501. return -ENOSYS;
  502. break;
  503. }
  504. #ifdef CONFIG_DEBUG_USER
  505. /*
  506. * experience shows that these seem to indicate that
  507. * something catastrophic has happened
  508. */
  509. if (user_debug & UDBG_SYSCALL) {
  510. printk("[%d] %s: arm syscall %d\n",
  511. task_pid_nr(current), current->comm, no);
  512. dump_instr("", regs);
  513. if (user_mode(regs)) {
  514. __show_regs(regs);
  515. c_backtrace(regs->ARM_fp, processor_mode(regs));
  516. }
  517. }
  518. #endif
  519. info.si_signo = SIGILL;
  520. info.si_errno = 0;
  521. info.si_code = ILL_ILLTRP;
  522. info.si_addr = (void __user *)instruction_pointer(regs) -
  523. (thumb_mode(regs) ? 2 : 4);
  524. arm_notify_die("Oops - bad syscall(2)", regs, &info, no, 0);
  525. return 0;
  526. }
  527. #ifdef CONFIG_TLS_REG_EMUL
  528. /*
  529. * We might be running on an ARMv6+ processor which should have the TLS
  530. * register but for some reason we can't use it, or maybe an SMP system
  531. * using a pre-ARMv6 processor (there are apparently a few prototypes like
  532. * that in existence) and therefore access to that register must be
  533. * emulated.
  534. */
  535. static int get_tp_trap(struct pt_regs *regs, unsigned int instr)
  536. {
  537. int reg = (instr >> 12) & 15;
  538. if (reg == 15)
  539. return 1;
  540. regs->uregs[reg] = current_thread_info()->tp_value;
  541. regs->ARM_pc += 4;
  542. return 0;
  543. }
  544. static struct undef_hook arm_mrc_hook = {
  545. .instr_mask = 0x0fff0fff,
  546. .instr_val = 0x0e1d0f70,
  547. .cpsr_mask = PSR_T_BIT,
  548. .cpsr_val = 0,
  549. .fn = get_tp_trap,
  550. };
  551. static int __init arm_mrc_hook_init(void)
  552. {
  553. register_undef_hook(&arm_mrc_hook);
  554. return 0;
  555. }
  556. late_initcall(arm_mrc_hook_init);
  557. #endif
  558. void __bad_xchg(volatile void *ptr, int size)
  559. {
  560. printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",
  561. __builtin_return_address(0), ptr, size);
  562. BUG();
  563. }
  564. EXPORT_SYMBOL(__bad_xchg);
  565. /*
  566. * A data abort trap was taken, but we did not handle the instruction.
  567. * Try to abort the user program, or panic if it was the kernel.
  568. */
  569. asmlinkage void
  570. baddataabort(int code, unsigned long instr, struct pt_regs *regs)
  571. {
  572. unsigned long addr = instruction_pointer(regs);
  573. siginfo_t info;
  574. #ifdef CONFIG_DEBUG_USER
  575. if (user_debug & UDBG_BADABORT) {
  576. printk(KERN_ERR "[%d] %s: bad data abort: code %d instr 0x%08lx\n",
  577. task_pid_nr(current), current->comm, code, instr);
  578. dump_instr(KERN_ERR, regs);
  579. show_pte(current->mm, addr);
  580. }
  581. #endif
  582. info.si_signo = SIGILL;
  583. info.si_errno = 0;
  584. info.si_code = ILL_ILLOPC;
  585. info.si_addr = (void __user *)addr;
  586. arm_notify_die("unknown data abort code", regs, &info, instr, 0);
  587. }
  588. void __attribute__((noreturn)) __bug(const char *file, int line)
  589. {
  590. printk(KERN_CRIT"kernel BUG at %s:%d!\n", file, line);
  591. *(int *)0 = 0;
  592. /* Avoid "noreturn function does return" */
  593. for (;;);
  594. }
  595. EXPORT_SYMBOL(__bug);
  596. void __readwrite_bug(const char *fn)
  597. {
  598. printk("%s called, but not implemented\n", fn);
  599. BUG();
  600. }
  601. EXPORT_SYMBOL(__readwrite_bug);
  602. void __pte_error(const char *file, int line, unsigned long val)
  603. {
  604. printk("%s:%d: bad pte %08lx.\n", file, line, val);
  605. }
  606. void __pmd_error(const char *file, int line, unsigned long val)
  607. {
  608. printk("%s:%d: bad pmd %08lx.\n", file, line, val);
  609. }
  610. void __pgd_error(const char *file, int line, unsigned long val)
  611. {
  612. printk("%s:%d: bad pgd %08lx.\n", file, line, val);
  613. }
  614. asmlinkage void __div0(void)
  615. {
  616. printk("Division by zero in kernel.\n");
  617. dump_stack();
  618. }
  619. EXPORT_SYMBOL(__div0);
  620. void abort(void)
  621. {
  622. BUG();
  623. /* if that doesn't kill us, halt */
  624. panic("Oops failed to kill thread");
  625. }
  626. EXPORT_SYMBOL(abort);
  627. void __init trap_init(void)
  628. {
  629. return;
  630. }
  631. void __init early_trap_init(void)
  632. {
  633. unsigned long vectors = CONFIG_VECTORS_BASE;
  634. extern char __stubs_start[], __stubs_end[];
  635. extern char __vectors_start[], __vectors_end[];
  636. extern char __kuser_helper_start[], __kuser_helper_end[];
  637. int kuser_sz = __kuser_helper_end - __kuser_helper_start;
  638. /*
  639. * Copy the vectors, stubs and kuser helpers (in entry-armv.S)
  640. * into the vector page, mapped at 0xffff0000, and ensure these
  641. * are visible to the instruction stream.
  642. */
  643. memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
  644. memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);
  645. memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
  646. /*
  647. * Copy signal return handlers into the vector page, and
  648. * set sigreturn to be a pointer to these.
  649. */
  650. memcpy((void *)KERN_SIGRETURN_CODE, sigreturn_codes,
  651. sizeof(sigreturn_codes));
  652. memcpy((void *)KERN_RESTART_CODE, syscall_restart_code,
  653. sizeof(syscall_restart_code));
  654. flush_icache_range(vectors, vectors + PAGE_SIZE);
  655. modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
  656. }