1/* 2 * Copyright (c) 2018-2019, 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(jmp_buf env); 16 */ 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/* 34 * void longjmp(jmp_buf env, int val); 35 */ 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 58 ands x0, x1, x1 /* Move val to x0 and set flags */ 59 cinc x0, x0, eq /* If val is 0, return 1 */ 60 ret 61endfunc longjmp 62