The comment re ELF_NREG is incorrect or out-of-date. Make use of the fact that target_elf_gregset_t is a proper structure by using target_user_regs_struct.
Drop target_elf_greg_t and tswapreg. Signed-off-by: Richard Henderson <richard.hender...@linaro.org> --- linux-user/x86_64/target_elf.h | 14 +++----- linux-user/x86_64/target_ptrace.h | 2 +- linux-user/x86_64/elfload.c | 56 +++++++++++++++---------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h index 74a77d94cd..32a9eec431 100644 --- a/linux-user/x86_64/target_elf.h +++ b/linux-user/x86_64/target_elf.h @@ -8,22 +8,18 @@ #ifndef X86_64_TARGET_ELF_H #define X86_64_TARGET_ELF_H +#include "target_ptrace.h" + #define HAVE_ELF_HWCAP 1 #define HAVE_ELF_PLATFORM 1 #define HAVE_ELF_CORE_DUMP 1 /* - * Note that ELF_NREG should be 29 as there should be place for - * TRAPNO and ERR "registers" as well but linux doesn't dump those. - * - * See linux kernel: arch/x86/include/asm/elf.h + * See linux kernel: arch/x86/include/asm/elf.h, where + * elf_gregset_t is mapped to struct user_regs_struct via sizeof. */ -#define ELF_NREG 27 - -typedef abi_ulong target_elf_greg_t; - typedef struct target_elf_gregset_t { - target_elf_greg_t regs[ELF_NREG]; + struct target_user_regs_struct pt; } target_elf_gregset_t; #endif diff --git a/linux-user/x86_64/target_ptrace.h b/linux-user/x86_64/target_ptrace.h index ba162569a6..33527127cb 100644 --- a/linux-user/x86_64/target_ptrace.h +++ b/linux-user/x86_64/target_ptrace.h @@ -23,7 +23,7 @@ struct target_user_regs_struct { abi_ulong dx; abi_ulong si; abi_ulong di; - abi_ulong orig_rax; + abi_ulong orig_ax; abi_ulong ip; abi_ulong cs; abi_ulong flags; diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c index 76cf5c1509..18d632ec34 100644 --- a/linux-user/x86_64/elfload.c +++ b/linux-user/x86_64/elfload.c @@ -21,35 +21,33 @@ const char *get_elf_platform(CPUState *cs) return "x86_64"; } -#define tswapreg(ptr) tswapal(ptr) - void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env) { - r->regs[0] = tswapreg(env->regs[15]); - r->regs[1] = tswapreg(env->regs[14]); - r->regs[2] = tswapreg(env->regs[13]); - r->regs[3] = tswapreg(env->regs[12]); - r->regs[4] = tswapreg(env->regs[R_EBP]); - r->regs[5] = tswapreg(env->regs[R_EBX]); - r->regs[6] = tswapreg(env->regs[11]); - r->regs[7] = tswapreg(env->regs[10]); - r->regs[8] = tswapreg(env->regs[9]); - r->regs[9] = tswapreg(env->regs[8]); - r->regs[10] = tswapreg(env->regs[R_EAX]); - r->regs[11] = tswapreg(env->regs[R_ECX]); - r->regs[12] = tswapreg(env->regs[R_EDX]); - r->regs[13] = tswapreg(env->regs[R_ESI]); - r->regs[14] = tswapreg(env->regs[R_EDI]); - r->regs[15] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax); - r->regs[16] = tswapreg(env->eip); - r->regs[17] = tswapreg(env->segs[R_CS].selector & 0xffff); - r->regs[18] = tswapreg(env->eflags); - r->regs[19] = tswapreg(env->regs[R_ESP]); - r->regs[20] = tswapreg(env->segs[R_SS].selector & 0xffff); - r->regs[21] = tswapreg(env->segs[R_FS].selector & 0xffff); - r->regs[22] = tswapreg(env->segs[R_GS].selector & 0xffff); - r->regs[23] = tswapreg(env->segs[R_DS].selector & 0xffff); - r->regs[24] = tswapreg(env->segs[R_ES].selector & 0xffff); - r->regs[25] = tswapreg(env->segs[R_FS].selector & 0xffff); - r->regs[26] = tswapreg(env->segs[R_GS].selector & 0xffff); + r->pt.r15 = tswapal(env->regs[15]); + r->pt.r14 = tswapal(env->regs[14]); + r->pt.r13 = tswapal(env->regs[13]); + r->pt.r12 = tswapal(env->regs[12]); + r->pt.bp = tswapal(env->regs[R_EBP]); + r->pt.bx = tswapal(env->regs[R_EBX]); + r->pt.r11 = tswapal(env->regs[11]); + r->pt.r10 = tswapal(env->regs[10]); + r->pt.r9 = tswapal(env->regs[9]); + r->pt.r8 = tswapal(env->regs[8]); + r->pt.ax = tswapal(env->regs[R_EAX]); + r->pt.cx = tswapal(env->regs[R_ECX]); + r->pt.dx = tswapal(env->regs[R_EDX]); + r->pt.si = tswapal(env->regs[R_ESI]); + r->pt.di = tswapal(env->regs[R_EDI]); + r->pt.orig_ax = tswapal(get_task_state(env_cpu_const(env))->orig_ax); + r->pt.ip = tswapal(env->eip); + r->pt.cs = tswapal(env->segs[R_CS].selector & 0xffff); + r->pt.flags = tswapal(env->eflags); + r->pt.sp = tswapal(env->regs[R_ESP]); + r->pt.ss = tswapal(env->segs[R_SS].selector & 0xffff); + r->pt.fs_base = tswapal(env->segs[R_FS].selector & 0xffff); + r->pt.gs_base = tswapal(env->segs[R_GS].selector & 0xffff); + r->pt.ds = tswapal(env->segs[R_DS].selector & 0xffff); + r->pt.es = tswapal(env->segs[R_ES].selector & 0xffff); + r->pt.fs = tswapal(env->segs[R_FS].selector & 0xffff); + r->pt.gs = tswapal(env->segs[R_GS].selector & 0xffff); } -- 2.43.0