r4k_switch.S 5.2 KB

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