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