head_booke.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. #ifndef __HEAD_BOOKE_H__
  2. #define __HEAD_BOOKE_H__
  3. /*
  4. * Macros used for common Book-e exception handling
  5. */
  6. #define SET_IVOR(vector_number, vector_label) \
  7. li r26,vector_label@l; \
  8. mtspr SPRN_IVOR##vector_number,r26; \
  9. sync
  10. #define NORMAL_EXCEPTION_PROLOG \
  11. mtspr SPRN_SPRG0,r10; /* save two registers to work with */\
  12. mtspr SPRN_SPRG1,r11; \
  13. mtspr SPRN_SPRG4W,r1; \
  14. mfcr r10; /* save CR in r10 for now */\
  15. mfspr r11,SPRN_SRR1; /* check whether user or kernel */\
  16. andi. r11,r11,MSR_PR; \
  17. beq 1f; \
  18. mfspr r1,SPRN_SPRG3; /* if from user, start at top of */\
  19. lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\
  20. addi r1,r1,THREAD_SIZE; \
  21. 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\
  22. mr r11,r1; \
  23. stw r10,_CCR(r11); /* save various registers */\
  24. stw r12,GPR12(r11); \
  25. stw r9,GPR9(r11); \
  26. mfspr r10,SPRN_SPRG0; \
  27. stw r10,GPR10(r11); \
  28. mfspr r12,SPRN_SPRG1; \
  29. stw r12,GPR11(r11); \
  30. mflr r10; \
  31. stw r10,_LINK(r11); \
  32. mfspr r10,SPRN_SPRG4R; \
  33. mfspr r12,SPRN_SRR0; \
  34. stw r10,GPR1(r11); \
  35. mfspr r9,SPRN_SRR1; \
  36. stw r10,0(r11); \
  37. rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
  38. stw r0,GPR0(r11); \
  39. SAVE_4GPRS(3, r11); \
  40. SAVE_2GPRS(7, r11)
  41. /* To handle the additional exception priority levels on 40x and Book-E
  42. * processors we allocate a 4k stack per additional priority level. The various
  43. * head_xxx.S files allocate space (exception_stack_top) for each priority's
  44. * stack times the number of CPUs
  45. *
  46. * On 40x critical is the only additional level
  47. * On 44x/e500 we have critical and machine check
  48. * On e200 we have critical and debug (machine check occurs via critical)
  49. *
  50. * Additionally we reserve a SPRG for each priority level so we can free up a
  51. * GPR to use as the base for indirect access to the exception stacks. This
  52. * is necessary since the MMU is always on, for Book-E parts, and the stacks
  53. * are offset from KERNELBASE.
  54. *
  55. * There is some space optimization to be had here if desired. However
  56. * to allow for a common kernel with support for debug exceptions either
  57. * going to critical or their own debug level we aren't currently
  58. * providing configurations that micro-optimize space usage.
  59. */
  60. #ifdef CONFIG_44x
  61. #define NUM_EXCEPTION_LVLS 2
  62. #else
  63. #define NUM_EXCEPTION_LVLS 3
  64. #endif
  65. #define BOOKE_EXCEPTION_STACK_SIZE (4096 * NUM_EXCEPTION_LVLS)
  66. /* CRIT_SPRG only used in critical exception handling */
  67. #define CRIT_SPRG SPRN_SPRG2
  68. /* MCHECK_SPRG only used in machine check exception handling */
  69. #define MCHECK_SPRG SPRN_SPRG6W
  70. #define MCHECK_STACK_TOP (exception_stack_top - 4096)
  71. #define CRIT_STACK_TOP (exception_stack_top)
  72. /* only on e200 for now */
  73. #define DEBUG_STACK_TOP (exception_stack_top - 8192)
  74. #define DEBUG_SPRG SPRN_SPRG6W
  75. #ifdef CONFIG_SMP
  76. #define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
  77. mfspr r8,SPRN_PIR; \
  78. mulli r8,r8,BOOKE_EXCEPTION_STACK_SIZE; \
  79. neg r8,r8; \
  80. addis r8,r8,level##_STACK_TOP@ha; \
  81. addi r8,r8,level##_STACK_TOP@l
  82. #else
  83. #define BOOKE_LOAD_EXC_LEVEL_STACK(level) \
  84. lis r8,level##_STACK_TOP@h; \
  85. ori r8,r8,level##_STACK_TOP@l
  86. #endif
  87. /*
  88. * Exception prolog for critical/machine check exceptions. This is a
  89. * little different from the normal exception prolog above since a
  90. * critical/machine check exception can potentially occur at any point
  91. * during normal exception processing. Thus we cannot use the same SPRG
  92. * registers as the normal prolog above. Instead we use a portion of the
  93. * critical/machine check exception stack at low physical addresses.
  94. */
  95. #define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, exc_level_srr0, exc_level_srr1) \
  96. mtspr exc_level##_SPRG,r8; \
  97. BOOKE_LOAD_EXC_LEVEL_STACK(exc_level);/* r8 points to the exc_level stack*/ \
  98. stw r10,GPR10-INT_FRAME_SIZE(r8); \
  99. stw r11,GPR11-INT_FRAME_SIZE(r8); \
  100. mfcr r10; /* save CR in r10 for now */\
  101. mfspr r11,exc_level_srr1; /* check whether user or kernel */\
  102. andi. r11,r11,MSR_PR; \
  103. mr r11,r8; \
  104. mfspr r8,exc_level##_SPRG; \
  105. beq 1f; \
  106. /* COMING FROM USER MODE */ \
  107. mfspr r11,SPRN_SPRG3; /* if from user, start at top of */\
  108. lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
  109. addi r11,r11,THREAD_SIZE; \
  110. 1: subi r11,r11,INT_FRAME_SIZE; /* Allocate an exception frame */\
  111. stw r10,_CCR(r11); /* save various registers */\
  112. stw r12,GPR12(r11); \
  113. stw r9,GPR9(r11); \
  114. mflr r10; \
  115. stw r10,_LINK(r11); \
  116. mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
  117. stw r12,_DEAR(r11); /* since they may have had stuff */\
  118. mfspr r9,SPRN_ESR; /* in them at the point where the */\
  119. stw r9,_ESR(r11); /* exception was taken */\
  120. mfspr r12,exc_level_srr0; \
  121. stw r1,GPR1(r11); \
  122. mfspr r9,exc_level_srr1; \
  123. stw r1,0(r11); \
  124. mr r1,r11; \
  125. rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
  126. stw r0,GPR0(r11); \
  127. SAVE_4GPRS(3, r11); \
  128. SAVE_2GPRS(7, r11)
  129. #define CRITICAL_EXCEPTION_PROLOG \
  130. EXC_LEVEL_EXCEPTION_PROLOG(CRIT, SPRN_CSRR0, SPRN_CSRR1)
  131. #define DEBUG_EXCEPTION_PROLOG \
  132. EXC_LEVEL_EXCEPTION_PROLOG(DEBUG, SPRN_DSRR0, SPRN_DSRR1)
  133. #define MCHECK_EXCEPTION_PROLOG \
  134. EXC_LEVEL_EXCEPTION_PROLOG(MCHECK, SPRN_MCSRR0, SPRN_MCSRR1)
  135. /*
  136. * Exception vectors.
  137. */
  138. #define START_EXCEPTION(label) \
  139. .align 5; \
  140. label:
  141. #define FINISH_EXCEPTION(func) \
  142. bl transfer_to_handler_full; \
  143. .long func; \
  144. .long ret_from_except_full
  145. #define EXCEPTION(n, label, hdlr, xfer) \
  146. START_EXCEPTION(label); \
  147. NORMAL_EXCEPTION_PROLOG; \
  148. addi r3,r1,STACK_FRAME_OVERHEAD; \
  149. xfer(n, hdlr)
  150. #define CRITICAL_EXCEPTION(n, label, hdlr) \
  151. START_EXCEPTION(label); \
  152. CRITICAL_EXCEPTION_PROLOG; \
  153. addi r3,r1,STACK_FRAME_OVERHEAD; \
  154. EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  155. NOCOPY, crit_transfer_to_handler, \
  156. ret_from_crit_exc)
  157. #define MCHECK_EXCEPTION(n, label, hdlr) \
  158. START_EXCEPTION(label); \
  159. MCHECK_EXCEPTION_PROLOG; \
  160. mfspr r5,SPRN_ESR; \
  161. stw r5,_ESR(r11); \
  162. addi r3,r1,STACK_FRAME_OVERHEAD; \
  163. EXC_XFER_TEMPLATE(hdlr, n+4, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  164. NOCOPY, mcheck_transfer_to_handler, \
  165. ret_from_mcheck_exc)
  166. #define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \
  167. li r10,trap; \
  168. stw r10,_TRAP(r11); \
  169. lis r10,msr@h; \
  170. ori r10,r10,msr@l; \
  171. copyee(r10, r9); \
  172. bl tfer; \
  173. .long hdlr; \
  174. .long ret
  175. #define COPY_EE(d, s) rlwimi d,s,0,16,16
  176. #define NOCOPY(d, s)
  177. #define EXC_XFER_STD(n, hdlr) \
  178. EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \
  179. ret_from_except_full)
  180. #define EXC_XFER_LITE(n, hdlr) \
  181. EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
  182. ret_from_except)
  183. #define EXC_XFER_EE(n, hdlr) \
  184. EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \
  185. ret_from_except_full)
  186. #define EXC_XFER_EE_LITE(n, hdlr) \
  187. EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
  188. ret_from_except)
  189. /* Check for a single step debug exception while in an exception
  190. * handler before state has been saved. This is to catch the case
  191. * where an instruction that we are trying to single step causes
  192. * an exception (eg ITLB/DTLB miss) and thus the first instruction of
  193. * the exception handler generates a single step debug exception.
  194. *
  195. * If we get a debug trap on the first instruction of an exception handler,
  196. * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
  197. * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
  198. * The exception handler was handling a non-critical interrupt, so it will
  199. * save (and later restore) the MSR via SPRN_CSRR1, which will still have
  200. * the MSR_DE bit set.
  201. */
  202. #define DEBUG_DEBUG_EXCEPTION \
  203. START_EXCEPTION(DebugDebug); \
  204. DEBUG_EXCEPTION_PROLOG; \
  205. \
  206. /* \
  207. * If there is a single step or branch-taken exception in an \
  208. * exception entry sequence, it was probably meant to apply to \
  209. * the code where the exception occurred (since exception entry \
  210. * doesn't turn off DE automatically). We simulate the effect \
  211. * of turning off DE on entry to an exception handler by turning \
  212. * off DE in the CSRR1 value and clearing the debug status. \
  213. */ \
  214. mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
  215. andis. r10,r10,DBSR_IC@h; \
  216. beq+ 2f; \
  217. \
  218. lis r10,KERNELBASE@h; /* check if exception in vectors */ \
  219. ori r10,r10,KERNELBASE@l; \
  220. cmplw r12,r10; \
  221. blt+ 2f; /* addr below exception vectors */ \
  222. \
  223. lis r10,DebugDebug@h; \
  224. ori r10,r10,DebugDebug@l; \
  225. cmplw r12,r10; \
  226. bgt+ 2f; /* addr above exception vectors */ \
  227. \
  228. /* here it looks like we got an inappropriate debug exception. */ \
  229. 1: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CDRR1 value */ \
  230. lis r10,DBSR_IC@h; /* clear the IC event */ \
  231. mtspr SPRN_DBSR,r10; \
  232. /* restore state and get out */ \
  233. lwz r10,_CCR(r11); \
  234. lwz r0,GPR0(r11); \
  235. lwz r1,GPR1(r11); \
  236. mtcrf 0x80,r10; \
  237. mtspr SPRN_DSRR0,r12; \
  238. mtspr SPRN_DSRR1,r9; \
  239. lwz r9,GPR9(r11); \
  240. lwz r12,GPR12(r11); \
  241. mtspr DEBUG_SPRG,r8; \
  242. BOOKE_LOAD_EXC_LEVEL_STACK(DEBUG); /* r8 points to the debug stack */ \
  243. lwz r10,GPR10-INT_FRAME_SIZE(r8); \
  244. lwz r11,GPR11-INT_FRAME_SIZE(r8); \
  245. mfspr r8,DEBUG_SPRG; \
  246. \
  247. RFDI; \
  248. b .; \
  249. \
  250. /* continue normal handling for a critical exception... */ \
  251. 2: mfspr r4,SPRN_DBSR; \
  252. addi r3,r1,STACK_FRAME_OVERHEAD; \
  253. EXC_XFER_TEMPLATE(DebugException, 0x2002, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, debug_transfer_to_handler, ret_from_debug_exc)
  254. #define DEBUG_CRIT_EXCEPTION \
  255. START_EXCEPTION(DebugCrit); \
  256. CRITICAL_EXCEPTION_PROLOG; \
  257. \
  258. /* \
  259. * If there is a single step or branch-taken exception in an \
  260. * exception entry sequence, it was probably meant to apply to \
  261. * the code where the exception occurred (since exception entry \
  262. * doesn't turn off DE automatically). We simulate the effect \
  263. * of turning off DE on entry to an exception handler by turning \
  264. * off DE in the CSRR1 value and clearing the debug status. \
  265. */ \
  266. mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
  267. andis. r10,r10,DBSR_IC@h; \
  268. beq+ 2f; \
  269. \
  270. lis r10,KERNELBASE@h; /* check if exception in vectors */ \
  271. ori r10,r10,KERNELBASE@l; \
  272. cmplw r12,r10; \
  273. blt+ 2f; /* addr below exception vectors */ \
  274. \
  275. lis r10,DebugCrit@h; \
  276. ori r10,r10,DebugCrit@l; \
  277. cmplw r12,r10; \
  278. bgt+ 2f; /* addr above exception vectors */ \
  279. \
  280. /* here it looks like we got an inappropriate debug exception. */ \
  281. 1: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CSRR1 value */ \
  282. lis r10,DBSR_IC@h; /* clear the IC event */ \
  283. mtspr SPRN_DBSR,r10; \
  284. /* restore state and get out */ \
  285. lwz r10,_CCR(r11); \
  286. lwz r0,GPR0(r11); \
  287. lwz r1,GPR1(r11); \
  288. mtcrf 0x80,r10; \
  289. mtspr SPRN_CSRR0,r12; \
  290. mtspr SPRN_CSRR1,r9; \
  291. lwz r9,GPR9(r11); \
  292. lwz r12,GPR12(r11); \
  293. mtspr CRIT_SPRG,r8; \
  294. BOOKE_LOAD_EXC_LEVEL_STACK(CRIT); /* r8 points to the debug stack */ \
  295. lwz r10,GPR10-INT_FRAME_SIZE(r8); \
  296. lwz r11,GPR11-INT_FRAME_SIZE(r8); \
  297. mfspr r8,CRIT_SPRG; \
  298. \
  299. rfci; \
  300. b .; \
  301. \
  302. /* continue normal handling for a critical exception... */ \
  303. 2: mfspr r4,SPRN_DBSR; \
  304. addi r3,r1,STACK_FRAME_OVERHEAD; \
  305. EXC_XFER_TEMPLATE(DebugException, 0x2002, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)
  306. #define INSTRUCTION_STORAGE_EXCEPTION \
  307. START_EXCEPTION(InstructionStorage) \
  308. NORMAL_EXCEPTION_PROLOG; \
  309. mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
  310. stw r5,_ESR(r11); \
  311. mr r4,r12; /* Pass SRR0 as arg2 */ \
  312. li r5,0; /* Pass zero as arg3 */ \
  313. EXC_XFER_EE_LITE(0x0400, handle_page_fault)
  314. #define ALIGNMENT_EXCEPTION \
  315. START_EXCEPTION(Alignment) \
  316. NORMAL_EXCEPTION_PROLOG; \
  317. mfspr r4,SPRN_DEAR; /* Grab the DEAR and save it */ \
  318. stw r4,_DEAR(r11); \
  319. addi r3,r1,STACK_FRAME_OVERHEAD; \
  320. EXC_XFER_EE(0x0600, alignment_exception)
  321. #define PROGRAM_EXCEPTION \
  322. START_EXCEPTION(Program) \
  323. NORMAL_EXCEPTION_PROLOG; \
  324. mfspr r4,SPRN_ESR; /* Grab the ESR and save it */ \
  325. stw r4,_ESR(r11); \
  326. addi r3,r1,STACK_FRAME_OVERHEAD; \
  327. EXC_XFER_STD(0x0700, program_check_exception)
  328. #define DECREMENTER_EXCEPTION \
  329. START_EXCEPTION(Decrementer) \
  330. NORMAL_EXCEPTION_PROLOG; \
  331. lis r0,TSR_DIS@h; /* Setup the DEC interrupt mask */ \
  332. mtspr SPRN_TSR,r0; /* Clear the DEC interrupt */ \
  333. addi r3,r1,STACK_FRAME_OVERHEAD; \
  334. EXC_XFER_LITE(0x0900, timer_interrupt)
  335. #define FP_UNAVAILABLE_EXCEPTION \
  336. START_EXCEPTION(FloatingPointUnavailable) \
  337. NORMAL_EXCEPTION_PROLOG; \
  338. bne load_up_fpu; /* if from user, just load it up */ \
  339. addi r3,r1,STACK_FRAME_OVERHEAD; \
  340. EXC_XFER_EE_LITE(0x800, kernel_fp_unavailable_exception)
  341. #endif /* __HEAD_BOOKE_H__ */