getcontext.S 2.6 KB

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