r2300_switch.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * r2300_switch.S: R2300 specific task switching code.
  3. *
  4. * Copyright (C) 1994, 1995, 1996, 1999 by Ralf Baechle
  5. * Copyright (C) 1994, 1995, 1996 by Andreas Busse
  6. *
  7. * Multi-cpu abstraction and macros for easier reading:
  8. * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
  9. *
  10. * Further modifications to make this work:
  11. * Copyright (c) 1998-2000 Harald Koerfgen
  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/page.h>
  19. #include <asm/regdef.h>
  20. #include <asm/stackframe.h>
  21. #include <asm/thread_info.h>
  22. #include <asm/asmmacro.h>
  23. .set mips1
  24. .align 5
  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. LEAF(resume)
  44. #ifndef CONFIG_CPU_HAS_LLSC
  45. sw zero, ll_bit
  46. #endif
  47. mfc0 t2, CP0_STATUS
  48. cpu_save_nonscratch a0
  49. sw ra, THREAD_REG31(a0)
  50. /*
  51. * check if we need to save FPU registers
  52. */
  53. lw t3, TASK_THREAD_INFO(a0)
  54. lw t0, TI_FLAGS(t3)
  55. li t1, _TIF_USEDFPU
  56. and t1, t0
  57. beqz t1, 1f
  58. nor t1, zero, t1
  59. and t0, t0, t1
  60. sw t0, TI_FLAGS(t3)
  61. /*
  62. * clear saved user stack CU1 bit
  63. */
  64. lw t0, ST_OFF(t3)
  65. li t1, ~ST0_CU1
  66. and t0, t0, t1
  67. sw t0, ST_OFF(t3)
  68. /* clear thread_struct CU1 bit */
  69. and t2, t1
  70. fpu_save_single a0, t0 # clobbers t0
  71. 1:
  72. sw t2, THREAD_STATUS(a0)
  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. addiu t1, $28, _THREAD_SIZE - 32
  80. sw t1, kernelsp
  81. mfc0 t1, CP0_STATUS /* Do we really need this? */
  82. li a3, 0xff01
  83. and t1, a3
  84. lw 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. fpu_save_single a0, t1 # clobbers t1
  97. jr ra
  98. END(_save_fp)
  99. /*
  100. * Restore a thread's fp context.
  101. */
  102. LEAF(_restore_fp)
  103. fpu_restore_single a0, t1 # clobbers t1
  104. jr ra
  105. END(_restore_fp)
  106. /*
  107. * Load the FPU with signalling NANS. This bit pattern we're using has
  108. * the property that no matter whether considered as single or as double
  109. * precision represents signaling NANS.
  110. *
  111. * We initialize fcr31 to rounding to nearest, no exceptions.
  112. */
  113. #define FPU_DEFAULT 0x00000000
  114. LEAF(_init_fpu)
  115. mfc0 t0, CP0_STATUS
  116. li t1, ST0_CU1
  117. or t0, t1
  118. mtc0 t0, CP0_STATUS
  119. li t1, FPU_DEFAULT
  120. ctc1 t1, fcr31
  121. li t0, -1
  122. mtc1 t0, $f0
  123. mtc1 t0, $f1
  124. mtc1 t0, $f2
  125. mtc1 t0, $f3
  126. mtc1 t0, $f4
  127. mtc1 t0, $f5
  128. mtc1 t0, $f6
  129. mtc1 t0, $f7
  130. mtc1 t0, $f8
  131. mtc1 t0, $f9
  132. mtc1 t0, $f10
  133. mtc1 t0, $f11
  134. mtc1 t0, $f12
  135. mtc1 t0, $f13
  136. mtc1 t0, $f14
  137. mtc1 t0, $f15
  138. mtc1 t0, $f16
  139. mtc1 t0, $f17
  140. mtc1 t0, $f18
  141. mtc1 t0, $f19
  142. mtc1 t0, $f20
  143. mtc1 t0, $f21
  144. mtc1 t0, $f22
  145. mtc1 t0, $f23
  146. mtc1 t0, $f24
  147. mtc1 t0, $f25
  148. mtc1 t0, $f26
  149. mtc1 t0, $f27
  150. mtc1 t0, $f28
  151. mtc1 t0, $f29
  152. mtc1 t0, $f30
  153. mtc1 t0, $f31
  154. jr ra
  155. END(_init_fpu)