lkml.org 
[lkml]   [2022]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 7/8] riscv: Use asm/insn.h for jump labels
Date
This converts kernel/jump_label.c to use asm/insn.h to generate the
jump/nop instructions.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
arch/riscv/kernel/jump_label.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c
index 20e09056d141..b5b4892c3e9e 100644
--- a/arch/riscv/kernel/jump_label.c
+++ b/arch/riscv/kernel/jump_label.c
@@ -9,11 +9,9 @@
#include <linux/memory.h>
#include <linux/mutex.h>
#include <asm/bug.h>
+#include <asm/insn.h>
#include <asm/patch.h>

-#define RISCV_INSN_NOP 0x00000013U
-#define RISCV_INSN_JAL 0x0000006fU
-
void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type)
{
@@ -23,14 +21,10 @@ void arch_jump_label_transform(struct jump_entry *entry,
if (type == JUMP_LABEL_JMP) {
long offset = jump_entry_target(entry) - jump_entry_code(entry);

- if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288))
+ if (WARN_ON(!riscv_insn_valid_20bit_offset(offset)))
return;

- insn = RISCV_INSN_JAL |
- (((u32)offset & GENMASK(19, 12)) << (12 - 12)) |
- (((u32)offset & GENMASK(11, 11)) << (20 - 11)) |
- (((u32)offset & GENMASK(10, 1)) << (21 - 1)) |
- (((u32)offset & GENMASK(20, 20)) << (31 - 20));
+ insn = RISCV_INSN_JAL | riscv_insn_j_imm(offset);
} else {
insn = RISCV_INSN_NOP;
}
--
2.35.1
\
 
 \ /
  Last update: 2022-02-24 16:27    [W:0.160 / U:0.208 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site