swapcontext.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. FDPIC_LOAD_JUMPTARGET (a5, a11, a5)
  32. callx0 a5
  33. bnez a2, .Lerror
  34. mov a2, a12
  35. l32i a0, a2, MCONTEXT_SC_PC
  36. l32i a1, a2, MCONTEXT_SC_A_0 + 4
  37. /* load callee-saved registers from the context */
  38. l32i a12, a2, MCONTEXT_SC_A_0 + 48
  39. l32i a13, a2, MCONTEXT_SC_A_0 + 52
  40. l32i a14, a2, MCONTEXT_SC_A_0 + 56
  41. l32i a15, a2, MCONTEXT_SC_A_0 + 60
  42. movi a2, 0
  43. ret
  44. .Lerror:
  45. l32i a0, a13, MCONTEXT_SC_PC
  46. l32i a12, a13, MCONTEXT_SC_A_0 + 48
  47. l32i a13, a13, MCONTEXT_SC_A_0 + 52
  48. ret
  49. END(__swapcontext)
  50. #elif defined(__XTENSA_WINDOWED_ABI__)
  51. ENTRY(__swapcontext)
  52. movi a4, __window_spill
  53. callx4 a4
  54. mov a9, a3
  55. s32i a0, a2, MCONTEXT_SC_PC
  56. /* copy registers a0..a3 from spill area */
  57. addi a3, a1, -16
  58. l32i a4, a3, 0
  59. l32i a5, a3, 4
  60. l32i a6, a3, 8
  61. l32i a7, a3, 12
  62. s32i a4, a2, MCONTEXT_SC_A_0 + 0
  63. s32i a5, a2, MCONTEXT_SC_A_0 + 4
  64. s32i a6, a2, MCONTEXT_SC_A_0 + 8
  65. s32i a7, a2, MCONTEXT_SC_A_0 + 12
  66. /* if it was call4 then register saving is done */
  67. extui a4, a0, 30, 2
  68. bltui a4, 2, 1f
  69. /* otherwise load spill overflow area address into a3 */
  70. addi a3, a5, -16
  71. l32i a3, a3, 4
  72. addi a3, a3, -32
  73. beqi a4, 2, 2f
  74. /* copy registers a8..a11 from spill overflow area */
  75. addi a3, a3, -16
  76. l32i a4, a3, 16
  77. l32i a5, a3, 20
  78. l32i a6, a3, 24
  79. l32i a7, a3, 28
  80. s32i a4, a2, MCONTEXT_SC_A_0 + 32
  81. s32i a5, a2, MCONTEXT_SC_A_0 + 36
  82. s32i a6, a2, MCONTEXT_SC_A_0 + 40
  83. s32i a7, a2, MCONTEXT_SC_A_0 + 44
  84. /* copy registers a4..a7 from spill overflow area */
  85. 2:
  86. l32i a4, a3, 0
  87. l32i a5, a3, 4
  88. l32i a6, a3, 8
  89. l32i a7, a3, 12
  90. s32i a4, a2, MCONTEXT_SC_A_0 + 16
  91. s32i a5, a2, MCONTEXT_SC_A_0 + 20
  92. s32i a6, a2, MCONTEXT_SC_A_0 + 24
  93. s32i a7, a2, MCONTEXT_SC_A_0 + 28
  94. 1:
  95. movi a6, SIG_SETMASK
  96. addi a7, a9, UCONTEXT_SIGMASK
  97. addi a8, a2, UCONTEXT_SIGMASK
  98. mov a2, a9
  99. movi a4, JUMPTARGET (sigprocmask)
  100. callx4 a4
  101. bnez a6, .Lerror
  102. l32i a0, a2, MCONTEXT_SC_PC
  103. /* copy registers a0..a3 to spill area */
  104. addi a3, a1, -16
  105. l32i a4, a2, MCONTEXT_SC_A_0 + 0
  106. l32i a5, a2, MCONTEXT_SC_A_0 + 4
  107. l32i a6, a2, MCONTEXT_SC_A_0 + 8
  108. l32i a7, a2, MCONTEXT_SC_A_0 + 12
  109. s32i a4, a3, 0
  110. s32i a5, a3, 4
  111. s32i a6, a3, 8
  112. s32i a7, a3, 12
  113. /* if it was call4 then register setup is done */
  114. extui a4, a0, 30, 2
  115. bltui a4, 2, 1f
  116. /* otherwise load spill overflow area address into a3 */
  117. addi a3, a5, -16
  118. l32i a3, a3, 4
  119. addi a3, a3, -32
  120. beqi a4, 2, 2f
  121. /* copy registers a8..a11 to spill overflow area */
  122. addi a3, a3, -16
  123. l32i a4, a2, MCONTEXT_SC_A_0 + 32
  124. l32i a5, a2, MCONTEXT_SC_A_0 + 36
  125. l32i a6, a2, MCONTEXT_SC_A_0 + 40
  126. l32i a7, a2, MCONTEXT_SC_A_0 + 44
  127. s32i a4, a3, 16
  128. s32i a5, a3, 20
  129. s32i a6, a3, 24
  130. s32i a7, a3, 28
  131. /* copy registers a4..a7 to spill overflow area */
  132. 2:
  133. l32i a4, a2, MCONTEXT_SC_A_0 + 16
  134. l32i a5, a2, MCONTEXT_SC_A_0 + 20
  135. l32i a6, a2, MCONTEXT_SC_A_0 + 24
  136. l32i a7, a2, MCONTEXT_SC_A_0 + 28
  137. s32i a4, a3, 0
  138. s32i a5, a3, 4
  139. s32i a6, a3, 8
  140. s32i a7, a3, 12
  141. 1:
  142. movi a2, 0
  143. retw
  144. .Lerror:
  145. mov a2, a6
  146. retw
  147. END(__swapcontext)
  148. #else
  149. #error Unsupported Xtensa ABI
  150. #endif
  151. weak_alias (__swapcontext, swapcontext)