fpu.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. LOADBASE(r3, last_task_used_math)
  41. tophys(r3,r3)
  42. LDL r4,OFF(last_task_used_math)(r3)
  43. CMPI 0,r4,0
  44. beq 1f
  45. tophys(r4,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-4(r4)
  50. LDL r5,PT_REGS(r4)
  51. tophys(r5,r5)
  52. LDL 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. 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. ld 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-4(r5)
  73. mtfsf 0xff,fr0
  74. REST_32FPRS(0, r5)
  75. #ifndef CONFIG_SMP
  76. subi r4,r5,THREAD
  77. tovirt(r4,r4)
  78. STL r4,OFF(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. CMPI 0,r3,0
  98. beqlr- /* if no previous owner, done */
  99. addi r3,r3,THREAD /* want THREAD of task */
  100. LDL r5,PT_REGS(r3)
  101. CMPI 0,r5,0
  102. SAVE_32FPRS(0, r3)
  103. mffs fr0
  104. stfd fr0,THREAD_FPSCR-4(r3)
  105. beq 1f
  106. LDL 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. STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  110. 1:
  111. #ifndef CONFIG_SMP
  112. li r5,0
  113. LOADBASE(r4,last_task_used_math)
  114. STL r5,OFF(last_task_used_math)(r4)
  115. #endif /* CONFIG_SMP */
  116. blr