traps.c 20 KB

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