getcontext.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #ifdef PROF
  52. .set noat
  53. move AT, ra
  54. jal _mcount
  55. .set at
  56. #endif
  57. /* Store a magic flag. */
  58. li v1, 1
  59. REG_S v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
  60. REG_S s0, (16 * SZREG + MCONTEXT_GREGS)(a0)
  61. REG_S s1, (17 * SZREG + MCONTEXT_GREGS)(a0)
  62. REG_S s2, (18 * SZREG + MCONTEXT_GREGS)(a0)
  63. REG_S s3, (19 * SZREG + MCONTEXT_GREGS)(a0)
  64. REG_S s4, (20 * SZREG + MCONTEXT_GREGS)(a0)
  65. REG_S s5, (21 * SZREG + MCONTEXT_GREGS)(a0)
  66. REG_S s6, (22 * SZREG + MCONTEXT_GREGS)(a0)
  67. REG_S s7, (23 * SZREG + MCONTEXT_GREGS)(a0)
  68. #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
  69. REG_S _GP, (28 * SZREG + MCONTEXT_GREGS)(a0)
  70. #endif
  71. REG_S _SP, (29 * SZREG + MCONTEXT_GREGS)(a0)
  72. REG_S fp, (30 * SZREG + MCONTEXT_GREGS)(a0)
  73. REG_S ra, (31 * SZREG + MCONTEXT_GREGS)(a0)
  74. REG_S ra, MCONTEXT_PC(a0)
  75. #ifdef __mips_hard_float
  76. # if _MIPS_SIM == _ABI64
  77. s.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(a0)
  78. s.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(a0)
  79. s.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(a0)
  80. s.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(a0)
  81. s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
  82. s.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(a0)
  83. s.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(a0)
  84. s.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(a0)
  85. # else /* _MIPS_SIM != _ABI64 */
  86. s.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(a0)
  87. s.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(a0)
  88. s.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(a0)
  89. s.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(a0)
  90. s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
  91. s.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(a0)
  92. # endif /* _MIPS_SIM != _ABI64 */
  93. cfc1 v1, fcr31
  94. sw v1, MCONTEXT_FPC_CSR(a0)
  95. #endif /* __mips_hard_float */
  96. /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
  97. li a3, _NSIG8
  98. PTR_ADDU a2, a0, UCONTEXT_SIGMASK
  99. move a1, zero
  100. li a0, SIG_BLOCK
  101. li v0, SYS_ify (rt_sigprocmask)
  102. syscall
  103. bnez a3, 99f
  104. #ifdef __PIC__
  105. RESTORE_GP64
  106. PTR_ADDIU sp, FRAMESZ
  107. #endif
  108. move v0, zero
  109. jr ra
  110. 99:
  111. #ifdef __PIC__
  112. PTR_LA t9, JUMPTARGET (__syscall_error)
  113. RESTORE_GP64
  114. PTR_ADDIU sp, FRAMESZ
  115. jr t9
  116. #else /* ! __PIC__ */
  117. j JUMPTARGET (__syscall_error)
  118. #endif /* ! __PIC__ */
  119. PSEUDO_END (__getcontext)
  120. weak_alias (__getcontext, getcontext)