fpu.S 3.8 KB

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