traps.c 18 KB

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