traps.c 21 KB

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