blob: 9cb31eac4e1dd41e05d39a27f4221f30844e7e48 [file] [log] [blame]
Jeenu Viswambharan2de81532018-02-16 11:54:24 +00001/*
Govindraj Rajaeee28e72023-08-01 15:52:40 -05002 * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharan2de81532018-02-16 11:54:24 +00003 *
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/*
Antonio Nino Diaz4586d1c2019-02-08 13:10:45 +000015 * int setjmp(jmp_buf env);
Jeenu Viswambharan2de81532018-02-16 11:54:24 +000016 */
17func setjmp
18 mov x7, sp
19
20 stp x19, x20, [x0, #JMP_CTX_X19]
21 stp x21, x22, [x0, #JMP_CTX_X21]
22 stp x23, x24, [x0, #JMP_CTX_X23]
23 stp x25, x26, [x0, #JMP_CTX_X25]
24 stp x27, x28, [x0, #JMP_CTX_X27]
25 stp x29, x30, [x0, #JMP_CTX_X29]
26 stp x7, xzr, [x0, #JMP_CTX_SP]
27
28 mov x0, #0
29 ret
30endfunc setjmp
31
32
33/*
Antonio Nino Diaz4586d1c2019-02-08 13:10:45 +000034 * void longjmp(jmp_buf env, int val);
Jeenu Viswambharan2de81532018-02-16 11:54:24 +000035 */
36func longjmp
37 ldp x7, xzr, [x0, #JMP_CTX_SP]
38
39#if ENABLE_ASSERTIONS
40 /*
41 * Since we're unwinding the stack, assert that the stack being reset to
42 * is shallower.
43 */
44 mov x19, sp
45 cmp x7, x19
46 ASM_ASSERT(ge)
47#endif
48
49 ldp x19, x20, [x0, #JMP_CTX_X19]
50 ldp x21, x22, [x0, #JMP_CTX_X21]
51 ldp x23, x24, [x0, #JMP_CTX_X23]
52 ldp x25, x26, [x0, #JMP_CTX_X25]
53 ldp x27, x28, [x0, #JMP_CTX_X27]
54 ldp x29, x30, [x0, #JMP_CTX_X29]
55
56 mov sp, x7
57
Antonio Nino Diaz4586d1c2019-02-08 13:10:45 +000058 ands x0, x1, x1 /* Move val to x0 and set flags */
59 cinc x0, x0, eq /* If val is 0, return 1 */
Jeenu Viswambharan2de81532018-02-16 11:54:24 +000060 ret
61endfunc longjmp