traps.c 19 KB

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