From: Stafford Horne <shorne@gmail.com>
To: Barebox <barebox@lists.infradead.org>
Cc: Openrisc <openrisc@lists.librecores.org>,
Ahmad Fatoum <a.fatoum@pengutronix.de>,
Stafford Horne <shorne@gmail.com>
Subject: [PATCH 4/4] openrisc: Implement setjmp/longjmp/initjmp
Date: Wed, 3 Mar 2021 22:50:26 +0900 [thread overview]
Message-ID: <20210303135026.3450789-5-shorne@gmail.com> (raw)
In-Reply-To: <20210303135026.3450789-1-shorne@gmail.com>
Tested on or1ksim and this seems to work. This is mostly the same
as the glibc port implementation, but adjusted as per requirements per
barebox.
Signed-off-by: Stafford Horne <shorne@gmail.com>
---
arch/openrisc/Kconfig | 1 +
arch/openrisc/include/asm/setjmp.h | 17 +++++++++
arch/openrisc/lib/Makefile | 1 +
arch/openrisc/lib/setjmp.S | 56 ++++++++++++++++++++++++++++++
4 files changed, 75 insertions(+)
create mode 100644 arch/openrisc/include/asm/setjmp.h
create mode 100644 arch/openrisc/lib/setjmp.S
diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index 32d23029d..bd8851e4b 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -4,6 +4,7 @@ config OPENRISC
select HAS_CACHE
select HAVE_CONFIGURABLE_MEMORY_LAYOUT
select GENERIC_FIND_NEXT_BIT
+ select HAS_ARCH_SJLJ
default y
# not used
diff --git a/arch/openrisc/include/asm/setjmp.h b/arch/openrisc/include/asm/setjmp.h
new file mode 100644
index 000000000..40f55b7eb
--- /dev/null
+++ b/arch/openrisc/include/asm/setjmp.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Define the machine-dependent type `jmp_buf'. OpenRISC version.
+ * Copyright (C) 2021 Free Software Foundation, Inc.
+ * This file is part of the GNU C Library.
+ */
+
+#ifndef _OR1K_BITS_SETJMP_H
+#define _OR1K_BITS_SETJMP_H 1
+
+typedef long int jmp_buf[13];
+
+int setjmp(jmp_buf jmp) __attribute__((returns_twice));
+void longjmp(jmp_buf jmp, int ret) __attribute__((noreturn));
+int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
+
+#endif /* _OR1K_BITS_SETJMP_H */
diff --git a/arch/openrisc/lib/Makefile b/arch/openrisc/lib/Makefile
index 62082feed..808b09f3a 100644
--- a/arch/openrisc/lib/Makefile
+++ b/arch/openrisc/lib/Makefile
@@ -5,4 +5,5 @@ obj-y += muldi3.o
obj-y += lshrdi3.o
obj-y += ashldi3.o
obj-y += ashrdi3.o
+obj-y += setjmp.o
obj-$(CONFIG_BUILTIN_DTB) += dtb.o
diff --git a/arch/openrisc/lib/setjmp.S b/arch/openrisc/lib/setjmp.S
new file mode 100644
index 000000000..7da347780
--- /dev/null
+++ b/arch/openrisc/lib/setjmp.S
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <linux/linkage.h>
+
+/* int setjmp (jmp_buf); */
+ENTRY(setjmp)
+ l.sw 0(r3), r1
+ l.sw 4(r3), r2
+ l.sw 8(r3), r9
+ l.sw 12(r3), r10
+ l.sw 16(r3), r14
+ l.sw 20(r3), r16
+ l.sw 24(r3), r18
+ l.sw 28(r3), r20
+ l.sw 32(r3), r22
+ l.sw 36(r3), r24
+ l.sw 40(r3), r26
+ l.sw 44(r3), r28
+ l.sw 48(r3), r30
+ l.jr r9
+ l.movhi r11, 0x0
+END(setjmp)
+
+/* volatile void longjmp (jmp_buf, int); */
+ENTRY(longjmp)
+ l.lwz r1, 0(r3)
+ l.lwz r2, 4(r3)
+
+ /* if r4 is 0, something wrong, so set it to 1 */
+ l.sfeqi r4, 0x0
+ l.bnf 1f /* r4 != 0, longjmp value sensible */
+ l.nop
+ l.ori r4, r0, 0x1 /* make nonzero */
+1:
+ l.lwz r9, 8(r3)
+ l.lwz r10, 12(r3)
+ l.lwz r14, 16(r3)
+ l.lwz r16, 20(r3)
+ l.lwz r18, 24(r3)
+ l.lwz r20, 28(r3)
+ l.lwz r22, 32(r3)
+ l.lwz r24, 36(r3)
+ l.lwz r26, 40(r3)
+ l.lwz r28, 44(r3)
+ l.lwz r30, 48(r3)
+ l.jr r9
+ l.addi r11, r4, 0x0
+END(longjmp)
+
+/* int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top); */
+ENTRY(initjmp)
+ l.sw 8(r3), r4
+ l.sw 0(r3), r5
+ l.jr r9
+ l.movhi r11, 0x0
+END(initjmp)
--
2.26.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-03-03 20:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-03 13:50 [PATCH 0/4] OpenRISC fixes and setjmp/longjmp work Stafford Horne
2021-03-03 13:50 ` [PATCH 1/4] openrisc: Use movhi to zero registers Stafford Horne
2021-03-03 13:50 ` [PATCH 2/4] openrisc: Add gitignore for dtb files Stafford Horne
2021-03-03 13:50 ` [PATCH 3/4] openrisc: Add linkage.h Stafford Horne
2021-03-03 13:50 ` Stafford Horne [this message]
2021-03-03 14:03 ` [PATCH 0/4] OpenRISC fixes and setjmp/longjmp work Ahmad Fatoum
2021-03-03 14:12 ` Stafford Horne
2021-03-03 20:25 ` Stafford Horne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210303135026.3450789-5-shorne@gmail.com \
--to=shorne@gmail.com \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=openrisc@lists.librecores.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox