setcontext.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Set current 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 __setcontext (const ucontext_t *ucp)
  19. Restores the machine context in UCP and thereby resumes execution
  20. in that context.
  21. This implementation is intended to be used for *synchronous* context
  22. switches only. Therefore, it does not have to restore anything
  23. other than the PRESERVED state. */
  24. .text
  25. ENTRY (__setcontext)
  26. DELOUSE (0)
  27. /* Save a copy of UCP. */
  28. mov x9, x0
  29. /* Set the signal mask with
  30. rt_sigprocmask (SIG_SETMASK, mask, NULL, _NSIG/8). */
  31. mov x0, #SIG_SETMASK
  32. add x1, x9, #UCONTEXT_SIGMASK
  33. mov x2, #0
  34. mov x3, #_NSIG8
  35. mov x8, SYS_ify (rt_sigprocmask)
  36. svc 0
  37. cbz x0, 1f
  38. b C_SYMBOL_NAME (__syscall_error)
  39. 1:
  40. /* Restore the general purpose registers. */
  41. mov x0, x9
  42. cfi_def_cfa (x0, 0)
  43. cfi_offset (x18, oX0 + 18 * SZREG)
  44. cfi_offset (x19, oX0 + 19 * SZREG)
  45. cfi_offset (x20, oX0 + 20 * SZREG)
  46. cfi_offset (x21, oX0 + 21 * SZREG)
  47. cfi_offset (x22, oX0 + 22 * SZREG)
  48. cfi_offset (x23, oX0 + 23 * SZREG)
  49. cfi_offset (x24, oX0 + 24 * SZREG)
  50. cfi_offset (x25, oX0 + 25 * SZREG)
  51. cfi_offset (x26, oX0 + 26 * SZREG)
  52. cfi_offset (x27, oX0 + 27 * SZREG)
  53. cfi_offset (x28, oX0 + 28 * SZREG)
  54. cfi_offset (x29, oX0 + 29 * SZREG)
  55. cfi_offset (x30, oX0 + 30 * SZREG)
  56. cfi_offset ( d8, oV0 + 8 * SZVREG)
  57. cfi_offset ( d9, oV0 + 9 * SZVREG)
  58. cfi_offset (d10, oV0 + 10 * SZVREG)
  59. cfi_offset (d11, oV0 + 11 * SZVREG)
  60. cfi_offset (d12, oV0 + 12 * SZVREG)
  61. cfi_offset (d13, oV0 + 13 * SZVREG)
  62. cfi_offset (d14, oV0 + 14 * SZVREG)
  63. cfi_offset (d15, oV0 + 15 * SZVREG)
  64. ldp x18, x19, [x0, oX0 + 18 * SZREG]
  65. ldp x20, x21, [x0, oX0 + 20 * SZREG]
  66. ldp x22, x23, [x0, oX0 + 22 * SZREG]
  67. ldp x24, x25, [x0, oX0 + 24 * SZREG]
  68. ldp x26, x27, [x0, oX0 + 26 * SZREG]
  69. ldp x28, x29, [x0, oX0 + 28 * SZREG]
  70. ldr x30, [x0, oX0 + 30 * SZREG]
  71. ldr x2, [x0, oSP]
  72. mov sp, x2
  73. /* Check for FP SIMD context. We don't support restoring
  74. contexts created by the kernel, so this context must have
  75. been created by getcontext. Hence we can rely on the
  76. first extension block being the FP SIMD context. */
  77. add x2, x0, #oEXTENSION
  78. mov w3, #(FPSIMD_MAGIC & 0xffff)
  79. movk w3, #(FPSIMD_MAGIC >> 16), lsl #16
  80. ldr w1, [x2, #oHEAD + oMAGIC]
  81. cmp w1, w3
  82. b.ne 2f
  83. /* Restore the FP SIMD context. */
  84. add x3, x2, #oV0 + 8 * SZVREG
  85. ldp q8, q9, [x3], #2 * SZVREG
  86. ldp q10, q11, [x3], #2 * SZVREG
  87. ldp q12, q13, [x3], #2 * SZVREG
  88. ldp q14, q15, [x3], #2 * SZVREG
  89. add x3, x2, oFPSR
  90. ldr w4, [x3]
  91. msr fpsr, x4
  92. ldr w4, [x3, oFPCR - oFPSR]
  93. msr fpcr, x4
  94. 2:
  95. ldr x16, [x0, oPC]
  96. /* Restore arg registers. */
  97. ldp x2, x3, [x0, oX0 + 2 * SZREG]
  98. ldp x4, x5, [x0, oX0 + 4 * SZREG]
  99. ldp x6, x7, [x0, oX0 + 6 * SZREG]
  100. ldp x0, x1, [x0, oX0 + 0 * SZREG]
  101. /* Jump to the new pc value. */
  102. br x16
  103. PSEUDO_END (__setcontext)
  104. weak_alias (__setcontext, setcontext)
  105. ENTRY (__startcontext)
  106. mov x0, x19
  107. cbnz x0, __setcontext
  108. 1: b HIDDEN_JUMPTARGET (exit)
  109. END (__startcontext)