traps.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /* traps.c: high-level exception handler for FR-V
  2. *
  3. * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/sched.h>
  13. #include <linux/signal.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/types.h>
  17. #include <linux/user.h>
  18. #include <linux/string.h>
  19. #include <linux/linkage.h>
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <asm/setup.h>
  23. #include <asm/fpu.h>
  24. #include <asm/system.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/siginfo.h>
  28. #include <asm/unaligned.h>
  29. void show_backtrace(struct pt_regs *, unsigned long);
  30. extern asmlinkage void __break_hijack_kernel_event(void);
  31. /*****************************************************************************/
  32. /*
  33. * instruction access error
  34. */
  35. asmlinkage void insn_access_error(unsigned long esfr1, unsigned long epcr0, unsigned long esr0)
  36. {
  37. siginfo_t info;
  38. die_if_kernel("-- Insn Access Error --\n"
  39. "EPCR0 : %08lx\n"
  40. "ESR0 : %08lx\n",
  41. epcr0, esr0);
  42. info.si_signo = SIGSEGV;
  43. info.si_code = SEGV_ACCERR;
  44. info.si_errno = 0;
  45. info.si_addr = (void *) ((epcr0 & EPCR0_V) ? (epcr0 & EPCR0_PC) : __frame->pc);
  46. force_sig_info(info.si_signo, &info, current);
  47. } /* end insn_access_error() */
  48. /*****************************************************************************/
  49. /*
  50. * handler for:
  51. * - illegal instruction
  52. * - privileged instruction
  53. * - unsupported trap
  54. * - debug exceptions
  55. */
  56. asmlinkage void illegal_instruction(unsigned long esfr1, unsigned long epcr0, unsigned long esr0)
  57. {
  58. siginfo_t info;
  59. die_if_kernel("-- Illegal Instruction --\n"
  60. "EPCR0 : %08lx\n"
  61. "ESR0 : %08lx\n"
  62. "ESFR1 : %08lx\n",
  63. epcr0, esr0, esfr1);
  64. info.si_errno = 0;
  65. info.si_addr = (void *) ((epcr0 & EPCR0_PC) ? (epcr0 & EPCR0_PC) : __frame->pc);
  66. switch (__frame->tbr & TBR_TT) {
  67. case TBR_TT_ILLEGAL_INSTR:
  68. info.si_signo = SIGILL;
  69. info.si_code = ILL_ILLOPC;
  70. break;
  71. case TBR_TT_PRIV_INSTR:
  72. info.si_signo = SIGILL;
  73. info.si_code = ILL_PRVOPC;
  74. break;
  75. case TBR_TT_TRAP2 ... TBR_TT_TRAP126:
  76. info.si_signo = SIGILL;
  77. info.si_code = ILL_ILLTRP;
  78. break;
  79. /* GDB uses "tira gr0, #1" as a breakpoint instruction. */
  80. case TBR_TT_TRAP1:
  81. case TBR_TT_BREAK:
  82. info.si_signo = SIGTRAP;
  83. info.si_code =
  84. (__frame->__status & REG__STATUS_STEPPED) ? TRAP_TRACE : TRAP_BRKPT;
  85. break;
  86. }
  87. force_sig_info(info.si_signo, &info, current);
  88. } /* end illegal_instruction() */
  89. /*****************************************************************************/
  90. /*
  91. *
  92. */
  93. asmlinkage void media_exception(unsigned long msr0, unsigned long msr1)
  94. {
  95. siginfo_t info;
  96. die_if_kernel("-- Media Exception --\n"
  97. "MSR0 : %08lx\n"
  98. "MSR1 : %08lx\n",
  99. msr0, msr1);
  100. info.si_signo = SIGFPE;
  101. info.si_code = FPE_MDAOVF;
  102. info.si_errno = 0;
  103. info.si_addr = (void *) __frame->pc;
  104. force_sig_info(info.si_signo, &info, current);
  105. } /* end media_exception() */
  106. /*****************************************************************************/
  107. /*
  108. * instruction or data access exception
  109. */
  110. asmlinkage void memory_access_exception(unsigned long esr0,
  111. unsigned long ear0,
  112. unsigned long epcr0)
  113. {
  114. siginfo_t info;
  115. #ifdef CONFIG_MMU
  116. unsigned long fixup;
  117. if ((esr0 & ESRx_EC) == ESRx_EC_DATA_ACCESS)
  118. if (handle_misalignment(esr0, ear0, epcr0) == 0)
  119. return;
  120. if ((fixup = search_exception_table(__frame->pc)) != 0) {
  121. __frame->pc = fixup;
  122. return;
  123. }
  124. #endif
  125. die_if_kernel("-- Memory Access Exception --\n"
  126. "ESR0 : %08lx\n"
  127. "EAR0 : %08lx\n"
  128. "EPCR0 : %08lx\n",
  129. esr0, ear0, epcr0);
  130. info.si_signo = SIGSEGV;
  131. info.si_code = SEGV_ACCERR;
  132. info.si_errno = 0;
  133. info.si_addr = NULL;
  134. if ((esr0 & (ESRx_VALID | ESR0_EAV)) == (ESRx_VALID | ESR0_EAV))
  135. info.si_addr = (void *) ear0;
  136. force_sig_info(info.si_signo, &info, current);
  137. } /* end memory_access_exception() */
  138. /*****************************************************************************/
  139. /*
  140. * data access error
  141. * - double-word data load from CPU control area (0xFExxxxxx)
  142. * - read performed on inactive or self-refreshing SDRAM
  143. * - error notification from slave device
  144. * - misaligned address
  145. * - access to out of bounds memory region
  146. * - user mode accessing privileged memory region
  147. * - write to R/O memory region
  148. */
  149. asmlinkage void data_access_error(unsigned long esfr1, unsigned long esr15, unsigned long ear15)
  150. {
  151. siginfo_t info;
  152. die_if_kernel("-- Data Access Error --\n"
  153. "ESR15 : %08lx\n"
  154. "EAR15 : %08lx\n",
  155. esr15, ear15);
  156. info.si_signo = SIGSEGV;
  157. info.si_code = SEGV_ACCERR;
  158. info.si_errno = 0;
  159. info.si_addr = (void *)
  160. (((esr15 & (ESRx_VALID|ESR15_EAV)) == (ESRx_VALID|ESR15_EAV)) ? ear15 : 0);
  161. force_sig_info(info.si_signo, &info, current);
  162. } /* end data_access_error() */
  163. /*****************************************************************************/
  164. /*
  165. * data store error - should only happen if accessing inactive or self-refreshing SDRAM
  166. */
  167. asmlinkage void data_store_error(unsigned long esfr1, unsigned long esr15)
  168. {
  169. die_if_kernel("-- Data Store Error --\n"
  170. "ESR15 : %08lx\n",
  171. esr15);
  172. BUG();
  173. } /* end data_store_error() */
  174. /*****************************************************************************/
  175. /*
  176. *
  177. */
  178. asmlinkage void division_exception(unsigned long esfr1, unsigned long esr0, unsigned long isr)
  179. {
  180. siginfo_t info;
  181. die_if_kernel("-- Division Exception --\n"
  182. "ESR0 : %08lx\n"
  183. "ISR : %08lx\n",
  184. esr0, isr);
  185. info.si_signo = SIGFPE;
  186. info.si_code = FPE_INTDIV;
  187. info.si_errno = 0;
  188. info.si_addr = (void *) __frame->pc;
  189. force_sig_info(info.si_signo, &info, current);
  190. } /* end division_exception() */
  191. /*****************************************************************************/
  192. /*
  193. *
  194. */
  195. asmlinkage void compound_exception(unsigned long esfr1,
  196. unsigned long esr0, unsigned long esr14, unsigned long esr15,
  197. unsigned long msr0, unsigned long msr1)
  198. {
  199. die_if_kernel("-- Compound Exception --\n"
  200. "ESR0 : %08lx\n"
  201. "ESR15 : %08lx\n"
  202. "ESR15 : %08lx\n"
  203. "MSR0 : %08lx\n"
  204. "MSR1 : %08lx\n",
  205. esr0, esr14, esr15, msr0, msr1);
  206. BUG();
  207. } /* end compound_exception() */
  208. /*****************************************************************************/
  209. /*
  210. * The architecture-independent backtrace generator
  211. */
  212. void dump_stack(void)
  213. {
  214. show_stack(NULL, NULL);
  215. }
  216. EXPORT_SYMBOL(dump_stack);
  217. void show_stack(struct task_struct *task, unsigned long *sp)
  218. {
  219. }
  220. void show_trace_task(struct task_struct *tsk)
  221. {
  222. printk("CONTEXT: stack=0x%lx frame=0x%p LR=0x%lx RET=0x%lx\n",
  223. tsk->thread.sp, tsk->thread.frame, tsk->thread.lr, tsk->thread.sched_lr);
  224. }
  225. static const char *regnames[] = {
  226. "PSR ", "ISR ", "CCR ", "CCCR",
  227. "LR ", "LCR ", "PC ", "_stt",
  228. "sys ", "GR8*", "GNE0", "GNE1",
  229. "IACH", "IACL",
  230. "TBR ", "SP ", "FP ", "GR3 ",
  231. "GR4 ", "GR5 ", "GR6 ", "GR7 ",
  232. "GR8 ", "GR9 ", "GR10", "GR11",
  233. "GR12", "GR13", "GR14", "GR15",
  234. "GR16", "GR17", "GR18", "GR19",
  235. "GR20", "GR21", "GR22", "GR23",
  236. "GR24", "GR25", "GR26", "GR27",
  237. "EFRM", "CURR", "GR30", "BFRM"
  238. };
  239. void show_regs(struct pt_regs *regs)
  240. {
  241. uint32_t *reg;
  242. int loop;
  243. printk("\n");
  244. printk("Frame: @%08x [%s]\n",
  245. (uint32_t) regs,
  246. regs->psr & PSR_S ? "kernel" : "user");
  247. reg = (uint32_t *) regs;
  248. for (loop = 0; loop < REG__END; loop++) {
  249. printk("%s %08x", regnames[loop + 0], reg[loop + 0]);
  250. if (loop == REG__END - 1 || loop % 5 == 4)
  251. printk("\n");
  252. else
  253. printk(" | ");
  254. }
  255. printk("Process %s (pid: %d)\n", current->comm, current->pid);
  256. }
  257. void die_if_kernel(const char *str, ...)
  258. {
  259. char buffer[256];
  260. va_list va;
  261. if (user_mode(__frame))
  262. return;
  263. va_start(va, str);
  264. vsprintf(buffer, str, va);
  265. va_end(va);
  266. console_verbose();
  267. printk("\n===================================\n");
  268. printk("%s\n", buffer);
  269. show_backtrace(__frame, 0);
  270. __break_hijack_kernel_event();
  271. do_exit(SIGSEGV);
  272. }
  273. /*****************************************************************************/
  274. /*
  275. * dump the contents of an exception frame
  276. */
  277. static void show_backtrace_regs(struct pt_regs *frame)
  278. {
  279. uint32_t *reg;
  280. int loop;
  281. /* print the registers for this frame */
  282. printk("<-- %s Frame: @%p -->\n",
  283. frame->psr & PSR_S ? "Kernel Mode" : "User Mode",
  284. frame);
  285. reg = (uint32_t *) frame;
  286. for (loop = 0; loop < REG__END; loop++) {
  287. printk("%s %08x", regnames[loop + 0], reg[loop + 0]);
  288. if (loop == REG__END - 1 || loop % 5 == 4)
  289. printk("\n");
  290. else
  291. printk(" | ");
  292. }
  293. printk("--------\n");
  294. } /* end show_backtrace_regs() */
  295. /*****************************************************************************/
  296. /*
  297. * generate a backtrace of the kernel stack
  298. */
  299. void show_backtrace(struct pt_regs *frame, unsigned long sp)
  300. {
  301. struct pt_regs *frame0;
  302. unsigned long tos = 0, stop = 0, base;
  303. int format;
  304. base = ((((unsigned long) frame) + 8191) & ~8191) - sizeof(struct user_context);
  305. frame0 = (struct pt_regs *) base;
  306. if (sp) {
  307. tos = sp;
  308. stop = (unsigned long) frame;
  309. }
  310. printk("\nProcess %s (pid: %d)\n\n", current->comm, current->pid);
  311. for (;;) {
  312. /* dump stack segment between frames */
  313. //printk("%08lx -> %08lx\n", tos, stop);
  314. format = 0;
  315. while (tos < stop) {
  316. if (format == 0)
  317. printk(" %04lx :", tos & 0xffff);
  318. printk(" %08lx", *(unsigned long *) tos);
  319. tos += 4;
  320. format++;
  321. if (format == 8) {
  322. printk("\n");
  323. format = 0;
  324. }
  325. }
  326. if (format > 0)
  327. printk("\n");
  328. /* dump frame 0 outside of the loop */
  329. if (frame == frame0)
  330. break;
  331. tos = frame->sp;
  332. if (((unsigned long) frame) + sizeof(*frame) != tos) {
  333. printk("-- TOS %08lx does not follow frame %p --\n",
  334. tos, frame);
  335. break;
  336. }
  337. show_backtrace_regs(frame);
  338. /* dump the stack between this frame and the next */
  339. stop = (unsigned long) frame->next_frame;
  340. if (stop != base &&
  341. (stop < tos ||
  342. stop > base ||
  343. (stop < base && stop + sizeof(*frame) > base) ||
  344. stop & 3)) {
  345. printk("-- next_frame %08lx is invalid (range %08lx-%08lx) --\n",
  346. stop, tos, base);
  347. break;
  348. }
  349. /* move to next frame */
  350. frame = frame->next_frame;
  351. }
  352. /* we can always dump frame 0, even if the rest of the stack is corrupt */
  353. show_backtrace_regs(frame0);
  354. } /* end show_backtrace() */
  355. /*****************************************************************************/
  356. /*
  357. * initialise traps
  358. */
  359. void __init trap_init (void)
  360. {
  361. } /* end trap_init() */