blob: 9060cb7569fb412050628e9f0ad6062af4b08784 [file] [log] [blame]
Jeenu Viswambharan2de81532018-02-16 11:54:24 +00001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
8#include <assert_macros.S>
9#include <setjmp.h>
10
11 .globl setjmp
12 .globl longjmp
13
14/*
15 * int setjmp(struct jmpbuf *buf);
16 *
17 * Sets a jump point in the buffer specified in x0. Returns 0 to the caller when
18 * when setting up the jump, and 1 when returning from the jump.
19 */
20func setjmp
21 mov x7, sp
22
23 stp x19, x20, [x0, #JMP_CTX_X19]
24 stp x21, x22, [x0, #JMP_CTX_X21]
25 stp x23, x24, [x0, #JMP_CTX_X23]
26 stp x25, x26, [x0, #JMP_CTX_X25]
27 stp x27, x28, [x0, #JMP_CTX_X27]
28 stp x29, x30, [x0, #JMP_CTX_X29]
29 stp x7, xzr, [x0, #JMP_CTX_SP]
30
31 mov x0, #0
32 ret
33endfunc setjmp
34
35
36/*
37 * void longjmp(struct jmpbuf *buf);
38 *
39 * Return to a jump point setup by setjmp()
40 */
41func longjmp
42 ldp x7, xzr, [x0, #JMP_CTX_SP]
43
44#if ENABLE_ASSERTIONS
45 /*
46 * Since we're unwinding the stack, assert that the stack being reset to
47 * is shallower.
48 */
49 mov x19, sp
50 cmp x7, x19
51 ASM_ASSERT(ge)
52#endif
53
54 ldp x19, x20, [x0, #JMP_CTX_X19]
55 ldp x21, x22, [x0, #JMP_CTX_X21]
56 ldp x23, x24, [x0, #JMP_CTX_X23]
57 ldp x25, x26, [x0, #JMP_CTX_X25]
58 ldp x27, x28, [x0, #JMP_CTX_X27]
59 ldp x29, x30, [x0, #JMP_CTX_X29]
60
61 mov sp, x7
62
63 mov x0, #1
64 ret
65endfunc longjmp