r4k_switch.S 5.0 KB

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