traps.c 20 KB

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