fpu.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. */
  11. #include <linux/config.h>
  12. #include <asm/reg.h>
  13. #include <asm/page.h>
  14. #include <asm/mmu.h>
  15. #include <asm/pgtable.h>
  16. #include <asm/cputable.h>
  17. #include <asm/cache.h>
  18. #include <asm/thread_info.h>
  19. #include <asm/ppc_asm.h>
  20. #include <asm/asm-offsets.h>
  21. /*
  22. * This task wants to use the FPU now.
  23. * On UP, disable FP for the task which had the FPU previously,
  24. * and save its floating-point registers in its thread_struct.
  25. * Load up this task's FP registers from its thread_struct,
  26. * enable the FPU for the current task and return to the task.
  27. */
  28. _GLOBAL(load_up_fpu)
  29. mfmsr r5
  30. ori r5,r5,MSR_FP
  31. SYNC
  32. MTMSRD(r5) /* enable use of fpu now */
  33. isync
  34. /*
  35. * For SMP, we don't do lazy FPU switching because it just gets too
  36. * horrendously complex, especially when a task switches from one CPU
  37. * to another. Instead we call giveup_fpu in switch_to.
  38. */
  39. #ifndef CONFIG_SMP
  40. LOAD_REG_ADDRBASE(r3, last_task_used_math)
  41. toreal(r3)
  42. PPC_LL r4,ADDROFF(last_task_used_math)(r3)
  43. PPC_LCMPI 0,r4,0
  44. beq 1f
  45. toreal(r4)
  46. addi r4,r4,THREAD /* want last_task_used_math->thread */
  47. SAVE_32FPRS(0, r4)
  48. mffs fr0
  49. stfd fr0,THREAD_FPSCR(r4)
  50. PPC_LL r5,PT_REGS(r4)
  51. toreal(r5)
  52. PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  53. li r10,MSR_FP|MSR_FE0|MSR_FE1
  54. andc r4,r4,r10 /* disable FP for previous task */
  55. PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  56. 1:
  57. #endif /* CONFIG_SMP */
  58. /* enable use of FP after return */
  59. #ifdef CONFIG_PPC32
  60. mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
  61. lwz r4,THREAD_FPEXC_MODE(r5)
  62. ori r9,r9,MSR_FP /* enable FP for current */
  63. or r9,r9,r4
  64. #else
  65. ld r4,PACACURRENT(r13)
  66. addi r5,r4,THREAD /* Get THREAD */
  67. lwz r4,THREAD_FPEXC_MODE(r5)
  68. ori r12,r12,MSR_FP
  69. or r12,r12,r4
  70. std r12,_MSR(r1)
  71. #endif
  72. lfd fr0,THREAD_FPSCR(r5)
  73. mtfsf 0xff,fr0
  74. REST_32FPRS(0, r5)
  75. #ifndef CONFIG_SMP
  76. subi r4,r5,THREAD
  77. fromreal(r4)
  78. PPC_STL r4,ADDROFF(last_task_used_math)(r3)
  79. #endif /* CONFIG_SMP */
  80. /* restore registers and return */
  81. /* we haven't used ctr or xer or lr */
  82. b fast_exception_return
  83. /*
  84. * giveup_fpu(tsk)
  85. * Disable FP for the task given as the argument,
  86. * and save the floating-point registers in its thread_struct.
  87. * Enables the FPU for use in the kernel on return.
  88. */
  89. _GLOBAL(giveup_fpu)
  90. mfmsr r5
  91. ori r5,r5,MSR_FP
  92. SYNC_601
  93. ISYNC_601
  94. MTMSRD(r5) /* enable use of fpu now */
  95. SYNC_601
  96. isync
  97. PPC_LCMPI 0,r3,0
  98. beqlr- /* if no previous owner, done */
  99. addi r3,r3,THREAD /* want THREAD of task */
  100. PPC_LL r5,PT_REGS(r3)
  101. PPC_LCMPI 0,r5,0
  102. SAVE_32FPRS(0, r3)
  103. mffs fr0
  104. stfd fr0,THREAD_FPSCR(r3)
  105. beq 1f
  106. PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  107. li r3,MSR_FP|MSR_FE0|MSR_FE1
  108. andc r4,r4,r3 /* disable FP for previous task */
  109. PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  110. 1:
  111. #ifndef CONFIG_SMP
  112. li r5,0
  113. LOAD_REG_ADDRBASE(r4,last_task_used_math)
  114. PPC_STL r5,ADDROFF(last_task_used_math)(r4)
  115. #endif /* CONFIG_SMP */
  116. blr
  117. /*
  118. * These are used in the alignment trap handler when emulating
  119. * single-precision loads and stores.
  120. * We restore and save the fpscr so the task gets the same result
  121. * and exceptions as if the cpu had performed the load or store.
  122. */
  123. _GLOBAL(cvt_fd)
  124. lfd 0,THREAD_FPSCR(r5) /* load up fpscr value */
  125. mtfsf 0xff,0
  126. lfs 0,0(r3)
  127. stfd 0,0(r4)
  128. mffs 0
  129. stfd 0,THREAD_FPSCR(r5) /* save new fpscr value */
  130. blr
  131. _GLOBAL(cvt_df)
  132. lfd 0,THREAD_FPSCR(r5) /* load up fpscr value */
  133. mtfsf 0xff,0
  134. lfd 0,0(r3)
  135. stfs 0,0(r4)
  136. mffs 0
  137. stfd 0,THREAD_FPSCR(r5) /* save new fpscr value */
  138. blr