head_booke.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. *
  49. * Additionally we reserve a SPRG for each priority level so we can free up a
  50. * GPR to use as the base for indirect access to the exception stacks. This
  51. * is necessary since the MMU is always on, for Book-E parts, and the stacks
  52. * are offset from KERNELBASE.
  53. *
  54. */
  55. #define BOOKE_EXCEPTION_STACK_SIZE (8192)
  56. /* CRIT_SPRG only used in critical exception handling */
  57. #define CRIT_SPRG SPRN_SPRG2
  58. /* MCHECK_SPRG only used in critical exception handling */
  59. #define MCHECK_SPRG SPRN_SPRG6W
  60. #define MCHECK_STACK_TOP (exception_stack_top - 4096)
  61. #define CRIT_STACK_TOP (exception_stack_top)
  62. #ifdef CONFIG_SMP
  63. #define BOOKE_LOAD_CRIT_STACK \
  64. mfspr r8,SPRN_PIR; \
  65. mulli r8,r8,BOOKE_EXCEPTION_STACK_SIZE; \
  66. neg r8,r8; \
  67. addis r8,r8,CRIT_STACK_TOP@ha; \
  68. addi r8,r8,CRIT_STACK_TOP@l
  69. #define BOOKE_LOAD_MCHECK_STACK \
  70. mfspr r8,SPRN_PIR; \
  71. mulli r8,r8,BOOKE_EXCEPTION_STACK_SIZE; \
  72. neg r8,r8; \
  73. addis r8,r8,MCHECK_STACK_TOP@ha; \
  74. addi r8,r8,MCHECK_STACK_TOP@l
  75. #else
  76. #define BOOKE_LOAD_CRIT_STACK \
  77. lis r8,CRIT_STACK_TOP@h; \
  78. ori r8,r8,CRIT_STACK_TOP@l
  79. #define BOOKE_LOAD_MCHECK_STACK \
  80. lis r8,MCHECK_STACK_TOP@h; \
  81. ori r8,r8,MCHECK_STACK_TOP@l
  82. #endif
  83. /*
  84. * Exception prolog for critical exceptions. This is a little different
  85. * from the normal exception prolog above since a critical exception
  86. * can potentially occur at any point during normal exception processing.
  87. * Thus we cannot use the same SPRG registers as the normal prolog above.
  88. * Instead we use a portion of the critical exception stack at low physical
  89. * addresses.
  90. */
  91. #define CRITICAL_EXCEPTION_PROLOG \
  92. mtspr CRIT_SPRG,r8; \
  93. BOOKE_LOAD_CRIT_STACK; /* r8 points to the crit stack */ \
  94. stw r10,GPR10-INT_FRAME_SIZE(r8); \
  95. stw r11,GPR11-INT_FRAME_SIZE(r8); \
  96. mfcr r10; /* save CR in r10 for now */\
  97. mfspr r11,SPRN_CSRR1; /* check whether user or kernel */\
  98. andi. r11,r11,MSR_PR; \
  99. mr r11,r8; \
  100. mfspr r8,CRIT_SPRG; \
  101. beq 1f; \
  102. /* COMING FROM USER MODE */ \
  103. mfspr r11,SPRN_SPRG3; /* if from user, start at top of */\
  104. lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
  105. addi r11,r11,THREAD_SIZE; \
  106. 1: subi r11,r11,INT_FRAME_SIZE; /* Allocate an exception frame */\
  107. stw r10,_CCR(r11); /* save various registers */\
  108. stw r12,GPR12(r11); \
  109. stw r9,GPR9(r11); \
  110. mflr r10; \
  111. stw r10,_LINK(r11); \
  112. mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
  113. stw r12,_DEAR(r11); /* since they may have had stuff */\
  114. mfspr r9,SPRN_ESR; /* in them at the point where the */\
  115. stw r9,_ESR(r11); /* exception was taken */\
  116. mfspr r12,SPRN_CSRR0; \
  117. stw r1,GPR1(r11); \
  118. mfspr r9,SPRN_CSRR1; \
  119. stw r1,0(r11); \
  120. mr r1,r11; \
  121. rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
  122. stw r0,GPR0(r11); \
  123. SAVE_4GPRS(3, r11); \
  124. SAVE_2GPRS(7, r11)
  125. /*
  126. * Exception prolog for machine check exceptions. This is similar to
  127. * the critical exception prolog, except that machine check exceptions
  128. * have their stack.
  129. */
  130. #define MCHECK_EXCEPTION_PROLOG \
  131. mtspr MCHECK_SPRG,r8; \
  132. BOOKE_LOAD_MCHECK_STACK; /* r8 points to the mcheck stack */\
  133. stw r10,GPR10-INT_FRAME_SIZE(r8); \
  134. stw r11,GPR11-INT_FRAME_SIZE(r8); \
  135. mfcr r10; /* save CR in r10 for now */\
  136. mfspr r11,SPRN_MCSRR1; /* check whether user or kernel */\
  137. andi. r11,r11,MSR_PR; \
  138. mr r11,r8; \
  139. mfspr r8,MCHECK_SPRG; \
  140. beq 1f; \
  141. /* COMING FROM USER MODE */ \
  142. mfspr r11,SPRN_SPRG3; /* if from user, start at top of */\
  143. lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
  144. addi r11,r11,THREAD_SIZE; \
  145. 1: subi r11,r11,INT_FRAME_SIZE; /* Allocate an exception frame */\
  146. stw r10,_CCR(r11); /* save various registers */\
  147. stw r12,GPR12(r11); \
  148. stw r9,GPR9(r11); \
  149. mflr r10; \
  150. stw r10,_LINK(r11); \
  151. mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
  152. stw r12,_DEAR(r11); /* since they may have had stuff */\
  153. mfspr r9,SPRN_ESR; /* in them at the point where the */\
  154. stw r9,_ESR(r11); /* exception was taken */\
  155. mfspr r12,SPRN_MCSRR0; \
  156. stw r1,GPR1(r11); \
  157. mfspr r9,SPRN_MCSRR1; \
  158. stw r1,0(r11); \
  159. mr r1,r11; \
  160. rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
  161. stw r0,GPR0(r11); \
  162. SAVE_4GPRS(3, r11); \
  163. SAVE_2GPRS(7, r11)
  164. /*
  165. * Exception vectors.
  166. */
  167. #define START_EXCEPTION(label) \
  168. .align 5; \
  169. label:
  170. #define FINISH_EXCEPTION(func) \
  171. bl transfer_to_handler_full; \
  172. .long func; \
  173. .long ret_from_except_full
  174. #define EXCEPTION(n, label, hdlr, xfer) \
  175. START_EXCEPTION(label); \
  176. NORMAL_EXCEPTION_PROLOG; \
  177. addi r3,r1,STACK_FRAME_OVERHEAD; \
  178. xfer(n, hdlr)
  179. #define CRITICAL_EXCEPTION(n, label, hdlr) \
  180. START_EXCEPTION(label); \
  181. CRITICAL_EXCEPTION_PROLOG; \
  182. addi r3,r1,STACK_FRAME_OVERHEAD; \
  183. EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  184. NOCOPY, crit_transfer_to_handler, \
  185. ret_from_crit_exc)
  186. #define MCHECK_EXCEPTION(n, label, hdlr) \
  187. START_EXCEPTION(label); \
  188. MCHECK_EXCEPTION_PROLOG; \
  189. mfspr r5,SPRN_ESR; \
  190. stw r5,_ESR(r11); \
  191. addi r3,r1,STACK_FRAME_OVERHEAD; \
  192. EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  193. NOCOPY, mcheck_transfer_to_handler, \
  194. ret_from_mcheck_exc)
  195. #define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \
  196. li r10,trap; \
  197. stw r10,TRAP(r11); \
  198. lis r10,msr@h; \
  199. ori r10,r10,msr@l; \
  200. copyee(r10, r9); \
  201. bl tfer; \
  202. .long hdlr; \
  203. .long ret
  204. #define COPY_EE(d, s) rlwimi d,s,0,16,16
  205. #define NOCOPY(d, s)
  206. #define EXC_XFER_STD(n, hdlr) \
  207. EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \
  208. ret_from_except_full)
  209. #define EXC_XFER_LITE(n, hdlr) \
  210. EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
  211. ret_from_except)
  212. #define EXC_XFER_EE(n, hdlr) \
  213. EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \
  214. ret_from_except_full)
  215. #define EXC_XFER_EE_LITE(n, hdlr) \
  216. EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
  217. ret_from_except)
  218. /* Check for a single step debug exception while in an exception
  219. * handler before state has been saved. This is to catch the case
  220. * where an instruction that we are trying to single step causes
  221. * an exception (eg ITLB/DTLB miss) and thus the first instruction of
  222. * the exception handler generates a single step debug exception.
  223. *
  224. * If we get a debug trap on the first instruction of an exception handler,
  225. * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
  226. * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
  227. * The exception handler was handling a non-critical interrupt, so it will
  228. * save (and later restore) the MSR via SPRN_CSRR1, which will still have
  229. * the MSR_DE bit set.
  230. */
  231. #define DEBUG_EXCEPTION \
  232. START_EXCEPTION(Debug); \
  233. CRITICAL_EXCEPTION_PROLOG; \
  234. \
  235. /* \
  236. * If there is a single step or branch-taken exception in an \
  237. * exception entry sequence, it was probably meant to apply to \
  238. * the code where the exception occurred (since exception entry \
  239. * doesn't turn off DE automatically). We simulate the effect \
  240. * of turning off DE on entry to an exception handler by turning \
  241. * off DE in the CSRR1 value and clearing the debug status. \
  242. */ \
  243. mfspr r10,SPRN_DBSR; /* check single-step/branch taken */ \
  244. andis. r10,r10,DBSR_IC@h; \
  245. beq+ 2f; \
  246. \
  247. lis r10,KERNELBASE@h; /* check if exception in vectors */ \
  248. ori r10,r10,KERNELBASE@l; \
  249. cmplw r12,r10; \
  250. blt+ 2f; /* addr below exception vectors */ \
  251. \
  252. lis r10,Debug@h; \
  253. ori r10,r10,Debug@l; \
  254. cmplw r12,r10; \
  255. bgt+ 2f; /* addr above exception vectors */ \
  256. \
  257. /* here it looks like we got an inappropriate debug exception. */ \
  258. 1: rlwinm r9,r9,0,~MSR_DE; /* clear DE in the CSRR1 value */ \
  259. lis r10,DBSR_IC@h; /* clear the IC event */ \
  260. mtspr SPRN_DBSR,r10; \
  261. /* restore state and get out */ \
  262. lwz r10,_CCR(r11); \
  263. lwz r0,GPR0(r11); \
  264. lwz r1,GPR1(r11); \
  265. mtcrf 0x80,r10; \
  266. mtspr SPRN_CSRR0,r12; \
  267. mtspr SPRN_CSRR1,r9; \
  268. lwz r9,GPR9(r11); \
  269. lwz r12,GPR12(r11); \
  270. mtspr CRIT_SPRG,r8; \
  271. BOOKE_LOAD_CRIT_STACK; /* r8 points to the crit stack */ \
  272. lwz r10,GPR10-INT_FRAME_SIZE(r8); \
  273. lwz r11,GPR11-INT_FRAME_SIZE(r8); \
  274. mfspr r8,CRIT_SPRG; \
  275. \
  276. rfci; \
  277. b .; \
  278. \
  279. /* continue normal handling for a critical exception... */ \
  280. 2: mfspr r4,SPRN_DBSR; \
  281. addi r3,r1,STACK_FRAME_OVERHEAD; \
  282. EXC_XFER_TEMPLATE(DebugException, 0x2002, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)
  283. #define INSTRUCTION_STORAGE_EXCEPTION \
  284. START_EXCEPTION(InstructionStorage) \
  285. NORMAL_EXCEPTION_PROLOG; \
  286. mfspr r5,SPRN_ESR; /* Grab the ESR and save it */ \
  287. stw r5,_ESR(r11); \
  288. mr r4,r12; /* Pass SRR0 as arg2 */ \
  289. li r5,0; /* Pass zero as arg3 */ \
  290. EXC_XFER_EE_LITE(0x0400, handle_page_fault)
  291. #define ALIGNMENT_EXCEPTION \
  292. START_EXCEPTION(Alignment) \
  293. NORMAL_EXCEPTION_PROLOG; \
  294. mfspr r4,SPRN_DEAR; /* Grab the DEAR and save it */ \
  295. stw r4,_DEAR(r11); \
  296. addi r3,r1,STACK_FRAME_OVERHEAD; \
  297. EXC_XFER_EE(0x0600, AlignmentException)
  298. #define PROGRAM_EXCEPTION \
  299. START_EXCEPTION(Program) \
  300. NORMAL_EXCEPTION_PROLOG; \
  301. mfspr r4,SPRN_ESR; /* Grab the ESR and save it */ \
  302. stw r4,_ESR(r11); \
  303. addi r3,r1,STACK_FRAME_OVERHEAD; \
  304. EXC_XFER_STD(0x0700, ProgramCheckException)
  305. #define DECREMENTER_EXCEPTION \
  306. START_EXCEPTION(Decrementer) \
  307. NORMAL_EXCEPTION_PROLOG; \
  308. lis r0,TSR_DIS@h; /* Setup the DEC interrupt mask */ \
  309. mtspr SPRN_TSR,r0; /* Clear the DEC interrupt */ \
  310. addi r3,r1,STACK_FRAME_OVERHEAD; \
  311. EXC_XFER_LITE(0x0900, timer_interrupt)
  312. #define FP_UNAVAILABLE_EXCEPTION \
  313. START_EXCEPTION(FloatingPointUnavailable) \
  314. NORMAL_EXCEPTION_PROLOG; \
  315. bne load_up_fpu; /* if from user, just load it up */ \
  316. addi r3,r1,STACK_FRAME_OVERHEAD; \
  317. EXC_XFER_EE_LITE(0x800, KernelFP)
  318. #endif /* __HEAD_BOOKE_H__ */