Update copyright dates with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / loongarch / swapcontext.S
blobe58d5c0cf4398754b1bd6d8e321d35187066ec46
1 /* Save and set current context.
2    Copyright (C) 2022-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/>.  */
19 #include "ucontext-macros.h"
21 /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
23 LEAF (__swapcontext)
24         ori             a2, sp, 0               /* Save sp to a2 */
25         addi.d          sp, sp, -16
26         st.d            a1, sp, 0
27         ori             t0, a1, 0
29         SAVE_INT_REG (ra,   1, a0)
30         SAVE_INT_REG (a2,   3, a0)              /* Store sp */
31         SAVE_INT_REG (zero, 4, a0)              /* return 0 by overwriting a0 */
32         SAVE_INT_REG (x,   21, a0)
33         SAVE_INT_REG (fp,  22, a0)
34         SAVE_INT_REG (s0,  23, a0)
35         SAVE_INT_REG (s1,  24, a0)
36         SAVE_INT_REG (s2,  25, a0)
37         SAVE_INT_REG (s3,  26, a0)
38         SAVE_INT_REG (s4,  27, a0)
39         SAVE_INT_REG (s5,  28, a0)
40         SAVE_INT_REG (s6,  29, a0)
41         SAVE_INT_REG (s7,  30, a0)
42         SAVE_INT_REG (s8,  31, a0)
44         st.d            ra, a0, MCONTEXT_PC
46 /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
47         li.d            a3, _NSIG8
48         li.d            a2, UCONTEXT_SIGMASK
49         add.d           a2, a2, a0
50         li.d            a1, UCONTEXT_SIGMASK
51         add.d           a1, a1, t0
52         li.d            a0, SIG_SETMASK
54         li.d            a7, SYS_ify (rt_sigprocmask)
55         syscall         0
57         blt             a0, zero, 99f
59         ld.d            t0, sp, 0               /* Load a1 to t0 */
61 /* Note the contents of argument registers will be random
62    unless makecontext() has been called.  */
63         RESTORE_INT_REG (ra,   1, t0)
64         RESTORE_INT_REG (sp,   3, t0)
65         RESTORE_INT_REG (a0,   4, t0)
66         RESTORE_INT_REG (a1,   5, t0)
67         RESTORE_INT_REG (a2,   6, t0)
68         RESTORE_INT_REG (a3,   7, t0)
69         RESTORE_INT_REG (a4,   8, t0)
70         RESTORE_INT_REG (a5,   9, t0)
71         RESTORE_INT_REG (a6,  10, t0)
72         RESTORE_INT_REG (a7,  11, t0)
73         RESTORE_INT_REG (x,   21, t0)
74         RESTORE_INT_REG (fp,  22, t0)
75         RESTORE_INT_REG (s0,  23, t0)
76         RESTORE_INT_REG (s1,  24, t0)
77         RESTORE_INT_REG (s2,  25, t0)
78         RESTORE_INT_REG (s3,  26, t0)
79         RESTORE_INT_REG (s4,  27, t0)
80         RESTORE_INT_REG (s5,  28, t0)
81         RESTORE_INT_REG (s6,  29, t0)
82         RESTORE_INT_REG (s7,  30, t0)
83         RESTORE_INT_REG (s8,  31, t0)
85         ld.d            t1, t0, MCONTEXT_PC
86         jirl            $r0, t1, 0
89 99:
90         addi.d          sp, sp, 16
91         b               __syscall_error
93 PSEUDO_END (__swapcontext)
95 weak_alias (__swapcontext, swapcontext)