xref: /freebsd/lib/libc/aarch64/gen/setjmp.S (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1/*-
2 * Copyright (c) 2014 Andrew Turner
3 * Copyright (c) 2014 The FreeBSD Foundation
4 *
5 * Portions of this software were developed by Andrew Turner
6 * under sponsorship from the FreeBSD Foundation
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31#include <machine/asm.h>
32#include <machine/setjmp.h>
33
34ENTRY(setjmp)
35	sub	sp, sp, #16
36	stp	x0, lr, [sp]
37
38	/* Store the signal mask */
39	add	x2, x0, #(_JB_SIGMASK * 8)	/* oset */
40	mov	x1, #0				/* set */
41	mov	x0, #1				/* SIG_BLOCK */
42	bl	sigprocmask
43
44	ldp	x0, lr, [sp]
45	add	sp, sp, #16
46
47	/* Store the magic value and stack pointer */
48	ldr	x8, .Lmagic
49	mov	x9, sp
50	stp	x8, x9, [x0], #16
51
52	/* Store the general purpose registers and lr */
53	stp	x19, x20, [x0], #16
54	stp	x21, x22, [x0], #16
55	stp	x23, x24, [x0], #16
56	stp	x25, x26, [x0], #16
57	stp	x27, x28, [x0], #16
58	stp	x29, lr, [x0], #16
59
60	/* Store the vfp registers */
61	stp	d8, d9, [x0], #16
62	stp	d10, d11, [x0], #16
63	stp	d12, d13, [x0], #16
64	stp	d14, d15, [x0]
65
66	/* Return value */
67	mov	x0, #0
68	ret
69	.align	3
70.Lmagic:
71	.quad	_JB_MAGIC_SETJMP
72END(setjmp)
73
74ENTRY(longjmp)
75	sub	sp, sp, #32
76	stp	x0, lr, [sp]
77	str	x1, [sp, #16]
78
79	/* Restore the signal mask */
80	mov	x2, #0				/* oset */
81	add	x1, x0, #(_JB_SIGMASK * 8)	/* set */
82	mov	x0, #3				/* SIG_SETMASK */
83	bl	sigprocmask
84
85	ldr	x1, [sp, #16]
86	ldp	x0, lr, [sp]
87	add	sp, sp, #32
88
89	/* Check the magic value */
90	ldr	x8, [x0], #8
91	ldr	x9, .Lmagic
92	cmp	x8, x9
93	b.ne	botch
94
95	/* Restore the stack pointer */
96	ldr	x8, [x0], #8
97	mov	sp, x8
98
99	/* Restore the general purpose registers and lr */
100	ldp	x19, x20, [x0], #16
101	ldp	x21, x22, [x0], #16
102	ldp	x23, x24, [x0], #16
103	ldp	x25, x26, [x0], #16
104	ldp	x27, x28, [x0], #16
105	ldp	x29, lr, [x0], #16
106
107	/* Restore the vfp registers */
108	ldp	d8, d9, [x0], #16
109	ldp	d10, d11, [x0], #16
110	ldp	d12, d13, [x0], #16
111	ldp	d14, d15, [x0]
112
113	/* Load the return value */
114	cmp	x1, #0
115	csinc	x0, x1, xzr, ne
116	ret
117
118botch:
119	bl	_C_LABEL(longjmperror)
120	bl	_C_LABEL(abort)
121END(longjmp)
122