tbictx.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * tbictx.S
  3. *
  4. * Copyright (C) 2001, 2002, 2007, 2012 Imagination Technologies.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU General Public License version 2 as published by the
  8. * Free Software Foundation.
  9. *
  10. * Explicit state save and restore routines forming part of the thread binary
  11. * interface for META processors
  12. */
  13. .file "tbictx.S"
  14. #include <asm/metag_regs.h>
  15. #include <asm/tbx.h>
  16. #ifdef METAC_1_0
  17. /* Ax.4 is NOT saved in XAX3 */
  18. #define A0_4
  19. #else
  20. /* Ax.4 is saved in XAX4 */
  21. #define A0_4 A0.4,
  22. #endif
  23. /* Size of the TBICTX structure */
  24. #define TBICTX_BYTES ((TBICTX_AX_REGS*8)+TBICTX_AX)
  25. /*
  26. * TBIRES __TBINestInts( TBIRES State, void *pExt, int NoNestMask )
  27. */
  28. .text
  29. .balign 4
  30. .global ___TBINestInts
  31. .type ___TBINestInts,function
  32. ___TBINestInts:
  33. XOR D0Ar4,D0Ar4,#-1 /* D0Ar4 = ~TrigBit */
  34. AND D0Ar4,D0Ar4,#0xFFFF /* D0Ar4 &= 0xFFFF */
  35. MOV D0Ar6,TXMASKI /* BGNDHALT currently enabled? */
  36. TSTT D0Ar2,#TBICTX_XDX8_BIT+TBICTX_XAXX_BIT+TBICTX_XHL2_BIT+TBICTX_XTDP_BIT+TBICTX_XCBF_BIT
  37. AND D0Ar4,D0Ar2,D0Ar4 /* D0Ar4 = Ints to allow */
  38. XOR D0Ar2,D0Ar2,D0Ar4 /* Less Ints in TrigMask */
  39. BNZ ___TBINestInts2 /* Jump if ctx save required! */
  40. TSTT D0Ar2,#TBICTX_CBUF_BIT+TBICTX_CBRP_BIT /* Is catch state dirty? */
  41. OR D0Ar4,D0Ar4,D0Ar6 /* Or in TXMASKI BGNDHALT if set */
  42. TSTNZ D0Ar4,D0Ar4 /* Yes: AND triggers enabled */
  43. MOV D0Re0,D0Ar2 /* Update State argument */
  44. MOV D1Re0,D1Ar1 /* with less Ints in TrigMask */
  45. MOVZ TXMASKI,D0Ar4 /* Early return: Enable Ints */
  46. MOVZ PC,D1RtP /* Early return */
  47. .size ___TBINestInts,.-___TBINestInts
  48. /*
  49. * Drop thru into sub-function-
  50. */
  51. .global ___TBINestInts2
  52. .type ___TBINestInts2,function
  53. ___TBINestInts2:
  54. MOV D0FrT,A0FrP /* Full entry sequence so we */
  55. ADD A0FrP,A0StP,#0 /* can make sub-calls */
  56. MSETL [A0StP],D0FrT,D0.5,D0.6 /* and preserve our result */
  57. ORT D0Ar2,D0Ar2,#TBICTX_XCBF_BIT /* Add in XCBF save request */
  58. MOV D0.5,D0Ar2 /* Save State in DX.5 */
  59. MOV D1.5,D1Ar1
  60. OR D0.6,D0Ar4,D0Ar6 /* Save TrigMask in D0.6 */
  61. MOVT D1RtP,#HI(___TBICtxSave) /* Save catch buffer */
  62. CALL D1RtP,#LO(___TBICtxSave)
  63. MOV TXMASKI,D0.6 /* Allow Ints */
  64. MOV D0Re0,D0.5 /* Return State */
  65. MOV D1Re0,D1.5
  66. MGETL D0FrT,D0.5,D0.6,[A0FrP] /* Full exit sequence */
  67. SUB A0StP,A0FrP,#(8*3)
  68. MOV A0FrP,D0FrT
  69. MOV PC,D1RtP
  70. .size ___TBINestInts2,.-___TBINestInts2
  71. /*
  72. * void *__TBICtxSave( TBIRES State, void *pExt )
  73. *
  74. * D0Ar2 contains TBICTX_*_BIT values that control what
  75. * extended data is to be saved beyond the end of D1Ar1.
  76. * These bits must be ored into the SaveMask of this structure.
  77. *
  78. * Virtually all possible scratch registers are used.
  79. *
  80. * The D1Ar1 parameter is only used as the basis for saving
  81. * CBUF state.
  82. */
  83. /*
  84. * If TBICTX_XEXT_BIT is specified in State. then State.pCtx->Ext is
  85. * utilised to save the base address of the context save area and
  86. * the extended states saved. The XEXT flag then indicates that the
  87. * original state of the A0.2 and A1.2 registers from TBICTX.Ext.AX2
  88. * are stored as the first part of the extended state structure.
  89. */
  90. .balign 4
  91. .global ___TBICtxSave
  92. .type ___TBICtxSave,function
  93. ___TBICtxSave:
  94. GETD D0Re0,[D1Ar1+#TBICTX_SaveMask-2] /* Get SaveMask */
  95. TSTT D0Ar2,#TBICTX_XDX8_BIT+TBICTX_XAXX_BIT+TBICTX_XHL2_BIT+TBICTX_XTDP_BIT+TBICTX_XEXT_BIT
  96. /* Just XCBF to save? */
  97. MOV A0.2,D1Ar3 /* Save pointer into A0.2 */
  98. MOV A1.2,D1RtP /* Free off D0FrT:D1RtP pair */
  99. BZ $LCtxSaveCBUF /* Yes: Only XCBF may be saved */
  100. TSTT D0Ar2,#TBICTX_XEXT_BIT /* Extended base-state model? */
  101. BZ $LCtxSaveXDX8
  102. GETL D0Ar6,D1Ar5,[D1Ar1+#TBICTX_Ext_AX2] /* Get A0.2, A1.2 state */
  103. MOV D0Ar4,D0Ar2 /* Extract Ctx.SaveFlags value */
  104. ANDMT D0Ar4,D0Ar4,#TBICTX_XDX8_BIT+TBICTX_XAXX_BIT+TBICTX_XHL2_BIT+TBICTX_XTDP_BIT+TBICTX_XEXT_BIT
  105. SETD [D1Ar1+#TBICTX_Ext_Ctx_pExt],A0.2
  106. SETD [D1Ar1+#TBICTX_Ext_Ctx_SaveMask-2],D0Ar4
  107. SETL [A0.2++],D0Ar6,D1Ar5 /* Save A0.2, A1.2 state */
  108. $LCtxSaveXDX8:
  109. TSTT D0Ar2,#TBICTX_XDX8_BIT /* Save extended DX regs? */
  110. BZ $LCtxSaveXAXX
  111. /*
  112. * Save 8 extra DX registers
  113. */
  114. MSETL [A0.2],D0.8,D0.9,D0.10,D0.11,D0.12,D0.13,D0.14,D0.15
  115. $LCtxSaveXAXX:
  116. TSTT D0Ar2,#TBICTX_XAXX_BIT /* Save extended AX regs? */
  117. SWAP D0Re0,A0.2 /* pDst into D0Re0 */
  118. BZ $LCtxSaveXHL2
  119. /*
  120. * Save 4 extra AX registers
  121. */
  122. MSETL [D0Re0], A0_4 A0.5,A0.6,A0.7 /* Save 8*3 bytes */
  123. $LCtxSaveXHL2:
  124. TSTT D0Ar2,#TBICTX_XHL2_BIT /* Save hardware-loop regs? */
  125. SWAP D0Re0,A0.2 /* pDst back into A0.2 */
  126. MOV D0Ar6,TXL1START
  127. MOV D1Ar5,TXL2START
  128. BZ $LCtxSaveXTDP
  129. /*
  130. * Save hardware loop registers
  131. */
  132. SETL [A0.2++],D0Ar6,D1Ar5 /* Save 8*1 bytes */
  133. MOV D0Ar6,TXL1END
  134. MOV D1Ar5,TXL2END
  135. MOV D0FrT,TXL1COUNT
  136. MOV D1RtP,TXL2COUNT
  137. MSETL [A0.2],D0Ar6,D0FrT /* Save 8*2 bytes */
  138. /*
  139. * Clear loop counters to disable any current loops
  140. */
  141. XOR TXL1COUNT,D0FrT,D0FrT
  142. XOR TXL2COUNT,D1RtP,D1RtP
  143. $LCtxSaveXTDP:
  144. TSTT D0Ar2,#TBICTX_XTDP_BIT /* Save per-thread DSP regs? */
  145. BZ $LCtxSaveCBUF
  146. /*
  147. * Save per-thread DSP registers; ACC.0, PR.0, PI.1-3 (PI.0 is zero)
  148. */
  149. #ifndef CTX_NO_DSP
  150. D SETL [A0.2++],AC0.0,AC1.0 /* Save ACx.0 lower 32-bits */
  151. DH SETL [A0.2++],AC0.0,AC1.0 /* Save ACx.0 upper 32-bits */
  152. D SETL [A0.2++],D0AR.0,D1AR.0 /* Save DSP RAM registers */
  153. D SETL [A0.2++],D0AR.1,D1AR.1
  154. D SETL [A0.2++],D0AW.0,D1AW.0
  155. D SETL [A0.2++],D0AW.1,D1AW.1
  156. D SETL [A0.2++],D0BR.0,D1BR.0
  157. D SETL [A0.2++],D0BR.1,D1BR.1
  158. D SETL [A0.2++],D0BW.0,D1BW.0
  159. D SETL [A0.2++],D0BW.1,D1BW.1
  160. D SETL [A0.2++],D0ARI.0,D1ARI.0
  161. D SETL [A0.2++],D0ARI.1,D1ARI.1
  162. D SETL [A0.2++],D0AWI.0,D1AWI.0
  163. D SETL [A0.2++],D0AWI.1,D1AWI.1
  164. D SETL [A0.2++],D0BRI.0,D1BRI.0
  165. D SETL [A0.2++],D0BRI.1,D1BRI.1
  166. D SETL [A0.2++],D0BWI.0,D1BWI.0
  167. D SETL [A0.2++],D0BWI.1,D1BWI.1
  168. D SETD [A0.2++],T0
  169. D SETD [A0.2++],T1
  170. D SETD [A0.2++],T2
  171. D SETD [A0.2++],T3
  172. D SETD [A0.2++],T4
  173. D SETD [A0.2++],T5
  174. D SETD [A0.2++],T6
  175. D SETD [A0.2++],T7
  176. D SETD [A0.2++],T8
  177. D SETD [A0.2++],T9
  178. D SETD [A0.2++],TA
  179. D SETD [A0.2++],TB
  180. D SETD [A0.2++],TC
  181. D SETD [A0.2++],TD
  182. D SETD [A0.2++],TE
  183. D SETD [A0.2++],TF
  184. #else
  185. ADD A0.2,A0.2,#(8*18+4*16)
  186. #endif
  187. MOV D0Ar6,TXMRSIZE
  188. MOV D1Ar5,TXDRSIZE
  189. SETL [A0.2++],D0Ar6,D1Ar5 /* Save 8*1 bytes */
  190. $LCtxSaveCBUF:
  191. #ifdef TBI_1_3
  192. MOV D0Ar4,D0Re0 /* Copy Ctx Flags */
  193. ANDT D0Ar4,D0Ar4,#TBICTX_XCBF_BIT /* mask XCBF if already set */
  194. XOR D0Ar4,D0Ar4,#-1
  195. AND D0Ar2,D0Ar2,D0Ar4 /* remove XCBF if already set */
  196. #endif
  197. TSTT D0Ar2,#TBICTX_XCBF_BIT /* Want to save CBUF? */
  198. ANDT D0Ar2,D0Ar2,#TBICTX_XDX8_BIT+TBICTX_XAXX_BIT+TBICTX_XHL2_BIT+TBICTX_XTDP_BIT+TBICTX_XEXT_BIT
  199. OR D0Ar2,D0Ar2,D0Re0 /* Generate new SaveMask */
  200. SETD [D1Ar1+#TBICTX_SaveMask-2],D0Ar2/* Add in bits saved to TBICTX */
  201. MOV D0Re0,A0.2 /* Return end of save area */
  202. MOV D0Ar4,TXDIVTIME /* Get TXDIVTIME */
  203. MOVZ PC,A1.2 /* No: Early return */
  204. TSTT D0Ar2,#TBICTX_CBUF_BIT+TBICTX_CBRP_BIT /* Need to save CBUF? */
  205. MOVZ PC,A1.2 /* No: Early return */
  206. ORT D0Ar2,D0Ar2,#TBICTX_XCBF_BIT
  207. SETD [D1Ar1+#TBICTX_SaveMask-2],D0Ar2/* Add in XCBF bit to TBICTX */
  208. ADD A0.2,D1Ar1,#TBICTX_BYTES /* Dump CBUF state after TBICTX */
  209. /*
  210. * Save CBUF
  211. */
  212. SETD [A0.2+# 0],TXCATCH0 /* Restore TXCATCHn */
  213. SETD [A0.2+# 4],TXCATCH1
  214. TSTT D0Ar2,#TBICTX_CBRP_BIT /* ... RDDIRTY was/is set */
  215. SETD [A0.2+# 8],TXCATCH2
  216. SETD [A0.2+#12],TXCATCH3
  217. BZ $LCtxSaveComplete
  218. SETL [A0.2+#(2*8)],RD /* Save read pipeline */
  219. SETL [A0.2+#(3*8)],RD /* Save read pipeline */
  220. SETL [A0.2+#(4*8)],RD /* Save read pipeline */
  221. SETL [A0.2+#(5*8)],RD /* Save read pipeline */
  222. SETL [A0.2+#(6*8)],RD /* Save read pipeline */
  223. SETL [A0.2+#(7*8)],RD /* Save read pipeline */
  224. AND TXDIVTIME,D0Ar4,#TXDIVTIME_DIV_BITS /* Clear RPDIRTY */
  225. $LCtxSaveComplete:
  226. MOV PC,A1.2 /* Return */
  227. .size ___TBICtxSave,.-___TBICtxSave
  228. /*
  229. * void *__TBICtxRestore( TBIRES State, void *pExt )
  230. *
  231. * D0Ar2 contains TBICTX_*_BIT values that control what
  232. * extended data is to be recovered from D1Ar3 (pExt).
  233. *
  234. * Virtually all possible scratch registers are used.
  235. */
  236. /*
  237. * If TBICTX_XEXT_BIT is specified in State. Then the saved state of
  238. * the orginal A0.2 and A1.2 is restored from pExt and the XEXT
  239. * related flags are removed from State.pCtx->SaveMask.
  240. *
  241. */
  242. .balign 4
  243. .global ___TBICtxRestore
  244. .type ___TBICtxRestore,function
  245. ___TBICtxRestore:
  246. GETD D0Ar6,[D1Ar1+#TBICTX_CurrMODE] /* Get TXMODE Value */
  247. ANDST D0Ar2,D0Ar2,#TBICTX_XDX8_BIT+TBICTX_XAXX_BIT+TBICTX_XHL2_BIT+TBICTX_XTDP_BIT+TBICTX_XEXT_BIT
  248. MOV D1Re0,D0Ar2 /* Keep flags in D1Re0 */
  249. MOV D0Re0,D1Ar3 /* D1Ar3 is default result */
  250. MOVZ PC,D1RtP /* Early return, nothing to do */
  251. ANDT D0Ar6,D0Ar6,#0xE000 /* Top bits of TXMODE required */
  252. MOV A0.3,D0Ar6 /* Save TXMODE for later */
  253. TSTT D1Re0,#TBICTX_XEXT_BIT /* Check for XEXT bit */
  254. BZ $LCtxRestXDX8
  255. GETD D0Ar4,[D1Ar1+#TBICTX_SaveMask-2]/* Get current SaveMask */
  256. GETL D0Ar6,D1Ar5,[D0Re0++] /* Restore A0.2, A1.2 state */
  257. ANDMT D0Ar4,D0Ar4,#(0xFFFF-(TBICTX_XDX8_BIT+TBICTX_XAXX_BIT+TBICTX_XHL2_BIT+TBICTX_XTDP_BIT+TBICTX_XEXT_BIT))
  258. SETD [D1Ar1+#TBICTX_SaveMask-2],D0Ar4/* New SaveMask */
  259. #ifdef METAC_1_0
  260. SETD [D1Ar1+#TBICTX_Ext_AX2_U0],D0Ar6
  261. MOV D0Ar6,D1Ar1
  262. SETD [D0Ar6+#TBICTX_Ext_AX2_U1],D1Ar5
  263. #else
  264. SETL [D1Ar1+#TBICTX_Ext_AX2],D0Ar6,D1Ar5
  265. #endif
  266. $LCtxRestXDX8:
  267. TSTT D1Re0,#TBICTX_XDX8_BIT /* Get extended DX regs? */
  268. MOV A1.2,D1RtP /* Free off D1RtP register */
  269. BZ $LCtxRestXAXX
  270. /*
  271. * Restore 8 extra DX registers
  272. */
  273. MGETL D0.8,D0.9,D0.10,D0.11,D0.12,D0.13,D0.14,D0.15,[D0Re0]
  274. $LCtxRestXAXX:
  275. TSTT D1Re0,#TBICTX_XAXX_BIT /* Get extended AX regs? */
  276. BZ $LCtxRestXHL2
  277. /*
  278. * Restore 3 extra AX registers
  279. */
  280. MGETL A0_4 A0.5,A0.6,A0.7,[D0Re0] /* Get 8*3 bytes */
  281. $LCtxRestXHL2:
  282. TSTT D1Re0,#TBICTX_XHL2_BIT /* Get hardware-loop regs? */
  283. BZ $LCtxRestXTDP
  284. /*
  285. * Get hardware loop registers
  286. */
  287. MGETL D0Ar6,D0Ar4,D0Ar2,[D0Re0] /* Get 8*3 bytes */
  288. MOV TXL1START,D0Ar6
  289. MOV TXL2START,D1Ar5
  290. MOV TXL1END,D0Ar4
  291. MOV TXL2END,D1Ar3
  292. MOV TXL1COUNT,D0Ar2
  293. MOV TXL2COUNT,D1Ar1
  294. $LCtxRestXTDP:
  295. TSTT D1Re0,#TBICTX_XTDP_BIT /* Get per-thread DSP regs? */
  296. MOVZ PC,A1.2 /* No: Early return */
  297. /*
  298. * Get per-thread DSP registers; ACC.0, PR.0, PI.1-3 (PI.0 is zero)
  299. */
  300. MOV A0.2,D0Re0
  301. GETL D0Ar6,D1Ar5,[D0Re0++#((16*4)+(18*8))]
  302. #ifndef CTX_NO_DSP
  303. D GETL AC0.0,AC1.0,[A0.2++] /* Restore ACx.0 lower 32-bits */
  304. DH GETL AC0.0,AC1.0,[A0.2++] /* Restore ACx.0 upper 32-bits */
  305. #else
  306. ADD A0.2,A0.2,#(2*8)
  307. #endif
  308. ADD D0Re0,D0Re0,#(2*4)
  309. MOV TXMODE,A0.3 /* Some TXMODE bits needed */
  310. MOV TXMRSIZE,D0Ar6
  311. MOV TXDRSIZE,D1Ar5
  312. #ifndef CTX_NO_DSP
  313. D GETL D0AR.0,D1AR.0,[A0.2++] /* Restore DSP RAM registers */
  314. D GETL D0AR.1,D1AR.1,[A0.2++]
  315. D GETL D0AW.0,D1AW.0,[A0.2++]
  316. D GETL D0AW.1,D1AW.1,[A0.2++]
  317. D GETL D0BR.0,D1BR.0,[A0.2++]
  318. D GETL D0BR.1,D1BR.1,[A0.2++]
  319. D GETL D0BW.0,D1BW.0,[A0.2++]
  320. D GETL D0BW.1,D1BW.1,[A0.2++]
  321. #else
  322. ADD A0.2,A0.2,#(8*8)
  323. #endif
  324. MOV TXMODE,#0 /* Restore TXMODE */
  325. #ifndef CTX_NO_DSP
  326. D GETL D0ARI.0,D1ARI.0,[A0.2++]
  327. D GETL D0ARI.1,D1ARI.1,[A0.2++]
  328. D GETL D0AWI.0,D1AWI.0,[A0.2++]
  329. D GETL D0AWI.1,D1AWI.1,[A0.2++]
  330. D GETL D0BRI.0,D1BRI.0,[A0.2++]
  331. D GETL D0BRI.1,D1BRI.1,[A0.2++]
  332. D GETL D0BWI.0,D1BWI.0,[A0.2++]
  333. D GETL D0BWI.1,D1BWI.1,[A0.2++]
  334. D GETD T0,[A0.2++]
  335. D GETD T1,[A0.2++]
  336. D GETD T2,[A0.2++]
  337. D GETD T3,[A0.2++]
  338. D GETD T4,[A0.2++]
  339. D GETD T5,[A0.2++]
  340. D GETD T6,[A0.2++]
  341. D GETD T7,[A0.2++]
  342. D GETD T8,[A0.2++]
  343. D GETD T9,[A0.2++]
  344. D GETD TA,[A0.2++]
  345. D GETD TB,[A0.2++]
  346. D GETD TC,[A0.2++]
  347. D GETD TD,[A0.2++]
  348. D GETD TE,[A0.2++]
  349. D GETD TF,[A0.2++]
  350. #else
  351. ADD A0.2,A0.2,#(8*8+4*16)
  352. #endif
  353. MOV PC,A1.2 /* Return */
  354. .size ___TBICtxRestore,.-___TBICtxRestore
  355. /*
  356. * End of tbictx.S
  357. */