traps.c 20 KB

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