Move elf_core_copy_regs to elfload.c. Move HAVE_ELF_CORE_DUMP, ELF_NREGS, target_elf_gregset_t to target_elf.h. For now, duplicate the definitions of target_elf_greg_t and tswapreg.
Signed-off-by: Richard Henderson <richard.hender...@linaro.org> --- linux-user/i386/target_elf.h | 15 +++++++ linux-user/x86_64/target_elf.h | 15 +++++++ linux-user/elfload.c | 77 ---------------------------------- linux-user/i386/elfload.c | 24 +++++++++++ linux-user/x86_64/elfload.c | 34 +++++++++++++++ 5 files changed, 88 insertions(+), 77 deletions(-) diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h index 44dde1ac4a..eb286868e1 100644 --- a/linux-user/i386/target_elf.h +++ b/linux-user/i386/target_elf.h @@ -10,5 +10,20 @@ #define HAVE_ELF_HWCAP 1 #define HAVE_ELF_PLATFORM 1 +#define HAVE_ELF_CORE_DUMP 1 + +/* + * Note that ELF_NREG should be 19 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 + */ +#define ELF_NREG 17 + +typedef abi_ulong target_elf_greg_t; + +typedef struct target_elf_gregset_t { + target_elf_greg_t regs[ELF_NREG]; +} target_elf_gregset_t; #endif diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h index 498c3f7e4e..74a77d94cd 100644 --- a/linux-user/x86_64/target_elf.h +++ b/linux-user/x86_64/target_elf.h @@ -10,5 +10,20 @@ #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 + */ +#define ELF_NREG 27 + +typedef abi_ulong target_elf_greg_t; + +typedef struct target_elf_gregset_t { + target_elf_greg_t regs[ELF_NREG]; +} target_elf_gregset_t; #endif diff --git a/linux-user/elfload.c b/linux-user/elfload.c index af31a34594..e4f821f8c8 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -153,49 +153,6 @@ typedef abi_int target_pid_t; #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_X86_64 -#define ELF_NREG 27 -typedef struct target_elf_gregset_t { - target_elf_greg_t regs[ELF_NREG]; -} target_elf_gregset_t; - -/* - * 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 - */ -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); -} - #if ULONG_MAX > UINT32_MAX #define INIT_GUEST_COMMPAGE static bool init_guest_commpage(void) @@ -232,39 +189,6 @@ static bool init_guest_commpage(void) #define EXSTACK_DEFAULT true -#define ELF_NREG 17 -typedef struct target_elf_gregset_t { - target_elf_greg_t regs[ELF_NREG]; -} target_elf_gregset_t; - -/* - * Note that ELF_NREG should be 19 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 - */ -void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env) -{ - r->regs[0] = tswapreg(env->regs[R_EBX]); - r->regs[1] = tswapreg(env->regs[R_ECX]); - r->regs[2] = tswapreg(env->regs[R_EDX]); - r->regs[3] = tswapreg(env->regs[R_ESI]); - r->regs[4] = tswapreg(env->regs[R_EDI]); - r->regs[5] = tswapreg(env->regs[R_EBP]); - r->regs[6] = tswapreg(env->regs[R_EAX]); - r->regs[7] = tswapreg(env->segs[R_DS].selector & 0xffff); - r->regs[8] = tswapreg(env->segs[R_ES].selector & 0xffff); - r->regs[9] = tswapreg(env->segs[R_FS].selector & 0xffff); - r->regs[10] = tswapreg(env->segs[R_GS].selector & 0xffff); - r->regs[11] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax); - r->regs[12] = tswapreg(env->eip); - r->regs[13] = tswapreg(env->segs[R_CS].selector & 0xffff); - r->regs[14] = tswapreg(env->eflags); - r->regs[15] = tswapreg(env->regs[R_ESP]); - r->regs[16] = tswapreg(env->segs[R_SS].selector & 0xffff); -} - /* * i386 is the only target which supplies AT_SYSINFO for the vdso. * All others only supply AT_SYSINFO_EHDR. @@ -281,7 +205,6 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env) #define VDSO_HEADER "vdso.c.inc" -#define HAVE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 #endif /* TARGET_I386 */ diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c index ef3a6c35d2..279aeb8116 100644 --- a/linux-user/i386/elfload.c +++ b/linux-user/i386/elfload.c @@ -3,6 +3,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "loader.h" +#include "target_elf.h" const char *get_elf_cpu_model(uint32_t eflags) @@ -23,3 +24,26 @@ const char *get_elf_platform(CPUState *cs) family = MAX(MIN(family, 6), 3); return elf_platform[family - 3]; } + +#define tswapreg(ptr) tswapal(ptr) + +void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env) +{ + r->regs[0] = tswapreg(env->regs[R_EBX]); + r->regs[1] = tswapreg(env->regs[R_ECX]); + r->regs[2] = tswapreg(env->regs[R_EDX]); + r->regs[3] = tswapreg(env->regs[R_ESI]); + r->regs[4] = tswapreg(env->regs[R_EDI]); + r->regs[5] = tswapreg(env->regs[R_EBP]); + r->regs[6] = tswapreg(env->regs[R_EAX]); + r->regs[7] = tswapreg(env->segs[R_DS].selector & 0xffff); + r->regs[8] = tswapreg(env->segs[R_ES].selector & 0xffff); + r->regs[9] = tswapreg(env->segs[R_FS].selector & 0xffff); + r->regs[10] = tswapreg(env->segs[R_GS].selector & 0xffff); + r->regs[11] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax); + r->regs[12] = tswapreg(env->eip); + r->regs[13] = tswapreg(env->segs[R_CS].selector & 0xffff); + r->regs[14] = tswapreg(env->eflags); + r->regs[15] = tswapreg(env->regs[R_ESP]); + r->regs[16] = tswapreg(env->segs[R_SS].selector & 0xffff); +} diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c index 88541ea45e..76cf5c1509 100644 --- a/linux-user/x86_64/elfload.c +++ b/linux-user/x86_64/elfload.c @@ -3,6 +3,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "loader.h" +#include "target_elf.h" const char *get_elf_cpu_model(uint32_t eflags) @@ -19,3 +20,36 @@ 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); +} -- 2.43.0