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