traps.c 18 KB

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