fpu.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * FPU support code, moved here from head.S so that it can be used
  3. * by chips which use other head-whatever.S files.
  4. *
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Copyright (C) 1996 Paul Mackerras.
  8. * Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. */
  16. #include <asm/reg.h>
  17. #include <asm/page.h>
  18. #include <asm/mmu.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/cputable.h>
  21. #include <asm/cache.h>
  22. #include <asm/thread_info.h>
  23. #include <asm/ppc_asm.h>
  24. #include <asm/asm-offsets.h>
  25. #include <asm/ptrace.h>
  26. #ifdef CONFIG_VSX
  27. #define __REST_32FPVSRS(n,c,base) \
  28. BEGIN_FTR_SECTION \
  29. b 2f; \
  30. END_FTR_SECTION_IFSET(CPU_FTR_VSX); \
  31. REST_32FPRS(n,base); \
  32. b 3f; \
  33. 2: REST_32VSRS(n,c,base); \
  34. 3:
  35. #define __REST_32FPVSRS_TRANSACT(n,c,base) \
  36. BEGIN_FTR_SECTION \
  37. b 2f; \
  38. END_FTR_SECTION_IFSET(CPU_FTR_VSX); \
  39. REST_32FPRS_TRANSACT(n,base); \
  40. b 3f; \
  41. 2: REST_32VSRS_TRANSACT(n,c,base); \
  42. 3:
  43. #define __SAVE_32FPVSRS(n,c,base) \
  44. BEGIN_FTR_SECTION \
  45. b 2f; \
  46. END_FTR_SECTION_IFSET(CPU_FTR_VSX); \
  47. SAVE_32FPRS(n,base); \
  48. b 3f; \
  49. 2: SAVE_32VSRS(n,c,base); \
  50. 3:
  51. #else
  52. #define __REST_32FPVSRS(n,b,base) REST_32FPRS(n, base)
  53. #define __REST_32FPVSRS_TRANSACT(n,b,base) REST_32FPRS(n, base)
  54. #define __SAVE_32FPVSRS(n,b,base) SAVE_32FPRS(n, base)
  55. #endif
  56. #define REST_32FPVSRS(n,c,base) __REST_32FPVSRS(n,__REG_##c,__REG_##base)
  57. #define REST_32FPVSRS_TRANSACT(n,c,base) \
  58. __REST_32FPVSRS_TRANSACT(n,__REG_##c,__REG_##base)
  59. #define SAVE_32FPVSRS(n,c,base) __SAVE_32FPVSRS(n,__REG_##c,__REG_##base)
  60. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  61. /*
  62. * Wrapper to call load_up_fpu from C.
  63. * void do_load_up_fpu(struct pt_regs *regs);
  64. */
  65. _GLOBAL(do_load_up_fpu)
  66. mflr r0
  67. std r0, 16(r1)
  68. stdu r1, -112(r1)
  69. subi r6, r3, STACK_FRAME_OVERHEAD
  70. /* load_up_fpu expects r12=MSR, r13=PACA, and returns
  71. * with r12 = new MSR.
  72. */
  73. ld r12,_MSR(r6)
  74. GET_PACA(r13)
  75. bl load_up_fpu
  76. std r12,_MSR(r6)
  77. ld r0, 112+16(r1)
  78. addi r1, r1, 112
  79. mtlr r0
  80. blr
  81. /* void do_load_up_transact_fpu(struct thread_struct *thread)
  82. *
  83. * This is similar to load_up_fpu but for the transactional version of the FP
  84. * register set. It doesn't mess with the task MSR or valid flags.
  85. * Furthermore, we don't do lazy FP with TM currently.
  86. */
  87. _GLOBAL(do_load_up_transact_fpu)
  88. mfmsr r6
  89. ori r5,r6,MSR_FP
  90. #ifdef CONFIG_VSX
  91. BEGIN_FTR_SECTION
  92. oris r5,r5,MSR_VSX@h
  93. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  94. #endif
  95. SYNC
  96. MTMSRD(r5)
  97. lfd fr0,THREAD_TRANSACT_FPSCR(r3)
  98. MTFSF_L(fr0)
  99. REST_32FPVSRS_TRANSACT(0, R4, R3)
  100. /* FP/VSX off again */
  101. MTMSRD(r6)
  102. SYNC
  103. blr
  104. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  105. /*
  106. * This task wants to use the FPU now.
  107. * On UP, disable FP for the task which had the FPU previously,
  108. * and save its floating-point registers in its thread_struct.
  109. * Load up this task's FP registers from its thread_struct,
  110. * enable the FPU for the current task and return to the task.
  111. */
  112. _GLOBAL(load_up_fpu)
  113. mfmsr r5
  114. ori r5,r5,MSR_FP
  115. #ifdef CONFIG_VSX
  116. BEGIN_FTR_SECTION
  117. oris r5,r5,MSR_VSX@h
  118. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  119. #endif
  120. SYNC
  121. MTMSRD(r5) /* enable use of fpu now */
  122. isync
  123. /*
  124. * For SMP, we don't do lazy FPU switching because it just gets too
  125. * horrendously complex, especially when a task switches from one CPU
  126. * to another. Instead we call giveup_fpu in switch_to.
  127. */
  128. #ifndef CONFIG_SMP
  129. LOAD_REG_ADDRBASE(r3, last_task_used_math)
  130. toreal(r3)
  131. PPC_LL r4,ADDROFF(last_task_used_math)(r3)
  132. PPC_LCMPI 0,r4,0
  133. beq 1f
  134. toreal(r4)
  135. addi r4,r4,THREAD /* want last_task_used_math->thread */
  136. SAVE_32FPVSRS(0, R5, R4)
  137. mffs fr0
  138. stfd fr0,THREAD_FPSCR(r4)
  139. PPC_LL r5,PT_REGS(r4)
  140. toreal(r5)
  141. PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  142. li r10,MSR_FP|MSR_FE0|MSR_FE1
  143. andc r4,r4,r10 /* disable FP for previous task */
  144. PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  145. 1:
  146. #endif /* CONFIG_SMP */
  147. /* enable use of FP after return */
  148. #ifdef CONFIG_PPC32
  149. mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  150. lwz r4,THREAD_FPEXC_MODE(r5)
  151. ori r9,r9,MSR_FP /* enable FP for current */
  152. or r9,r9,r4
  153. #else
  154. ld r4,PACACURRENT(r13)
  155. addi r5,r4,THREAD /* Get THREAD */
  156. lwz r4,THREAD_FPEXC_MODE(r5)
  157. ori r12,r12,MSR_FP
  158. or r12,r12,r4
  159. std r12,_MSR(r1)
  160. #endif
  161. lfd fr0,THREAD_FPSCR(r5)
  162. MTFSF_L(fr0)
  163. REST_32FPVSRS(0, R4, R5)
  164. #ifndef CONFIG_SMP
  165. subi r4,r5,THREAD
  166. fromreal(r4)
  167. PPC_STL r4,ADDROFF(last_task_used_math)(r3)
  168. #endif /* CONFIG_SMP */
  169. /* restore registers and return */
  170. /* we haven't used ctr or xer or lr */
  171. blr
  172. /*
  173. * giveup_fpu(tsk)
  174. * Disable FP for the task given as the argument,
  175. * and save the floating-point registers in its thread_struct.
  176. * Enables the FPU for use in the kernel on return.
  177. */
  178. _GLOBAL(giveup_fpu)
  179. mfmsr r5
  180. ori r5,r5,MSR_FP
  181. #ifdef CONFIG_VSX
  182. BEGIN_FTR_SECTION
  183. oris r5,r5,MSR_VSX@h
  184. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  185. #endif
  186. SYNC_601
  187. ISYNC_601
  188. MTMSRD(r5) /* enable use of fpu now */
  189. SYNC_601
  190. isync
  191. PPC_LCMPI 0,r3,0
  192. beqlr- /* if no previous owner, done */
  193. addi r3,r3,THREAD /* want THREAD of task */
  194. PPC_LL r5,PT_REGS(r3)
  195. PPC_LCMPI 0,r5,0
  196. SAVE_32FPVSRS(0, R4 ,R3)
  197. mffs fr0
  198. stfd fr0,THREAD_FPSCR(r3)
  199. beq 1f
  200. PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  201. li r3,MSR_FP|MSR_FE0|MSR_FE1
  202. #ifdef CONFIG_VSX
  203. BEGIN_FTR_SECTION
  204. oris r3,r3,MSR_VSX@h
  205. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  206. #endif
  207. andc r4,r4,r3 /* disable FP for previous task */
  208. PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  209. 1:
  210. #ifndef CONFIG_SMP
  211. li r5,0
  212. LOAD_REG_ADDRBASE(r4,last_task_used_math)
  213. PPC_STL r5,ADDROFF(last_task_used_math)(r4)
  214. #endif /* CONFIG_SMP */
  215. blr
  216. /*
  217. * These are used in the alignment trap handler when emulating
  218. * single-precision loads and stores.
  219. */
  220. _GLOBAL(cvt_fd)
  221. lfs 0,0(r3)
  222. stfd 0,0(r4)
  223. blr
  224. _GLOBAL(cvt_df)
  225. lfd 0,0(r3)
  226. stfs 0,0(r4)
  227. blr