From patchwork Thu Jul 14 00:03:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 9228623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B9B8A60572 for ; Thu, 14 Jul 2016 00:04:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA05526E69 for ; Thu, 14 Jul 2016 00:04:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EC3A27FBE; Thu, 14 Jul 2016 00:04:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6577227FB6 for ; Thu, 14 Jul 2016 00:04:30 +0000 (UTC) Received: from localhost ([::1]:50614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNU8j-0007fj-Tq for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Jul 2016 20:04:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNU8B-0007f2-M4 for qemu-devel@nongnu.org; Wed, 13 Jul 2016 20:03:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNU86-0000Kx-TY for qemu-devel@nongnu.org; Wed, 13 Jul 2016 20:03:55 -0400 Received: from mail-bl2nam02on0041.outbound.protection.outlook.com ([104.47.38.41]:29792 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNU86-0000Kt-PX for qemu-devel@nongnu.org; Wed, 13 Jul 2016 20:03:50 -0400 Received: from BL2NAM02FT018.eop-nam02.prod.protection.outlook.com (10.152.76.56) by BL2NAM02HT165.eop-nam02.prod.protection.outlook.com (10.152.76.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.534.7; Thu, 14 Jul 2016 00:03:49 +0000 Authentication-Results: spf=fail (sender IP is 149.199.60.96) smtp.mailfrom=xilinx.com; redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=xilinx.com; Received-SPF: Fail (protection.outlook.com: domain of xilinx.com does not designate 149.199.60.96 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.96; helo=xsj-tvapsmtpgw01; Received: from xsj-tvapsmtpgw01 (149.199.60.96) by BL2NAM02FT018.mail.protection.outlook.com (10.152.77.170) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.534.7 via Frontend Transport; Thu, 14 Jul 2016 00:03:48 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:38538 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1bNU83-0007Nu-U0; Wed, 13 Jul 2016 17:03:47 -0700 Received: from [127.0.0.1] (port=43825 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1bNU83-00019K-QP; Wed, 13 Jul 2016 17:03:47 -0700 Received: from xsj-tvapsmtp02 (xsj-tvapsmtp02.xilinx.com [172.16.1.203]) by tsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id u6DNv7St011009; Wed, 13 Jul 2016 16:57:08 -0700 Received: from [172.19.74.182] (port=53722 helo=xsjalistai50.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1bNU83-00019H-2Z; Wed, 13 Jul 2016 17:03:47 -0700 From: Alistair Francis To: , Date: Wed, 13 Jul 2016 17:03:24 -0700 Message-ID: <6160031ceab98811f73ab3d81d546bd568ef8e41.1468454556.git.alistair.francis@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-RCIS-Action: ALLOW X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-22448.005 X-TM-AS-Result: No--9.656-7.0-31-10 X-imss-scan-details: No--9.656-7.0-31-10 X-TMASE-MatchedRID: bWXPfm7qERPHz0i32AeJEVVN8laWo90MYQXxsZnRwoICsxyhR8y7CR9Y 5WQrOqCXkZ3T6ylBNAUBtjkcfRMmqRUBkTmMruyZ0Xw0ILvo/uXLkIfkvoeba9JgDNnoqapaWLt 167EoD8yHcBnWFx4x4lBY98a/SWy3FIXwv4qc0ZOeAiCmPx4NwBnUJ0Ek6yhjxEHRux+uk8jHUU +U0ACZwHmgZknCCMXVu8RpnX94W1/5l40AzH8ULDB8Dw60fhSlnqg/VrSZEiM= X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.96; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(81166006)(11100500001)(77096005)(8936002)(7696003)(5003600100003)(76176999)(106466001)(33646002)(4326007)(50986999)(586003)(19580405001)(50226002)(305945005)(50466002)(229853001)(86362001)(71366001)(81156014)(48376002)(7846002)(105606002)(5001770100001)(9786002)(2906002)(2950100001)(64026002)(36756003)(356003)(8676002)(5003940100001)(189998001)(19580395003)(87936001)(47776003)(118296001)(85426001)(92566002)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2NAM02HT165; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; PTR:unknown-60-96.xilinx.com; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 2405e018-58ea-4789-d4a5-08d3ab7a5508 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2NAM02HT165; X-Microsoft-Antispam-PRVS: <6408ba3f49b44f52bfa18ccc11810a99@BL2NAM02HT165.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(8121501046)(5005006)(13017025)(13015025)(13024025)(13018025)(3002001)(10201501046)(6055026); SRVR:BL2NAM02HT165; BCL:0; PCL:0; RULEID:; SRVR:BL2NAM02HT165; X-Forefront-PRVS: 00032065B2 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2016 00:03:48.8498 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.96]; Helo=[xsj-tvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2NAM02HT165 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.41 Subject: [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cov@codeaurora.org, crosthwaitepeter@gmail.com, pbonzini@redhat.com, armbru@redhat.com, alistair.francis@xilinx.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- V9: - Update documentation V8: - Move into load_elf64/load_elf32 V7: - Fix typo include/hw/elf_ops.h | 5 +++++ include/hw/loader.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index f510e7e..db70c11 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 < 1) { + /* 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..fd540fc 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -68,6 +68,9 @@ 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 no @elf_machine is provided the machine will default to the value + * in the ELFs 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),