All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/8] riscv: Add setjmp/longjmp code
Date: Wed, 18 Apr 2018 15:40:23 +0200	[thread overview]
Message-ID: <20180418134030.55127-2-agraf@suse.de> (raw)
In-Reply-To: <20180418134030.55127-1-agraf@suse.de>

To support efi_loader we need to have platform support for setjmp/longjmp.
Add it here.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/riscv/include/asm/setjmp.h | 24 ++++++++++++++++++
 arch/riscv/lib/Makefile         |  1 +
 arch/riscv/lib/setjmp.S         | 54 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 arch/riscv/include/asm/setjmp.h
 create mode 100644 arch/riscv/lib/setjmp.S

diff --git a/arch/riscv/include/asm/setjmp.h b/arch/riscv/include/asm/setjmp.h
new file mode 100644
index 0000000000..37e8281aaa
--- /dev/null
+++ b/arch/riscv/include/asm/setjmp.h
@@ -0,0 +1,24 @@
+/*
+ * (C) Copyright 2018 Alexander Graf <agraf@suse.de>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _SETJMP_H_
+#define _SETJMP_H_	1
+
+/*
+ * This really should be opaque, but the EFI implementation wrongly
+ * assumes that a 'struct jmp_buf_data' is defined.
+ */
+struct jmp_buf_data {
+	/* x2, x8, x9, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27 */
+	u64  regs[13];
+};
+
+typedef struct jmp_buf_data jmp_buf[1];
+
+int setjmp(jmp_buf jmp);
+void longjmp(jmp_buf jmp, int ret);
+
+#endif /* _SETJMP_H_ */
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 323cf3e835..6d97aa2719 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o
 obj-$(CONFIG_CMD_GO) += boot.o
 obj-y	+= cache.o
 obj-y	+= interrupts.o
+obj-y   += setjmp.o
diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S
new file mode 100644
index 0000000000..55c5128163
--- /dev/null
+++ b/arch/riscv/lib/setjmp.S
@@ -0,0 +1,54 @@
+/*
+ * (C) 2018 Alexander Graf <agraf@suse.de>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <config.h>
+#include <linux/linkage.h>
+
+.pushsection .text.setjmp, "ax"
+ENTRY(setjmp)
+	/* Preserve all callee-saved registers and the SP */
+	sd s0, 0(a0)
+	sd s1, 8(a0)
+	sd s2, 16(a0)
+	sd s3, 24(a0)
+	sd s4, 32(a0)
+	sd s5, 40(a0)
+	sd s6, 48(a0)
+	sd s7, 56(a0)
+	sd s8, 64(a0)
+	sd s9, 72(a0)
+	sd s10, 80(a0)
+	sd s11, 88(a0)
+	li  a0, 0
+	ret
+ENDPROC(setjmp)
+.popsection
+
+.pushsection .text.longjmp, "ax"
+ENTRY(longjmp)
+	ld s0, 0(a0)
+	ld s1, 8(a0)
+	ld s2, 16(a0)
+	ld s3, 24(a0)
+	ld s4, 32(a0)
+	ld s5, 40(a0)
+	ld s6, 48(a0)
+	ld s7, 56(a0)
+	ld s8, 64(a0)
+	ld s9, 72(a0)
+	ld s10, 80(a0)
+	ld s11, 88(a0)
+
+	/* Move the return value in place, but return 1 if passed 0. */
+	beq a1, zero, longjmp_1
+	mv a0, a1
+	ret
+
+	longjmp_1:
+	li a0, 1
+	ret
+ENDPROC(longjmp)
+.popsection
-- 
2.12.3

  reply	other threads:[~2018-04-18 13:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
2018-04-18 13:40 ` Alexander Graf [this message]
2018-04-18 13:40 ` [U-Boot] [PATCH 2/8] riscv: Enable function sections Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v Alexander Graf
2018-04-18 15:48   ` Heinrich Schuchardt
2018-04-18 16:41     ` Alexander Graf
2018-04-19  5:57   ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 4/8] riscv: Add board_quiesce_devices stub Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 5/8] efi_loader: Use EFI_CACHELINE_SIZE in the image loader too Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines Alexander Graf
2018-04-18 15:43   ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 7/8] riscv: nx25: Enable distro boot Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support Alexander Graf
2018-04-19  5:14   ` Heinrich Schuchardt

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=20180418134030.55127-2-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.