ldstfp.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Floating-point, VMX/Altivec and VSX loads and stores
  3. * for use in instruction emulation.
  4. *
  5. * Copyright 2010 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <asm/processor.h>
  13. #include <asm/ppc_asm.h>
  14. #include <asm/ppc-opcode.h>
  15. #include <asm/reg.h>
  16. #include <asm/asm-offsets.h>
  17. #include <linux/errno.h>
  18. #ifdef CONFIG_PPC_FPU
  19. #define STKFRM (PPC_MIN_STKFRM + 16)
  20. /* Get the contents of frN into *p; N is in r3 and p is in r4. */
  21. _GLOBAL(get_fpr)
  22. mflr r0
  23. mfmsr r6
  24. ori r7, r6, MSR_FP
  25. MTMSRD(r7)
  26. isync
  27. rlwinm r3,r3,3,0xf8
  28. bcl 20,31,1f
  29. reg = 0
  30. .rept 32
  31. stfd reg, 0(r4)
  32. b 2f
  33. reg = reg + 1
  34. .endr
  35. 1: mflr r5
  36. add r5,r3,r5
  37. mtctr r5
  38. mtlr r0
  39. bctr
  40. 2: MTMSRD(r6)
  41. isync
  42. blr
  43. /* Put the contents of *p into frN; N is in r3 and p is in r4. */
  44. _GLOBAL(put_fpr)
  45. mflr r0
  46. mfmsr r6
  47. ori r7, r6, MSR_FP
  48. MTMSRD(r7)
  49. isync
  50. rlwinm r3,r3,3,0xf8
  51. bcl 20,31,1f
  52. reg = 0
  53. .rept 32
  54. lfd reg, 0(r4)
  55. b 2f
  56. reg = reg + 1
  57. .endr
  58. 1: mflr r5
  59. add r5,r3,r5
  60. mtctr r5
  61. mtlr r0
  62. bctr
  63. 2: MTMSRD(r6)
  64. isync
  65. blr
  66. #ifdef CONFIG_ALTIVEC
  67. /* Get the contents of vrN into *p; N is in r3 and p is in r4. */
  68. _GLOBAL(get_vr)
  69. mflr r0
  70. mfmsr r6
  71. oris r7, r6, MSR_VEC@h
  72. MTMSRD(r7)
  73. isync
  74. rlwinm r3,r3,3,0xf8
  75. bcl 20,31,1f
  76. reg = 0
  77. .rept 32
  78. stvx reg, 0, r4
  79. b 2f
  80. reg = reg + 1
  81. .endr
  82. 1: mflr r5
  83. add r5,r3,r5
  84. mtctr r5
  85. mtlr r0
  86. bctr
  87. 2: MTMSRD(r6)
  88. isync
  89. blr
  90. /* Put the contents of *p into vrN; N is in r3 and p is in r4. */
  91. _GLOBAL(put_vr)
  92. mflr r0
  93. mfmsr r6
  94. oris r7, r6, MSR_VEC@h
  95. MTMSRD(r7)
  96. isync
  97. rlwinm r3,r3,3,0xf8
  98. bcl 20,31,1f
  99. reg = 0
  100. .rept 32
  101. lvx reg, 0, r4
  102. b 2f
  103. reg = reg + 1
  104. .endr
  105. 1: mflr r5
  106. add r5,r3,r5
  107. mtctr r5
  108. mtlr r0
  109. bctr
  110. 2: MTMSRD(r6)
  111. isync
  112. blr
  113. #endif /* CONFIG_ALTIVEC */
  114. #ifdef CONFIG_VSX
  115. /* Get the contents of vsN into vs0; N is in r3. */
  116. _GLOBAL(get_vsr)
  117. mflr r0
  118. rlwinm r3,r3,3,0x1f8
  119. bcl 20,31,1f
  120. blr /* vs0 is already in vs0 */
  121. nop
  122. reg = 1
  123. .rept 63
  124. XXLOR(0,reg,reg)
  125. blr
  126. reg = reg + 1
  127. .endr
  128. 1: mflr r5
  129. add r5,r3,r5
  130. mtctr r5
  131. mtlr r0
  132. bctr
  133. /* Put the contents of vs0 into vsN; N is in r3. */
  134. _GLOBAL(put_vsr)
  135. mflr r0
  136. rlwinm r3,r3,3,0x1f8
  137. bcl 20,31,1f
  138. blr /* v0 is already in v0 */
  139. nop
  140. reg = 1
  141. .rept 63
  142. XXLOR(reg,0,0)
  143. blr
  144. reg = reg + 1
  145. .endr
  146. 1: mflr r5
  147. add r5,r3,r5
  148. mtctr r5
  149. mtlr r0
  150. bctr
  151. /* Load VSX reg N from vector doubleword *p. N is in r3, p in r4. */
  152. _GLOBAL(load_vsrn)
  153. PPC_STLU r1,-STKFRM(r1)
  154. mflr r0
  155. PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
  156. mfmsr r6
  157. oris r7,r6,MSR_VSX@h
  158. cmpwi cr7,r3,0
  159. li r8,STKFRM-16
  160. MTMSRD(r7)
  161. isync
  162. beq cr7,1f
  163. STXVD2X(0,R1,R8)
  164. 1: LXVD2X(0,R0,R4)
  165. #ifdef __LITTLE_ENDIAN__
  166. XXSWAPD(0,0)
  167. #endif
  168. beq cr7,4f
  169. bl put_vsr
  170. LXVD2X(0,R1,R8)
  171. 4: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
  172. mtlr r0
  173. MTMSRD(r6)
  174. isync
  175. addi r1,r1,STKFRM
  176. blr
  177. /* Store VSX reg N to vector doubleword *p. N is in r3, p in r4. */
  178. _GLOBAL(store_vsrn)
  179. PPC_STLU r1,-STKFRM(r1)
  180. mflr r0
  181. PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
  182. mfmsr r6
  183. oris r7,r6,MSR_VSX@h
  184. li r8,STKFRM-16
  185. MTMSRD(r7)
  186. isync
  187. STXVD2X(0,R1,R8)
  188. bl get_vsr
  189. #ifdef __LITTLE_ENDIAN__
  190. XXSWAPD(0,0)
  191. #endif
  192. STXVD2X(0,R0,R4)
  193. LXVD2X(0,R1,R8)
  194. PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
  195. mtlr r0
  196. MTMSRD(r6)
  197. isync
  198. mr r3,r9
  199. addi r1,r1,STKFRM
  200. blr
  201. #endif /* CONFIG_VSX */
  202. /* Convert single-precision to double, without disturbing FPRs. */
  203. /* conv_sp_to_dp(float *sp, double *dp) */
  204. _GLOBAL(conv_sp_to_dp)
  205. mfmsr r6
  206. ori r7, r6, MSR_FP
  207. MTMSRD(r7)
  208. isync
  209. stfd fr0, -16(r1)
  210. lfs fr0, 0(r3)
  211. stfd fr0, 0(r4)
  212. lfd fr0, -16(r1)
  213. MTMSRD(r6)
  214. isync
  215. blr
  216. /* Convert single-precision to double, without disturbing FPRs. */
  217. /* conv_sp_to_dp(double *dp, float *sp) */
  218. _GLOBAL(conv_dp_to_sp)
  219. mfmsr r6
  220. ori r7, r6, MSR_FP
  221. MTMSRD(r7)
  222. isync
  223. stfd fr0, -16(r1)
  224. lfd fr0, 0(r3)
  225. stfs fr0, 0(r4)
  226. lfd fr0, -16(r1)
  227. MTMSRD(r6)
  228. isync
  229. blr
  230. #endif /* CONFIG_PPC_FPU */