r2300_switch.S 3.3 KB

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