r4k_switch.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/regdef.h>
  19. #include <asm/stackframe.h>
  20. #include <asm/thread_info.h>
  21. #include <asm/asmmacro.h>
  22. /* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
  23. #undef fp
  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. #ifndef USE_ALTERNATE_RESUME_IMPL
  30. /*
  31. * task_struct *resume(task_struct *prev, task_struct *next,
  32. * struct thread_info *next_ti)
  33. */
  34. .align 5
  35. LEAF(resume)
  36. mfc0 t1, CP0_STATUS
  37. LONG_S t1, THREAD_STATUS(a0)
  38. cpu_save_nonscratch a0
  39. LONG_S ra, THREAD_REG31(a0)
  40. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  41. PTR_LA t8, __stack_chk_guard
  42. LONG_L t9, TASK_STACK_CANARY(a1)
  43. LONG_S t9, 0(t8)
  44. #endif
  45. /*
  46. * The order of restoring the registers takes care of the race
  47. * updating $28, $29 and kernelsp without disabling ints.
  48. */
  49. move $28, a2
  50. cpu_restore_nonscratch a1
  51. PTR_ADDU t0, $28, _THREAD_SIZE - 32
  52. set_saved_sp t0, t1, t2
  53. mfc0 t1, CP0_STATUS /* Do we really need this? */
  54. li a3, 0xff01
  55. and t1, a3
  56. LONG_L a2, THREAD_STATUS(a1)
  57. nor a3, $0, a3
  58. and a2, a3
  59. or a2, t1
  60. mtc0 a2, CP0_STATUS
  61. move v0, a0
  62. jr ra
  63. END(resume)
  64. #endif /* USE_ALTERNATE_RESUME_IMPL */
  65. /*
  66. * Save a thread's fp context.
  67. */
  68. LEAF(_save_fp)
  69. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2) || \
  70. defined(CONFIG_CPU_MIPS32_R6)
  71. mfc0 t0, CP0_STATUS
  72. #endif
  73. fpu_save_double a0 t0 t1 # clobbers t1
  74. jr ra
  75. END(_save_fp)
  76. /*
  77. * Restore a thread's fp context.
  78. */
  79. LEAF(_restore_fp)
  80. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2) || \
  81. defined(CONFIG_CPU_MIPS32_R6)
  82. mfc0 t0, CP0_STATUS
  83. #endif
  84. fpu_restore_double a0 t0 t1 # clobbers t1
  85. jr ra
  86. END(_restore_fp)
  87. #ifdef CONFIG_CPU_HAS_MSA
  88. /*
  89. * Save a thread's MSA vector context.
  90. */
  91. LEAF(_save_msa)
  92. msa_save_all a0
  93. jr ra
  94. END(_save_msa)
  95. /*
  96. * Restore a thread's MSA vector context.
  97. */
  98. LEAF(_restore_msa)
  99. msa_restore_all a0
  100. jr ra
  101. END(_restore_msa)
  102. LEAF(_init_msa_upper)
  103. msa_init_all_upper
  104. jr ra
  105. END(_init_msa_upper)
  106. #endif
  107. /*
  108. * Load the FPU with signalling NANS. This bit pattern we're using has
  109. * the property that no matter whether considered as single or as double
  110. * precision represents signaling NANS.
  111. *
  112. * The value to initialize fcr31 to comes in $a0.
  113. */
  114. .set push
  115. SET_HARDFLOAT
  116. LEAF(_init_fpu)
  117. mfc0 t0, CP0_STATUS
  118. li t1, ST0_CU1
  119. or t0, t1
  120. mtc0 t0, CP0_STATUS
  121. enable_fpu_hazard
  122. ctc1 a0, fcr31
  123. li t1, -1 # SNaN
  124. #ifdef CONFIG_64BIT
  125. sll t0, t0, 5
  126. bgez t0, 1f # 16 / 32 register mode?
  127. dmtc1 t1, $f1
  128. dmtc1 t1, $f3
  129. dmtc1 t1, $f5
  130. dmtc1 t1, $f7
  131. dmtc1 t1, $f9
  132. dmtc1 t1, $f11
  133. dmtc1 t1, $f13
  134. dmtc1 t1, $f15
  135. dmtc1 t1, $f17
  136. dmtc1 t1, $f19
  137. dmtc1 t1, $f21
  138. dmtc1 t1, $f23
  139. dmtc1 t1, $f25
  140. dmtc1 t1, $f27
  141. dmtc1 t1, $f29
  142. dmtc1 t1, $f31
  143. 1:
  144. #endif
  145. #ifdef CONFIG_CPU_MIPS32
  146. mtc1 t1, $f0
  147. mtc1 t1, $f1
  148. mtc1 t1, $f2
  149. mtc1 t1, $f3
  150. mtc1 t1, $f4
  151. mtc1 t1, $f5
  152. mtc1 t1, $f6
  153. mtc1 t1, $f7
  154. mtc1 t1, $f8
  155. mtc1 t1, $f9
  156. mtc1 t1, $f10
  157. mtc1 t1, $f11
  158. mtc1 t1, $f12
  159. mtc1 t1, $f13
  160. mtc1 t1, $f14
  161. mtc1 t1, $f15
  162. mtc1 t1, $f16
  163. mtc1 t1, $f17
  164. mtc1 t1, $f18
  165. mtc1 t1, $f19
  166. mtc1 t1, $f20
  167. mtc1 t1, $f21
  168. mtc1 t1, $f22
  169. mtc1 t1, $f23
  170. mtc1 t1, $f24
  171. mtc1 t1, $f25
  172. mtc1 t1, $f26
  173. mtc1 t1, $f27
  174. mtc1 t1, $f28
  175. mtc1 t1, $f29
  176. mtc1 t1, $f30
  177. mtc1 t1, $f31
  178. #if defined(CONFIG_CPU_MIPS32_R2) || defined(CONFIG_CPU_MIPS32_R6)
  179. .set push
  180. .set MIPS_ISA_LEVEL_RAW
  181. .set fp=64
  182. sll t0, t0, 5 # is Status.FR set?
  183. bgez t0, 1f # no: skip setting upper 32b
  184. mthc1 t1, $f0
  185. mthc1 t1, $f1
  186. mthc1 t1, $f2
  187. mthc1 t1, $f3
  188. mthc1 t1, $f4
  189. mthc1 t1, $f5
  190. mthc1 t1, $f6
  191. mthc1 t1, $f7
  192. mthc1 t1, $f8
  193. mthc1 t1, $f9
  194. mthc1 t1, $f10
  195. mthc1 t1, $f11
  196. mthc1 t1, $f12
  197. mthc1 t1, $f13
  198. mthc1 t1, $f14
  199. mthc1 t1, $f15
  200. mthc1 t1, $f16
  201. mthc1 t1, $f17
  202. mthc1 t1, $f18
  203. mthc1 t1, $f19
  204. mthc1 t1, $f20
  205. mthc1 t1, $f21
  206. mthc1 t1, $f22
  207. mthc1 t1, $f23
  208. mthc1 t1, $f24
  209. mthc1 t1, $f25
  210. mthc1 t1, $f26
  211. mthc1 t1, $f27
  212. mthc1 t1, $f28
  213. mthc1 t1, $f29
  214. mthc1 t1, $f30
  215. mthc1 t1, $f31
  216. 1: .set pop
  217. #endif /* CONFIG_CPU_MIPS32_R2 || CONFIG_CPU_MIPS32_R6 */
  218. #else
  219. .set MIPS_ISA_ARCH_LEVEL_RAW
  220. dmtc1 t1, $f0
  221. dmtc1 t1, $f2
  222. dmtc1 t1, $f4
  223. dmtc1 t1, $f6
  224. dmtc1 t1, $f8
  225. dmtc1 t1, $f10
  226. dmtc1 t1, $f12
  227. dmtc1 t1, $f14
  228. dmtc1 t1, $f16
  229. dmtc1 t1, $f18
  230. dmtc1 t1, $f20
  231. dmtc1 t1, $f22
  232. dmtc1 t1, $f24
  233. dmtc1 t1, $f26
  234. dmtc1 t1, $f28
  235. dmtc1 t1, $f30
  236. #endif
  237. jr ra
  238. END(_init_fpu)
  239. .set pop /* SET_HARDFLOAT */