PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/mn10300/kernel/traps.c

https://bitbucket.org/sola/android_board_beagleboard_kernel
C | 597 lines | 437 code | 81 blank | 79 comment | 49 complexity | ba01d887b617683450ff3c8cd1074e0f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /* MN10300 Exception handling
  2. *
  3. * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. * Modified by David Howells (dhowells@redhat.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public Licence
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the Licence, or (at your option) any later version.
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/string.h>
  15. #include <linux/errno.h>
  16. #include <linux/ptrace.h>
  17. #include <linux/timer.h>
  18. #include <linux/mm.h>
  19. #include <linux/smp.h>
  20. #include <linux/init.h>
  21. #include <linux/delay.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/kallsyms.h>
  25. #include <linux/pci.h>
  26. #include <linux/kdebug.h>
  27. #include <linux/bug.h>
  28. #include <linux/irq.h>
  29. #include <asm/processor.h>
  30. #include <asm/system.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/io.h>
  33. #include <asm/atomic.h>
  34. #include <asm/smp.h>
  35. #include <asm/pgalloc.h>
  36. #include <asm/cacheflush.h>
  37. #include <asm/cpu-regs.h>
  38. #include <asm/busctl-regs.h>
  39. #include <unit/leds.h>
  40. #include <asm/fpu.h>
  41. #include <asm/gdb-stub.h>
  42. #include <asm/sections.h>
  43. #if (CONFIG_INTERRUPT_VECTOR_BASE & 0xffffff)
  44. #error "INTERRUPT_VECTOR_BASE not aligned to 16MiB boundary!"
  45. #endif
  46. int kstack_depth_to_print = 24;
  47. spinlock_t die_lock = __SPIN_LOCK_UNLOCKED(die_lock);
  48. ATOMIC_NOTIFIER_HEAD(mn10300_die_chain);
  49. /*
  50. * These constants are for searching for possible module text
  51. * segments. MODULE_RANGE is a guess of how much space is likely
  52. * to be vmalloced.
  53. */
  54. #define MODULE_RANGE (8 * 1024 * 1024)
  55. #define DO_ERROR(signr, prologue, str, name) \
  56. asmlinkage void name(struct pt_regs *regs, u32 intcode) \
  57. { \
  58. prologue; \
  59. if (die_if_no_fixup(str, regs, intcode)) \
  60. return; \
  61. force_sig(signr, current); \
  62. }
  63. #define DO_EINFO(signr, prologue, str, name, sicode) \
  64. asmlinkage void name(struct pt_regs *regs, u32 intcode) \
  65. { \
  66. siginfo_t info; \
  67. prologue; \
  68. if (die_if_no_fixup(str, regs, intcode)) \
  69. return; \
  70. info.si_signo = signr; \
  71. if (signr == SIGILL && sicode == ILL_ILLOPC) { \
  72. uint8_t opcode; \
  73. if (get_user(opcode, (uint8_t __user *)regs->pc) == 0) \
  74. if (opcode == 0xff) \
  75. info.si_signo = SIGTRAP; \
  76. } \
  77. info.si_errno = 0; \
  78. info.si_code = sicode; \
  79. info.si_addr = (void *) regs->pc; \
  80. force_sig_info(info.si_signo, &info, current); \
  81. }
  82. DO_ERROR(SIGTRAP, {}, "trap", trap);
  83. DO_ERROR(SIGSEGV, {}, "ibreak", ibreak);
  84. DO_ERROR(SIGSEGV, {}, "obreak", obreak);
  85. DO_EINFO(SIGSEGV, {}, "access error", access_error, SEGV_ACCERR);
  86. DO_EINFO(SIGSEGV, {}, "insn access error", insn_acc_error, SEGV_ACCERR);
  87. DO_EINFO(SIGSEGV, {}, "data access error", data_acc_error, SEGV_ACCERR);
  88. DO_EINFO(SIGILL, {}, "privileged opcode", priv_op, ILL_PRVOPC);
  89. DO_EINFO(SIGILL, {}, "invalid opcode", invalid_op, ILL_ILLOPC);
  90. DO_EINFO(SIGILL, {}, "invalid ex opcode", invalid_exop, ILL_ILLOPC);
  91. DO_EINFO(SIGBUS, {}, "invalid address", mem_error, BUS_ADRERR);
  92. DO_EINFO(SIGBUS, {}, "bus error", bus_error, BUS_ADRERR);
  93. DO_ERROR(SIGTRAP,
  94. #ifndef CONFIG_MN10300_USING_JTAG
  95. DCR &= ~0x0001,
  96. #else
  97. {},
  98. #endif
  99. "single step", istep);
  100. /*
  101. * handle NMI
  102. */
  103. asmlinkage void nmi(struct pt_regs *regs, enum exception_code code)
  104. {
  105. /* see if gdbstub wants to deal with it */
  106. #ifdef CONFIG_GDBSTUB
  107. if (gdbstub_intercept(regs, code))
  108. return;
  109. #endif
  110. printk(KERN_WARNING "--- Register Dump ---\n");
  111. show_registers(regs);
  112. printk(KERN_WARNING "---------------------\n");
  113. }
  114. /*
  115. * show a stack trace from the specified stack pointer
  116. */
  117. void show_trace(unsigned long *sp)
  118. {
  119. unsigned long *stack, addr, module_start, module_end;
  120. int i;
  121. printk(KERN_EMERG "\nCall Trace:");
  122. stack = sp;
  123. i = 0;
  124. module_start = VMALLOC_START;
  125. module_end = VMALLOC_END;
  126. while (((long) stack & (THREAD_SIZE - 1)) != 0) {
  127. addr = *stack++;
  128. if (__kernel_text_address(addr)) {
  129. #if 1
  130. printk(" [<%08lx>]", addr);
  131. print_symbol(" %s", addr);
  132. printk("\n");
  133. #else
  134. if ((i % 6) == 0)
  135. printk(KERN_EMERG " ");
  136. printk("[<%08lx>] ", addr);
  137. i++;
  138. #endif
  139. }
  140. }
  141. printk("\n");
  142. }
  143. /*
  144. * show the raw stack from the specified stack pointer
  145. */
  146. void show_stack(struct task_struct *task, unsigned long *sp)
  147. {
  148. unsigned long *stack;
  149. int i;
  150. if (!sp)
  151. sp = (unsigned long *) &sp;
  152. stack = sp;
  153. printk(KERN_EMERG "Stack:");
  154. for (i = 0; i < kstack_depth_to_print; i++) {
  155. if (((long) stack & (THREAD_SIZE - 1)) == 0)
  156. break;
  157. if ((i % 8) == 0)
  158. printk(KERN_EMERG " ");
  159. printk("%08lx ", *stack++);
  160. }
  161. show_trace(sp);
  162. }
  163. /*
  164. * the architecture-independent dump_stack generator
  165. */
  166. void dump_stack(void)
  167. {
  168. unsigned long stack;
  169. show_stack(current, &stack);
  170. }
  171. EXPORT_SYMBOL(dump_stack);
  172. /*
  173. * dump the register file in the specified exception frame
  174. */
  175. void show_registers_only(struct pt_regs *regs)
  176. {
  177. unsigned long ssp;
  178. ssp = (unsigned long) regs + sizeof(*regs);
  179. printk(KERN_EMERG "PC: %08lx EPSW: %08lx SSP: %08lx mode: %s\n",
  180. regs->pc, regs->epsw, ssp, user_mode(regs) ? "User" : "Super");
  181. printk(KERN_EMERG "d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
  182. regs->d0, regs->d1, regs->d2, regs->d3);
  183. printk(KERN_EMERG "a0: %08lx a1: %08lx a2: %08lx a3: %08lx\n",
  184. regs->a0, regs->a1, regs->a2, regs->a3);
  185. printk(KERN_EMERG "e0: %08lx e1: %08lx e2: %08lx e3: %08lx\n",
  186. regs->e0, regs->e1, regs->e2, regs->e3);
  187. printk(KERN_EMERG "e4: %08lx e5: %08lx e6: %08lx e7: %08lx\n",
  188. regs->e4, regs->e5, regs->e6, regs->e7);
  189. printk(KERN_EMERG "lar: %08lx lir: %08lx mdr: %08lx usp: %08lx\n",
  190. regs->lar, regs->lir, regs->mdr, regs->sp);
  191. printk(KERN_EMERG "cvf: %08lx crl: %08lx crh: %08lx drq: %08lx\n",
  192. regs->mcvf, regs->mcrl, regs->mcrh, regs->mdrq);
  193. printk(KERN_EMERG "threadinfo=%p task=%p)\n",
  194. current_thread_info(), current);
  195. if ((unsigned long) current >= PAGE_OFFSET &&
  196. (unsigned long) current < (unsigned long)high_memory)
  197. printk(KERN_EMERG "Process %s (pid: %d)\n",
  198. current->comm, current->pid);
  199. #ifdef CONFIG_SMP
  200. printk(KERN_EMERG "CPUID: %08x\n", CPUID);
  201. #endif
  202. printk(KERN_EMERG "CPUP: %04hx\n", CPUP);
  203. printk(KERN_EMERG "TBR: %08x\n", TBR);
  204. printk(KERN_EMERG "DEAR: %08x\n", DEAR);
  205. printk(KERN_EMERG "sISR: %08x\n", sISR);
  206. printk(KERN_EMERG "NMICR: %04hx\n", NMICR);
  207. printk(KERN_EMERG "BCBERR: %08x\n", BCBERR);
  208. printk(KERN_EMERG "BCBEAR: %08x\n", BCBEAR);
  209. printk(KERN_EMERG "MMUFCR: %08x\n", MMUFCR);
  210. printk(KERN_EMERG "IPTEU : %08x IPTEL2: %08x\n", IPTEU, IPTEL2);
  211. printk(KERN_EMERG "DPTEU: %08x DPTEL2: %08x\n", DPTEU, DPTEL2);
  212. }
  213. /*
  214. * dump the registers and the stack
  215. */
  216. void show_registers(struct pt_regs *regs)
  217. {
  218. unsigned long sp;
  219. int i;
  220. show_registers_only(regs);
  221. if (!user_mode(regs))
  222. sp = (unsigned long) regs + sizeof(*regs);
  223. else
  224. sp = regs->sp;
  225. /* when in-kernel, we also print out the stack and code at the
  226. * time of the fault..
  227. */
  228. if (!user_mode(regs)) {
  229. printk(KERN_EMERG "\n");
  230. show_stack(current, (unsigned long *) sp);
  231. #if 0
  232. printk(KERN_EMERG "\nCode: ");
  233. if (regs->pc < PAGE_OFFSET)
  234. goto bad;
  235. for (i = 0; i < 20; i++) {
  236. unsigned char c;
  237. if (__get_user(c, &((unsigned char *) regs->pc)[i]))
  238. goto bad;
  239. printk("%02x ", c);
  240. }
  241. #else
  242. i = 0;
  243. #endif
  244. }
  245. printk("\n");
  246. return;
  247. #if 0
  248. bad:
  249. printk(KERN_EMERG " Bad PC value.");
  250. break;
  251. #endif
  252. }
  253. /*
  254. *
  255. */
  256. void show_trace_task(struct task_struct *tsk)
  257. {
  258. unsigned long sp = tsk->thread.sp;
  259. /* User space on another CPU? */
  260. if ((sp ^ (unsigned long) tsk) & (PAGE_MASK << 1))
  261. return;
  262. show_trace((unsigned long *) sp);
  263. }
  264. /*
  265. * note the untimely death of part of the kernel
  266. */
  267. void die(const char *str, struct pt_regs *regs, enum exception_code code)
  268. {
  269. console_verbose();
  270. spin_lock_irq(&die_lock);
  271. printk(KERN_EMERG "\n%s: %04x\n",
  272. str, code & 0xffff);
  273. show_registers(regs);
  274. if (regs->pc >= 0x02000000 && regs->pc < 0x04000000 &&
  275. (regs->epsw & (EPSW_IM | EPSW_IE)) != (EPSW_IM | EPSW_IE)) {
  276. printk(KERN_EMERG "Exception in usermode interrupt handler\n");
  277. printk(KERN_EMERG "\nPlease connect to kernel debugger !!\n");
  278. asm volatile ("0: bra 0b");
  279. }
  280. spin_unlock_irq(&die_lock);
  281. do_exit(SIGSEGV);
  282. }
  283. /*
  284. * see if there's a fixup handler we can force a jump to when an exception
  285. * happens due to something kernel code did
  286. */
  287. int die_if_no_fixup(const char *str, struct pt_regs *regs,
  288. enum exception_code code)
  289. {
  290. if (user_mode(regs))
  291. return 0;
  292. peripheral_leds_display_exception(code);
  293. switch (code) {
  294. /* see if we can fixup the kernel accessing memory */
  295. case EXCEP_ITLBMISS:
  296. case EXCEP_DTLBMISS:
  297. case EXCEP_IAERROR:
  298. case EXCEP_DAERROR:
  299. case EXCEP_MEMERR:
  300. case EXCEP_MISALIGN:
  301. case EXCEP_BUSERROR:
  302. case EXCEP_ILLDATACC:
  303. case EXCEP_IOINSACC:
  304. case EXCEP_PRIVINSACC:
  305. case EXCEP_PRIVDATACC:
  306. case EXCEP_DATINSACC:
  307. if (fixup_exception(regs))
  308. return 1;
  309. case EXCEP_UNIMPINS:
  310. if (regs->pc && *(uint8_t *)regs->pc == 0xff)
  311. if (notify_die(DIE_BREAKPOINT, str, regs, code, 0, 0))
  312. return 1;
  313. break;
  314. default:
  315. break;
  316. }
  317. /* see if gdbstub wants to deal with it */
  318. #ifdef CONFIG_GDBSTUB
  319. if (gdbstub_intercept(regs, code))
  320. return 1;
  321. #endif
  322. if (notify_die(DIE_GPF, str, regs, code, 0, 0))
  323. return 1;
  324. /* make the process die as the last resort */
  325. die(str, regs, code);
  326. }
  327. /*
  328. * handle unsupported syscall instructions (syscall 1-15)
  329. */
  330. static asmlinkage void unsupported_syscall(struct pt_regs *regs,
  331. enum exception_code code)
  332. {
  333. struct task_struct *tsk = current;
  334. siginfo_t info;
  335. /* catch a kernel BUG() */
  336. if (code == EXCEP_SYSCALL15 && !user_mode(regs)) {
  337. if (report_bug(regs->pc, regs) == BUG_TRAP_TYPE_BUG) {
  338. #ifdef CONFIG_GDBSTUB
  339. gdbstub_intercept(regs, code);
  340. #endif
  341. }
  342. }
  343. regs->pc -= 2; /* syscall return addr is _after_ the instruction */
  344. die_if_no_fixup("An unsupported syscall insn was used by the kernel\n",
  345. regs, code);
  346. info.si_signo = SIGILL;
  347. info.si_errno = ENOSYS;
  348. info.si_code = ILL_ILLTRP;
  349. info.si_addr = (void *) regs->pc;
  350. force_sig_info(SIGILL, &info, tsk);
  351. }
  352. /*
  353. * display the register file when the stack pointer gets clobbered
  354. */
  355. asmlinkage void do_double_fault(struct pt_regs *regs)
  356. {
  357. struct task_struct *tsk = current;
  358. strcpy(tsk->comm, "emergency tsk");
  359. tsk->pid = 0;
  360. console_verbose();
  361. printk(KERN_EMERG "--- double fault ---\n");
  362. show_registers(regs);
  363. }
  364. /*
  365. * asynchronous bus error (external, usually I/O DMA)
  366. */
  367. asmlinkage void io_bus_error(u32 bcberr, u32 bcbear, struct pt_regs *regs)
  368. {
  369. console_verbose();
  370. printk(KERN_EMERG "Asynchronous I/O Bus Error\n");
  371. printk(KERN_EMERG "==========================\n");
  372. if (bcberr & BCBERR_BEME)
  373. printk(KERN_EMERG "- Multiple recorded errors\n");
  374. printk(KERN_EMERG "- Faulting Buses:%s%s%s\n",
  375. bcberr & BCBERR_BEMR_CI ? " CPU-Ins-Fetch" : "",
  376. bcberr & BCBERR_BEMR_CD ? " CPU-Data" : "",
  377. bcberr & BCBERR_BEMR_DMA ? " DMA" : "");
  378. printk(KERN_EMERG "- %s %s access made to %s at address %08x\n",
  379. bcberr & BCBERR_BEBST ? "Burst" : "Single",
  380. bcberr & BCBERR_BERW ? "Read" : "Write",
  381. bcberr & BCBERR_BESB_MON ? "Monitor Space" :
  382. bcberr & BCBERR_BESB_IO ? "Internal CPU I/O Space" :
  383. bcberr & BCBERR_BESB_EX ? "External I/O Bus" :
  384. bcberr & BCBERR_BESB_OPEX ? "External Memory Bus" :
  385. "On Chip Memory",
  386. bcbear
  387. );
  388. printk(KERN_EMERG "- Detected by the %s\n",
  389. bcberr&BCBERR_BESD ? "Bus Control Unit" : "Slave Bus");
  390. #ifdef CONFIG_PCI
  391. #define BRIDGEREGB(X) (*(volatile __u8 *)(0xBE040000 + (X)))
  392. #define BRIDGEREGW(X) (*(volatile __u16 *)(0xBE040000 + (X)))
  393. #define BRIDGEREGL(X) (*(volatile __u32 *)(0xBE040000 + (X)))
  394. printk(KERN_EMERG "- PCI Memory Paging Reg: %08x\n",
  395. *(volatile __u32 *) (0xBFFFFFF4));
  396. printk(KERN_EMERG "- PCI Bridge Base Address 0: %08x\n",
  397. BRIDGEREGL(PCI_BASE_ADDRESS_0));
  398. printk(KERN_EMERG "- PCI Bridge AMPCI Base Address: %08x\n",
  399. BRIDGEREGL(0x48));
  400. printk(KERN_EMERG "- PCI Bridge Command: %04hx\n",
  401. BRIDGEREGW(PCI_COMMAND));
  402. printk(KERN_EMERG "- PCI Bridge Status: %04hx\n",
  403. BRIDGEREGW(PCI_STATUS));
  404. printk(KERN_EMERG "- PCI Bridge Int Status: %08hx\n",
  405. BRIDGEREGL(0x4c));
  406. #endif
  407. printk(KERN_EMERG "\n");
  408. show_registers(regs);
  409. panic("Halted due to asynchronous I/O Bus Error\n");
  410. }
  411. /*
  412. * handle an exception for which a handler has not yet been installed
  413. */
  414. asmlinkage void uninitialised_exception(struct pt_regs *regs,
  415. enum exception_code code)
  416. {
  417. /* see if gdbstub wants to deal with it */
  418. #ifdef CONFIG_GDBSTUB
  419. if (gdbstub_intercept(regs, code))
  420. return;
  421. #endif
  422. peripheral_leds_display_exception(code);
  423. printk(KERN_EMERG "Uninitialised Exception 0x%04x\n", code & 0xFFFF);
  424. show_registers(regs);
  425. for (;;)
  426. continue;
  427. }
  428. /*
  429. * set an interrupt stub to jump to a handler
  430. * ! NOTE: this does *not* flush the caches
  431. */
  432. void __init __set_intr_stub(enum exception_code code, void *handler)
  433. {
  434. unsigned long addr;
  435. u8 *vector = (u8 *)(CONFIG_INTERRUPT_VECTOR_BASE + code);
  436. addr = (unsigned long) handler - (unsigned long) vector;
  437. vector[0] = 0xdc; /* JMP handler */
  438. vector[1] = addr;
  439. vector[2] = addr >> 8;
  440. vector[3] = addr >> 16;
  441. vector[4] = addr >> 24;
  442. vector[5] = 0xcb;
  443. vector[6] = 0xcb;
  444. vector[7] = 0xcb;
  445. }
  446. /*
  447. * set an interrupt stub to jump to a handler
  448. */
  449. void __init set_intr_stub(enum exception_code code, void *handler)
  450. {
  451. unsigned long addr;
  452. u8 *vector = (u8 *)(CONFIG_INTERRUPT_VECTOR_BASE + code);
  453. unsigned long flags;
  454. addr = (unsigned long) handler - (unsigned long) vector;
  455. flags = arch_local_cli_save();
  456. vector[0] = 0xdc; /* JMP handler */
  457. vector[1] = addr;
  458. vector[2] = addr >> 8;
  459. vector[3] = addr >> 16;
  460. vector[4] = addr >> 24;
  461. vector[5] = 0xcb;
  462. vector[6] = 0xcb;
  463. vector[7] = 0xcb;
  464. arch_local_irq_restore(flags);
  465. #ifndef CONFIG_MN10300_CACHE_SNOOP
  466. mn10300_dcache_flush_inv();
  467. mn10300_icache_inv();
  468. #endif
  469. }
  470. /*
  471. * initialise the exception table
  472. */
  473. void __init trap_init(void)
  474. {
  475. set_excp_vector(EXCEP_TRAP, trap);
  476. set_excp_vector(EXCEP_ISTEP, istep);
  477. set_excp_vector(EXCEP_IBREAK, ibreak);
  478. set_excp_vector(EXCEP_OBREAK, obreak);
  479. set_excp_vector(EXCEP_PRIVINS, priv_op);
  480. set_excp_vector(EXCEP_UNIMPINS, invalid_op);
  481. set_excp_vector(EXCEP_UNIMPEXINS, invalid_exop);
  482. set_excp_vector(EXCEP_MEMERR, mem_error);
  483. set_excp_vector(EXCEP_MISALIGN, misalignment);
  484. set_excp_vector(EXCEP_BUSERROR, bus_error);
  485. set_excp_vector(EXCEP_ILLINSACC, insn_acc_error);
  486. set_excp_vector(EXCEP_ILLDATACC, data_acc_error);
  487. set_excp_vector(EXCEP_IOINSACC, insn_acc_error);
  488. set_excp_vector(EXCEP_PRIVINSACC, insn_acc_error);
  489. set_excp_vector(EXCEP_PRIVDATACC, data_acc_error);
  490. set_excp_vector(EXCEP_DATINSACC, insn_acc_error);
  491. set_excp_vector(EXCEP_FPU_UNIMPINS, fpu_invalid_op);
  492. set_excp_vector(EXCEP_FPU_OPERATION, fpu_exception);
  493. set_excp_vector(EXCEP_NMI, nmi);
  494. set_excp_vector(EXCEP_SYSCALL1, unsupported_syscall);
  495. set_excp_vector(EXCEP_SYSCALL2, unsupported_syscall);
  496. set_excp_vector(EXCEP_SYSCALL3, unsupported_syscall);
  497. set_excp_vector(EXCEP_SYSCALL4, unsupported_syscall);
  498. set_excp_vector(EXCEP_SYSCALL5, unsupported_syscall);
  499. set_excp_vector(EXCEP_SYSCALL6, unsupported_syscall);
  500. set_excp_vector(EXCEP_SYSCALL7, unsupported_syscall);
  501. set_excp_vector(EXCEP_SYSCALL8, unsupported_syscall);
  502. set_excp_vector(EXCEP_SYSCALL9, unsupported_syscall);
  503. set_excp_vector(EXCEP_SYSCALL10, unsupported_syscall);
  504. set_excp_vector(EXCEP_SYSCALL11, unsupported_syscall);
  505. set_excp_vector(EXCEP_SYSCALL12, unsupported_syscall);
  506. set_excp_vector(EXCEP_SYSCALL13, unsupported_syscall);
  507. set_excp_vector(EXCEP_SYSCALL14, unsupported_syscall);
  508. set_excp_vector(EXCEP_SYSCALL15, unsupported_syscall);
  509. }
  510. /*
  511. * determine if a program counter value is a valid bug address
  512. */
  513. int is_valid_bugaddr(unsigned long pc)
  514. {
  515. return pc >= PAGE_OFFSET;
  516. }