mips_fp_gcc.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * File : mips_vfp32_asm.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2016Äê9ÔÂ9ÈÕ Urey the first version
  23. */
  24. #ifndef __ASSEMBLY__
  25. # define __ASSEMBLY__
  26. #endif
  27. #ifdef __mips_hard_float
  28. .module hardfloat
  29. .module doublefloat
  30. .set nomips16
  31. #include "../common/mips.h"
  32. #undef fp
  33. .global mips_vfp32_init
  34. LEAF(mips_vfp32_init)
  35. mfc0 t0, CP0_STATUS
  36. or t0 , M_StatusCU1
  37. mtc0 t0, CP0_STATUS
  38. jr ra
  39. nop
  40. END(mips_vfp32_init)
  41. #
  42. # FUNCTION: _fpctx_save
  43. #
  44. # DESCRIPTION: save floating point registers to memory starting at a0
  45. #
  46. # RETURNS: int
  47. # 0: No context saved
  48. # CTX_*: Type of context stored
  49. #
  50. .global _fpctx_save
  51. LEAF(_fpctx_save)
  52. sw zero, LINKCTX_NEXT(a0)
  53. mfc0 t0, CP0_STATUS
  54. li t1, M_StatusCU1
  55. and t1, t0, t1
  56. bnez t1, 1f
  57. # FP not enabled, bail out
  58. move v0, zero
  59. jr ra
  60. 1: # Save FP32 base
  61. li t1, ST0_FR
  62. and t0, t0, t1
  63. cfc1 t2, $31
  64. sw t2, FP32CTX_CSR(a0)
  65. sdc1 $f0, FP32CTX_0(a0)
  66. sdc1 $f2, FP32CTX_2(a0)
  67. sdc1 $f4, FP32CTX_4(a0)
  68. sdc1 $f6, FP32CTX_6(a0)
  69. sdc1 $f8, FP32CTX_8(a0)
  70. sdc1 $f10, FP32CTX_10(a0)
  71. sdc1 $f12, FP32CTX_12(a0)
  72. sdc1 $f14, FP32CTX_14(a0)
  73. sdc1 $f16, FP32CTX_16(a0)
  74. sdc1 $f18, FP32CTX_18(a0)
  75. sdc1 $f20, FP32CTX_20(a0)
  76. sdc1 $f22, FP32CTX_22(a0)
  77. sdc1 $f24, FP32CTX_24(a0)
  78. sdc1 $f26, FP32CTX_26(a0)
  79. sdc1 $f28, FP32CTX_28(a0)
  80. sdc1 $f30, FP32CTX_30(a0)
  81. bnez t0, 2f
  82. li v0, LINKCTX_TYPE_FP32
  83. sw v0, LINKCTX_ID(a0)
  84. jr ra
  85. 2: # Save FP64 extra
  86. .set push
  87. .set fp=64
  88. sdc1 $f1, FP64CTX_1(a0)
  89. sdc1 $f3, FP64CTX_3(a0)
  90. sdc1 $f5, FP64CTX_5(a0)
  91. sdc1 $f7, FP64CTX_7(a0)
  92. sdc1 $f9, FP64CTX_9(a0)
  93. sdc1 $f11, FP64CTX_11(a0)
  94. sdc1 $f13, FP64CTX_13(a0)
  95. sdc1 $f15, FP64CTX_15(a0)
  96. sdc1 $f17, FP64CTX_17(a0)
  97. sdc1 $f19, FP64CTX_19(a0)
  98. sdc1 $f21, FP64CTX_21(a0)
  99. sdc1 $f23, FP64CTX_23(a0)
  100. sdc1 $f25, FP64CTX_25(a0)
  101. sdc1 $f27, FP64CTX_27(a0)
  102. sdc1 $f29, FP64CTX_29(a0)
  103. sdc1 $f31, FP64CTX_31(a0)
  104. .set pop
  105. li v0, LINKCTX_TYPE_FP64
  106. sw v0, LINKCTX_ID(a0)
  107. jr ra
  108. END(_fpctx_save)
  109. #
  110. # FUNCTION: _fpctx_load
  111. #
  112. # DESCRIPTION: load floating point registers from context chain starting at a0
  113. #
  114. # RETURNS: int
  115. # 0: Unrecognised context
  116. # CTX_*: Type of context restored
  117. #
  118. .global _fpctx_load
  119. LEAF(_fpctx_load)
  120. lw v0, LINKCTX_ID(a0)
  121. # Detect type
  122. li t0, LINKCTX_TYPE_FP64
  123. li t1, LINKCTX_TYPE_FP32
  124. li t2, M_StatusCU1
  125. beq v0, t0, 0f
  126. beq v0, t1, 1f
  127. # Don't recognise this context, fail
  128. move v0, zero
  129. jr ra
  130. 0: # FP64 context
  131. # Enable CU1
  132. di t3
  133. ehb
  134. or t3, t3, t2
  135. mtc0 t3, CP0_STATUS
  136. ehb
  137. # Load FP64 extra
  138. .set push
  139. .set fp=64
  140. ldc1 $f1, FP64CTX_1(a0)
  141. ldc1 $f3, FP64CTX_3(a0)
  142. ldc1 $f5, FP64CTX_5(a0)
  143. ldc1 $f7, FP64CTX_7(a0)
  144. ldc1 $f9, FP64CTX_9(a0)
  145. ldc1 $f11, FP64CTX_11(a0)
  146. ldc1 $f13, FP64CTX_13(a0)
  147. ldc1 $f15, FP64CTX_15(a0)
  148. ldc1 $f17, FP64CTX_17(a0)
  149. ldc1 $f19, FP64CTX_19(a0)
  150. ldc1 $f21, FP64CTX_21(a0)
  151. ldc1 $f23, FP64CTX_23(a0)
  152. ldc1 $f25, FP64CTX_25(a0)
  153. ldc1 $f27, FP64CTX_27(a0)
  154. ldc1 $f29, FP64CTX_29(a0)
  155. ldc1 $f31, FP64CTX_31(a0)
  156. .set pop
  157. 1: # FP32 context
  158. # Enable CU1
  159. di t3
  160. ehb
  161. or t3, t3, t2
  162. mtc0 t3, CP0_STATUS
  163. ehb
  164. # Load FP32 base
  165. lw t1, FP32CTX_CSR(a0)
  166. ctc1 t1, $31
  167. ldc1 $f0, FP32CTX_0(a0)
  168. ldc1 $f2, FP32CTX_2(a0)
  169. ldc1 $f4, FP32CTX_4(a0)
  170. ldc1 $f6, FP32CTX_6(a0)
  171. ldc1 $f8, FP32CTX_8(a0)
  172. ldc1 $f10, FP32CTX_10(a0)
  173. ldc1 $f12, FP32CTX_12(a0)
  174. ldc1 $f14, FP32CTX_14(a0)
  175. ldc1 $f16, FP32CTX_16(a0)
  176. ldc1 $f18, FP32CTX_18(a0)
  177. ldc1 $f20, FP32CTX_20(a0)
  178. ldc1 $f22, FP32CTX_22(a0)
  179. ldc1 $f24, FP32CTX_24(a0)
  180. ldc1 $f26, FP32CTX_26(a0)
  181. ldc1 $f28, FP32CTX_28(a0)
  182. ldc1 $f30, FP32CTX_30(a0)
  183. # Return CTX_FP32/64
  184. jr ra
  185. END(_fpctx_load)
  186. #endif