traps.c 19 KB

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