r4k_switch.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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/offset.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. mfc0 t1, CP0_STATUS /* Do we really need this? */
  82. li a3, 0xff01
  83. and t1, a3
  84. LONG_L a2, THREAD_STATUS(a1)
  85. nor a3, $0, a3
  86. and a2, a3
  87. or a2, t1
  88. mtc0 a2, CP0_STATUS
  89. move v0, a0
  90. jr ra
  91. END(resume)
  92. /*
  93. * Save a thread's fp context.
  94. */
  95. LEAF(_save_fp)
  96. #ifdef CONFIG_64BIT
  97. mfc0 t1, CP0_STATUS
  98. #endif
  99. fpu_save_double a0 t1 t0 t2 # clobbers t1
  100. jr ra
  101. END(_save_fp)
  102. /*
  103. * Restore a thread's fp context.
  104. */
  105. LEAF(_restore_fp)
  106. fpu_restore_double a0, t1 # clobbers t1
  107. jr ra
  108. END(_restore_fp)
  109. /*
  110. * Load the FPU with signalling NANS. This bit pattern we're using has
  111. * the property that no matter whether considered as single or as double
  112. * precision represents signaling NANS.
  113. *
  114. * We initialize fcr31 to rounding to nearest, no exceptions.
  115. */
  116. #define FPU_DEFAULT 0x00000000
  117. LEAF(_init_fpu)
  118. mfc0 t0, CP0_STATUS
  119. li t1, ST0_CU1
  120. or t0, t1
  121. mtc0 t0, CP0_STATUS
  122. fpu_enable_hazard
  123. li t1, FPU_DEFAULT
  124. ctc1 t1, fcr31
  125. li t1, -1 # SNaN
  126. #ifdef CONFIG_64BIT
  127. sll t0, t0, 5
  128. bgez t0, 1f # 16 / 32 register mode?
  129. dmtc1 t1, $f1
  130. dmtc1 t1, $f3
  131. dmtc1 t1, $f5
  132. dmtc1 t1, $f7
  133. dmtc1 t1, $f9
  134. dmtc1 t1, $f11
  135. dmtc1 t1, $f13
  136. dmtc1 t1, $f15
  137. dmtc1 t1, $f17
  138. dmtc1 t1, $f19
  139. dmtc1 t1, $f21
  140. dmtc1 t1, $f23
  141. dmtc1 t1, $f25
  142. dmtc1 t1, $f27
  143. dmtc1 t1, $f29
  144. dmtc1 t1, $f31
  145. 1:
  146. #endif
  147. #ifdef CONFIG_CPU_MIPS32
  148. mtc1 t1, $f0
  149. mtc1 t1, $f1
  150. mtc1 t1, $f2
  151. mtc1 t1, $f3
  152. mtc1 t1, $f4
  153. mtc1 t1, $f5
  154. mtc1 t1, $f6
  155. mtc1 t1, $f7
  156. mtc1 t1, $f8
  157. mtc1 t1, $f9
  158. mtc1 t1, $f10
  159. mtc1 t1, $f11
  160. mtc1 t1, $f12
  161. mtc1 t1, $f13
  162. mtc1 t1, $f14
  163. mtc1 t1, $f15
  164. mtc1 t1, $f16
  165. mtc1 t1, $f17
  166. mtc1 t1, $f18
  167. mtc1 t1, $f19
  168. mtc1 t1, $f20
  169. mtc1 t1, $f21
  170. mtc1 t1, $f22
  171. mtc1 t1, $f23
  172. mtc1 t1, $f24
  173. mtc1 t1, $f25
  174. mtc1 t1, $f26
  175. mtc1 t1, $f27
  176. mtc1 t1, $f28
  177. mtc1 t1, $f29
  178. mtc1 t1, $f30
  179. mtc1 t1, $f31
  180. #else
  181. .set mips3
  182. dmtc1 t1, $f0
  183. dmtc1 t1, $f2
  184. dmtc1 t1, $f4
  185. dmtc1 t1, $f6
  186. dmtc1 t1, $f8
  187. dmtc1 t1, $f10
  188. dmtc1 t1, $f12
  189. dmtc1 t1, $f14
  190. dmtc1 t1, $f16
  191. dmtc1 t1, $f18
  192. dmtc1 t1, $f20
  193. dmtc1 t1, $f22
  194. dmtc1 t1, $f24
  195. dmtc1 t1, $f26
  196. dmtc1 t1, $f28
  197. dmtc1 t1, $f30
  198. #endif
  199. jr ra
  200. END(_init_fpu)