From: Emil Renner Berthing <kernel@esmil.dk>
To: linux-riscv@lists.infradead.org
Cc: Emil Renner Berthing <kernel@esmil.dk>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Peter Zijlstra <peterz@infradead.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Jason Baron <jbaron@akamai.com>, Ard Biesheuvel <ardb@kernel.org>,
Jisheng Zhang <jszhang@kernel.org>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 6/8] riscv: Use asm/insn.h to generate plt entries
Date: Thu, 24 Feb 2022 16:24:54 +0100 [thread overview]
Message-ID: <20220224152456.493365-7-kernel@esmil.dk> (raw)
In-Reply-To: <20220224152456.493365-1-kernel@esmil.dk>
This converts kernel/module-sections.c to use asm/insn.h to generate
the instructions in the plt entries.
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
arch/riscv/kernel/module-sections.c | 27 ++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)
diff --git a/arch/riscv/kernel/module-sections.c b/arch/riscv/kernel/module-sections.c
index 39d4ac681c2a..cb73399c3603 100644
--- a/arch/riscv/kernel/module-sections.c
+++ b/arch/riscv/kernel/module-sections.c
@@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleloader.h>
+#include <asm/insn.h>
struct got_entry {
unsigned long symbol_addr; /* the real variable address */
@@ -61,36 +62,16 @@ struct plt_entry {
u32 insn_jr; /* jr t1 */
};
-#define OPC_AUIPC 0x0017
-#define OPC_LD 0x3003
-#define OPC_JALR 0x0067
-#define REG_T0 0x5
-#define REG_T1 0x6
-
static struct plt_entry emit_plt_entry(unsigned long val,
unsigned long plt,
unsigned long got_plt)
{
- /*
- * U-Type encoding:
- * +------------+----------+----------+
- * | imm[31:12] | rd[11:7] | opc[6:0] |
- * +------------+----------+----------+
- *
- * I-Type encoding:
- * +------------+------------+--------+----------+----------+
- * | imm[31:20] | rs1[19:15] | funct3 | rd[11:7] | opc[6:0] |
- * +------------+------------+--------+----------+----------+
- *
- */
unsigned long offset = got_plt - plt;
- u32 hi20 = (offset + 0x800) & 0xfffff000;
- u32 lo12 = (offset - hi20);
return (struct plt_entry) {
- OPC_AUIPC | (REG_T0 << 7) | hi20,
- OPC_LD | (lo12 << 20) | (REG_T0 << 15) | (REG_T1 << 7),
- OPC_JALR | (REG_T1 << 15)
+ RISCV_INSN_AUIPC | RISCV_INSN_RD_T0 | riscv_insn_u_imm(offset + 0x800),
+ RISCV_INSN_LD | RISCV_INSN_RD_T1 | RISCV_INSN_RS1_T0 | riscv_insn_i_imm(offset),
+ RISCV_INSN_JALR | RISCV_INSN_RS1_T1,
};
}
--
2.35.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Emil Renner Berthing <kernel@esmil.dk>
To: linux-riscv@lists.infradead.org
Cc: Emil Renner Berthing <kernel@esmil.dk>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Peter Zijlstra <peterz@infradead.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Jason Baron <jbaron@akamai.com>, Ard Biesheuvel <ardb@kernel.org>,
Jisheng Zhang <jszhang@kernel.org>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 6/8] riscv: Use asm/insn.h to generate plt entries
Date: Thu, 24 Feb 2022 16:24:54 +0100 [thread overview]
Message-ID: <20220224152456.493365-7-kernel@esmil.dk> (raw)
In-Reply-To: <20220224152456.493365-1-kernel@esmil.dk>
This converts kernel/module-sections.c to use asm/insn.h to generate
the instructions in the plt entries.
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
arch/riscv/kernel/module-sections.c | 27 ++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)
diff --git a/arch/riscv/kernel/module-sections.c b/arch/riscv/kernel/module-sections.c
index 39d4ac681c2a..cb73399c3603 100644
--- a/arch/riscv/kernel/module-sections.c
+++ b/arch/riscv/kernel/module-sections.c
@@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleloader.h>
+#include <asm/insn.h>
struct got_entry {
unsigned long symbol_addr; /* the real variable address */
@@ -61,36 +62,16 @@ struct plt_entry {
u32 insn_jr; /* jr t1 */
};
-#define OPC_AUIPC 0x0017
-#define OPC_LD 0x3003
-#define OPC_JALR 0x0067
-#define REG_T0 0x5
-#define REG_T1 0x6
-
static struct plt_entry emit_plt_entry(unsigned long val,
unsigned long plt,
unsigned long got_plt)
{
- /*
- * U-Type encoding:
- * +------------+----------+----------+
- * | imm[31:12] | rd[11:7] | opc[6:0] |
- * +------------+----------+----------+
- *
- * I-Type encoding:
- * +------------+------------+--------+----------+----------+
- * | imm[31:20] | rs1[19:15] | funct3 | rd[11:7] | opc[6:0] |
- * +------------+------------+--------+----------+----------+
- *
- */
unsigned long offset = got_plt - plt;
- u32 hi20 = (offset + 0x800) & 0xfffff000;
- u32 lo12 = (offset - hi20);
return (struct plt_entry) {
- OPC_AUIPC | (REG_T0 << 7) | hi20,
- OPC_LD | (lo12 << 20) | (REG_T0 << 15) | (REG_T1 << 7),
- OPC_JALR | (REG_T1 << 15)
+ RISCV_INSN_AUIPC | RISCV_INSN_RD_T0 | riscv_insn_u_imm(offset + 0x800),
+ RISCV_INSN_LD | RISCV_INSN_RD_T1 | RISCV_INSN_RS1_T0 | riscv_insn_i_imm(offset),
+ RISCV_INSN_JALR | RISCV_INSN_RS1_T1,
};
}
--
2.35.1
next prev parent reply other threads:[~2022-02-24 15:26 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-24 15:24 [PATCH v3 0/8] Add RISC-V asm/insn.h header Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
2022-02-24 15:24 ` [PATCH v3 1/8] riscv: Avoid unaligned access when relocating modules Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
2022-02-26 4:48 ` Samuel Bronson
2022-02-26 4:48 ` Samuel Bronson
2022-02-28 12:46 ` Emil Renner Berthing
2022-02-28 12:46 ` Emil Renner Berthing
2022-02-24 15:24 ` [PATCH v3 2/8] riscv: Remove unneeded definitions from asm/module.h Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
2022-02-24 15:24 ` [PATCH v3 3/8] riscv: Remove unneeded definitions from asm/ftrace.h Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
2022-02-24 15:24 ` [PATCH v3 4/8] riscv: Add asm/insn.h header Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
2022-02-24 15:24 ` [PATCH v3 5/8] riscv: Use asm/insn.h for module relocations Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing [this message]
2022-02-24 15:24 ` [PATCH v3 6/8] riscv: Use asm/insn.h to generate plt entries Emil Renner Berthing
2022-02-24 15:24 ` [PATCH v3 7/8] riscv: Use asm/insn.h for jump labels Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
2022-02-24 15:24 ` [PATCH v3 8/8] riscv: Use asm/insn.h for dynamic ftrace Emil Renner Berthing
2022-02-24 15:24 ` Emil Renner Berthing
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=20220224152456.493365-7-kernel@esmil.dk \
--to=kernel@esmil.dk \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=jbaron@akamai.com \
--cc=jpoimboe@redhat.com \
--cc=jszhang@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mingo@redhat.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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 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.