Skip to content

Commit 589fed4

Browse files
Björn Töpelborkmann
authored andcommitted
riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h
Add macros for 64-bit RISC-V PT_REGS to bpf_tracing.h. Signed-off-by: Björn Töpel <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b390d69 commit 589fed4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tools/lib/bpf/bpf_tracing.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#elif defined(__TARGET_ARCH_sparc)
2525
#define bpf_target_sparc
2626
#define bpf_target_defined
27+
#elif defined(__TARGET_ARCH_riscv)
28+
#define bpf_target_riscv
29+
#define bpf_target_defined
2730
#else
2831

2932
/* Fall back to what the compiler says */
@@ -48,6 +51,9 @@
4851
#elif defined(__sparc__)
4952
#define bpf_target_sparc
5053
#define bpf_target_defined
54+
#elif defined(__riscv) && __riscv_xlen == 64
55+
#define bpf_target_riscv
56+
#define bpf_target_defined
5157
#endif /* no compiler target */
5258

5359
#endif
@@ -288,6 +294,32 @@ struct pt_regs;
288294
#define PT_REGS_IP_CORE(x) BPF_CORE_READ((x), pc)
289295
#endif
290296

297+
#elif defined(bpf_target_riscv)
298+
299+
struct pt_regs;
300+
#define PT_REGS_RV const volatile struct user_regs_struct
301+
#define PT_REGS_PARM1(x) (((PT_REGS_RV *)(x))->a0)
302+
#define PT_REGS_PARM2(x) (((PT_REGS_RV *)(x))->a1)
303+
#define PT_REGS_PARM3(x) (((PT_REGS_RV *)(x))->a2)
304+
#define PT_REGS_PARM4(x) (((PT_REGS_RV *)(x))->a3)
305+
#define PT_REGS_PARM5(x) (((PT_REGS_RV *)(x))->a4)
306+
#define PT_REGS_RET(x) (((PT_REGS_RV *)(x))->ra)
307+
#define PT_REGS_FP(x) (((PT_REGS_RV *)(x))->s5)
308+
#define PT_REGS_RC(x) (((PT_REGS_RV *)(x))->a5)
309+
#define PT_REGS_SP(x) (((PT_REGS_RV *)(x))->sp)
310+
#define PT_REGS_IP(x) (((PT_REGS_RV *)(x))->epc)
311+
312+
#define PT_REGS_PARM1_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a0)
313+
#define PT_REGS_PARM2_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a1)
314+
#define PT_REGS_PARM3_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a2)
315+
#define PT_REGS_PARM4_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a3)
316+
#define PT_REGS_PARM5_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a4)
317+
#define PT_REGS_RET_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), ra)
318+
#define PT_REGS_FP_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), fp)
319+
#define PT_REGS_RC_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a5)
320+
#define PT_REGS_SP_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), sp)
321+
#define PT_REGS_IP_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), epc)
322+
291323
#endif
292324

293325
#if defined(bpf_target_powerpc)

0 commit comments

Comments
 (0)