From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn7hk-00063E-AY for qemu-devel@nongnu.org; Thu, 22 Sep 2016 13:22:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn7hg-0002m9-7I for qemu-devel@nongnu.org; Thu, 22 Sep 2016 13:22:36 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:47101) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn7hf-0002lg-VX for qemu-devel@nongnu.org; Thu, 22 Sep 2016 13:22:32 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bn7hf-0007LU-HT for qemu-devel@nongnu.org; Thu, 22 Sep 2016 18:22:31 +0100 From: Peter Maydell Date: Thu, 22 Sep 2016 18:22:05 +0100 Message-Id: <1474564935-23831-27-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1474564935-23831-1-git-send-email-peter.maydell@linaro.org> References: <1474564935-23831-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PULL 26/36] loader: Allow ELF loader to auto-detect the ELF arch List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Alistair Francis If the caller didn't specify an architecture for the ELF machine the load_elf() function will auto detect it based on the ELF file. Signed-off-by: Alistair Francis Reviewed-by: Peter Maydell Message-id: f2d70b47fcad31445f947f8817a0e146d80a046b.1474331683.git.alistair.francis@xilinx.com Signed-off-by: Peter Maydell --- include/hw/elf_ops.h | 5 +++++ include/hw/loader.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index f510e7e..5038c7f 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -280,6 +280,11 @@ static int glue(load_elf, SZ)(const char *name, int fd, glue(bswap_ehdr, SZ)(&ehdr); } + if (elf_machine <= EM_NONE) { + /* The caller didn't specify an ARCH, we can figure it out */ + elf_machine = ehdr.e_machine; + } + switch (elf_machine) { case EM_PPC64: if (ehdr.e_machine != EM_PPC64) { diff --git a/include/hw/loader.h b/include/hw/loader.h index 4879b63..c59673d 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -68,6 +68,8 @@ const char *load_elf_strerror(int error); * load will fail if the target ELF does not match. Some architectures * have some architecture-specific behaviours that come into effect when * their particular values for @elf_machine are set. + * If @elf_machine is EM_NONE then the machine type will be read from the + * ELF header and no checks will be carried out against the machine type. */ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), -- 2.7.4