traps.c 20 KB

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