From patchwork Thu Mar 3 19:42:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 8495861 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E97F89F2F0 for ; Thu, 3 Mar 2016 19:45:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5588920386 for ; Thu, 3 Mar 2016 19:45:21 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 187B02037C for ; Thu, 3 Mar 2016 19:45:20 +0000 (UTC) Received: from localhost ([::1]:37030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abZBX-00085E-B4 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Mar 2016 14:45:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abZBJ-0007t1-EQ for qemu-devel@nongnu.org; Thu, 03 Mar 2016 14:45:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abZBF-0001Wm-3I for qemu-devel@nongnu.org; Thu, 03 Mar 2016 14:45:05 -0500 Received: from mail-sn1nam02on0065.outbound.protection.outlook.com ([104.47.36.65]:56141 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abZBE-0001WV-Ts for qemu-devel@nongnu.org; Thu, 03 Mar 2016 14:45:01 -0500 Received: from SN1NAM02FT011.eop-nam02.prod.protection.outlook.com (10.152.72.60) by SN1NAM02HT005.eop-nam02.prod.protection.outlook.com (10.152.73.17) with Microsoft SMTP Server (TLS) id 15.1.409.7; Thu, 3 Mar 2016 19:44:59 +0000 Authentication-Results: spf=fail (sender IP is 149.199.60.96) smtp.mailfrom=xilinx.com; suse.de; dkim=none (message not signed) header.d=none; suse.de; 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 SN1NAM02FT011.mail.protection.outlook.com (10.152.72.82) with Microsoft SMTP Server (TLS) id 15.1.427.7 via Frontend Transport; Thu, 3 Mar 2016 19:44:59 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:39787 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1abZBC-0002OQ-L8; Thu, 03 Mar 2016 11:44:58 -0800 Received: from [127.0.0.1] (port=40731 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1abZBC-0003Bs-Gr; Thu, 03 Mar 2016 11:44:58 -0800 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 u23Jd9Xc015264; Thu, 3 Mar 2016 11:39:09 -0800 Received: from [172.19.74.182] (port=36966 helo=xsjalistai50.xlnx.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1abZBB-0003Bp-HQ; Thu, 03 Mar 2016 11:44:57 -0800 From: Alistair Francis To: Date: Thu, 3 Mar 2016 11:42:06 -0800 Message-ID: <68acbc29910a71900a50abb0032a0fcc3ab521ed.1456968047.git.alistair.francis@xilinx.com> X-Mailer: git-send-email 2.5.0 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-22168.006 X-TM-AS-Result: No--3.020-7.0-31-10 X-imss-scan-details: No--3.020-7.0-31-10 X-TMASE-MatchedRID: eiHJ4NstS4LHz0i32AeJEVVN8laWo90MI9yVcHNDU7baqqH/oHw+kWaS 4uH1erX9KWrPX3PpGcsnEtFE/84LtK+/EguYor8cFEUknJ/kEl7dB/CxWTRRuwihQpoXbuXFpFL PWuLEdTBxM8/Uxji8dAVoCgCS4hCkMmGAEJw56lzSPh+SfmODjxDk4UptEhFSW3Ihu14hSINopE ZMr4Jflw8i8E9YQ6PciB6mlDKe1V7S/yytHeCN9GXv4CQeNUk7G6qTOwq/n72eqD9WtJkSIw== X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.96; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(6806005)(1096002)(87936001)(5003600100002)(76176999)(2950100001)(2906002)(50986999)(105606002)(1220700001)(5008740100001)(5003940100001)(36756003)(47776003)(586003)(48376002)(110136002)(11100500001)(189998001)(4326007)(118296001)(50466002)(229853001)(50226001)(71366001)(92566002)(64026002)(77096005)(19580395003)(85426001)(33646002)(19580405001)(106466001)(86362001)(2351001)(81166005)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1NAM02HT005; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 5eba05d9-6b04-435a-3e24-08d3439c4e32 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1NAM02HT005; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(13023025)(8121501046)(13015025)(13024025)(5005006)(13017025)(3002001)(10201501046); SRVR:SN1NAM02HT005; BCL:0; PCL:0; RULEID:; SRVR:SN1NAM02HT005; X-Forefront-PRVS: 0870212862 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2016 19:44:59.2121 (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: SN1NAM02HT005 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.65 Cc: peter.maydell@linaro.org, armbru@redhat.com, alistair.francis@xilinx.com, crosthwaitepeter@gmail.com, cov@codeaurora.org, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v4 1/3] loader: Allow ELF loader to auto-detect the ELF arch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org 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 --- hw/core/loader.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/core/loader.c b/hw/core/loader.c index 3a57415..3a50771 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -339,6 +339,7 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), { int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED; uint8_t e_ident[EI_NIDENT]; + uint16_t e_machine; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) { @@ -371,6 +372,15 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), goto fail; } + if (elf_machine < 1) { + /* The caller didn't specify and ARCH, we can figure it out */ + lseek(fd, 0x12, SEEK_SET); + if (read(fd, &e_machine, sizeof(e_machine)) != sizeof(e_machine)) { + goto fail; + } + elf_machine = e_machine; + } + lseek(fd, 0, SEEK_SET); if (e_ident[EI_CLASS] == ELFCLASS64) { ret = load_elf64(filename, fd, translate_fn, translate_opaque, must_swab,