r4k_switch.S 6.2 KB

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