r4k_switch.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 1995, 1996, 1998, 1999, 2002, 2003 Ralf Baechle
  7. * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
  8. * Copyright (C) 1994, 1995, 1996, by Andreas Busse
  9. * Copyright (C) 1999 Silicon Graphics, Inc.
  10. * Copyright (C) 2000 MIPS Technologies, Inc.
  11. * written by Carsten Langgaard, carstenl@mips.com
  12. */
  13. #include <asm/asm.h>
  14. #include <asm/cachectl.h>
  15. #include <asm/fpregdef.h>
  16. #include <asm/mipsregs.h>
  17. #include <asm/asm-offsets.h>
  18. #include <asm/pgtable-bits.h>
  19. #include <asm/regdef.h>
  20. #include <asm/stackframe.h>
  21. #include <asm/thread_info.h>
  22. #include <asm/asmmacro.h>
  23. /*
  24. * Offset to the current process status flags, the first 32 bytes of the
  25. * stack are not used.
  26. */
  27. #define ST_OFF (_THREAD_SIZE - 32 - PT_SIZE + PT_STATUS)
  28. /*
  29. * FPU context is saved iff the process has used it's FPU in the current
  30. * time slice as indicated by _TIF_USEDFPU. In any case, the CU1 bit for user
  31. * space STATUS register should be 0, so that a process *always* starts its
  32. * userland with FPU disabled after each context switch.
  33. *
  34. * FPU will be enabled as soon as the process accesses FPU again, through
  35. * do_cpu() trap.
  36. */
  37. /*
  38. * task_struct *resume(task_struct *prev, task_struct *next,
  39. * struct thread_info *next_ti, int usedfpu)
  40. */
  41. .align 5
  42. LEAF(resume)
  43. mfc0 t1, CP0_STATUS
  44. LONG_S t1, THREAD_STATUS(a0)
  45. cpu_save_nonscratch a0
  46. LONG_S ra, THREAD_REG31(a0)
  47. /*
  48. * check if we need to save FPU registers
  49. */
  50. beqz a3, 1f
  51. PTR_L t3, TASK_THREAD_INFO(a0)
  52. /*
  53. * clear saved user stack CU1 bit
  54. */
  55. LONG_L t0, ST_OFF(t3)
  56. li t1, ~ST0_CU1
  57. and t0, t0, t1
  58. LONG_S t0, ST_OFF(t3)
  59. fpu_save_double a0 t0 t1 # c0_status passed in t0
  60. # clobbers t1
  61. 1:
  62. /*
  63. * The order of restoring the registers takes care of the race
  64. * updating $28, $29 and kernelsp without disabling ints.
  65. */
  66. move $28, a2
  67. cpu_restore_nonscratch a1
  68. PTR_ADDU t0, $28, _THREAD_SIZE - 32
  69. set_saved_sp t0, t1, t2
  70. #ifdef CONFIG_MIPS_MT_SMTC
  71. /* Read-modify-writes of Status must be atomic on a VPE */
  72. mfc0 t2, CP0_TCSTATUS
  73. ori t1, t2, TCSTATUS_IXMT
  74. mtc0 t1, CP0_TCSTATUS
  75. andi t2, t2, TCSTATUS_IXMT
  76. _ehb
  77. DMT 8 # dmt t0
  78. move t1,ra
  79. jal mips_ihb
  80. move ra,t1
  81. #endif /* CONFIG_MIPS_MT_SMTC */
  82. mfc0 t1, CP0_STATUS /* Do we really need this? */
  83. li a3, 0xff01
  84. and t1, a3
  85. LONG_L a2, THREAD_STATUS(a1)
  86. nor a3, $0, a3
  87. and a2, a3
  88. or a2, t1
  89. mtc0 a2, CP0_STATUS
  90. #ifdef CONFIG_MIPS_MT_SMTC
  91. _ehb
  92. andi t0, t0, VPECONTROL_TE
  93. beqz t0, 1f
  94. emt
  95. 1:
  96. mfc0 t1, CP0_TCSTATUS
  97. xori t1, t1, TCSTATUS_IXMT
  98. or t1, t1, t2
  99. mtc0 t1, CP0_TCSTATUS
  100. _ehb
  101. #endif /* CONFIG_MIPS_MT_SMTC */
  102. move v0, a0
  103. jr ra
  104. END(resume)
  105. /*
  106. * Save a thread's fp context.
  107. */
  108. LEAF(_save_fp)
  109. #ifdef CONFIG_64BIT
  110. mfc0 t0, CP0_STATUS
  111. #endif
  112. fpu_save_double a0 t0 t1 # clobbers t1
  113. jr ra
  114. END(_save_fp)
  115. /*
  116. * Restore a thread's fp context.
  117. */
  118. LEAF(_restore_fp)
  119. #ifdef CONFIG_64BIT
  120. mfc0 t0, CP0_STATUS
  121. #endif
  122. fpu_restore_double a0 t0 t1 # clobbers t1
  123. jr ra
  124. END(_restore_fp)
  125. /*
  126. * Load the FPU with signalling NANS. This bit pattern we're using has
  127. * the property that no matter whether considered as single or as double
  128. * precision represents signaling NANS.
  129. *
  130. * We initialize fcr31 to rounding to nearest, no exceptions.
  131. */
  132. #define FPU_DEFAULT 0x00000000
  133. LEAF(_init_fpu)
  134. #ifdef CONFIG_MIPS_MT_SMTC
  135. /* Rather than manipulate per-VPE Status, set per-TC bit in TCStatus */
  136. mfc0 t0, CP0_TCSTATUS
  137. /* Bit position is the same for Status, TCStatus */
  138. li t1, ST0_CU1
  139. or t0, t1
  140. mtc0 t0, CP0_TCSTATUS
  141. #else /* Normal MIPS CU1 enable */
  142. mfc0 t0, CP0_STATUS
  143. li t1, ST0_CU1
  144. or t0, t1
  145. mtc0 t0, CP0_STATUS
  146. #endif /* CONFIG_MIPS_MT_SMTC */
  147. enable_fpu_hazard
  148. li t1, FPU_DEFAULT
  149. ctc1 t1, fcr31
  150. li t1, -1 # SNaN
  151. #ifdef CONFIG_64BIT
  152. sll t0, t0, 5
  153. bgez t0, 1f # 16 / 32 register mode?
  154. dmtc1 t1, $f1
  155. dmtc1 t1, $f3
  156. dmtc1 t1, $f5
  157. dmtc1 t1, $f7
  158. dmtc1 t1, $f9
  159. dmtc1 t1, $f11
  160. dmtc1 t1, $f13
  161. dmtc1 t1, $f15
  162. dmtc1 t1, $f17
  163. dmtc1 t1, $f19
  164. dmtc1 t1, $f21
  165. dmtc1 t1, $f23
  166. dmtc1 t1, $f25
  167. dmtc1 t1, $f27
  168. dmtc1 t1, $f29
  169. dmtc1 t1, $f31
  170. 1:
  171. #endif
  172. #ifdef CONFIG_CPU_MIPS32
  173. mtc1 t1, $f0
  174. mtc1 t1, $f1
  175. mtc1 t1, $f2
  176. mtc1 t1, $f3
  177. mtc1 t1, $f4
  178. mtc1 t1, $f5
  179. mtc1 t1, $f6
  180. mtc1 t1, $f7
  181. mtc1 t1, $f8
  182. mtc1 t1, $f9
  183. mtc1 t1, $f10
  184. mtc1 t1, $f11
  185. mtc1 t1, $f12
  186. mtc1 t1, $f13
  187. mtc1 t1, $f14
  188. mtc1 t1, $f15
  189. mtc1 t1, $f16
  190. mtc1 t1, $f17
  191. mtc1 t1, $f18
  192. mtc1 t1, $f19
  193. mtc1 t1, $f20
  194. mtc1 t1, $f21
  195. mtc1 t1, $f22
  196. mtc1 t1, $f23
  197. mtc1 t1, $f24
  198. mtc1 t1, $f25
  199. mtc1 t1, $f26
  200. mtc1 t1, $f27
  201. mtc1 t1, $f28
  202. mtc1 t1, $f29
  203. mtc1 t1, $f30
  204. mtc1 t1, $f31
  205. #else
  206. .set mips3
  207. dmtc1 t1, $f0
  208. dmtc1 t1, $f2
  209. dmtc1 t1, $f4
  210. dmtc1 t1, $f6
  211. dmtc1 t1, $f8
  212. dmtc1 t1, $f10
  213. dmtc1 t1, $f12
  214. dmtc1 t1, $f14
  215. dmtc1 t1, $f16
  216. dmtc1 t1, $f18
  217. dmtc1 t1, $f20
  218. dmtc1 t1, $f22
  219. dmtc1 t1, $f24
  220. dmtc1 t1, $f26
  221. dmtc1 t1, $f28
  222. dmtc1 t1, $f30
  223. #endif
  224. jr ra
  225. END(_init_fpu)