1/* Copyright (C) 2012-2022 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3
4   The GNU C Library is free software; you can redistribute it and/or
5   modify it under the terms of the GNU Lesser General Public
6   License as published by the Free Software Foundation; either
7   version 2.1 of the License, or (at your option) any later version.
8
9   The GNU C Library is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with the GNU C Library; if not, see
16   <https://www.gnu.org/licenses/>.  */
17
18#include <sysdep.h>
19
20#include "ucontext_i.h"
21
22	.syntax unified
23	.text
24
25/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
26
27ENTRY(swapcontext)
28
29	/* Have getcontext() do most of the work then fix up
30	   LR afterwards.  Save R3 to keep the stack aligned.  */
31	push	{r0,r1,r3,r14}
32	cfi_adjust_cfa_offset (16)
33	cfi_rel_offset (r0,0)
34	cfi_rel_offset (r1,4)
35	cfi_rel_offset (r3,8)
36	cfi_rel_offset (r14,12)
37
38	bl	__getcontext
39	mov	r4, r0
40
41	pop	{r0,r1,r3,r14}
42	cfi_adjust_cfa_offset (-16)
43	cfi_restore (r0)
44	cfi_restore (r1)
45	cfi_restore (r3)
46	cfi_restore (r14)
47
48	/* Exit if getcontext() failed.  */
49	cmp 	r4, #0
50	itt	ne
51	movne	r0, r4
52	RETINSTR(ne, r14)
53
54	/* Fix up LR and the PC.  */
55	str	r13,[r0, #MCONTEXT_ARM_SP]
56	str	r14,[r0, #MCONTEXT_ARM_LR]
57	str	r14,[r0, #MCONTEXT_ARM_PC]
58
59	/* And swap using swapcontext().  */
60	mov	r0, r1
61	b	__setcontext
62
63END(swapcontext)
64