Jeenu Viswambharan | 2de8153 | 2018-02-16 11:54:24 +0000 | [diff] [blame] | 1 | /* |
Govindraj Raja | eee28e7 | 2023-08-01 15:52:40 -0500 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved. |
Jeenu Viswambharan | 2de8153 | 2018-02-16 11:54:24 +0000 | [diff] [blame] | 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 | /* |
Antonio Nino Diaz | 4586d1c | 2019-02-08 13:10:45 +0000 | [diff] [blame] | 15 | * int setjmp(jmp_buf env); |
Jeenu Viswambharan | 2de8153 | 2018-02-16 11:54:24 +0000 | [diff] [blame] | 16 | */ |
| 17 | func 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 |
| 30 | endfunc setjmp |
| 31 | |
| 32 | |
| 33 | /* |
Antonio Nino Diaz | 4586d1c | 2019-02-08 13:10:45 +0000 | [diff] [blame] | 34 | * void longjmp(jmp_buf env, int val); |
Jeenu Viswambharan | 2de8153 | 2018-02-16 11:54:24 +0000 | [diff] [blame] | 35 | */ |
| 36 | func 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 Diaz | 4586d1c | 2019-02-08 13:10:45 +0000 | [diff] [blame] | 58 | ands x0, x1, x1 /* Move val to x0 and set flags */ |
| 59 | cinc x0, x0, eq /* If val is 0, return 1 */ |
Jeenu Viswambharan | 2de8153 | 2018-02-16 11:54:24 +0000 | [diff] [blame] | 60 | ret |
| 61 | endfunc longjmp |