1 /* Set current context.
2 Copyright (C) 2009-2018 Free Software Foundation, Inc.
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.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <http://www.gnu.org/licenses/>. */
18 #include "ucontext-macros.h"
20 /* int __setcontext (const ucontext_t *ucp)
22 Restores the machine context in UCP and thereby resumes execution
25 This implementation is intended to be used for *synchronous* context
26 switches only. Therefore, it does not have to restore anything
27 other than the PRESERVED state. */
32 mv t0, a0 /* Save ucp into t0. */
34 /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
37 add a1, a0, UCONTEXT_SIGMASK
40 li a7, SYS_ify (rt_sigprocmask)
47 #ifndef __riscv_float_abi_soft
48 lw t1, MCONTEXT_FSR(t0)
50 RESTORE_FP_REG_CFI (fs0, 8, t0)
51 RESTORE_FP_REG_CFI (fs1, 9, t0)
52 RESTORE_FP_REG_CFI (fs2, 18, t0)
53 RESTORE_FP_REG_CFI (fs3, 19, t0)
54 RESTORE_FP_REG_CFI (fs4, 20, t0)
55 RESTORE_FP_REG_CFI (fs5, 21, t0)
56 RESTORE_FP_REG_CFI (fs6, 22, t0)
57 RESTORE_FP_REG_CFI (fs7, 23, t0)
58 RESTORE_FP_REG_CFI (fs8, 24, t0)
59 RESTORE_FP_REG_CFI (fs9, 25, t0)
60 RESTORE_FP_REG_CFI (fs10, 26, t0)
61 RESTORE_FP_REG_CFI (fs11, 27, t0)
64 #endif /* __riscv_float_abi_soft */
66 /* Note the contents of argument registers will be random
67 unless makecontext() has been called. */
68 RESTORE_INT_REG (t1, 0, t0)
69 RESTORE_INT_REG_CFI (ra, 1, t0)
70 RESTORE_INT_REG (sp, 2, t0)
71 RESTORE_INT_REG_CFI (s0, 8, t0)
72 RESTORE_INT_REG_CFI (s1, 9, t0)
73 RESTORE_INT_REG (a0, 10, t0)
74 RESTORE_INT_REG (a1, 11, t0)
75 RESTORE_INT_REG (a2, 12, t0)
76 RESTORE_INT_REG (a3, 13, t0)
77 RESTORE_INT_REG (a4, 14, t0)
78 RESTORE_INT_REG (a5, 15, t0)
79 RESTORE_INT_REG (a6, 16, t0)
80 RESTORE_INT_REG (a7, 17, t0)
81 RESTORE_INT_REG_CFI (s2, 18, t0)
82 RESTORE_INT_REG_CFI (s3, 19, t0)
83 RESTORE_INT_REG_CFI (s4, 20, t0)
84 RESTORE_INT_REG_CFI (s5, 21, t0)
85 RESTORE_INT_REG_CFI (s6, 22, t0)
86 RESTORE_INT_REG_CFI (s7, 23, t0)
87 RESTORE_INT_REG_CFI (s8, 24, t0)
88 RESTORE_INT_REG_CFI (s9, 25, t0)
89 RESTORE_INT_REG_CFI (s10, 26, t0)
90 RESTORE_INT_REG_CFI (s11, 27, t0)
96 PSEUDO_END (setcontext)
100 /* Terminate call stack by noting ra == 0. Happily, s0 == 0 here. */
101 cfi_register (ra, s0)
103 /* Call the function passed to makecontext. */
106 /* Invoke subsequent context if present, else exit(0). */
112 PSEUDO_END (start_context)