xref: /freebsd/lib/libc/aarch64/gen/_setjmp.S (revision a7623790fb345e6dc986dfd31df0ace115e6f2e4)
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	/* Store the magic value and stack pointer */
39	ldr	x8, .Lmagic
40	mov	x9, sp
41	stp	x8, x9, [x0], #16
42
43	/* Store the general purpose registers and lr */
44	stp	x19, x20, [x0], #16
45	stp	x21, x22, [x0], #16
46	stp	x23, x24, [x0], #16
47	stp	x25, x26, [x0], #16
48	stp	x27, x28, [x0], #16
49	stp	x29, lr, [x0], #16
50
51#ifndef _STANDALONE
52	/* Store the vfp registers */
53	stp	d8, d9, [x0], #16
54	stp	d10, d11, [x0], #16
55	stp	d12, d13, [x0], #16
56	stp	d14, d15, [x0]
57#endif
58
59	/* Return value */
60	mov	x0, #0
61	ret
62	.align	3
63.Lmagic:
64	.quad	_JB_MAGIC__SETJMP
65END(_setjmp)
66
67ENTRY(_longjmp)
68	/* Check the magic value */
69	ldr	x8, [x0], #8
70	ldr	x9, .Lmagic
71	cmp	x8, x9
72	b.ne	botch
73
74	/* Restore the stack pointer */
75	ldr	x8, [x0], #8
76	mov	sp, x8
77
78	/* Restore the general purpose registers and lr */
79	ldp	x19, x20, [x0], #16
80	ldp	x21, x22, [x0], #16
81	ldp	x23, x24, [x0], #16
82	ldp	x25, x26, [x0], #16
83	ldp	x27, x28, [x0], #16
84	ldp	x29, lr, [x0], #16
85
86#ifndef _STANDALONE
87	/* Restore the vfp registers */
88	ldp	d8, d9, [x0], #16
89	ldp	d10, d11, [x0], #16
90	ldp	d12, d13, [x0], #16
91	ldp	d14, d15, [x0]
92#endif
93
94	/* Load the return value */
95	mov	x0, x1
96	ret
97
98botch:
99#ifdef _STANDALONE
100	b	botch
101#else
102	bl	_C_LABEL(longjmperror)
103	bl	_C_LABEL(abort)
104#endif
105END(_longjmp)
106