minstate.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #include <asm/cache.h>
  2. #include "entry.h"
  3. #include <asm/native/inst.h>
  4. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  5. /* read ar.itc in advance, and use it before leaving bank 0 */
  6. #define ACCOUNT_GET_STAMP \
  7. (pUStk) mov.m r20=ar.itc;
  8. #define ACCOUNT_SYS_ENTER \
  9. (pUStk) br.call.spnt rp=account_sys_enter \
  10. ;;
  11. #else
  12. #define ACCOUNT_GET_STAMP
  13. #define ACCOUNT_SYS_ENTER
  14. #endif
  15. .section ".data..patch.rse", "a"
  16. .previous
  17. /*
  18. * DO_SAVE_MIN switches to the kernel stacks (if necessary) and saves
  19. * the minimum state necessary that allows us to turn psr.ic back
  20. * on.
  21. *
  22. * Assumed state upon entry:
  23. * psr.ic: off
  24. * r31: contains saved predicates (pr)
  25. *
  26. * Upon exit, the state is as follows:
  27. * psr.ic: off
  28. * r2 = points to &pt_regs.r16
  29. * r8 = contents of ar.ccv
  30. * r9 = contents of ar.csd
  31. * r10 = contents of ar.ssd
  32. * r11 = FPSR_DEFAULT
  33. * r12 = kernel sp (kernel virtual address)
  34. * r13 = points to current task_struct (kernel virtual address)
  35. * p15 = TRUE if psr.i is set in cr.ipsr
  36. * predicate registers (other than p2, p3, and p15), b6, r3, r14, r15:
  37. * preserved
  38. *
  39. * Note that psr.ic is NOT turned on by this macro. This is so that
  40. * we can pass interruption state as arguments to a handler.
  41. */
  42. #define IA64_NATIVE_DO_SAVE_MIN(__COVER,SAVE_IFS,EXTRA,WORKAROUND) \
  43. mov r16=IA64_KR(CURRENT); /* M */ \
  44. mov r27=ar.rsc; /* M */ \
  45. mov r20=r1; /* A */ \
  46. mov r25=ar.unat; /* M */ \
  47. MOV_FROM_IPSR(p0,r29); /* M */ \
  48. mov r26=ar.pfs; /* I */ \
  49. MOV_FROM_IIP(r28); /* M */ \
  50. mov r21=ar.fpsr; /* M */ \
  51. __COVER; /* B;; (or nothing) */ \
  52. ;; \
  53. adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16; \
  54. ;; \
  55. ld1 r17=[r16]; /* load current->thread.on_ustack flag */ \
  56. st1 [r16]=r0; /* clear current->thread.on_ustack flag */ \
  57. adds r1=-IA64_TASK_THREAD_ON_USTACK_OFFSET,r16 \
  58. /* switch from user to kernel RBS: */ \
  59. ;; \
  60. invala; /* M */ \
  61. SAVE_IFS; \
  62. cmp.eq pKStk,pUStk=r0,r17; /* are we in kernel mode already? */ \
  63. ;; \
  64. (pUStk) mov ar.rsc=0; /* set enforced lazy mode, pl 0, little-endian, loadrs=0 */ \
  65. ;; \
  66. (pUStk) mov.m r24=ar.rnat; \
  67. (pUStk) addl r22=IA64_RBS_OFFSET,r1; /* compute base of RBS */ \
  68. (pKStk) mov r1=sp; /* get sp */ \
  69. ;; \
  70. (pUStk) lfetch.fault.excl.nt1 [r22]; \
  71. (pUStk) addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r1; /* compute base of memory stack */ \
  72. (pUStk) mov r23=ar.bspstore; /* save ar.bspstore */ \
  73. ;; \
  74. (pUStk) mov ar.bspstore=r22; /* switch to kernel RBS */ \
  75. (pKStk) addl r1=-IA64_PT_REGS_SIZE,r1; /* if in kernel mode, use sp (r12) */ \
  76. ;; \
  77. (pUStk) mov r18=ar.bsp; \
  78. (pUStk) mov ar.rsc=0x3; /* set eager mode, pl 0, little-endian, loadrs=0 */ \
  79. adds r17=2*L1_CACHE_BYTES,r1; /* really: biggest cache-line size */ \
  80. adds r16=PT(CR_IPSR),r1; \
  81. ;; \
  82. lfetch.fault.excl.nt1 [r17],L1_CACHE_BYTES; \
  83. st8 [r16]=r29; /* save cr.ipsr */ \
  84. ;; \
  85. lfetch.fault.excl.nt1 [r17]; \
  86. tbit.nz p15,p0=r29,IA64_PSR_I_BIT; \
  87. mov r29=b0 \
  88. ;; \
  89. WORKAROUND; \
  90. adds r16=PT(R8),r1; /* initialize first base pointer */ \
  91. adds r17=PT(R9),r1; /* initialize second base pointer */ \
  92. (pKStk) mov r18=r0; /* make sure r18 isn't NaT */ \
  93. ;; \
  94. .mem.offset 0,0; st8.spill [r16]=r8,16; \
  95. .mem.offset 8,0; st8.spill [r17]=r9,16; \
  96. ;; \
  97. .mem.offset 0,0; st8.spill [r16]=r10,24; \
  98. .mem.offset 8,0; st8.spill [r17]=r11,24; \
  99. ;; \
  100. st8 [r16]=r28,16; /* save cr.iip */ \
  101. st8 [r17]=r30,16; /* save cr.ifs */ \
  102. (pUStk) sub r18=r18,r22; /* r18=RSE.ndirty*8 */ \
  103. mov r8=ar.ccv; \
  104. mov r9=ar.csd; \
  105. mov r10=ar.ssd; \
  106. movl r11=FPSR_DEFAULT; /* L-unit */ \
  107. ;; \
  108. st8 [r16]=r25,16; /* save ar.unat */ \
  109. st8 [r17]=r26,16; /* save ar.pfs */ \
  110. shl r18=r18,16; /* compute ar.rsc to be used for "loadrs" */ \
  111. ;; \
  112. st8 [r16]=r27,16; /* save ar.rsc */ \
  113. (pUStk) st8 [r17]=r24,16; /* save ar.rnat */ \
  114. (pKStk) adds r17=16,r17; /* skip over ar_rnat field */ \
  115. ;; /* avoid RAW on r16 & r17 */ \
  116. (pUStk) st8 [r16]=r23,16; /* save ar.bspstore */ \
  117. st8 [r17]=r31,16; /* save predicates */ \
  118. (pKStk) adds r16=16,r16; /* skip over ar_bspstore field */ \
  119. ;; \
  120. st8 [r16]=r29,16; /* save b0 */ \
  121. st8 [r17]=r18,16; /* save ar.rsc value for "loadrs" */ \
  122. cmp.eq pNonSys,pSys=r0,r0 /* initialize pSys=0, pNonSys=1 */ \
  123. ;; \
  124. .mem.offset 0,0; st8.spill [r16]=r20,16; /* save original r1 */ \
  125. .mem.offset 8,0; st8.spill [r17]=r12,16; \
  126. adds r12=-16,r1; /* switch to kernel memory stack (with 16 bytes of scratch) */ \
  127. ;; \
  128. .mem.offset 0,0; st8.spill [r16]=r13,16; \
  129. .mem.offset 8,0; st8.spill [r17]=r21,16; /* save ar.fpsr */ \
  130. mov r13=IA64_KR(CURRENT); /* establish `current' */ \
  131. ;; \
  132. .mem.offset 0,0; st8.spill [r16]=r15,16; \
  133. .mem.offset 8,0; st8.spill [r17]=r14,16; \
  134. ;; \
  135. .mem.offset 0,0; st8.spill [r16]=r2,16; \
  136. .mem.offset 8,0; st8.spill [r17]=r3,16; \
  137. ACCOUNT_GET_STAMP \
  138. adds r2=IA64_PT_REGS_R16_OFFSET,r1; \
  139. ;; \
  140. EXTRA; \
  141. movl r1=__gp; /* establish kernel global pointer */ \
  142. ;; \
  143. ACCOUNT_SYS_ENTER \
  144. bsw.1; /* switch back to bank 1 (must be last in insn group) */ \
  145. ;;
  146. /*
  147. * SAVE_REST saves the remainder of pt_regs (with psr.ic on).
  148. *
  149. * Assumed state upon entry:
  150. * psr.ic: on
  151. * r2: points to &pt_regs.r16
  152. * r3: points to &pt_regs.r17
  153. * r8: contents of ar.ccv
  154. * r9: contents of ar.csd
  155. * r10: contents of ar.ssd
  156. * r11: FPSR_DEFAULT
  157. *
  158. * Registers r14 and r15 are guaranteed not to be touched by SAVE_REST.
  159. */
  160. #define SAVE_REST \
  161. .mem.offset 0,0; st8.spill [r2]=r16,16; \
  162. .mem.offset 8,0; st8.spill [r3]=r17,16; \
  163. ;; \
  164. .mem.offset 0,0; st8.spill [r2]=r18,16; \
  165. .mem.offset 8,0; st8.spill [r3]=r19,16; \
  166. ;; \
  167. .mem.offset 0,0; st8.spill [r2]=r20,16; \
  168. .mem.offset 8,0; st8.spill [r3]=r21,16; \
  169. mov r18=b6; \
  170. ;; \
  171. .mem.offset 0,0; st8.spill [r2]=r22,16; \
  172. .mem.offset 8,0; st8.spill [r3]=r23,16; \
  173. mov r19=b7; \
  174. ;; \
  175. .mem.offset 0,0; st8.spill [r2]=r24,16; \
  176. .mem.offset 8,0; st8.spill [r3]=r25,16; \
  177. ;; \
  178. .mem.offset 0,0; st8.spill [r2]=r26,16; \
  179. .mem.offset 8,0; st8.spill [r3]=r27,16; \
  180. ;; \
  181. .mem.offset 0,0; st8.spill [r2]=r28,16; \
  182. .mem.offset 8,0; st8.spill [r3]=r29,16; \
  183. ;; \
  184. .mem.offset 0,0; st8.spill [r2]=r30,16; \
  185. .mem.offset 8,0; st8.spill [r3]=r31,32; \
  186. ;; \
  187. mov ar.fpsr=r11; /* M-unit */ \
  188. st8 [r2]=r8,8; /* ar.ccv */ \
  189. adds r24=PT(B6)-PT(F7),r3; \
  190. ;; \
  191. stf.spill [r2]=f6,32; \
  192. stf.spill [r3]=f7,32; \
  193. ;; \
  194. stf.spill [r2]=f8,32; \
  195. stf.spill [r3]=f9,32; \
  196. ;; \
  197. stf.spill [r2]=f10; \
  198. stf.spill [r3]=f11; \
  199. adds r25=PT(B7)-PT(F11),r3; \
  200. ;; \
  201. st8 [r24]=r18,16; /* b6 */ \
  202. st8 [r25]=r19,16; /* b7 */ \
  203. ;; \
  204. st8 [r24]=r9; /* ar.csd */ \
  205. st8 [r25]=r10; /* ar.ssd */ \
  206. ;;
  207. #define RSE_WORKAROUND \
  208. (pUStk) extr.u r17=r18,3,6; \
  209. (pUStk) sub r16=r18,r22; \
  210. [1:](pKStk) br.cond.sptk.many 1f; \
  211. .xdata4 ".data..patch.rse",1b-. \
  212. ;; \
  213. cmp.ge p6,p7 = 33,r17; \
  214. ;; \
  215. (p6) mov r17=0x310; \
  216. (p7) mov r17=0x308; \
  217. ;; \
  218. cmp.leu p1,p0=r16,r17; \
  219. (p1) br.cond.sptk.many 1f; \
  220. dep.z r17=r26,0,62; \
  221. movl r16=2f; \
  222. ;; \
  223. mov ar.pfs=r17; \
  224. dep r27=r0,r27,16,14; \
  225. mov b0=r16; \
  226. ;; \
  227. br.ret.sptk b0; \
  228. ;; \
  229. 2: \
  230. mov ar.rsc=r0 \
  231. ;; \
  232. flushrs; \
  233. ;; \
  234. mov ar.bspstore=r22 \
  235. ;; \
  236. mov r18=ar.bsp; \
  237. ;; \
  238. 1: \
  239. .pred.rel "mutex", pKStk, pUStk
  240. #define SAVE_MIN_WITH_COVER DO_SAVE_MIN(COVER, mov r30=cr.ifs, , RSE_WORKAROUND)
  241. #define SAVE_MIN_WITH_COVER_R19 DO_SAVE_MIN(COVER, mov r30=cr.ifs, mov r15=r19, RSE_WORKAROUND)
  242. #define SAVE_MIN DO_SAVE_MIN( , mov r30=r0, , )