traps.c 18 KB

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