1 /* Modify saved context.
2 Copyright (C) 2015-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
20 #include "ucontext_i.h"
22 /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
26 /* Same as getcontext(). */
27 stw r16, (UCONTEXT_MCONTEXT + 16*4)(r4)
28 stw r17, (UCONTEXT_MCONTEXT + 17*4)(r4)
29 stw r18, (UCONTEXT_MCONTEXT + 18*4)(r4)
30 stw r19, (UCONTEXT_MCONTEXT + 19*4)(r4)
31 stw r20, (UCONTEXT_MCONTEXT + 20*4)(r4)
32 stw r21, (UCONTEXT_MCONTEXT + 21*4)(r4)
33 stw r22, (UCONTEXT_MCONTEXT + 22*4)(r4)
34 stw ra, (UCONTEXT_MCONTEXT + 24*4)(r4)
35 stw fp, (UCONTEXT_MCONTEXT + 25*4)(r4)
36 stw gp, (UCONTEXT_MCONTEXT + 26*4)(r4)
37 /* Store return address at place for EA. */
38 stw ra, (UCONTEXT_MCONTEXT + 28*4)(r4)
39 stw sp, (UCONTEXT_MCONTEXT + 29*4)(r4)
40 /* Store zero for return success. */
41 stw zero, (UCONTEXT_MCONTEXT + 2*4)(r4)
43 /* Store value "1" at uc_flags to recognize as getcontext created. */
45 stw r2, UCONTEXT_FLAGS(r4)
47 /* Store MCONTEXT_VERSION at first word of mcontext_t. */
48 movi r2, MCONTEXT_VERSION
49 stw r2, UCONTEXT_MCONTEXT(r4)
51 /* Save ucp to non-argument syscall preserved register. */
54 /* Get signal mask. */
55 /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
57 addi r6, r4, UCONTEXT_SIGMASK
60 movi r2, SYS_ify (rt_sigprocmask)
62 bne r7, zero, SYSCALL_ERROR_LABEL
65 /* Same as setcontext(). */
66 ldw r5, UCONTEXT_FLAGS(r10)
68 bne r5, r6, .Lsigreturn
70 /* Restore signal mask. */
71 /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
73 addi r5, r10, UCONTEXT_SIGMASK
76 movi r2, SYS_ify (rt_sigprocmask)
78 bne r7, zero, SYSCALL_ERROR_LABEL
80 /* Restore argument registers, for the makecontext() case. */
81 ldw r4, (UCONTEXT_MCONTEXT + 4*4)(r10)
82 ldw r5, (UCONTEXT_MCONTEXT + 5*4)(r10)
83 ldw r6, (UCONTEXT_MCONTEXT + 6*4)(r10)
84 ldw r7, (UCONTEXT_MCONTEXT + 7*4)(r10)
86 ldw r16, (UCONTEXT_MCONTEXT + 16*4)(r10)
87 ldw r17, (UCONTEXT_MCONTEXT + 17*4)(r10)
88 ldw r18, (UCONTEXT_MCONTEXT + 18*4)(r10)
89 ldw r19, (UCONTEXT_MCONTEXT + 19*4)(r10)
90 ldw r20, (UCONTEXT_MCONTEXT + 20*4)(r10)
91 ldw r21, (UCONTEXT_MCONTEXT + 21*4)(r10)
92 ldw r22, (UCONTEXT_MCONTEXT + 22*4)(r10)
93 ldw ra, (UCONTEXT_MCONTEXT + 24*4)(r10)
94 ldw fp, (UCONTEXT_MCONTEXT + 25*4)(r10)
95 ldw gp, (UCONTEXT_MCONTEXT + 26*4)(r10)
96 /* Load address to continue execution. */
97 ldw r3, (UCONTEXT_MCONTEXT + 28*4)(r10)
98 ldw sp, (UCONTEXT_MCONTEXT + 29*4)(r10)
104 addi sp, sp, -RT_SIGFRAME_SIZE
105 cfi_adjust_cfa_offset (RT_SIGFRAME_SIZE)
107 addi r2, sp, RT_SIGFRAME_UCONTEXT
108 movi r3, UCONTEXT_SIZE-4
117 movi r2, SYS_ify (rt_sigreturn)
120 addi sp, sp, RT_SIGFRAME_SIZE
121 cfi_adjust_cfa_offset (-RT_SIGFRAME_SIZE)
122 br SYSCALL_ERROR_LABEL
124 PSEUDO_END (__swapcontext)
125 weak_alias (__swapcontext, swapcontext)