1/* Save current context.
2   Copyright (C) 2022 Free Software Foundation, Inc.
3   This file is part of the GNU C Library.
4
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.
9
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.
14
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
19#include "ucontext-macros.h"
20
21/* int getcontext (ucontext_t *ucp) */
22
23	.text
24LEAF (__getcontext)
25	SAVE_INT_REG (ra,   1, a0)
26	SAVE_INT_REG (sp,   3, a0)
27	SAVE_INT_REG (zero, 4, a0) /* return 0 by overwriting a0.  */
28	SAVE_INT_REG (x,   21, a0)
29	SAVE_INT_REG (fp,  22, a0)
30	SAVE_INT_REG (s0,  23, a0)
31	SAVE_INT_REG (s1,  24, a0)
32	SAVE_INT_REG (s2,  25, a0)
33	SAVE_INT_REG (s3,  26, a0)
34	SAVE_INT_REG (s4,  27, a0)
35	SAVE_INT_REG (s5,  28, a0)
36	SAVE_INT_REG (s6,  29, a0)
37	SAVE_INT_REG (s7,  30, a0)
38	SAVE_INT_REG (s8,  31, a0)
39	st.d		ra, a0, MCONTEXT_PC
40
41/* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
42	li.d		a3, _NSIG8
43	li.d		a2, UCONTEXT_SIGMASK
44	add.d		a2, a2, a0
45	ori		a1, zero,0
46	li.d		a0, SIG_BLOCK
47
48	li.d		a7, SYS_ify (rt_sigprocmask)
49	syscall		0
50	blt		a0, zero, 99f
51
52	jirl		$r0, $r1, 0
53
5499:
55	b		__syscall_error
56
57PSEUDO_END (__getcontext)
58
59weak_alias (__getcontext, getcontext)
60