r4k_switch.S 5.1 KB

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