r4k_switch.S
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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 by 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.  */
  11. #include <asm/asm.h>
  12. #include <asm/cachectl.h>
  13. #include <asm/fpregdef.h>
  14. #include <asm/mipsregs.h>
  15. #include <asm/offset.h>
  16. #include <asm/page.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/processor.h>
  19. #include <asm/regdef.h>
  20. #include <asm/stackframe.h>
  21. #include <asm/asmmacro.h>
  22. .set mips3
  23. /*
  24.  * task_struct *resume(task_struct *prev, task_struct *next)
  25.  */
  26. .set noreorder
  27. .align 5
  28. LEAF(resume)
  29. mfc0 t1, CP0_STATUS
  30. sd t1, THREAD_STATUS(a0)
  31. cpu_save_nonscratch a0
  32. sd ra, THREAD_REG31(a0)
  33. /*
  34.  * The order of restoring the registers takes care of the race
  35.  * updating $28, $29 and kernelsp without disabling ints.
  36.  */
  37. move $28, a1
  38. cpu_restore_nonscratch $28
  39. daddiu a1, $28, KERNEL_STACK_SIZE-32
  40. set_saved_sp a1 t0
  41. mfc0 t1, CP0_STATUS /* Do we really need this? */
  42. li a3, 0xff00
  43. and t1, a3
  44. ld a2, THREAD_STATUS($28)
  45. nor a3, $0, a3
  46. and a2, a3
  47. or a2, t1
  48. mtc0 a2, CP0_STATUS
  49. jr ra
  50.  move v0, a0
  51. END(resume)
  52. /*
  53.  * Do lazy fpu context switch.  Saves FPU context to the process in a0
  54.  * and loads the new context of the current process.
  55.  */
  56. #define ST_OFF (KERNEL_STACK_SIZE - 32 - PT_SIZE + PT_STATUS)
  57. LEAF(lazy_fpu_switch)
  58. mfc0 t0, CP0_STATUS # enable cp1
  59. li t3, ST0_CU1
  60. or t0, t3
  61. mtc0 t0, CP0_STATUS
  62. FPU_ENABLE_HAZARD
  63. beqz a0, 2f # Save floating point state
  64.  nor t3, zero, t3
  65. ld t1, ST_OFF(a0) # last thread looses fpu
  66. and t1, t3
  67. sd t1, ST_OFF(a0)
  68. sll t2, t1, 5
  69. bgez t2, 1f
  70.  sdc1 $f0, (THREAD_FPU + 0x00)(a0)
  71. fpu_save_16odd a0
  72. 1:
  73. fpu_save_16even a0 t1 # clobbers t1
  74. 2:
  75. beqz a1, 3f
  76. sll t0, t0, 5 # load new fp state
  77. bgez t0, 1f
  78.  ldc1 $f0, (THREAD_FPU + 0x00)(a1)
  79. fpu_restore_16odd a1
  80. 1:
  81. .set reorder
  82. fpu_restore_16even a1, t0 # clobbers t0
  83. 3:
  84. jr ra
  85. END(lazy_fpu_switch)
  86. /*
  87.  * Save a thread's fp context.
  88.  */
  89. .set noreorder
  90. LEAF(save_fp)
  91. mfc0 t0, CP0_STATUS
  92. sll t1, t0, 5
  93. bgez t1, 1f # 16 register mode?
  94.  nop
  95. fpu_save_16odd a0
  96. 1:
  97. fpu_save_16even a0 t1 # clobbers t1
  98. jr ra
  99.  sdc1 $f0, (THREAD_FPU + 0x00)(a0)
  100. END(save_fp)
  101. /*
  102.  * Restore a thread's fp context.
  103.  */
  104. LEAF(restore_fp)
  105. mfc0 t0, CP0_STATUS
  106. sll t1, t0, 5
  107. bgez t1, 1f # 16 register mode?
  108.  nop
  109. fpu_restore_16odd a0
  110. 1:
  111. fpu_restore_16even a0, t0 # clobbers t0
  112. jr ra
  113.  ldc1 $f0, (THREAD_FPU + 0x00)(a0)
  114. END(restore_fp)
  115. /*
  116.  * Load the FPU with signalling NANS.  This bit pattern we're using has
  117.  * the property that no matter whether considered as single or as double
  118.  * precision represents signaling NANS.
  119.  *
  120.  * We initialize fcr31 to rounding to nearest, no exceptions.
  121.  */
  122. #define FPU_DEFAULT  0x00000000
  123. LEAF(init_fpu)
  124. mfc0 t0, CP0_STATUS
  125. li t1, ST0_CU1
  126. or t0, t1
  127. mtc0 t0, CP0_STATUS
  128. FPU_ENABLE_HAZARD
  129. sll t0, t0, 5
  130. li t1, FPU_DEFAULT
  131. ctc1 t1, fcr31
  132. bgez t0, 1f # 16 / 32 register mode?
  133.  li t0, -1
  134. dmtc1 t0, $f1
  135. dmtc1 t0, $f3
  136. dmtc1 t0, $f5
  137. dmtc1 t0, $f7
  138. dmtc1 t0, $f9
  139. dmtc1 t0, $f11
  140. dmtc1 t0, $f13
  141. dmtc1 t0, $f15
  142. dmtc1 t0, $f17
  143. dmtc1 t0, $f19
  144. dmtc1 t0, $f21
  145. dmtc1 t0, $f23
  146. dmtc1 t0, $f25
  147. dmtc1 t0, $f27
  148. dmtc1 t0, $f29
  149. dmtc1 t0, $f31
  150. 1: dmtc1 t0, $f0
  151. dmtc1 t0, $f2
  152. dmtc1 t0, $f4
  153. dmtc1 t0, $f6
  154. dmtc1 t0, $f8
  155. dmtc1 t0, $f10
  156. dmtc1 t0, $f12
  157. dmtc1 t0, $f14
  158. dmtc1 t0, $f16
  159. dmtc1 t0, $f18
  160. dmtc1 t0, $f20
  161. dmtc1 t0, $f22
  162. dmtc1 t0, $f24
  163. dmtc1 t0, $f26
  164. dmtc1 t0, $f28
  165. jr ra
  166.  dmtc1 t0, $f30
  167. END(init_fpu)