memleax/1001-add-sw_64-support-not-upstream-modified.patch
herengui 6d61ec045c 添加龙芯和申威架构支持
Signed-off-by: herengui <herengui@kylinsec.com.cn>
(cherry picked from commit f9dd70d0d108c5cdd48ddb677ef291ccc65c07c2)
2023-09-12 09:01:07 +08:00

154 lines
3.7 KiB
Diff

From 2ffd47cc031947d85da9f2f11139b9bbadba5daa Mon Sep 17 00:00:00 2001
From: herengui <herengui@kylinsec.com.cn>
Date: Tue, 29 Aug 2023 13:53:15 +0800
Subject: [PATCH] add sw_64 support not upstream modified
Signed-off-by: herengui <herengui@kylinsec.com.cn>
---
configure | 7 +++++-
machines.h | 30 +++++++++++++++++++++++
ptrace_utils.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 100 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index 60fd170..a68210f 100755
--- a/configure
+++ b/configure
@@ -63,9 +63,14 @@ case `uname -m` in
machine="loongarch64"
CFLAGS="$CFLAGS -DMLX_LOONGARCH64"
;;
+'sw_64')
+ machine="sw_64"
+ CFLAGS="$CFLAGS -DMLX_SW_64"
+ LDFLAGS="$LDFLAGS -llzma"
+ ;;
*)
echo "Error: unsupported machine: `uname -m`."
- echo "Only x86, x86_64, arm, loongarch and aarch64 are supported."
+ echo "Only x86, x86_64, arm, loongarch, sw_64 and aarch64 are supported."
exit 2
;;
esac
diff --git a/machines.h b/machines.h
index 477f060..24d8ce0 100644
--- a/machines.h
+++ b/machines.h
@@ -117,6 +117,36 @@ static inline int is_breakpoint(pid_t pid, uintptr_t address)
return ptrace_get_data(pid, address) == 0x002a0000;
}
+#elif defined(MLX_SW_64)
+static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[30];
+}
+static inline uintptr_t call_return_value(registers_info_t *regs)
+{
+ return regs->regs[0];
+}
+static inline uintptr_t call_arg1(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[0];
+}
+static inline uintptr_t call_arg2(pid_t pid, registers_info_t *regs)
+{
+ return regs->regs[1];
+}
+static inline uintptr_t pc_unwind(pid_t pid, registers_info_t *regs)
+{
+ return regs->pc;
+}
+static inline void set_breakpoint(pid_t pid, uintptr_t address, uintptr_t code)
+{
+ ptrace_set_data(pid, address, 0x00000080);
+}
+static inline int is_breakpoint(pid_t pid, uintptr_t address)
+{
+ return ptrace_get_data(pid, address) == 0x00000080;
+}
+
#elif defined(MLX_ARMv7)
static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs)
{
diff --git a/ptrace_utils.h b/ptrace_utils.h
index 5fc1cd6..1a3b888 100644
--- a/ptrace_utils.h
+++ b/ptrace_utils.h
@@ -17,8 +17,71 @@
#include <elf.h>
#include <sys/uio.h>
- #ifdef MLX_ARMv7
+#ifdef MLX_SW_64
+#ifndef __ASSEMBLY__
+
+typedef uint64_t __u64;
+struct user_pt_regs {
+ __u64 regs[31];
+ __u64 pc;
+ __u64 pstate;
+};
+
+struct pt_regs {
+ union {
+ struct user_pt_regs user_regs;
+ struct {
+ unsigned long r0;
+ unsigned long r1;
+ unsigned long r2;
+ unsigned long r3;
+ unsigned long r4;
+ unsigned long r5;
+ unsigned long r6;
+ unsigned long r7;
+ unsigned long r8;
+ unsigned long r9;
+ unsigned long r10;
+ unsigned long r11;
+ unsigned long r12;
+ unsigned long r13;
+ unsigned long r14;
+ unsigned long r15;
+ unsigned long r16;
+ unsigned long r17;
+ unsigned long r18;
+ unsigned long r19;
+ unsigned long r20;
+ unsigned long r21;
+ unsigned long r22;
+ unsigned long r23;
+ unsigned long r24;
+ unsigned long r25;
+ unsigned long r26;
+ unsigned long r27;
+ unsigned long r28;
+ unsigned long gp;
+ unsigned long sp;
+ unsigned long pc;
+ unsigned long ps;
+ };
+ };
+ /* These are saved by HMcode: */
+ unsigned long hm_ps;
+ unsigned long hm_pc;
+ unsigned long hm_gp;
+ unsigned long hm_r16;
+ unsigned long hm_r17;
+ unsigned long hm_r18;
+};
+
+#endif
+#endif
+
+ #if (defined MLX_ARMv7)
typedef struct user_regs registers_info_t;
+ #elif (defined MLX_SW_64)
+typedef struct user_pt_regs registers_info_t;
#else
typedef struct user_regs_struct registers_info_t;
#endif
--
2.41.0