linux-user: Move elf_core_copy_regs to xtensa/elfload.c

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.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2025-07-29 06:17:52 -10:00
parent 59b51b4e7c
commit 952916bb8f
3 changed files with 45 additions and 39 deletions

View file

@ -531,45 +531,6 @@ static bool init_guest_commpage(void)
#define ELF_CLASS ELFCLASS32
#define ELF_ARCH EM_XTENSA
/* See linux kernel: arch/xtensa/include/asm/elf.h. */
#define ELF_NREG 128
typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
} target_elf_gregset_t;
enum {
TARGET_REG_PC,
TARGET_REG_PS,
TARGET_REG_LBEG,
TARGET_REG_LEND,
TARGET_REG_LCOUNT,
TARGET_REG_SAR,
TARGET_REG_WINDOWSTART,
TARGET_REG_WINDOWBASE,
TARGET_REG_THREADPTR,
TARGET_REG_AR0 = 64,
};
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUXtensaState *env)
{
unsigned i;
r->regs[TARGET_REG_PC] = tswapreg(env->pc);
r->regs[TARGET_REG_PS] = tswapreg(env->sregs[PS] & ~PS_EXCM);
r->regs[TARGET_REG_LBEG] = tswapreg(env->sregs[LBEG]);
r->regs[TARGET_REG_LEND] = tswapreg(env->sregs[LEND]);
r->regs[TARGET_REG_LCOUNT] = tswapreg(env->sregs[LCOUNT]);
r->regs[TARGET_REG_SAR] = tswapreg(env->sregs[SAR]);
r->regs[TARGET_REG_WINDOWSTART] = tswapreg(env->sregs[WINDOW_START]);
r->regs[TARGET_REG_WINDOWBASE] = tswapreg(env->sregs[WINDOW_BASE]);
r->regs[TARGET_REG_THREADPTR] = tswapreg(env->uregs[THREADPTR]);
xtensa_sync_phys_from_window((CPUXtensaState *)env);
for (i = 0; i < env->config->nareg; ++i) {
r->regs[TARGET_REG_AR0 + i] = tswapreg(env->phys_regs[i]);
}
}
#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_XTENSA */

View file

@ -3,9 +3,44 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
{
return XTENSA_DEFAULT_CPU_MODEL;
}
#define tswapreg(ptr) tswapal(ptr)
enum {
TARGET_REG_PC,
TARGET_REG_PS,
TARGET_REG_LBEG,
TARGET_REG_LEND,
TARGET_REG_LCOUNT,
TARGET_REG_SAR,
TARGET_REG_WINDOWSTART,
TARGET_REG_WINDOWBASE,
TARGET_REG_THREADPTR,
TARGET_REG_AR0 = 64,
};
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUXtensaState *env)
{
unsigned i;
r->regs[TARGET_REG_PC] = tswapreg(env->pc);
r->regs[TARGET_REG_PS] = tswapreg(env->sregs[PS] & ~PS_EXCM);
r->regs[TARGET_REG_LBEG] = tswapreg(env->sregs[LBEG]);
r->regs[TARGET_REG_LEND] = tswapreg(env->sregs[LEND]);
r->regs[TARGET_REG_LCOUNT] = tswapreg(env->sregs[LCOUNT]);
r->regs[TARGET_REG_SAR] = tswapreg(env->sregs[SAR]);
r->regs[TARGET_REG_WINDOWSTART] = tswapreg(env->sregs[WINDOW_START]);
r->regs[TARGET_REG_WINDOWBASE] = tswapreg(env->sregs[WINDOW_BASE]);
r->regs[TARGET_REG_THREADPTR] = tswapreg(env->uregs[THREADPTR]);
xtensa_sync_phys_from_window((CPUXtensaState *)env);
for (i = 0; i < env->config->nareg; ++i) {
r->regs[TARGET_REG_AR0 + i] = tswapreg(env->phys_regs[i]);
}
}

View file

@ -8,4 +8,14 @@
#ifndef XTENSA_TARGET_ELF_H
#define XTENSA_TARGET_ELF_H
#define HAVE_ELF_CORE_DUMP 1
typedef abi_ulong target_elf_greg_t;
/* See linux kernel: arch/xtensa/include/asm/elf.h. */
#define ELF_NREG 128
typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
} target_elf_gregset_t;
#endif