fpu.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 SAVE_32FPVSRS(n,c,base) \
  36. BEGIN_FTR_SECTION \
  37. b 2f; \
  38. END_FTR_SECTION_IFSET(CPU_FTR_VSX); \
  39. SAVE_32FPRS(n,base); \
  40. b 3f; \
  41. 2: SAVE_32VSRS(n,c,base); \
  42. 3:
  43. #else
  44. #define REST_32FPVSRS(n,b,base) REST_32FPRS(n, base)
  45. #define SAVE_32FPVSRS(n,b,base) SAVE_32FPRS(n, base)
  46. #endif
  47. /*
  48. * This task wants to use the FPU now.
  49. * On UP, disable FP for the task which had the FPU previously,
  50. * and save its floating-point registers in its thread_struct.
  51. * Load up this task's FP registers from its thread_struct,
  52. * enable the FPU for the current task and return to the task.
  53. */
  54. _GLOBAL(load_up_fpu)
  55. mfmsr r5
  56. ori r5,r5,MSR_FP
  57. #ifdef CONFIG_VSX
  58. BEGIN_FTR_SECTION
  59. oris r5,r5,MSR_VSX@h
  60. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  61. #endif
  62. SYNC
  63. MTMSRD(r5) /* enable use of fpu now */
  64. isync
  65. /*
  66. * For SMP, we don't do lazy FPU switching because it just gets too
  67. * horrendously complex, especially when a task switches from one CPU
  68. * to another. Instead we call giveup_fpu in switch_to.
  69. */
  70. #ifndef CONFIG_SMP
  71. LOAD_REG_ADDRBASE(r3, last_task_used_math)
  72. toreal(r3)
  73. PPC_LL r4,ADDROFF(last_task_used_math)(r3)
  74. PPC_LCMPI 0,r4,0
  75. beq 1f
  76. toreal(r4)
  77. addi r4,r4,THREAD /* want last_task_used_math->thread */
  78. SAVE_32FPVSRS(0, r5, r4)
  79. mffs fr0
  80. stfd fr0,THREAD_FPSCR(r4)
  81. PPC_LL r5,PT_REGS(r4)
  82. toreal(r5)
  83. PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  84. li r10,MSR_FP|MSR_FE0|MSR_FE1
  85. andc r4,r4,r10 /* disable FP for previous task */
  86. PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  87. 1:
  88. #endif /* CONFIG_SMP */
  89. /* enable use of FP after return */
  90. #ifdef CONFIG_PPC32
  91. mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  92. lwz r4,THREAD_FPEXC_MODE(r5)
  93. ori r9,r9,MSR_FP /* enable FP for current */
  94. or r9,r9,r4
  95. #else
  96. ld r4,PACACURRENT(r13)
  97. addi r5,r4,THREAD /* Get THREAD */
  98. lwz r4,THREAD_FPEXC_MODE(r5)
  99. ori r12,r12,MSR_FP
  100. or r12,r12,r4
  101. std r12,_MSR(r1)
  102. #endif
  103. lfd fr0,THREAD_FPSCR(r5)
  104. MTFSF_L(fr0)
  105. REST_32FPVSRS(0, r4, r5)
  106. #ifndef CONFIG_SMP
  107. subi r4,r5,THREAD
  108. fromreal(r4)
  109. PPC_STL r4,ADDROFF(last_task_used_math)(r3)
  110. #endif /* CONFIG_SMP */
  111. /* restore registers and return */
  112. /* we haven't used ctr or xer or lr */
  113. blr
  114. /*
  115. * giveup_fpu(tsk)
  116. * Disable FP for the task given as the argument,
  117. * and save the floating-point registers in its thread_struct.
  118. * Enables the FPU for use in the kernel on return.
  119. */
  120. _GLOBAL(giveup_fpu)
  121. mfmsr r5
  122. ori r5,r5,MSR_FP
  123. #ifdef CONFIG_VSX
  124. BEGIN_FTR_SECTION
  125. oris r5,r5,MSR_VSX@h
  126. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  127. #endif
  128. SYNC_601
  129. ISYNC_601
  130. MTMSRD(r5) /* enable use of fpu now */
  131. SYNC_601
  132. isync
  133. PPC_LCMPI 0,r3,0
  134. beqlr- /* if no previous owner, done */
  135. addi r3,r3,THREAD /* want THREAD of task */
  136. PPC_LL r5,PT_REGS(r3)
  137. PPC_LCMPI 0,r5,0
  138. SAVE_32FPVSRS(0, r4 ,r3)
  139. mffs fr0
  140. stfd fr0,THREAD_FPSCR(r3)
  141. beq 1f
  142. PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  143. li r3,MSR_FP|MSR_FE0|MSR_FE1
  144. #ifdef CONFIG_VSX
  145. BEGIN_FTR_SECTION
  146. oris r3,r3,MSR_VSX@h
  147. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  148. #endif
  149. andc r4,r4,r3 /* disable FP for previous task */
  150. PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  151. 1:
  152. #ifndef CONFIG_SMP
  153. li r5,0
  154. LOAD_REG_ADDRBASE(r4,last_task_used_math)
  155. PPC_STL r5,ADDROFF(last_task_used_math)(r4)
  156. #endif /* CONFIG_SMP */
  157. blr
  158. /*
  159. * These are used in the alignment trap handler when emulating
  160. * single-precision loads and stores.
  161. */
  162. _GLOBAL(cvt_fd)
  163. lfs 0,0(r3)
  164. stfd 0,0(r4)
  165. blr
  166. _GLOBAL(cvt_df)
  167. lfd 0,0(r3)
  168. stfs 0,0(r4)
  169. blr