fpu.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/processor.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/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. .globl load_up_fpu
  29. load_up_fpu:
  30. mfmsr r5
  31. ori r5,r5,MSR_FP
  32. #ifdef CONFIG_PPC64BRIDGE
  33. clrldi r5,r5,1 /* turn off 64-bit mode */
  34. #endif /* CONFIG_PPC64BRIDGE */
  35. SYNC
  36. MTMSRD(r5) /* enable use of fpu now */
  37. isync
  38. /*
  39. * For SMP, we don't do lazy FPU switching because it just gets too
  40. * horrendously complex, especially when a task switches from one CPU
  41. * to another. Instead we call giveup_fpu in switch_to.
  42. */
  43. #ifndef CONFIG_SMP
  44. tophys(r6,0) /* get __pa constant */
  45. addis r3,r6,last_task_used_math@ha
  46. lwz r4,last_task_used_math@l(r3)
  47. cmpwi 0,r4,0
  48. beq 1f
  49. add r4,r4,r6
  50. addi r4,r4,THREAD /* want last_task_used_math->thread */
  51. SAVE_32FPRS(0, r4)
  52. mffs fr0
  53. stfd fr0,THREAD_FPSCR-4(r4)
  54. lwz r5,PT_REGS(r4)
  55. add r5,r5,r6
  56. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  57. li r10,MSR_FP|MSR_FE0|MSR_FE1
  58. andc r4,r4,r10 /* disable FP for previous task */
  59. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  60. 1:
  61. #endif /* CONFIG_SMP */
  62. /* enable use of FP after return */
  63. mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
  64. lwz r4,THREAD_FPEXC_MODE(r5)
  65. ori r9,r9,MSR_FP /* enable FP for current */
  66. or r9,r9,r4
  67. lfd fr0,THREAD_FPSCR-4(r5)
  68. mtfsf 0xff,fr0
  69. REST_32FPRS(0, r5)
  70. #ifndef CONFIG_SMP
  71. subi r4,r5,THREAD
  72. sub r4,r4,r6
  73. stw r4,last_task_used_math@l(r3)
  74. #endif /* CONFIG_SMP */
  75. /* restore registers and return */
  76. /* we haven't used ctr or xer or lr */
  77. b fast_exception_return
  78. /*
  79. * FP unavailable trap from kernel - print a message, but let
  80. * the task use FP in the kernel until it returns to user mode.
  81. */
  82. .globl KernelFP
  83. KernelFP:
  84. lwz r3,_MSR(r1)
  85. ori r3,r3,MSR_FP
  86. stw r3,_MSR(r1) /* enable use of FP after return */
  87. lis r3,86f@h
  88. ori r3,r3,86f@l
  89. mr r4,r2 /* current */
  90. lwz r5,_NIP(r1)
  91. bl printk
  92. b ret_from_except
  93. 86: .string "floating point used in kernel (task=%p, pc=%x)\n"
  94. .align 4,0
  95. /*
  96. * giveup_fpu(tsk)
  97. * Disable FP for the task given as the argument,
  98. * and save the floating-point registers in its thread_struct.
  99. * Enables the FPU for use in the kernel on return.
  100. */
  101. .globl giveup_fpu
  102. giveup_fpu:
  103. mfmsr r5
  104. ori r5,r5,MSR_FP
  105. SYNC_601
  106. ISYNC_601
  107. MTMSRD(r5) /* enable use of fpu now */
  108. SYNC_601
  109. isync
  110. cmpwi 0,r3,0
  111. beqlr- /* if no previous owner, done */
  112. addi r3,r3,THREAD /* want THREAD of task */
  113. lwz r5,PT_REGS(r3)
  114. cmpwi 0,r5,0
  115. SAVE_32FPRS(0, r3)
  116. mffs fr0
  117. stfd fr0,THREAD_FPSCR-4(r3)
  118. beq 1f
  119. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  120. li r3,MSR_FP|MSR_FE0|MSR_FE1
  121. andc r4,r4,r3 /* disable FP for previous task */
  122. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  123. 1:
  124. #ifndef CONFIG_SMP
  125. li r5,0
  126. lis r4,last_task_used_math@ha
  127. stw r5,last_task_used_math@l(r4)
  128. #endif /* CONFIG_SMP */
  129. blr