From 3546fafed9fb09e653f72f5f47034d0eba97e270 Mon Sep 17 00:00:00 2001 From: herengui Date: Tue, 16 May 2023 15:36:25 +0800 Subject: [PATCH] add loongarch64 support Signed-off-by: herengui --- configure | 6 +++++- machines.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 7c7280f..60fd170 100755 --- a/configure +++ b/configure @@ -59,9 +59,13 @@ case `uname -m` in machine="aarch64" CFLAGS="$CFLAGS -DMLX_AARCH64" ;; +'loongarch64') + machine="loongarch64" + CFLAGS="$CFLAGS -DMLX_LOONGARCH64" + ;; *) echo "Error: unsupported machine: `uname -m`." - echo "Only x86, x86_64, arm, and aarch64 are supported." + echo "Only x86, x86_64, arm, loongarch and aarch64 are supported." exit 2 ;; esac diff --git a/machines.h b/machines.h index cbbe69d..477f060 100644 --- a/machines.h +++ b/machines.h @@ -87,6 +87,36 @@ static inline int is_breakpoint(pid_t pid, uintptr_t address) return (ptrace_get_data(pid, address) & 0xFF) == 0xCC; } +#elif defined(MLX_LOONGARCH64) +static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs) +{ + return ptrace_get_data(pid, regs->regs[3]); +} +static inline uintptr_t call_return_value(registers_info_t *regs) +{ + return regs->regs[1]; +} +static inline uintptr_t call_arg1(pid_t pid, registers_info_t *regs) +{ + return regs->regs[6]; +} +static inline uintptr_t call_arg2(pid_t pid, registers_info_t *regs) +{ + return regs->regs[7]; +} +static inline uintptr_t pc_unwind(pid_t pid, registers_info_t *regs) +{ + return regs->csr_era;; +} +static inline void set_breakpoint(pid_t pid, uintptr_t address, uintptr_t code) +{ + ptrace_set_data(pid, address, (code & 0x002a0000)); +} +static inline int is_breakpoint(pid_t pid, uintptr_t address) +{ + return ptrace_get_data(pid, address) == 0x002a0000; +} + #elif defined(MLX_ARMv7) static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs) { -- 2.40.1