traps.c 10 KB

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