setcontext.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Set current context.
  2. Copyright (C) 2009-2018 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
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the 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 "ucontext-macros.h"
  16. /* int __setcontext (const ucontext_t *ucp)
  17. Restores the machine context in UCP and thereby resumes execution
  18. in that context.
  19. This implementation is intended to be used for *synchronous* context
  20. switches only. Therefore, it does not have to restore anything
  21. other than the PRESERVED state. */
  22. .text
  23. LEAF (__setcontext)
  24. mv t0, a0 /* Save ucp into t0. */
  25. /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
  26. li a3, _NSIG8
  27. mv a2, zero
  28. add a1, a0, UCONTEXT_SIGMASK
  29. li a0, SIG_SETMASK
  30. li a7, SYS_ify (rt_sigprocmask)
  31. scall
  32. bltz a0, 99f
  33. cfi_def_cfa (t0, 0)
  34. #ifndef __riscv_float_abi_soft
  35. lw t1, MCONTEXT_FSR(t0)
  36. RESTORE_FP_REG_CFI (fs0, 8, t0)
  37. RESTORE_FP_REG_CFI (fs1, 9, t0)
  38. RESTORE_FP_REG_CFI (fs2, 18, t0)
  39. RESTORE_FP_REG_CFI (fs3, 19, t0)
  40. RESTORE_FP_REG_CFI (fs4, 20, t0)
  41. RESTORE_FP_REG_CFI (fs5, 21, t0)
  42. RESTORE_FP_REG_CFI (fs6, 22, t0)
  43. RESTORE_FP_REG_CFI (fs7, 23, t0)
  44. RESTORE_FP_REG_CFI (fs8, 24, t0)
  45. RESTORE_FP_REG_CFI (fs9, 25, t0)
  46. RESTORE_FP_REG_CFI (fs10, 26, t0)
  47. RESTORE_FP_REG_CFI (fs11, 27, t0)
  48. fssr t1
  49. #endif /* __riscv_float_abi_soft */
  50. /* Note the contents of argument registers will be random
  51. unless makecontext() has been called. */
  52. RESTORE_INT_REG (t1, 0, t0)
  53. RESTORE_INT_REG_CFI (ra, 1, t0)
  54. RESTORE_INT_REG (sp, 2, t0)
  55. RESTORE_INT_REG_CFI (s0, 8, t0)
  56. RESTORE_INT_REG_CFI (s1, 9, t0)
  57. RESTORE_INT_REG (a0, 10, t0)
  58. RESTORE_INT_REG (a1, 11, t0)
  59. RESTORE_INT_REG (a2, 12, t0)
  60. RESTORE_INT_REG (a3, 13, t0)
  61. RESTORE_INT_REG (a4, 14, t0)
  62. RESTORE_INT_REG (a5, 15, t0)
  63. RESTORE_INT_REG (a6, 16, t0)
  64. RESTORE_INT_REG (a7, 17, t0)
  65. RESTORE_INT_REG_CFI (s2, 18, t0)
  66. RESTORE_INT_REG_CFI (s3, 19, t0)
  67. RESTORE_INT_REG_CFI (s4, 20, t0)
  68. RESTORE_INT_REG_CFI (s5, 21, t0)
  69. RESTORE_INT_REG_CFI (s6, 22, t0)
  70. RESTORE_INT_REG_CFI (s7, 23, t0)
  71. RESTORE_INT_REG_CFI (s8, 24, t0)
  72. RESTORE_INT_REG_CFI (s9, 25, t0)
  73. RESTORE_INT_REG_CFI (s10, 26, t0)
  74. RESTORE_INT_REG_CFI (s11, 27, t0)
  75. jr t1
  76. 99: j __syscall_error
  77. PSEUDO_END (__setcontext)
  78. weak_alias (__setcontext, setcontext)
  79. LEAF (__start_context)
  80. /* Terminate call stack by noting ra == 0. Happily, s0 == 0 here. */
  81. cfi_register (ra, s0)
  82. /* Call the function passed to makecontext. */
  83. jalr s1
  84. /* Invoke subsequent context if present, else exit(0). */
  85. mv a0, s2
  86. beqz s2, 1f
  87. jal __setcontext
  88. 1: j exit
  89. PSEUDO_END (__start_context)