* [PATCH v3 01/87] linux-user/x86_64: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:17 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 02/87] linux-user/i386: " Richard Henderson
` (86 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
A structure typedef may be abstract, while an array typedef cannot.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 60 +++++++++++++++++++++++---------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index fce4c05674..ba205c5a19 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -154,7 +154,9 @@ typedef abi_int target_pid_t;
#define ELF_ARCH EM_X86_64
#define ELF_NREG 27
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+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
@@ -163,35 +165,35 @@ typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
*
* See linux kernel: arch/x86/include/asm/elf.h
*/
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
{
- (*regs)[0] = tswapreg(env->regs[15]);
- (*regs)[1] = tswapreg(env->regs[14]);
- (*regs)[2] = tswapreg(env->regs[13]);
- (*regs)[3] = tswapreg(env->regs[12]);
- (*regs)[4] = tswapreg(env->regs[R_EBP]);
- (*regs)[5] = tswapreg(env->regs[R_EBX]);
- (*regs)[6] = tswapreg(env->regs[11]);
- (*regs)[7] = tswapreg(env->regs[10]);
- (*regs)[8] = tswapreg(env->regs[9]);
- (*regs)[9] = tswapreg(env->regs[8]);
- (*regs)[10] = tswapreg(env->regs[R_EAX]);
- (*regs)[11] = tswapreg(env->regs[R_ECX]);
- (*regs)[12] = tswapreg(env->regs[R_EDX]);
- (*regs)[13] = tswapreg(env->regs[R_ESI]);
- (*regs)[14] = tswapreg(env->regs[R_EDI]);
- (*regs)[15] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
- (*regs)[16] = tswapreg(env->eip);
- (*regs)[17] = tswapreg(env->segs[R_CS].selector & 0xffff);
- (*regs)[18] = tswapreg(env->eflags);
- (*regs)[19] = tswapreg(env->regs[R_ESP]);
- (*regs)[20] = tswapreg(env->segs[R_SS].selector & 0xffff);
- (*regs)[21] = tswapreg(env->segs[R_FS].selector & 0xffff);
- (*regs)[22] = tswapreg(env->segs[R_GS].selector & 0xffff);
- (*regs)[23] = tswapreg(env->segs[R_DS].selector & 0xffff);
- (*regs)[24] = tswapreg(env->segs[R_ES].selector & 0xffff);
- (*regs)[25] = tswapreg(env->segs[R_FS].selector & 0xffff);
- (*regs)[26] = tswapreg(env->segs[R_GS].selector & 0xffff);
+ 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
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 02/87] linux-user/i386: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
2025-08-28 12:07 ` [PATCH v3 01/87] linux-user/x86_64: Convert target_elf_gregset_t to a struct Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:17 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 03/87] linux-user/arm: " Richard Henderson
` (85 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index ba205c5a19..e8a7f040ed 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -233,7 +233,9 @@ static bool init_guest_commpage(void)
#define EXSTACK_DEFAULT true
#define ELF_NREG 17
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+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
@@ -242,25 +244,25 @@ typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
*
* See linux kernel: arch/x86/include/asm/elf.h
*/
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
{
- (*regs)[0] = tswapreg(env->regs[R_EBX]);
- (*regs)[1] = tswapreg(env->regs[R_ECX]);
- (*regs)[2] = tswapreg(env->regs[R_EDX]);
- (*regs)[3] = tswapreg(env->regs[R_ESI]);
- (*regs)[4] = tswapreg(env->regs[R_EDI]);
- (*regs)[5] = tswapreg(env->regs[R_EBP]);
- (*regs)[6] = tswapreg(env->regs[R_EAX]);
- (*regs)[7] = tswapreg(env->segs[R_DS].selector & 0xffff);
- (*regs)[8] = tswapreg(env->segs[R_ES].selector & 0xffff);
- (*regs)[9] = tswapreg(env->segs[R_FS].selector & 0xffff);
- (*regs)[10] = tswapreg(env->segs[R_GS].selector & 0xffff);
- (*regs)[11] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
- (*regs)[12] = tswapreg(env->eip);
- (*regs)[13] = tswapreg(env->segs[R_CS].selector & 0xffff);
- (*regs)[14] = tswapreg(env->eflags);
- (*regs)[15] = tswapreg(env->regs[R_ESP]);
- (*regs)[16] = tswapreg(env->segs[R_SS].selector & 0xffff);
+ 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);
}
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 03/87] linux-user/arm: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
2025-08-28 12:07 ` [PATCH v3 01/87] linux-user/x86_64: Convert target_elf_gregset_t to a struct Richard Henderson
2025-08-28 12:07 ` [PATCH v3 02/87] linux-user/i386: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:18 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 04/87] linux-user/aarch64: " Richard Henderson
` (84 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
While we're at it, loop over the general registers
rather than open-code them.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 30 +++++++++---------------------
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index e8a7f040ed..0180f6063f 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -296,29 +296,17 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
#define EXSTACK_DEFAULT true
#define ELF_NREG 18
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUARMState *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
- (*regs)[0] = tswapreg(env->regs[0]);
- (*regs)[1] = tswapreg(env->regs[1]);
- (*regs)[2] = tswapreg(env->regs[2]);
- (*regs)[3] = tswapreg(env->regs[3]);
- (*regs)[4] = tswapreg(env->regs[4]);
- (*regs)[5] = tswapreg(env->regs[5]);
- (*regs)[6] = tswapreg(env->regs[6]);
- (*regs)[7] = tswapreg(env->regs[7]);
- (*regs)[8] = tswapreg(env->regs[8]);
- (*regs)[9] = tswapreg(env->regs[9]);
- (*regs)[10] = tswapreg(env->regs[10]);
- (*regs)[11] = tswapreg(env->regs[11]);
- (*regs)[12] = tswapreg(env->regs[12]);
- (*regs)[13] = tswapreg(env->regs[13]);
- (*regs)[14] = tswapreg(env->regs[14]);
- (*regs)[15] = tswapreg(env->regs[15]);
-
- (*regs)[16] = tswapreg(cpsr_read((CPUARMState *)env));
- (*regs)[17] = tswapreg(env->regs[0]); /* XXX */
+ for (int i = 0; i < 16; ++i) {
+ r->regs[i] = tswapreg(env->regs[i]);
+ }
+ r->regs[16] = tswapreg(cpsr_read((CPUARMState *)env));
+ r->regs[17] = tswapreg(env->regs[0]); /* XXX */
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 04/87] linux-user/aarch64: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (2 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 03/87] linux-user/arm: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:18 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 05/87] linux-user/ppc: " Richard Henderson
` (83 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0180f6063f..da57c6c2ce 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -384,18 +384,17 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define ELF_CLASS ELFCLASS64
#define ELF_NREG 34
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
- const CPUARMState *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
- int i;
-
- for (i = 0; i < 32; i++) {
- (*regs)[i] = tswapreg(env->xregs[i]);
+ for (int i = 0; i < 32; i++) {
+ r->regs[i] = tswapreg(env->xregs[i]);
}
- (*regs)[32] = tswapreg(env->pc);
- (*regs)[33] = tswapreg(pstate_read((CPUARMState *)env));
+ r->regs[32] = tswapreg(env->pc);
+ r->regs[33] = tswapreg(pstate_read((CPUARMState *)env));
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 05/87] linux-user/ppc: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (3 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 04/87] linux-user/aarch64: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:18 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 06/87] linux-user/loongarch64: " Richard Henderson
` (82 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index da57c6c2ce..0dd76937f9 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -470,25 +470,27 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
/* See linux kernel: arch/powerpc/include/asm/elf.h. */
#define ELF_NREG 48
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
{
int i;
target_ulong ccr = 0;
for (i = 0; i < ARRAY_SIZE(env->gpr); i++) {
- (*regs)[i] = tswapreg(env->gpr[i]);
+ r->regs[i] = tswapreg(env->gpr[i]);
}
- (*regs)[32] = tswapreg(env->nip);
- (*regs)[33] = tswapreg(env->msr);
- (*regs)[35] = tswapreg(env->ctr);
- (*regs)[36] = tswapreg(env->lr);
- (*regs)[37] = tswapreg(cpu_read_xer(env));
+ r->regs[32] = tswapreg(env->nip);
+ r->regs[33] = tswapreg(env->msr);
+ r->regs[35] = tswapreg(env->ctr);
+ r->regs[36] = tswapreg(env->lr);
+ r->regs[37] = tswapreg(cpu_read_xer(env));
ccr = ppc_get_cr(env);
- (*regs)[38] = tswapreg(ccr);
+ r->regs[38] = tswapreg(ccr);
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 06/87] linux-user/loongarch64: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (4 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 05/87] linux-user/ppc: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:18 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 07/87] linux-user/mips: " Richard Henderson
` (81 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0dd76937f9..1e59399afa 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -518,7 +518,9 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
/* See linux kernel: arch/loongarch/include/asm/elf.h */
#define ELF_NREG 45
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
enum {
TARGET_EF_R0 = 0,
@@ -526,19 +528,17 @@ enum {
TARGET_EF_CSR_BADV = TARGET_EF_R0 + 34,
};
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
+static void elf_core_copy_regs(target_elf_gregset_t *r,
const CPULoongArchState *env)
{
- int i;
+ r->regs[TARGET_EF_R0] = 0;
- (*regs)[TARGET_EF_R0] = 0;
-
- for (i = 1; i < ARRAY_SIZE(env->gpr); i++) {
- (*regs)[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
+ for (int i = 1; i < ARRAY_SIZE(env->gpr); i++) {
+ r->regs[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
}
- (*regs)[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
- (*regs)[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
+ r->regs[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
+ r->regs[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 07/87] linux-user/mips: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (5 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 06/87] linux-user/loongarch64: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:20 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 08/87] linux-user/microblaze: " Richard Henderson
` (80 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
While we're at it, merge the store of TARGET_EF_R0 into the
loop over all R0 registers.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1e59399afa..8fcdb0569b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -564,7 +564,9 @@ static void elf_core_copy_regs(target_elf_gregset_t *r,
/* See linux kernel: arch/mips/include/asm/elf.h. */
#define ELF_NREG 45
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
/* See linux kernel: arch/mips/include/asm/reg.h. */
enum {
@@ -584,27 +586,25 @@ enum {
};
/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMIPSState *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
{
int i;
- for (i = 0; i < TARGET_EF_R0; i++) {
- (*regs)[i] = 0;
+ for (i = 0; i <= TARGET_EF_R0; i++) {
+ r->regs[i] = 0;
}
- (*regs)[TARGET_EF_R0] = 0;
-
for (i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
- (*regs)[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]);
+ r->regs[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]);
}
- (*regs)[TARGET_EF_R26] = 0;
- (*regs)[TARGET_EF_R27] = 0;
- (*regs)[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]);
- (*regs)[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]);
- (*regs)[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC);
- (*regs)[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr);
- (*regs)[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status);
- (*regs)[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
+ r->regs[TARGET_EF_R26] = 0;
+ r->regs[TARGET_EF_R27] = 0;
+ r->regs[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]);
+ r->regs[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]);
+ r->regs[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC);
+ r->regs[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr);
+ r->regs[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status);
+ r->regs[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 08/87] linux-user/microblaze: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (6 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 07/87] linux-user/mips: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:20 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 09/87] linux-user/openrisc: " Richard Henderson
` (79 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
While we're at it, drop "pos++" and simply open-code indexes.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8fcdb0569b..40a5bcccab 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -623,23 +623,23 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
#define USE_ELF_CORE_DUMP
#define ELF_NREG 38
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMBState *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
{
- int i, pos = 0;
-
- for (i = 0; i < 32; i++) {
- (*regs)[pos++] = tswapreg(env->regs[i]);
+ for (int i = 0; i < 32; i++) {
+ r->regs[i] = tswapreg(env->regs[i]);
}
- (*regs)[pos++] = tswapreg(env->pc);
- (*regs)[pos++] = tswapreg(mb_cpu_read_msr(env));
- (*regs)[pos++] = 0;
- (*regs)[pos++] = tswapreg(env->ear);
- (*regs)[pos++] = 0;
- (*regs)[pos++] = tswapreg(env->esr);
+ r->regs[32] = tswapreg(env->pc);
+ r->regs[33] = tswapreg(mb_cpu_read_msr(env));
+ r->regs[34] = 0;
+ r->regs[35] = tswapreg(env->ear);
+ r->regs[36] = 0;
+ r->regs[37] = tswapreg(env->esr);
}
#endif /* TARGET_MICROBLAZE */
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 08/87] linux-user/microblaze: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 ` [PATCH v3 08/87] linux-user/microblaze: " Richard Henderson
@ 2025-08-28 14:20 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:20 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> While we're at it, drop "pos++" and simply open-code indexes.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/elfload.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 09/87] linux-user/openrisc: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (7 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 08/87] linux-user/microblaze: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:21 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 10/87] linux-user/sh4: " Richard Henderson
` (78 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 40a5bcccab..da034e5a76 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -655,18 +655,18 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
/* See linux kernel arch/openrisc/include/asm/elf.h. */
#define ELF_NREG 34 /* gprs and pc, sr */
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
+static void elf_core_copy_regs(target_elf_gregset_t *r,
const CPUOpenRISCState *env)
{
- int i;
-
- for (i = 0; i < 32; i++) {
- (*regs)[i] = tswapreg(cpu_get_gpr(env, i));
+ for (int i = 0; i < 32; i++) {
+ r->regs[i] = tswapreg(cpu_get_gpr(env, i));
}
- (*regs)[32] = tswapreg(env->pc);
- (*regs)[33] = tswapreg(cpu_get_sr(env));
+ r->regs[32] = tswapreg(env->pc);
+ r->regs[33] = tswapreg(cpu_get_sr(env));
}
#endif /* TARGET_OPENRISC */
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 10/87] linux-user/sh4: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (8 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 09/87] linux-user/openrisc: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:21 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 11/87] linux-user/m68k: " Richard Henderson
` (77 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index da034e5a76..cc9140bf32 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -678,7 +678,9 @@ static void elf_core_copy_regs(target_elf_gregset_t *r,
/* See linux kernel: arch/sh/include/asm/elf.h. */
#define ELF_NREG 23
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
/* See linux kernel: arch/sh/include/asm/ptrace.h. */
enum {
@@ -691,22 +693,19 @@ enum {
TARGET_REG_SYSCALL = 22
};
-static inline void elf_core_copy_regs(target_elf_gregset_t *regs,
- const CPUSH4State *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
{
- int i;
-
- for (i = 0; i < 16; i++) {
- (*regs)[i] = tswapreg(env->gregs[i]);
+ for (int i = 0; i < 16; i++) {
+ r->regs[i] = tswapreg(env->gregs[i]);
}
- (*regs)[TARGET_REG_PC] = tswapreg(env->pc);
- (*regs)[TARGET_REG_PR] = tswapreg(env->pr);
- (*regs)[TARGET_REG_SR] = tswapreg(env->sr);
- (*regs)[TARGET_REG_GBR] = tswapreg(env->gbr);
- (*regs)[TARGET_REG_MACH] = tswapreg(env->mach);
- (*regs)[TARGET_REG_MACL] = tswapreg(env->macl);
- (*regs)[TARGET_REG_SYSCALL] = 0; /* FIXME */
+ r->regs[TARGET_REG_PC] = tswapreg(env->pc);
+ r->regs[TARGET_REG_PR] = tswapreg(env->pr);
+ r->regs[TARGET_REG_SR] = tswapreg(env->sr);
+ r->regs[TARGET_REG_GBR] = tswapreg(env->gbr);
+ r->regs[TARGET_REG_MACH] = tswapreg(env->mach);
+ r->regs[TARGET_REG_MACL] = tswapreg(env->macl);
+ r->regs[TARGET_REG_SYSCALL] = 0; /* FIXME */
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 11/87] linux-user/m68k: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (9 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 10/87] linux-user/sh4: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:21 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 12/87] linux-user/s390x: " Richard Henderson
` (76 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 46 +++++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index cc9140bf32..63376fa1d6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -720,30 +720,32 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
/* See linux kernel: arch/m68k/include/asm/elf.h. */
#define ELF_NREG 20
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *env)
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
{
- (*regs)[0] = tswapreg(env->dregs[1]);
- (*regs)[1] = tswapreg(env->dregs[2]);
- (*regs)[2] = tswapreg(env->dregs[3]);
- (*regs)[3] = tswapreg(env->dregs[4]);
- (*regs)[4] = tswapreg(env->dregs[5]);
- (*regs)[5] = tswapreg(env->dregs[6]);
- (*regs)[6] = tswapreg(env->dregs[7]);
- (*regs)[7] = tswapreg(env->aregs[0]);
- (*regs)[8] = tswapreg(env->aregs[1]);
- (*regs)[9] = tswapreg(env->aregs[2]);
- (*regs)[10] = tswapreg(env->aregs[3]);
- (*regs)[11] = tswapreg(env->aregs[4]);
- (*regs)[12] = tswapreg(env->aregs[5]);
- (*regs)[13] = tswapreg(env->aregs[6]);
- (*regs)[14] = tswapreg(env->dregs[0]);
- (*regs)[15] = tswapreg(env->aregs[7]);
- (*regs)[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */
- (*regs)[17] = tswapreg(env->sr);
- (*regs)[18] = tswapreg(env->pc);
- (*regs)[19] = 0; /* FIXME: regs->format | regs->vector */
+ r->regs[0] = tswapreg(env->dregs[1]);
+ r->regs[1] = tswapreg(env->dregs[2]);
+ r->regs[2] = tswapreg(env->dregs[3]);
+ r->regs[3] = tswapreg(env->dregs[4]);
+ r->regs[4] = tswapreg(env->dregs[5]);
+ r->regs[5] = tswapreg(env->dregs[6]);
+ r->regs[6] = tswapreg(env->dregs[7]);
+ r->regs[7] = tswapreg(env->aregs[0]);
+ r->regs[8] = tswapreg(env->aregs[1]);
+ r->regs[9] = tswapreg(env->aregs[2]);
+ r->regs[10] = tswapreg(env->aregs[3]);
+ r->regs[11] = tswapreg(env->aregs[4]);
+ r->regs[12] = tswapreg(env->aregs[5]);
+ r->regs[13] = tswapreg(env->aregs[6]);
+ r->regs[14] = tswapreg(env->dregs[0]);
+ r->regs[15] = tswapreg(env->aregs[7]);
+ r->regs[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */
+ r->regs[17] = tswapreg(env->sr);
+ r->regs[18] = tswapreg(env->pc);
+ r->regs[19] = 0; /* FIXME: regs->format | regs->vector */
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 12/87] linux-user/s390x: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (10 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 11/87] linux-user/m68k: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:27 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 13/87] linux-user/xtensa: " Richard Henderson
` (75 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 63376fa1d6..98c17d32e6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -770,7 +770,9 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
/* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs). */
#define ELF_NREG 27
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
enum {
TARGET_REG_PSWM = 0,
@@ -780,22 +782,22 @@ enum {
TARGET_REG_ORIG_R2 = 26,
};
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
+static void elf_core_copy_regs(target_elf_gregset_t *r,
const CPUS390XState *env)
{
int i;
uint32_t *aregs;
- (*regs)[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
- (*regs)[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
+ r->regs[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
+ r->regs[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
for (i = 0; i < 16; i++) {
- (*regs)[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
+ r->regs[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
}
- aregs = (uint32_t *)&((*regs)[TARGET_REG_ARS]);
+ aregs = (uint32_t *)&(r->regs[TARGET_REG_ARS]);
for (i = 0; i < 16; i++) {
aregs[i] = tswap32(env->aregs[i]);
}
- (*regs)[TARGET_REG_ORIG_R2] = 0;
+ r->regs[TARGET_REG_ORIG_R2] = 0;
}
#define USE_ELF_CORE_DUMP
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 12/87] linux-user/s390x: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 ` [PATCH v3 12/87] linux-user/s390x: " Richard Henderson
@ 2025-08-28 14:27 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:27 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/elfload.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 63376fa1d6..98c17d32e6 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -770,7 +770,9 @@ static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
>
> /* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs). */
> #define ELF_NREG 27
> -typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
> +typedef struct target_elf_gregset_t {
> + target_elf_greg_t regs[ELF_NREG];
> +} target_elf_gregset_t;
>
> enum {
> TARGET_REG_PSWM = 0,
> @@ -780,22 +782,22 @@ enum {
> TARGET_REG_ORIG_R2 = 26,
> };
>
> -static void elf_core_copy_regs(target_elf_gregset_t *regs,
> +static void elf_core_copy_regs(target_elf_gregset_t *r,
> const CPUS390XState *env)
> {
> int i;
> uint32_t *aregs;
>
> - (*regs)[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
> - (*regs)[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
> + r->regs[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
> + r->regs[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
> for (i = 0; i < 16; i++) {
> - (*regs)[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
> + r->regs[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
> }
> - aregs = (uint32_t *)&((*regs)[TARGET_REG_ARS]);
> + aregs = (uint32_t *)&(r->regs[TARGET_REG_ARS]);
> for (i = 0; i < 16; i++) {
> aregs[i] = tswap32(env->aregs[i]);
> }
This code (which takes a pointer to an entry in an
array of 64-bit integers, casts it to a pointer to
uint32_t, and then stores to that) looks very suspicious
for not handing big-endian hosts correctly. But that's
a separate problem, so for this refactoring
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
> - (*regs)[TARGET_REG_ORIG_R2] = 0;
> + r->regs[TARGET_REG_ORIG_R2] = 0;
> }
>
> #define USE_ELF_CORE_DUMP
> --
> 2.43.0
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 13/87] linux-user/xtensa: Convert target_elf_gregset_t to a struct
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (11 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 12/87] linux-user/s390x: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:27 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 14/87] linux-user: Update comment for target_elf_gregset_t Richard Henderson
` (74 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 98c17d32e6..930701f08f 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -873,7 +873,9 @@ static bool init_guest_commpage(void)
/* See linux kernel: arch/xtensa/include/asm/elf.h. */
#define ELF_NREG 128
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
enum {
TARGET_REG_PC,
@@ -888,23 +890,23 @@ enum {
TARGET_REG_AR0 = 64,
};
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
+static void elf_core_copy_regs(target_elf_gregset_t *r,
const CPUXtensaState *env)
{
unsigned i;
- (*regs)[TARGET_REG_PC] = tswapreg(env->pc);
- (*regs)[TARGET_REG_PS] = tswapreg(env->sregs[PS] & ~PS_EXCM);
- (*regs)[TARGET_REG_LBEG] = tswapreg(env->sregs[LBEG]);
- (*regs)[TARGET_REG_LEND] = tswapreg(env->sregs[LEND]);
- (*regs)[TARGET_REG_LCOUNT] = tswapreg(env->sregs[LCOUNT]);
- (*regs)[TARGET_REG_SAR] = tswapreg(env->sregs[SAR]);
- (*regs)[TARGET_REG_WINDOWSTART] = tswapreg(env->sregs[WINDOW_START]);
- (*regs)[TARGET_REG_WINDOWBASE] = tswapreg(env->sregs[WINDOW_BASE]);
- (*regs)[TARGET_REG_THREADPTR] = tswapreg(env->uregs[THREADPTR]);
+ 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) {
- (*regs)[TARGET_REG_AR0 + i] = tswapreg(env->phys_regs[i]);
+ r->regs[TARGET_REG_AR0 + i] = tswapreg(env->phys_regs[i]);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 14/87] linux-user: Update comment for target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (12 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 13/87] linux-user/xtensa: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:27 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 15/87] linux-user: Declare elf_core_copy_regs in loader.h Richard Henderson
` (73 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
The only thing now used by generic core dump code is
target_elf_gregset_t; ELF_NREG and target_elf_greg_t
are now private to the implementation.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 930701f08f..74f88dfa68 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2859,12 +2859,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
*
* #define USE_ELF_CORE_DUMP
*
- * Next you define type of register set used for dumping. ELF specification
- * says that it needs to be array of elf_greg_t that has size of ELF_NREG.
- *
- * typedef <target_regtype> target_elf_greg_t;
- * #define ELF_NREG <number of registers>
- * typedef taret_elf_greg_t target_elf_gregset_t[ELF_NREG];
+ * Next you define type of register set used for dumping:
+ * typedef struct target_elf_gregset_t { ... } target_elf_gregset_t;
*
* Last step is to implement target specific function that copies registers
* from given cpu into just specified register set. Prototype is:
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 15/87] linux-user: Declare elf_core_copy_regs in loader.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (13 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 14/87] linux-user: Update comment for target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:28 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 16/87] linux-user: Rename USE_ELF_CORE_DUMP to HAVE_ELF_CORE_DUMP Richard Henderson
` (72 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Drop the static from all implementations.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/loader.h | 3 +++
linux-user/elfload.c | 33 ++++++++++++++-------------------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 6482c7c90c..8f4a7f69ac 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -106,4 +106,7 @@ const char *elf_hwcap2_str(uint32_t bit);
const char *get_elf_platform(CPUState *cs);
const char *get_elf_base_platform(CPUState *cs);
+struct target_elf_gregset_t;
+void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *);
+
#endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 74f88dfa68..5ed5b3c544 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -165,7 +165,7 @@ typedef struct target_elf_gregset_t {
*
* See linux kernel: arch/x86/include/asm/elf.h
*/
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
+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]);
@@ -244,7 +244,7 @@ typedef struct target_elf_gregset_t {
*
* See linux kernel: arch/x86/include/asm/elf.h
*/
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
+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]);
@@ -300,7 +300,7 @@ typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
for (int i = 0; i < 16; ++i) {
r->regs[i] = tswapreg(env->regs[i]);
@@ -388,7 +388,7 @@ typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
for (int i = 0; i < 32; i++) {
r->regs[i] = tswapreg(env->xregs[i]);
@@ -474,7 +474,7 @@ typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
{
int i;
target_ulong ccr = 0;
@@ -528,8 +528,7 @@ enum {
TARGET_EF_CSR_BADV = TARGET_EF_R0 + 34,
};
-static void elf_core_copy_regs(target_elf_gregset_t *r,
- const CPULoongArchState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPULoongArchState *env)
{
r->regs[TARGET_EF_R0] = 0;
@@ -586,7 +585,7 @@ enum {
};
/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
{
int i;
@@ -628,7 +627,7 @@ typedef struct target_elf_gregset_t {
} target_elf_gregset_t;
/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
{
for (int i = 0; i < 32; i++) {
r->regs[i] = tswapreg(env->regs[i]);
@@ -659,8 +658,7 @@ typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *r,
- const CPUOpenRISCState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUOpenRISCState *env)
{
for (int i = 0; i < 32; i++) {
r->regs[i] = tswapreg(cpu_get_gpr(env, i));
@@ -693,7 +691,7 @@ enum {
TARGET_REG_SYSCALL = 22
};
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
{
for (int i = 0; i < 16; i++) {
r->regs[i] = tswapreg(env->gregs[i]);
@@ -724,7 +722,7 @@ typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
} target_elf_gregset_t;
-static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
{
r->regs[0] = tswapreg(env->dregs[1]);
r->regs[1] = tswapreg(env->dregs[2]);
@@ -782,8 +780,7 @@ enum {
TARGET_REG_ORIG_R2 = 26,
};
-static void elf_core_copy_regs(target_elf_gregset_t *r,
- const CPUS390XState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUS390XState *env)
{
int i;
uint32_t *aregs;
@@ -890,8 +887,7 @@ enum {
TARGET_REG_AR0 = 64,
};
-static void elf_core_copy_regs(target_elf_gregset_t *r,
- const CPUXtensaState *env)
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUXtensaState *env)
{
unsigned i;
@@ -2865,8 +2861,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
* Last step is to implement target specific function that copies registers
* from given cpu into just specified register set. Prototype is:
*
- * static void elf_core_copy_regs(taret_elf_gregset_t *regs,
- * const CPUArchState *env);
+ * void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUArchState *env);
*
* Parameters:
* regs - copy register values into here (allocated and zeroed by caller)
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 16/87] linux-user: Rename USE_ELF_CORE_DUMP to HAVE_ELF_CORE_DUMP
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (14 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 15/87] linux-user: Declare elf_core_copy_regs in loader.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:28 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 17/87] linux-user: Move elf_core_copy_regs to {i386, x86_64}/elfload.c Richard Henderson
` (71 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
The other knobs in target_elf.h are all HAVE_*.
Rename this USE_ELF_CORE_DUMP to match.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5ed5b3c544..af31a34594 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -281,7 +281,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
#define VDSO_HEADER "vdso.c.inc"
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_I386 */
@@ -309,7 +309,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
r->regs[17] = tswapreg(env->regs[0]); /* XXX */
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
/* The commpage only exists for 32 bit kernels */
@@ -397,7 +397,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
r->regs[33] = tswapreg(pstate_read((CPUARMState *)env));
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#if TARGET_BIG_ENDIAN
@@ -493,7 +493,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
r->regs[38] = tswapreg(ccr);
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#ifndef TARGET_PPC64
@@ -540,7 +540,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPULoongArchState *env)
r->regs[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_LOONGARCH64 */
@@ -606,7 +606,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
r->regs[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_MIPS */
@@ -620,7 +620,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
#define ELF_EXEC_PAGESIZE 4096
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_NREG 38
typedef struct target_elf_gregset_t {
target_elf_greg_t regs[ELF_NREG];
@@ -649,7 +649,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
#define ELF_CLASS ELFCLASS32
#define ELF_DATA ELFDATA2MSB
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 8192
/* See linux kernel arch/openrisc/include/asm/elf.h. */
@@ -706,7 +706,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
r->regs[TARGET_REG_SYSCALL] = 0; /* FIXME */
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif
@@ -746,7 +746,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
r->regs[19] = 0; /* FIXME: regs->format | regs->vector */
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 8192
#endif
@@ -797,7 +797,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUS390XState *env)
r->regs[TARGET_REG_ORIG_R2] = 0;
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#define VDSO_HEADER "vdso.c.inc"
@@ -906,7 +906,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUXtensaState *env)
}
}
-#define USE_ELF_CORE_DUMP
+#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_XTENSA */
@@ -1115,9 +1115,9 @@ static void bswap_mips_abiflags(Mips_elf_abiflags_v0 *abiflags)
}
#endif
-#ifdef USE_ELF_CORE_DUMP
+#ifdef HAVE_ELF_CORE_DUMP
static int elf_core_dump(int, const CPUArchState *);
-#endif /* USE_ELF_CORE_DUMP */
+#endif /* HAVE_ELF_CORE_DUMP */
static void load_symbols(struct elfhdr *hdr, const ImageSource *src,
abi_ulong load_bias);
@@ -2827,14 +2827,14 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
g_free(elf_interpreter);
}
-#ifdef USE_ELF_CORE_DUMP
+#ifdef HAVE_ELF_CORE_DUMP
bprm->core_dump = &elf_core_dump;
#endif
return 0;
}
-#ifdef USE_ELF_CORE_DUMP
+#ifdef HAVE_ELF_CORE_DUMP
/*
* Definitions to generate Intel SVR4-like core files.
@@ -2850,10 +2850,10 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
* Core dump code is copied from linux kernel (fs/binfmt_elf.c).
*
* Porting ELF coredump for target is (quite) simple process. First you
- * define USE_ELF_CORE_DUMP in target ELF code (where init_thread() for
+ * define HAVE_ELF_CORE_DUMP in target ELF code (where init_thread() for
* the target resides):
*
- * #define USE_ELF_CORE_DUMP
+ * #define HAVE_ELF_CORE_DUMP
*
* Next you define type of register set used for dumping:
* typedef struct target_elf_gregset_t { ... } target_elf_gregset_t;
@@ -3392,4 +3392,4 @@ static int elf_core_dump(int signr, const CPUArchState *env)
}
return ret;
}
-#endif /* USE_ELF_CORE_DUMP */
+#endif /* HAVE_ELF_CORE_DUMP */
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 17/87] linux-user: Move elf_core_copy_regs to {i386, x86_64}/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (15 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 16/87] linux-user: Rename USE_ELF_CORE_DUMP to HAVE_ELF_CORE_DUMP Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:29 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 18/87] linux-user: Move elf_core_copy_regs to arm/elfload.c Richard Henderson
` (70 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@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
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 18/87] linux-user: Move elf_core_copy_regs to arm/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (16 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 17/87] linux-user: Move elf_core_copy_regs to {i386, x86_64}/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:30 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 19/87] linux-user: Move elf_core_copy_regs to aarch64/elfload.c Richard Henderson
` (69 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/arm/target_elf.h | 8 ++++++++
linux-user/arm/elfload.c | 12 ++++++++++++
linux-user/elfload.c | 15 ---------------
3 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 856ca41b16..94db3738e8 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -11,5 +11,13 @@
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+#define ELF_NREG 18
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
#endif
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index 7de1f13f4b..47fe16a1a6 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -4,6 +4,7 @@
#include "qemu.h"
#include "loader.h"
#include "target/arm/cpu-features.h"
+#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
@@ -199,3 +200,14 @@ const char *get_elf_platform(CPUState *cs)
#undef END
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
+{
+ for (int i = 0; i < 16; ++i) {
+ r->regs[i] = tswapreg(env->regs[i]);
+ }
+ r->regs[16] = tswapreg(cpsr_read((CPUARMState *)env));
+ r->regs[17] = tswapreg(env->regs[0]); /* XXX */
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index e4f821f8c8..72a291e51f 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -218,21 +218,6 @@ static bool init_guest_commpage(void)
#define ELF_CLASS ELFCLASS32
#define EXSTACK_DEFAULT true
-#define ELF_NREG 18
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
-{
- for (int i = 0; i < 16; ++i) {
- r->regs[i] = tswapreg(env->regs[i]);
- }
- r->regs[16] = tswapreg(cpsr_read((CPUARMState *)env));
- r->regs[17] = tswapreg(env->regs[0]); /* XXX */
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
/* The commpage only exists for 32 bit kernels */
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 19/87] linux-user: Move elf_core_copy_regs to aarch64/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (17 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 18/87] linux-user: Move elf_core_copy_regs to arm/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:30 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 20/87] linux-user: Move elf_core_copy_regs to ppc/elfload.c Richard Henderson
` (68 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/aarch64/target_elf.h | 8 ++++++++
linux-user/aarch64/elfload.c | 12 ++++++++++++
linux-user/elfload.c | 15 ---------------
3 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index dee79ce0c6..b0728a1008 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -11,5 +11,13 @@
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+#define ELF_NREG 34
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
#endif
diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
index 1030cb8094..00550f9fdf 100644
--- a/linux-user/aarch64/elfload.c
+++ b/linux-user/aarch64/elfload.c
@@ -4,6 +4,7 @@
#include "qemu.h"
#include "loader.h"
#include "target/arm/cpu-features.h"
+#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
@@ -347,3 +348,14 @@ const char *get_elf_platform(CPUState *cs)
{
return TARGET_BIG_ENDIAN ? "aarch64_be" : "aarch64";
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
+{
+ for (int i = 0; i < 32; i++) {
+ r->regs[i] = tswapreg(env->xregs[i]);
+ }
+ r->regs[32] = tswapreg(env->pc);
+ r->regs[33] = tswapreg(pstate_read((CPUARMState *)env));
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 72a291e51f..017346b82d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -291,21 +291,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define ELF_ARCH EM_AARCH64
#define ELF_CLASS ELFCLASS64
-#define ELF_NREG 34
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
-{
- for (int i = 0; i < 32; i++) {
- r->regs[i] = tswapreg(env->xregs[i]);
- }
- r->regs[32] = tswapreg(env->pc);
- r->regs[33] = tswapreg(pstate_read((CPUARMState *)env));
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#if TARGET_BIG_ENDIAN
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 20/87] linux-user: Move elf_core_copy_regs to ppc/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (18 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 19/87] linux-user: Move elf_core_copy_regs to aarch64/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:30 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 21/87] linux-user: Move elf_core_copy_regs to loongarch64/elfload.c Richard Henderson
` (67 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/ppc/target_elf.h | 9 +++++++++
linux-user/elfload.c | 26 --------------------------
linux-user/ppc/elfload.c | 22 ++++++++++++++++++++++
3 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/linux-user/ppc/target_elf.h b/linux-user/ppc/target_elf.h
index 4203a89d66..72615553ea 100644
--- a/linux-user/ppc/target_elf.h
+++ b/linux-user/ppc/target_elf.h
@@ -10,5 +10,14 @@
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+/* See linux kernel: arch/powerpc/include/asm/elf.h. */
+#define ELF_NREG 48
+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 017346b82d..d1d0a112fb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -361,32 +361,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \
} while (0)
-/* See linux kernel: arch/powerpc/include/asm/elf.h. */
-#define ELF_NREG 48
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
-{
- int i;
- target_ulong ccr = 0;
-
- for (i = 0; i < ARRAY_SIZE(env->gpr); i++) {
- r->regs[i] = tswapreg(env->gpr[i]);
- }
-
- r->regs[32] = tswapreg(env->nip);
- r->regs[33] = tswapreg(env->msr);
- r->regs[35] = tswapreg(env->ctr);
- r->regs[36] = tswapreg(env->lr);
- r->regs[37] = tswapreg(cpu_read_xer(env));
-
- ccr = ppc_get_cr(env);
- r->regs[38] = tswapreg(ccr);
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#ifndef TARGET_PPC64
diff --git a/linux-user/ppc/elfload.c b/linux-user/ppc/elfload.c
index a214675650..114e40a358 100644
--- a/linux-user/ppc/elfload.c
+++ b/linux-user/ppc/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)
@@ -129,3 +130,24 @@ abi_ulong get_elf_hwcap2(CPUState *cs)
return features;
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
+{
+ int i;
+ target_ulong ccr = 0;
+
+ for (i = 0; i < ARRAY_SIZE(env->gpr); i++) {
+ r->regs[i] = tswapreg(env->gpr[i]);
+ }
+
+ r->regs[32] = tswapreg(env->nip);
+ r->regs[33] = tswapreg(env->msr);
+ r->regs[35] = tswapreg(env->ctr);
+ r->regs[36] = tswapreg(env->lr);
+ r->regs[37] = tswapreg(cpu_read_xer(env));
+
+ ccr = ppc_get_cr(env);
+ r->regs[38] = tswapreg(ccr);
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 20/87] linux-user: Move elf_core_copy_regs to ppc/elfload.c
2025-08-28 12:07 ` [PATCH v3 20/87] linux-user: Move elf_core_copy_regs to ppc/elfload.c Richard Henderson
@ 2025-08-28 14:30 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:30 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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.henderson@linaro.org>
> ---
> linux-user/ppc/target_elf.h | 9 +++++++++
> linux-user/elfload.c | 26 --------------------------
> linux-user/ppc/elfload.c | 22 ++++++++++++++++++++++
> 3 files changed, 31 insertions(+), 26 deletions(-)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 21/87] linux-user: Move elf_core_copy_regs to loongarch64/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (19 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 20/87] linux-user: Move elf_core_copy_regs to ppc/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:31 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 22/87] linux-user: Move elf_core_copy_regs to mips/elfload.c Richard Henderson
` (66 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/loongarch64/target_elf.h | 9 +++++++++
linux-user/elfload.c | 25 -------------------------
linux-user/loongarch64/elfload.c | 21 +++++++++++++++++++++
3 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index eb17927325..90bca4499d 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -8,5 +8,14 @@
#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];
+} target_elf_gregset_t;
#endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index d1d0a112fb..4acd7b9ffe 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -383,31 +383,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define VDSO_HEADER "vdso.c.inc"
-/* 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];
-} target_elf_gregset_t;
-
-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;
-
- for (int i = 1; i < ARRAY_SIZE(env->gpr); i++) {
- r->regs[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
- }
-
- r->regs[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
- r->regs[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_LOONGARCH64 */
diff --git a/linux-user/loongarch64/elfload.c b/linux-user/loongarch64/elfload.c
index 911352840f..832890de10 100644
--- a/linux-user/loongarch64/elfload.c
+++ b/linux-user/loongarch64/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)
@@ -61,3 +62,23 @@ const char *get_elf_platform(CPUState *cs)
{
return "loongarch";
}
+
+#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;
+
+ for (int i = 1; i < ARRAY_SIZE(env->gpr); i++) {
+ r->regs[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
+ }
+
+ r->regs[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
+ r->regs[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 22/87] linux-user: Move elf_core_copy_regs to mips/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (20 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 21/87] linux-user: Move elf_core_copy_regs to loongarch64/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:31 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 23/87] linux-user: Move elf_core_copy_regs to microblaze/elfload.c Richard Henderson
` (65 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/mips/target_elf.h | 9 +++++++
linux-user/mips64/target_elf.h | 13 ++++++++++
linux-user/elfload.c | 46 ----------------------------------
linux-user/mips/elfload.c | 46 ++++++++++++++++++++++++++++++++++
4 files changed, 68 insertions(+), 46 deletions(-)
diff --git a/linux-user/mips/target_elf.h b/linux-user/mips/target_elf.h
index 08e699c085..f767767eaa 100644
--- a/linux-user/mips/target_elf.h
+++ b/linux-user/mips/target_elf.h
@@ -10,5 +10,14 @@
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_BASE_PLATFORM 1
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+/* See linux kernel: arch/mips/include/asm/elf.h. */
+#define ELF_NREG 45
+typedef struct target_elf_gregset_t {
+ target_elf_greg_t regs[ELF_NREG];
+} target_elf_gregset_t;
#endif
diff --git a/linux-user/mips64/target_elf.h b/linux-user/mips64/target_elf.h
index 24bb7fcd3f..046a165eef 100644
--- a/linux-user/mips64/target_elf.h
+++ b/linux-user/mips64/target_elf.h
@@ -10,5 +10,18 @@
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_BASE_PLATFORM 1
+#define HAVE_ELF_CORE_DUMP 1
+
+#ifdef TARGET_ABI_MIPSN32
+typedef abi_ullong target_elf_greg_t;
+#else
+typedef abi_ulong target_elf_greg_t;
+#endif
+
+/* See linux kernel: arch/mips/include/asm/elf.h. */
+#define ELF_NREG 45
+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 4acd7b9ffe..5a3a5cfc39 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -403,52 +403,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
#endif
-/* See linux kernel: arch/mips/include/asm/elf.h. */
-#define ELF_NREG 45
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-/* See linux kernel: arch/mips/include/asm/reg.h. */
-enum {
-#ifdef TARGET_MIPS64
- TARGET_EF_R0 = 0,
-#else
- TARGET_EF_R0 = 6,
-#endif
- TARGET_EF_R26 = TARGET_EF_R0 + 26,
- TARGET_EF_R27 = TARGET_EF_R0 + 27,
- TARGET_EF_LO = TARGET_EF_R0 + 32,
- TARGET_EF_HI = TARGET_EF_R0 + 33,
- TARGET_EF_CP0_EPC = TARGET_EF_R0 + 34,
- TARGET_EF_CP0_BADVADDR = TARGET_EF_R0 + 35,
- TARGET_EF_CP0_STATUS = TARGET_EF_R0 + 36,
- TARGET_EF_CP0_CAUSE = TARGET_EF_R0 + 37
-};
-
-/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
-{
- int i;
-
- for (i = 0; i <= TARGET_EF_R0; i++) {
- r->regs[i] = 0;
- }
- for (i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
- r->regs[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]);
- }
-
- r->regs[TARGET_EF_R26] = 0;
- r->regs[TARGET_EF_R27] = 0;
- r->regs[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]);
- r->regs[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]);
- r->regs[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC);
- r->regs[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr);
- r->regs[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status);
- r->regs[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif /* TARGET_MIPS */
diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c
index c353ccc1ad..6e884911af 100644
--- a/linux-user/mips/elfload.c
+++ b/linux-user/mips/elfload.c
@@ -4,6 +4,7 @@
#include "qemu.h"
#include "loader.h"
#include "elf.h"
+#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
@@ -122,3 +123,48 @@ const char *get_elf_base_platform(CPUState *cs)
}
#undef MATCH_PLATFORM_INSN
+
+#ifdef TARGET_ABI_MIPSN32
+#define tswapreg(ptr) tswap64(ptr)
+#else
+#define tswapreg(ptr) tswapal(ptr)
+#endif
+
+/* See linux kernel: arch/mips/include/asm/reg.h. */
+enum {
+#ifdef TARGET_MIPS64
+ TARGET_EF_R0 = 0,
+#else
+ TARGET_EF_R0 = 6,
+#endif
+ TARGET_EF_R26 = TARGET_EF_R0 + 26,
+ TARGET_EF_R27 = TARGET_EF_R0 + 27,
+ TARGET_EF_LO = TARGET_EF_R0 + 32,
+ TARGET_EF_HI = TARGET_EF_R0 + 33,
+ TARGET_EF_CP0_EPC = TARGET_EF_R0 + 34,
+ TARGET_EF_CP0_BADVADDR = TARGET_EF_R0 + 35,
+ TARGET_EF_CP0_STATUS = TARGET_EF_R0 + 36,
+ TARGET_EF_CP0_CAUSE = TARGET_EF_R0 + 37
+};
+
+/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
+{
+ int i;
+
+ for (i = 0; i <= TARGET_EF_R0; i++) {
+ r->regs[i] = 0;
+ }
+ for (i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
+ r->regs[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]);
+ }
+
+ r->regs[TARGET_EF_R26] = 0;
+ r->regs[TARGET_EF_R27] = 0;
+ r->regs[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]);
+ r->regs[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]);
+ r->regs[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC);
+ r->regs[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr);
+ r->regs[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status);
+ r->regs[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 22/87] linux-user: Move elf_core_copy_regs to mips/elfload.c
2025-08-28 12:07 ` [PATCH v3 22/87] linux-user: Move elf_core_copy_regs to mips/elfload.c Richard Henderson
@ 2025-08-28 14:31 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:31 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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.henderson@linaro.org>
> ---
> linux-user/mips/target_elf.h | 9 +++++++
> linux-user/mips64/target_elf.h | 13 ++++++++++
> linux-user/elfload.c | 46 ----------------------------------
> linux-user/mips/elfload.c | 46 ++++++++++++++++++++++++++++++++++
> 4 files changed, 68 insertions(+), 46 deletions(-)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 23/87] linux-user: Move elf_core_copy_regs to microblaze/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (21 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 22/87] linux-user: Move elf_core_copy_regs to mips/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:31 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 24/87] linux-user: Move elf_core_copy_regs to openrisc/elfload.c Richard Henderson
` (64 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/microblaze/target_elf.h | 9 +++++++++
linux-user/elfload.c | 21 ---------------------
linux-user/microblaze/elfload.c | 17 +++++++++++++++++
3 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index bfe2997fd2..cc5cc0477e 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -8,4 +8,13 @@
#ifndef MICROBLAZE_TARGET_ELF_H
#define MICROBLAZE_TARGET_ELF_H
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+#define ELF_NREG 38
+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 5a3a5cfc39..96ed6b6515 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -416,27 +416,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define ELF_EXEC_PAGESIZE 4096
-#define HAVE_ELF_CORE_DUMP
-#define ELF_NREG 38
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
-{
- for (int i = 0; i < 32; i++) {
- r->regs[i] = tswapreg(env->regs[i]);
- }
-
- r->regs[32] = tswapreg(env->pc);
- r->regs[33] = tswapreg(mb_cpu_read_msr(env));
- r->regs[34] = 0;
- r->regs[35] = tswapreg(env->ear);
- r->regs[36] = 0;
- r->regs[37] = tswapreg(env->esr);
-}
-
#endif /* TARGET_MICROBLAZE */
#ifdef TARGET_OPENRISC
diff --git a/linux-user/microblaze/elfload.c b/linux-user/microblaze/elfload.c
index b92442dfeb..89250dbd63 100644
--- a/linux-user/microblaze/elfload.c
+++ b/linux-user/microblaze/elfload.c
@@ -3,9 +3,26 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
+#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
{
return "any";
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
+{
+ for (int i = 0; i < 32; i++) {
+ r->regs[i] = tswapreg(env->regs[i]);
+ }
+
+ r->regs[32] = tswapreg(env->pc);
+ r->regs[33] = tswapreg(mb_cpu_read_msr(env));
+ r->regs[34] = 0;
+ r->regs[35] = tswapreg(env->ear);
+ r->regs[36] = 0;
+ r->regs[37] = tswapreg(env->esr);
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 23/87] linux-user: Move elf_core_copy_regs to microblaze/elfload.c
2025-08-28 12:07 ` [PATCH v3 23/87] linux-user: Move elf_core_copy_regs to microblaze/elfload.c Richard Henderson
@ 2025-08-28 14:31 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:31 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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.henderson@linaro.org>
> ---
> linux-user/microblaze/target_elf.h | 9 +++++++++
> linux-user/elfload.c | 21 ---------------------
> linux-user/microblaze/elfload.c | 17 +++++++++++++++++
> 3 files changed, 26 insertions(+), 21 deletions(-)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 24/87] linux-user: Move elf_core_copy_regs to openrisc/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (22 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 23/87] linux-user: Move elf_core_copy_regs to microblaze/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:32 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 25/87] linux-user: Move elf_core_copy_regs to sh4/elfload.c Richard Henderson
` (63 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/openrisc/target_elf.h | 10 ++++++++++
linux-user/elfload.c | 16 ----------------
linux-user/openrisc/elfload.c | 12 ++++++++++++
3 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/linux-user/openrisc/target_elf.h b/linux-user/openrisc/target_elf.h
index b34f2ff672..e97bdc11ed 100644
--- a/linux-user/openrisc/target_elf.h
+++ b/linux-user/openrisc/target_elf.h
@@ -8,4 +8,14 @@
#ifndef OPENRISC_TARGET_ELF_H
#define OPENRISC_TARGET_ELF_H
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+/* See linux kernel arch/openrisc/include/asm/elf.h. */
+#define ELF_NREG 34 /* gprs and pc, sr */
+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 96ed6b6515..8c3ef41312 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -424,24 +424,8 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define ELF_CLASS ELFCLASS32
#define ELF_DATA ELFDATA2MSB
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 8192
-/* See linux kernel arch/openrisc/include/asm/elf.h. */
-#define ELF_NREG 34 /* gprs and pc, sr */
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUOpenRISCState *env)
-{
- for (int i = 0; i < 32; i++) {
- r->regs[i] = tswapreg(cpu_get_gpr(env, i));
- }
- r->regs[32] = tswapreg(env->pc);
- r->regs[33] = tswapreg(cpu_get_sr(env));
-}
-
#endif /* TARGET_OPENRISC */
#ifdef TARGET_SH4
diff --git a/linux-user/openrisc/elfload.c b/linux-user/openrisc/elfload.c
index b92442dfeb..bb5ad96711 100644
--- a/linux-user/openrisc/elfload.c
+++ b/linux-user/openrisc/elfload.c
@@ -3,9 +3,21 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
+#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
{
return "any";
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUOpenRISCState *env)
+{
+ for (int i = 0; i < 32; i++) {
+ r->regs[i] = tswapreg(cpu_get_gpr(env, i));
+ }
+ r->regs[32] = tswapreg(env->pc);
+ r->regs[33] = tswapreg(cpu_get_sr(env));
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 24/87] linux-user: Move elf_core_copy_regs to openrisc/elfload.c
2025-08-28 12:07 ` [PATCH v3 24/87] linux-user: Move elf_core_copy_regs to openrisc/elfload.c Richard Henderson
@ 2025-08-28 14:32 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:32 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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.henderson@linaro.org>
> ---
> linux-user/openrisc/target_elf.h | 10 ++++++++++
> linux-user/elfload.c | 16 ----------------
> linux-user/openrisc/elfload.c | 12 ++++++++++++
> 3 files changed, 22 insertions(+), 16 deletions(-)
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 25/87] linux-user: Move elf_core_copy_regs to sh4/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (23 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 24/87] linux-user: Move elf_core_copy_regs to openrisc/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:32 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 26/87] linux-user: Move elf_core_copy_regs to m68k/elfload.c Richard Henderson
` (62 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/sh4/target_elf.h | 9 +++++++++
linux-user/elfload.c | 33 ---------------------------------
linux-user/sh4/elfload.c | 29 +++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 33 deletions(-)
diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h
index badd0f5371..f7443ddbac 100644
--- a/linux-user/sh4/target_elf.h
+++ b/linux-user/sh4/target_elf.h
@@ -9,5 +9,14 @@
#define SH4_TARGET_ELF_H
#define HAVE_ELF_HWCAP 1
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+/* See linux kernel: arch/sh/include/asm/elf.h. */
+#define ELF_NREG 23
+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 8c3ef41312..69532faddb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -433,39 +433,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define ELF_CLASS ELFCLASS32
#define ELF_ARCH EM_SH
-/* See linux kernel: arch/sh/include/asm/elf.h. */
-#define ELF_NREG 23
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-/* See linux kernel: arch/sh/include/asm/ptrace.h. */
-enum {
- TARGET_REG_PC = 16,
- TARGET_REG_PR = 17,
- TARGET_REG_SR = 18,
- TARGET_REG_GBR = 19,
- TARGET_REG_MACH = 20,
- TARGET_REG_MACL = 21,
- TARGET_REG_SYSCALL = 22
-};
-
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
-{
- for (int i = 0; i < 16; i++) {
- r->regs[i] = tswapreg(env->gregs[i]);
- }
-
- r->regs[TARGET_REG_PC] = tswapreg(env->pc);
- r->regs[TARGET_REG_PR] = tswapreg(env->pr);
- r->regs[TARGET_REG_SR] = tswapreg(env->sr);
- r->regs[TARGET_REG_GBR] = tswapreg(env->gbr);
- r->regs[TARGET_REG_MACH] = tswapreg(env->mach);
- r->regs[TARGET_REG_MACL] = tswapreg(env->macl);
- r->regs[TARGET_REG_SYSCALL] = 0; /* FIXME */
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#endif
diff --git a/linux-user/sh4/elfload.c b/linux-user/sh4/elfload.c
index 99ad4f6334..71cae9703e 100644
--- a/linux-user/sh4/elfload.c
+++ b/linux-user/sh4/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)
@@ -36,3 +37,31 @@ abi_ulong get_elf_hwcap(CPUState *cs)
return hwcap;
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+/* See linux kernel: arch/sh/include/asm/ptrace.h. */
+enum {
+ TARGET_REG_PC = 16,
+ TARGET_REG_PR = 17,
+ TARGET_REG_SR = 18,
+ TARGET_REG_GBR = 19,
+ TARGET_REG_MACH = 20,
+ TARGET_REG_MACL = 21,
+ TARGET_REG_SYSCALL = 22
+};
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
+{
+ for (int i = 0; i < 16; i++) {
+ r->regs[i] = tswapreg(env->gregs[i]);
+ }
+
+ r->regs[TARGET_REG_PC] = tswapreg(env->pc);
+ r->regs[TARGET_REG_PR] = tswapreg(env->pr);
+ r->regs[TARGET_REG_SR] = tswapreg(env->sr);
+ r->regs[TARGET_REG_GBR] = tswapreg(env->gbr);
+ r->regs[TARGET_REG_MACH] = tswapreg(env->mach);
+ r->regs[TARGET_REG_MACL] = tswapreg(env->macl);
+ r->regs[TARGET_REG_SYSCALL] = 0; /* FIXME */
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 25/87] linux-user: Move elf_core_copy_regs to sh4/elfload.c
2025-08-28 12:07 ` [PATCH v3 25/87] linux-user: Move elf_core_copy_regs to sh4/elfload.c Richard Henderson
@ 2025-08-28 14:32 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:32 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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.henderson@linaro.org>
> ---
> linux-user/sh4/target_elf.h | 9 +++++++++
> linux-user/elfload.c | 33 ---------------------------------
> linux-user/sh4/elfload.c | 29 +++++++++++++++++++++++++++++
> 3 files changed, 38 insertions(+), 33 deletions(-)
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 26/87] linux-user: Move elf_core_copy_regs to m68k/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (24 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 25/87] linux-user: Move elf_core_copy_regs to sh4/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:32 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 27/87] linux-user: Move elf_core_copy_regs to s390x/elfload.c Richard Henderson
` (61 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/m68k/target_elf.h | 10 ++++++++++
linux-user/elfload.c | 31 -------------------------------
linux-user/m68k/elfload.c | 27 +++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 31 deletions(-)
diff --git a/linux-user/m68k/target_elf.h b/linux-user/m68k/target_elf.h
index 62ff9d38d4..cd6908ab57 100644
--- a/linux-user/m68k/target_elf.h
+++ b/linux-user/m68k/target_elf.h
@@ -8,4 +8,14 @@
#ifndef M68K_TARGET_ELF_H
#define M68K_TARGET_ELF_H
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+/* See linux kernel: arch/m68k/include/asm/elf.h. */
+#define ELF_NREG 20
+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 69532faddb..e92c424faf 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -442,37 +442,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define ELF_CLASS ELFCLASS32
#define ELF_ARCH EM_68K
-/* See linux kernel: arch/m68k/include/asm/elf.h. */
-#define ELF_NREG 20
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
-{
- r->regs[0] = tswapreg(env->dregs[1]);
- r->regs[1] = tswapreg(env->dregs[2]);
- r->regs[2] = tswapreg(env->dregs[3]);
- r->regs[3] = tswapreg(env->dregs[4]);
- r->regs[4] = tswapreg(env->dregs[5]);
- r->regs[5] = tswapreg(env->dregs[6]);
- r->regs[6] = tswapreg(env->dregs[7]);
- r->regs[7] = tswapreg(env->aregs[0]);
- r->regs[8] = tswapreg(env->aregs[1]);
- r->regs[9] = tswapreg(env->aregs[2]);
- r->regs[10] = tswapreg(env->aregs[3]);
- r->regs[11] = tswapreg(env->aregs[4]);
- r->regs[12] = tswapreg(env->aregs[5]);
- r->regs[13] = tswapreg(env->aregs[6]);
- r->regs[14] = tswapreg(env->dregs[0]);
- r->regs[15] = tswapreg(env->aregs[7]);
- r->regs[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */
- r->regs[17] = tswapreg(env->sr);
- r->regs[18] = tswapreg(env->pc);
- r->regs[19] = 0; /* FIXME: regs->format | regs->vector */
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 8192
#endif
diff --git a/linux-user/m68k/elfload.c b/linux-user/m68k/elfload.c
index 561ac5b3b3..2970ff7dec 100644
--- a/linux-user/m68k/elfload.c
+++ b/linux-user/m68k/elfload.c
@@ -4,6 +4,7 @@
#include "qemu.h"
#include "loader.h"
#include "elf.h"
+#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
@@ -16,3 +17,29 @@ const char *get_elf_cpu_model(uint32_t eflags)
/* Coldfire */
return "any";
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
+{
+ r->regs[0] = tswapreg(env->dregs[1]);
+ r->regs[1] = tswapreg(env->dregs[2]);
+ r->regs[2] = tswapreg(env->dregs[3]);
+ r->regs[3] = tswapreg(env->dregs[4]);
+ r->regs[4] = tswapreg(env->dregs[5]);
+ r->regs[5] = tswapreg(env->dregs[6]);
+ r->regs[6] = tswapreg(env->dregs[7]);
+ r->regs[7] = tswapreg(env->aregs[0]);
+ r->regs[8] = tswapreg(env->aregs[1]);
+ r->regs[9] = tswapreg(env->aregs[2]);
+ r->regs[10] = tswapreg(env->aregs[3]);
+ r->regs[11] = tswapreg(env->aregs[4]);
+ r->regs[12] = tswapreg(env->aregs[5]);
+ r->regs[13] = tswapreg(env->aregs[6]);
+ r->regs[14] = tswapreg(env->dregs[0]);
+ r->regs[15] = tswapreg(env->aregs[7]);
+ r->regs[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */
+ r->regs[17] = tswapreg(env->sr);
+ r->regs[18] = tswapreg(env->pc);
+ r->regs[19] = 0; /* FIXME: regs->format | regs->vector */
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 26/87] linux-user: Move elf_core_copy_regs to m68k/elfload.c
2025-08-28 12:07 ` [PATCH v3 26/87] linux-user: Move elf_core_copy_regs to m68k/elfload.c Richard Henderson
@ 2025-08-28 14:32 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:32 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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.henderson@linaro.org>
> ---
> linux-user/m68k/target_elf.h | 10 ++++++++++
> linux-user/elfload.c | 31 -------------------------------
> linux-user/m68k/elfload.c | 27 +++++++++++++++++++++++++++
> 3 files changed, 37 insertions(+), 31 deletions(-)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 27/87] linux-user: Move elf_core_copy_regs to s390x/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (25 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 26/87] linux-user: Move elf_core_copy_regs to m68k/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:33 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 28/87] linux-user: Move elf_core_copy_regs to xtensa/elfload.c Richard Henderson
` (60 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/s390x/target_elf.h | 9 +++++++++
linux-user/elfload.c | 32 --------------------------------
linux-user/s390x/elfload.c | 28 ++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 32 deletions(-)
diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
index cebace949a..b7d863ee66 100644
--- a/linux-user/s390x/target_elf.h
+++ b/linux-user/s390x/target_elf.h
@@ -9,5 +9,14 @@
#define S390X_TARGET_ELF_H
#define HAVE_ELF_HWCAP 1
+#define HAVE_ELF_CORE_DUMP 1
+
+typedef abi_ulong target_elf_greg_t;
+
+/* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs). */
+#define ELF_NREG 27
+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 e92c424faf..7c783b74d4 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -461,38 +461,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define ELF_DATA ELFDATA2MSB
#define ELF_ARCH EM_S390
-/* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs). */
-#define ELF_NREG 27
-typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
-} target_elf_gregset_t;
-
-enum {
- TARGET_REG_PSWM = 0,
- TARGET_REG_PSWA = 1,
- TARGET_REG_GPRS = 2,
- TARGET_REG_ARS = 18,
- TARGET_REG_ORIG_R2 = 26,
-};
-
-void elf_core_copy_regs(target_elf_gregset_t *r, const CPUS390XState *env)
-{
- int i;
- uint32_t *aregs;
-
- r->regs[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
- r->regs[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
- for (i = 0; i < 16; i++) {
- r->regs[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
- }
- aregs = (uint32_t *)&(r->regs[TARGET_REG_ARS]);
- for (i = 0; i < 16; i++) {
- aregs[i] = tswap32(env->aregs[i]);
- }
- r->regs[TARGET_REG_ORIG_R2] = 0;
-}
-
-#define HAVE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
#define VDSO_HEADER "vdso.c.inc"
diff --git a/linux-user/s390x/elfload.c b/linux-user/s390x/elfload.c
index 79ceaba51d..4113273b72 100644
--- a/linux-user/s390x/elfload.c
+++ b/linux-user/s390x/elfload.c
@@ -4,6 +4,7 @@
#include "qemu.h"
#include "loader.h"
#include "elf.h"
+#include "target_elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
@@ -66,3 +67,30 @@ const char *elf_hwcap_str(uint32_t bit)
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
}
+
+#define tswapreg(ptr) tswapal(ptr)
+
+enum {
+ TARGET_REG_PSWM = 0,
+ TARGET_REG_PSWA = 1,
+ TARGET_REG_GPRS = 2,
+ TARGET_REG_ARS = 18,
+ TARGET_REG_ORIG_R2 = 26,
+};
+
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPUS390XState *env)
+{
+ int i;
+ uint32_t *aregs;
+
+ r->regs[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
+ r->regs[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
+ for (i = 0; i < 16; i++) {
+ r->regs[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
+ }
+ aregs = (uint32_t *)&(r->regs[TARGET_REG_ARS]);
+ for (i = 0; i < 16; i++) {
+ aregs[i] = tswap32(env->aregs[i]);
+ }
+ r->regs[TARGET_REG_ORIG_R2] = 0;
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 28/87] linux-user: Move elf_core_copy_regs to xtensa/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (26 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 27/87] linux-user: Move elf_core_copy_regs to s390x/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:33 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 29/87] linux-user: Remove target_elf_greg_t, tswapreg from elfload.c Richard Henderson
` (59 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@linaro.org>
---
linux-user/xtensa/target_elf.h | 10 +++++++++
linux-user/elfload.c | 39 ----------------------------------
linux-user/xtensa/elfload.c | 35 ++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/linux-user/xtensa/target_elf.h b/linux-user/xtensa/target_elf.h
index 2c55c22e14..43e241aac1 100644
--- a/linux-user/xtensa/target_elf.h
+++ b/linux-user/xtensa/target_elf.h
@@ -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
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7c783b74d4..5cdbdc20d9 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -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 */
diff --git a/linux-user/xtensa/elfload.c b/linux-user/xtensa/elfload.c
index e35ba69a10..49e709a094 100644
--- a/linux-user/xtensa/elfload.c
+++ b/linux-user/xtensa/elfload.c
@@ -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]);
+ }
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 29/87] linux-user: Remove target_elf_greg_t, tswapreg from elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (27 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 28/87] linux-user: Move elf_core_copy_regs to xtensa/elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:33 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h Richard Henderson
` (58 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
These are no longer used within the generic file.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5cdbdc20d9..07d83c674d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,14 +130,6 @@ int info_is_fdpic(struct image_info *info)
#define ELF_DATA ELFDATA2LSB
#endif
-#ifdef TARGET_ABI_MIPSN32
-typedef abi_ullong target_elf_greg_t;
-#define tswapreg(ptr) tswap64(ptr)
-#else
-typedef abi_ulong target_elf_greg_t;
-#define tswapreg(ptr) tswapal(ptr)
-#endif
-
#ifdef USE_UID16
typedef abi_ushort target_uid_t;
typedef abi_ushort target_gid_t;
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (28 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 29/87] linux-user: Remove target_elf_greg_t, tswapreg from elfload.c Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:42 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 31/87] linux-user/i386: Expand target_elf_gregset_t Richard Henderson
` (57 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move the target_pt_regs structure from target_syscall.h.
Rename the bits according to user_regs_struct, which is
what is actually used by ELF_CORE_COPY_REGS; the layout
of the two structure definitions is identical.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/i386/target_ptrace.h | 31 +++++++++++++++++++++++++++++++
linux-user/i386/target_syscall.h | 18 ------------------
2 files changed, 31 insertions(+), 18 deletions(-)
create mode 100644 linux-user/i386/target_ptrace.h
diff --git a/linux-user/i386/target_ptrace.h b/linux-user/i386/target_ptrace.h
new file mode 100644
index 0000000000..51edb637af
--- /dev/null
+++ b/linux-user/i386/target_ptrace.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef I386_TARGET_PTRACE_H
+#define I386_TARGET_PTRACE_H
+
+/*
+ * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
+ * arch/x86/include/asm/user_32.h (struct user_regs_struct).
+ * The structure layouts are identical; the user_regs_struct names are better.
+ */
+struct target_pt_regs {
+ abi_ulong bx;
+ abi_ulong cx;
+ abi_ulong dx;
+ abi_ulong si;
+ abi_ulong di;
+ abi_ulong bp;
+ abi_ulong ax;
+ abi_ulong ds;
+ abi_ulong es;
+ abi_ulong fs;
+ abi_ulong gs;
+ abi_ulong orig_ax;
+ abi_ulong ip;
+ abi_ulong cs;
+ abi_ulong flags;
+ abi_ulong sp;
+ abi_ulong ss;
+};
+
+#endif /* I386_TARGET_PTRACE_H */
diff --git a/linux-user/i386/target_syscall.h b/linux-user/i386/target_syscall.h
index aaade06b13..c214a909a6 100644
--- a/linux-user/i386/target_syscall.h
+++ b/linux-user/i386/target_syscall.h
@@ -5,24 +5,6 @@
#define __USER_CS (0x23)
#define __USER_DS (0x2B)
-struct target_pt_regs {
- long ebx;
- long ecx;
- long edx;
- long esi;
- long edi;
- long ebp;
- long eax;
- int xds;
- int xes;
- long orig_eax;
- long eip;
- int xcs;
- long eflags;
- long esp;
- int xss;
-};
-
/* ioctls */
#define TARGET_LDT_ENTRIES 8192
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
2025-08-28 12:07 ` [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h Richard Henderson
@ 2025-08-28 14:42 ` Peter Maydell
2025-08-28 22:14 ` Richard Henderson
0 siblings, 1 reply; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:42 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the target_pt_regs structure from target_syscall.h.
> Rename the bits according to user_regs_struct, which is
> what is actually used by ELF_CORE_COPY_REGS; the layout
> of the two structure definitions is identical.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/i386/target_ptrace.h | 31 +++++++++++++++++++++++++++++++
> linux-user/i386/target_syscall.h | 18 ------------------
> 2 files changed, 31 insertions(+), 18 deletions(-)
> create mode 100644 linux-user/i386/target_ptrace.h
>
> diff --git a/linux-user/i386/target_ptrace.h b/linux-user/i386/target_ptrace.h
> new file mode 100644
> index 0000000000..51edb637af
> --- /dev/null
> +++ b/linux-user/i386/target_ptrace.h
> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +
> +#ifndef I386_TARGET_PTRACE_H
> +#define I386_TARGET_PTRACE_H
> +
> +/*
> + * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
> + * arch/x86/include/asm/user_32.h (struct user_regs_struct).
> + * The structure layouts are identical; the user_regs_struct names are better.
> + */
Why do you think the user_regs_struct names are better?
"bx" suggests a 16-bit register, but these are 32-bit, right?
> +struct target_pt_regs {
> + abi_ulong bx;
> + abi_ulong cx;
> + abi_ulong dx;
> + abi_ulong si;
> + abi_ulong di;
> + abi_ulong bp;
> + abi_ulong ax;
> + abi_ulong ds;
> + abi_ulong es;
> + abi_ulong fs;
> + abi_ulong gs;
> + abi_ulong orig_ax;
> + abi_ulong ip;
> + abi_ulong cs;
> + abi_ulong flags;
> + abi_ulong sp;
> + abi_ulong ss;
> +};
> +
> +#endif /* I386_TARGET_PTRACE_H */
> diff --git a/linux-user/i386/target_syscall.h b/linux-user/i386/target_syscall.h
> index aaade06b13..c214a909a6 100644
> --- a/linux-user/i386/target_syscall.h
> +++ b/linux-user/i386/target_syscall.h
> @@ -5,24 +5,6 @@
> #define __USER_CS (0x23)
> #define __USER_DS (0x2B)
>
> -struct target_pt_regs {
> - long ebx;
> - long ecx;
> - long edx;
> - long esi;
> - long edi;
> - long ebp;
> - long eax;
> - int xds;
> - int xes;
> - long orig_eax;
> - long eip;
> - int xcs;
> - long eflags;
> - long esp;
> - int xss;
> -};
Commit message should say something about why we're changing
the types (though clearly here the target-specific types are
more sensible than the host-specific ones).
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread* Re: [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
2025-08-28 14:42 ` Peter Maydell
@ 2025-08-28 22:14 ` Richard Henderson
2025-08-29 8:31 ` Peter Maydell
0 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 22:14 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel
On 8/29/25 00:42, Peter Maydell wrote:
> On Thu, 28 Aug 2025 at 13:09, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>> +/*
>> + * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
>> + * arch/x86/include/asm/user_32.h (struct user_regs_struct).
>> + * The structure layouts are identical; the user_regs_struct names are better.
>> + */
>
> Why do you think the user_regs_struct names are better?
> "bx" suggests a 16-bit register, but these are 32-bit, right?
Mostly I really don't like xds etc.
> Commit message should say something about why we're changing
> the types (though clearly here the target-specific types are
> more sensible than the host-specific ones).
Oops, yes. There are quite a lot of error across the various target_pt_regs structures
that we never caught because they were never used.
r~
^ permalink raw reply [flat|nested] 152+ messages in thread
* Re: [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
2025-08-28 22:14 ` Richard Henderson
@ 2025-08-29 8:31 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-29 8:31 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 23:14, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 8/29/25 00:42, Peter Maydell wrote:
> > On Thu, 28 Aug 2025 at 13:09, Richard Henderson
> > <richard.henderson@linaro.org> wrote:
> >> +/*
> >> + * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
> >> + * arch/x86/include/asm/user_32.h (struct user_regs_struct).
> >> + * The structure layouts are identical; the user_regs_struct names are better.
> >> + */
> >
> > Why do you think the user_regs_struct names are better?
> > "bx" suggests a 16-bit register, but these are 32-bit, right?
>
> Mostly I really don't like xds etc.
>
> > Commit message should say something about why we're changing
> > the types (though clearly here the target-specific types are
> > more sensible than the host-specific ones).
>
> Oops, yes. There are quite a lot of error across the various target_pt_regs structures
> that we never caught because they were never used.
With that,
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 31/87] linux-user/i386: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (29 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:43 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 32/87] linux-user/x86_64: Create target_ptrace.h Richard Henderson
` (56 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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_pt_regs.
Drop target_elf_greg_t and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/i386/target_elf.h | 15 ++++++---------
linux-user/i386/elfload.c | 36 +++++++++++++++++-------------------
2 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index eb286868e1..da1e0a09bc 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -8,22 +8,19 @@
#ifndef I386_TARGET_ELF_H
#define I386_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 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
+ * See linux kernel: arch/x86/include/asm/elf.h, where elf_gregset_t
+ * is mapped to struct user_regs_struct via sizeof, and that the
+ * definitions of user_regs_struct and pt_regs is identical.
*/
-#define ELF_NREG 17
-
-typedef abi_ulong target_elf_greg_t;
-
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ struct target_pt_regs pt;
} target_elf_gregset_t;
#endif
diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
index 279aeb8116..26b12001a3 100644
--- a/linux-user/i386/elfload.c
+++ b/linux-user/i386/elfload.c
@@ -25,25 +25,23 @@ const char *get_elf_platform(CPUState *cs)
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);
+ r->pt.bx = tswapal(env->regs[R_EBX]);
+ 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.bp = tswapal(env->regs[R_EBP]);
+ r->pt.ax = tswapal(env->regs[R_EAX]);
+ 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);
+ 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);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 31/87] linux-user/i386: Expand target_elf_gregset_t
2025-08-28 12:07 ` [PATCH v3 31/87] linux-user/i386: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 14:43 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:43 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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_pt_regs.
>
> Drop target_elf_greg_t and tswapreg.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/i386/target_elf.h | 15 ++++++---------
> linux-user/i386/elfload.c | 36 +++++++++++++++++-------------------
> 2 files changed, 23 insertions(+), 28 deletions(-)
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 32/87] linux-user/x86_64: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (30 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 31/87] linux-user/i386: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:45 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 33/87] linux-user/x86_64: Expand target_elf_gregset_t Richard Henderson
` (55 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Remove the target_pt_regs structure from target_syscall.h.
Add target_user_regs_struct to target_ptrace.h, which matches
what is actually used on x86_64.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/x86_64/target_ptrace.h | 40 ++++++++++++++++++++++++++++++
linux-user/x86_64/target_syscall.h | 28 ---------------------
2 files changed, 40 insertions(+), 28 deletions(-)
create mode 100644 linux-user/x86_64/target_ptrace.h
diff --git a/linux-user/x86_64/target_ptrace.h b/linux-user/x86_64/target_ptrace.h
new file mode 100644
index 0000000000..ba162569a6
--- /dev/null
+++ b/linux-user/x86_64/target_ptrace.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef X86_64_TARGET_PTRACE_H
+#define X86_64_TARGET_PTRACE_H
+
+/*
+ * The struct pt_regs in arch/x86/include/uapi/asm/ptrace.h has missing
+ * register values and is not used. See arch/x86/include/asm/user_64.h.
+ */
+struct target_user_regs_struct {
+ abi_ulong r15;
+ abi_ulong r14;
+ abi_ulong r13;
+ abi_ulong r12;
+ abi_ulong bp;
+ abi_ulong bx;
+ abi_ulong r11;
+ abi_ulong r10;
+ abi_ulong r9;
+ abi_ulong r8;
+ abi_ulong ax;
+ abi_ulong cx;
+ abi_ulong dx;
+ abi_ulong si;
+ abi_ulong di;
+ abi_ulong orig_rax;
+ abi_ulong ip;
+ abi_ulong cs;
+ abi_ulong flags;
+ abi_ulong sp;
+ abi_ulong ss;
+ abi_ulong fs_base;
+ abi_ulong gs_base;
+ abi_ulong ds;
+ abi_ulong es;
+ abi_ulong fs;
+ abi_ulong gs;
+};
+
+#endif /* X86_64_TARGET_PTRACE_H */
diff --git a/linux-user/x86_64/target_syscall.h b/linux-user/x86_64/target_syscall.h
index fb558345d3..68f55f8e7b 100644
--- a/linux-user/x86_64/target_syscall.h
+++ b/linux-user/x86_64/target_syscall.h
@@ -4,34 +4,6 @@
#define __USER_CS (0x33)
#define __USER_DS (0x2B)
-struct target_pt_regs {
- abi_ulong r15;
- abi_ulong r14;
- abi_ulong r13;
- abi_ulong r12;
- abi_ulong rbp;
- abi_ulong rbx;
-/* arguments: non interrupts/non tracing syscalls only save up to here */
- abi_ulong r11;
- abi_ulong r10;
- abi_ulong r9;
- abi_ulong r8;
- abi_ulong rax;
- abi_ulong rcx;
- abi_ulong rdx;
- abi_ulong rsi;
- abi_ulong rdi;
- abi_ulong orig_rax;
-/* end of arguments */
-/* cpu exception frame or undefined */
- abi_ulong rip;
- abi_ulong cs;
- abi_ulong eflags;
- abi_ulong rsp;
- abi_ulong ss;
-/* top of stack page */
-};
-
/* Maximum number of LDT entries supported. */
#define TARGET_LDT_ENTRIES 8192
/* The size of each LDT entry. */
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 33/87] linux-user/x86_64: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (31 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 32/87] linux-user/x86_64: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:45 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 34/87] linux-user/x86_64: Fix dump of fs_base, gs_base Richard Henderson
` (54 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.henderson@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
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 34/87] linux-user/x86_64: Fix dump of fs_base, gs_base
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (32 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 33/87] linux-user/x86_64: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:45 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 35/87] linux-user/aarch64: Create target_ptrace.h Richard Henderson
` (53 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
We were storing the selector, not the base.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/x86_64/elfload.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
index 18d632ec34..12de1c54c7 100644
--- a/linux-user/x86_64/elfload.c
+++ b/linux-user/x86_64/elfload.c
@@ -44,8 +44,8 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
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.fs_base = tswapal(env->segs[R_FS].base);
+ r->pt.gs_base = tswapal(env->segs[R_GS].base);
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);
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 35/87] linux-user/aarch64: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (33 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 34/87] linux-user/x86_64: Fix dump of fs_base, gs_base Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:46 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 36/87] linux-user/aarch64: Expand target_elf_gregset_t Richard Henderson
` (52 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move the target_pt_regs structure from target_syscall.h, and
rename to target_user_pt_regs, to match what's in ptrace.h.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/target_ptrace.h | 14 ++++++++++++++
linux-user/aarch64/target_syscall.h | 7 -------
2 files changed, 14 insertions(+), 7 deletions(-)
create mode 100644 linux-user/aarch64/target_ptrace.h
diff --git a/linux-user/aarch64/target_ptrace.h b/linux-user/aarch64/target_ptrace.h
new file mode 100644
index 0000000000..10681338ba
--- /dev/null
+++ b/linux-user/aarch64/target_ptrace.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef AARCH64_TARGET_PTRACE_H
+#define AARCH64_TARGET_PTRACE_H
+
+/* See arch/arm64/include/uapi/asm/ptrace.h. */
+struct target_user_pt_regs {
+ uint64_t regs[31];
+ uint64_t sp;
+ uint64_t pc;
+ uint64_t pstate;
+};
+
+#endif /* AARCH64_TARGET_PTRACE_H */
diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h
index c055133725..bd05f6c7fe 100644
--- a/linux-user/aarch64/target_syscall.h
+++ b/linux-user/aarch64/target_syscall.h
@@ -1,13 +1,6 @@
#ifndef AARCH64_TARGET_SYSCALL_H
#define AARCH64_TARGET_SYSCALL_H
-struct target_pt_regs {
- uint64_t regs[31];
- uint64_t sp;
- uint64_t pc;
- uint64_t pstate;
-};
-
#if TARGET_BIG_ENDIAN
#define UNAME_MACHINE "aarch64_be"
#else
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 35/87] linux-user/aarch64: Create target_ptrace.h
2025-08-28 12:07 ` [PATCH v3 35/87] linux-user/aarch64: Create target_ptrace.h Richard Henderson
@ 2025-08-28 14:46 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:46 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:10, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the target_pt_regs structure from target_syscall.h, and
> rename to target_user_pt_regs, to match what's in ptrace.h.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/aarch64/target_ptrace.h | 14 ++++++++++++++
> linux-user/aarch64/target_syscall.h | 7 -------
> 2 files changed, 14 insertions(+), 7 deletions(-)
> create mode 100644 linux-user/aarch64/target_ptrace.h
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 36/87] linux-user/aarch64: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (34 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 35/87] linux-user/aarch64: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:46 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 37/87] linux-user/arm: Create target_ptrace.h Richard Henderson
` (51 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a
proper structure by using target_user_pt_regs.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/target_elf.h | 11 +++++++----
linux-user/aarch64/elfload.c | 11 +++++------
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index b0728a1008..9eb8bb547e 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -8,16 +8,19 @@
#ifndef AARCH64_TARGET_ELF_H
#define AARCH64_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-#define ELF_NREG 34
+/*
+ * See linux kernel: arch/arm64/include/asm/elf.h, where
+ * elf_gregset_t is mapped to struct user_pt_regs via sizeof.
+ */
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/aarch64/elfload.c b/linux-user/aarch64/elfload.c
index 00550f9fdf..07a0c3f844 100644
--- a/linux-user/aarch64/elfload.c
+++ b/linux-user/aarch64/elfload.c
@@ -349,13 +349,12 @@ const char *get_elf_platform(CPUState *cs)
return TARGET_BIG_ENDIAN ? "aarch64_be" : "aarch64";
}
-#define tswapreg(ptr) tswapal(ptr)
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
- for (int i = 0; i < 32; i++) {
- r->regs[i] = tswapreg(env->xregs[i]);
+ for (int i = 0; i < 31; i++) {
+ r->pt.regs[i] = tswap64(env->xregs[i]);
}
- r->regs[32] = tswapreg(env->pc);
- r->regs[33] = tswapreg(pstate_read((CPUARMState *)env));
+ r->pt.sp = tswap64(env->xregs[31]);
+ r->pt.pc = tswap64(env->pc);
+ r->pt.pstate = tswap64(pstate_read((CPUARMState *)env));
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 37/87] linux-user/arm: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (35 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 36/87] linux-user/aarch64: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:47 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t Richard Henderson
` (50 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move the target_pt_regs structure from target_syscall.h.
Replace the array with proper structure fields.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/arm/target_ptrace.h | 16 ++++++++++++++++
linux-user/arm/target_syscall.h | 8 --------
2 files changed, 16 insertions(+), 8 deletions(-)
create mode 100644 linux-user/arm/target_ptrace.h
diff --git a/linux-user/arm/target_ptrace.h b/linux-user/arm/target_ptrace.h
new file mode 100644
index 0000000000..1610b8e03c
--- /dev/null
+++ b/linux-user/arm/target_ptrace.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef ARM_TARGET_PTRACE_H
+#define ARM_TARGET_PTRACE_H
+
+/*
+ * See arch/arm/include/uapi/asm/ptrace.h.
+ * Instead of an array and ARM_xx defines, use proper fields.
+ */
+struct target_pt_regs {
+ abi_ulong regs[16];
+ abi_ulong cpsr;
+ abi_ulong orig_r0;
+};
+
+#endif /* ARM_TARGET_PTRACE_H */
diff --git a/linux-user/arm/target_syscall.h b/linux-user/arm/target_syscall.h
index 412ad434cf..8c4ddba717 100644
--- a/linux-user/arm/target_syscall.h
+++ b/linux-user/arm/target_syscall.h
@@ -1,14 +1,6 @@
#ifndef ARM_TARGET_SYSCALL_H
#define ARM_TARGET_SYSCALL_H
-/* this struct defines the way the registers are stored on the
- stack during a system call. */
-
-/* uregs[0..15] are r0 to r15; uregs[16] is CPSR; uregs[17] is ORIG_r0 */
-struct target_pt_regs {
- abi_long uregs[18];
-};
-
#define ARM_SYSCALL_BASE 0x900000
#define ARM_THUMB_SYSCALL 0
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 37/87] linux-user/arm: Create target_ptrace.h
2025-08-28 12:07 ` [PATCH v3 37/87] linux-user/arm: Create target_ptrace.h Richard Henderson
@ 2025-08-28 14:47 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:47 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:10, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the target_pt_regs structure from target_syscall.h.
> Replace the array with proper structure fields.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/arm/target_ptrace.h | 16 ++++++++++++++++
> linux-user/arm/target_syscall.h | 8 --------
> 2 files changed, 16 insertions(+), 8 deletions(-)
> create mode 100644 linux-user/arm/target_ptrace.h
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (36 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 37/87] linux-user/arm: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:47 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 39/87] linux-user/loongarch64: Create target_ptrace.h Richard Henderson
` (49 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/arm/target_elf.h | 11 +++++++----
linux-user/arm/elfload.c | 8 +++-----
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 94db3738e8..fa8f8af2f3 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -8,16 +8,19 @@
#ifndef ARM_TARGET_ELF_H
#define ARM_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-#define ELF_NREG 18
+/*
+ * See linux kernel: arch/arm/include/asm/elf.h, where
+ * elf_gregset_t is mapped to struct pt_regs via sizeof.
+ */
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ struct target_pt_regs pt;
} target_elf_gregset_t;
#endif
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index 47fe16a1a6..726d3ec25c 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -201,13 +201,11 @@ const char *get_elf_platform(CPUState *cs)
#undef END
}
-#define tswapreg(ptr) tswapal(ptr)
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
for (int i = 0; i < 16; ++i) {
- r->regs[i] = tswapreg(env->regs[i]);
+ r->pt.regs[i] = tswapal(env->regs[i]);
}
- r->regs[16] = tswapreg(cpsr_read((CPUARMState *)env));
- r->regs[17] = tswapreg(env->regs[0]); /* XXX */
+ r->pt.cpsr = tswapal(cpsr_read((CPUARMState *)env));
+ r->pt.orig_r0 = tswapal(env->regs[0]);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t
2025-08-28 12:07 ` [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 14:47 ` Peter Maydell
2025-08-28 22:28 ` Richard Henderson
0 siblings, 1 reply; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:47 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:10, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Make use of the fact that target_elf_gregset_t is a proper structure.
> Drop ELF_NREG, target_elf_greg_t, and tswapreg.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/arm/target_elf.h | 11 +++++++----
> linux-user/arm/elfload.c | 8 +++-----
> 2 files changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
> index 94db3738e8..fa8f8af2f3 100644
> --- a/linux-user/arm/target_elf.h
> +++ b/linux-user/arm/target_elf.h
> @@ -8,16 +8,19 @@
> #ifndef ARM_TARGET_ELF_H
> #define ARM_TARGET_ELF_H
>
> +#include "target_ptrace.h"
> +
> #define HAVE_ELF_HWCAP 1
> #define HAVE_ELF_HWCAP2 1
> #define HAVE_ELF_PLATFORM 1
> #define HAVE_ELF_CORE_DUMP 1
>
> -typedef abi_ulong target_elf_greg_t;
> -
> -#define ELF_NREG 18
> +/*
> + * See linux kernel: arch/arm/include/asm/elf.h, where
> + * elf_gregset_t is mapped to struct pt_regs via sizeof.
> + */
> typedef struct target_elf_gregset_t {
> - target_elf_greg_t regs[ELF_NREG];
> + struct target_pt_regs pt;
> } target_elf_gregset_t;
>
> #endif
> diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
> index 47fe16a1a6..726d3ec25c 100644
> --- a/linux-user/arm/elfload.c
> +++ b/linux-user/arm/elfload.c
> @@ -201,13 +201,11 @@ const char *get_elf_platform(CPUState *cs)
> #undef END
> }
>
> -#define tswapreg(ptr) tswapal(ptr)
> -
> void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
> {
> for (int i = 0; i < 16; ++i) {
> - r->regs[i] = tswapreg(env->regs[i]);
> + r->pt.regs[i] = tswapal(env->regs[i]);
> }
> - r->regs[16] = tswapreg(cpsr_read((CPUARMState *)env));
> - r->regs[17] = tswapreg(env->regs[0]); /* XXX */
> + r->pt.cpsr = tswapal(cpsr_read((CPUARMState *)env));
> + r->pt.orig_r0 = tswapal(env->regs[0]);
Why is it OK to drop the "XXX" comment here ?
otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread* Re: [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t
2025-08-28 14:47 ` Peter Maydell
@ 2025-08-28 22:28 ` Richard Henderson
2025-08-29 8:35 ` Peter Maydell
0 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 22:28 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel
On 8/29/25 00:47, Peter Maydell wrote:
> On Thu, 28 Aug 2025 at 13:10, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> Make use of the fact that target_elf_gregset_t is a proper structure.
>> Drop ELF_NREG, target_elf_greg_t, and tswapreg.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>> linux-user/arm/target_elf.h | 11 +++++++----
>> linux-user/arm/elfload.c | 8 +++-----
>> 2 files changed, 10 insertions(+), 9 deletions(-)
>>
>> diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
>> index 94db3738e8..fa8f8af2f3 100644
>> --- a/linux-user/arm/target_elf.h
>> +++ b/linux-user/arm/target_elf.h
>> @@ -8,16 +8,19 @@
>> #ifndef ARM_TARGET_ELF_H
>> #define ARM_TARGET_ELF_H
>>
>> +#include "target_ptrace.h"
>> +
>> #define HAVE_ELF_HWCAP 1
>> #define HAVE_ELF_HWCAP2 1
>> #define HAVE_ELF_PLATFORM 1
>> #define HAVE_ELF_CORE_DUMP 1
>>
>> -typedef abi_ulong target_elf_greg_t;
>> -
>> -#define ELF_NREG 18
>> +/*
>> + * See linux kernel: arch/arm/include/asm/elf.h, where
>> + * elf_gregset_t is mapped to struct pt_regs via sizeof.
>> + */
>> typedef struct target_elf_gregset_t {
>> - target_elf_greg_t regs[ELF_NREG];
>> + struct target_pt_regs pt;
>> } target_elf_gregset_t;
>>
>> #endif
>> diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
>> index 47fe16a1a6..726d3ec25c 100644
>> --- a/linux-user/arm/elfload.c
>> +++ b/linux-user/arm/elfload.c
>> @@ -201,13 +201,11 @@ const char *get_elf_platform(CPUState *cs)
>> #undef END
>> }
>>
>> -#define tswapreg(ptr) tswapal(ptr)
>> -
>> void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
>> {
>> for (int i = 0; i < 16; ++i) {
>> - r->regs[i] = tswapreg(env->regs[i]);
>> + r->pt.regs[i] = tswapal(env->regs[i]);
>> }
>> - r->regs[16] = tswapreg(cpsr_read((CPUARMState *)env));
>> - r->regs[17] = tswapreg(env->regs[0]); /* XXX */
>> + r->pt.cpsr = tswapal(cpsr_read((CPUARMState *)env));
>> + r->pt.orig_r0 = tswapal(env->regs[0]);
>
> Why is it OK to drop the "XXX" comment here ?
I assumed XXX meant "what is this", and the answer is orig_r0.
I'm not even sure the value is wrong as-is, due to the way we process syscalls.
r~
^ permalink raw reply [flat|nested] 152+ messages in thread* Re: [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t
2025-08-28 22:28 ` Richard Henderson
@ 2025-08-29 8:35 ` Peter Maydell
2025-08-29 10:03 ` Richard Henderson
0 siblings, 1 reply; 152+ messages in thread
From: Peter Maydell @ 2025-08-29 8:35 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 23:28, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 8/29/25 00:47, Peter Maydell wrote:
> > On Thu, 28 Aug 2025 at 13:10, Richard Henderson
> > <richard.henderson@linaro.org> wrote:
> >> void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
> >> {
> >> for (int i = 0; i < 16; ++i) {
> >> - r->regs[i] = tswapreg(env->regs[i]);
> >> + r->pt.regs[i] = tswapal(env->regs[i]);
> >> }
> >> - r->regs[16] = tswapreg(cpsr_read((CPUARMState *)env));
> >> - r->regs[17] = tswapreg(env->regs[0]); /* XXX */
> >> + r->pt.cpsr = tswapal(cpsr_read((CPUARMState *)env));
> >> + r->pt.orig_r0 = tswapal(env->regs[0]);
> >
> > Why is it OK to drop the "XXX" comment here ?
>
> I assumed XXX meant "what is this", and the answer is orig_r0.
> I'm not even sure the value is wrong as-is, due to the way we process syscalls.
I suspect the XXX is probably because the original author
was unsure why this was here -- after all we've already
put env->regs[0] into r->pt.regs[0], so why have the
extra field if it never has a different value?
Compare the "FIXME" comment in the m68k elf_core_copy_regs(),
and contrast the way our x86 code is explicitly
putting some other value in orig_ax. Are these different
kinds of orig_foo, or are we doing unnecessary work on
x86, or missing something for arm and m68k?
If it is OK to use env->regs[0] here we could probably
use a comment explaining why the struct field exists
and why our implementation differs from the kernel in
a way that makes the two fields always have the same value.
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread* Re: [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t
2025-08-29 8:35 ` Peter Maydell
@ 2025-08-29 10:03 ` Richard Henderson
0 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-29 10:03 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel
On 8/29/25 18:35, Peter Maydell wrote:
> Compare the "FIXME" comment in the m68k elf_core_copy_regs(),
> and contrast the way our x86 code is explicitly
> putting some other value in orig_ax. Are these different
> kinds of orig_foo, or are we doing unnecessary work on
> x86, or missing something for arm and m68k?
I really don't know the answer to that one.
I'll put a fixme back here for now.
r~
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 39/87] linux-user/loongarch64: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (37 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 38/87] linux-user/arm: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:49 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 40/87] linux-user/loongarch64: Expand target_elf_gregset_t Richard Henderson
` (48 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Remove the target_pt_regs structure from target_syscall.h.
Add target_user_pt_regs to target_ptrace.h, which matches
what is actually used on loongarch64.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/loongarch64/target_ptrace.h | 15 +++++++++++++++
linux-user/loongarch64/target_syscall.h | 23 -----------------------
2 files changed, 15 insertions(+), 23 deletions(-)
create mode 100644 linux-user/loongarch64/target_ptrace.h
diff --git a/linux-user/loongarch64/target_ptrace.h b/linux-user/loongarch64/target_ptrace.h
new file mode 100644
index 0000000000..2578e09207
--- /dev/null
+++ b/linux-user/loongarch64/target_ptrace.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef LOONGARCH64_TARGET_PTRACE_H
+#define LOONGARCH64_TARGET_PTRACE_H
+
+/* See arch/loongarch/include/uapi/asm/ptrace.h. */
+struct target_user_pt_regs {
+ abi_ulong regs[32];
+ abi_ulong orig_a0;
+ abi_ulong csr_era;
+ abi_ulong csr_badv;
+ abi_ulong reserved[10];
+};
+
+#endif /* LOONGARCH64_TARGET_PTRACE_H */
diff --git a/linux-user/loongarch64/target_syscall.h b/linux-user/loongarch64/target_syscall.h
index 39f229bb9c..f7ced7b2be 100644
--- a/linux-user/loongarch64/target_syscall.h
+++ b/linux-user/loongarch64/target_syscall.h
@@ -8,29 +8,6 @@
#include "qemu/units.h"
-/*
- * this struct defines the way the registers are stored on the
- * stack during a system call.
- */
-
-struct target_pt_regs {
- /* Saved main processor registers. */
- target_ulong regs[32];
-
- /* Saved special registers. */
- struct {
- target_ulong era;
- target_ulong badv;
- target_ulong crmd;
- target_ulong prmd;
- target_ulong euen;
- target_ulong ecfg;
- target_ulong estat;
- } csr;
- target_ulong orig_a0;
- target_ulong __last[0];
-};
-
#define UNAME_MACHINE "loongarch64"
#define UNAME_MINIMUM_RELEASE "5.19.0"
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 39/87] linux-user/loongarch64: Create target_ptrace.h
2025-08-28 12:07 ` [PATCH v3 39/87] linux-user/loongarch64: Create target_ptrace.h Richard Henderson
@ 2025-08-28 14:49 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:49 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:10, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Remove the target_pt_regs structure from target_syscall.h.
> Add target_user_pt_regs to target_ptrace.h, which matches
> what is actually used on loongarch64.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/loongarch64/target_ptrace.h | 15 +++++++++++++++
> linux-user/loongarch64/target_syscall.h | 23 -----------------------
> 2 files changed, 15 insertions(+), 23 deletions(-)
> create mode 100644 linux-user/loongarch64/target_ptrace.h
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 40/87] linux-user/loongarch64: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (38 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 39/87] linux-user/loongarch64: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:49 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 41/87] linux-user/m68k: " Richard Henderson
` (47 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
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.
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
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 40/87] linux-user/loongarch64: Expand target_elf_gregset_t
2025-08-28 12:07 ` [PATCH v3 40/87] linux-user/loongarch64: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 14:49 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:49 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:13, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> 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.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 41/87] linux-user/m68k: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (39 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 40/87] linux-user/loongarch64: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:53 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 42/87] linux-user/microblaze: Create target_ptrace.h Richard Henderson
` (46 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/m68k/target_elf.h | 24 ++++++++++++++++-----
linux-user/m68k/elfload.c | 42 +++++++++++++++++-------------------
2 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/linux-user/m68k/target_elf.h b/linux-user/m68k/target_elf.h
index cd6908ab57..0737412cee 100644
--- a/linux-user/m68k/target_elf.h
+++ b/linux-user/m68k/target_elf.h
@@ -10,12 +10,26 @@
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-/* See linux kernel: arch/m68k/include/asm/elf.h. */
-#define ELF_NREG 20
+/*
+ * See linux kernel: arch/m68k/include/asm/elf.h, where
+ * elf_gregset_t is mapped to struct user_regs_struct via sizeof.
+ *
+ * Note that user_regs_struct has
+ * short stkadj, sr;
+ * ...
+ * short fmtvec, __fill;
+ * but ELF_CORE_COPY_REGS writes to unsigned longs.
+ * Therefore adjust the sr and fmtvec fields to match.
+ */
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ abi_ulong d1, d2, d3, d4, d5, d6, d7;
+ abi_ulong a0, a1, a2, a3, a4, a5, a6;
+ abi_ulong d0;
+ abi_ulong usp;
+ abi_ulong orig_d0;
+ abi_ulong sr;
+ abi_ulong pc;
+ abi_ulong fmtvec;
} target_elf_gregset_t;
#endif
diff --git a/linux-user/m68k/elfload.c b/linux-user/m68k/elfload.c
index 2970ff7dec..423d1f680a 100644
--- a/linux-user/m68k/elfload.c
+++ b/linux-user/m68k/elfload.c
@@ -18,28 +18,26 @@ const char *get_elf_cpu_model(uint32_t eflags)
return "any";
}
-#define tswapreg(ptr) tswapal(ptr)
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUM68KState *env)
{
- r->regs[0] = tswapreg(env->dregs[1]);
- r->regs[1] = tswapreg(env->dregs[2]);
- r->regs[2] = tswapreg(env->dregs[3]);
- r->regs[3] = tswapreg(env->dregs[4]);
- r->regs[4] = tswapreg(env->dregs[5]);
- r->regs[5] = tswapreg(env->dregs[6]);
- r->regs[6] = tswapreg(env->dregs[7]);
- r->regs[7] = tswapreg(env->aregs[0]);
- r->regs[8] = tswapreg(env->aregs[1]);
- r->regs[9] = tswapreg(env->aregs[2]);
- r->regs[10] = tswapreg(env->aregs[3]);
- r->regs[11] = tswapreg(env->aregs[4]);
- r->regs[12] = tswapreg(env->aregs[5]);
- r->regs[13] = tswapreg(env->aregs[6]);
- r->regs[14] = tswapreg(env->dregs[0]);
- r->regs[15] = tswapreg(env->aregs[7]);
- r->regs[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */
- r->regs[17] = tswapreg(env->sr);
- r->regs[18] = tswapreg(env->pc);
- r->regs[19] = 0; /* FIXME: regs->format | regs->vector */
+ r->d1 = tswapal(env->dregs[1]);
+ r->d2 = tswapal(env->dregs[2]);
+ r->d3 = tswapal(env->dregs[3]);
+ r->d4 = tswapal(env->dregs[4]);
+ r->d5 = tswapal(env->dregs[5]);
+ r->d6 = tswapal(env->dregs[6]);
+ r->d7 = tswapal(env->dregs[7]);
+ r->a0 = tswapal(env->aregs[0]);
+ r->a1 = tswapal(env->aregs[1]);
+ r->a2 = tswapal(env->aregs[2]);
+ r->a3 = tswapal(env->aregs[3]);
+ r->a4 = tswapal(env->aregs[4]);
+ r->a5 = tswapal(env->aregs[5]);
+ r->a6 = tswapal(env->aregs[6]);
+ r->d0 = tswapal(env->dregs[0]);
+ r->usp = tswapal(env->aregs[7]);
+ r->orig_d0 = tswapal(env->dregs[0]); /* FIXME */
+ r->sr = tswapal(env->sr);
+ r->pc = tswapal(env->pc);
+ /* FIXME: regs->format | regs->vector */
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 42/87] linux-user/microblaze: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (40 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 41/87] linux-user/m68k: " Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:53 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 43/87] linux-user/microblaze: Fold target_pt_regs.r* to an array Richard Henderson
` (45 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move the target_pt_regs structure from target_syscall.h.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/microblaze/target_ptrace.h | 50 ++++++++++++++++++++++++++
linux-user/microblaze/target_syscall.h | 44 -----------------------
linux-user/microblaze/signal.c | 1 +
3 files changed, 51 insertions(+), 44 deletions(-)
create mode 100644 linux-user/microblaze/target_ptrace.h
diff --git a/linux-user/microblaze/target_ptrace.h b/linux-user/microblaze/target_ptrace.h
new file mode 100644
index 0000000000..a46c8cb7bc
--- /dev/null
+++ b/linux-user/microblaze/target_ptrace.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef MICROBLAZE_TARGET_PTRACE_H
+#define MICROBLAZE_TARGET_PTRACE_H
+
+/* We use microblaze_reg_t to keep things similar to the kernel sources. */
+typedef uint32_t microblaze_reg_t;
+
+struct target_pt_regs {
+ microblaze_reg_t r0;
+ microblaze_reg_t r1;
+ microblaze_reg_t r2;
+ microblaze_reg_t r3;
+ microblaze_reg_t r4;
+ microblaze_reg_t r5;
+ microblaze_reg_t r6;
+ microblaze_reg_t r7;
+ microblaze_reg_t r8;
+ microblaze_reg_t r9;
+ microblaze_reg_t r10;
+ microblaze_reg_t r11;
+ microblaze_reg_t r12;
+ microblaze_reg_t r13;
+ microblaze_reg_t r14;
+ microblaze_reg_t r15;
+ microblaze_reg_t r16;
+ microblaze_reg_t r17;
+ microblaze_reg_t r18;
+ microblaze_reg_t r19;
+ microblaze_reg_t r20;
+ microblaze_reg_t r21;
+ microblaze_reg_t r22;
+ microblaze_reg_t r23;
+ microblaze_reg_t r24;
+ microblaze_reg_t r25;
+ microblaze_reg_t r26;
+ microblaze_reg_t r27;
+ microblaze_reg_t r28;
+ microblaze_reg_t r29;
+ microblaze_reg_t r30;
+ microblaze_reg_t r31;
+ microblaze_reg_t pc;
+ microblaze_reg_t msr;
+ microblaze_reg_t ear;
+ microblaze_reg_t esr;
+ microblaze_reg_t fsr;
+ uint32_t kernel_mode;
+};
+
+#endif /* MICROBLAZE_TARGET_PTRACE_H */
diff --git a/linux-user/microblaze/target_syscall.h b/linux-user/microblaze/target_syscall.h
index 43362a1664..66f5a9ebe2 100644
--- a/linux-user/microblaze/target_syscall.h
+++ b/linux-user/microblaze/target_syscall.h
@@ -4,50 +4,6 @@
#define UNAME_MACHINE "microblaze"
#define UNAME_MINIMUM_RELEASE "2.6.32"
-/* We use microblaze_reg_t to keep things similar to the kernel sources. */
-typedef uint32_t microblaze_reg_t;
-
-struct target_pt_regs {
- microblaze_reg_t r0;
- microblaze_reg_t r1;
- microblaze_reg_t r2;
- microblaze_reg_t r3;
- microblaze_reg_t r4;
- microblaze_reg_t r5;
- microblaze_reg_t r6;
- microblaze_reg_t r7;
- microblaze_reg_t r8;
- microblaze_reg_t r9;
- microblaze_reg_t r10;
- microblaze_reg_t r11;
- microblaze_reg_t r12;
- microblaze_reg_t r13;
- microblaze_reg_t r14;
- microblaze_reg_t r15;
- microblaze_reg_t r16;
- microblaze_reg_t r17;
- microblaze_reg_t r18;
- microblaze_reg_t r19;
- microblaze_reg_t r20;
- microblaze_reg_t r21;
- microblaze_reg_t r22;
- microblaze_reg_t r23;
- microblaze_reg_t r24;
- microblaze_reg_t r25;
- microblaze_reg_t r26;
- microblaze_reg_t r27;
- microblaze_reg_t r28;
- microblaze_reg_t r29;
- microblaze_reg_t r30;
- microblaze_reg_t r31;
- microblaze_reg_t pc;
- microblaze_reg_t msr;
- microblaze_reg_t ear;
- microblaze_reg_t esr;
- microblaze_reg_t fsr;
- uint32_t kernel_mode;
-};
-
#define TARGET_CLONE_BACKWARDS
#define TARGET_MCL_CURRENT 1
#define TARGET_MCL_FUTURE 2
diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c
index f6d47d76ff..7aef781314 100644
--- a/linux-user/microblaze/signal.c
+++ b/linux-user/microblaze/signal.c
@@ -21,6 +21,7 @@
#include "user-internals.h"
#include "signal-common.h"
#include "linux-user/trace.h"
+#include "target_ptrace.h"
struct target_sigcontext {
struct target_pt_regs regs; /* needs to be first */
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 43/87] linux-user/microblaze: Fold target_pt_regs.r* to an array
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (41 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 42/87] linux-user/microblaze: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:54 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 44/87] linux-user/microblaze: Expand target_elf_gregset_t Richard Henderson
` (44 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Separately enumerating all 32 registers is not helpful.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/microblaze/target_ptrace.h | 34 +------------
linux-user/microblaze/signal.c | 70 +++------------------------
2 files changed, 8 insertions(+), 96 deletions(-)
diff --git a/linux-user/microblaze/target_ptrace.h b/linux-user/microblaze/target_ptrace.h
index a46c8cb7bc..ead913e5a4 100644
--- a/linux-user/microblaze/target_ptrace.h
+++ b/linux-user/microblaze/target_ptrace.h
@@ -7,38 +7,8 @@
typedef uint32_t microblaze_reg_t;
struct target_pt_regs {
- microblaze_reg_t r0;
- microblaze_reg_t r1;
- microblaze_reg_t r2;
- microblaze_reg_t r3;
- microblaze_reg_t r4;
- microblaze_reg_t r5;
- microblaze_reg_t r6;
- microblaze_reg_t r7;
- microblaze_reg_t r8;
- microblaze_reg_t r9;
- microblaze_reg_t r10;
- microblaze_reg_t r11;
- microblaze_reg_t r12;
- microblaze_reg_t r13;
- microblaze_reg_t r14;
- microblaze_reg_t r15;
- microblaze_reg_t r16;
- microblaze_reg_t r17;
- microblaze_reg_t r18;
- microblaze_reg_t r19;
- microblaze_reg_t r20;
- microblaze_reg_t r21;
- microblaze_reg_t r22;
- microblaze_reg_t r23;
- microblaze_reg_t r24;
- microblaze_reg_t r25;
- microblaze_reg_t r26;
- microblaze_reg_t r27;
- microblaze_reg_t r28;
- microblaze_reg_t r29;
- microblaze_reg_t r30;
- microblaze_reg_t r31;
+ /* Note the kernel enumerates all 32 registers. */
+ microblaze_reg_t r[32];
microblaze_reg_t pc;
microblaze_reg_t msr;
microblaze_reg_t ear;
diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c
index 7aef781314..e874e4def1 100644
--- a/linux-user/microblaze/signal.c
+++ b/linux-user/microblaze/signal.c
@@ -51,75 +51,17 @@ struct target_rt_sigframe {
static void setup_sigcontext(struct target_sigcontext *sc, CPUMBState *env)
{
- __put_user(env->regs[0], &sc->regs.r0);
- __put_user(env->regs[1], &sc->regs.r1);
- __put_user(env->regs[2], &sc->regs.r2);
- __put_user(env->regs[3], &sc->regs.r3);
- __put_user(env->regs[4], &sc->regs.r4);
- __put_user(env->regs[5], &sc->regs.r5);
- __put_user(env->regs[6], &sc->regs.r6);
- __put_user(env->regs[7], &sc->regs.r7);
- __put_user(env->regs[8], &sc->regs.r8);
- __put_user(env->regs[9], &sc->regs.r9);
- __put_user(env->regs[10], &sc->regs.r10);
- __put_user(env->regs[11], &sc->regs.r11);
- __put_user(env->regs[12], &sc->regs.r12);
- __put_user(env->regs[13], &sc->regs.r13);
- __put_user(env->regs[14], &sc->regs.r14);
- __put_user(env->regs[15], &sc->regs.r15);
- __put_user(env->regs[16], &sc->regs.r16);
- __put_user(env->regs[17], &sc->regs.r17);
- __put_user(env->regs[18], &sc->regs.r18);
- __put_user(env->regs[19], &sc->regs.r19);
- __put_user(env->regs[20], &sc->regs.r20);
- __put_user(env->regs[21], &sc->regs.r21);
- __put_user(env->regs[22], &sc->regs.r22);
- __put_user(env->regs[23], &sc->regs.r23);
- __put_user(env->regs[24], &sc->regs.r24);
- __put_user(env->regs[25], &sc->regs.r25);
- __put_user(env->regs[26], &sc->regs.r26);
- __put_user(env->regs[27], &sc->regs.r27);
- __put_user(env->regs[28], &sc->regs.r28);
- __put_user(env->regs[29], &sc->regs.r29);
- __put_user(env->regs[30], &sc->regs.r30);
- __put_user(env->regs[31], &sc->regs.r31);
+ for (int i = 0; i < 32; ++i) {
+ __put_user(env->regs[i], &sc->regs.r[i]);
+ }
__put_user(env->pc, &sc->regs.pc);
}
static void restore_sigcontext(struct target_sigcontext *sc, CPUMBState *env)
{
- __get_user(env->regs[0], &sc->regs.r0);
- __get_user(env->regs[1], &sc->regs.r1);
- __get_user(env->regs[2], &sc->regs.r2);
- __get_user(env->regs[3], &sc->regs.r3);
- __get_user(env->regs[4], &sc->regs.r4);
- __get_user(env->regs[5], &sc->regs.r5);
- __get_user(env->regs[6], &sc->regs.r6);
- __get_user(env->regs[7], &sc->regs.r7);
- __get_user(env->regs[8], &sc->regs.r8);
- __get_user(env->regs[9], &sc->regs.r9);
- __get_user(env->regs[10], &sc->regs.r10);
- __get_user(env->regs[11], &sc->regs.r11);
- __get_user(env->regs[12], &sc->regs.r12);
- __get_user(env->regs[13], &sc->regs.r13);
- __get_user(env->regs[14], &sc->regs.r14);
- __get_user(env->regs[15], &sc->regs.r15);
- __get_user(env->regs[16], &sc->regs.r16);
- __get_user(env->regs[17], &sc->regs.r17);
- __get_user(env->regs[18], &sc->regs.r18);
- __get_user(env->regs[19], &sc->regs.r19);
- __get_user(env->regs[20], &sc->regs.r20);
- __get_user(env->regs[21], &sc->regs.r21);
- __get_user(env->regs[22], &sc->regs.r22);
- __get_user(env->regs[23], &sc->regs.r23);
- __get_user(env->regs[24], &sc->regs.r24);
- __get_user(env->regs[25], &sc->regs.r25);
- __get_user(env->regs[26], &sc->regs.r26);
- __get_user(env->regs[27], &sc->regs.r27);
- __get_user(env->regs[28], &sc->regs.r28);
- __get_user(env->regs[29], &sc->regs.r29);
- __get_user(env->regs[30], &sc->regs.r30);
- __get_user(env->regs[31], &sc->regs.r31);
+ for (int i = 0; i < 32; ++i) {
+ __get_user(env->regs[i], &sc->regs.r[i]);
+ }
__get_user(env->pc, &sc->regs.pc);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 44/87] linux-user/microblaze: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (42 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 43/87] linux-user/microblaze: Fold target_pt_regs.r* to an array Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:56 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 45/87] linux-user/mips: Create target_ptrace.h Richard Henderson
` (43 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/microblaze/target_elf.h | 11 +++++++----
linux-user/microblaze/elfload.c | 14 +++++---------
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index cc5cc0477e..56de77d4f3 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -8,13 +8,16 @@
#ifndef MICROBLAZE_TARGET_ELF_H
#define MICROBLAZE_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-#define ELF_NREG 38
+/*
+ * See linux kernel: arch/microblaze/include/asm/elf.h, where
+ * elf_gregset_t is mapped to struct pt_regs via sizeof.
+ */
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ struct target_pt_regs pt;
} target_elf_gregset_t;
#endif
diff --git a/linux-user/microblaze/elfload.c b/linux-user/microblaze/elfload.c
index 89250dbd63..7eb1b26d17 100644
--- a/linux-user/microblaze/elfload.c
+++ b/linux-user/microblaze/elfload.c
@@ -11,18 +11,14 @@ const char *get_elf_cpu_model(uint32_t eflags)
return "any";
}
-#define tswapreg(ptr) tswapal(ptr)
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
{
for (int i = 0; i < 32; i++) {
- r->regs[i] = tswapreg(env->regs[i]);
+ r->pt.r[i] = tswapal(env->regs[i]);
}
- r->regs[32] = tswapreg(env->pc);
- r->regs[33] = tswapreg(mb_cpu_read_msr(env));
- r->regs[34] = 0;
- r->regs[35] = tswapreg(env->ear);
- r->regs[36] = 0;
- r->regs[37] = tswapreg(env->esr);
+ r->pt.pc = tswapal(env->pc);
+ r->pt.msr = tswapal(mb_cpu_read_msr(env));
+ r->pt.ear = tswapal(env->ear);
+ r->pt.esr = tswapal(env->esr);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 45/87] linux-user/mips: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (43 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 44/87] linux-user/microblaze: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 14:57 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 46/87] linux-user/mips: Use target_ulong for target_elf_greg_t Richard Henderson
` (42 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move the target_pt_regs structure from target_syscall.h.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/mips/target_ptrace.h | 17 +++++++++++++++++
linux-user/mips/target_syscall.h | 19 -------------------
linux-user/mips64/target_ptrace.h | 16 ++++++++++++++++
linux-user/mips64/target_syscall.h | 16 ----------------
4 files changed, 33 insertions(+), 35 deletions(-)
create mode 100644 linux-user/mips/target_ptrace.h
create mode 100644 linux-user/mips64/target_ptrace.h
diff --git a/linux-user/mips/target_ptrace.h b/linux-user/mips/target_ptrace.h
new file mode 100644
index 0000000000..2f63b27ac4
--- /dev/null
+++ b/linux-user/mips/target_ptrace.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef MIPS_TARGET_PTRACE_H
+#define MIPS_TARGET_PTRACE_H
+
+struct target_pt_regs {
+ abi_ulong pad0[6];
+ abi_ulong regs[32];
+ abi_ulong lo;
+ abi_ulong hi;
+ abi_ulong cp0_epc;
+ abi_ulong cp0_badvaddr;
+ abi_ulong cp0_status;
+ abi_ulong cp0_cause;
+};
+
+#endif /* MIPS_TARGET_PTRACE_H */
diff --git a/linux-user/mips/target_syscall.h b/linux-user/mips/target_syscall.h
index 08ead67810..dfcdf320b7 100644
--- a/linux-user/mips/target_syscall.h
+++ b/linux-user/mips/target_syscall.h
@@ -1,25 +1,6 @@
#ifndef MIPS_TARGET_SYSCALL_H
#define MIPS_TARGET_SYSCALL_H
-/* this struct defines the way the registers are stored on the
- stack during a system call. */
-
-struct target_pt_regs {
- /* Pad bytes for argument save space on the stack. */
- abi_ulong pad0[6];
-
- /* Saved main processor registers. */
- abi_ulong regs[32];
-
- /* Saved special registers. */
- abi_ulong cp0_status;
- abi_ulong lo;
- abi_ulong hi;
- abi_ulong cp0_badvaddr;
- abi_ulong cp0_cause;
- abi_ulong cp0_epc;
-};
-
#define UNAME_MACHINE "mips"
#define UNAME_MINIMUM_RELEASE "2.6.32"
diff --git a/linux-user/mips64/target_ptrace.h b/linux-user/mips64/target_ptrace.h
new file mode 100644
index 0000000000..41f0bf6c1c
--- /dev/null
+++ b/linux-user/mips64/target_ptrace.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef MIPS64_TARGET_PTRACE_H
+#define MIPS64_TARGET_PTRACE_H
+
+struct target_pt_regs {
+ target_ulong regs[32];
+ target_ulong lo;
+ target_ulong hi;
+ target_ulong cp0_epc;
+ target_ulong cp0_badvaddr;
+ target_ulong cp0_status;
+ target_ulong cp0_cause;
+};
+
+#endif /* MIPS64_TARGET_PTRACE_H */
diff --git a/linux-user/mips64/target_syscall.h b/linux-user/mips64/target_syscall.h
index 358dc2d64c..9135bf5e8b 100644
--- a/linux-user/mips64/target_syscall.h
+++ b/linux-user/mips64/target_syscall.h
@@ -1,22 +1,6 @@
#ifndef MIPS64_TARGET_SYSCALL_H
#define MIPS64_TARGET_SYSCALL_H
-/* this struct defines the way the registers are stored on the
- stack during a system call. */
-
-struct target_pt_regs {
- /* Saved main processor registers. */
- target_ulong regs[32];
-
- /* Saved special registers. */
- target_ulong cp0_status;
- target_ulong lo;
- target_ulong hi;
- target_ulong cp0_badvaddr;
- target_ulong cp0_cause;
- target_ulong cp0_epc;
-};
-
#define UNAME_MACHINE "mips64"
#define UNAME_MINIMUM_RELEASE "2.6.32"
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 45/87] linux-user/mips: Create target_ptrace.h
2025-08-28 12:07 ` [PATCH v3 45/87] linux-user/mips: Create target_ptrace.h Richard Henderson
@ 2025-08-28 14:57 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 14:57 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:13, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the target_pt_regs structure from target_syscall.h.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/mips/target_ptrace.h | 17 +++++++++++++++++
> linux-user/mips/target_syscall.h | 19 -------------------
> linux-user/mips64/target_ptrace.h | 16 ++++++++++++++++
> linux-user/mips64/target_syscall.h | 16 ----------------
> 4 files changed, 33 insertions(+), 35 deletions(-)
> create mode 100644 linux-user/mips/target_ptrace.h
> create mode 100644 linux-user/mips64/target_ptrace.h
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 46/87] linux-user/mips: Use target_ulong for target_elf_greg_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (44 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 45/87] linux-user/mips: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 15:04 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 47/87] linux-user/openrisc: Create target_ptrace.h Richard Henderson
` (41 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
The target_ulong type matches the abi_ulong/abi_ullong
selection within mips64/target_elf.h.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/mips/target_elf.h | 10 ++++---
linux-user/mips64/target_elf.h | 14 +++++-----
linux-user/mips/elfload.c | 48 +++++++---------------------------
3 files changed, 22 insertions(+), 50 deletions(-)
diff --git a/linux-user/mips/target_elf.h b/linux-user/mips/target_elf.h
index f767767eaa..a4b7fadbd6 100644
--- a/linux-user/mips/target_elf.h
+++ b/linux-user/mips/target_elf.h
@@ -8,16 +8,18 @@
#ifndef MIPS_TARGET_ELF_H
#define MIPS_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_BASE_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
/* See linux kernel: arch/mips/include/asm/elf.h. */
-#define ELF_NREG 45
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ union {
+ abi_ulong reserved[45];
+ struct target_pt_regs pt;
+ };
} target_elf_gregset_t;
#endif
diff --git a/linux-user/mips64/target_elf.h b/linux-user/mips64/target_elf.h
index 046a165eef..67bc963134 100644
--- a/linux-user/mips64/target_elf.h
+++ b/linux-user/mips64/target_elf.h
@@ -8,20 +8,18 @@
#ifndef MIPS64_TARGET_ELF_H
#define MIPS64_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_BASE_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
-#ifdef TARGET_ABI_MIPSN32
-typedef abi_ullong target_elf_greg_t;
-#else
-typedef abi_ulong target_elf_greg_t;
-#endif
-
/* See linux kernel: arch/mips/include/asm/elf.h. */
-#define ELF_NREG 45
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ union {
+ target_ulong reserved[45];
+ struct target_pt_regs pt;
+ };
} target_elf_gregset_t;
#endif
diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c
index 6e884911af..e0c50f50ed 100644
--- a/linux-user/mips/elfload.c
+++ b/linux-user/mips/elfload.c
@@ -124,47 +124,19 @@ const char *get_elf_base_platform(CPUState *cs)
#undef MATCH_PLATFORM_INSN
-#ifdef TARGET_ABI_MIPSN32
-#define tswapreg(ptr) tswap64(ptr)
-#else
-#define tswapreg(ptr) tswapal(ptr)
-#endif
-
-/* See linux kernel: arch/mips/include/asm/reg.h. */
-enum {
-#ifdef TARGET_MIPS64
- TARGET_EF_R0 = 0,
-#else
- TARGET_EF_R0 = 6,
-#endif
- TARGET_EF_R26 = TARGET_EF_R0 + 26,
- TARGET_EF_R27 = TARGET_EF_R0 + 27,
- TARGET_EF_LO = TARGET_EF_R0 + 32,
- TARGET_EF_HI = TARGET_EF_R0 + 33,
- TARGET_EF_CP0_EPC = TARGET_EF_R0 + 34,
- TARGET_EF_CP0_BADVADDR = TARGET_EF_R0 + 35,
- TARGET_EF_CP0_STATUS = TARGET_EF_R0 + 36,
- TARGET_EF_CP0_CAUSE = TARGET_EF_R0 + 37
-};
-
/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env)
{
- int i;
-
- for (i = 0; i <= TARGET_EF_R0; i++) {
- r->regs[i] = 0;
- }
- for (i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
- r->regs[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]);
+ for (int i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
+ r->pt.regs[i] = tswapl(env->active_tc.gpr[i]);
}
- r->regs[TARGET_EF_R26] = 0;
- r->regs[TARGET_EF_R27] = 0;
- r->regs[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]);
- r->regs[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]);
- r->regs[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC);
- r->regs[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr);
- r->regs[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status);
- r->regs[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
+ r->pt.regs[26] = 0;
+ r->pt.regs[27] = 0;
+ r->pt.lo = tswapl(env->active_tc.LO[0]);
+ r->pt.hi = tswapl(env->active_tc.HI[0]);
+ r->pt.cp0_epc = tswapl(env->active_tc.PC);
+ r->pt.cp0_badvaddr = tswapl(env->CP0_BadVAddr);
+ r->pt.cp0_status = tswapl(env->CP0_Status);
+ r->pt.cp0_cause = tswapl(env->CP0_Cause);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 47/87] linux-user/openrisc: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (45 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 46/87] linux-user/mips: Use target_ulong for target_elf_greg_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 15:04 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 48/87] linux-user/openrisc: Expand target_elf_gregset_t Richard Henderson
` (40 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move the target_pt_regs structure from target_syscall.h and
rename to target_user_regs_struct, obviating the comment.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/openrisc/target_ptrace.h | 13 +++++++++++++
linux-user/openrisc/target_syscall.h | 11 -----------
linux-user/openrisc/signal.c | 3 ++-
3 files changed, 15 insertions(+), 12 deletions(-)
create mode 100644 linux-user/openrisc/target_ptrace.h
diff --git a/linux-user/openrisc/target_ptrace.h b/linux-user/openrisc/target_ptrace.h
new file mode 100644
index 0000000000..563c648525
--- /dev/null
+++ b/linux-user/openrisc/target_ptrace.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef OPENRISC_TARGET_PTRACE_H
+#define OPENRISC_TARGET_PTRACE_H
+
+/* See arch/openrisc/include/uapi/asm/ptrace.h. */
+struct target_user_regs_struct {
+ abi_ulong gpr[32];
+ abi_ulong pc;
+ abi_ulong sr;
+};
+
+#endif /* OPENRISC_TARGET_PTRACE_H */
diff --git a/linux-user/openrisc/target_syscall.h b/linux-user/openrisc/target_syscall.h
index 7fe5b73d3b..c8394e9dcd 100644
--- a/linux-user/openrisc/target_syscall.h
+++ b/linux-user/openrisc/target_syscall.h
@@ -1,17 +1,6 @@
#ifndef OPENRISC_TARGET_SYSCALL_H
#define OPENRISC_TARGET_SYSCALL_H
-/* Note that in linux/arch/openrisc/include/uapi/asm/ptrace.h,
- * this is called user_regs_struct. Given that this is what
- * is used within struct sigcontext we need this definition.
- * However, elfload.c wants this name.
- */
-struct target_pt_regs {
- abi_ulong gpr[32];
- abi_ulong pc;
- abi_ulong sr;
-};
-
#define UNAME_MACHINE "openrisc"
#define UNAME_MINIMUM_RELEASE "2.6.32"
diff --git a/linux-user/openrisc/signal.c b/linux-user/openrisc/signal.c
index cb74a9fe5e..40249095f2 100644
--- a/linux-user/openrisc/signal.c
+++ b/linux-user/openrisc/signal.c
@@ -21,9 +21,10 @@
#include "user-internals.h"
#include "signal-common.h"
#include "linux-user/trace.h"
+#include "target_ptrace.h"
typedef struct target_sigcontext {
- struct target_pt_regs regs;
+ struct target_user_regs_struct regs;
abi_ulong oldmask;
} target_sigcontext;
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 48/87] linux-user/openrisc: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (46 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 47/87] linux-user/openrisc: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 15:04 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 49/87] linux-user/ppc: Create target_ptrace.h Richard Henderson
` (39 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/openrisc/target_elf.h | 12 +++++++-----
linux-user/openrisc/elfload.c | 8 +++-----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/linux-user/openrisc/target_elf.h b/linux-user/openrisc/target_elf.h
index e97bdc11ed..ad80e4b41a 100644
--- a/linux-user/openrisc/target_elf.h
+++ b/linux-user/openrisc/target_elf.h
@@ -8,14 +8,16 @@
#ifndef OPENRISC_TARGET_ELF_H
#define OPENRISC_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-/* See linux kernel arch/openrisc/include/asm/elf.h. */
-#define ELF_NREG 34 /* gprs and pc, sr */
+/*
+ * See linux kernel: arch/openrisc/include/uapi/asm/elf.h, where
+ * elf_gregset_t is mapped to struct user_regs_struct via sizeof.
+ */
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/openrisc/elfload.c b/linux-user/openrisc/elfload.c
index bb5ad96711..6bf02bf58d 100644
--- a/linux-user/openrisc/elfload.c
+++ b/linux-user/openrisc/elfload.c
@@ -11,13 +11,11 @@ const char *get_elf_cpu_model(uint32_t eflags)
return "any";
}
-#define tswapreg(ptr) tswapal(ptr)
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUOpenRISCState *env)
{
for (int i = 0; i < 32; i++) {
- r->regs[i] = tswapreg(cpu_get_gpr(env, i));
+ r->pt.gpr[i] = tswapal(cpu_get_gpr(env, i));
}
- r->regs[32] = tswapreg(env->pc);
- r->regs[33] = tswapreg(cpu_get_sr(env));
+ r->pt.pc = tswapal(env->pc);
+ r->pt.sr = tswapal(cpu_get_sr(env));
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 49/87] linux-user/ppc: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (47 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 48/87] linux-user/openrisc: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 15:05 ` Peter Maydell
2025-08-28 12:07 ` [PATCH v3 50/87] linux-user/ppc: Expand target_elf_gregset_t Richard Henderson
` (38 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move the target_pt_regs structure from target_syscall.h.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/ppc/target_ptrace.h | 26 ++++++++++++++++++++++++++
linux-user/ppc/target_syscall.h | 28 ----------------------------
2 files changed, 26 insertions(+), 28 deletions(-)
create mode 100644 linux-user/ppc/target_ptrace.h
diff --git a/linux-user/ppc/target_ptrace.h b/linux-user/ppc/target_ptrace.h
new file mode 100644
index 0000000000..df77bfde73
--- /dev/null
+++ b/linux-user/ppc/target_ptrace.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef PPC_TARGET_PTRACE_H
+#define PPC_TARGET_PTRACE_H
+
+struct target_pt_regs {
+ abi_ulong gpr[32];
+ abi_ulong nip;
+ abi_ulong msr;
+ abi_ulong orig_gpr3; /* Used for restarting system calls */
+ abi_ulong ctr;
+ abi_ulong link;
+ abi_ulong xer;
+ abi_ulong ccr;
+#if defined(TARGET_PPC64)
+ abi_ulong softe;
+#else
+ abi_ulong mq; /* 601 only (not used at present) */
+#endif
+ abi_ulong trap; /* Reason for being here */
+ abi_ulong dar; /* Fault registers */
+ abi_ulong dsisr;
+ abi_ulong result; /* Result of a system call */
+};
+
+#endif /* PPC_TARGET_PTRACE_H */
diff --git a/linux-user/ppc/target_syscall.h b/linux-user/ppc/target_syscall.h
index 77b36d0b46..976b4bb7e9 100644
--- a/linux-user/ppc/target_syscall.h
+++ b/linux-user/ppc/target_syscall.h
@@ -20,34 +20,6 @@
#ifndef PPC_TARGET_SYSCALL_H
#define PPC_TARGET_SYSCALL_H
-/* XXX: ABSOLUTELY BUGGY:
- * for now, this is quite just a cut-and-paste from i386 target...
- */
-
-/* default linux values for the selectors */
-#define __USER_DS (1)
-
-struct target_pt_regs {
- abi_ulong gpr[32];
- abi_ulong nip;
- abi_ulong msr;
- abi_ulong orig_gpr3; /* Used for restarting system calls */
- abi_ulong ctr;
- abi_ulong link;
- abi_ulong xer;
- abi_ulong ccr;
-#if defined(TARGET_PPC64)
- abi_ulong softe;
-#else
- abi_ulong mq; /* 601 only (not used at present) */
-#endif
- /* Used on APUS to hold IPL value. */
- abi_ulong trap; /* Reason for being here */
- abi_ulong dar; /* Fault registers */
- abi_ulong dsisr;
- abi_ulong result; /* Result of a system call */
-};
-
/* ioctls */
struct target_revectored_struct {
abi_ulong __map[8]; /* 256 bits */
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 49/87] linux-user/ppc: Create target_ptrace.h
2025-08-28 12:07 ` [PATCH v3 49/87] linux-user/ppc: Create target_ptrace.h Richard Henderson
@ 2025-08-28 15:05 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 15:05 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:13, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the target_pt_regs structure from target_syscall.h.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/ppc/target_ptrace.h | 26 ++++++++++++++++++++++++++
> linux-user/ppc/target_syscall.h | 28 ----------------------------
> 2 files changed, 26 insertions(+), 28 deletions(-)
> create mode 100644 linux-user/ppc/target_ptrace.h
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 50/87] linux-user/ppc: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (48 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 49/87] linux-user/ppc: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:07 ` Richard Henderson
2025-08-28 15:06 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 51/87] linux-user/s390x: Create target_ptrace.h Richard Henderson
` (37 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:07 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/ppc/target_elf.h | 16 +++++++++++-----
linux-user/ppc/elfload.c | 23 ++++++++---------------
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/linux-user/ppc/target_elf.h b/linux-user/ppc/target_elf.h
index 72615553ea..2a61cd2896 100644
--- a/linux-user/ppc/target_elf.h
+++ b/linux-user/ppc/target_elf.h
@@ -8,16 +8,22 @@
#ifndef PPC_TARGET_ELF_H
#define PPC_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-/* See linux kernel: arch/powerpc/include/asm/elf.h. */
-#define ELF_NREG 48
+/*
+ * The size of 48 words is set in arch/powerpc/include/uapi/asm/elf.h.
+ * However PPC_ELF_CORE_COPY_REGS in arch/powerpc/include/asm/elf.h
+ * open-codes a memcpy from struct pt_regs, then zeros the rest.
+ */
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ union {
+ struct target_pt_regs pt;
+ abi_ulong reserved[48];
+ };
} target_elf_gregset_t;
#endif
diff --git a/linux-user/ppc/elfload.c b/linux-user/ppc/elfload.c
index 114e40a358..0d54da9803 100644
--- a/linux-user/ppc/elfload.c
+++ b/linux-user/ppc/elfload.c
@@ -131,23 +131,16 @@ abi_ulong get_elf_hwcap2(CPUState *cs)
return features;
}
-#define tswapreg(ptr) tswapal(ptr)
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUPPCState *env)
{
- int i;
- target_ulong ccr = 0;
-
- for (i = 0; i < ARRAY_SIZE(env->gpr); i++) {
- r->regs[i] = tswapreg(env->gpr[i]);
+ for (int i = 0; i < ARRAY_SIZE(env->gpr); i++) {
+ r->pt.gpr[i] = tswapal(env->gpr[i]);
}
- r->regs[32] = tswapreg(env->nip);
- r->regs[33] = tswapreg(env->msr);
- r->regs[35] = tswapreg(env->ctr);
- r->regs[36] = tswapreg(env->lr);
- r->regs[37] = tswapreg(cpu_read_xer(env));
-
- ccr = ppc_get_cr(env);
- r->regs[38] = tswapreg(ccr);
+ r->pt.nip = tswapal(env->nip);
+ r->pt.msr = tswapal(env->msr);
+ r->pt.ctr = tswapal(env->ctr);
+ r->pt.link = tswapal(env->lr);
+ r->pt.xer = tswapal(cpu_read_xer(env));
+ r->pt.ccr = tswapal(ppc_get_cr(env));
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 51/87] linux-user/s390x: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (49 preceding siblings ...)
2025-08-28 12:07 ` [PATCH v3 50/87] linux-user/ppc: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:10 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 52/87] linux-user/s390x: Expand target_elf_gregset_t Richard Henderson
` (36 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move target_psw_t to target_ptrace.h.
Remove the target_pt_regs; add target_s390x_reg to target_ptrace.h,
which matches what is actually used.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/s390x/target_ptrace.h | 18 ++++++++++++++++++
linux-user/s390x/target_syscall.h | 22 ----------------------
linux-user/s390x/signal.c | 1 +
3 files changed, 19 insertions(+), 22 deletions(-)
create mode 100644 linux-user/s390x/target_ptrace.h
diff --git a/linux-user/s390x/target_ptrace.h b/linux-user/s390x/target_ptrace.h
new file mode 100644
index 0000000000..a5ceb75a74
--- /dev/null
+++ b/linux-user/s390x/target_ptrace.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef S390X_TARGET_PTRACE_H
+#define S390X_TARGET_PTRACE_H
+
+typedef struct {
+ abi_ulong mask;
+ abi_ulong addr;
+} target_psw_t;
+
+struct target_s390_regs {
+ target_psw_t psw;
+ abi_ulong gprs[16];
+ abi_uint acrs[16];
+ abi_ulong orig_gpr2;
+};
+
+#endif /* S390X_TARGET_PTRACE_H */
diff --git a/linux-user/s390x/target_syscall.h b/linux-user/s390x/target_syscall.h
index 4018988a25..f01f9a0baa 100644
--- a/linux-user/s390x/target_syscall.h
+++ b/linux-user/s390x/target_syscall.h
@@ -1,28 +1,6 @@
#ifndef S390X_TARGET_SYSCALL_H
#define S390X_TARGET_SYSCALL_H
-/* this typedef defines how a Program Status Word looks like */
-typedef struct {
- abi_ulong mask;
- abi_ulong addr;
-} __attribute__ ((aligned(8))) target_psw_t;
-
-/*
- * The pt_regs struct defines the way the registers are stored on
- * the stack during a system call.
- */
-
-#define TARGET_NUM_GPRS 16
-
-struct target_pt_regs {
- abi_ulong args[1];
- target_psw_t psw;
- abi_ulong gprs[TARGET_NUM_GPRS];
- abi_ulong orig_gpr2;
- unsigned short ilen;
- unsigned short trap;
-};
-
#define UNAME_MACHINE "s390x"
#define UNAME_MINIMUM_RELEASE "2.6.32"
diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index df49c24708..96d1c8d11c 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -22,6 +22,7 @@
#include "signal-common.h"
#include "linux-user/trace.h"
#include "vdso-asmoffset.h"
+#include "target_ptrace.h"
#define __NUM_GPRS 16
#define __NUM_FPRS 16
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 51/87] linux-user/s390x: Create target_ptrace.h
2025-08-28 12:08 ` [PATCH v3 51/87] linux-user/s390x: Create target_ptrace.h Richard Henderson
@ 2025-08-28 15:10 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 15:10 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:14, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move target_psw_t to target_ptrace.h.
> Remove the target_pt_regs; add target_s390x_reg to target_ptrace.h,
> which matches what is actually used.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/s390x/target_ptrace.h | 18 ++++++++++++++++++
> linux-user/s390x/target_syscall.h | 22 ----------------------
> linux-user/s390x/signal.c | 1 +
> 3 files changed, 19 insertions(+), 22 deletions(-)
> create mode 100644 linux-user/s390x/target_ptrace.h
>
> diff --git a/linux-user/s390x/target_ptrace.h b/linux-user/s390x/target_ptrace.h
> new file mode 100644
> index 0000000000..a5ceb75a74
> --- /dev/null
> +++ b/linux-user/s390x/target_ptrace.h
> @@ -0,0 +1,18 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +
> +#ifndef S390X_TARGET_PTRACE_H
> +#define S390X_TARGET_PTRACE_H
> +
> +typedef struct {
> + abi_ulong mask;
> + abi_ulong addr;
> +} target_psw_t;
> +
> +struct target_s390_regs {
> + target_psw_t psw;
> + abi_ulong gprs[16];
> + abi_uint acrs[16];
> + abi_ulong orig_gpr2;
> +};
> +
> +#endif /* S390X_TARGET_PTRACE_H */
> diff --git a/linux-user/s390x/target_syscall.h b/linux-user/s390x/target_syscall.h
> index 4018988a25..f01f9a0baa 100644
> --- a/linux-user/s390x/target_syscall.h
> +++ b/linux-user/s390x/target_syscall.h
> @@ -1,28 +1,6 @@
> #ifndef S390X_TARGET_SYSCALL_H
> #define S390X_TARGET_SYSCALL_H
>
> -/* this typedef defines how a Program Status Word looks like */
> -typedef struct {
> - abi_ulong mask;
> - abi_ulong addr;
> -} __attribute__ ((aligned(8))) target_psw_t;
You might mention in the commit message that abi_ulong
already has an aligned attribute which for s390 will be 8,
so it's OK to drop the attribute on the struct here.
Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 52/87] linux-user/s390x: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (50 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 51/87] linux-user/s390x: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:16 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 53/87] linux-user/sh4: Create target_ptrace.h Richard Henderson
` (35 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
This lets us drop the ugly cast to uint32_t* in the middle.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/s390x/target_elf.h | 12 +++++++-----
linux-user/s390x/elfload.c | 28 +++++++---------------------
2 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
index b7d863ee66..670c7b3eed 100644
--- a/linux-user/s390x/target_elf.h
+++ b/linux-user/s390x/target_elf.h
@@ -8,15 +8,17 @@
#ifndef S390X_TARGET_ELF_H
#define S390X_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-/* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs). */
-#define ELF_NREG 27
+/*
+ * See linux kernel: arch/s390/include/asm/elf.h, where
+ * elf_gregset_t is typedef'd to struct s390_regs.
+ */
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ struct target_s390_regs pt;
} target_elf_gregset_t;
#endif
diff --git a/linux-user/s390x/elfload.c b/linux-user/s390x/elfload.c
index 4113273b72..27109279e2 100644
--- a/linux-user/s390x/elfload.c
+++ b/linux-user/s390x/elfload.c
@@ -68,29 +68,15 @@ const char *elf_hwcap_str(uint32_t bit)
return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
}
-#define tswapreg(ptr) tswapal(ptr)
-
-enum {
- TARGET_REG_PSWM = 0,
- TARGET_REG_PSWA = 1,
- TARGET_REG_GPRS = 2,
- TARGET_REG_ARS = 18,
- TARGET_REG_ORIG_R2 = 26,
-};
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUS390XState *env)
{
- int i;
- uint32_t *aregs;
-
- r->regs[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
- r->regs[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
- for (i = 0; i < 16; i++) {
- r->regs[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
+ r->pt.psw.mask = tswapal(env->psw.mask);
+ r->pt.psw.addr = tswapal(env->psw.addr);
+ for (int i = 0; i < 16; i++) {
+ r->pt.gprs[i] = tswapal(env->regs[i]);
}
- aregs = (uint32_t *)&(r->regs[TARGET_REG_ARS]);
- for (i = 0; i < 16; i++) {
- aregs[i] = tswap32(env->aregs[i]);
+ for (int i = 0; i < 16; i++) {
+ r->pt.acrs[i] = tswap32(env->aregs[i]);
}
- r->regs[TARGET_REG_ORIG_R2] = 0;
+ r->pt.orig_gpr2 = 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 52/87] linux-user/s390x: Expand target_elf_gregset_t
2025-08-28 12:08 ` [PATCH v3 52/87] linux-user/s390x: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 15:16 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 15:16 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:14, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Make use of the fact that target_elf_gregset_t is a proper structure.
> This lets us drop the ugly cast to uint32_t* in the middle.
>
> Drop ELF_NREG, target_elf_greg_t, and tswapreg.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/s390x/target_elf.h | 12 +++++++-----
> linux-user/s390x/elfload.c | 28 +++++++---------------------
> 2 files changed, 14 insertions(+), 26 deletions(-)
>
> diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
> index b7d863ee66..670c7b3eed 100644
> --- a/linux-user/s390x/target_elf.h
> +++ b/linux-user/s390x/target_elf.h
> @@ -8,15 +8,17 @@
> #ifndef S390X_TARGET_ELF_H
> #define S390X_TARGET_ELF_H
>
> +#include "target_ptrace.h"
> +
> #define HAVE_ELF_HWCAP 1
> #define HAVE_ELF_CORE_DUMP 1
>
> -typedef abi_ulong target_elf_greg_t;
> -
> -/* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs). */
> -#define ELF_NREG 27
> +/*
> + * See linux kernel: arch/s390/include/asm/elf.h, where
> + * elf_gregset_t is typedef'd to struct s390_regs.
> + */
> typedef struct target_elf_gregset_t {
> - target_elf_greg_t regs[ELF_NREG];
> + struct target_s390_regs pt;
> } target_elf_gregset_t;
>
> #endif
> diff --git a/linux-user/s390x/elfload.c b/linux-user/s390x/elfload.c
> index 4113273b72..27109279e2 100644
> --- a/linux-user/s390x/elfload.c
> +++ b/linux-user/s390x/elfload.c
> @@ -68,29 +68,15 @@ const char *elf_hwcap_str(uint32_t bit)
> return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
> }
>
> -#define tswapreg(ptr) tswapal(ptr)
> -
> -enum {
> - TARGET_REG_PSWM = 0,
> - TARGET_REG_PSWA = 1,
> - TARGET_REG_GPRS = 2,
> - TARGET_REG_ARS = 18,
> - TARGET_REG_ORIG_R2 = 26,
> -};
> -
> void elf_core_copy_regs(target_elf_gregset_t *r, const CPUS390XState *env)
> {
> - int i;
> - uint32_t *aregs;
> -
> - r->regs[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
> - r->regs[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
> - for (i = 0; i < 16; i++) {
> - r->regs[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
> + r->pt.psw.mask = tswapal(env->psw.mask);
> + r->pt.psw.addr = tswapal(env->psw.addr);
> + for (int i = 0; i < 16; i++) {
> + r->pt.gprs[i] = tswapal(env->regs[i]);
> }
> - aregs = (uint32_t *)&(r->regs[TARGET_REG_ARS]);
> - for (i = 0; i < 16; i++) {
> - aregs[i] = tswap32(env->aregs[i]);
> + for (int i = 0; i < 16; i++) {
> + r->pt.acrs[i] = tswap32(env->aregs[i]);
> }
This cleans up that suspicious cast, which is nice.
> - r->regs[TARGET_REG_ORIG_R2] = 0;
> + r->pt.orig_gpr2 = 0;
> }
> -
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 53/87] linux-user/sh4: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (51 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 52/87] linux-user/s390x: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:16 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 54/87] linux-user/sh4: Expand target_elf_gregset_t Richard Henderson
` (34 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move target_pt_regs to target_ptrace.h.
Convert to abi_foo types.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sh4/target_ptrace.h | 18 ++++++++++++++++++
linux-user/sh4/target_syscall.h | 11 -----------
2 files changed, 18 insertions(+), 11 deletions(-)
create mode 100644 linux-user/sh4/target_ptrace.h
diff --git a/linux-user/sh4/target_ptrace.h b/linux-user/sh4/target_ptrace.h
new file mode 100644
index 0000000000..b80218526b
--- /dev/null
+++ b/linux-user/sh4/target_ptrace.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef SH4_TARGET_PTRACE_H
+#define SH4_TARGET_PTRACE_H
+
+/* See arch/sh/include/uapi/asm/ptrace_32.h. */
+struct target_pt_regs {
+ abi_ulong regs[16];
+ abi_ulong pc;
+ abi_ulong pr;
+ abi_ulong sr;
+ abi_ulong gbr;
+ abi_ulong mach;
+ abi_ulong macl;
+ abi_long tra;
+};
+
+#endif /* SH4_TARGET_PTRACE_H */
diff --git a/linux-user/sh4/target_syscall.h b/linux-user/sh4/target_syscall.h
index 148398855d..2f3557742d 100644
--- a/linux-user/sh4/target_syscall.h
+++ b/linux-user/sh4/target_syscall.h
@@ -1,17 +1,6 @@
#ifndef SH4_TARGET_SYSCALL_H
#define SH4_TARGET_SYSCALL_H
-struct target_pt_regs {
- unsigned long regs[16];
- unsigned long pc;
- unsigned long pr;
- unsigned long sr;
- unsigned long gbr;
- unsigned long mach;
- unsigned long macl;
- long tra;
-};
-
#define UNAME_MACHINE "sh4"
#define UNAME_MINIMUM_RELEASE "2.6.32"
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 54/87] linux-user/sh4: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (52 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 53/87] linux-user/sh4: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:17 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 55/87] linux-user/xtensa: Create target_ptrace.h Richard Henderson
` (33 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sh4/target_elf.h | 12 +++++++-----
linux-user/sh4/elfload.c | 28 +++++++---------------------
2 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h
index f7443ddbac..fd3ae68a01 100644
--- a/linux-user/sh4/target_elf.h
+++ b/linux-user/sh4/target_elf.h
@@ -8,15 +8,17 @@
#ifndef SH4_TARGET_ELF_H
#define SH4_TARGET_ELF_H
+#include "target_ptrace.h"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_CORE_DUMP 1
-typedef abi_ulong target_elf_greg_t;
-
-/* See linux kernel: arch/sh/include/asm/elf.h. */
-#define ELF_NREG 23
+/*
+ * See linux kernel: arch/sh/include/asm/elf.h, where
+ * elf_gregset_t is mapped to struct pt_regs via sizeof.
+ */
typedef struct target_elf_gregset_t {
- target_elf_greg_t regs[ELF_NREG];
+ struct target_pt_regs pt;
} target_elf_gregset_t;
#endif
diff --git a/linux-user/sh4/elfload.c b/linux-user/sh4/elfload.c
index 71cae9703e..ddf2aaaed7 100644
--- a/linux-user/sh4/elfload.c
+++ b/linux-user/sh4/elfload.c
@@ -38,30 +38,16 @@ abi_ulong get_elf_hwcap(CPUState *cs)
return hwcap;
}
-#define tswapreg(ptr) tswapal(ptr)
-
-/* See linux kernel: arch/sh/include/asm/ptrace.h. */
-enum {
- TARGET_REG_PC = 16,
- TARGET_REG_PR = 17,
- TARGET_REG_SR = 18,
- TARGET_REG_GBR = 19,
- TARGET_REG_MACH = 20,
- TARGET_REG_MACL = 21,
- TARGET_REG_SYSCALL = 22
-};
-
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUSH4State *env)
{
for (int i = 0; i < 16; i++) {
- r->regs[i] = tswapreg(env->gregs[i]);
+ r->pt.regs[i] = tswapal(env->gregs[i]);
}
- r->regs[TARGET_REG_PC] = tswapreg(env->pc);
- r->regs[TARGET_REG_PR] = tswapreg(env->pr);
- r->regs[TARGET_REG_SR] = tswapreg(env->sr);
- r->regs[TARGET_REG_GBR] = tswapreg(env->gbr);
- r->regs[TARGET_REG_MACH] = tswapreg(env->mach);
- r->regs[TARGET_REG_MACL] = tswapreg(env->macl);
- r->regs[TARGET_REG_SYSCALL] = 0; /* FIXME */
+ r->pt.pc = tswapal(env->pc);
+ r->pt.pr = tswapal(env->pr);
+ r->pt.sr = tswapal(env->sr);
+ r->pt.gbr = tswapal(env->gbr);
+ r->pt.mach = tswapal(env->mach);
+ r->pt.macl = tswapal(env->macl);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 55/87] linux-user/xtensa: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (53 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 54/87] linux-user/sh4: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:18 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 56/87] linux-user/xtensa: Expand target_elf_gregset_t Richard Henderson
` (32 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Remove the target_pt_regs; add target_use_pt_regs to
target_ptrace.h, which matches what is actually used.
Remove xtensa_reg_t and xtregs_opt_t.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/xtensa/target_ptrace.h | 22 +++++++++++++++++++
linux-user/xtensa/target_syscall.h | 35 ------------------------------
2 files changed, 22 insertions(+), 35 deletions(-)
create mode 100644 linux-user/xtensa/target_ptrace.h
diff --git a/linux-user/xtensa/target_ptrace.h b/linux-user/xtensa/target_ptrace.h
new file mode 100644
index 0000000000..32443d0dee
--- /dev/null
+++ b/linux-user/xtensa/target_ptrace.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef XTENSA_TARGET_PTRACE_H
+#define XTENSA_TARGET_PTRACE_H
+
+/* See arch/xtensa/include/uapi/asm/ptrace.h. */
+struct target_user_pt_regs {
+ uint32_t pc;
+ uint32_t ps;
+ uint32_t lbeg;
+ uint32_t lend;
+ uint32_t lcount;
+ uint32_t sar;
+ uint32_t windowstart;
+ uint32_t windowbase;
+ uint32_t threadptr;
+ uint32_t syscall;
+ uint32_t reserved[6 + 48];
+ uint32_t a[64];
+};
+
+#endif /* XTENSA_TARGET_PTRACE_H */
diff --git a/linux-user/xtensa/target_syscall.h b/linux-user/xtensa/target_syscall.h
index afc86a153f..5d4352a4d1 100644
--- a/linux-user/xtensa/target_syscall.h
+++ b/linux-user/xtensa/target_syscall.h
@@ -8,41 +8,6 @@
#define MMAP_SHIFT TARGET_PAGE_BITS
-typedef uint32_t xtensa_reg_t;
-typedef struct {
-} xtregs_opt_t; /* TODO */
-
-struct target_pt_regs {
- xtensa_reg_t pc; /* 4 */
- xtensa_reg_t ps; /* 8 */
- xtensa_reg_t depc; /* 12 */
- xtensa_reg_t exccause; /* 16 */
- xtensa_reg_t excvaddr; /* 20 */
- xtensa_reg_t debugcause; /* 24 */
- xtensa_reg_t wmask; /* 28 */
- xtensa_reg_t lbeg; /* 32 */
- xtensa_reg_t lend; /* 36 */
- xtensa_reg_t lcount; /* 40 */
- xtensa_reg_t sar; /* 44 */
- xtensa_reg_t windowbase; /* 48 */
- xtensa_reg_t windowstart; /* 52 */
- xtensa_reg_t syscall; /* 56 */
- xtensa_reg_t icountlevel; /* 60 */
- xtensa_reg_t scompare1; /* 64 */
- xtensa_reg_t threadptr; /* 68 */
-
- /* Additional configurable registers that are used by the compiler. */
- xtregs_opt_t xtregs_opt;
-
- /* Make sure the areg field is 16 bytes aligned. */
- int align[0] __attribute__ ((aligned(16)));
-
- /* current register frame.
- * Note: The ESF for kernel exceptions ends after 16 registers!
- */
- xtensa_reg_t areg[16];
-};
-
#define TARGET_MCL_CURRENT 1
#define TARGET_MCL_FUTURE 2
#define TARGET_MCL_ONFAULT 4
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 55/87] linux-user/xtensa: Create target_ptrace.h
2025-08-28 12:08 ` [PATCH v3 55/87] linux-user/xtensa: Create target_ptrace.h Richard Henderson
@ 2025-08-28 15:18 ` Peter Maydell
0 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 15:18 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:14, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Remove the target_pt_regs; add target_use_pt_regs to
"user"
> target_ptrace.h, which matches what is actually used.
> Remove xtensa_reg_t and xtregs_opt_t.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/xtensa/target_ptrace.h | 22 +++++++++++++++++++
> linux-user/xtensa/target_syscall.h | 35 ------------------------------
> 2 files changed, 22 insertions(+), 35 deletions(-)
> create mode 100644 linux-user/xtensa/target_ptrace.h
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread
* [PATCH v3 56/87] linux-user/xtensa: Expand target_elf_gregset_t
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (54 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 55/87] linux-user/xtensa: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:18 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 57/87] linux-user: Move init_guest_commpage to x86_64/elfload.c Richard Henderson
` (31 subsequent siblings)
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Make use of the fact that target_elf_gregset_t is a proper structure.
Drop ELF_NREG, target_elf_greg_t, and tswapreg.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/xtensa/target_elf.h | 12 ++++++-----
linux-user/xtensa/elfload.c | 39 +++++++++++-----------------------
2 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/linux-user/xtensa/target_elf.h b/linux-user/xtensa/target_elf.h
index 43e241aac1..850a7206a5 100644
--- a/linux-user/xtensa/target_elf.h
+++ b/linux-user/xtensa/target_elf.h
@@ -8,14 +8,16 @@
#ifndef XTENSA_TARGET_ELF_H
#define XTENSA_TARGET_ELF_H
+#include "target_ptrace.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
+/*
+ * See linux kernel: arch/xtensa/include/asm/elf.h, where elf_gregset_t
+ * is mapped to struct user_pt_regs via typedef and sizeof.
+ */
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/xtensa/elfload.c b/linux-user/xtensa/elfload.c
index 49e709a094..68aeed855f 100644
--- a/linux-user/xtensa/elfload.c
+++ b/linux-user/xtensa/elfload.c
@@ -11,36 +11,21 @@ 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->pt.pc = tswap32(env->pc);
+ r->pt.ps = tswap32(env->sregs[PS] & ~PS_EXCM);
+ r->pt.lbeg = tswap32(env->sregs[LBEG]);
+ r->pt.lend = tswap32(env->sregs[LEND]);
+ r->pt.lcount = tswap32(env->sregs[LCOUNT]);
+ r->pt.sar = tswap32(env->sregs[SAR]);
+ r->pt.windowstart = tswap32(env->sregs[WINDOW_START]);
+ r->pt.windowbase = tswap32(env->sregs[WINDOW_BASE]);
+ r->pt.threadptr = tswap32(env->uregs[THREADPTR]);
- 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]);
+
+ for (unsigned i = 0; i < env->config->nareg; ++i) {
+ r->pt.a[i] = tswap32(env->phys_regs[i]);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 57/87] linux-user: Move init_guest_commpage to x86_64/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (55 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 56/87] linux-user/xtensa: Expand target_elf_gregset_t Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 58/87] linux-user: Move init_guest_commpage to arm/elfload.c Richard Henderson
` (30 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Rename INIT_GUEST_COMMPAGE to HAVE_GUEST_COMMPAGE
to match the other HAVE_* defines.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/loader.h | 3 +++
linux-user/x86_64/target_elf.h | 1 +
linux-user/elfload.c | 23 +----------------------
linux-user/x86_64/elfload.c | 20 ++++++++++++++++++++
4 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 8f4a7f69ac..98015fba7d 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -105,6 +105,9 @@ const char *elf_hwcap_str(uint32_t bit);
const char *elf_hwcap2_str(uint32_t bit);
const char *get_elf_platform(CPUState *cs);
const char *get_elf_base_platform(CPUState *cs);
+#if defined(TARGET_X86_64)
+bool init_guest_commpage(void);
+#endif
struct target_elf_gregset_t;
void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *);
diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h
index 32a9eec431..f05b1d4dba 100644
--- a/linux-user/x86_64/target_elf.h
+++ b/linux-user/x86_64/target_elf.h
@@ -13,6 +13,7 @@
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
+#define HAVE_GUEST_COMMPAGE 1
/*
* See linux kernel: arch/x86/include/asm/elf.h, where
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 07d83c674d..0ba75a83b3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -145,27 +145,6 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS64
#define ELF_ARCH EM_X86_64
-#if ULONG_MAX > UINT32_MAX
-#define INIT_GUEST_COMMPAGE
-static bool init_guest_commpage(void)
-{
- /*
- * The vsyscall page is at a high negative address aka kernel space,
- * which means that we cannot actually allocate it with target_mmap.
- * We still should be able to use page_set_flags, unless the user
- * has specified -R reserved_va, which would trigger an assert().
- */
- if (reserved_va != 0 &&
- TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 > reserved_va) {
- error_report("Cannot allocate vsyscall page");
- exit(EXIT_FAILURE);
- }
- page_set_flags(TARGET_VSYSCALL_PAGE,
- TARGET_VSYSCALL_PAGE | ~TARGET_PAGE_MASK,
- PAGE_EXEC | PAGE_VALID);
- return true;
-}
-#endif
#else
/*
@@ -1215,7 +1194,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
#else
#define HI_COMMPAGE 0
#define LO_COMMPAGE -1
-#ifndef INIT_GUEST_COMMPAGE
+#ifndef HAVE_GUEST_COMMPAGE
#define init_guest_commpage() true
#endif
#endif
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
index 12de1c54c7..1e7000c6bc 100644
--- a/linux-user/x86_64/elfload.c
+++ b/linux-user/x86_64/elfload.c
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "qemu/osdep.h"
+#include "qemu/error-report.h"
#include "qemu.h"
#include "loader.h"
#include "target_elf.h"
@@ -21,6 +22,25 @@ const char *get_elf_platform(CPUState *cs)
return "x86_64";
}
+bool init_guest_commpage(void)
+{
+ /*
+ * The vsyscall page is at a high negative address aka kernel space,
+ * which means that we cannot actually allocate it with target_mmap.
+ * We still should be able to use page_set_flags, unless the user
+ * has specified -R reserved_va, which would trigger an assert().
+ */
+ if (reserved_va != 0 &&
+ TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 > reserved_va) {
+ error_report("Cannot allocate vsyscall page");
+ exit(EXIT_FAILURE);
+ }
+ page_set_flags(TARGET_VSYSCALL_PAGE,
+ TARGET_VSYSCALL_PAGE | ~TARGET_PAGE_MASK,
+ PAGE_EXEC | PAGE_VALID);
+ return true;
+}
+
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
{
r->pt.r15 = tswapal(env->regs[15]);
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 58/87] linux-user: Move init_guest_commpage to arm/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (56 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 57/87] linux-user: Move init_guest_commpage to x86_64/elfload.c Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 59/87] linux-user: Move init_guest_commpage to hppa/elfload.c Richard Henderson
` (29 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/arm/target_elf.h | 2 ++
linux-user/loader.h | 2 +-
linux-user/arm/elfload.c | 46 +++++++++++++++++++++++++++++++++++
linux-user/elfload.c | 48 -------------------------------------
4 files changed, 49 insertions(+), 49 deletions(-)
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index fa8f8af2f3..5f81a43efb 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -15,6 +15,8 @@
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
+#define HI_COMMPAGE ((intptr_t)0xffff0f00u)
+
/*
* See linux kernel: arch/arm/include/asm/elf.h, where
* elf_gregset_t is mapped to struct pt_regs via sizeof.
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 98015fba7d..0c2cc556c3 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -105,7 +105,7 @@ const char *elf_hwcap_str(uint32_t bit);
const char *elf_hwcap2_str(uint32_t bit);
const char *get_elf_platform(CPUState *cs);
const char *get_elf_base_platform(CPUState *cs);
-#if defined(TARGET_X86_64)
+#if defined(TARGET_X86_64) || defined(TARGET_ARM)
bool init_guest_commpage(void);
#endif
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index 726d3ec25c..a3f14af691 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -3,6 +3,8 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
+#include "user-internals.h"
+#include "target_elf.h"
#include "target/arm/cpu-features.h"
#include "target_elf.h"
@@ -201,6 +203,50 @@ const char *get_elf_platform(CPUState *cs)
#undef END
}
+bool init_guest_commpage(void)
+{
+ ARMCPU *cpu = ARM_CPU(thread_cpu);
+ int host_page_size = qemu_real_host_page_size();
+ abi_ptr commpage;
+ void *want;
+ void *addr;
+
+ /*
+ * M-profile allocates maximum of 2GB address space, so can never
+ * allocate the commpage. Skip it.
+ */
+ if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
+ return true;
+ }
+
+ commpage = HI_COMMPAGE & -host_page_size;
+ want = g2h_untagged(commpage);
+ addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE |
+ (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE),
+ -1, 0);
+
+ if (addr == MAP_FAILED) {
+ perror("Allocating guest commpage");
+ exit(EXIT_FAILURE);
+ }
+ if (addr != want) {
+ return false;
+ }
+
+ /* Set kernel helper versions; rest of page is 0. */
+ __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
+
+ if (mprotect(addr, host_page_size, PROT_READ)) {
+ perror("Protecting guest commpage");
+ exit(EXIT_FAILURE);
+ }
+
+ page_set_flags(commpage, commpage | (host_page_size - 1),
+ PAGE_READ | PAGE_EXEC | PAGE_VALID);
+ return true;
+}
+
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
for (int i = 0; i < 16; ++i) {
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0ba75a83b3..2281853c57 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -191,54 +191,6 @@ typedef abi_int target_pid_t;
#define ELF_EXEC_PAGESIZE 4096
-/* The commpage only exists for 32 bit kernels */
-
-#define HI_COMMPAGE (intptr_t)0xffff0f00u
-
-static bool init_guest_commpage(void)
-{
- ARMCPU *cpu = ARM_CPU(thread_cpu);
- int host_page_size = qemu_real_host_page_size();
- abi_ptr commpage;
- void *want;
- void *addr;
-
- /*
- * M-profile allocates maximum of 2GB address space, so can never
- * allocate the commpage. Skip it.
- */
- if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
- return true;
- }
-
- commpage = HI_COMMPAGE & -host_page_size;
- want = g2h_untagged(commpage);
- addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE |
- (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE),
- -1, 0);
-
- if (addr == MAP_FAILED) {
- perror("Allocating guest commpage");
- exit(EXIT_FAILURE);
- }
- if (addr != want) {
- return false;
- }
-
- /* Set kernel helper versions; rest of page is 0. */
- __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
-
- if (mprotect(addr, host_page_size, PROT_READ)) {
- perror("Protecting guest commpage");
- exit(EXIT_FAILURE);
- }
-
- page_set_flags(commpage, commpage | (host_page_size - 1),
- PAGE_READ | PAGE_EXEC | PAGE_VALID);
- return true;
-}
-
#if TARGET_BIG_ENDIAN
#include "elf.h"
#include "vdso-be8.c.inc"
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 59/87] linux-user: Move init_guest_commpage to hppa/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (57 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 58/87] linux-user: Move init_guest_commpage to arm/elfload.c Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 60/87] linux-user: Replace init_guest_commpage macro with function Richard Henderson
` (28 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/hppa/target_elf.h | 2 ++
linux-user/loader.h | 2 --
linux-user/elfload.c | 32 --------------------------------
linux-user/hppa/elfload.c | 31 +++++++++++++++++++++++++++++++
4 files changed, 33 insertions(+), 34 deletions(-)
diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h
index 85be00584d..b654758afa 100644
--- a/linux-user/hppa/target_elf.h
+++ b/linux-user/hppa/target_elf.h
@@ -10,4 +10,6 @@
#define HAVE_ELF_PLATFORM 1
+#define LO_COMMPAGE 0
+
#endif
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 0c2cc556c3..c3b8f92e23 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -105,9 +105,7 @@ const char *elf_hwcap_str(uint32_t bit);
const char *elf_hwcap2_str(uint32_t bit);
const char *get_elf_platform(CPUState *cs);
const char *get_elf_base_platform(CPUState *cs);
-#if defined(TARGET_X86_64) || defined(TARGET_ARM)
bool init_guest_commpage(void);
-#endif
struct target_elf_gregset_t;
void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *);
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 2281853c57..25f29e60de 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -415,38 +415,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
#define VDSO_HEADER "vdso.c.inc"
-#define LO_COMMPAGE 0
-
-static bool init_guest_commpage(void)
-{
- /* If reserved_va, then we have already mapped 0 page on the host. */
- if (!reserved_va) {
- void *want, *addr;
-
- want = g2h_untagged(LO_COMMPAGE);
- addr = mmap(want, TARGET_PAGE_SIZE, PROT_NONE,
- MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED_NOREPLACE, -1, 0);
- if (addr == MAP_FAILED) {
- perror("Allocating guest commpage");
- exit(EXIT_FAILURE);
- }
- if (addr != want) {
- return false;
- }
- }
-
- /*
- * On Linux, page zero is normally marked execute only + gateway.
- * Normal read or write is supposed to fail (thus PROT_NONE above),
- * but specific offsets have kernel code mapped to raise permissions
- * and implement syscalls. Here, simply mark the page executable.
- * Special case the entry points during translation (see do_page_zero).
- */
- page_set_flags(LO_COMMPAGE, LO_COMMPAGE | ~TARGET_PAGE_MASK,
- PAGE_EXEC | PAGE_VALID);
- return true;
-}
-
#endif /* TARGET_HPPA */
#ifdef TARGET_XTENSA
diff --git a/linux-user/hppa/elfload.c b/linux-user/hppa/elfload.c
index 9dd3fe092a..018034f244 100644
--- a/linux-user/hppa/elfload.c
+++ b/linux-user/hppa/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)
@@ -14,3 +15,33 @@ const char *get_elf_platform(CPUState *cs)
{
return "PARISC";
}
+
+bool init_guest_commpage(void)
+{
+ /* If reserved_va, then we have already mapped 0 page on the host. */
+ if (!reserved_va) {
+ void *want, *addr;
+
+ want = g2h_untagged(LO_COMMPAGE);
+ addr = mmap(want, TARGET_PAGE_SIZE, PROT_NONE,
+ MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED_NOREPLACE, -1, 0);
+ if (addr == MAP_FAILED) {
+ perror("Allocating guest commpage");
+ exit(EXIT_FAILURE);
+ }
+ if (addr != want) {
+ return false;
+ }
+ }
+
+ /*
+ * On Linux, page zero is normally marked execute only + gateway.
+ * Normal read or write is supposed to fail (thus PROT_NONE above),
+ * but specific offsets have kernel code mapped to raise permissions
+ * and implement syscalls. Here, simply mark the page executable.
+ * Special case the entry points during translation (see do_page_zero).
+ */
+ page_set_flags(LO_COMMPAGE, LO_COMMPAGE | ~TARGET_PAGE_MASK,
+ PAGE_EXEC | PAGE_VALID);
+ return true;
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 60/87] linux-user: Replace init_guest_commpage macro with function
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (58 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 59/87] linux-user: Move init_guest_commpage to hppa/elfload.c Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 61/87] linux-user: Move get_vdso_image_info to arm/elfload.c Richard Henderson
` (27 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Turn the fallback macro into a function. This will produce
a link error if the other macros are set up incorrectly.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 25f29e60de..81bf05f581 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1115,7 +1115,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
#define HI_COMMPAGE 0
#define LO_COMMPAGE -1
#ifndef HAVE_GUEST_COMMPAGE
-#define init_guest_commpage() true
+bool init_guest_commpage(void) { return true; }
#endif
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 61/87] linux-user: Move get_vdso_image_info to arm/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (59 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 60/87] linux-user: Replace init_guest_commpage macro with function Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 62/87] linux-user: Remove ELF_EXEC_PAGESIZE Richard Henderson
` (26 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Rename from vdso_image_info to avoid a symbol clash.
Define HAVE_VDSO_IMAGE_INFO to signal the external definition exists.
Provide fallback versions for other targets.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/arm/target_elf.h | 1 +
linux-user/loader.h | 12 +++++++++++
linux-user/arm/elfload.c | 20 ++++++++++++++++++
linux-user/elfload.c | 41 ++++++++-----------------------------
4 files changed, 42 insertions(+), 32 deletions(-)
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 5f81a43efb..19fdfa2f2c 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -14,6 +14,7 @@
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
+#define HAVE_VDSO_IMAGE_INFO 1
#define HI_COMMPAGE ((intptr_t)0xffff0f00u)
diff --git a/linux-user/loader.h b/linux-user/loader.h
index c3b8f92e23..2175dd4e0a 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -110,4 +110,16 @@ bool init_guest_commpage(void);
struct target_elf_gregset_t;
void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *);
+typedef struct {
+ const uint8_t *image;
+ const uint32_t *relocs;
+ unsigned image_size;
+ unsigned reloc_count;
+ unsigned sigreturn_ofs;
+ unsigned rt_sigreturn_ofs;
+} VdsoImageInfo;
+
+/* Note that both Elf32_Word and Elf64_Word are uint32_t. */
+const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags);
+
#endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index a3f14af691..7e804d82a3 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -7,6 +7,7 @@
#include "target_elf.h"
#include "target/arm/cpu-features.h"
#include "target_elf.h"
+#include "elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
@@ -255,3 +256,22 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
r->pt.cpsr = tswapal(cpsr_read((CPUARMState *)env));
r->pt.orig_r0 = tswapal(env->regs[0]);
}
+
+#if TARGET_BIG_ENDIAN
+# include "vdso-be8.c.inc"
+# include "vdso-be32.c.inc"
+#else
+# include "vdso-le.c.inc"
+#endif
+
+const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags)
+{
+#if TARGET_BIG_ENDIAN
+ return (EF_ARM_EABI_VERSION(elf_flags) >= EF_ARM_EABI_VER4
+ && (elf_flags & EF_ARM_BE8)
+ ? &vdso_be8_image_info
+ : &vdso_be32_image_info);
+#else
+ return &vdso_image_info;
+#endif
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 81bf05f581..aed390ebb3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -40,15 +40,6 @@
#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0
#endif
-typedef struct {
- const uint8_t *image;
- const uint32_t *relocs;
- unsigned image_size;
- unsigned reloc_count;
- unsigned sigreturn_ofs;
- unsigned rt_sigreturn_ofs;
-} VdsoImageInfo;
-
#define ELF_OSABI ELFOSABI_SYSV
/* from personality.h */
@@ -191,23 +182,6 @@ typedef abi_int target_pid_t;
#define ELF_EXEC_PAGESIZE 4096
-#if TARGET_BIG_ENDIAN
-#include "elf.h"
-#include "vdso-be8.c.inc"
-#include "vdso-be32.c.inc"
-
-static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
-{
- return (EF_ARM_EABI_VERSION(elf_flags) >= EF_ARM_EABI_VER4
- && (elf_flags & EF_ARM_BE8)
- ? &vdso_be8_image_info
- : &vdso_be32_image_info);
-}
-#define vdso_image_info vdso_image_info
-#else
-# define VDSO_HEADER "vdso-le.c.inc"
-#endif
-
#else
/* 64 bit ARM definitions */
@@ -1973,14 +1947,17 @@ static void load_elf_interp(const char *filename, struct image_info *info,
load_elf_image(filename, &src, info, &ehdr, NULL);
}
-#ifndef vdso_image_info
+#ifndef HAVE_VDSO_IMAGE_INFO
+const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags)
+{
#ifdef VDSO_HEADER
#include VDSO_HEADER
-#define vdso_image_info(flags) &vdso_image_info
+ return &vdso_image_info;
#else
-#define vdso_image_info(flags) NULL
-#endif /* VDSO_HEADER */
-#endif /* vdso_image_info */
+ return NULL;
+#endif
+}
+#endif /* HAVE_VDSO_IMAGE_INFO */
static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso)
{
@@ -2311,7 +2288,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
* Load a vdso if available, which will amongst other things contain the
* signal trampolines. Otherwise, allocate a separate page for them.
*/
- const VdsoImageInfo *vdso = vdso_image_info(info->elf_flags);
+ const VdsoImageInfo *vdso = get_vdso_image_info(info->elf_flags);
if (vdso) {
load_elf_vdso(&vdso_info, vdso);
info->vdso = vdso_info.load_bias;
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 62/87] linux-user: Remove ELF_EXEC_PAGESIZE
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (60 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 61/87] linux-user: Move get_vdso_image_info to arm/elfload.c Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 63/87] linux-user: Remove redundant ELF_DATA definitons Richard Henderson
` (25 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Use TARGET_PAGE_SIZE instead. If the target page size may vary,
using a different fixed size is wrong.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 32 ++------------------------------
1 file changed, 2 insertions(+), 30 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index aed390ebb3..59e6605e36 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -167,8 +167,6 @@ typedef abi_int target_pid_t;
#define VDSO_HEADER "vdso.c.inc"
-#define ELF_EXEC_PAGESIZE 4096
-
#endif /* TARGET_I386 */
#ifdef TARGET_ARM
@@ -180,16 +178,12 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS32
#define EXSTACK_DEFAULT true
-#define ELF_EXEC_PAGESIZE 4096
-
#else
/* 64 bit ARM definitions */
#define ELF_ARCH EM_AARCH64
#define ELF_CLASS ELFCLASS64
-#define ELF_EXEC_PAGESIZE 4096
-
#if TARGET_BIG_ENDIAN
# define VDSO_HEADER "vdso-be.c.inc"
#else
@@ -258,8 +252,6 @@ typedef abi_int target_pid_t;
NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \
} while (0)
-#define ELF_EXEC_PAGESIZE 4096
-
#ifndef TARGET_PPC64
# define VDSO_HEADER "vdso-32.c.inc"
#elif TARGET_BIG_ENDIAN
@@ -280,8 +272,6 @@ typedef abi_int target_pid_t;
#define VDSO_HEADER "vdso.c.inc"
-#define ELF_EXEC_PAGESIZE 4096
-
#endif /* TARGET_LOONGARCH64 */
#ifdef TARGET_MIPS
@@ -300,8 +290,6 @@ typedef abi_int target_pid_t;
#define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
#endif
-#define ELF_EXEC_PAGESIZE 4096
-
#endif /* TARGET_MIPS */
#ifdef TARGET_MICROBLAZE
@@ -311,8 +299,6 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS32
#define ELF_ARCH EM_MICROBLAZE
-#define ELF_EXEC_PAGESIZE 4096
-
#endif /* TARGET_MICROBLAZE */
#ifdef TARGET_OPENRISC
@@ -321,8 +307,6 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS32
#define ELF_DATA ELFDATA2MSB
-#define ELF_EXEC_PAGESIZE 8192
-
#endif /* TARGET_OPENRISC */
#ifdef TARGET_SH4
@@ -330,8 +314,6 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS32
#define ELF_ARCH EM_SH
-#define ELF_EXEC_PAGESIZE 4096
-
#endif
#ifdef TARGET_M68K
@@ -339,8 +321,6 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS32
#define ELF_ARCH EM_68K
-#define ELF_EXEC_PAGESIZE 8192
-
#endif
#ifdef TARGET_ALPHA
@@ -348,8 +328,6 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS64
#define ELF_ARCH EM_ALPHA
-#define ELF_EXEC_PAGESIZE 8192
-
#endif /* TARGET_ALPHA */
#ifdef TARGET_S390X
@@ -358,8 +336,6 @@ typedef abi_int target_pid_t;
#define ELF_DATA ELFDATA2MSB
#define ELF_ARCH EM_S390
-#define ELF_EXEC_PAGESIZE 4096
-
#define VDSO_HEADER "vdso.c.inc"
#endif /* TARGET_S390X */
@@ -376,8 +352,6 @@ typedef abi_int target_pid_t;
#define VDSO_HEADER "vdso-64.c.inc"
#endif
-#define ELF_EXEC_PAGESIZE 4096
-
#endif /* TARGET_RISCV */
#ifdef TARGET_HPPA
@@ -396,8 +370,6 @@ typedef abi_int target_pid_t;
#define ELF_CLASS ELFCLASS32
#define ELF_ARCH EM_XTENSA
-#define ELF_EXEC_PAGESIZE 4096
-
#endif /* TARGET_XTENSA */
#ifdef TARGET_HEXAGON
@@ -2697,7 +2669,7 @@ static int wmr_fill_region_phdr(void *opaque, vaddr start,
phdr->p_flags = (flags & PAGE_READ ? PF_R : 0)
| (flags & PAGE_WRITE_ORG ? PF_W : 0)
| (flags & PAGE_EXEC ? PF_X : 0);
- phdr->p_align = ELF_EXEC_PAGESIZE;
+ phdr->p_align = TARGET_PAGE_SIZE;
bswap_phdr(phdr, 1);
d->phdr = phdr + 1;
@@ -2805,7 +2777,7 @@ static int elf_core_dump(int signr, const CPUArchState *env)
offset += size_note("CORE", sizeof(struct target_elf_prpsinfo));
offset += size_note("CORE", sizeof(struct target_elf_prstatus)) * cpus;
note_size = offset - note_offset;
- data_offset = ROUND_UP(offset, ELF_EXEC_PAGESIZE);
+ data_offset = TARGET_PAGE_ALIGN(offset);
/* Do not dump if the corefile size exceeds the limit. */
if (dumpsize.rlim_cur != RLIM_INFINITY
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 63/87] linux-user: Remove redundant ELF_DATA definitons
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (61 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 62/87] linux-user: Remove ELF_EXEC_PAGESIZE Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 64/87] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h Richard Henderson
` (24 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
We already provide ELF_DATA based on TARGET_BIG_ENDIAN.
Remove the extra definitions from openrisc and s390x.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 59e6605e36..8ff9f83bb8 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -305,7 +305,6 @@ typedef abi_int target_pid_t;
#define ELF_ARCH EM_OPENRISC
#define ELF_CLASS ELFCLASS32
-#define ELF_DATA ELFDATA2MSB
#endif /* TARGET_OPENRISC */
@@ -333,7 +332,6 @@ typedef abi_int target_pid_t;
#ifdef TARGET_S390X
#define ELF_CLASS ELFCLASS64
-#define ELF_DATA ELFDATA2MSB
#define ELF_ARCH EM_S390
#define VDSO_HEADER "vdso.c.inc"
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 64/87] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (62 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 63/87] linux-user: Remove redundant ELF_DATA definitons Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 65/87] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h Richard Henderson
` (23 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/i386/target_elf.h | 22 +++++++++++++++++++
linux-user/x86_64/target_elf.h | 4 ++++
linux-user/elfload.c | 39 ----------------------------------
3 files changed, 26 insertions(+), 39 deletions(-)
diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index da1e0a09bc..99a95ee45b 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -10,6 +10,11 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_386
+#define EXSTACK_DEFAULT true
+#define VDSO_HEADER "vdso.c.inc"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
@@ -23,4 +28,21 @@ typedef struct target_elf_gregset_t {
struct target_pt_regs pt;
} target_elf_gregset_t;
+/*
+ * This is used to ensure we don't load something for the wrong architecture.
+ */
+#define elf_check_arch(x) ((x) == EM_386 || (x) == EM_486)
+
+/*
+ * i386 is the only target which supplies AT_SYSINFO for the vdso.
+ * All others only supply AT_SYSINFO_EHDR.
+ */
+#define DLINFO_ARCH_ITEMS (vdso_info != NULL)
+#define ARCH_DLINFO \
+ do { \
+ if (vdso_info) { \
+ NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); \
+ } \
+ } while (0)
+
#endif
diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h
index f05b1d4dba..f3c09bb8da 100644
--- a/linux-user/x86_64/target_elf.h
+++ b/linux-user/x86_64/target_elf.h
@@ -10,6 +10,10 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS64
+#define ELF_ARCH EM_X86_64
+#define VDSO_HEADER "vdso.c.inc"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8ff9f83bb8..73ca6c681e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,45 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_I386
-
-#ifdef TARGET_X86_64
-#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_X86_64
-
-#else
-
-/*
- * This is used to ensure we don't load something for the wrong architecture.
- */
-#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) )
-
-/*
- * These are used to set parameters in the core dumps.
- */
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_386
-
-#define EXSTACK_DEFAULT true
-
-/*
- * i386 is the only target which supplies AT_SYSINFO for the vdso.
- * All others only supply AT_SYSINFO_EHDR.
- */
-#define DLINFO_ARCH_ITEMS (vdso_info != NULL)
-#define ARCH_DLINFO \
- do { \
- if (vdso_info) { \
- NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); \
- } \
- } while (0)
-
-#endif /* TARGET_X86_64 */
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#endif /* TARGET_I386 */
-
#ifdef TARGET_ARM
#ifndef TARGET_AARCH64
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 65/87] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (63 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 64/87] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 66/87] linux-user: Move elf parameters to sparc/target_elf.h Richard Henderson
` (22 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/target_elf.h | 9 +++++++++
linux-user/arm/target_elf.h | 4 ++++
linux-user/elfload.c | 25 -------------------------
3 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index 9eb8bb547e..3c9fef9378 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -10,6 +10,9 @@
#include "target_ptrace.h"
+#define ELF_ARCH EM_AARCH64
+#define ELF_CLASS ELFCLASS64
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
@@ -23,4 +26,10 @@ typedef struct target_elf_gregset_t {
struct target_user_pt_regs pt;
} target_elf_gregset_t;
+#if TARGET_BIG_ENDIAN
+# define VDSO_HEADER "vdso-be.c.inc"
+#else
+# define VDSO_HEADER "vdso-le.c.inc"
+#endif
+
#endif
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 19fdfa2f2c..d871d6d665 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -10,6 +10,10 @@
#include "target_ptrace.h"
+#define ELF_ARCH EM_ARM
+#define ELF_CLASS ELFCLASS32
+#define EXSTACK_DEFAULT true
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 73ca6c681e..838d7199a6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,31 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_ARM
-
-#ifndef TARGET_AARCH64
-/* 32 bit ARM definitions */
-
-#define ELF_ARCH EM_ARM
-#define ELF_CLASS ELFCLASS32
-#define EXSTACK_DEFAULT true
-
-#else
-/* 64 bit ARM definitions */
-
-#define ELF_ARCH EM_AARCH64
-#define ELF_CLASS ELFCLASS64
-
-#if TARGET_BIG_ENDIAN
-# define VDSO_HEADER "vdso-be.c.inc"
-#else
-# define VDSO_HEADER "vdso-le.c.inc"
-#endif
-
-#endif /* not TARGET_AARCH64 */
-
-#endif /* TARGET_ARM */
-
#ifdef TARGET_SPARC
#ifndef TARGET_SPARC64
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 66/87] linux-user: Move elf parameters to sparc/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (64 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 65/87] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 67/87] linux-user: Move elf parameters to ppc/target_elf.h Richard Henderson
` (21 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/target_elf.h | 11 +++++++++++
linux-user/elfload.c | 15 ---------------
2 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
index b7544db0a1..f89c708c46 100644
--- a/linux-user/sparc/target_elf.h
+++ b/linux-user/sparc/target_elf.h
@@ -8,6 +8,17 @@
#ifndef SPARC_TARGET_ELF_H
#define SPARC_TARGET_ELF_H
+#ifndef TARGET_SPARC64
+# define ELF_CLASS ELFCLASS32
+# define ELF_ARCH EM_SPARC
+#elif defined(TARGET_ABI32)
+# define ELF_CLASS ELFCLASS32
+# define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
+#else
+# define ELF_CLASS ELFCLASS64
+# define ELF_ARCH EM_SPARCV9
+#endif
+
#define HAVE_ELF_HWCAP 1
#endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 838d7199a6..ccdd87aa12 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,21 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_SPARC
-
-#ifndef TARGET_SPARC64
-# define ELF_CLASS ELFCLASS32
-# define ELF_ARCH EM_SPARC
-#elif defined(TARGET_ABI32)
-# define ELF_CLASS ELFCLASS32
-# define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
-#else
-# define ELF_CLASS ELFCLASS64
-# define ELF_ARCH EM_SPARCV9
-#endif
-
-#endif /* TARGET_SPARC */
-
#ifdef TARGET_PPC
#define ELF_MACHINE PPC_ELF_MACHINE
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 67/87] linux-user: Move elf parameters to ppc/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (65 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 66/87] linux-user: Move elf parameters to sparc/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 68/87] linux-user: Move elf parameters to loongarch64/target_elf.h Richard Henderson
` (20 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/ppc/target_elf.h | 43 ++++++++++++++++++++++++++++++
linux-user/elfload.c | 53 -------------------------------------
2 files changed, 43 insertions(+), 53 deletions(-)
diff --git a/linux-user/ppc/target_elf.h b/linux-user/ppc/target_elf.h
index 2a61cd2896..9a47f18fb8 100644
--- a/linux-user/ppc/target_elf.h
+++ b/linux-user/ppc/target_elf.h
@@ -10,6 +10,17 @@
#include "target_ptrace.h"
+#define ELF_MACHINE PPC_ELF_MACHINE
+
+#ifdef TARGET_PPC64
+# define elf_check_arch(x) ((x) == EM_PPC64)
+# define ELF_CLASS ELFCLASS64
+#else
+# define ELF_CLASS ELFCLASS32
+# define EXSTACK_DEFAULT true
+#endif
+#define ELF_ARCH EM_PPC
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_CORE_DUMP 1
@@ -26,4 +37,36 @@ typedef struct target_elf_gregset_t {
};
} target_elf_gregset_t;
+#ifndef TARGET_PPC64
+# define VDSO_HEADER "vdso-32.c.inc"
+#elif TARGET_BIG_ENDIAN
+# define VDSO_HEADER "vdso-64.c.inc"
+#else
+# define VDSO_HEADER "vdso-64le.c.inc"
+#endif
+
+/*
+ * The requirements here are:
+ * - keep the final alignment of sp (sp & 0xf)
+ * - make sure the 32-bit value at the first 16 byte aligned position of
+ * AUXV is greater than 16 for glibc compatibility.
+ * AT_IGNOREPPC is used for that.
+ * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
+ * even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
+ */
+#define DLINFO_ARCH_ITEMS 5
+#define ARCH_DLINFO \
+ do { \
+ PowerPCCPU *cpu = POWERPC_CPU(thread_cpu); \
+ /* \
+ * Handle glibc compatibility: these magic entries must \
+ * be at the lowest addresses in the final auxv. \
+ */ \
+ NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
+ NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
+ NEW_AUX_ENT(AT_DCACHEBSIZE, cpu->env.dcache_line_size); \
+ NEW_AUX_ENT(AT_ICACHEBSIZE, cpu->env.icache_line_size); \
+ NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \
+ } while (0)
+
#endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index ccdd87aa12..526c90e2c1 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,59 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_PPC
-
-#define ELF_MACHINE PPC_ELF_MACHINE
-
-#if defined(TARGET_PPC64)
-
-#define elf_check_arch(x) ( (x) == EM_PPC64 )
-
-#define ELF_CLASS ELFCLASS64
-
-#else
-
-#define ELF_CLASS ELFCLASS32
-#define EXSTACK_DEFAULT true
-
-#endif
-
-#define ELF_ARCH EM_PPC
-
-/*
- * The requirements here are:
- * - keep the final alignment of sp (sp & 0xf)
- * - make sure the 32-bit value at the first 16 byte aligned position of
- * AUXV is greater than 16 for glibc compatibility.
- * AT_IGNOREPPC is used for that.
- * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
- * even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
- */
-#define DLINFO_ARCH_ITEMS 5
-#define ARCH_DLINFO \
- do { \
- PowerPCCPU *cpu = POWERPC_CPU(thread_cpu); \
- /* \
- * Handle glibc compatibility: these magic entries must \
- * be at the lowest addresses in the final auxv. \
- */ \
- NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
- NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
- NEW_AUX_ENT(AT_DCACHEBSIZE, cpu->env.dcache_line_size); \
- NEW_AUX_ENT(AT_ICACHEBSIZE, cpu->env.icache_line_size); \
- NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \
- } while (0)
-
-#ifndef TARGET_PPC64
-# define VDSO_HEADER "vdso-32.c.inc"
-#elif TARGET_BIG_ENDIAN
-# define VDSO_HEADER "vdso-64.c.inc"
-#else
-# define VDSO_HEADER "vdso-64le.c.inc"
-#endif
-
-#endif
-
#ifdef TARGET_LOONGARCH64
#define ELF_CLASS ELFCLASS64
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 68/87] linux-user: Move elf parameters to loongarch64/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (66 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 67/87] linux-user: Move elf parameters to ppc/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 69/87] linux-user: Move elf parameters to {mips, mips64}/target_elf.h Richard Henderson
` (19 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/loongarch64/target_elf.h | 6 ++++++
linux-user/elfload.c | 12 ------------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index 1f40419af2..47bf51a41c 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -8,6 +8,12 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS64
+#define ELF_ARCH EM_LOONGARCH
+#define EXSTACK_DEFAULT true
+#define elf_check_arch(x) ((x) == EM_LOONGARCH)
+#define VDSO_HEADER "vdso.c.inc"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 526c90e2c1..a4005c44ef 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,18 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_LOONGARCH64
-
-#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_LOONGARCH
-#define EXSTACK_DEFAULT true
-
-#define elf_check_arch(x) ((x) == EM_LOONGARCH)
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#endif /* TARGET_LOONGARCH64 */
-
#ifdef TARGET_MIPS
#ifdef TARGET_MIPS64
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 69/87] linux-user: Move elf parameters to {mips, mips64}/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (67 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 68/87] linux-user: Move elf parameters to loongarch64/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 70/87] linux-user: Move elf parameters to microblaze/target_elf.h Richard Henderson
` (18 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/mips/target_elf.h | 4 ++++
linux-user/mips64/target_elf.h | 10 ++++++++++
linux-user/elfload.c | 18 ------------------
3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/linux-user/mips/target_elf.h b/linux-user/mips/target_elf.h
index a4b7fadbd6..f400bc2fdb 100644
--- a/linux-user/mips/target_elf.h
+++ b/linux-user/mips/target_elf.h
@@ -10,6 +10,10 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_MIPS
+#define EXSTACK_DEFAULT true
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_BASE_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/mips64/target_elf.h b/linux-user/mips64/target_elf.h
index 67bc963134..c455985a76 100644
--- a/linux-user/mips64/target_elf.h
+++ b/linux-user/mips64/target_elf.h
@@ -10,6 +10,16 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS64
+#define ELF_ARCH EM_MIPS
+#define EXSTACK_DEFAULT true
+
+#ifdef TARGET_ABI_MIPSN32
+#define elf_check_abi(x) ((x) & EF_MIPS_ABI2)
+#else
+#define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
+#endif
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_BASE_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a4005c44ef..a67147d43b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,24 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_MIPS
-
-#ifdef TARGET_MIPS64
-#define ELF_CLASS ELFCLASS64
-#else
-#define ELF_CLASS ELFCLASS32
-#endif
-#define ELF_ARCH EM_MIPS
-#define EXSTACK_DEFAULT true
-
-#ifdef TARGET_ABI_MIPSN32
-#define elf_check_abi(x) ((x) & EF_MIPS_ABI2)
-#else
-#define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
-#endif
-
-#endif /* TARGET_MIPS */
-
#ifdef TARGET_MICROBLAZE
#define elf_check_arch(x) ( (x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 70/87] linux-user: Move elf parameters to microblaze/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (68 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 69/87] linux-user: Move elf parameters to {mips, mips64}/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 71/87] linux-user: Move elf parameters to openrisc/target_elf.h Richard Henderson
` (17 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/microblaze/target_elf.h | 5 +++++
linux-user/elfload.c | 9 ---------
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index 56de77d4f3..a622cd8e43 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -10,6 +10,11 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_MICROBLAZE
+
+#define elf_check_arch(x) ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
+
#define HAVE_ELF_CORE_DUMP 1
/*
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a67147d43b..6c8771d804 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,15 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_MICROBLAZE
-
-#define elf_check_arch(x) ( (x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_MICROBLAZE
-
-#endif /* TARGET_MICROBLAZE */
-
#ifdef TARGET_OPENRISC
#define ELF_ARCH EM_OPENRISC
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 71/87] linux-user: Move elf parameters to openrisc/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (69 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 70/87] linux-user: Move elf parameters to microblaze/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 72/87] linux-user: Move elf parameters to sh4/target_elf.h Richard Henderson
` (16 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/openrisc/target_elf.h | 3 +++
linux-user/elfload.c | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/linux-user/openrisc/target_elf.h b/linux-user/openrisc/target_elf.h
index ad80e4b41a..ed9739380f 100644
--- a/linux-user/openrisc/target_elf.h
+++ b/linux-user/openrisc/target_elf.h
@@ -10,6 +10,9 @@
#include "target_ptrace.h"
+#define ELF_ARCH EM_OPENRISC
+#define ELF_CLASS ELFCLASS32
+
#define HAVE_ELF_CORE_DUMP 1
/*
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 6c8771d804..d0993621c1 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,13 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_OPENRISC
-
-#define ELF_ARCH EM_OPENRISC
-#define ELF_CLASS ELFCLASS32
-
-#endif /* TARGET_OPENRISC */
-
#ifdef TARGET_SH4
#define ELF_CLASS ELFCLASS32
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 72/87] linux-user: Move elf parameters to sh4/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (70 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 71/87] linux-user: Move elf parameters to openrisc/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 73/87] linux-user: Move elf parameters to m68k/target_elf.h Richard Henderson
` (15 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sh4/target_elf.h | 3 +++
linux-user/elfload.c | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h
index fd3ae68a01..61aea237c4 100644
--- a/linux-user/sh4/target_elf.h
+++ b/linux-user/sh4/target_elf.h
@@ -10,6 +10,9 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_SH
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index d0993621c1..1a6e81394c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,13 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_SH4
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_SH
-
-#endif
-
#ifdef TARGET_M68K
#define ELF_CLASS ELFCLASS32
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 73/87] linux-user: Move elf parameters to m68k/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (71 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 72/87] linux-user: Move elf parameters to sh4/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 74/87] linux-user: Move elf parameters to alpha/target_elf.h Richard Henderson
` (14 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/m68k/target_elf.h | 3 +++
linux-user/elfload.c | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/linux-user/m68k/target_elf.h b/linux-user/m68k/target_elf.h
index 0737412cee..073c85becc 100644
--- a/linux-user/m68k/target_elf.h
+++ b/linux-user/m68k/target_elf.h
@@ -8,6 +8,9 @@
#ifndef M68K_TARGET_ELF_H
#define M68K_TARGET_ELF_H
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_68K
+
#define HAVE_ELF_CORE_DUMP 1
/*
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1a6e81394c..a3757c595e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,13 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_M68K
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_68K
-
-#endif
-
#ifdef TARGET_ALPHA
#define ELF_CLASS ELFCLASS64
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 74/87] linux-user: Move elf parameters to alpha/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (72 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 73/87] linux-user: Move elf parameters to m68k/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 75/87] linux-user: Move elf parameters to s390x/target_elf.h Richard Henderson
` (13 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/alpha/target_elf.h | 3 +++
linux-user/elfload.c | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/linux-user/alpha/target_elf.h b/linux-user/alpha/target_elf.h
index 52b68680ad..f9d6372c9f 100644
--- a/linux-user/alpha/target_elf.h
+++ b/linux-user/alpha/target_elf.h
@@ -8,4 +8,7 @@
#ifndef ALPHA_TARGET_ELF_H
#define ALPHA_TARGET_ELF_H
+#define ELF_CLASS ELFCLASS64
+#define ELF_ARCH EM_ALPHA
+
#endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a3757c595e..aff800baff 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,13 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_ALPHA
-
-#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_ALPHA
-
-#endif /* TARGET_ALPHA */
-
#ifdef TARGET_S390X
#define ELF_CLASS ELFCLASS64
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 75/87] linux-user: Move elf parameters to s390x/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (73 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 74/87] linux-user: Move elf parameters to alpha/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 76/87] linux-user: Move elf parameters to riscv/target_elf.h Richard Henderson
` (12 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/s390x/target_elf.h | 4 ++++
linux-user/elfload.c | 9 ---------
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
index 670c7b3eed..b23e46ab46 100644
--- a/linux-user/s390x/target_elf.h
+++ b/linux-user/s390x/target_elf.h
@@ -10,6 +10,10 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS64
+#define ELF_ARCH EM_S390
+#define VDSO_HEADER "vdso.c.inc"
+
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index aff800baff..705d726922 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,15 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_S390X
-
-#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_S390
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#endif /* TARGET_S390X */
-
#ifdef TARGET_RISCV
#define ELF_ARCH EM_RISCV
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 76/87] linux-user: Move elf parameters to riscv/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (74 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 75/87] linux-user: Move elf parameters to s390x/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 77/87] linux-user: Move elf parameters to hppa/target_elf.h Richard Henderson
` (11 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/riscv/target_elf.h | 10 ++++++++++
linux-user/elfload.c | 14 --------------
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/linux-user/riscv/target_elf.h b/linux-user/riscv/target_elf.h
index 48d9af557b..51b8def1d1 100644
--- a/linux-user/riscv/target_elf.h
+++ b/linux-user/riscv/target_elf.h
@@ -8,6 +8,16 @@
#ifndef RISCV_TARGET_ELF_H
#define RISCV_TARGET_ELF_H
+#define ELF_ARCH EM_RISCV
+
+#ifdef TARGET_RISCV32
+#define ELF_CLASS ELFCLASS32
+#define VDSO_HEADER "vdso-32.c.inc"
+#else
+#define ELF_CLASS ELFCLASS64
+#define VDSO_HEADER "vdso-64.c.inc"
+#endif
+
#define HAVE_ELF_HWCAP 1
#endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 705d726922..6e476d5308 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,20 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_RISCV
-
-#define ELF_ARCH EM_RISCV
-
-#ifdef TARGET_RISCV32
-#define ELF_CLASS ELFCLASS32
-#define VDSO_HEADER "vdso-32.c.inc"
-#else
-#define ELF_CLASS ELFCLASS64
-#define VDSO_HEADER "vdso-64.c.inc"
-#endif
-
-#endif /* TARGET_RISCV */
-
#ifdef TARGET_HPPA
#define ELF_CLASS ELFCLASS32
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 77/87] linux-user: Move elf parameters to hppa/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (75 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 76/87] linux-user: Move elf parameters to riscv/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 78/87] linux-user: Move elf parameters to xtensa/target_elf.h Richard Henderson
` (10 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/hppa/target_elf.h | 6 ++++++
linux-user/elfload.c | 11 -----------
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h
index b654758afa..9b6363a0a7 100644
--- a/linux-user/hppa/target_elf.h
+++ b/linux-user/hppa/target_elf.h
@@ -8,8 +8,14 @@
#ifndef HPPA_TARGET_ELF_H
#define HPPA_TARGET_ELF_H
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_PARISC
+
#define HAVE_ELF_PLATFORM 1
#define LO_COMMPAGE 0
+#define STACK_GROWS_DOWN 0
+#define STACK_ALIGNMENT 64
+#define VDSO_HEADER "vdso.c.inc"
#endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 6e476d5308..6732011332 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,17 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_HPPA
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_PARISC
-#define STACK_GROWS_DOWN 0
-#define STACK_ALIGNMENT 64
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#endif /* TARGET_HPPA */
-
#ifdef TARGET_XTENSA
#define ELF_CLASS ELFCLASS32
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 78/87] linux-user: Move elf parameters to xtensa/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (76 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 77/87] linux-user: Move elf parameters to hppa/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 79/87] linux-user: Move elf parameters to hexagon/target_elf.h Richard Henderson
` (9 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/xtensa/target_elf.h | 3 +++
linux-user/elfload.c | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/linux-user/xtensa/target_elf.h b/linux-user/xtensa/target_elf.h
index 850a7206a5..0689e79be5 100644
--- a/linux-user/xtensa/target_elf.h
+++ b/linux-user/xtensa/target_elf.h
@@ -10,6 +10,9 @@
#include "target_ptrace.h"
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_XTENSA
+
#define HAVE_ELF_CORE_DUMP 1
/*
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 6732011332..804a819471 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,13 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_XTENSA
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_XTENSA
-
-#endif /* TARGET_XTENSA */
-
#ifdef TARGET_HEXAGON
#define ELF_CLASS ELFCLASS32
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 79/87] linux-user: Move elf parameters to hexagon/target_elf.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (77 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 78/87] linux-user: Move elf parameters to xtensa/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 80/87] linux-user: Standardize on ELF_MACHINE not ELF_ARCH Richard Henderson
` (8 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/hexagon/target_elf.h | 3 +++
linux-user/elfload.c | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/linux-user/hexagon/target_elf.h b/linux-user/hexagon/target_elf.h
index eccf207f6b..a9f6d77fc6 100644
--- a/linux-user/hexagon/target_elf.h
+++ b/linux-user/hexagon/target_elf.h
@@ -18,4 +18,7 @@
#ifndef HEXAGON_TARGET_ELF_H
#define HEXAGON_TARGET_ELF_H
+#define ELF_CLASS ELFCLASS32
+#define ELF_ARCH EM_HEXAGON
+
#endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 804a819471..33c4214c95 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,13 +130,6 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifdef TARGET_HEXAGON
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_HEXAGON
-
-#endif /* TARGET_HEXAGON */
-
#ifndef ELF_MACHINE
#define ELF_MACHINE ELF_ARCH
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 80/87] linux-user: Standardize on ELF_MACHINE not ELF_ARCH
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (78 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 79/87] linux-user: Move elf parameters to hexagon/target_elf.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 81/87] linux-user: Rename elf_check_arch Richard Henderson
` (7 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
PowerPC was the one outlier that defined both ELF_ARCH and
ELF_MACHINE; ELF_ARCH was defined incorrectly, necessitating
the definition of elf_check_arch.
However, the elf file header field in question is called
e_machine, so ELF_MACHINE is in fact the better name.
Mechanically change most target/target_elf.h files,
then adjust ppc/target_elf.h manually.
Do not provide a default for ELF_MACHINE.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/target_elf.h | 2 +-
linux-user/alpha/target_elf.h | 2 +-
linux-user/arm/target_elf.h | 2 +-
linux-user/hexagon/target_elf.h | 2 +-
linux-user/hppa/target_elf.h | 2 +-
linux-user/i386/target_elf.h | 2 +-
linux-user/loongarch64/target_elf.h | 2 +-
linux-user/m68k/target_elf.h | 2 +-
linux-user/microblaze/target_elf.h | 2 +-
linux-user/mips/target_elf.h | 2 +-
linux-user/mips64/target_elf.h | 2 +-
linux-user/openrisc/target_elf.h | 2 +-
linux-user/ppc/target_elf.h | 2 --
linux-user/riscv/target_elf.h | 2 +-
linux-user/s390x/target_elf.h | 2 +-
linux-user/sh4/target_elf.h | 2 +-
linux-user/sparc/target_elf.h | 4 ++--
linux-user/x86_64/target_elf.h | 2 +-
linux-user/xtensa/target_elf.h | 2 +-
linux-user/elfload.c | 6 +-----
20 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index 3c9fef9378..9ec51f6237 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -10,7 +10,7 @@
#include "target_ptrace.h"
-#define ELF_ARCH EM_AARCH64
+#define ELF_MACHINE EM_AARCH64
#define ELF_CLASS ELFCLASS64
#define HAVE_ELF_HWCAP 1
diff --git a/linux-user/alpha/target_elf.h b/linux-user/alpha/target_elf.h
index f9d6372c9f..864dc6e2e6 100644
--- a/linux-user/alpha/target_elf.h
+++ b/linux-user/alpha/target_elf.h
@@ -9,6 +9,6 @@
#define ALPHA_TARGET_ELF_H
#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_ALPHA
+#define ELF_MACHINE EM_ALPHA
#endif
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index d871d6d665..12cdc8e5a7 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -10,7 +10,7 @@
#include "target_ptrace.h"
-#define ELF_ARCH EM_ARM
+#define ELF_MACHINE EM_ARM
#define ELF_CLASS ELFCLASS32
#define EXSTACK_DEFAULT true
diff --git a/linux-user/hexagon/target_elf.h b/linux-user/hexagon/target_elf.h
index a9f6d77fc6..f81ae3895a 100644
--- a/linux-user/hexagon/target_elf.h
+++ b/linux-user/hexagon/target_elf.h
@@ -19,6 +19,6 @@
#define HEXAGON_TARGET_ELF_H
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_HEXAGON
+#define ELF_MACHINE EM_HEXAGON
#endif
diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h
index 9b6363a0a7..76930c9369 100644
--- a/linux-user/hppa/target_elf.h
+++ b/linux-user/hppa/target_elf.h
@@ -9,7 +9,7 @@
#define HPPA_TARGET_ELF_H
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_PARISC
+#define ELF_MACHINE EM_PARISC
#define HAVE_ELF_PLATFORM 1
diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index 99a95ee45b..bb7571f6cb 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_386
+#define ELF_MACHINE EM_386
#define EXSTACK_DEFAULT true
#define VDSO_HEADER "vdso.c.inc"
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index 47bf51a41c..b988592993 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -9,7 +9,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_LOONGARCH
+#define ELF_MACHINE EM_LOONGARCH
#define EXSTACK_DEFAULT true
#define elf_check_arch(x) ((x) == EM_LOONGARCH)
#define VDSO_HEADER "vdso.c.inc"
diff --git a/linux-user/m68k/target_elf.h b/linux-user/m68k/target_elf.h
index 073c85becc..b997fa0b6d 100644
--- a/linux-user/m68k/target_elf.h
+++ b/linux-user/m68k/target_elf.h
@@ -9,7 +9,7 @@
#define M68K_TARGET_ELF_H
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_68K
+#define ELF_MACHINE EM_68K
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index a622cd8e43..1ec91ea5a9 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_MICROBLAZE
+#define ELF_MACHINE EM_MICROBLAZE
#define elf_check_arch(x) ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
diff --git a/linux-user/mips/target_elf.h b/linux-user/mips/target_elf.h
index f400bc2fdb..157306f7a0 100644
--- a/linux-user/mips/target_elf.h
+++ b/linux-user/mips/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_MIPS
+#define ELF_MACHINE EM_MIPS
#define EXSTACK_DEFAULT true
#define HAVE_ELF_HWCAP 1
diff --git a/linux-user/mips64/target_elf.h b/linux-user/mips64/target_elf.h
index c455985a76..061471a0f1 100644
--- a/linux-user/mips64/target_elf.h
+++ b/linux-user/mips64/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_MIPS
+#define ELF_MACHINE EM_MIPS
#define EXSTACK_DEFAULT true
#ifdef TARGET_ABI_MIPSN32
diff --git a/linux-user/openrisc/target_elf.h b/linux-user/openrisc/target_elf.h
index ed9739380f..e8554f5339 100644
--- a/linux-user/openrisc/target_elf.h
+++ b/linux-user/openrisc/target_elf.h
@@ -10,7 +10,7 @@
#include "target_ptrace.h"
-#define ELF_ARCH EM_OPENRISC
+#define ELF_MACHINE EM_OPENRISC
#define ELF_CLASS ELFCLASS32
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/ppc/target_elf.h b/linux-user/ppc/target_elf.h
index 9a47f18fb8..22854cf52f 100644
--- a/linux-user/ppc/target_elf.h
+++ b/linux-user/ppc/target_elf.h
@@ -13,13 +13,11 @@
#define ELF_MACHINE PPC_ELF_MACHINE
#ifdef TARGET_PPC64
-# define elf_check_arch(x) ((x) == EM_PPC64)
# define ELF_CLASS ELFCLASS64
#else
# define ELF_CLASS ELFCLASS32
# define EXSTACK_DEFAULT true
#endif
-#define ELF_ARCH EM_PPC
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_HWCAP2 1
diff --git a/linux-user/riscv/target_elf.h b/linux-user/riscv/target_elf.h
index 51b8def1d1..dbbfdf54d3 100644
--- a/linux-user/riscv/target_elf.h
+++ b/linux-user/riscv/target_elf.h
@@ -8,7 +8,7 @@
#ifndef RISCV_TARGET_ELF_H
#define RISCV_TARGET_ELF_H
-#define ELF_ARCH EM_RISCV
+#define ELF_MACHINE EM_RISCV
#ifdef TARGET_RISCV32
#define ELF_CLASS ELFCLASS32
diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
index b23e46ab46..ef5edbd860 100644
--- a/linux-user/s390x/target_elf.h
+++ b/linux-user/s390x/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_S390
+#define ELF_MACHINE EM_S390
#define VDSO_HEADER "vdso.c.inc"
#define HAVE_ELF_HWCAP 1
diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h
index 61aea237c4..d9e253d425 100644
--- a/linux-user/sh4/target_elf.h
+++ b/linux-user/sh4/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_SH
+#define ELF_MACHINE EM_SH
#define HAVE_ELF_HWCAP 1
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
index f89c708c46..6b0cac3caf 100644
--- a/linux-user/sparc/target_elf.h
+++ b/linux-user/sparc/target_elf.h
@@ -10,13 +10,13 @@
#ifndef TARGET_SPARC64
# define ELF_CLASS ELFCLASS32
-# define ELF_ARCH EM_SPARC
+# define ELF_MACHINE EM_SPARC
#elif defined(TARGET_ABI32)
# define ELF_CLASS ELFCLASS32
# define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
#else
# define ELF_CLASS ELFCLASS64
-# define ELF_ARCH EM_SPARCV9
+# define ELF_MACHINE EM_SPARCV9
#endif
#define HAVE_ELF_HWCAP 1
diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h
index f3c09bb8da..840bddf5ec 100644
--- a/linux-user/x86_64/target_elf.h
+++ b/linux-user/x86_64/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS64
-#define ELF_ARCH EM_X86_64
+#define ELF_MACHINE EM_X86_64
#define VDSO_HEADER "vdso.c.inc"
#define HAVE_ELF_HWCAP 1
diff --git a/linux-user/xtensa/target_elf.h b/linux-user/xtensa/target_elf.h
index 0689e79be5..1bf8f2a14a 100644
--- a/linux-user/xtensa/target_elf.h
+++ b/linux-user/xtensa/target_elf.h
@@ -11,7 +11,7 @@
#include "target_ptrace.h"
#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH EM_XTENSA
+#define ELF_MACHINE EM_XTENSA
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 33c4214c95..c481759710 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,12 +130,8 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifndef ELF_MACHINE
-#define ELF_MACHINE ELF_ARCH
-#endif
-
#ifndef elf_check_arch
-#define elf_check_arch(x) ((x) == ELF_ARCH)
+#define elf_check_arch(x) ((x) == ELF_MACHINE)
#endif
#ifndef elf_check_abi
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 81/87] linux-user: Rename elf_check_arch
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (79 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 80/87] linux-user: Standardize on ELF_MACHINE not ELF_ARCH Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 82/87] linux-user: Remove ELIBBAD from elfload.c Richard Henderson
` (6 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Rename to elf_check_machine to match ELF_MACHINE.
Remove the unnecessary definition for loongarch64.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/i386/target_elf.h | 2 +-
linux-user/loongarch64/target_elf.h | 1 -
linux-user/microblaze/target_elf.h | 2 +-
linux-user/sparc/target_elf.h | 2 +-
linux-user/elfload.c | 6 +++---
5 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index bb7571f6cb..33ce82ab2f 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -31,7 +31,7 @@ typedef struct target_elf_gregset_t {
/*
* This is used to ensure we don't load something for the wrong architecture.
*/
-#define elf_check_arch(x) ((x) == EM_386 || (x) == EM_486)
+#define elf_check_machine(x) ((x) == EM_386 || (x) == EM_486)
/*
* i386 is the only target which supplies AT_SYSINFO for the vdso.
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index b988592993..3aa8c83958 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -11,7 +11,6 @@
#define ELF_CLASS ELFCLASS64
#define ELF_MACHINE EM_LOONGARCH
#define EXSTACK_DEFAULT true
-#define elf_check_arch(x) ((x) == EM_LOONGARCH)
#define VDSO_HEADER "vdso.c.inc"
#define HAVE_ELF_HWCAP 1
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index 1ec91ea5a9..7b3ef70d23 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -13,7 +13,7 @@
#define ELF_CLASS ELFCLASS32
#define ELF_MACHINE EM_MICROBLAZE
-#define elf_check_arch(x) ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
+#define elf_check_machine(x) ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
#define HAVE_ELF_CORE_DUMP 1
diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
index 6b0cac3caf..7827767bcb 100644
--- a/linux-user/sparc/target_elf.h
+++ b/linux-user/sparc/target_elf.h
@@ -13,7 +13,7 @@
# define ELF_MACHINE EM_SPARC
#elif defined(TARGET_ABI32)
# define ELF_CLASS ELFCLASS32
-# define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
+# define elf_check_machine(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
#else
# define ELF_CLASS ELFCLASS64
# define ELF_MACHINE EM_SPARCV9
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index c481759710..aa0eed6dea 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -130,8 +130,8 @@ typedef abi_uint target_gid_t;
#endif
typedef abi_int target_pid_t;
-#ifndef elf_check_arch
-#define elf_check_arch(x) ((x) == ELF_MACHINE)
+#ifndef elf_check_machine
+#define elf_check_machine(x) ((x) == ELF_MACHINE)
#endif
#ifndef elf_check_abi
@@ -346,7 +346,7 @@ static bool elf_check_ident(struct elfhdr *ehdr)
This has to wait until after bswapping the header. */
static bool elf_check_ehdr(struct elfhdr *ehdr)
{
- return (elf_check_arch(ehdr->e_machine)
+ return (elf_check_machine(ehdr->e_machine)
&& elf_check_abi(ehdr->e_flags)
&& ehdr->e_ehsize == sizeof(struct elfhdr)
&& ehdr->e_phentsize == sizeof(struct elf_phdr)
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 82/87] linux-user: Remove ELIBBAD from elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (80 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 81/87] linux-user: Rename elf_check_arch Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 83/87] linux-user: Remove MAP_DENYWRITE " Richard Henderson
` (5 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
The last use of this fallback was removed in 8e62a71738bc.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index aa0eed6dea..c0326928d4 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -110,11 +110,6 @@ int info_is_fdpic(struct image_info *info)
#define MAP_DENYWRITE 0
#endif
-/* should probably go in elf.h */
-#ifndef ELIBBAD
-#define ELIBBAD 80
-#endif
-
#if TARGET_BIG_ENDIAN
#define ELF_DATA ELFDATA2MSB
#else
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 83/87] linux-user: Remove MAP_DENYWRITE from elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (81 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 82/87] linux-user: Remove ELIBBAD from elfload.c Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 84/87] linux-user: Move arch_parse_elf_property to aarch64/elfload.c Richard Henderson
` (4 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
The last use of this fallback was removed in bf858897b769.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index c0326928d4..8b92fba0f0 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -105,11 +105,6 @@ int info_is_fdpic(struct image_info *info)
return info->personality == PER_LINUX_FDPIC;
}
-/* this flag is uneffective under linux too, should be deleted */
-#ifndef MAP_DENYWRITE
-#define MAP_DENYWRITE 0
-#endif
-
#if TARGET_BIG_ENDIAN
#define ELF_DATA ELFDATA2MSB
#else
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 84/87] linux-user: Move arch_parse_elf_property to aarch64/elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (82 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 83/87] linux-user: Remove MAP_DENYWRITE " Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 85/87] linux-user: Remove a.out declarations from elfload.c Richard Henderson
` (3 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Rename the controlling macro to HAVE_ELF_GNU_PROPERTY to
match the other HAVE_* macros.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/target_elf.h | 1 +
linux-user/loader.h | 5 +++++
linux-user/aarch64/elfload.c | 18 +++++++++++++++
linux-user/elfload.c | 39 +++++++--------------------------
4 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index 9ec51f6237..4cdeb64b0d 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -17,6 +17,7 @@
#define HAVE_ELF_HWCAP2 1
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
+#define HAVE_ELF_GNU_PROPERTY 1
/*
* See linux kernel: arch/arm64/include/asm/elf.h, where
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 2175dd4e0a..e42b8fa1e3 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -122,4 +122,9 @@ typedef struct {
/* Note that both Elf32_Word and Elf64_Word are uint32_t. */
const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags);
+bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
+ const uint32_t *data,
+ struct image_info *info,
+ Error **errp);
+
#endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
index 07a0c3f844..8076968251 100644
--- a/linux-user/aarch64/elfload.c
+++ b/linux-user/aarch64/elfload.c
@@ -1,10 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "qemu.h"
#include "loader.h"
#include "target/arm/cpu-features.h"
#include "target_elf.h"
+#include "elf.h"
const char *get_elf_cpu_model(uint32_t eflags)
@@ -349,6 +351,22 @@ const char *get_elf_platform(CPUState *cs)
return TARGET_BIG_ENDIAN ? "aarch64_be" : "aarch64";
}
+bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
+ const uint32_t *data,
+ struct image_info *info,
+ Error **errp)
+{
+ if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
+ if (pr_datasz != sizeof(uint32_t)) {
+ error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND");
+ return false;
+ }
+ /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */
+ info->note_flags = *data;
+ }
+ return true;
+}
+
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
for (int i = 0; i < 31; i++) {
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8b92fba0f0..12d4873212 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -166,41 +166,18 @@ const char *get_elf_platform(CPUState *cs) { return NULL; }
const char *get_elf_base_platform(CPUState *cs) { return NULL; }
#endif
-#include "elf.h"
-
-/* We must delay the following stanzas until after "elf.h". */
-#if defined(TARGET_AARCH64)
-
-static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
- const uint32_t *data,
- struct image_info *info,
- Error **errp)
-{
- if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
- if (pr_datasz != sizeof(uint32_t)) {
- error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND");
- return false;
- }
- /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */
- info->note_flags = *data;
- }
- return true;
-}
-#define ARCH_USE_GNU_PROPERTY 1
-
-#else
-
-static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
- const uint32_t *data,
- struct image_info *info,
- Error **errp)
+#ifndef HAVE_ELF_GNU_PROPERTY
+bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
+ const uint32_t *data, struct image_info *info,
+ Error **errp)
{
g_assert_not_reached();
}
-#define ARCH_USE_GNU_PROPERTY 0
-
+#define HAVE_ELF_GNU_PROPERTY 0
#endif
+#include "elf.h"
+
struct exec
{
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
@@ -1233,7 +1210,7 @@ static bool parse_elf_properties(const ImageSource *src,
uint32_t prev_type;
/* Unless the arch requires properties, ignore them. */
- if (!ARCH_USE_GNU_PROPERTY) {
+ if (!HAVE_ELF_GNU_PROPERTY) {
return true;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 85/87] linux-user: Remove a.out declarations from elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (83 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 84/87] linux-user: Move arch_parse_elf_property to aarch64/elfload.c Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 12:08 ` [PATCH v3 86/87] linux-user/sparc: Create target_ptrace.h Richard Henderson
` (2 subsequent siblings)
87 siblings, 0 replies; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
These should have been removed with the rest of the stub a.out
support in b9329d4b5321, though they were not in use even then.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 19 -------------------
1 file changed, 19 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 12d4873212..26c090c95d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -178,25 +178,6 @@ bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
#include "elf.h"
-struct exec
-{
- unsigned int a_info; /* Use macros N_MAGIC, etc for access */
- unsigned int a_text; /* length of text, in bytes */
- unsigned int a_data; /* length of data, in bytes */
- unsigned int a_bss; /* length of uninitialized data area, in bytes */
- unsigned int a_syms; /* length of symbol table data in file, in bytes */
- unsigned int a_entry; /* start address */
- unsigned int a_trsize; /* length of relocation info for text, in bytes */
- unsigned int a_drsize; /* length of relocation info for data, in bytes */
-};
-
-
-#define N_MAGIC(exec) ((exec).a_info & 0xffff)
-#define OMAGIC 0407
-#define NMAGIC 0410
-#define ZMAGIC 0413
-#define QMAGIC 0314
-
#define DLINFO_ITEMS 16
static inline void memcpy_fromfs(void * to, const void * from, unsigned long n)
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 86/87] linux-user/sparc: Create target_ptrace.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (84 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 85/87] linux-user: Remove a.out declarations from elfload.c Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:19 ` Peter Maydell
2025-08-28 12:08 ` [PATCH v3 87/87] linux-user: Remove target_pt_regs from target_syscall.h Richard Henderson
2025-08-28 15:21 ` [PATCH v3 00/87] linux-user: Split up elfload.c Peter Maydell
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
Move target_pt_regs to target_ptrace.h.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/target_ptrace.h | 24 ++++++++++++++++++++++++
linux-user/sparc/target_syscall.h | 19 -------------------
linux-user/sparc/signal.c | 2 ++
3 files changed, 26 insertions(+), 19 deletions(-)
create mode 100644 linux-user/sparc/target_ptrace.h
diff --git a/linux-user/sparc/target_ptrace.h b/linux-user/sparc/target_ptrace.h
new file mode 100644
index 0000000000..a4d5416c1f
--- /dev/null
+++ b/linux-user/sparc/target_ptrace.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef SPARC_TARGET_PTRACE_H
+#define SPARC_TARGET_PTRACE_H
+
+/* See arch/sparc/include/uapi/asm/ptrace.h. */
+struct target_pt_regs {
+#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
+ abi_ulong u_regs[16];
+ abi_ulong tstate;
+ abi_ulong pc;
+ abi_ulong npc;
+ uint32_t y;
+ uint32_t magic;
+#else
+ abi_ulong psr;
+ abi_ulong pc;
+ abi_ulong npc;
+ abi_ulong y;
+ abi_ulong u_regs[16];
+#endif
+};
+
+#endif /* SPARC_TARGET_PTRACE_H */
diff --git a/linux-user/sparc/target_syscall.h b/linux-user/sparc/target_syscall.h
index e421165357..a90ed2983a 100644
--- a/linux-user/sparc/target_syscall.h
+++ b/linux-user/sparc/target_syscall.h
@@ -1,25 +1,6 @@
#ifndef SPARC_TARGET_SYSCALL_H
#define SPARC_TARGET_SYSCALL_H
-#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
-struct target_pt_regs {
- abi_ulong u_regs[16];
- abi_ulong tstate;
- abi_ulong pc;
- abi_ulong npc;
- uint32_t y;
- uint32_t magic;
-};
-#else
-struct target_pt_regs {
- abi_ulong psr;
- abi_ulong pc;
- abi_ulong npc;
- abi_ulong y;
- abi_ulong u_regs[16];
-};
-#endif
-
#ifdef TARGET_SPARC64
# define UNAME_MACHINE "sparc64"
#else
diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index 8181b8b92c..d339f89928 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -21,6 +21,8 @@
#include "user-internals.h"
#include "signal-common.h"
#include "linux-user/trace.h"
+#include "target_ptrace.h"
+
/* A Sparc register window */
struct target_reg_window {
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* [PATCH v3 87/87] linux-user: Remove target_pt_regs from target_syscall.h
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (85 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 86/87] linux-user/sparc: Create target_ptrace.h Richard Henderson
@ 2025-08-28 12:08 ` Richard Henderson
2025-08-28 15:20 ` Peter Maydell
2025-08-28 15:21 ` [PATCH v3 00/87] linux-user: Split up elfload.c Peter Maydell
87 siblings, 1 reply; 152+ messages in thread
From: Richard Henderson @ 2025-08-28 12:08 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell
All target_pt_regs which have not been broken out to
target_ptrace.h by this point are unused. Remove them.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/alpha/target_syscall.h | 40 -----------------------------
linux-user/hexagon/target_syscall.h | 5 ----
linux-user/hppa/target_syscall.h | 18 -------------
linux-user/m68k/target_syscall.h | 16 ------------
linux-user/riscv/target_syscall.h | 35 -------------------------
5 files changed, 114 deletions(-)
diff --git a/linux-user/alpha/target_syscall.h b/linux-user/alpha/target_syscall.h
index fda3a49f29..53706b749f 100644
--- a/linux-user/alpha/target_syscall.h
+++ b/linux-user/alpha/target_syscall.h
@@ -1,46 +1,6 @@
#ifndef ALPHA_TARGET_SYSCALL_H
#define ALPHA_TARGET_SYSCALL_H
-/* default linux values for the selectors */
-#define __USER_DS (1)
-
-struct target_pt_regs {
- abi_ulong r0;
- abi_ulong r1;
- abi_ulong r2;
- abi_ulong r3;
- abi_ulong r4;
- abi_ulong r5;
- abi_ulong r6;
- abi_ulong r7;
- abi_ulong r8;
- abi_ulong r19;
- abi_ulong r20;
- abi_ulong r21;
- abi_ulong r22;
- abi_ulong r23;
- abi_ulong r24;
- abi_ulong r25;
- abi_ulong r26;
- abi_ulong r27;
- abi_ulong r28;
- abi_ulong hae;
-/* JRP - These are the values provided to a0-a2 by PALcode */
- abi_ulong trap_a0;
- abi_ulong trap_a1;
- abi_ulong trap_a2;
-/* These are saved by PAL-code: */
- abi_ulong ps;
- abi_ulong pc;
- abi_ulong gp;
- abi_ulong r16;
- abi_ulong r17;
- abi_ulong r18;
-/* Those is needed by qemu to temporary store the user stack pointer */
- abi_ulong usp;
- abi_ulong unique;
-};
-
#define UNAME_MACHINE "alpha"
#define UNAME_MINIMUM_RELEASE "2.6.32"
diff --git a/linux-user/hexagon/target_syscall.h b/linux-user/hexagon/target_syscall.h
index 7f91a4abc7..d9c94737a5 100644
--- a/linux-user/hexagon/target_syscall.h
+++ b/linux-user/hexagon/target_syscall.h
@@ -18,11 +18,6 @@
#ifndef HEXAGON_TARGET_SYSCALL_H
#define HEXAGON_TARGET_SYSCALL_H
-struct target_pt_regs {
- abi_long sepc;
- abi_long sp;
-};
-
#define UNAME_MACHINE "hexagon"
#define UNAME_MINIMUM_RELEASE "4.15.0"
diff --git a/linux-user/hppa/target_syscall.h b/linux-user/hppa/target_syscall.h
index 9a8f8ca628..4b21e85371 100644
--- a/linux-user/hppa/target_syscall.h
+++ b/linux-user/hppa/target_syscall.h
@@ -1,24 +1,6 @@
#ifndef HPPA_TARGET_SYSCALL_H
#define HPPA_TARGET_SYSCALL_H
-struct target_pt_regs {
- target_ulong gr[32];
- uint64_t fr[32];
- target_ulong sr[8];
- target_ulong iasq[2];
- target_ulong iaoq[2];
- target_ulong cr27;
- target_ulong __pad0;
- target_ulong orig_r28;
- target_ulong ksp;
- target_ulong kpc;
- target_ulong sar;
- target_ulong iir;
- target_ulong isr;
- target_ulong ior;
- target_ulong ipsw;
-};
-
#define UNAME_MACHINE "parisc"
#define UNAME_MINIMUM_RELEASE "2.6.32"
#define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/m68k/target_syscall.h b/linux-user/m68k/target_syscall.h
index 8d4ddbd76c..3ca0231c70 100644
--- a/linux-user/m68k/target_syscall.h
+++ b/linux-user/m68k/target_syscall.h
@@ -1,22 +1,6 @@
#ifndef M68K_TARGET_SYSCALL_H
#define M68K_TARGET_SYSCALL_H
-/* this struct defines the way the registers are stored on the
- stack during a system call. */
-
-struct target_pt_regs {
- abi_long d1, d2, d3, d4, d5, d6, d7;
- abi_long a0, a1, a2, a3, a4, a5, a6;
- abi_ulong d0;
- abi_ulong usp;
- abi_ulong orig_d0;
- int16_t stkadj;
- uint16_t sr;
- abi_ulong pc;
- uint16_t fntvex;
- uint16_t __fill;
-};
-
#define UNAME_MACHINE "m68k"
#define UNAME_MINIMUM_RELEASE "2.6.32"
diff --git a/linux-user/riscv/target_syscall.h b/linux-user/riscv/target_syscall.h
index 7601f10c28..69a7b753eb 100644
--- a/linux-user/riscv/target_syscall.h
+++ b/linux-user/riscv/target_syscall.h
@@ -8,41 +8,6 @@
#ifndef LINUX_USER_RISCV_TARGET_SYSCALL_H
#define LINUX_USER_RISCV_TARGET_SYSCALL_H
-struct target_pt_regs {
- abi_long sepc;
- abi_long ra;
- abi_long sp;
- abi_long gp;
- abi_long tp;
- abi_long t0;
- abi_long t1;
- abi_long t2;
- abi_long s0;
- abi_long s1;
- abi_long a0;
- abi_long a1;
- abi_long a2;
- abi_long a3;
- abi_long a4;
- abi_long a5;
- abi_long a6;
- abi_long a7;
- abi_long s2;
- abi_long s3;
- abi_long s4;
- abi_long s5;
- abi_long s6;
- abi_long s7;
- abi_long s8;
- abi_long s9;
- abi_long s10;
- abi_long s11;
- abi_long t3;
- abi_long t4;
- abi_long t5;
- abi_long t6;
-};
-
#ifdef TARGET_RISCV32
#define UNAME_MACHINE "riscv32"
#define UNAME_MINIMUM_RELEASE "5.4.0"
--
2.43.0
^ permalink raw reply related [flat|nested] 152+ messages in thread* Re: [PATCH v3 00/87] linux-user: Split up elfload.c
2025-08-28 12:07 [PATCH v3 00/87] linux-user: Split up elfload.c Richard Henderson
` (86 preceding siblings ...)
2025-08-28 12:08 ` [PATCH v3 87/87] linux-user: Remove target_pt_regs from target_syscall.h Richard Henderson
@ 2025-08-28 15:21 ` Peter Maydell
87 siblings, 0 replies; 152+ messages in thread
From: Peter Maydell @ 2025-08-28 15:21 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Thu, 28 Aug 2025 at 13:08, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The goal is to kill the massive target ifdef ladder in elfload.c.
>
> The functions get moved to linux-user/target/elfload.c.
> The macros get moved to linux-user/target/target_elf.h.
> These are mostly use to parameterize include/elf.h or elfload.c.
>
> The init_thread functions, storing into target_pt_regs, have been
> merged with target_cpu_copy_regs, copying out of target_pt_regs
> into CPUArchState. Merging these found a few bits of silliness
> where pt_regs fields were initialized but not used. To encourage
> this never to return, remove most target_pt_regs and hide the rest
> within the relevant signal.c.
>
> Changes for v3:
> - 48 patches merged to master.
> - Don't eliminate target_elf_gregset_t; instead:
> - Convert the array to a struct, which can be declared abstract,
> - Move ptrace-y structure to target_ptrace.h, if applicable.
> - Use it to define target_elf_gregset_t.
> This resolves Peter's primary objection to v2, which over-simplified
> the interface to elf_core_copy_regs. As an added benefit, cleans up
> some other really ugly bits.
I think I've reviewed all of these patches now -- ping me
if I missed one.
thanks
-- PMM
^ permalink raw reply [flat|nested] 152+ messages in thread