setcontext.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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(__setcontext)
  18. addi sp, sp, -16
  19. s32i a0, sp, 0
  20. s32i a2, sp, 4
  21. addi a3, a2, UCONTEXT_SIGMASK
  22. movi a4, 0
  23. movi a2, SIG_SETMASK
  24. movi a5, JUMPTARGET (sigprocmask)
  25. FDPIC_LOAD_JUMPTARGET (a5, a11, a5)
  26. callx0 a5
  27. bnez a2, .Lerror
  28. l32i a2, sp, 4
  29. l32i a0, a2, MCONTEXT_SC_PC
  30. l32i a1, a2, MCONTEXT_SC_A_0 + 4
  31. /* load callee-saved registers from the context */
  32. l32i a12, a2, MCONTEXT_SC_A_0 + 48
  33. l32i a13, a2, MCONTEXT_SC_A_0 + 52
  34. l32i a14, a2, MCONTEXT_SC_A_0 + 56
  35. l32i a15, a2, MCONTEXT_SC_A_0 + 60
  36. movi a2, 0
  37. ret
  38. .Lerror:
  39. l32i a0, sp, 0
  40. addi sp, sp, 16
  41. ret
  42. END(__setcontext)
  43. #elif defined(__XTENSA_WINDOWED_ABI__)
  44. ENTRY(__setcontext)
  45. movi a6, SIG_SETMASK
  46. addi a7, a2, UCONTEXT_SIGMASK
  47. movi a8, 0
  48. movi a4, JUMPTARGET (sigprocmask)
  49. callx4 a4
  50. bnez a6, .Lerror
  51. movi a4, __window_spill
  52. callx4 a4
  53. l32i a0, a2, MCONTEXT_SC_PC
  54. /* copy registers a0..a3 to spill area */
  55. addi a3, a1, -16
  56. l32i a4, a2, MCONTEXT_SC_A_0 + 0
  57. l32i a5, a2, MCONTEXT_SC_A_0 + 4
  58. l32i a6, a2, MCONTEXT_SC_A_0 + 8
  59. l32i a7, a2, MCONTEXT_SC_A_0 + 12
  60. s32i a4, a3, 0
  61. s32i a5, a3, 4
  62. s32i a6, a3, 8
  63. s32i a7, a3, 12
  64. /* if it was call4 then register setup is done */
  65. extui a4, a0, 30, 2
  66. bltui a4, 2, 1f
  67. /* otherwise load spill overflow area address into a3 */
  68. addi a3, a5, -16
  69. l32i a3, a3, 4
  70. addi a3, a3, -32
  71. beqi a4, 2, 2f
  72. /* copy registers a8..a11 to spill overflow area */
  73. addi a3, a3, -16
  74. l32i a4, a2, MCONTEXT_SC_A_0 + 32
  75. l32i a5, a2, MCONTEXT_SC_A_0 + 36
  76. l32i a6, a2, MCONTEXT_SC_A_0 + 40
  77. l32i a7, a2, MCONTEXT_SC_A_0 + 44
  78. s32i a4, a3, 16
  79. s32i a5, a3, 20
  80. s32i a6, a3, 24
  81. s32i a7, a3, 28
  82. /* copy registers a4..a7 to spill overflow area */
  83. 2:
  84. l32i a4, a2, MCONTEXT_SC_A_0 + 16
  85. l32i a5, a2, MCONTEXT_SC_A_0 + 20
  86. l32i a6, a2, MCONTEXT_SC_A_0 + 24
  87. l32i a7, a2, MCONTEXT_SC_A_0 + 28
  88. s32i a4, a3, 0
  89. s32i a5, a3, 4
  90. s32i a6, a3, 8
  91. s32i a7, a3, 12
  92. 1:
  93. movi a2, 0
  94. retw
  95. .Lerror:
  96. mov a2, a6
  97. retw
  98. END(__setcontext)
  99. #else
  100. #error Unsupported Xtensa ABI
  101. #endif
  102. weak_alias (__setcontext, setcontext)