1/* Install given context.
2   Copyright (C) 2005-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 <sysdep.h>
20
21#include "ucontext_i.h"
22
23/*  int __setcontext (const ucontext_t *uc);  */
24
25	.text
26	.align  5
27ENTRY(__setcontext)
28
29	mov	r4, r8
30
31	/* sigprocmask (SIG_SETMASK, &uc->uc_sigmask, NULL).  */
32	mov	r4, r5
33	add	#(oSIGMASK/2), r5
34	add	#(oSIGMASK/2), r5
35	mov	#SIG_SETMASK, r4
36	mov	#0, r6
37	mov	#+SYS_ify(sigprocmask), r3
38	trapa	#0x13
39	mov     r0, r1
40	mov	#-12, r2
41	shad	r2, r1
42	not	r1, r1			// r1=0 means r0 = -1 to -4095
43	tst	r1, r1			// i.e. error in linux
44	bf	.Lsetcontext_restore
45.Lsyscall_error:
46	SYSCALL_ERROR_HANDLER
47.Lpseudo_end:
48	rts
49	 nop
50
51.Lsetcontext_restore:
52#ifdef __SH_FPU_ANY__
53	mov	r8, r0
54	add	#(oFR0),r0
55	fmov.s	@r0+, fr0
56	fmov.s	@r0+, fr1
57	fmov.s	@r0+, fr2
58	fmov.s	@r0+, fr3
59	fmov.s	@r0+, fr4
60	fmov.s	@r0+, fr5
61	fmov.s	@r0+, fr6
62	fmov.s	@r0+, fr7
63	fmov.s	@r0+, fr8
64	fmov.s	@r0+, fr9
65	fmov.s	@r0+, fr10
66	fmov.s	@r0+, fr11
67	fmov.s	@r0+, fr12
68	fmov.s	@r0+, fr13
69	fmov.s	@r0+, fr14
70	fmov.s	@r0+, fr15
71	frchg
72	fmov.s	@r0+, fr0
73	fmov.s	@r0+, fr1
74	fmov.s	@r0+, fr2
75	fmov.s	@r0+, fr3
76	fmov.s	@r0+, fr4
77	fmov.s	@r0+, fr5
78	fmov.s	@r0+, fr6
79	fmov.s	@r0+, fr7
80	fmov.s	@r0+, fr8
81	fmov.s	@r0+, fr9
82	fmov.s	@r0+, fr10
83	fmov.s	@r0+, fr11
84	fmov.s	@r0+, fr12
85	fmov.s	@r0+, fr13
86	fmov.s	@r0+, fr14
87	fmov.s	@r0+, fr15
88	frchg
89	lds.l	@r0+, fpscr
90	lds.l	@r0+, fpul
91#endif /* __SH_FPU_ANY__ */
92
93	mov	r8, r0
94	add	#(oPC), r0
95	mov.l	@r0+, r2
96	lds.l	@r0+, pr
97
98	/* Restore T frag.  */
99	mov.l	@r0+, r1
100	shlr	r1
101	/* Skip GBR which is used for thread pointer.  */
102	add	#4, r0
103
104	lds.l	@r0+, mach
105	lds.l	@r0+, macl
106
107	mov	r8, r0
108	add	#(oR9), r0
109	mov.l	@r0+, r9
110	mov.l	@r0+, r10
111	mov.l	@r0+, r11
112	mov.l	@r0+, r12
113	mov.l	@r0+, r13
114	mov.l	@r0+, r14
115	mov.l	@r0+, r15
116
117	mov	r8, r0
118	mov.l	@(oR0,r0), r1
119	mov.l	r1, @-r15
120	cfi_adjust_cfa_offset(4)
121	cfi_rel_offset (r1, 0)
122	mov.l	r2, @-r15
123	cfi_adjust_cfa_offset(4)
124	cfi_rel_offset (r2, 0)
125
126	mov.l	@(oR1,r0), r1
127	mov.l	@(oR2,r0), r2
128	mov.l	@(oR3,r0), r3
129	mov.l	@(oR4,r0), r4
130	mov.l	@(oR5,r0), r5
131	mov.l	@(oR6,r0), r6
132	mov.l	@(oR7,r0), r7
133	mov.l	@(oR8,r0), r8
134	mov.l	@r15+, r0
135	cfi_adjust_cfa_offset(-4)
136	jmp	@r0
137	 mov.l	@r15+, r0
138
139PSEUDO_END(__setcontext)
140
141weak_alias (__setcontext, setcontext)
142