From 491849427b03671a1acbaf7a774631ac8714a16c Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Fri, 21 Apr 2023 16:59:11 +0900 Subject: [PATCH] libc: aarch64 setjmp, untested --- base/usr/include/setjmp.h | 4 ++++ libc/arch/aarch64/setjmp.c | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 libc/arch/aarch64/setjmp.c diff --git a/base/usr/include/setjmp.h b/base/usr/include/setjmp.h index 87686076..1845fe62 100644 --- a/base/usr/include/setjmp.h +++ b/base/usr/include/setjmp.h @@ -5,7 +5,11 @@ _Begin_C_Header /* i386 */ +#ifdef __aarch64__ +#define _JBLEN 32 +#else #define _JBLEN 9 +#endif typedef long long jmp_buf[_JBLEN]; diff --git a/libc/arch/aarch64/setjmp.c b/libc/arch/aarch64/setjmp.c new file mode 100644 index 00000000..6b02bfa3 --- /dev/null +++ b/libc/arch/aarch64/setjmp.c @@ -0,0 +1,43 @@ +#include +#include + +asm ( + ".globl setjmp\n" + "setjmp:\n" + "mov x2, sp\n" + "stp x2, x29, [x0]\n" + "stp x30, x1, [x0, (1 * 16)]\n" + "stp x19, x20, [x0, (2 * 16)]\n" + "stp x21, x22, [x0, (3 * 16)]\n" + "stp x23, x24, [x0, (4 * 16)]\n" + "stp x25, x26, [x0, (5 * 16)]\n" + "stp x27, x28, [x0, (6 * 16)]\n" + "mov x0, 0\n" + "ret\n" + ".globl longjmp\n" + "longjmp:\n" + "ldp x2, x29, [x0]\n" + "ldp x30, x1, [x0, (1 * 16)]\n" + "ldp x19, x20, [x0, (2 * 16)]\n" + "ldp x21, x22, [x0, (3 * 16)]\n" + "ldp x23, x24, [x0, (4 * 16)]\n" + "ldp x25, x26, [x0, (5 * 16)]\n" + "ldp x27, x28, [x0, (6 * 16)]\n" + "mov sp, x2\n" + "mov x0, 1\n" + "ret\n" +); + +#if 0 +int _setjmp(jmp_buf env); +void _longjmp(jmp_buf env, int val); + +int setjmp(jmp_buf env) { + fprintf(stderr, "setjmp called\n"); + return _setjmp(env); +} +void longjmp(jmp_buf env, int val) { + fprintf(stderr, "longjmp called\n"); + _longjmp(env,val); +} +#endif