[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] lib: add setjmp/longjmp for riscv64
From: |
Ekaitz Zarraga |
Subject: |
[PATCH] lib: add setjmp/longjmp for riscv64 |
Date: |
Wed, 18 Oct 2023 13:12:11 +0000 |
>From 456fe2e37a29b445d9aa3163c82279fb7b1c2162 Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Wed, 18 Oct 2023 14:41:46 +0200
Subject: [PATCH] lib: add setjmp/longjmp for riscv64
Note about the -tcc file:
HAVE_FLOAT_ASM defines if there's assembly support for float
instructions.
HAVE_FLOAT defines if there's floating point arithmetic support.
This is important for TinyCC because the assembler and the C
compiler are split. TinyCC can HAVE_FLOAT but no assembler support
for them.
* lib/riscv64-mes-gcc/setjmp.c: Add file
* lib/riscv64-mes-tcc/setjmp.c: Add file
---
lib/riscv64-mes-gcc/setjmp.c | 70 +++++++++++++++++++++++---
lib/riscv64-mes-tcc/setjmp.c | 97 ++++++++++++++++++++++++++++++++++++
2 files changed, 160 insertions(+), 7 deletions(-)
create mode 100644 lib/riscv64-mes-tcc/setjmp.c
diff --git a/lib/riscv64-mes-gcc/setjmp.c b/lib/riscv64-mes-gcc/setjmp.c
index 190c1a19..dae21fa0 100644
--- a/lib/riscv64-mes-gcc/setjmp.c
+++ b/lib/riscv64-mes-gcc/setjmp.c
@@ -2,6 +2,7 @@
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
+ * Copyright © 2023 Ekaitz Zarraga <ekaitz@elenq.tech>
*
* This file is part of GNU Mes.
*
@@ -22,19 +23,74 @@
#include <setjmp.h>
#include <stdlib.h>
-/* This doesn't do anything at the moment.
- * According to setjmp.h "It is not supported to use mes' setjmp
implementation together with GCC."
- * We cannot offer this functionality as a C function. It remains to be done
(as assembly) for tcc.
- */
-
void
longjmp (jmp_buf env, int val)
{
- exit (42);
+ val = val == 0 ? 1 : val;
+ asm(
+ "ld s0, 0(a0)\n\t"
+ "ld s1, 8(a0)\n\t"
+ "ld s2, 16(a0)\n\t"
+ "ld s3, 24(a0)\n\t"
+ "ld s4, 32(a0)\n\t"
+ "ld s5, 40(a0)\n\t"
+ "ld s6, 48(a0)\n\t"
+ "ld s7, 56(a0)\n\t"
+ "ld s8, 64(a0)\n\t"
+ "ld s9, 72(a0)\n\t"
+ "ld s10, 80(a0)\n\t"
+ "ld s11, 88(a0)\n\t"
+ "ld sp, 96(a0)\n\t"
+ "ld ra, 104(a0)\n\t"
+#ifndef __riscv_float_abi_soft
+ "fld fs0, 112(a0)\n\t"
+ "fld fs1, 120(a0)\n\t"
+ "fld fs2, 128(a0)\n\t"
+ "fld fs3, 136(a0)\n\t"
+ "fld fs4, 144(a0)\n\t"
+ "fld fs5, 152(a0)\n\t"
+ "fld fs6, 160(a0)\n\t"
+ "fld fs7, 168(a0)\n\t"
+ "fld fs8, 176(a0)\n\t"
+ "fld fs9, 184(a0)\n\t"
+ "fld fs10, 192(a0)\n\t"
+ "fld fs11, 200(a0)\n\t"
+#endif
+ );
}
int
setjmp (jmp_buf env)
{
- return -1;
+ asm(
+ "sd s0, 0(a0)\n\t"
+ "sd s1, 8(a0)\n\t"
+ "sd s2, 16(a0)\n\t"
+ "sd s3, 24(a0)\n\t"
+ "sd s4, 32(a0)\n\t"
+ "sd s5, 40(a0)\n\t"
+ "sd s6, 48(a0)\n\t"
+ "sd s7, 56(a0)\n\t"
+ "sd s8, 64(a0)\n\t"
+ "sd s9, 72(a0)\n\t"
+ "sd s10, 80(a0)\n\t"
+ "sd s11, 88(a0)\n\t"
+ "sd sp, 96(a0)\n\t"
+ "sd ra, 104(a0)\n\t"
+#ifndef __riscv_float_abi_soft
+ "fsd fs0, 112(a0)\n\t"
+ "fsd fs1, 120(a0)\n\t"
+ "fsd fs2, 128(a0)\n\t"
+ "fsd fs3, 136(a0)\n\t"
+ "fsd fs4, 144(a0)\n\t"
+ "fsd fs5, 152(a0)\n\t"
+ "fsd fs6, 160(a0)\n\t"
+ "fsd fs7, 168(a0)\n\t"
+ "fsd fs8, 176(a0)\n\t"
+ "fsd fs9, 184(a0)\n\t"
+ "fsd fs10, 192(a0)\n\t"
+ "fsd fs11, 200(a0)\n\t"
+#endif
+ );
+ return 0;
}
diff --git a/lib/riscv64-mes-tcc/setjmp.c b/lib/riscv64-mes-tcc/setjmp.c
new file mode 100644
index 00000000..96434d94
--- /dev/null
+++ b/lib/riscv64-mes-tcc/setjmp.c
@@ -0,0 +1,97 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+ * Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
+ * Copyright © 2023 Ekaitz Zarraga <ekaitz@elenq.tech>
+ *
+ * This file is part of GNU Mes.
+ *
+ * GNU Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <setjmp.h>
+#include <stdlib.h>
+
+void
+longjmp (jmp_buf env, int val)
+{
+ val = val == 0 ? 1 : val;
+ asm(
+ "ld s0, a0,0\n\t"
+ "ld s1, a0,8\n\t"
+ "ld s2, a0,16\n\t"
+ "ld s3, a0,24\n\t"
+ "ld s4, a0,32\n\t"
+ "ld s5, a0,40\n\t"
+ "ld s6, a0,48\n\t"
+ "ld s7, a0,56\n\t"
+ "ld s8, a0,64\n\t"
+ "ld s9, a0,72\n\t"
+ "ld s10,a0,80\n\t"
+ "ld s11,a0,88\n\t"
+ "ld sp, a0,96\n\t"
+ "ld ra, a0,104\n\t"
+#if HAVE_FLOAT_ASM && HAVE_FLOAT && ! __riscv_float_abi_soft
+ "fld fs0, a0,112\n\t"
+ "fld fs1, a0,120\n\t"
+ "fld fs2, a0,128\n\t"
+ "fld fs3, a0,136\n\t"
+ "fld fs4, a0,144\n\t"
+ "fld fs5, a0,152\n\t"
+ "fld fs6, a0,160\n\t"
+ "fld fs7, a0,168\n\t"
+ "fld fs8, a0,176\n\t"
+ "fld fs9, a0,184\n\t"
+ "fld fs10,a0,192\n\t"
+ "fld fs11,a0,200\n\t"
+#endif
+ );
+}
+
+int
+setjmp (jmp_buf env)
+{
+ asm(
+ "sd a0, s0,0\n\t"
+ "sd a0, s1,8\n\t"
+ "sd a0, s2,16\n\t"
+ "sd a0, s3,24\n\t"
+ "sd a0, s4,32\n\t"
+ "sd a0, s5,40\n\t"
+ "sd a0, s6,48\n\t"
+ "sd a0, s7,56\n\t"
+ "sd a0, s8,64\n\t"
+ "sd a0, s9,72\n\t"
+ "sd a0, s10,80\n\t"
+ "sd a0, s11,88\n\t"
+ "sd a0, sp,96\n\t"
+ "sd a0, ra,104\n\t"
+#if HAVE_FLOAT_ASM && HAVE_FLOAT && ! __riscv_float_abi_soft
+ "fsd a0, fs0,112\n\t"
+ "fsd a0, fs1,120\n\t"
+ "fsd a0, fs2,128\n\t"
+ "fsd a0, fs3,136\n\t"
+ "fsd a0, fs4,144\n\t"
+ "fsd a0, fs5,152\n\t"
+ "fsd a0, fs6,160\n\t"
+ "fsd a0, fs7,168\n\t"
+ "fsd a0, fs8,176\n\t"
+ "fsd a0, fs9,184\n\t"
+ "fsd a0, fs10,192\n\t"
+ "fsd a0, fs11,200\n\t"
+#endif
+ );
+ return 0;
+}
+
--
2.41.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] lib: add setjmp/longjmp for riscv64,
Ekaitz Zarraga <=