Linux: Remove unused generic Makefile
[glibc.git] / sysdeps / unix / sysv / linux / loongarch / setcontext.S
blobd01409af468753f203430c314e8b96a23aa8917e
1 /* 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/>.  */
18 #include "sys/regdef.h"
19 #include "ucontext-macros.h"
21 /*  int __setcontext (const ucontext_t *ucp)
23   Restores the machine context in UCP and thereby resumes execution
24   in that context.
26   This implementation is intended to be used for *synchronous* context
27   switches only.  Therefore, it does not have to restore anything
28   other than the PRESERVED state.  */
30         .text
31 LEAF (__setcontext)
33         addi.d          sp, sp, -16
34         st.d            a0, sp, 0       /* Save ucp to stack */
36 /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
37         li.d            a3, _NSIG8
38         li.d            a2, 0
39         li.d            a1, UCONTEXT_SIGMASK
40         add.d           a1, a1, a0
41         li.d            a0, SIG_SETMASK
43         li.d            a7, SYS_ify (rt_sigprocmask)
44         syscall         0
46         blt             a0, $r0, 99f
48         ld.d            t0, sp, 0       /* Load ucp to t0 */
49         cfi_def_cfa (12, 0)
51 /* Note the contents of argument registers will be random
52    unless makecontext() has been called.  */
53         RESTORE_INT_REG(ra,   1, t0)
54         RESTORE_INT_REG(sp,   3, t0)
55         RESTORE_INT_REG(a0,   4, t0)
56         RESTORE_INT_REG(a1,   5, t0)
57         RESTORE_INT_REG(a2,   6, t0)
58         RESTORE_INT_REG(a3,   7, t0)
59         RESTORE_INT_REG(a4,   8, t0)
60         RESTORE_INT_REG(a5,   9, t0)
61         RESTORE_INT_REG(a6,  10, t0)
62         RESTORE_INT_REG(a7,  11, t0)
63         RESTORE_INT_REG(x,   21, t0)
64         RESTORE_INT_REG(fp,  22, t0)
65         RESTORE_INT_REG(s0,  23, t0)
66         RESTORE_INT_REG(s1,  24, t0)
67         RESTORE_INT_REG(s2,  25, t0)
68         RESTORE_INT_REG(s3,  26, t0)
69         RESTORE_INT_REG(s4,  27, t0)
70         RESTORE_INT_REG(s5,  28, t0)
71         RESTORE_INT_REG(s6,  29, t0)
72         RESTORE_INT_REG(s7,  30, t0)
73         RESTORE_INT_REG(s8,  31, t0)
75         ld.d            t1, t0, MCONTEXT_PC
76         jirl            $r0,t1,0
78 99:
79         addi.d          sp, sp, 16
80         b               __syscall_error
82 PSEUDO_END (__setcontext)
83 weak_alias (__setcontext, setcontext)
85 LEAF (__start_context)
87         /* Terminate call stack by noting ra == 0.  Happily, s0 == 0 here.  */
88         cfi_register (1, 23)
90         /* Call the function passed to makecontext.  */
91         jirl            $r1,s1,0
93         /* Invoke subsequent context if present, else exit(0).  */
94         ori             a0, s2, 0
95         beqz            s2, 1f
96         bl              __setcontext
98         b               HIDDEN_JUMPTARGET(exit)
100 PSEUDO_END (__start_context)