Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loongfire: port loxilb to loongarch #73

Open
vincentmli opened this issue Jan 24, 2025 · 1 comment
Open

loongfire: port loxilb to loongarch #73

vincentmli opened this issue Jan 24, 2025 · 1 comment

Comments

@vincentmli
Copy link
Owner

attempting to port loxilb to loongfire, but loxilb libbpf is on 0.8 which does not have loongarch support

@vincentmli
Copy link
Owner Author

copied the loongarch from libbpf 1.2.3 and renamed loongarch to loongarch64 to libbpf 0.8 seems working ok

[root@fedora libbpf]# diff -u src/bpf_tracing.h src/bpf_tracing.h.loongarch 
--- src/bpf_tracing.h	2025-01-31 13:32:38.733091585 -0800
+++ src/bpf_tracing.h.loongarch	2025-01-31 13:32:05.732071368 -0800
@@ -30,6 +30,9 @@
 #elif defined(__TARGET_ARCH_arc)
 	#define bpf_target_arc
 	#define bpf_target_defined
+#elif defined(__TARGET_ARCH_loongarch64)
+        #define bpf_target_loongarch64
+        #define bpf_target_defined
 #else
 
 /* Fall back to what the compiler says */
@@ -60,6 +63,9 @@
 #elif defined(__arc__)
 	#define bpf_target_arc
 	#define bpf_target_defined
+#elif defined(__loongarch64__)
+        #define bpf_target_loongarch64
+        #define bpf_target_defined
 #endif /* no compiler target */
 
 #endif
@@ -256,6 +262,39 @@
 /* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */
 #define PT_REGS_SYSCALL_REGS(ctx) ctx
 
+#elif defined(bpf_target_loongarch64)
+
+/*
+ * https://docs.kernel.org/loongarch/introduction.html
+ * https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
+ */
+
+/* loongarch provides struct user_pt_regs instead of struct pt_regs to userspace */
+#define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x))
+#define __PT_PARM1_REG regs[4]
+#define __PT_PARM2_REG regs[5]
+#define __PT_PARM3_REG regs[6]
+#define __PT_PARM4_REG regs[7]
+#define __PT_PARM5_REG regs[8]
+#define __PT_PARM6_REG regs[9]
+#define __PT_PARM7_REG regs[10]
+#define __PT_PARM8_REG regs[11]
+
+/* loongarch does not select ARCH_HAS_SYSCALL_WRAPPER. */
+#define PT_REGS_SYSCALL_REGS(ctx) ctx
+#define __PT_PARM1_SYSCALL_REG __PT_PARM1_REG
+#define __PT_PARM2_SYSCALL_REG __PT_PARM2_REG
+#define __PT_PARM3_SYSCALL_REG __PT_PARM3_REG
+#define __PT_PARM4_SYSCALL_REG __PT_PARM4_REG
+#define __PT_PARM5_SYSCALL_REG __PT_PARM5_REG
+#define __PT_PARM6_SYSCALL_REG __PT_PARM6_REG
+
+#define __PT_RET_REG regs[1]
+#define __PT_FP_REG regs[22]
+#define __PT_RC_REG regs[4]
+#define __PT_SP_REG regs[3]
+#define __PT_IP_REG csr_era
+
 #endif
 
 #if defined(bpf_target_defined)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant