Skip to content

Commit 7f70c93

Browse files
author
blueswir1
committed
Make the ELF loader aware of backwards compatibility
Most 64 bit architectures I'm aware of support running 32 bit code of the same architecture as well. So x86_64 can run i386 code easily and ppc64 can run ppc code. Unfortunately, the current checks are pretty strict. So you can only load e.g. an x86_64 elf binary on qemu-system-x86_64, but no i386 one. This can get really annoying. I first encountered this issue with my multiboot patch, where qemu-system-x86_64 was unable to load an i386 elf binary because the elf loader rejected it. The same thing happened again on PPC64 now. The firmware we're loading is a PPC32 elf binary, as it's shared with PPC32. But the platform is PPC64. Right now there is a hack for this in the ppc cpu.h definition, that simply sets the type to PPC32 in system emulation mode. While that works fine for the firmware, it's no good if you also want to load a PPC64 kernel with -kernel. So in order to solve this mess, I figured the easiest way is to make the elf loader aware of platforms that are backwards compatible. For now I was only sure that x86_64 does i386 and ppc64 does ppc32, but maybe there are other combinations too. This patch is a prerequisite for having a working -kernel option on PPC64. Signed-off-by: Alexander Graf <[email protected]> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6855 c046a42c-6fe2-441c-8c8c-71466251a162
1 parent 92a3ecd commit 7f70c93

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

elf_ops.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,21 @@ static int glue(load_elf, SZ)(int fd, int64_t address_offset,
194194
glue(bswap_ehdr, SZ)(&ehdr);
195195
}
196196

197-
if (ELF_MACHINE != ehdr.e_machine)
198-
goto fail;
197+
switch (ELF_MACHINE) {
198+
case EM_PPC64:
199+
if (EM_PPC64 != ehdr.e_machine)
200+
if (EM_PPC != ehdr.e_machine)
201+
goto fail;
202+
break;
203+
case EM_X86_64:
204+
if (EM_X86_64 != ehdr.e_machine)
205+
if (EM_386 != ehdr.e_machine)
206+
goto fail;
207+
break;
208+
default:
209+
if (ELF_MACHINE != ehdr.e_machine)
210+
goto fail;
211+
}
199212

200213
if (pentry)
201214
*pentry = (uint64_t)(elf_sword)ehdr.e_entry;

target-ppc/cpu.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868

6969
#define TARGET_HAS_ICE 1
7070

71-
/* Load a 32 bit BIOS also on 64 bit machines */
72-
#if defined (TARGET_PPC64) && defined(CONFIG_USER_ONLY)
71+
#if defined (TARGET_PPC64)
7372
#define ELF_MACHINE EM_PPC64
7473
#else
7574
#define ELF_MACHINE EM_PPC

0 commit comments

Comments
 (0)