From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Jules Maselbas <jmaselbas@kalray.eu>,
Stafford Horne <shorne@gmail.com>,
Ahmad Fatoum <a.fatoum@pengutronix.de>,
sha@pengutronix.de
Subject: [PATCH v2 11/11] powerpc: Implement initjmp/setjmp/longjmp
Date: Mon, 1 Mar 2021 12:01:06 +0100 [thread overview]
Message-ID: <20210301110106.3764-12-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210301110106.3764-1-a.fatoum@pengutronix.de>
From: Sascha Hauer <s.hauer@pengutronix.de>
Implementation has been taken from newlib as this is much simpler than
the glibc version.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/setjmp.h | 21 ++++++++
arch/powerpc/lib/Makefile | 2 +-
arch/powerpc/lib/setjmp.S | 86 +++++++++++++++++++++++++++++++
4 files changed, 109 insertions(+), 1 deletion(-)
create mode 100644 arch/powerpc/include/asm/setjmp.h
create mode 100644 arch/powerpc/lib/setjmp.S
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 90ec7b1702e9..376c1bf42b5e 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -6,6 +6,7 @@ config PPC
select HAS_CACHE
select GENERIC_FIND_NEXT_BIT
select OFTREE
+ select HAS_ARCH_SJLJ
default y
choice
diff --git a/arch/powerpc/include/asm/setjmp.h b/arch/powerpc/include/asm/setjmp.h
new file mode 100644
index 000000000000..c558415c99d9
--- /dev/null
+++ b/arch/powerpc/include/asm/setjmp.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
+ * (C) Copyright 2016 Alexander Graf <agraf@suse.de>
+ */
+
+#ifndef _SETJMP_H_
+#define _SETJMP_H_ 1
+
+#include <asm/types.h>
+
+typedef struct __jmp_buf_internal_tag {
+ long int __regs[24];
+} jmp_buf[1];
+
+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 /* _SETJMP_H_ */
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index ba2f078b6277..405351c19929 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -9,4 +9,4 @@ obj-$(CONFIG_CMD_BOOTM) += ppclinux.o
obj-$(CONFIG_MODULES) += module.o
obj-y += crtsavres.o
obj-y += reloc.o
-
+obj-y += setjmp.o
diff --git a/arch/powerpc/lib/setjmp.S b/arch/powerpc/lib/setjmp.S
new file mode 100644
index 000000000000..021a57eebc3c
--- /dev/null
+++ b/arch/powerpc/lib/setjmp.S
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/*
+ * This is a simple version of setjmp and longjmp for the PowerPC.
+ * Ian Lance Taylor, Cygnus Support, 9 Feb 1994.
+ */
+
+#include <linux/linkage.h>
+#include <asm/ppc_asm.tmpl>
+
+ENTRY(setjmp)
+ addi r3,r3,7 # align to 8 byte boundary
+ rlwinm r3,r3,0,0,28
+ stw r1,0(r3) # offset 0
+ stwu r2,4(r3) # offset 4
+ stwu r13,4(r3) # offset 8
+ stwu r14,4(r3) # offset 12
+ stwu r15,4(r3) # offset 16
+ stwu r16,4(r3) # offset 20
+ stwu r17,4(r3) # offset 24
+ stwu r18,4(r3) # offset 28
+ stwu r19,4(r3) # offset 32
+ stwu r20,4(r3) # offset 36
+ stwu r21,4(r3) # offset 40
+ stwu r22,4(r3) # offset 44
+ stwu r23,4(r3) # offset 48
+ stwu r24,4(r3) # offset 52
+ stwu r25,4(r3) # offset 56
+ stwu r26,4(r3) # offset 60
+ stwu r27,4(r3) # offset 64
+ stwu r28,4(r3) # offset 68
+ stwu r29,4(r3) # offset 72
+ stwu r30,4(r3) # offset 76
+ stwu r31,4(r3) # offset 80
+ mflr r4
+ stwu r4,4(r3) # offset 84
+ mfcr r4
+ stwu r4,4(r3) # offset 88
+
+ li r3,0
+ blr
+END(setjmp)
+
+ENTRY(longjmp)
+ addi r3,r3,7 # align to 8 byte boundary
+ rlwinm r3,r3,0,0,28
+ lwz r1,0(r3) # offset 0
+ lwzu r2,4(r3) # offset 4
+ lwzu r13,4(r3) # offset 8
+ lwzu r14,4(r3) # offset 12
+ lwzu r15,4(r3) # offset 16
+ lwzu r16,4(r3) # offset 20
+ lwzu r17,4(r3) # offset 24
+ lwzu r18,4(r3) # offset 28
+ lwzu r19,4(r3) # offset 32
+ lwzu r20,4(r3) # offset 36
+ lwzu r21,4(r3) # offset 40
+ lwzu r22,4(r3) # offset 44
+ lwzu r23,4(r3) # offset 48
+ lwzu r24,4(r3) # offset 52
+ lwzu r25,4(r3) # offset 56
+ lwzu r26,4(r3) # offset 60
+ lwzu r27,4(r3) # offset 64
+ lwzu r28,4(r3) # offset 68
+ lwzu r29,4(r3) # offset 72
+ lwzu r30,4(r3) # offset 76
+ lwzu r31,4(r3) # offset 80
+ lwzu r5,4(r3) # offset 84
+ mtlr r5
+ lwzu r5,4(r3) # offset 88
+ mtcrf 255,r5
+
+ mr. r3,r4
+ bclr+ 4,2
+ li r3,1
+ blr
+END(longjmp)
+
+ENTRY(initjmp)
+ addi r3,r3,7 # align to 8 byte boundary
+ rlwinm r3,r3,0,0,28
+ stw r5,0(r3) # offset 0
+ stwu r4,88(r3) # offset 88
+ li r3,0
+ blr
+END(initjmp)
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-03-01 11:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 11:00 [PATCH v2 00/11] common: introduce bthreads, co-operative Ahmad Fatoum
2021-03-01 11:00 ` [PATCH v2 01/11] console: unconditionally run poller_call in ctrlc() Ahmad Fatoum
2021-03-03 10:20 ` [PATCH] fixup! common: introduce bthreads, co-operative barebox threads Ahmad Fatoum
2021-03-04 8:49 ` Sascha Hauer
2021-03-04 9:17 ` Ahmad Fatoum
2021-03-01 11:00 ` [PATCH v2 02/11] " Ahmad Fatoum
2021-03-01 12:42 ` Peter Korsgaard
2021-03-02 8:56 ` Ahmad Fatoum
2021-03-02 8:56 ` [PATCH] fixup! " Ahmad Fatoum
2021-03-01 11:00 ` [PATCH v2 03/11] ARM: asm: setjmp: annotate setjmp/longjmp for GCC Ahmad Fatoum
2021-03-01 11:00 ` [PATCH v2 04/11] ARM: asm: setjmp: implement coroutine dependency initjmp() Ahmad Fatoum
2021-03-01 11:01 ` [PATCH v2 05/11] sandbox: asm: implement setjmp/longjmp/initjmp Ahmad Fatoum
2021-03-01 11:01 ` [PATCH v2 06/11] riscv: Add asm/asm.h Ahmad Fatoum
2021-03-01 11:01 ` [PATCH v2 07/11] riscv: Add asm/linkage.h Ahmad Fatoum
2021-03-01 11:01 ` [PATCH v2 08/11] riscv: Implement setjmp/longjmp/initjmp Ahmad Fatoum
2021-03-01 11:01 ` [PATCH v2 09/11] mips: Add linkage.h Ahmad Fatoum
2021-03-01 11:01 ` [PATCH v2 10/11] mips: Implement setjmp/longjmp/initjmp Ahmad Fatoum
2021-03-02 22:19 ` Peter Mamonov
2021-03-04 8:38 ` Sascha Hauer
2021-03-07 12:00 ` Peter Mamonov
2021-03-10 8:17 ` Ahmad Fatoum
2021-03-14 12:40 ` Ahmad Fatoum
2021-03-01 11:01 ` Ahmad Fatoum [this message]
2021-03-03 12:15 ` [PATCH v2 00/11] common: introduce bthreads, co-operative Stafford Horne
2021-03-03 13:35 ` Stafford Horne
2021-03-03 13:58 ` Ahmad Fatoum
2021-03-03 15:12 ` Sascha Hauer
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=20210301110106.3764-12-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jmaselbas@kalray.eu \
--cc=sha@pengutronix.de \
--cc=shorne@gmail.com \
/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