summaryrefslogtreecommitdiffstats
path: root/arch/loongarch/include/asm/inst.h
diff options
context:
space:
mode:
authorTiezhu Yang <yangtiezhu@loongson.cn>2023-02-25 08:52:57 +0100
committerHuacai Chen <chenhuacai@loongson.cn>2023-02-25 15:12:17 +0100
commit6d4cc40fb5f58147defc6c0e9d86e6232fe31616 (patch)
tree71f244b9bce629eb133a0cb8d90c08f2cdd9e98f /arch/loongarch/include/asm/inst.h
parentLoongArch: Simulate branch and PC* instructions (diff)
downloadlinux-6d4cc40fb5f58147defc6c0e9d86e6232fe31616.tar.xz
linux-6d4cc40fb5f58147defc6c0e9d86e6232fe31616.zip
LoongArch: Add kprobes support
Kprobes allows you to trap at almost any kernel address and execute a callback function, this commit adds kprobes support for LoongArch. Tested-by: Jeff Xie <xiehuan09@gmail.com> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Diffstat (limited to 'arch/loongarch/include/asm/inst.h')
-rw-r--r--arch/loongarch/include/asm/inst.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/arch/loongarch/include/asm/inst.h b/arch/loongarch/include/asm/inst.h
index 3ade9ff2bb8f..a04fe755d719 100644
--- a/arch/loongarch/include/asm/inst.h
+++ b/arch/loongarch/include/asm/inst.h
@@ -24,6 +24,10 @@
#define ADDR_IMM(addr, INSN) ((addr & ADDR_IMMMASK_##INSN) >> ADDR_IMMSHIFT_##INSN)
+enum reg0i15_op {
+ break_op = 0x54,
+};
+
enum reg0i26_op {
b_op = 0x14,
bl_op = 0x15,
@@ -180,6 +184,11 @@ enum reg3sa2_op {
alsld_op = 0x16,
};
+struct reg0i15_format {
+ unsigned int immediate : 15;
+ unsigned int opcode : 17;
+};
+
struct reg0i26_format {
unsigned int immediate_h : 10;
unsigned int immediate_l : 16;
@@ -265,6 +274,7 @@ struct reg3sa2_format {
union loongarch_instruction {
unsigned int word;
+ struct reg0i15_format reg0i15_format;
struct reg0i26_format reg0i26_format;
struct reg1i20_format reg1i20_format;
struct reg1i21_format reg1i21_format;
@@ -323,6 +333,11 @@ static inline bool is_imm_negative(unsigned long val, unsigned int bit)
return val & (1UL << (bit - 1));
}
+static inline bool is_break_ins(union loongarch_instruction *ip)
+{
+ return ip->reg0i15_format.opcode == break_op;
+}
+
static inline bool is_pc_ins(union loongarch_instruction *ip)
{
return ip->reg1i20_format.opcode >= pcaddi_op &&