fpu.S 3.7 KB

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