setcontext.S 5.1 KB

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