mca_asm.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * File: mca_asm.h
  3. *
  4. * Copyright (C) 1999 Silicon Graphics, Inc.
  5. * Copyright (C) Vijay Chander (vijay@engr.sgi.com)
  6. * Copyright (C) Srinivasa Thirumalachar <sprasad@engr.sgi.com>
  7. * Copyright (C) 2000 Hewlett-Packard Co.
  8. * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
  9. * Copyright (C) 2002 Intel Corp.
  10. * Copyright (C) 2002 Jenna Hall <jenna.s.hall@intel.com>
  11. */
  12. #ifndef _ASM_IA64_MCA_ASM_H
  13. #define _ASM_IA64_MCA_ASM_H
  14. #define PSR_IC 13
  15. #define PSR_I 14
  16. #define PSR_DT 17
  17. #define PSR_RT 27
  18. #define PSR_MC 35
  19. #define PSR_IT 36
  20. #define PSR_BN 44
  21. /*
  22. * This macro converts a instruction virtual address to a physical address
  23. * Right now for simulation purposes the virtual addresses are
  24. * direct mapped to physical addresses.
  25. * 1. Lop off bits 61 thru 63 in the virtual address
  26. */
  27. #define INST_VA_TO_PA(addr) \
  28. dep addr = 0, addr, 61, 3
  29. /*
  30. * This macro converts a data virtual address to a physical address
  31. * Right now for simulation purposes the virtual addresses are
  32. * direct mapped to physical addresses.
  33. * 1. Lop off bits 61 thru 63 in the virtual address
  34. */
  35. #define DATA_VA_TO_PA(addr) \
  36. tpa addr = addr
  37. /*
  38. * This macro converts a data physical address to a virtual address
  39. * Right now for simulation purposes the virtual addresses are
  40. * direct mapped to physical addresses.
  41. * 1. Put 0x7 in bits 61 thru 63.
  42. */
  43. #define DATA_PA_TO_VA(addr,temp) \
  44. mov temp = 0x7 ;; \
  45. dep addr = temp, addr, 61, 3
  46. #define GET_THIS_PADDR(reg, var) \
  47. mov reg = IA64_KR(PER_CPU_DATA);; \
  48. addl reg = THIS_CPU(var), reg
  49. /*
  50. * This macro jumps to the instruction at the given virtual address
  51. * and starts execution in physical mode with all the address
  52. * translations turned off.
  53. * 1. Save the current psr
  54. * 2. Make sure that all the upper 32 bits are off
  55. *
  56. * 3. Clear the interrupt enable and interrupt state collection bits
  57. * in the psr before updating the ipsr and iip.
  58. *
  59. * 4. Turn off the instruction, data and rse translation bits of the psr
  60. * and store the new value into ipsr
  61. * Also make sure that the interrupts are disabled.
  62. * Ensure that we are in little endian mode.
  63. * [psr.{rt, it, dt, i, be} = 0]
  64. *
  65. * 5. Get the physical address corresponding to the virtual address
  66. * of the next instruction bundle and put it in iip.
  67. * (Using magic numbers 24 and 40 in the deposint instruction since
  68. * the IA64_SDK code directly maps to lower 24bits as physical address
  69. * from a virtual address).
  70. *
  71. * 6. Do an rfi to move the values from ipsr to psr and iip to ip.
  72. */
  73. #define PHYSICAL_MODE_ENTER(temp1, temp2, start_addr, old_psr) \
  74. mov old_psr = psr; \
  75. ;; \
  76. dep old_psr = 0, old_psr, 32, 32; \
  77. \
  78. mov ar.rsc = 0 ; \
  79. ;; \
  80. srlz.d; \
  81. mov temp2 = ar.bspstore; \
  82. ;; \
  83. DATA_VA_TO_PA(temp2); \
  84. ;; \
  85. mov temp1 = ar.rnat; \
  86. ;; \
  87. mov ar.bspstore = temp2; \
  88. ;; \
  89. mov ar.rnat = temp1; \
  90. mov temp1 = psr; \
  91. mov temp2 = psr; \
  92. ;; \
  93. \
  94. dep temp2 = 0, temp2, PSR_IC, 2; \
  95. ;; \
  96. mov psr.l = temp2; \
  97. ;; \
  98. srlz.d; \
  99. dep temp1 = 0, temp1, 32, 32; \
  100. ;; \
  101. dep temp1 = 0, temp1, PSR_IT, 1; \
  102. ;; \
  103. dep temp1 = 0, temp1, PSR_DT, 1; \
  104. ;; \
  105. dep temp1 = 0, temp1, PSR_RT, 1; \
  106. ;; \
  107. dep temp1 = 0, temp1, PSR_I, 1; \
  108. ;; \
  109. dep temp1 = 0, temp1, PSR_IC, 1; \
  110. ;; \
  111. dep temp1 = -1, temp1, PSR_MC, 1; \
  112. ;; \
  113. mov cr.ipsr = temp1; \
  114. ;; \
  115. LOAD_PHYSICAL(p0, temp2, start_addr); \
  116. ;; \
  117. mov cr.iip = temp2; \
  118. mov cr.ifs = r0; \
  119. DATA_VA_TO_PA(sp); \
  120. DATA_VA_TO_PA(gp); \
  121. ;; \
  122. srlz.i; \
  123. ;; \
  124. nop 1; \
  125. nop 2; \
  126. nop 1; \
  127. nop 2; \
  128. rfi; \
  129. ;;
  130. /*
  131. * This macro jumps to the instruction at the given virtual address
  132. * and starts execution in virtual mode with all the address
  133. * translations turned on.
  134. * 1. Get the old saved psr
  135. *
  136. * 2. Clear the interrupt state collection bit in the current psr.
  137. *
  138. * 3. Set the instruction translation bit back in the old psr
  139. * Note we have to do this since we are right now saving only the
  140. * lower 32-bits of old psr.(Also the old psr has the data and
  141. * rse translation bits on)
  142. *
  143. * 4. Set ipsr to this old_psr with "it" bit set and "bn" = 1.
  144. *
  145. * 5. Reset the current thread pointer (r13).
  146. *
  147. * 6. Set iip to the virtual address of the next instruction bundle.
  148. *
  149. * 7. Do an rfi to move ipsr to psr and iip to ip.
  150. */
  151. #define VIRTUAL_MODE_ENTER(temp1, temp2, start_addr, old_psr) \
  152. mov temp2 = psr; \
  153. ;; \
  154. mov old_psr = temp2; \
  155. ;; \
  156. dep temp2 = 0, temp2, PSR_IC, 2; \
  157. ;; \
  158. mov psr.l = temp2; \
  159. mov ar.rsc = 0; \
  160. ;; \
  161. srlz.d; \
  162. mov r13 = ar.k6; \
  163. mov temp2 = ar.bspstore; \
  164. ;; \
  165. DATA_PA_TO_VA(temp2,temp1); \
  166. ;; \
  167. mov temp1 = ar.rnat; \
  168. ;; \
  169. mov ar.bspstore = temp2; \
  170. ;; \
  171. mov ar.rnat = temp1; \
  172. ;; \
  173. mov temp1 = old_psr; \
  174. ;; \
  175. mov temp2 = 1; \
  176. ;; \
  177. dep temp1 = temp2, temp1, PSR_IC, 1; \
  178. ;; \
  179. dep temp1 = temp2, temp1, PSR_IT, 1; \
  180. ;; \
  181. dep temp1 = temp2, temp1, PSR_DT, 1; \
  182. ;; \
  183. dep temp1 = temp2, temp1, PSR_RT, 1; \
  184. ;; \
  185. dep temp1 = temp2, temp1, PSR_BN, 1; \
  186. ;; \
  187. \
  188. mov cr.ipsr = temp1; \
  189. movl temp2 = start_addr; \
  190. ;; \
  191. mov cr.iip = temp2; \
  192. ;; \
  193. DATA_PA_TO_VA(sp, temp1); \
  194. DATA_PA_TO_VA(gp, temp2); \
  195. srlz.i; \
  196. ;; \
  197. nop 1; \
  198. nop 2; \
  199. nop 1; \
  200. rfi \
  201. ;;
  202. /*
  203. * The following offsets capture the order in which the
  204. * RSE related registers from the old context are
  205. * saved onto the new stack frame.
  206. *
  207. * +-----------------------+
  208. * |NDIRTY [BSP - BSPSTORE]|
  209. * +-----------------------+
  210. * | RNAT |
  211. * +-----------------------+
  212. * | BSPSTORE |
  213. * +-----------------------+
  214. * | IFS |
  215. * +-----------------------+
  216. * | PFS |
  217. * +-----------------------+
  218. * | RSC |
  219. * +-----------------------+ <-------- Bottom of new stack frame
  220. */
  221. #define rse_rsc_offset 0
  222. #define rse_pfs_offset (rse_rsc_offset+0x08)
  223. #define rse_ifs_offset (rse_pfs_offset+0x08)
  224. #define rse_bspstore_offset (rse_ifs_offset+0x08)
  225. #define rse_rnat_offset (rse_bspstore_offset+0x08)
  226. #define rse_ndirty_offset (rse_rnat_offset+0x08)
  227. /*
  228. * rse_switch_context
  229. *
  230. * 1. Save old RSC onto the new stack frame
  231. * 2. Save PFS onto new stack frame
  232. * 3. Cover the old frame and start a new frame.
  233. * 4. Save IFS onto new stack frame
  234. * 5. Save the old BSPSTORE on the new stack frame
  235. * 6. Save the old RNAT on the new stack frame
  236. * 7. Write BSPSTORE with the new backing store pointer
  237. * 8. Read and save the new BSP to calculate the #dirty registers
  238. * NOTE: Look at pages 11-10, 11-11 in PRM Vol 2
  239. */
  240. #define rse_switch_context(temp,p_stackframe,p_bspstore) \
  241. ;; \
  242. mov temp=ar.rsc;; \
  243. st8 [p_stackframe]=temp,8;; \
  244. mov temp=ar.pfs;; \
  245. st8 [p_stackframe]=temp,8; \
  246. cover ;; \
  247. mov temp=cr.ifs;; \
  248. st8 [p_stackframe]=temp,8;; \
  249. mov temp=ar.bspstore;; \
  250. st8 [p_stackframe]=temp,8;; \
  251. mov temp=ar.rnat;; \
  252. st8 [p_stackframe]=temp,8; \
  253. mov ar.bspstore=p_bspstore;; \
  254. mov temp=ar.bsp;; \
  255. sub temp=temp,p_bspstore;; \
  256. st8 [p_stackframe]=temp,8;;
  257. /*
  258. * rse_return_context
  259. * 1. Allocate a zero-sized frame
  260. * 2. Store the number of dirty registers RSC.loadrs field
  261. * 3. Issue a loadrs to insure that any registers from the interrupted
  262. * context which were saved on the new stack frame have been loaded
  263. * back into the stacked registers
  264. * 4. Restore BSPSTORE
  265. * 5. Restore RNAT
  266. * 6. Restore PFS
  267. * 7. Restore IFS
  268. * 8. Restore RSC
  269. * 9. Issue an RFI
  270. */
  271. #define rse_return_context(psr_mask_reg,temp,p_stackframe) \
  272. ;; \
  273. alloc temp=ar.pfs,0,0,0,0; \
  274. add p_stackframe=rse_ndirty_offset,p_stackframe;; \
  275. ld8 temp=[p_stackframe];; \
  276. shl temp=temp,16;; \
  277. mov ar.rsc=temp;; \
  278. loadrs;; \
  279. add p_stackframe=-rse_ndirty_offset+rse_bspstore_offset,p_stackframe;;\
  280. ld8 temp=[p_stackframe];; \
  281. mov ar.bspstore=temp;; \
  282. add p_stackframe=-rse_bspstore_offset+rse_rnat_offset,p_stackframe;;\
  283. ld8 temp=[p_stackframe];; \
  284. mov ar.rnat=temp;; \
  285. add p_stackframe=-rse_rnat_offset+rse_pfs_offset,p_stackframe;; \
  286. ld8 temp=[p_stackframe];; \
  287. mov ar.pfs=temp;; \
  288. add p_stackframe=-rse_pfs_offset+rse_ifs_offset,p_stackframe;; \
  289. ld8 temp=[p_stackframe];; \
  290. mov cr.ifs=temp;; \
  291. add p_stackframe=-rse_ifs_offset+rse_rsc_offset,p_stackframe;; \
  292. ld8 temp=[p_stackframe];; \
  293. mov ar.rsc=temp ; \
  294. mov temp=psr;; \
  295. or temp=temp,psr_mask_reg;; \
  296. mov cr.ipsr=temp;; \
  297. mov temp=ip;; \
  298. add temp=0x30,temp;; \
  299. mov cr.iip=temp;; \
  300. srlz.i;; \
  301. rfi;;
  302. #endif /* _ASM_IA64_MCA_ASM_H */