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