swapcontext.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Copyright (C) 2018 - 2022 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #include "ucontext_i.h"
  16. #if defined(__XTENSA_CALL0_ABI__)
  17. ENTRY(__swapcontext)
  18. s32i a0, a2, MCONTEXT_SC_PC
  19. s32i a1, a2, MCONTEXT_SC_A_0 + 4
  20. /* save callee-saved registers in the context */
  21. s32i a12, a2, MCONTEXT_SC_A_0 + 48
  22. s32i a13, a2, MCONTEXT_SC_A_0 + 52
  23. s32i a14, a2, MCONTEXT_SC_A_0 + 56
  24. s32i a15, a2, MCONTEXT_SC_A_0 + 60
  25. mov a12, a3
  26. mov a13, a2
  27. addi a3, a3, UCONTEXT_SIGMASK
  28. addi a4, a2, UCONTEXT_SIGMASK
  29. movi a2, SIG_SETMASK
  30. movi a5, JUMPTARGET (sigprocmask)
  31. callx0 a5
  32. bnez a2, .Lerror
  33. mov a2, a12
  34. l32i a0, a2, MCONTEXT_SC_PC
  35. l32i a1, a2, MCONTEXT_SC_A_0 + 4
  36. /* load callee-saved registers from the context */
  37. l32i a12, a2, MCONTEXT_SC_A_0 + 48
  38. l32i a13, a2, MCONTEXT_SC_A_0 + 52
  39. l32i a14, a2, MCONTEXT_SC_A_0 + 56
  40. l32i a15, a2, MCONTEXT_SC_A_0 + 60
  41. movi a2, 0
  42. ret
  43. .Lerror:
  44. l32i a0, a13, MCONTEXT_SC_PC
  45. l32i a12, a13, MCONTEXT_SC_A_0 + 48
  46. l32i a13, a13, MCONTEXT_SC_A_0 + 52
  47. ret
  48. END(__swapcontext)
  49. #elif defined(__XTENSA_WINDOWED_ABI__)
  50. ENTRY(__swapcontext)
  51. movi a4, __window_spill
  52. callx4 a4
  53. mov a9, a3
  54. s32i a0, a2, MCONTEXT_SC_PC
  55. /* copy registers a0..a3 from spill area */
  56. addi a3, a1, -16
  57. l32i a4, a3, 0
  58. l32i a5, a3, 4
  59. l32i a6, a3, 8
  60. l32i a7, a3, 12
  61. s32i a4, a2, MCONTEXT_SC_A_0 + 0
  62. s32i a5, a2, MCONTEXT_SC_A_0 + 4
  63. s32i a6, a2, MCONTEXT_SC_A_0 + 8
  64. s32i a7, a2, MCONTEXT_SC_A_0 + 12
  65. /* if it was call4 then register saving is done */
  66. extui a4, a0, 30, 2
  67. bltui a4, 2, 1f
  68. /* otherwise load spill overflow area address into a3 */
  69. addi a3, a5, -16
  70. l32i a3, a3, 4
  71. addi a3, a3, -32
  72. beqi a4, 2, 2f
  73. /* copy registers a8..a11 from spill overflow area */
  74. addi a3, a3, -16
  75. l32i a4, a3, 16
  76. l32i a5, a3, 20
  77. l32i a6, a3, 24
  78. l32i a7, a3, 28
  79. s32i a4, a2, MCONTEXT_SC_A_0 + 32
  80. s32i a5, a2, MCONTEXT_SC_A_0 + 36
  81. s32i a6, a2, MCONTEXT_SC_A_0 + 40
  82. s32i a7, a2, MCONTEXT_SC_A_0 + 44
  83. /* copy registers a4..a7 from spill overflow area */
  84. 2:
  85. l32i a4, a3, 0
  86. l32i a5, a3, 4
  87. l32i a6, a3, 8
  88. l32i a7, a3, 12
  89. s32i a4, a2, MCONTEXT_SC_A_0 + 16
  90. s32i a5, a2, MCONTEXT_SC_A_0 + 20
  91. s32i a6, a2, MCONTEXT_SC_A_0 + 24
  92. s32i a7, a2, MCONTEXT_SC_A_0 + 28
  93. 1:
  94. movi a6, SIG_SETMASK
  95. addi a7, a9, UCONTEXT_SIGMASK
  96. addi a8, a2, UCONTEXT_SIGMASK
  97. mov a2, a9
  98. movi a4, JUMPTARGET (sigprocmask)
  99. callx4 a4
  100. bnez a6, .Lerror
  101. l32i a0, a2, MCONTEXT_SC_PC
  102. /* copy registers a0..a3 to spill area */
  103. addi a3, a1, -16
  104. l32i a4, a2, MCONTEXT_SC_A_0 + 0
  105. l32i a5, a2, MCONTEXT_SC_A_0 + 4
  106. l32i a6, a2, MCONTEXT_SC_A_0 + 8
  107. l32i a7, a2, MCONTEXT_SC_A_0 + 12
  108. s32i a4, a3, 0
  109. s32i a5, a3, 4
  110. s32i a6, a3, 8
  111. s32i a7, a3, 12
  112. /* if it was call4 then register setup is done */
  113. extui a4, a0, 30, 2
  114. bltui a4, 2, 1f
  115. /* otherwise load spill overflow area address into a3 */
  116. addi a3, a5, -16
  117. l32i a3, a3, 4
  118. addi a3, a3, -32
  119. beqi a4, 2, 2f
  120. /* copy registers a8..a11 to spill overflow area */
  121. addi a3, a3, -16
  122. l32i a4, a2, MCONTEXT_SC_A_0 + 32
  123. l32i a5, a2, MCONTEXT_SC_A_0 + 36
  124. l32i a6, a2, MCONTEXT_SC_A_0 + 40
  125. l32i a7, a2, MCONTEXT_SC_A_0 + 44
  126. s32i a4, a3, 16
  127. s32i a5, a3, 20
  128. s32i a6, a3, 24
  129. s32i a7, a3, 28
  130. /* copy registers a4..a7 to spill overflow area */
  131. 2:
  132. l32i a4, a2, MCONTEXT_SC_A_0 + 16
  133. l32i a5, a2, MCONTEXT_SC_A_0 + 20
  134. l32i a6, a2, MCONTEXT_SC_A_0 + 24
  135. l32i a7, a2, MCONTEXT_SC_A_0 + 28
  136. s32i a4, a3, 0
  137. s32i a5, a3, 4
  138. s32i a6, a3, 8
  139. s32i a7, a3, 12
  140. 1:
  141. movi a2, 0
  142. retw
  143. .Lerror:
  144. mov a2, a6
  145. retw
  146. END(__swapcontext)
  147. #else
  148. #error Unsupported Xtensa ABI
  149. #endif
  150. weak_alias (__swapcontext, swapcontext)