traps.c 18 KB

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