swapcontext.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Save and 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 swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
  16. LEAF (swapcontext)
  17. mv t0, a1 /* Save ucp into t0. */
  18. SAVE_INT_REG (ra, 0, a0)
  19. SAVE_INT_REG (ra, 1, a0)
  20. SAVE_INT_REG (sp, 2, a0)
  21. SAVE_INT_REG (s0, 8, a0)
  22. SAVE_INT_REG (s1, 9, a0)
  23. SAVE_INT_REG (x0, 10, a0) /* return 0 by overwriting a0. */
  24. SAVE_INT_REG (s2, 18, a0)
  25. SAVE_INT_REG (s3, 19, a0)
  26. SAVE_INT_REG (s4, 20, a0)
  27. SAVE_INT_REG (s5, 21, a0)
  28. SAVE_INT_REG (s6, 22, a0)
  29. SAVE_INT_REG (s7, 23, a0)
  30. SAVE_INT_REG (s8, 24, a0)
  31. SAVE_INT_REG (s9, 25, a0)
  32. SAVE_INT_REG (s10, 26, a0)
  33. SAVE_INT_REG (s11, 27, a0)
  34. #ifndef __riscv_float_abi_soft
  35. frsr a1
  36. SAVE_FP_REG (fs0, 8, a0)
  37. SAVE_FP_REG (fs1, 9, a0)
  38. SAVE_FP_REG (fs2, 18, a0)
  39. SAVE_FP_REG (fs3, 19, a0)
  40. SAVE_FP_REG (fs4, 20, a0)
  41. SAVE_FP_REG (fs5, 21, a0)
  42. SAVE_FP_REG (fs6, 22, a0)
  43. SAVE_FP_REG (fs7, 23, a0)
  44. SAVE_FP_REG (fs8, 24, a0)
  45. SAVE_FP_REG (fs9, 25, a0)
  46. SAVE_FP_REG (fs10, 26, a0)
  47. SAVE_FP_REG (fs11, 27, a0)
  48. sw a1, MCONTEXT_FSR(a0)
  49. #endif /* __riscv_float_abi_soft */
  50. /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
  51. li a3, _NSIG8
  52. add a2, a0, UCONTEXT_SIGMASK
  53. add a1, t0, UCONTEXT_SIGMASK
  54. li a0, SIG_SETMASK
  55. li a7, SYS_ify (rt_sigprocmask)
  56. scall
  57. bltz a0, 99f
  58. #ifndef __riscv_float_abi_soft
  59. lw t1, MCONTEXT_FSR(t0)
  60. RESTORE_FP_REG (fs0, 8, t0)
  61. RESTORE_FP_REG (fs1, 9, t0)
  62. RESTORE_FP_REG (fs2, 18, t0)
  63. RESTORE_FP_REG (fs3, 19, t0)
  64. RESTORE_FP_REG (fs4, 20, t0)
  65. RESTORE_FP_REG (fs5, 21, t0)
  66. RESTORE_FP_REG (fs6, 22, t0)
  67. RESTORE_FP_REG (fs7, 23, t0)
  68. RESTORE_FP_REG (fs8, 24, t0)
  69. RESTORE_FP_REG (fs9, 25, t0)
  70. RESTORE_FP_REG (fs10, 26, t0)
  71. RESTORE_FP_REG (fs11, 27, t0)
  72. fssr t1
  73. #endif /* __riscv_float_abi_soft */
  74. /* Note the contents of argument registers will be random
  75. unless makecontext() has been called. */
  76. RESTORE_INT_REG (t1, 0, t0)
  77. RESTORE_INT_REG (ra, 1, t0)
  78. RESTORE_INT_REG (sp, 2, t0)
  79. RESTORE_INT_REG (s0, 8, t0)
  80. RESTORE_INT_REG (s1, 9, t0)
  81. RESTORE_INT_REG (a0, 10, t0)
  82. RESTORE_INT_REG (a1, 11, t0)
  83. RESTORE_INT_REG (a2, 12, t0)
  84. RESTORE_INT_REG (a3, 13, t0)
  85. RESTORE_INT_REG (a4, 14, t0)
  86. RESTORE_INT_REG (a5, 15, t0)
  87. RESTORE_INT_REG (a6, 16, t0)
  88. RESTORE_INT_REG (a7, 17, t0)
  89. RESTORE_INT_REG (s2, 18, t0)
  90. RESTORE_INT_REG (s3, 19, t0)
  91. RESTORE_INT_REG (s4, 20, t0)
  92. RESTORE_INT_REG (s5, 21, t0)
  93. RESTORE_INT_REG (s6, 22, t0)
  94. RESTORE_INT_REG (s7, 23, t0)
  95. RESTORE_INT_REG (s8, 24, t0)
  96. RESTORE_INT_REG (s9, 25, t0)
  97. RESTORE_INT_REG (s10, 26, t0)
  98. RESTORE_INT_REG (s11, 27, t0)
  99. jr t1
  100. 99: j __syscall_error
  101. PSEUDO_END (swapcontext)