swapcontext.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Modify saved context.
  2. Copyright (C) 2009-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #include "ucontext_i.h"
  17. #include "ucontext-internal.h"
  18. /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
  19. .text
  20. ENTRY(__swapcontext)
  21. DELOUSE (0)
  22. /* Set the value returned when swapcontext() returns in this context. */
  23. str xzr, [x0, oX0 + 0 * SZREG]
  24. stp x18, x19, [x0, oX0 + 18 * SZREG]
  25. stp x20, x21, [x0, oX0 + 20 * SZREG]
  26. stp x22, x23, [x0, oX0 + 22 * SZREG]
  27. stp x24, x25, [x0, oX0 + 24 * SZREG]
  28. stp x26, x27, [x0, oX0 + 26 * SZREG]
  29. stp x28, x29, [x0, oX0 + 28 * SZREG]
  30. str x30, [x0, oX0 + 30 * SZREG]
  31. str x30, [x0, oPC]
  32. mov x2, sp
  33. str x2, [x0, oSP]
  34. /* Figure out where to place the first context extension
  35. block. */
  36. add x2, x0, #oEXTENSION
  37. /* Write the context extension fpsimd header. */
  38. mov w3, #(FPSIMD_MAGIC & 0xffff)
  39. movk w3, #(FPSIMD_MAGIC >> 16), lsl #16
  40. str w3, [x2, #oHEAD + oMAGIC]
  41. mov w3, #FPSIMD_CONTEXT_SIZE
  42. str w3, [x2, #oHEAD + oSIZE]
  43. /* Fill in the FP SIMD context. */
  44. add x3, x2, #oV0 + 8 * SZVREG
  45. stp q8, q9, [x3], #2 * SZVREG
  46. stp q10, q11, [x3], #2 * SZVREG
  47. stp q12, q13, [x3], #2 * SZVREG
  48. stp q14, q15, [x3], #2 * SZVREG
  49. add x3, x2, #oFPSR
  50. mrs x4, fpsr
  51. str w4, [x3, #oFPSR - oFPSR]
  52. mrs x4, fpcr
  53. str w4, [x3, #oFPCR - oFPSR]
  54. /* Write the termination context extension header. */
  55. add x2, x2, #FPSIMD_CONTEXT_SIZE
  56. str xzr, [x2, #oHEAD + oMAGIC]
  57. str xzr, [x2, #oHEAD + oSIZE]
  58. /* Preserve ucp. */
  59. mov x21, x1
  60. /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask,
  61. _NSIG8) */
  62. /* Grab the signal mask */
  63. /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
  64. add x2, x0, #UCONTEXT_SIGMASK
  65. mov x0, SIG_BLOCK
  66. mov x1, 0
  67. mov x3, _NSIG8
  68. mov x8, SYS_ify (rt_sigprocmask)
  69. svc 0
  70. cbnz x0, 1f
  71. mov x22, x30
  72. mov x0, x21
  73. bl JUMPTARGET (__setcontext)
  74. mov x30, x22
  75. RET
  76. 1:
  77. b C_SYMBOL_NAME(__syscall_error)
  78. PSEUDO_END (__swapcontext)
  79. weak_alias (__swapcontext, swapcontext)