mipsmtregs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * MT regs definitions, follows on from mipsregs.h
  3. * Copyright (C) 2004 - 2005 MIPS Technologies, Inc. All rights reserved.
  4. * Elizabeth Clarke et. al.
  5. *
  6. */
  7. #ifndef _ASM_MIPSMTREGS_H
  8. #define _ASM_MIPSMTREGS_H
  9. #include <asm/mipsregs.h>
  10. #include <asm/war.h>
  11. #ifndef __ASSEMBLY__
  12. /*
  13. * C macros
  14. */
  15. #define read_c0_mvpcontrol() __read_32bit_c0_register($0, 1)
  16. #define write_c0_mvpcontrol(val) __write_32bit_c0_register($0, 1, val)
  17. #define read_c0_mvpconf0() __read_32bit_c0_register($0, 2)
  18. #define read_c0_mvpconf1() __read_32bit_c0_register($0, 3)
  19. #define read_c0_vpecontrol() __read_32bit_c0_register($1, 1)
  20. #define write_c0_vpecontrol(val) __write_32bit_c0_register($1, 1, val)
  21. #define read_c0_vpeconf0() __read_32bit_c0_register($1, 2)
  22. #define write_c0_vpeconf0(val) __write_32bit_c0_register($1, 2, val)
  23. #define read_c0_vpeconf1() __read_32bit_c0_register($1, 3)
  24. #define write_c0_vpeconf1(val) __write_32bit_c0_register($1, 3, val)
  25. #define read_c0_tcstatus() __read_32bit_c0_register($2, 1)
  26. #define write_c0_tcstatus(val) __write_32bit_c0_register($2, 1, val)
  27. #define read_c0_tcbind() __read_32bit_c0_register($2, 2)
  28. #define read_c0_tccontext() __read_32bit_c0_register($2, 5)
  29. #define write_c0_tccontext(val) __write_32bit_c0_register($2, 5, val)
  30. #else /* Assembly */
  31. /*
  32. * Macros for use in assembly language code
  33. */
  34. #define CP0_MVPCONTROL $0, 1
  35. #define CP0_MVPCONF0 $0, 2
  36. #define CP0_MVPCONF1 $0, 3
  37. #define CP0_VPECONTROL $1, 1
  38. #define CP0_VPECONF0 $1, 2
  39. #define CP0_VPECONF1 $1, 3
  40. #define CP0_YQMASK $1, 4
  41. #define CP0_VPESCHEDULE $1, 5
  42. #define CP0_VPESCHEFBK $1, 6
  43. #define CP0_TCSTATUS $2, 1
  44. #define CP0_TCBIND $2, 2
  45. #define CP0_TCRESTART $2, 3
  46. #define CP0_TCHALT $2, 4
  47. #define CP0_TCCONTEXT $2, 5
  48. #define CP0_TCSCHEDULE $2, 6
  49. #define CP0_TCSCHEFBK $2, 7
  50. #define CP0_SRSCONF0 $6, 1
  51. #define CP0_SRSCONF1 $6, 2
  52. #define CP0_SRSCONF2 $6, 3
  53. #define CP0_SRSCONF3 $6, 4
  54. #define CP0_SRSCONF4 $6, 5
  55. #endif
  56. /* MVPControl fields */
  57. #define MVPCONTROL_EVP (_ULCAST_(1))
  58. #define MVPCONTROL_VPC_SHIFT 1
  59. #define MVPCONTROL_VPC (_ULCAST_(1) << MVPCONTROL_VPC_SHIFT)
  60. #define MVPCONTROL_STLB_SHIFT 2
  61. #define MVPCONTROL_STLB (_ULCAST_(1) << MVPCONTROL_STLB_SHIFT)
  62. /* MVPConf0 fields */
  63. #define MVPCONF0_PTC_SHIFT 0
  64. #define MVPCONF0_PTC ( _ULCAST_(0xff))
  65. #define MVPCONF0_PVPE_SHIFT 10
  66. #define MVPCONF0_PVPE ( _ULCAST_(0xf) << MVPCONF0_PVPE_SHIFT)
  67. #define MVPCONF0_TCA_SHIFT 15
  68. #define MVPCONF0_TCA ( _ULCAST_(1) << MVPCONF0_TCA_SHIFT)
  69. #define MVPCONF0_PTLBE_SHIFT 16
  70. #define MVPCONF0_PTLBE (_ULCAST_(0x3ff) << MVPCONF0_PTLBE_SHIFT)
  71. #define MVPCONF0_TLBS_SHIFT 29
  72. #define MVPCONF0_TLBS (_ULCAST_(1) << MVPCONF0_TLBS_SHIFT)
  73. #define MVPCONF0_M_SHIFT 31
  74. #define MVPCONF0_M (_ULCAST_(0x1) << MVPCONF0_M_SHIFT)
  75. /* config3 fields */
  76. #define CONFIG3_MT_SHIFT 2
  77. #define CONFIG3_MT (_ULCAST_(1) << CONFIG3_MT_SHIFT)
  78. /* VPEControl fields (per VPE) */
  79. #define VPECONTROL_TARGTC (_ULCAST_(0xff))
  80. #define VPECONTROL_TE_SHIFT 15
  81. #define VPECONTROL_TE (_ULCAST_(1) << VPECONTROL_TE_SHIFT)
  82. #define VPECONTROL_EXCPT_SHIFT 16
  83. #define VPECONTROL_EXCPT (_ULCAST_(0x7) << VPECONTROL_EXCPT_SHIFT)
  84. /* Thread Exception Codes for EXCPT field */
  85. #define THREX_TU 0
  86. #define THREX_TO 1
  87. #define THREX_IYQ 2
  88. #define THREX_GSX 3
  89. #define THREX_YSCH 4
  90. #define THREX_GSSCH 5
  91. #define VPECONTROL_GSI_SHIFT 20
  92. #define VPECONTROL_GSI (_ULCAST_(1) << VPECONTROL_GSI_SHIFT)
  93. #define VPECONTROL_YSI_SHIFT 21
  94. #define VPECONTROL_YSI (_ULCAST_(1) << VPECONTROL_YSI_SHIFT)
  95. /* VPEConf0 fields (per VPE) */
  96. #define VPECONF0_VPA_SHIFT 0
  97. #define VPECONF0_VPA (_ULCAST_(1) << VPECONF0_VPA_SHIFT)
  98. #define VPECONF0_MVP_SHIFT 1
  99. #define VPECONF0_MVP (_ULCAST_(1) << VPECONF0_MVP_SHIFT)
  100. #define VPECONF0_XTC_SHIFT 21
  101. #define VPECONF0_XTC (_ULCAST_(0xff) << VPECONF0_XTC_SHIFT)
  102. /* VPEConf1 fields (per VPE) */
  103. #define VPECONF1_NCP1_SHIFT 0
  104. #define VPECONF1_NCP1 (_ULCAST_(0xff) << VPECONF1_NCP1_SHIFT)
  105. #define VPECONF1_NCP2_SHIFT 10
  106. #define VPECONF1_NCP2 (_ULCAST_(0xff) << VPECONF1_NCP2_SHIFT)
  107. #define VPECONF1_NCX_SHIFT 20
  108. #define VPECONF1_NCX (_ULCAST_(0xff) << VPECONF1_NCX_SHIFT)
  109. /* TCStatus fields (per TC) */
  110. #define TCSTATUS_TASID (_ULCAST_(0xff))
  111. #define TCSTATUS_IXMT_SHIFT 10
  112. #define TCSTATUS_IXMT (_ULCAST_(1) << TCSTATUS_IXMT_SHIFT)
  113. #define TCSTATUS_TKSU_SHIFT 11
  114. #define TCSTATUS_TKSU (_ULCAST_(3) << TCSTATUS_TKSU_SHIFT)
  115. #define TCSTATUS_A_SHIFT 13
  116. #define TCSTATUS_A (_ULCAST_(1) << TCSTATUS_A_SHIFT)
  117. #define TCSTATUS_DA_SHIFT 15
  118. #define TCSTATUS_DA (_ULCAST_(1) << TCSTATUS_DA_SHIFT)
  119. #define TCSTATUS_DT_SHIFT 20
  120. #define TCSTATUS_DT (_ULCAST_(1) << TCSTATUS_DT_SHIFT)
  121. #define TCSTATUS_TDS_SHIFT 21
  122. #define TCSTATUS_TDS (_ULCAST_(1) << TCSTATUS_TDS_SHIFT)
  123. #define TCSTATUS_TSST_SHIFT 22
  124. #define TCSTATUS_TSST (_ULCAST_(1) << TCSTATUS_TSST_SHIFT)
  125. #define TCSTATUS_RNST_SHIFT 23
  126. #define TCSTATUS_RNST (_ULCAST_(3) << TCSTATUS_RNST_SHIFT)
  127. /* Codes for RNST */
  128. #define TC_RUNNING 0
  129. #define TC_WAITING 1
  130. #define TC_YIELDING 2
  131. #define TC_GATED 3
  132. #define TCSTATUS_TMX_SHIFT 27
  133. #define TCSTATUS_TMX (_ULCAST_(1) << TCSTATUS_TMX_SHIFT)
  134. /* TCStatus TCU bits can use same definitions/offsets as CU bits in Status */
  135. /* TCBind */
  136. #define TCBIND_CURVPE_SHIFT 0
  137. #define TCBIND_CURVPE (_ULCAST_(0xf))
  138. #define TCBIND_CURTC_SHIFT 21
  139. #define TCBIND_CURTC (_ULCAST_(0xff) << TCBIND_CURTC_SHIFT)
  140. /* TCHalt */
  141. #define TCHALT_H (_ULCAST_(1))
  142. #ifndef __ASSEMBLY__
  143. static inline unsigned int dvpe(void)
  144. {
  145. int res = 0;
  146. __asm__ __volatile__(
  147. " .set push \n"
  148. " .set noreorder \n"
  149. " .set noat \n"
  150. " .set mips32r2 \n"
  151. " .word 0x41610001 # dvpe $1 \n"
  152. " move %0, $1 \n"
  153. " ehb \n"
  154. " .set pop \n"
  155. : "=r" (res));
  156. instruction_hazard();
  157. return res;
  158. }
  159. static inline void __raw_evpe(void)
  160. {
  161. __asm__ __volatile__(
  162. " .set push \n"
  163. " .set noreorder \n"
  164. " .set noat \n"
  165. " .set mips32r2 \n"
  166. " .word 0x41600021 # evpe \n"
  167. " ehb \n"
  168. " .set pop \n");
  169. }
  170. /* Enable virtual processor execution if previous suggested it should be.
  171. EVPE_ENABLE to force */
  172. #define EVPE_ENABLE MVPCONTROL_EVP
  173. static inline void evpe(int previous)
  174. {
  175. if ((previous & MVPCONTROL_EVP))
  176. __raw_evpe();
  177. }
  178. static inline unsigned int dmt(void)
  179. {
  180. int res;
  181. __asm__ __volatile__(
  182. " .set push \n"
  183. " .set mips32r2 \n"
  184. " .set noat \n"
  185. " .word 0x41610BC1 # dmt $1 \n"
  186. " ehb \n"
  187. " move %0, $1 \n"
  188. " .set pop \n"
  189. : "=r" (res));
  190. instruction_hazard();
  191. return res;
  192. }
  193. static inline void __raw_emt(void)
  194. {
  195. __asm__ __volatile__(
  196. " .set noreorder \n"
  197. " .set mips32r2 \n"
  198. " .word 0x41600be1 # emt \n"
  199. " ehb \n"
  200. " .set mips0 \n"
  201. " .set reorder");
  202. }
  203. /* enable multi-threaded execution if previous suggested it should be.
  204. EMT_ENABLE to force */
  205. #define EMT_ENABLE VPECONTROL_TE
  206. static inline void emt(int previous)
  207. {
  208. if ((previous & EMT_ENABLE))
  209. __raw_emt();
  210. }
  211. static inline void ehb(void)
  212. {
  213. __asm__ __volatile__(
  214. " .set mips32r2 \n"
  215. " ehb \n"
  216. " .set mips0 \n");
  217. }
  218. #define mftc0(rt,sel) \
  219. ({ \
  220. unsigned long __res; \
  221. \
  222. __asm__ __volatile__( \
  223. " .set push \n" \
  224. " .set mips32r2 \n" \
  225. " .set noat \n" \
  226. " # mftc0 $1, $" #rt ", " #sel " \n" \
  227. " .word 0x41000800 | (" #rt " << 16) | " #sel " \n" \
  228. " move %0, $1 \n" \
  229. " .set pop \n" \
  230. : "=r" (__res)); \
  231. \
  232. __res; \
  233. })
  234. #define mftgpr(rt) \
  235. ({ \
  236. unsigned long __res; \
  237. \
  238. __asm__ __volatile__( \
  239. " .set push \n" \
  240. " .set noat \n" \
  241. " .set mips32r2 \n" \
  242. " # mftgpr $1," #rt " \n" \
  243. " .word 0x41000820 | (" #rt " << 16) \n" \
  244. " move %0, $1 \n" \
  245. " .set pop \n" \
  246. : "=r" (__res)); \
  247. \
  248. __res; \
  249. })
  250. #define mftr(rt, u, sel) \
  251. ({ \
  252. unsigned long __res; \
  253. \
  254. __asm__ __volatile__( \
  255. " mftr %0, " #rt ", " #u ", " #sel " \n" \
  256. : "=r" (__res)); \
  257. \
  258. __res; \
  259. })
  260. #define mttgpr(rd,v) \
  261. do { \
  262. __asm__ __volatile__( \
  263. " .set push \n" \
  264. " .set mips32r2 \n" \
  265. " .set noat \n" \
  266. " move $1, %0 \n" \
  267. " # mttgpr $1, " #rd " \n" \
  268. " .word 0x41810020 | (" #rd " << 11) \n" \
  269. " .set pop \n" \
  270. : : "r" (v)); \
  271. } while (0)
  272. #define mttc0(rd, sel, v) \
  273. ({ \
  274. __asm__ __volatile__( \
  275. " .set push \n" \
  276. " .set mips32r2 \n" \
  277. " .set noat \n" \
  278. " move $1, %0 \n" \
  279. " # mttc0 %0," #rd ", " #sel " \n" \
  280. " .word 0x41810000 | (" #rd " << 11) | " #sel " \n" \
  281. " .set pop \n" \
  282. : \
  283. : "r" (v)); \
  284. })
  285. #define mttr(rd, u, sel, v) \
  286. ({ \
  287. __asm__ __volatile__( \
  288. "mttr %0," #rd ", " #u ", " #sel \
  289. : : "r" (v)); \
  290. })
  291. #define settc(tc) \
  292. do { \
  293. write_c0_vpecontrol((read_c0_vpecontrol()&~VPECONTROL_TARGTC) | (tc)); \
  294. ehb(); \
  295. } while (0)
  296. /* you *must* set the target tc (settc) before trying to use these */
  297. #define read_vpe_c0_vpecontrol() mftc0(1, 1)
  298. #define write_vpe_c0_vpecontrol(val) mttc0(1, 1, val)
  299. #define read_vpe_c0_vpeconf0() mftc0(1, 2)
  300. #define write_vpe_c0_vpeconf0(val) mttc0(1, 2, val)
  301. #define read_vpe_c0_vpeconf1() mftc0(1, 3)
  302. #define write_vpe_c0_vpeconf1(val) mttc0(1, 3, val)
  303. #define read_vpe_c0_count() mftc0(9, 0)
  304. #define write_vpe_c0_count(val) mttc0(9, 0, val)
  305. #define read_vpe_c0_status() mftc0(12, 0)
  306. #define write_vpe_c0_status(val) mttc0(12, 0, val)
  307. #define read_vpe_c0_cause() mftc0(13, 0)
  308. #define write_vpe_c0_cause(val) mttc0(13, 0, val)
  309. #define read_vpe_c0_config() mftc0(16, 0)
  310. #define write_vpe_c0_config(val) mttc0(16, 0, val)
  311. #define read_vpe_c0_config1() mftc0(16, 1)
  312. #define write_vpe_c0_config1(val) mttc0(16, 1, val)
  313. #define read_vpe_c0_config7() mftc0(16, 7)
  314. #define write_vpe_c0_config7(val) mttc0(16, 7, val)
  315. #define read_vpe_c0_ebase() mftc0(15, 1)
  316. #define write_vpe_c0_ebase(val) mttc0(15, 1, val)
  317. #define write_vpe_c0_compare(val) mttc0(11, 0, val)
  318. #define read_vpe_c0_badvaddr() mftc0(8, 0)
  319. #define read_vpe_c0_epc() mftc0(14, 0)
  320. #define write_vpe_c0_epc(val) mttc0(14, 0, val)
  321. /* TC */
  322. #define read_tc_c0_tcstatus() mftc0(2, 1)
  323. #define write_tc_c0_tcstatus(val) mttc0(2, 1, val)
  324. #define read_tc_c0_tcbind() mftc0(2, 2)
  325. #define write_tc_c0_tcbind(val) mttc0(2, 2, val)
  326. #define read_tc_c0_tcrestart() mftc0(2, 3)
  327. #define write_tc_c0_tcrestart(val) mttc0(2, 3, val)
  328. #define read_tc_c0_tchalt() mftc0(2, 4)
  329. #define write_tc_c0_tchalt(val) mttc0(2, 4, val)
  330. #define read_tc_c0_tccontext() mftc0(2, 5)
  331. #define write_tc_c0_tccontext(val) mttc0(2, 5, val)
  332. /* GPR */
  333. #define read_tc_gpr_sp() mftgpr(29)
  334. #define write_tc_gpr_sp(val) mttgpr(29, val)
  335. #define read_tc_gpr_gp() mftgpr(28)
  336. #define write_tc_gpr_gp(val) mttgpr(28, val)
  337. __BUILD_SET_C0(mvpcontrol)
  338. #endif /* Not __ASSEMBLY__ */
  339. #endif