tbictxfpu.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * tbictxfpu.S
  3. *
  4. * Copyright (C) 2009, 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 "tbifpuctx.S"
  14. #include <asm/metag_regs.h>
  15. #include <asm/tbx.h>
  16. #ifdef TBI_1_4
  17. /*
  18. * void *__TBICtxFPUSave( TBIRES State, void *pExt )
  19. *
  20. * D0Ar2 contains TBICTX_*_BIT values that control what
  21. * extended data is to be saved.
  22. * These bits must be ored into the SaveMask of this structure.
  23. *
  24. * Virtually all possible scratch registers are used.
  25. */
  26. .text
  27. .balign 4
  28. .global ___TBICtxFPUSave
  29. .type ___TBICtxFPUSave,function
  30. ___TBICtxFPUSave:
  31. /* D1Ar1:D0Ar2 - State
  32. * D1Ar3 - pExt
  33. * D0Ar4 - Value of METAC_CORE_ID
  34. * D1Ar5 - Scratch
  35. * D0Ar6 - Scratch
  36. */
  37. /* If the FPAC bit isnt set then there is nothing to do */
  38. TSTT D0Ar2,#TBICTX_FPAC_BIT
  39. MOVZ PC, D1RtP
  40. /* Obtain the Core config */
  41. MOVT D0Ar4, #HI(METAC_CORE_ID)
  42. ADD D0Ar4, D0Ar4, #LO(METAC_CORE_ID)
  43. GETD D0Ar4, [D0Ar4]
  44. /* Detect FX.8 - FX.15 and add to core config */
  45. MOV D0Ar6, TXENABLE
  46. AND D0Ar6, D0Ar6, #(TXENABLE_CLASSALT_FPUR8 << TXENABLE_CLASS_S)
  47. AND D0Ar4, D0Ar4, #LO(0x0000FFFF)
  48. ORT D0Ar4, D0Ar4, #HI(TBICTX_CFGFPU_FX16_BIT)
  49. XOR D0Ar4, D0Ar4, D0Ar6
  50. /* Save the relevant bits to the buffer */
  51. SETD [D1Ar3++], D0Ar4
  52. /* Save the relevant bits of TXDEFR (Assumes TXDEFR is coherent) ... */
  53. MOV D0Ar6, TXDEFR
  54. LSR D0Re0, D0Ar6, #8
  55. AND D0Re0, D0Re0, #LO(TXDEFR_FPE_FE_BITS>>8)
  56. AND D0Ar6, D0Ar6, #LO(TXDEFR_FPE_ICTRL_BITS)
  57. OR D0Re0, D0Re0, D0Ar6
  58. /* ... along with relevant bits of TXMODE to buffer */
  59. MOV D0Ar6, TXMODE
  60. ANDT D0Ar6, D0Ar6, #HI(TXMODE_FPURMODE_BITS)
  61. ORT D0Ar6, D0Ar6, #HI(TXMODE_FPURMODEWRITE_BIT)
  62. OR D0Ar6, D0Ar6, D0Re0
  63. SETD [D1Ar3++], D0Ar6
  64. GETD D0Ar6,[D1Ar1+#TBICTX_SaveMask-2] /* Get the current SaveMask */
  65. /* D0Ar6 - pCtx->SaveMask */
  66. TSTT D0Ar4, #HI(TBICTX_CFGFPU_FX16_BIT) /* Perform test here for extended FPU registers
  67. * to avoid stalls
  68. */
  69. /* Save the standard FPU registers */
  70. F MSETL [D1Ar3++], FX.0, FX.2, FX.4, FX.6
  71. /* Save the extended FPU registers if they are present */
  72. BZ $Lskip_save_fx8_fx16
  73. F MSETL [D1Ar3++], FX.8, FX.10, FX.12, FX.14
  74. $Lskip_save_fx8_fx16:
  75. /* Save the FPU Accumulator if it is present */
  76. TST D0Ar4, #METAC_COREID_NOFPACC_BIT
  77. BNZ $Lskip_save_fpacc
  78. F SETL [D1Ar3++], ACF.0
  79. F SETL [D1Ar3++], ACF.1
  80. F SETL [D1Ar3++], ACF.2
  81. $Lskip_save_fpacc:
  82. /* Update pCtx->SaveMask */
  83. ANDT D0Ar2, D0Ar2, #TBICTX_FPAC_BIT
  84. OR D0Ar6, D0Ar6, D0Ar2
  85. SETD [D1Ar1+#TBICTX_SaveMask-2],D0Ar6/* Add in XCBF bit to TBICTX */
  86. MOV D0Re0, D1Ar3 /* Return end of save area */
  87. MOV PC, D1RtP
  88. .size ___TBICtxFPUSave,.-___TBICtxFPUSave
  89. /*
  90. * void *__TBICtxFPURestore( TBIRES State, void *pExt )
  91. *
  92. * D0Ar2 contains TBICTX_*_BIT values that control what
  93. * extended data is to be recovered from D1Ar3 (pExt).
  94. *
  95. * Virtually all possible scratch registers are used.
  96. */
  97. /*
  98. * If TBICTX_XEXT_BIT is specified in State. Then the saved state of
  99. * the orginal A0.2 and A1.2 is restored from pExt and the XEXT
  100. * related flags are removed from State.pCtx->SaveMask.
  101. *
  102. */
  103. .balign 4
  104. .global ___TBICtxFPURestore
  105. .type ___TBICtxFPURestore,function
  106. ___TBICtxFPURestore:
  107. /* D1Ar1:D0Ar2 - State
  108. * D1Ar3 - pExt
  109. * D0Ar4 - Value of METAC_CORE_ID
  110. * D1Ar5 - Scratch
  111. * D0Ar6 - Scratch
  112. * D1Re0 - Scratch
  113. */
  114. /* If the FPAC bit isnt set then there is nothing to do */
  115. TSTT D0Ar2,#TBICTX_FPAC_BIT
  116. MOVZ PC, D1RtP
  117. /* Obtain the relevant bits of the Core config */
  118. GETD D0Ar4, [D1Ar3++]
  119. /* Restore FPU related parts of TXDEFR. Assumes TXDEFR is coherent */
  120. GETD D1Ar5, [D1Ar3++]
  121. MOV D0Ar6, D1Ar5
  122. LSL D1Re0, D1Ar5, #8
  123. ANDT D1Re0, D1Re0, #HI(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS)
  124. AND D1Ar5, D1Ar5, #LO(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS)
  125. OR D1Re0, D1Re0, D1Ar5
  126. MOV D1Ar5, TXDEFR
  127. ANDMT D1Ar5, D1Ar5, #HI(~(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS))
  128. ANDMB D1Ar5, D1Ar5, #LO(~(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS))
  129. OR D1Re0, D1Re0, D1Ar5
  130. MOV TXDEFR, D1Re0
  131. /* Restore relevant bits of TXMODE */
  132. MOV D1Ar5, TXMODE
  133. ANDMT D1Ar5, D1Ar5, #HI(~TXMODE_FPURMODE_BITS)
  134. ANDT D0Ar6, D0Ar6, #HI(TXMODE_FPURMODE_BITS|TXMODE_FPURMODEWRITE_BIT)
  135. OR D0Ar6, D0Ar6, D1Ar5
  136. MOV TXMODE, D0Ar6
  137. TSTT D0Ar4, #HI(TBICTX_CFGFPU_FX16_BIT) /* Perform test here for extended FPU registers
  138. * to avoid stalls
  139. */
  140. /* Save the standard FPU registers */
  141. F MGETL FX.0, FX.2, FX.4, FX.6, [D1Ar3++]
  142. /* Save the extended FPU registers if they are present */
  143. BZ $Lskip_restore_fx8_fx16
  144. F MGETL FX.8, FX.10, FX.12, FX.14, [D1Ar3++]
  145. $Lskip_restore_fx8_fx16:
  146. /* Save the FPU Accumulator if it is present */
  147. TST D0Ar4, #METAC_COREID_NOFPACC_BIT
  148. BNZ $Lskip_restore_fpacc
  149. F GETL ACF.0, [D1Ar3++]
  150. F GETL ACF.1, [D1Ar3++]
  151. F GETL ACF.2, [D1Ar3++]
  152. $Lskip_restore_fpacc:
  153. MOV D0Re0, D1Ar3 /* Return end of save area */
  154. MOV PC, D1RtP
  155. .size ___TBICtxFPURestore,.-___TBICtxFPURestore
  156. #endif /* TBI_1_4 */
  157. /*
  158. * End of tbictx.S
  159. */