getcontext.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Save 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 getcontext (ucontext_t *ucp) */
  22. .text
  23. LOCALSZ = 0
  24. MASK = 0x00000000
  25. #ifdef __PIC__
  26. LOCALSZ = 1 /* save gp */
  27. # if _MIPS_SIM != _ABIO32
  28. MASK = 0x10000000
  29. # endif
  30. #endif
  31. FRAMESZ = ((LOCALSZ * SZREG) + ALSZ) & ALMASK
  32. GPOFF = FRAMESZ - (1 * SZREG)
  33. NESTED (__getcontext, FRAMESZ, ra)
  34. .mask MASK, 0
  35. .fmask 0x00000000, 0
  36. #ifdef __PIC__
  37. SETUP_GP
  38. move a2, sp
  39. # define _SP a2
  40. # if _MIPS_SIM != _ABIO32
  41. move a3, gp
  42. # define _GP a3
  43. # endif
  44. PTR_ADDIU sp, -FRAMESZ
  45. SETUP_GP64 (GPOFF, __getcontext)
  46. SAVE_GP (GPOFF)
  47. #else /* ! __PIC__ */
  48. # define _SP sp
  49. # define _GP gp
  50. #endif /* ! __PIC__ */
  51. /* Store a magic flag. */
  52. li v1, 1
  53. REG_S v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
  54. REG_S s0, (16 * SZREG + MCONTEXT_GREGS)(a0)
  55. REG_S s1, (17 * SZREG + MCONTEXT_GREGS)(a0)
  56. REG_S s2, (18 * SZREG + MCONTEXT_GREGS)(a0)
  57. REG_S s3, (19 * SZREG + MCONTEXT_GREGS)(a0)
  58. REG_S s4, (20 * SZREG + MCONTEXT_GREGS)(a0)
  59. REG_S s5, (21 * SZREG + MCONTEXT_GREGS)(a0)
  60. REG_S s6, (22 * SZREG + MCONTEXT_GREGS)(a0)
  61. REG_S s7, (23 * SZREG + MCONTEXT_GREGS)(a0)
  62. #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
  63. REG_S _GP, (28 * SZREG + MCONTEXT_GREGS)(a0)
  64. #endif
  65. REG_S _SP, (29 * SZREG + MCONTEXT_GREGS)(a0)
  66. REG_S fp, (30 * SZREG + MCONTEXT_GREGS)(a0)
  67. REG_S ra, (31 * SZREG + MCONTEXT_GREGS)(a0)
  68. REG_S ra, MCONTEXT_PC(a0)
  69. #ifdef __mips_hard_float
  70. # if _MIPS_SIM == _ABI64
  71. s.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(a0)
  72. s.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(a0)
  73. s.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(a0)
  74. s.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(a0)
  75. s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
  76. s.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(a0)
  77. s.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(a0)
  78. s.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(a0)
  79. # else /* _MIPS_SIM != _ABI64 */
  80. s.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(a0)
  81. s.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(a0)
  82. s.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(a0)
  83. s.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(a0)
  84. s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
  85. s.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(a0)
  86. # endif /* _MIPS_SIM != _ABI64 */
  87. cfc1 v1, fcr31
  88. sw v1, MCONTEXT_FPC_CSR(a0)
  89. #endif /* __mips_hard_float */
  90. /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
  91. li a3, _NSIG8
  92. PTR_ADDU a2, a0, UCONTEXT_SIGMASK
  93. move a1, zero
  94. li a0, SIG_BLOCK
  95. li v0, SYS_ify (rt_sigprocmask)
  96. syscall
  97. bnez a3, 99f
  98. #ifdef __PIC__
  99. RESTORE_GP64
  100. PTR_ADDIU sp, FRAMESZ
  101. #endif
  102. move v0, zero
  103. jr ra
  104. 99:
  105. #ifdef __PIC__
  106. PTR_LA t9, JUMPTARGET (__syscall_error)
  107. RESTORE_GP64
  108. PTR_ADDIU sp, FRAMESZ
  109. jr t9
  110. #else /* ! __PIC__ */
  111. j JUMPTARGET (__syscall_error)
  112. #endif /* ! __PIC__ */
  113. PSEUDO_END (__getcontext)
  114. weak_alias (__getcontext, getcontext)