diff options
author | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2019-02-08 13:20:37 +0000 |
---|---|---|
committer | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2019-02-08 13:42:38 +0000 |
commit | 70b0f2789e93f253bec5cbd2986d0de023c1bdf4 (patch) | |
tree | 4de89a2865b8412b3061567f40ee497b45851904 /lib/libc | |
parent | e05663051671bdec38056a2da5ddebd390b4abca (diff) |
libc: Move setjmp to libc folder
Now that setjmp() and longjmp() are compliant with the standard they can
be moved with the other libc files.
Change-Id: Iea3b91c34eb353ace5e171e72f331602d57774d5
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/aarch64/setjmp.S | 61 | ||||
-rw-r--r-- | lib/libc/libc.mk | 9 |
2 files changed, 68 insertions, 2 deletions
diff --git a/lib/libc/aarch64/setjmp.S b/lib/libc/aarch64/setjmp.S new file mode 100644 index 00000000..9d9eb49b --- /dev/null +++ b/lib/libc/aarch64/setjmp.S @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <asm_macros.S> +#include <assert_macros.S> +#include <setjmp.h> + + .globl setjmp + .globl longjmp + +/* + * int setjmp(jmp_buf env); + */ +func setjmp + mov x7, sp + + stp x19, x20, [x0, #JMP_CTX_X19] + stp x21, x22, [x0, #JMP_CTX_X21] + stp x23, x24, [x0, #JMP_CTX_X23] + stp x25, x26, [x0, #JMP_CTX_X25] + stp x27, x28, [x0, #JMP_CTX_X27] + stp x29, x30, [x0, #JMP_CTX_X29] + stp x7, xzr, [x0, #JMP_CTX_SP] + + mov x0, #0 + ret +endfunc setjmp + + +/* + * void longjmp(jmp_buf env, int val); + */ +func longjmp + ldp x7, xzr, [x0, #JMP_CTX_SP] + +#if ENABLE_ASSERTIONS + /* + * Since we're unwinding the stack, assert that the stack being reset to + * is shallower. + */ + mov x19, sp + cmp x7, x19 + ASM_ASSERT(ge) +#endif + + ldp x19, x20, [x0, #JMP_CTX_X19] + ldp x21, x22, [x0, #JMP_CTX_X21] + ldp x23, x24, [x0, #JMP_CTX_X23] + ldp x25, x26, [x0, #JMP_CTX_X25] + ldp x27, x28, [x0, #JMP_CTX_X27] + ldp x29, x30, [x0, #JMP_CTX_X29] + + mov sp, x7 + + ands x0, x1, x1 /* Move val to x0 and set flags */ + cinc x0, x0, eq /* If val is 0, return 1 */ + ret +endfunc longjmp diff --git a/lib/libc/libc.mk b/lib/libc/libc.mk index 1276f5c8..e1b5560f 100644 --- a/lib/libc/libc.mk +++ b/lib/libc/libc.mk @@ -1,10 +1,10 @@ # -# Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # -LIBC_SRCS := $(addprefix lib/libc/, \ +LIBC_SRCS := $(addprefix lib/libc/, \ abort.c \ assert.c \ exit.c \ @@ -25,5 +25,10 @@ LIBC_SRCS := $(addprefix lib/libc/, \ strnlen.c \ strrchr.c) +ifeq (${ARCH},aarch64) +LIBC_SRCS += $(addprefix lib/libc/aarch64/, \ + setjmp.S) +endif + INCLUDES += -Iinclude/lib/libc \ -Iinclude/lib/libc/$(ARCH) \ |