aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-13 21:16:24 +0000
committerblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-13 21:16:24 +0000
commit7f70c93716412b0874ae231c2f5416edccb22e7f (patch)
tree4d0b56b7eba01af64aaa3327dabc6b13b2cb6e45
parent92a3ecda6735ca9d15cd739ca5973e006bb2cf7a (diff)
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 <alex@csgraf.de> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6855 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--elf_ops.h17
-rw-r--r--target-ppc/cpu.h3
2 files changed, 16 insertions, 4 deletions
diff --git a/elf_ops.h b/elf_ops.h
index feea12f261..485442a935 100644
--- a/elf_ops.h
+++ b/elf_ops.h
@@ -194,8 +194,21 @@ static int glue(load_elf, SZ)(int fd, int64_t address_offset,
glue(bswap_ehdr, SZ)(&ehdr);
}
- if (ELF_MACHINE != ehdr.e_machine)
- goto fail;
+ switch (ELF_MACHINE) {
+ case EM_PPC64:
+ if (EM_PPC64 != ehdr.e_machine)
+ if (EM_PPC != ehdr.e_machine)
+ goto fail;
+ break;
+ case EM_X86_64:
+ if (EM_X86_64 != ehdr.e_machine)
+ if (EM_386 != ehdr.e_machine)
+ goto fail;
+ break;
+ default:
+ if (ELF_MACHINE != ehdr.e_machine)
+ goto fail;
+ }
if (pentry)
*pentry = (uint64_t)(elf_sword)ehdr.e_entry;
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 77cf6de71e..87b34600ed 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -68,8 +68,7 @@
#define TARGET_HAS_ICE 1
-/* Load a 32 bit BIOS also on 64 bit machines */
-#if defined (TARGET_PPC64) && defined(CONFIG_USER_ONLY)
+#if defined (TARGET_PPC64)
#define ELF_MACHINE EM_PPC64
#else
#define ELF_MACHINE EM_PPC