mca_asm.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. * Copyright (C) 2005 Silicon Graphics, Inc
  12. * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
  13. */
  14. #ifndef _ASM_IA64_MCA_ASM_H
  15. #define _ASM_IA64_MCA_ASM_H
  16. #define PSR_IC 13
  17. #define PSR_I 14
  18. #define PSR_DT 17
  19. #define PSR_RT 27
  20. #define PSR_MC 35
  21. #define PSR_IT 36
  22. #define PSR_BN 44
  23. /*
  24. * This macro converts a instruction virtual address to a physical address
  25. * Right now for simulation purposes the virtual addresses are
  26. * direct mapped to physical addresses.
  27. * 1. Lop off bits 61 thru 63 in the virtual address
  28. */
  29. #define INST_VA_TO_PA(addr) \
  30. dep addr = 0, addr, 61, 3
  31. /*
  32. * This macro converts a data virtual address to a physical address
  33. * Right now for simulation purposes the virtual addresses are
  34. * direct mapped to physical addresses.
  35. * 1. Lop off bits 61 thru 63 in the virtual address
  36. */
  37. #define DATA_VA_TO_PA(addr) \
  38. tpa addr = addr
  39. /*
  40. * This macro converts a data physical address to a virtual address
  41. * Right now for simulation purposes the virtual addresses are
  42. * direct mapped to physical addresses.
  43. * 1. Put 0x7 in bits 61 thru 63.
  44. */
  45. #define DATA_PA_TO_VA(addr,temp) \
  46. mov temp = 0x7 ;; \
  47. dep addr = temp, addr, 61, 3
  48. #define GET_THIS_PADDR(reg, var) \
  49. mov reg = IA64_KR(PER_CPU_DATA);; \
  50. addl reg = THIS_CPU(var), reg
  51. /*
  52. * This macro jumps to the instruction at the given virtual address
  53. * and starts execution in physical mode with all the address
  54. * translations turned off.
  55. * 1. Save the current psr
  56. * 2. Make sure that all the upper 32 bits are off
  57. *
  58. * 3. Clear the interrupt enable and interrupt state collection bits
  59. * in the psr before updating the ipsr and iip.
  60. *
  61. * 4. Turn off the instruction, data and rse translation bits of the psr
  62. * and store the new value into ipsr
  63. * Also make sure that the interrupts are disabled.
  64. * Ensure that we are in little endian mode.
  65. * [psr.{rt, it, dt, i, be} = 0]
  66. *
  67. * 5. Get the physical address corresponding to the virtual address
  68. * of the next instruction bundle and put it in iip.
  69. * (Using magic numbers 24 and 40 in the deposint instruction since
  70. * the IA64_SDK code directly maps to lower 24bits as physical address
  71. * from a virtual address).
  72. *
  73. * 6. Do an rfi to move the values from ipsr to psr and iip to ip.
  74. */
  75. #define PHYSICAL_MODE_ENTER(temp1, temp2, start_addr, old_psr) \
  76. mov old_psr = psr; \
  77. ;; \
  78. dep old_psr = 0, old_psr, 32, 32; \
  79. \
  80. mov ar.rsc = 0 ; \
  81. ;; \
  82. srlz.d; \
  83. mov temp2 = ar.bspstore; \
  84. ;; \
  85. DATA_VA_TO_PA(temp2); \
  86. ;; \
  87. mov temp1 = ar.rnat; \
  88. ;; \
  89. mov ar.bspstore = temp2; \
  90. ;; \
  91. mov ar.rnat = temp1; \
  92. mov temp1 = psr; \
  93. mov temp2 = psr; \
  94. ;; \
  95. \
  96. dep temp2 = 0, temp2, PSR_IC, 2; \
  97. ;; \
  98. mov psr.l = temp2; \
  99. ;; \
  100. srlz.d; \
  101. dep temp1 = 0, temp1, 32, 32; \
  102. ;; \
  103. dep temp1 = 0, temp1, PSR_IT, 1; \
  104. ;; \
  105. dep temp1 = 0, temp1, PSR_DT, 1; \
  106. ;; \
  107. dep temp1 = 0, temp1, PSR_RT, 1; \
  108. ;; \
  109. dep temp1 = 0, temp1, PSR_I, 1; \
  110. ;; \
  111. dep temp1 = 0, temp1, PSR_IC, 1; \
  112. ;; \
  113. dep temp1 = -1, temp1, PSR_MC, 1; \
  114. ;; \
  115. mov cr.ipsr = temp1; \
  116. ;; \
  117. LOAD_PHYSICAL(p0, temp2, start_addr); \
  118. ;; \
  119. mov cr.iip = temp2; \
  120. mov cr.ifs = r0; \
  121. DATA_VA_TO_PA(sp); \
  122. DATA_VA_TO_PA(gp); \
  123. ;; \
  124. srlz.i; \
  125. ;; \
  126. nop 1; \
  127. nop 2; \
  128. nop 1; \
  129. nop 2; \
  130. rfi; \
  131. ;;
  132. /*
  133. * This macro jumps to the instruction at the given virtual address
  134. * and starts execution in virtual mode with all the address
  135. * translations turned on.
  136. * 1. Get the old saved psr
  137. *
  138. * 2. Clear the interrupt state collection bit in the current psr.
  139. *
  140. * 3. Set the instruction translation bit back in the old psr
  141. * Note we have to do this since we are right now saving only the
  142. * lower 32-bits of old psr.(Also the old psr has the data and
  143. * rse translation bits on)
  144. *
  145. * 4. Set ipsr to this old_psr with "it" bit set and "bn" = 1.
  146. *
  147. * 5. Reset the current thread pointer (r13).
  148. *
  149. * 6. Set iip to the virtual address of the next instruction bundle.
  150. *
  151. * 7. Do an rfi to move ipsr to psr and iip to ip.
  152. */
  153. #define VIRTUAL_MODE_ENTER(temp1, temp2, start_addr, old_psr) \
  154. mov temp2 = psr; \
  155. ;; \
  156. mov old_psr = temp2; \
  157. ;; \
  158. dep temp2 = 0, temp2, PSR_IC, 2; \
  159. ;; \
  160. mov psr.l = temp2; \
  161. mov ar.rsc = 0; \
  162. ;; \
  163. srlz.d; \
  164. mov r13 = ar.k6; \
  165. mov temp2 = ar.bspstore; \
  166. ;; \
  167. DATA_PA_TO_VA(temp2,temp1); \
  168. ;; \
  169. mov temp1 = ar.rnat; \
  170. ;; \
  171. mov ar.bspstore = temp2; \
  172. ;; \
  173. mov ar.rnat = temp1; \
  174. ;; \
  175. mov temp1 = old_psr; \
  176. ;; \
  177. mov temp2 = 1; \
  178. ;; \
  179. dep temp1 = temp2, temp1, PSR_IC, 1; \
  180. ;; \
  181. dep temp1 = temp2, temp1, PSR_IT, 1; \
  182. ;; \
  183. dep temp1 = temp2, temp1, PSR_DT, 1; \
  184. ;; \
  185. dep temp1 = temp2, temp1, PSR_RT, 1; \
  186. ;; \
  187. dep temp1 = temp2, temp1, PSR_BN, 1; \
  188. ;; \
  189. \
  190. mov cr.ipsr = temp1; \
  191. movl temp2 = start_addr; \
  192. ;; \
  193. mov cr.iip = temp2; \
  194. movl gp = __gp \
  195. ;; \
  196. DATA_PA_TO_VA(sp, temp1); \
  197. srlz.i; \
  198. ;; \
  199. nop 1; \
  200. nop 2; \
  201. nop 1; \
  202. rfi \
  203. ;;
  204. /*
  205. * The MCA and INIT stacks in struct ia64_mca_cpu look like normal kernel
  206. * stacks, except that the SAL/OS state and a switch_stack are stored near the
  207. * top of the MCA/INIT stack. To support concurrent entry to MCA or INIT, as
  208. * well as MCA over INIT, each event needs its own SAL/OS state. All entries
  209. * are 16 byte aligned.
  210. *
  211. * +---------------------------+
  212. * | pt_regs |
  213. * +---------------------------+
  214. * | switch_stack |
  215. * +---------------------------+
  216. * | SAL/OS state |
  217. * +---------------------------+
  218. * | 16 byte scratch area |
  219. * +---------------------------+ <-------- SP at start of C MCA handler
  220. * | ..... |
  221. * +---------------------------+
  222. * | RBS for MCA/INIT handler |
  223. * +---------------------------+
  224. * | struct task for MCA/INIT |
  225. * +---------------------------+ <-------- Bottom of MCA/INIT stack
  226. */
  227. #define ALIGN16(x) ((x)&~15)
  228. #define MCA_PT_REGS_OFFSET ALIGN16(KERNEL_STACK_SIZE-IA64_PT_REGS_SIZE)
  229. #define MCA_SWITCH_STACK_OFFSET ALIGN16(MCA_PT_REGS_OFFSET-IA64_SWITCH_STACK_SIZE)
  230. #define MCA_SOS_OFFSET ALIGN16(MCA_SWITCH_STACK_OFFSET-IA64_SAL_OS_STATE_SIZE)
  231. #define MCA_SP_OFFSET ALIGN16(MCA_SOS_OFFSET-16)
  232. #endif /* _ASM_IA64_MCA_ASM_H */