traps.c 18 KB

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