fpu.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #include <asm/export.h>
  27. #include <asm/asm-compat.h>
  28. #include <asm/feature-fixups.h>
  29. #ifdef CONFIG_VSX
  30. #define __REST_32FPVSRS(n,c,base) \
  31. BEGIN_FTR_SECTION \
  32. b 2f; \
  33. END_FTR_SECTION_IFSET(CPU_FTR_VSX); \
  34. REST_32FPRS(n,base); \
  35. b 3f; \
  36. 2: REST_32VSRS(n,c,base); \
  37. 3:
  38. #define __SAVE_32FPVSRS(n,c,base) \
  39. BEGIN_FTR_SECTION \
  40. b 2f; \
  41. END_FTR_SECTION_IFSET(CPU_FTR_VSX); \
  42. SAVE_32FPRS(n,base); \
  43. b 3f; \
  44. 2: SAVE_32VSRS(n,c,base); \
  45. 3:
  46. #else
  47. #define __REST_32FPVSRS(n,b,base) REST_32FPRS(n, base)
  48. #define __SAVE_32FPVSRS(n,b,base) SAVE_32FPRS(n, base)
  49. #endif
  50. #define REST_32FPVSRS(n,c,base) __REST_32FPVSRS(n,__REG_##c,__REG_##base)
  51. #define SAVE_32FPVSRS(n,c,base) __SAVE_32FPVSRS(n,__REG_##c,__REG_##base)
  52. /*
  53. * Load state from memory into FP registers including FPSCR.
  54. * Assumes the caller has enabled FP in the MSR.
  55. */
  56. _GLOBAL(load_fp_state)
  57. lfd fr0,FPSTATE_FPSCR(r3)
  58. MTFSF_L(fr0)
  59. REST_32FPVSRS(0, R4, R3)
  60. blr
  61. EXPORT_SYMBOL(load_fp_state)
  62. /*
  63. * Store FP state into memory, including FPSCR
  64. * Assumes the caller has enabled FP in the MSR.
  65. */
  66. _GLOBAL(store_fp_state)
  67. SAVE_32FPVSRS(0, R4, R3)
  68. mffs fr0
  69. stfd fr0,FPSTATE_FPSCR(r3)
  70. blr
  71. EXPORT_SYMBOL(store_fp_state)
  72. /*
  73. * This task wants to use the FPU now.
  74. * On UP, disable FP for the task which had the FPU previously,
  75. * and save its floating-point registers in its thread_struct.
  76. * Load up this task's FP registers from its thread_struct,
  77. * enable the FPU for the current task and return to the task.
  78. * Note that on 32-bit this can only use registers that will be
  79. * restored by fast_exception_return, i.e. r3 - r6, r10 and r11.
  80. */
  81. _GLOBAL(load_up_fpu)
  82. mfmsr r5
  83. ori r5,r5,MSR_FP
  84. #ifdef CONFIG_VSX
  85. BEGIN_FTR_SECTION
  86. oris r5,r5,MSR_VSX@h
  87. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  88. #endif
  89. SYNC
  90. MTMSRD(r5) /* enable use of fpu now */
  91. isync
  92. /* enable use of FP after return */
  93. #ifdef CONFIG_PPC32
  94. mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  95. lwz r4,THREAD_FPEXC_MODE(r5)
  96. ori r9,r9,MSR_FP /* enable FP for current */
  97. or r9,r9,r4
  98. #else
  99. ld r4,PACACURRENT(r13)
  100. addi r5,r4,THREAD /* Get THREAD */
  101. lwz r4,THREAD_FPEXC_MODE(r5)
  102. ori r12,r12,MSR_FP
  103. or r12,r12,r4
  104. std r12,_MSR(r1)
  105. #endif
  106. /* Don't care if r4 overflows, this is desired behaviour */
  107. lbz r4,THREAD_LOAD_FP(r5)
  108. addi r4,r4,1
  109. stb r4,THREAD_LOAD_FP(r5)
  110. addi r10,r5,THREAD_FPSTATE
  111. lfd fr0,FPSTATE_FPSCR(r10)
  112. MTFSF_L(fr0)
  113. REST_32FPVSRS(0, R4, R10)
  114. /* restore registers and return */
  115. /* we haven't used ctr or xer or lr */
  116. blr
  117. /*
  118. * save_fpu(tsk)
  119. * Save the floating-point registers in its thread_struct.
  120. * Enables the FPU for use in the kernel on return.
  121. */
  122. _GLOBAL(save_fpu)
  123. addi r3,r3,THREAD /* want THREAD of task */
  124. PPC_LL r6,THREAD_FPSAVEAREA(r3)
  125. PPC_LL r5,PT_REGS(r3)
  126. PPC_LCMPI 0,r6,0
  127. bne 2f
  128. addi r6,r3,THREAD_FPSTATE
  129. 2: SAVE_32FPVSRS(0, R4, R6)
  130. mffs fr0
  131. stfd fr0,FPSTATE_FPSCR(r6)
  132. blr
  133. /*
  134. * These are used in the alignment trap handler when emulating
  135. * single-precision loads and stores.
  136. */
  137. _GLOBAL(cvt_fd)
  138. lfs 0,0(r3)
  139. stfd 0,0(r4)
  140. blr
  141. _GLOBAL(cvt_df)
  142. lfd 0,0(r3)
  143. stfs 0,0(r4)
  144. blr