traps.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  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. #include <linux/module.h>
  12. #include <linux/ptrace.h>
  13. #include <linux/kallsyms.h>
  14. #include <linux/bug.h>
  15. #include <asm/soc.h>
  16. #include <asm/special_insns.h>
  17. #include <asm/traps.h>
  18. int (*c6x_nmi_handler)(struct pt_regs *regs);
  19. void __init trap_init(void)
  20. {
  21. ack_exception(EXCEPT_TYPE_NXF);
  22. ack_exception(EXCEPT_TYPE_EXC);
  23. ack_exception(EXCEPT_TYPE_IXF);
  24. ack_exception(EXCEPT_TYPE_SXF);
  25. enable_exception();
  26. }
  27. void show_regs(struct pt_regs *regs)
  28. {
  29. pr_err("\n");
  30. pr_err("PC: %08lx SP: %08lx\n", regs->pc, regs->sp);
  31. pr_err("Status: %08lx ORIG_A4: %08lx\n", regs->csr, regs->orig_a4);
  32. pr_err("A0: %08lx B0: %08lx\n", regs->a0, regs->b0);
  33. pr_err("A1: %08lx B1: %08lx\n", regs->a1, regs->b1);
  34. pr_err("A2: %08lx B2: %08lx\n", regs->a2, regs->b2);
  35. pr_err("A3: %08lx B3: %08lx\n", regs->a3, regs->b3);
  36. pr_err("A4: %08lx B4: %08lx\n", regs->a4, regs->b4);
  37. pr_err("A5: %08lx B5: %08lx\n", regs->a5, regs->b5);
  38. pr_err("A6: %08lx B6: %08lx\n", regs->a6, regs->b6);
  39. pr_err("A7: %08lx B7: %08lx\n", regs->a7, regs->b7);
  40. pr_err("A8: %08lx B8: %08lx\n", regs->a8, regs->b8);
  41. pr_err("A9: %08lx B9: %08lx\n", regs->a9, regs->b9);
  42. pr_err("A10: %08lx B10: %08lx\n", regs->a10, regs->b10);
  43. pr_err("A11: %08lx B11: %08lx\n", regs->a11, regs->b11);
  44. pr_err("A12: %08lx B12: %08lx\n", regs->a12, regs->b12);
  45. pr_err("A13: %08lx B13: %08lx\n", regs->a13, regs->b13);
  46. pr_err("A14: %08lx B14: %08lx\n", regs->a14, regs->dp);
  47. pr_err("A15: %08lx B15: %08lx\n", regs->a15, regs->sp);
  48. pr_err("A16: %08lx B16: %08lx\n", regs->a16, regs->b16);
  49. pr_err("A17: %08lx B17: %08lx\n", regs->a17, regs->b17);
  50. pr_err("A18: %08lx B18: %08lx\n", regs->a18, regs->b18);
  51. pr_err("A19: %08lx B19: %08lx\n", regs->a19, regs->b19);
  52. pr_err("A20: %08lx B20: %08lx\n", regs->a20, regs->b20);
  53. pr_err("A21: %08lx B21: %08lx\n", regs->a21, regs->b21);
  54. pr_err("A22: %08lx B22: %08lx\n", regs->a22, regs->b22);
  55. pr_err("A23: %08lx B23: %08lx\n", regs->a23, regs->b23);
  56. pr_err("A24: %08lx B24: %08lx\n", regs->a24, regs->b24);
  57. pr_err("A25: %08lx B25: %08lx\n", regs->a25, regs->b25);
  58. pr_err("A26: %08lx B26: %08lx\n", regs->a26, regs->b26);
  59. pr_err("A27: %08lx B27: %08lx\n", regs->a27, regs->b27);
  60. pr_err("A28: %08lx B28: %08lx\n", regs->a28, regs->b28);
  61. pr_err("A29: %08lx B29: %08lx\n", regs->a29, regs->b29);
  62. pr_err("A30: %08lx B30: %08lx\n", regs->a30, regs->b30);
  63. pr_err("A31: %08lx B31: %08lx\n", regs->a31, regs->b31);
  64. }
  65. void dump_stack(void)
  66. {
  67. unsigned long stack;
  68. show_stack(current, &stack);
  69. }
  70. EXPORT_SYMBOL(dump_stack);
  71. void die(char *str, struct pt_regs *fp, int nr)
  72. {
  73. console_verbose();
  74. pr_err("%s: %08x\n", str, nr);
  75. show_regs(fp);
  76. pr_err("Process %s (pid: %d, stackpage=%08lx)\n",
  77. current->comm, current->pid, (PAGE_SIZE +
  78. (unsigned long) current));
  79. dump_stack();
  80. while (1)
  81. ;
  82. }
  83. static void die_if_kernel(char *str, struct pt_regs *fp, int nr)
  84. {
  85. if (user_mode(fp))
  86. return;
  87. die(str, fp, nr);
  88. }
  89. /* Internal exceptions */
  90. static struct exception_info iexcept_table[10] = {
  91. { "Oops - instruction fetch", SIGBUS, BUS_ADRERR },
  92. { "Oops - fetch packet", SIGBUS, BUS_ADRERR },
  93. { "Oops - execute packet", SIGILL, ILL_ILLOPC },
  94. { "Oops - undefined instruction", SIGILL, ILL_ILLOPC },
  95. { "Oops - resource conflict", SIGILL, ILL_ILLOPC },
  96. { "Oops - resource access", SIGILL, ILL_PRVREG },
  97. { "Oops - privilege", SIGILL, ILL_PRVOPC },
  98. { "Oops - loops buffer", SIGILL, ILL_ILLOPC },
  99. { "Oops - software exception", SIGILL, ILL_ILLTRP },
  100. { "Oops - unknown exception", SIGILL, ILL_ILLOPC }
  101. };
  102. /* External exceptions */
  103. static struct exception_info eexcept_table[128] = {
  104. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  105. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  106. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  107. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  108. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  109. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  110. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  111. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  112. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  113. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  114. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  115. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  116. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  117. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  118. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  119. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  120. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  121. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  122. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  123. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  124. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  125. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  126. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  127. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  128. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  129. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  130. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  131. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  132. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  133. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  134. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  135. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  136. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  137. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  138. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  139. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  140. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  141. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  142. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  143. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  144. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  145. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  146. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  147. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  148. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  149. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  150. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  151. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  152. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  153. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  154. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  155. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  156. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  157. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  158. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  159. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  160. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  161. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  162. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  163. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  164. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  165. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  166. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  167. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  168. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  169. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  170. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  171. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  172. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  173. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  174. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  175. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  176. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  177. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  178. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  179. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  180. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  181. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  182. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  183. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  184. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  185. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  186. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  187. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  188. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  189. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  190. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  191. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  192. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  193. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  194. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  195. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  196. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  197. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  198. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  199. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  200. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  201. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  202. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  203. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  204. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  205. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  206. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  207. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  208. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  209. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  210. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  211. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  212. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  213. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  214. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  215. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  216. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  217. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  218. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  219. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  220. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  221. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  222. { "Oops - external exception", SIGBUS, BUS_ADRERR },
  223. { "Oops - CPU memory protection fault", SIGSEGV, SEGV_ACCERR },
  224. { "Oops - CPU memory protection fault in L1P", SIGSEGV, SEGV_ACCERR },
  225. { "Oops - DMA memory protection fault in L1P", SIGSEGV, SEGV_ACCERR },
  226. { "Oops - CPU memory protection fault in L1D", SIGSEGV, SEGV_ACCERR },
  227. { "Oops - DMA memory protection fault in L1D", SIGSEGV, SEGV_ACCERR },
  228. { "Oops - CPU memory protection fault in L2", SIGSEGV, SEGV_ACCERR },
  229. { "Oops - DMA memory protection fault in L2", SIGSEGV, SEGV_ACCERR },
  230. { "Oops - EMC CPU memory protection fault", SIGSEGV, SEGV_ACCERR },
  231. { "Oops - EMC bus error", SIGBUS, BUS_ADRERR }
  232. };
  233. static void do_trap(struct exception_info *except_info, struct pt_regs *regs)
  234. {
  235. unsigned long addr = instruction_pointer(regs);
  236. siginfo_t info;
  237. if (except_info->code != TRAP_BRKPT)
  238. pr_err("TRAP: %s PC[0x%lx] signo[%d] code[%d]\n",
  239. except_info->kernel_str, regs->pc,
  240. except_info->signo, except_info->code);
  241. die_if_kernel(except_info->kernel_str, regs, addr);
  242. info.si_signo = except_info->signo;
  243. info.si_errno = 0;
  244. info.si_code = except_info->code;
  245. info.si_addr = (void __user *)addr;
  246. force_sig_info(except_info->signo, &info, current);
  247. }
  248. /*
  249. * Process an internal exception (non maskable)
  250. */
  251. static int process_iexcept(struct pt_regs *regs)
  252. {
  253. unsigned int iexcept_report = get_iexcept();
  254. unsigned int iexcept_num;
  255. ack_exception(EXCEPT_TYPE_IXF);
  256. pr_err("IEXCEPT: PC[0x%lx]\n", regs->pc);
  257. while (iexcept_report) {
  258. iexcept_num = __ffs(iexcept_report);
  259. iexcept_report &= ~(1 << iexcept_num);
  260. set_iexcept(iexcept_report);
  261. if (*(unsigned int *)regs->pc == BKPT_OPCODE) {
  262. /* This is a breakpoint */
  263. struct exception_info bkpt_exception = {
  264. "Oops - undefined instruction",
  265. SIGTRAP, TRAP_BRKPT
  266. };
  267. do_trap(&bkpt_exception, regs);
  268. iexcept_report &= ~(0xFF);
  269. set_iexcept(iexcept_report);
  270. continue;
  271. }
  272. do_trap(&iexcept_table[iexcept_num], regs);
  273. }
  274. return 0;
  275. }
  276. /*
  277. * Process an external exception (maskable)
  278. */
  279. static void process_eexcept(struct pt_regs *regs)
  280. {
  281. int evt;
  282. pr_err("EEXCEPT: PC[0x%lx]\n", regs->pc);
  283. while ((evt = soc_get_exception()) >= 0)
  284. do_trap(&eexcept_table[evt], regs);
  285. ack_exception(EXCEPT_TYPE_EXC);
  286. }
  287. /*
  288. * Main exception processing
  289. */
  290. asmlinkage int process_exception(struct pt_regs *regs)
  291. {
  292. unsigned int type;
  293. unsigned int type_num;
  294. unsigned int ie_num = 9; /* default is unknown exception */
  295. while ((type = get_except_type()) != 0) {
  296. type_num = fls(type) - 1;
  297. switch (type_num) {
  298. case EXCEPT_TYPE_NXF:
  299. ack_exception(EXCEPT_TYPE_NXF);
  300. if (c6x_nmi_handler)
  301. (c6x_nmi_handler)(regs);
  302. else
  303. pr_alert("NMI interrupt!\n");
  304. break;
  305. case EXCEPT_TYPE_IXF:
  306. if (process_iexcept(regs))
  307. return 1;
  308. break;
  309. case EXCEPT_TYPE_EXC:
  310. process_eexcept(regs);
  311. break;
  312. case EXCEPT_TYPE_SXF:
  313. ie_num = 8;
  314. default:
  315. ack_exception(type_num);
  316. do_trap(&iexcept_table[ie_num], regs);
  317. break;
  318. }
  319. }
  320. return 0;
  321. }
  322. static int kstack_depth_to_print = 48;
  323. static void show_trace(unsigned long *stack, unsigned long *endstack)
  324. {
  325. unsigned long addr;
  326. int i;
  327. pr_debug("Call trace:");
  328. i = 0;
  329. while (stack + 1 <= endstack) {
  330. addr = *stack++;
  331. /*
  332. * If the address is either in the text segment of the
  333. * kernel, or in the region which contains vmalloc'ed
  334. * memory, it *may* be the address of a calling
  335. * routine; if so, print it so that someone tracing
  336. * down the cause of the crash will be able to figure
  337. * out the call path that was taken.
  338. */
  339. if (__kernel_text_address(addr)) {
  340. #ifndef CONFIG_KALLSYMS
  341. if (i % 5 == 0)
  342. pr_debug("\n ");
  343. #endif
  344. pr_debug(" [<%08lx>]", addr);
  345. print_symbol(" %s\n", addr);
  346. i++;
  347. }
  348. }
  349. pr_debug("\n");
  350. }
  351. void show_stack(struct task_struct *task, unsigned long *stack)
  352. {
  353. unsigned long *p, *endstack;
  354. int i;
  355. if (!stack) {
  356. if (task && task != current)
  357. /* We know this is a kernel stack,
  358. so this is the start/end */
  359. stack = (unsigned long *)thread_saved_ksp(task);
  360. else
  361. stack = (unsigned long *)&stack;
  362. }
  363. endstack = (unsigned long *)(((unsigned long)stack + THREAD_SIZE - 1)
  364. & -THREAD_SIZE);
  365. pr_debug("Stack from %08lx:", (unsigned long)stack);
  366. for (i = 0, p = stack; i < kstack_depth_to_print; i++) {
  367. if (p + 1 > endstack)
  368. break;
  369. if (i % 8 == 0)
  370. pr_cont("\n ");
  371. pr_cont(" %08lx", *p++);
  372. }
  373. pr_cont("\n");
  374. show_trace(stack, endstack);
  375. }
  376. int is_valid_bugaddr(unsigned long addr)
  377. {
  378. return __kernel_text_address(addr);
  379. }