swapcontext.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* Save and set current context.
  2. Copyright (C) 2009 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Maciej W. Rozycki <macro@codesourcery.com>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library. If not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <sysdep.h>
  17. #include <sys/asm.h>
  18. #include <sys/fpregdef.h>
  19. #include <sys/regdef.h>
  20. #include "ucontext_i.h"
  21. /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
  22. .text
  23. LOCALSZ = 0
  24. ARGSZ = 0
  25. MASK = 0x00000000
  26. #ifdef __PIC__
  27. LOCALSZ = 1 /* save gp */
  28. #endif
  29. #if _MIPS_SIM != _ABIO32
  30. ARGSZ = 1 /* save a1 */
  31. # ifdef __PIC__
  32. MASK = 0x10000000
  33. # endif
  34. #endif
  35. FRAMESZ = (((ARGSZ + LOCALSZ) * SZREG) + ALSZ) & ALMASK
  36. GPOFF = FRAMESZ - ((ARGSZ + 1) * SZREG)
  37. #if _MIPS_SIM != _ABIO32
  38. A1OFF = FRAMESZ - (1 * SZREG) /* callee-allocated */
  39. #else
  40. A1OFF = FRAMESZ + (1 * SZREG) /* caller-allocated */
  41. #endif
  42. NESTED (__swapcontext, FRAMESZ, ra)
  43. .mask MASK, -(ARGSZ * SZREG)
  44. .fmask 0x00000000, 0
  45. #ifdef __PIC__
  46. SETUP_GP
  47. move a2, sp
  48. # define _SP a2
  49. # if _MIPS_SIM != _ABIO32
  50. move a3, gp
  51. # define _GP a3
  52. # endif
  53. PTR_ADDIU sp, -FRAMESZ
  54. SETUP_GP64 (GPOFF, __swapcontext)
  55. SAVE_GP (GPOFF)
  56. #else /* ! __PIC__ */
  57. # define _SP sp
  58. # define _GP gp
  59. #endif /* ! __PIC__ */
  60. /* Store a magic flag. */
  61. li v1, 1
  62. REG_S v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
  63. REG_S s0, (16 * SZREG + MCONTEXT_GREGS)(a0)
  64. REG_S s1, (17 * SZREG + MCONTEXT_GREGS)(a0)
  65. REG_S s2, (18 * SZREG + MCONTEXT_GREGS)(a0)
  66. REG_S s3, (19 * SZREG + MCONTEXT_GREGS)(a0)
  67. REG_S s4, (20 * SZREG + MCONTEXT_GREGS)(a0)
  68. REG_S s5, (21 * SZREG + MCONTEXT_GREGS)(a0)
  69. REG_S s6, (22 * SZREG + MCONTEXT_GREGS)(a0)
  70. REG_S s7, (23 * SZREG + MCONTEXT_GREGS)(a0)
  71. #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
  72. REG_S _GP, (28 * SZREG + MCONTEXT_GREGS)(a0)
  73. #endif
  74. REG_S _SP, (29 * SZREG + MCONTEXT_GREGS)(a0)
  75. REG_S fp, (30 * SZREG + MCONTEXT_GREGS)(a0)
  76. REG_S ra, (31 * SZREG + MCONTEXT_GREGS)(a0)
  77. REG_S ra, MCONTEXT_PC(a0)
  78. #ifdef __mips_hard_float
  79. # if _MIPS_SIM == _ABI64
  80. s.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(a0)
  81. s.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(a0)
  82. s.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(a0)
  83. s.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(a0)
  84. s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
  85. s.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(a0)
  86. s.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(a0)
  87. s.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(a0)
  88. # else /* _MIPS_SIM != _ABI64 */
  89. s.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(a0)
  90. s.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(a0)
  91. s.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(a0)
  92. s.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(a0)
  93. s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
  94. s.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(a0)
  95. # endif /* _MIPS_SIM != _ABI64 */
  96. cfc1 v1, fcr31
  97. sw v1, MCONTEXT_FPC_CSR(a0)
  98. #endif /* __mips_hard_float */
  99. REG_S a1, A1OFF(sp)
  100. /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
  101. li a3, _NSIG8
  102. PTR_ADDU a2, a0, UCONTEXT_SIGMASK
  103. PTR_ADDU a1, a1, UCONTEXT_SIGMASK
  104. li a0, SIG_SETMASK
  105. li v0, SYS_ify (rt_sigprocmask)
  106. syscall
  107. bnez a3, 99f
  108. REG_L v0, A1OFF(sp)
  109. #ifdef __mips_hard_float
  110. # if _MIPS_SIM == _ABI64
  111. l.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(v0)
  112. l.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(v0)
  113. l.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(v0)
  114. l.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(v0)
  115. l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
  116. l.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(v0)
  117. l.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(v0)
  118. l.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(v0)
  119. # else /* _MIPS_SIM != _ABI64 */
  120. l.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(v0)
  121. l.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(v0)
  122. l.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(v0)
  123. l.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(v0)
  124. l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
  125. l.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(v0)
  126. # endif /* _MIPS_SIM != _ABI64 */
  127. lw v1, MCONTEXT_FPC_CSR(v0)
  128. ctc1 v1, fcr31
  129. #endif /* __mips_hard_float */
  130. /* Note the contents of argument registers will be random
  131. unless makecontext() has been called. */
  132. REG_L a0, (4 * SZREG + MCONTEXT_GREGS)(v0)
  133. REG_L a1, (5 * SZREG + MCONTEXT_GREGS)(v0)
  134. REG_L a2, (6 * SZREG + MCONTEXT_GREGS)(v0)
  135. REG_L a3, (7 * SZREG + MCONTEXT_GREGS)(v0)
  136. #if _MIPS_SIM != _ABIO32
  137. REG_L a4, (8 * SZREG + MCONTEXT_GREGS)(v0)
  138. REG_L a5, (9 * SZREG + MCONTEXT_GREGS)(v0)
  139. REG_L a6, (10 * SZREG + MCONTEXT_GREGS)(v0)
  140. REG_L a7, (11 * SZREG + MCONTEXT_GREGS)(v0)
  141. #endif
  142. REG_L s0, (16 * SZREG + MCONTEXT_GREGS)(v0)
  143. REG_L s1, (17 * SZREG + MCONTEXT_GREGS)(v0)
  144. REG_L s2, (18 * SZREG + MCONTEXT_GREGS)(v0)
  145. REG_L s3, (19 * SZREG + MCONTEXT_GREGS)(v0)
  146. REG_L s4, (20 * SZREG + MCONTEXT_GREGS)(v0)
  147. REG_L s5, (21 * SZREG + MCONTEXT_GREGS)(v0)
  148. REG_L s6, (22 * SZREG + MCONTEXT_GREGS)(v0)
  149. REG_L s7, (23 * SZREG + MCONTEXT_GREGS)(v0)
  150. #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
  151. REG_L gp, (28 * SZREG + MCONTEXT_GREGS)(v0)
  152. #endif
  153. REG_L sp, (29 * SZREG + MCONTEXT_GREGS)(v0)
  154. REG_L fp, (30 * SZREG + MCONTEXT_GREGS)(v0)
  155. REG_L ra, (31 * SZREG + MCONTEXT_GREGS)(v0)
  156. REG_L t9, MCONTEXT_PC(v0)
  157. move v0, zero
  158. jr t9
  159. 99:
  160. #ifdef __PIC__
  161. PTR_LA t9, JUMPTARGET (__syscall_error)
  162. RESTORE_GP64
  163. PTR_ADDIU sp, FRAMESZ
  164. jr t9
  165. #else /* ! __PIC__ */
  166. j JUMPTARGET (__syscall_error)
  167. #endif /* ! __PIC__ */
  168. PSEUDO_END (__swapcontext)
  169. weak_alias (__swapcontext, swapcontext)