r4k_switch.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. #ifndef USE_ALTERNATE_RESUME_IMPL
  29. /*
  30. * task_struct *resume(task_struct *prev, task_struct *next,
  31. * struct thread_info *next_ti, s32 fp_save)
  32. */
  33. .align 5
  34. LEAF(resume)
  35. mfc0 t1, CP0_STATUS
  36. LONG_S t1, THREAD_STATUS(a0)
  37. cpu_save_nonscratch a0
  38. LONG_S ra, THREAD_REG31(a0)
  39. /*
  40. * Check whether we need to save any FP context. FP context is saved
  41. * iff the process has used the context with the scalar FPU or the MSA
  42. * ASE in the current time slice, as indicated by _TIF_USEDFPU and
  43. * _TIF_USEDMSA respectively. switch_to will have set fp_save
  44. * accordingly to an FP_SAVE_ enum value.
  45. */
  46. beqz a3, 2f
  47. /*
  48. * We do. Clear the saved CU1 bit for prev, such that next time it is
  49. * scheduled it will start in userland with the FPU disabled. If the
  50. * task uses the FPU then it will be enabled again via the do_cpu trap.
  51. * This allows us to lazily restore the FP context.
  52. */
  53. PTR_L t3, TASK_THREAD_INFO(a0)
  54. LONG_L t0, ST_OFF(t3)
  55. li t1, ~ST0_CU1
  56. and t0, t0, t1
  57. LONG_S t0, ST_OFF(t3)
  58. /* Check whether we're saving scalar or vector context. */
  59. bgtz a3, 1f
  60. /* Save 128b MSA vector context. */
  61. msa_save_all a0
  62. b 2f
  63. 1: /* Save 32b/64b scalar FP context. */
  64. fpu_save_double a0 t0 t1 # c0_status passed in t0
  65. # clobbers t1
  66. 2:
  67. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  68. PTR_LA t8, __stack_chk_guard
  69. LONG_L t9, TASK_STACK_CANARY(a1)
  70. LONG_S t9, 0(t8)
  71. #endif
  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. mfc0 t1, CP0_STATUS /* Do we really need this? */
  81. li a3, 0xff01
  82. and t1, a3
  83. LONG_L a2, THREAD_STATUS(a1)
  84. nor a3, $0, a3
  85. and a2, a3
  86. or a2, t1
  87. mtc0 a2, CP0_STATUS
  88. move v0, a0
  89. jr ra
  90. END(resume)
  91. #endif /* USE_ALTERNATE_RESUME_IMPL */
  92. /*
  93. * Save a thread's fp context.
  94. */
  95. LEAF(_save_fp)
  96. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
  97. mfc0 t0, CP0_STATUS
  98. #endif
  99. fpu_save_double a0 t0 t1 # clobbers t1
  100. jr ra
  101. END(_save_fp)
  102. /*
  103. * Restore a thread's fp context.
  104. */
  105. LEAF(_restore_fp)
  106. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
  107. mfc0 t0, CP0_STATUS
  108. #endif
  109. fpu_restore_double a0 t0 t1 # clobbers t1
  110. jr ra
  111. END(_restore_fp)
  112. #ifdef CONFIG_CPU_HAS_MSA
  113. /*
  114. * Save a thread's MSA vector context.
  115. */
  116. LEAF(_save_msa)
  117. msa_save_all a0
  118. jr ra
  119. END(_save_msa)
  120. /*
  121. * Restore a thread's MSA vector context.
  122. */
  123. LEAF(_restore_msa)
  124. msa_restore_all a0
  125. jr ra
  126. END(_restore_msa)
  127. #endif
  128. /*
  129. * Load the FPU with signalling NANS. This bit pattern we're using has
  130. * the property that no matter whether considered as single or as double
  131. * precision represents signaling NANS.
  132. *
  133. * We initialize fcr31 to rounding to nearest, no exceptions.
  134. */
  135. #define FPU_DEFAULT 0x00000000
  136. LEAF(_init_fpu)
  137. mfc0 t0, CP0_STATUS
  138. li t1, ST0_CU1
  139. or t0, t1
  140. mtc0 t0, CP0_STATUS
  141. enable_fpu_hazard
  142. li t1, FPU_DEFAULT
  143. ctc1 t1, fcr31
  144. li t1, -1 # SNaN
  145. #ifdef CONFIG_64BIT
  146. sll t0, t0, 5
  147. bgez t0, 1f # 16 / 32 register mode?
  148. dmtc1 t1, $f1
  149. dmtc1 t1, $f3
  150. dmtc1 t1, $f5
  151. dmtc1 t1, $f7
  152. dmtc1 t1, $f9
  153. dmtc1 t1, $f11
  154. dmtc1 t1, $f13
  155. dmtc1 t1, $f15
  156. dmtc1 t1, $f17
  157. dmtc1 t1, $f19
  158. dmtc1 t1, $f21
  159. dmtc1 t1, $f23
  160. dmtc1 t1, $f25
  161. dmtc1 t1, $f27
  162. dmtc1 t1, $f29
  163. dmtc1 t1, $f31
  164. 1:
  165. #endif
  166. #ifdef CONFIG_CPU_MIPS32
  167. mtc1 t1, $f0
  168. mtc1 t1, $f1
  169. mtc1 t1, $f2
  170. mtc1 t1, $f3
  171. mtc1 t1, $f4
  172. mtc1 t1, $f5
  173. mtc1 t1, $f6
  174. mtc1 t1, $f7
  175. mtc1 t1, $f8
  176. mtc1 t1, $f9
  177. mtc1 t1, $f10
  178. mtc1 t1, $f11
  179. mtc1 t1, $f12
  180. mtc1 t1, $f13
  181. mtc1 t1, $f14
  182. mtc1 t1, $f15
  183. mtc1 t1, $f16
  184. mtc1 t1, $f17
  185. mtc1 t1, $f18
  186. mtc1 t1, $f19
  187. mtc1 t1, $f20
  188. mtc1 t1, $f21
  189. mtc1 t1, $f22
  190. mtc1 t1, $f23
  191. mtc1 t1, $f24
  192. mtc1 t1, $f25
  193. mtc1 t1, $f26
  194. mtc1 t1, $f27
  195. mtc1 t1, $f28
  196. mtc1 t1, $f29
  197. mtc1 t1, $f30
  198. mtc1 t1, $f31
  199. #ifdef CONFIG_CPU_MIPS32_R2
  200. .set push
  201. .set mips64r2
  202. sll t0, t0, 5 # is Status.FR set?
  203. bgez t0, 1f # no: skip setting upper 32b
  204. mthc1 t1, $f0
  205. mthc1 t1, $f1
  206. mthc1 t1, $f2
  207. mthc1 t1, $f3
  208. mthc1 t1, $f4
  209. mthc1 t1, $f5
  210. mthc1 t1, $f6
  211. mthc1 t1, $f7
  212. mthc1 t1, $f8
  213. mthc1 t1, $f9
  214. mthc1 t1, $f10
  215. mthc1 t1, $f11
  216. mthc1 t1, $f12
  217. mthc1 t1, $f13
  218. mthc1 t1, $f14
  219. mthc1 t1, $f15
  220. mthc1 t1, $f16
  221. mthc1 t1, $f17
  222. mthc1 t1, $f18
  223. mthc1 t1, $f19
  224. mthc1 t1, $f20
  225. mthc1 t1, $f21
  226. mthc1 t1, $f22
  227. mthc1 t1, $f23
  228. mthc1 t1, $f24
  229. mthc1 t1, $f25
  230. mthc1 t1, $f26
  231. mthc1 t1, $f27
  232. mthc1 t1, $f28
  233. mthc1 t1, $f29
  234. mthc1 t1, $f30
  235. mthc1 t1, $f31
  236. 1: .set pop
  237. #endif /* CONFIG_CPU_MIPS32_R2 */
  238. #else
  239. .set arch=r4000
  240. dmtc1 t1, $f0
  241. dmtc1 t1, $f2
  242. dmtc1 t1, $f4
  243. dmtc1 t1, $f6
  244. dmtc1 t1, $f8
  245. dmtc1 t1, $f10
  246. dmtc1 t1, $f12
  247. dmtc1 t1, $f14
  248. dmtc1 t1, $f16
  249. dmtc1 t1, $f18
  250. dmtc1 t1, $f20
  251. dmtc1 t1, $f22
  252. dmtc1 t1, $f24
  253. dmtc1 t1, $f26
  254. dmtc1 t1, $f28
  255. dmtc1 t1, $f30
  256. #endif
  257. jr ra
  258. END(_init_fpu)