getcontext.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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(__getcontext)
  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. movi a3, 0
  26. addi a4, a2, UCONTEXT_SIGMASK
  27. movi a2, SIG_BLOCK
  28. movi a5, JUMPTARGET (sigprocmask)
  29. jx a5
  30. END(__getcontext)
  31. #elif defined(__XTENSA_WINDOWED_ABI__)
  32. ENTRY(__getcontext)
  33. movi a4, __window_spill
  34. callx4 a4
  35. s32i a0, a2, MCONTEXT_SC_PC
  36. /* copy registers a0..a3 from spill area */
  37. addi a3, a1, -16
  38. l32i a4, a3, 0
  39. l32i a5, a3, 4
  40. l32i a6, a3, 8
  41. l32i a7, a3, 12
  42. s32i a4, a2, MCONTEXT_SC_A_0 + 0
  43. s32i a5, a2, MCONTEXT_SC_A_0 + 4
  44. s32i a6, a2, MCONTEXT_SC_A_0 + 8
  45. s32i a7, a2, MCONTEXT_SC_A_0 + 12
  46. /* if it was call4 then register saving is done */
  47. extui a4, a0, 30, 2
  48. bltui a4, 2, 1f
  49. /* otherwise load spill overflow area address into a3 */
  50. addi a3, a5, -16
  51. l32i a3, a3, 4
  52. addi a3, a3, -32
  53. beqi a4, 2, 2f
  54. /* copy registers a8..a11 from spill overflow area */
  55. addi a3, a3, -16
  56. l32i a4, a3, 16
  57. l32i a5, a3, 20
  58. l32i a6, a3, 24
  59. l32i a7, a3, 28
  60. s32i a4, a2, MCONTEXT_SC_A_0 + 32
  61. s32i a5, a2, MCONTEXT_SC_A_0 + 36
  62. s32i a6, a2, MCONTEXT_SC_A_0 + 40
  63. s32i a7, a2, MCONTEXT_SC_A_0 + 44
  64. /* copy registers a4..a7 from spill overflow area */
  65. 2:
  66. l32i a4, a3, 0
  67. l32i a5, a3, 4
  68. l32i a6, a3, 8
  69. l32i a7, a3, 12
  70. s32i a4, a2, MCONTEXT_SC_A_0 + 16
  71. s32i a5, a2, MCONTEXT_SC_A_0 + 20
  72. s32i a6, a2, MCONTEXT_SC_A_0 + 24
  73. s32i a7, a2, MCONTEXT_SC_A_0 + 28
  74. 1:
  75. movi a6, SIG_BLOCK
  76. movi a7, 0
  77. addi a8, a2, UCONTEXT_SIGMASK
  78. movi a4, JUMPTARGET (sigprocmask)
  79. callx4 a4
  80. mov a2, a6
  81. retw
  82. END(__getcontext)
  83. #else
  84. #error Unsupported Xtensa ABI
  85. #endif
  86. weak_alias (__getcontext, getcontext)