Make use of the fact that target_elf_gregset_t is a proper structure.
Note that the kernel's uses an array, and then it has a bunch of defines
to create symbolic offsets. Modulo some reserved fields, which we do
not implement here, this is the same layout as struct user_pt_regs.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/loongarch64/target_elf.h | 7 +++----
linux-user/loongarch64/elfload.c | 14 ++++----------
2 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index 90bca4499d..1f40419af2 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -6,16 +6,15 @@
#ifndef LOONGARCH_TARGET_ELF_H
#define LOONGARCH_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
/* See linux kernel: arch/loongarch/include/asm/elf.h */
-#define ELF_NREG 45
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ struct target_user_pt_regs pt;
} target_elf_gregset_t;
#endif
diff --git a/linux-user/loongarch64/elfload.c b/linux-user/loongarch64/elfload.c
index 832890de10..ce3bd0c607 100644
--- a/linux-user/loongarch64/elfload.c
+++ b/linux-user/loongarch64/elfload.c
@@ -65,20 +65,14 @@ const char *get_elf_platform(CPUState *cs)
#define tswapreg(ptr) tswapal(ptr)
-enum {
- TARGET_EF_R0 = 0,
- TARGET_EF_CSR_ERA = TARGET_EF_R0 + 33,
- TARGET_EF_CSR_BADV = TARGET_EF_R0 + 34,
-};
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPULoongArchState *env)
{
- r->regs[TARGET_EF_R0] = 0;
+ r->pt.regs[0] = 0;
for (int i = 1; i < ARRAY_SIZE(env->gpr); i++) {
- r->regs[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
+ r->pt.regs[i] = tswapreg(env->gpr[i]);
}
- r->regs[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
- r->regs[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
+ r->pt.csr_era = tswapreg(env->pc);
+ r->pt.csr_badv = tswapreg(env->CSR_BADV);
}
--
2.43.0