aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2021-08-03 19:20:13 +0200
committerLaurent Vivier <laurent@vivier.eu>2021-08-05 12:17:30 +0200
commit030912e01c0385b6b09e76549c1a8a04b624f49a (patch)
tree9982493e7dc0aa26b9d5a709c24374c9ee6e2476
parent0c40c18ecd564a5c3f27f1408aaf9848fe210349 (diff)
downloadqemu-030912e01c0385b6b09e76549c1a8a04b624f49a.zip
qemu-030912e01c0385b6b09e76549c1a8a04b624f49a.tar.gz
qemu-030912e01c0385b6b09e76549c1a8a04b624f49a.tar.bz2
linux-user/elfload: byteswap i386 registers when dumping core
Core dumps from emulating x86_64 on big-endian hosts contain incorrect register values. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20210803172013.148446-1-iii@linux.ibm.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
-rw-r--r--linux-user/elfload.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 42ef2a1..01e9a83 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -172,33 +172,33 @@ typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
*/
static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env)
{
- (*regs)[0] = env->regs[15];
- (*regs)[1] = env->regs[14];
- (*regs)[2] = env->regs[13];
- (*regs)[3] = env->regs[12];
- (*regs)[4] = env->regs[R_EBP];
- (*regs)[5] = env->regs[R_EBX];
- (*regs)[6] = env->regs[11];
- (*regs)[7] = env->regs[10];
- (*regs)[8] = env->regs[9];
- (*regs)[9] = env->regs[8];
- (*regs)[10] = env->regs[R_EAX];
- (*regs)[11] = env->regs[R_ECX];
- (*regs)[12] = env->regs[R_EDX];
- (*regs)[13] = env->regs[R_ESI];
- (*regs)[14] = env->regs[R_EDI];
- (*regs)[15] = env->regs[R_EAX]; /* XXX */
- (*regs)[16] = env->eip;
- (*regs)[17] = env->segs[R_CS].selector & 0xffff;
- (*regs)[18] = env->eflags;
- (*regs)[19] = env->regs[R_ESP];
- (*regs)[20] = env->segs[R_SS].selector & 0xffff;
- (*regs)[21] = env->segs[R_FS].selector & 0xffff;
- (*regs)[22] = env->segs[R_GS].selector & 0xffff;
- (*regs)[23] = env->segs[R_DS].selector & 0xffff;
- (*regs)[24] = env->segs[R_ES].selector & 0xffff;
- (*regs)[25] = env->segs[R_FS].selector & 0xffff;
- (*regs)[26] = env->segs[R_GS].selector & 0xffff;
+ (*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(env->regs[R_EAX]); /* XXX */
+ (*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);
}
#else
@@ -244,23 +244,23 @@ typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
*/
static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env)
{
- (*regs)[0] = env->regs[R_EBX];
- (*regs)[1] = env->regs[R_ECX];
- (*regs)[2] = env->regs[R_EDX];
- (*regs)[3] = env->regs[R_ESI];
- (*regs)[4] = env->regs[R_EDI];
- (*regs)[5] = env->regs[R_EBP];
- (*regs)[6] = env->regs[R_EAX];
- (*regs)[7] = env->segs[R_DS].selector & 0xffff;
- (*regs)[8] = env->segs[R_ES].selector & 0xffff;
- (*regs)[9] = env->segs[R_FS].selector & 0xffff;
- (*regs)[10] = env->segs[R_GS].selector & 0xffff;
- (*regs)[11] = env->regs[R_EAX]; /* XXX */
- (*regs)[12] = env->eip;
- (*regs)[13] = env->segs[R_CS].selector & 0xffff;
- (*regs)[14] = env->eflags;
- (*regs)[15] = env->regs[R_ESP];
- (*regs)[16] = env->segs[R_SS].selector & 0xffff;
+ (*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(env->regs[R_EAX]); /* XXX */
+ (*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);
}
#endif