From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LiEjz-0005xD-9y for qemu-devel@nongnu.org; Fri, 13 Mar 2009 17:16:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LiEjy-0005wQ-PK for qemu-devel@nongnu.org; Fri, 13 Mar 2009 17:16:27 -0400 Received: from [199.232.76.173] (port=46627 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LiEjy-0005wF-I0 for qemu-devel@nongnu.org; Fri, 13 Mar 2009 17:16:26 -0400 Received: from savannah.gnu.org ([199.232.41.3]:47629 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LiEjy-0005TN-Ba for qemu-devel@nongnu.org; Fri, 13 Mar 2009 17:16:26 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LiEjx-0007Yz-IM for qemu-devel@nongnu.org; Fri, 13 Mar 2009 21:16:25 +0000 Received: from blueswir1 by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LiEjx-0007Yv-4J for qemu-devel@nongnu.org; Fri, 13 Mar 2009 21:16:25 +0000 MIME-Version: 1.0 Errors-To: blueswir1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Blue Swirl Message-Id: Date: Fri, 13 Mar 2009 21:16:25 +0000 Subject: [Qemu-devel] [6855] Make the ELF loader aware of backwards compatibility Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6855 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6855 Author: blueswir1 Date: 2009-03-13 21:16:24 +0000 (Fri, 13 Mar 2009) Log Message: ----------- 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 Modified Paths: -------------- trunk/elf_ops.h trunk/target-ppc/cpu.h Modified: trunk/elf_ops.h =================================================================== --- trunk/elf_ops.h 2009-03-13 18:11:21 UTC (rev 6854) +++ trunk/elf_ops.h 2009-03-13 21:16:24 UTC (rev 6855) @@ -194,8 +194,21 @@ 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; Modified: trunk/target-ppc/cpu.h =================================================================== --- trunk/target-ppc/cpu.h 2009-03-13 18:11:21 UTC (rev 6854) +++ trunk/target-ppc/cpu.h 2009-03-13 21:16:24 UTC (rev 6855) @@ -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