traps.c 18 KB

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