setcontext.S 3.1 KB

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