setcontext.S 2.8 KB

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