r2300_switch.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <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/regdef.h>
  21. #include <asm/stackframe.h>
  22. #include <asm/thread_info.h>
  23. #include <asm/asmmacro.h>
  24. .set mips1
  25. .align 5
  26. /*
  27. * Offset to the current process status flags, the first 32 bytes of the
  28. * stack are not used.
  29. */
  30. #define ST_OFF (_THREAD_SIZE - 32 - PT_SIZE + PT_STATUS)
  31. /*
  32. * FPU context is saved iff the process has used it's FPU in the current
  33. * time slice as indicated by TIF_USEDFPU. In any case, the CU1 bit for user
  34. * space STATUS register should be 0, so that a process *always* starts its
  35. * userland with FPU disabled after each context switch.
  36. *
  37. * FPU will be enabled as soon as the process accesses FPU again, through
  38. * do_cpu() trap.
  39. */
  40. /*
  41. * task_struct *resume(task_struct *prev, task_struct *next,
  42. * struct thread_info *next_ti) )
  43. */
  44. LEAF(resume)
  45. #ifndef CONFIG_CPU_HAS_LLSC
  46. sw zero, ll_bit
  47. #endif
  48. mfc0 t1, CP0_STATUS
  49. sw t1, THREAD_STATUS(a0)
  50. cpu_save_nonscratch a0
  51. sw ra, THREAD_REG31(a0)
  52. /*
  53. * check if we need to save FPU registers
  54. */
  55. lw t3, TASK_THREAD_INFO(a0)
  56. lw 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. sw t0, TI_FLAGS(t3)
  63. /*
  64. * clear saved user stack CU1 bit
  65. */
  66. lw t0, ST_OFF(t3)
  67. li t1, ~ST0_CU1
  68. and t0, t0, t1
  69. sw t0, ST_OFF(t3)
  70. fpu_save_single a0, t0 # clobbers t0
  71. 1:
  72. /*
  73. * The order of restoring the registers takes care of the race
  74. * updating $28, $29 and kernelsp without disabling ints.
  75. */
  76. move $28, a2
  77. cpu_restore_nonscratch a1
  78. addiu t1, $28, _THREAD_SIZE - 32
  79. sw t1, kernelsp
  80. mfc0 t1, CP0_STATUS /* Do we really need this? */
  81. li a3, 0xff01
  82. and t1, a3
  83. lw a2, THREAD_STATUS(a1)
  84. nor a3, $0, a3
  85. and a2, a3
  86. or a2, t1
  87. mtc0 a2, CP0_STATUS
  88. move v0, a0
  89. jr ra
  90. END(resume)
  91. /*
  92. * Save a thread's fp context.
  93. */
  94. LEAF(_save_fp)
  95. fpu_save_single a0, t1 # clobbers t1
  96. jr ra
  97. END(_save_fp)
  98. /*
  99. * Restore a thread's fp context.
  100. */
  101. LEAF(_restore_fp)
  102. fpu_restore_single a0, t1 # clobbers t1
  103. jr ra
  104. END(_restore_fp)
  105. /*
  106. * Load the FPU with signalling NANS. This bit pattern we're using has
  107. * the property that no matter whether considered as single or as double
  108. * precision represents signaling NANS.
  109. *
  110. * We initialize fcr31 to rounding to nearest, no exceptions.
  111. */
  112. #define FPU_DEFAULT 0x00000000
  113. LEAF(_init_fpu)
  114. mfc0 t0, CP0_STATUS
  115. li t1, ST0_CU1
  116. or t0, t1
  117. mtc0 t0, CP0_STATUS
  118. li t1, FPU_DEFAULT
  119. ctc1 t1, fcr31
  120. li t0, -1
  121. mtc1 t0, $f0
  122. mtc1 t0, $f1
  123. mtc1 t0, $f2
  124. mtc1 t0, $f3
  125. mtc1 t0, $f4
  126. mtc1 t0, $f5
  127. mtc1 t0, $f6
  128. mtc1 t0, $f7
  129. mtc1 t0, $f8
  130. mtc1 t0, $f9
  131. mtc1 t0, $f10
  132. mtc1 t0, $f11
  133. mtc1 t0, $f12
  134. mtc1 t0, $f13
  135. mtc1 t0, $f14
  136. mtc1 t0, $f15
  137. mtc1 t0, $f16
  138. mtc1 t0, $f17
  139. mtc1 t0, $f18
  140. mtc1 t0, $f19
  141. mtc1 t0, $f20
  142. mtc1 t0, $f21
  143. mtc1 t0, $f22
  144. mtc1 t0, $f23
  145. mtc1 t0, $f24
  146. mtc1 t0, $f25
  147. mtc1 t0, $f26
  148. mtc1 t0, $f27
  149. mtc1 t0, $f28
  150. mtc1 t0, $f29
  151. mtc1 t0, $f30
  152. mtc1 t0, $f31
  153. jr ra
  154. END(_init_fpu)