r4k_switch.S 5.1 KB

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