traps.c 21 KB

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