exception-64e.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Definitions for use by exception code on Book3-E
  3. *
  4. * Copyright (C) 2008 Ben. Herrenschmidt (benh@kernel.crashing.org), IBM Corp.
  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. #ifndef _ASM_POWERPC_EXCEPTION_64E_H
  12. #define _ASM_POWERPC_EXCEPTION_64E_H
  13. /*
  14. * SPRGs usage an other considerations...
  15. *
  16. * Since TLB miss and other standard exceptions can be interrupted by
  17. * critical exceptions which can themselves be interrupted by machine
  18. * checks, and since the two later can themselves cause a TLB miss when
  19. * hitting the linear mapping for the kernel stacks, we need to be a bit
  20. * creative on how we use SPRGs.
  21. *
  22. * The base idea is that we have one SRPG reserved for critical and one
  23. * for machine check interrupts. Those are used to save a GPR that can
  24. * then be used to get the PACA, and store as much context as we need
  25. * to save in there. That includes saving the SPRGs used by the TLB miss
  26. * handler for linear mapping misses and the associated SRR0/1 due to
  27. * the above re-entrancy issue.
  28. *
  29. * So here's the current usage pattern. It's done regardless of which
  30. * SPRGs are user-readable though, thus we might have to change some of
  31. * this later. In order to do that more easily, we use special constants
  32. * for naming them
  33. *
  34. * WARNING: Some of these SPRGs are user readable. We need to do something
  35. * about it as some point by making sure they can't be used to leak kernel
  36. * critical data
  37. */
  38. /* We are out of SPRGs so we save some things in the PACA. The normal
  39. * exception frame is smaller than the CRIT or MC one though
  40. */
  41. #define EX_R1 (0 * 8)
  42. #define EX_CR (1 * 8)
  43. #define EX_R10 (2 * 8)
  44. #define EX_R11 (3 * 8)
  45. #define EX_R14 (4 * 8)
  46. #define EX_R15 (5 * 8)
  47. /* The TLB miss exception uses different slots */
  48. #define EX_TLB_R10 ( 0 * 8)
  49. #define EX_TLB_R11 ( 1 * 8)
  50. #define EX_TLB_R12 ( 2 * 8)
  51. #define EX_TLB_R13 ( 3 * 8)
  52. #define EX_TLB_R14 ( 4 * 8)
  53. #define EX_TLB_R15 ( 5 * 8)
  54. #define EX_TLB_R16 ( 6 * 8)
  55. #define EX_TLB_CR ( 7 * 8)
  56. #define EX_TLB_DEAR ( 8 * 8) /* Level 0 and 2 only */
  57. #define EX_TLB_ESR ( 9 * 8) /* Level 0 and 2 only */
  58. #define EX_TLB_SRR0 (10 * 8)
  59. #define EX_TLB_SRR1 (11 * 8)
  60. #define EX_TLB_MMUCR0 (12 * 8) /* Level 0 */
  61. #define EX_TLB_MAS1 (12 * 8) /* Level 0 */
  62. #define EX_TLB_MAS2 (13 * 8) /* Level 0 */
  63. #ifdef CONFIG_BOOK3E_MMU_TLB_STATS
  64. #define EX_TLB_R8 (14 * 8)
  65. #define EX_TLB_R9 (15 * 8)
  66. #define EX_TLB_LR (16 * 8)
  67. #define EX_TLB_SIZE (17 * 8)
  68. #else
  69. #define EX_TLB_SIZE (14 * 8)
  70. #endif
  71. #define START_EXCEPTION(label) \
  72. .globl exc_##label##_book3e; \
  73. exc_##label##_book3e:
  74. /* TLB miss exception prolog
  75. *
  76. * This prolog handles re-entrancy (up to 3 levels supported in the PACA
  77. * though we currently don't test for overflow). It provides you with a
  78. * re-entrancy safe working space of r10...r16 and CR with r12 being used
  79. * as the exception area pointer in the PACA for that level of re-entrancy
  80. * and r13 containing the PACA pointer.
  81. *
  82. * SRR0 and SRR1 are saved, but DEAR and ESR are not, since they don't apply
  83. * as-is for instruction exceptions. It's up to the actual exception code
  84. * to save them as well if required.
  85. */
  86. #define TLB_MISS_PROLOG \
  87. mtspr SPRN_SPRG_TLB_SCRATCH,r12; \
  88. mfspr r12,SPRN_SPRG_TLB_EXFRAME; \
  89. std r10,EX_TLB_R10(r12); \
  90. mfcr r10; \
  91. std r11,EX_TLB_R11(r12); \
  92. mfspr r11,SPRN_SPRG_TLB_SCRATCH; \
  93. std r13,EX_TLB_R13(r12); \
  94. mfspr r13,SPRN_SPRG_PACA; \
  95. std r14,EX_TLB_R14(r12); \
  96. addi r14,r12,EX_TLB_SIZE; \
  97. std r15,EX_TLB_R15(r12); \
  98. mfspr r15,SPRN_SRR1; \
  99. std r16,EX_TLB_R16(r12); \
  100. mfspr r16,SPRN_SRR0; \
  101. std r10,EX_TLB_CR(r12); \
  102. std r11,EX_TLB_R12(r12); \
  103. mtspr SPRN_SPRG_TLB_EXFRAME,r14; \
  104. std r15,EX_TLB_SRR1(r12); \
  105. std r16,EX_TLB_SRR0(r12); \
  106. TLB_MISS_PROLOG_STATS
  107. /* And these are the matching epilogs that restores things
  108. *
  109. * There are 3 epilogs:
  110. *
  111. * - SUCCESS : Unwinds one level
  112. * - ERROR : restore from level 0 and reset
  113. * - ERROR_SPECIAL : restore from current level and reset
  114. *
  115. * Normal errors use ERROR, that is, they restore the initial fault context
  116. * and trigger a fault. However, there is a special case for linear mapping
  117. * errors. Those should basically never happen, but if they do happen, we
  118. * want the error to point out the context that did that linear mapping
  119. * fault, not the initial level 0 (basically, we got a bogus PGF or something
  120. * like that). For userland errors on the linear mapping, there is no
  121. * difference since those are always level 0 anyway
  122. */
  123. #define TLB_MISS_RESTORE(freg) \
  124. ld r14,EX_TLB_CR(r12); \
  125. ld r10,EX_TLB_R10(r12); \
  126. ld r15,EX_TLB_SRR0(r12); \
  127. ld r16,EX_TLB_SRR1(r12); \
  128. mtspr SPRN_SPRG_TLB_EXFRAME,freg; \
  129. ld r11,EX_TLB_R11(r12); \
  130. mtcr r14; \
  131. ld r13,EX_TLB_R13(r12); \
  132. ld r14,EX_TLB_R14(r12); \
  133. mtspr SPRN_SRR0,r15; \
  134. ld r15,EX_TLB_R15(r12); \
  135. mtspr SPRN_SRR1,r16; \
  136. TLB_MISS_RESTORE_STATS \
  137. ld r16,EX_TLB_R16(r12); \
  138. ld r12,EX_TLB_R12(r12); \
  139. #define TLB_MISS_EPILOG_SUCCESS \
  140. TLB_MISS_RESTORE(r12)
  141. #define TLB_MISS_EPILOG_ERROR \
  142. addi r12,r13,PACA_EXTLB; \
  143. TLB_MISS_RESTORE(r12)
  144. #define TLB_MISS_EPILOG_ERROR_SPECIAL \
  145. addi r11,r13,PACA_EXTLB; \
  146. TLB_MISS_RESTORE(r11)
  147. #ifdef CONFIG_BOOK3E_MMU_TLB_STATS
  148. #define TLB_MISS_PROLOG_STATS \
  149. mflr r10; \
  150. std r8,EX_TLB_R8(r12); \
  151. std r9,EX_TLB_R9(r12); \
  152. std r10,EX_TLB_LR(r12);
  153. #define TLB_MISS_RESTORE_STATS \
  154. ld r16,EX_TLB_LR(r12); \
  155. ld r9,EX_TLB_R9(r12); \
  156. ld r8,EX_TLB_R8(r12); \
  157. mtlr r16;
  158. #define TLB_MISS_STATS_D(name) \
  159. addi r9,r13,MMSTAT_DSTATS+name; \
  160. bl .tlb_stat_inc;
  161. #define TLB_MISS_STATS_I(name) \
  162. addi r9,r13,MMSTAT_ISTATS+name; \
  163. bl .tlb_stat_inc;
  164. #define TLB_MISS_STATS_X(name) \
  165. ld r8,PACA_EXTLB+EX_TLB_ESR(r13); \
  166. cmpdi cr2,r8,-1; \
  167. beq cr2,61f; \
  168. addi r9,r13,MMSTAT_DSTATS+name; \
  169. b 62f; \
  170. 61: addi r9,r13,MMSTAT_ISTATS+name; \
  171. 62: bl .tlb_stat_inc;
  172. #define TLB_MISS_STATS_SAVE_INFO \
  173. std r14,EX_TLB_ESR(r12); /* save ESR */ \
  174. #else
  175. #define TLB_MISS_PROLOG_STATS
  176. #define TLB_MISS_RESTORE_STATS
  177. #define TLB_MISS_STATS_D(name)
  178. #define TLB_MISS_STATS_I(name)
  179. #define TLB_MISS_STATS_X(name)
  180. #define TLB_MISS_STATS_Y(name)
  181. #define TLB_MISS_STATS_SAVE_INFO
  182. #endif
  183. #define SET_IVOR(vector_number, vector_offset) \
  184. li r3,vector_offset@l; \
  185. ori r3,r3,interrupt_base_book3e@l; \
  186. mtspr SPRN_IVOR##vector_number,r3;
  187. #endif /* _ASM_POWERPC_EXCEPTION_64E_H */