setcontext.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* 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 setcontext (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 a0 */
  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. A0OFF = FRAMESZ - (1 * SZREG) /* callee-allocated */
  39. #else
  40. A0OFF = FRAMESZ + (0 * SZREG) /* caller-allocated */
  41. #endif
  42. NESTED (__setcontext, FRAMESZ, ra)
  43. .mask MASK, -(ARGSZ * SZREG)
  44. .fmask 0x00000000, 0
  45. #ifdef __PIC__
  46. SETUP_GP
  47. #endif
  48. PTR_ADDIU sp, -FRAMESZ
  49. #ifdef __PIC__
  50. SETUP_GP64 (GPOFF, __setcontext)
  51. SAVE_GP (GPOFF)
  52. #endif
  53. /* Check for the magic flag. */
  54. li v0, 1
  55. REG_L v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
  56. bne v0, v1, 98f
  57. REG_S a0, A0OFF(sp)
  58. /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
  59. li a3, _NSIG8
  60. move a2, zero
  61. PTR_ADDU a1, a0, UCONTEXT_SIGMASK
  62. li a0, SIG_SETMASK
  63. li v0, SYS_ify (rt_sigprocmask)
  64. syscall
  65. bnez a3, 99f
  66. REG_L v0, A0OFF(sp)
  67. #ifdef __mips_hard_float
  68. # if _MIPS_SIM == _ABI64
  69. l.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(v0)
  70. l.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(v0)
  71. l.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(v0)
  72. l.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(v0)
  73. l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
  74. l.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(v0)
  75. l.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(v0)
  76. l.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(v0)
  77. # else /* _MIPS_SIM != _ABI64 */
  78. l.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(v0)
  79. l.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(v0)
  80. l.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(v0)
  81. l.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(v0)
  82. l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
  83. l.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(v0)
  84. # endif /* _MIPS_SIM != _ABI64 */
  85. lw v1, MCONTEXT_FPC_CSR(v0)
  86. ctc1 v1, fcr31
  87. #endif /* __mips_hard_float */
  88. /* Note the contents of argument registers will be random
  89. unless makecontext() has been called. */
  90. REG_L a0, (4 * SZREG + MCONTEXT_GREGS)(v0)
  91. REG_L a1, (5 * SZREG + MCONTEXT_GREGS)(v0)
  92. REG_L a2, (6 * SZREG + MCONTEXT_GREGS)(v0)
  93. REG_L a3, (7 * SZREG + MCONTEXT_GREGS)(v0)
  94. #if _MIPS_SIM != _ABIO32
  95. REG_L a4, (8 * SZREG + MCONTEXT_GREGS)(v0)
  96. REG_L a5, (9 * SZREG + MCONTEXT_GREGS)(v0)
  97. REG_L a6, (10 * SZREG + MCONTEXT_GREGS)(v0)
  98. REG_L a7, (11 * SZREG + MCONTEXT_GREGS)(v0)
  99. #endif
  100. REG_L s0, (16 * SZREG + MCONTEXT_GREGS)(v0)
  101. REG_L s1, (17 * SZREG + MCONTEXT_GREGS)(v0)
  102. REG_L s2, (18 * SZREG + MCONTEXT_GREGS)(v0)
  103. REG_L s3, (19 * SZREG + MCONTEXT_GREGS)(v0)
  104. REG_L s4, (20 * SZREG + MCONTEXT_GREGS)(v0)
  105. REG_L s5, (21 * SZREG + MCONTEXT_GREGS)(v0)
  106. REG_L s6, (22 * SZREG + MCONTEXT_GREGS)(v0)
  107. REG_L s7, (23 * SZREG + MCONTEXT_GREGS)(v0)
  108. #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
  109. REG_L gp, (28 * SZREG + MCONTEXT_GREGS)(v0)
  110. #endif
  111. REG_L sp, (29 * SZREG + MCONTEXT_GREGS)(v0)
  112. REG_L fp, (30 * SZREG + MCONTEXT_GREGS)(v0)
  113. REG_L ra, (31 * SZREG + MCONTEXT_GREGS)(v0)
  114. REG_L t9, MCONTEXT_PC(v0)
  115. move v0, zero
  116. jr t9
  117. 98:
  118. /* This is a context obtained from a signal handler.
  119. Perform a full restore by pushing the context
  120. passed onto a simulated signal frame on the stack
  121. and call the signal return syscall as if a signal
  122. handler exited normally. */
  123. PTR_ADDIU sp, -((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
  124. /* Only ucontext is referred to from rt_sigreturn,
  125. copy it. */
  126. PTR_ADDIU t1, sp, RT_SIGFRAME_UCONTEXT
  127. li t3, ((UCONTEXT_SIZE + SZREG - 1) / SZREG) - 1
  128. 0:
  129. REG_L t2, (a0)
  130. PTR_ADDIU a0, SZREG
  131. REG_S t2, (t1)
  132. PTR_ADDIU t1, SZREG
  133. .set noreorder
  134. bgtz t3, 0b
  135. addiu t3, -1
  136. .set reorder
  137. /* rt_sigreturn () -- no arguments, sp points to struct rt_sigframe. */
  138. li v0, SYS_ify (rt_sigreturn)
  139. syscall
  140. /* Restore the stack and fall through to the error
  141. path. Successful rt_sigreturn never returns to
  142. its calling place. */
  143. PTR_ADDIU sp, ((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
  144. 99:
  145. #ifdef __PIC__
  146. PTR_LA t9, JUMPTARGET (__syscall_error)
  147. RESTORE_GP64
  148. PTR_ADDIU sp, FRAMESZ
  149. jr t9
  150. #else /* ! __PIC__ */
  151. j JUMPTARGET (__syscall_error)
  152. #endif /* ! __PIC__ */
  153. PSEUDO_END (__setcontext)
  154. weak_alias (__setcontext, setcontext)