memoryDefinitionWaterRelatedData.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Main exception handling logic.
  3. *
  4. * Copyright 2004-2010 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later
  7. */
  8. #include <linux/bug.h>
  9. #include <linux/uaccess.h>
  10. #include <linux/module.h>
  11. #include <asm/traps.h>
  12. #include <asm/cplb.h>
  13. #include <asm/blackfin.h>
  14. #include <asm/irq_handler.h>
  15. #include <linux/irq.h>
  16. #include <asm/trace.h>
  17. #include <asm/fixed_code.h>
  18. #include <asm/pseudo_instructions.h>
  19. #include <asm/pda.h>
  20. #ifdef CONFIG_KGDB
  21. # include <linux/kgdb.h>
  22. # define CHK_DEBUGGER_TRAP() \
  23. do { \
  24. kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
  25. } while (0)
  26. # define CHK_DEBUGGER_TRAP_MAYBE() \
  27. do { \
  28. if (kgdb_connected) \
  29. CHK_DEBUGGER_TRAP(); \
  30. } while (0)
  31. #else
  32. # define CHK_DEBUGGER_TRAP() do { } while (0)
  33. # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
  34. #endif
  35. #ifdef CONFIG_DEBUG_VERBOSE
  36. #define verbose_printk(fmt, arg...) \
  37. printk(fmt, ##arg)
  38. #else
  39. #define verbose_printk(fmt, arg...) \
  40. ({ if (0) printk(fmt, ##arg); 0; })
  41. #endif
  42. #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
  43. u32 last_seqstat;
  44. #ifdef CONFIG_DEBUG_MMRS_MODULE
  45. EXPORT_SYMBOL(last_seqstat);
  46. #endif
  47. #endif
  48. /* Initiate the event table handler */
  49. void __init trap_init(void)
  50. {
  51. CSYNC();
  52. bfin_write_EVT3(trap);
  53. CSYNC();
  54. }
  55. static int kernel_mode_regs(struct pt_regs *regs)
  56. {
  57. return regs->ipend & 0xffc0;
  58. }
  59. asmlinkage notrace void trap_c(struct pt_regs *fp)
  60. {
  61. #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
  62. int j;
  63. #endif
  64. #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
  65. int opcode;
  66. #endif
  67. unsigned int cpu = raw_smp_processor_id();
  68. const char *strerror = NULL;
  69. int sig = 0;
  70. siginfo_t info;
  71. unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
  72. trace_buffer_save(j);
  73. #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
  74. last_seqstat = (u32)fp->seqstat;
  75. #endif
  76. /* Important - be very careful dereferncing pointers - will lead to
  77. * double faults if the stack has become corrupt
  78. */
  79. /* trap_c() will be called for exceptions. During exceptions
  80. * processing, the pc value should be set with retx value.
  81. * With this change we can cleanup some code in signal.c- TODO
  82. */
  83. fp->orig_pc = fp->retx;
  84. /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
  85. trapnr, fp->ipend, fp->pc, fp->retx); */
  86. /* send the appropriate signal to the user program */
  87. switch (trapnr) {
  88. /* This table works in conjunction with the one in ./mach-common/entry.S
  89. * Some exceptions are handled there (in assembly, in exception space)
  90. * Some are handled here, (in C, in interrupt space)
  91. * Some, like CPLB, are handled in both, where the normal path is
  92. * handled in assembly/exception space, and the error path is handled
  93. * here
  94. */
  95. /* 0x00 - Linux Syscall, getting here is an error */
  96. /* 0x01 - userspace gdb breakpoint, handled here */
  97. case VEC_EXCPT01:
  98. info.si_code = TRAP_ILLTRAP;
  99. sig = SIGTRAP;
  100. CHK_DEBUGGER_TRAP_MAYBE();
  101. /* Check if this is a breakpoint in kernel space */
  102. if (kernel_mode_regs(fp))
  103. goto traps_done;
  104. else
  105. break;
  106. /* 0x03 - User Defined, userspace stack overflow */
  107. case VEC_EXCPT03:
  108. info.si_code = SEGV_STACKFLOW;
  109. sig = SIGSEGV;
  110. strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
  111. CHK_DEBUGGER_TRAP_MAYBE();
  112. break;
  113. /* 0x02 - KGDB initial connection and break signal trap */
  114. case VEC_EXCPT02:
  115. #ifdef CONFIG_KGDB
  116. info.si_code = TRAP_ILLTRAP;
  117. sig = SIGTRAP;
  118. CHK_DEBUGGER_TRAP();
  119. goto traps_done;
  120. #endif
  121. /* 0x04 - User Defined */
  122. /* 0x05 - User Defined */
  123. /* 0x06 - User Defined */
  124. /* 0x07 - User Defined */
  125. /* 0x08 - User Defined */
  126. /* 0x09 - User Defined */
  127. /* 0x0A - User Defined */
  128. /* 0x0B - User Defined */
  129. /* 0x0C - User Defined */
  130. /* 0x0D - User Defined */
  131. /* 0x0E - User Defined */
  132. /* 0x0F - User Defined */
  133. /* If we got here, it is most likely that someone was trying to use a
  134. * custom exception handler, and it is not actually installed properly
  135. */
  136. case VEC_EXCPT04 ... VEC_EXCPT15:
  137. info.si_code = ILL_ILLPARAOP;
  138. sig = SIGILL;
  139. strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
  140. CHK_DEBUGGER_TRAP_MAYBE();
  141. break;
  142. /* 0x10 HW Single step, handled here */
  143. case VEC_STEP:
  144. info.si_code = TRAP_STEP;
  145. sig = SIGTRAP;
  146. CHK_DEBUGGER_TRAP_MAYBE();
  147. /* Check if this is a single step in kernel space */
  148. if (kernel_mode_regs(fp))
  149. goto traps_done;
  150. else
  151. break;
  152. /* 0x11 - Trace Buffer Full, handled here */
  153. case VEC_OVFLOW:
  154. info.si_code = TRAP_TRACEFLOW;
  155. sig = SIGTRAP;
  156. strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
  157. CHK_DEBUGGER_TRAP_MAYBE();
  158. break;
  159. /* 0x12 - Reserved, Caught by default */
  160. /* 0x13 - Reserved, Caught by default */
  161. /* 0x14 - Reserved, Caught by default */
  162. /* 0x15 - Reserved, Caught by default */
  163. /* 0x16 - Reserved, Caught by default */
  164. /* 0x17 - Reserved, Caught by default */
  165. /* 0x18 - Reserved, Caught by default */
  166. /* 0x19 - Reserved, Caught by default */
  167. /* 0x1A - Reserved, Caught by default */
  168. /* 0x1B - Reserved, Caught by default */
  169. /* 0x1C - Reserved, Caught by default */
  170. /* 0x1D - Reserved, Caught by default */
  171. /* 0x1E - Reserved, Caught by default */
  172. /* 0x1F - Reserved, Caught by default */
  173. /* 0x20 - Reserved, Caught by default */
  174. /* 0x21 - Undefined Instruction, handled here */
  175. case VEC_UNDEF_I:
  176. #ifdef CONFIG_BUG
  177. if (kernel_mode_regs(fp)) {
  178. switch (report_bug(fp->pc, fp)) {
  179. case BUG_TRAP_TYPE_NONE:
  180. break;
  181. case BUG_TRAP_TYPE_WARN:
  182. dump_bfin_trace_buffer();
  183. fp->pc += 2;
  184. goto traps_done;
  185. case BUG_TRAP_TYPE_BUG:
  186. /* call to panic() will dump trace, and it is
  187. * off at this point, so it won't be clobbered
  188. */
  189. panic("BUG()");
  190. }
  191. }
  192. #endif
  193. #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
  194. /*
  195. * Support for the fake instructions, if the instruction fails,
  196. * then just execute a illegal opcode failure (like normal).
  197. * Don't support these instructions inside the kernel
  198. */
  199. if (!kernel_mode_regs(fp) && get_instruction(&opcode, (unsigned short *)fp->pc)) {
  200. if (execute_pseudodbg_assert(fp, opcode))
  201. goto traps_done;
  202. if (execute_pseudodbg(fp, opcode))
  203. goto traps_done;
  204. }
  205. #endif
  206. info.si_code = ILL_ILLOPC;
  207. sig = SIGILL;
  208. strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
  209. CHK_DEBUGGER_TRAP_MAYBE();
  210. break;
  211. /* 0x22 - Illegal Instruction Combination, handled here */
  212. case VEC_ILGAL_I:
  213. info.si_code = ILL_ILLPARAOP;
  214. sig = SIGILL;
  215. strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
  216. CHK_DEBUGGER_TRAP_MAYBE();
  217. break;
  218. /* 0x23 - Data CPLB protection violation, handled here */
  219. case VEC_CPLB_VL:
  220. info.si_code = ILL_CPLB_VI;
  221. sig = SIGSEGV;
  222. strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
  223. CHK_DEBUGGER_TRAP_MAYBE();
  224. break;
  225. /* 0x24 - Data access misaligned, handled here */
  226. case VEC_MISALI_D:
  227. info.si_code = BUS_ADRALN;
  228. sig = SIGBUS;
  229. strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
  230. CHK_DEBUGGER_TRAP_MAYBE();
  231. break;
  232. /* 0x25 - Unrecoverable Event, handled here */
  233. case VEC_UNCOV:
  234. info.si_code = ILL_ILLEXCPT;
  235. sig = SIGILL;
  236. strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
  237. CHK_DEBUGGER_TRAP_MAYBE();
  238. break;
  239. /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
  240. error case is handled here */
  241. case VEC_CPLB_M:
  242. info.si_code = BUS_ADRALN;
  243. sig = SIGBUS;
  244. strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
  245. break;
  246. /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
  247. case VEC_CPLB_MHIT:
  248. info.si_code = ILL_CPLB_MULHIT;
  249. sig = SIGSEGV;
  250. #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
  251. if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
  252. strerror = KERN_NOTICE "NULL pointer access\n";
  253. else
  254. #endif
  255. strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
  256. CHK_DEBUGGER_TRAP_MAYBE();
  257. break;
  258. /* 0x28 - Emulation Watchpoint, handled here */
  259. case VEC_WATCH:
  260. info.si_code = TRAP_WATCHPT;
  261. sig = SIGTRAP;
  262. pr_debug(EXC_0x28(KERN_DEBUG));
  263. CHK_DEBUGGER_TRAP_MAYBE();
  264. /* Check if this is a watchpoint in kernel space */
  265. if (kernel_mode_regs(fp))
  266. goto traps_done;
  267. else
  268. break;
  269. #ifdef CONFIG_BF535
  270. /* 0x29 - Instruction fetch access error (535 only) */
  271. case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
  272. info.si_code = BUS_OPFETCH;
  273. sig = SIGBUS;
  274. strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
  275. CHK_DEBUGGER_TRAP_MAYBE();
  276. break;
  277. #else