From patchwork Wed May 25 18:49:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 626429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rFLz52nCjz9snm for ; Thu, 26 May 2016 04:53:53 +1000 (AEST) Received: from localhost ([::1]:34760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5dwF-0005xL-6i for incoming@patchwork.ozlabs.org; Wed, 25 May 2016 14:53:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5dvA-000589-A8 for qemu-devel@nongnu.org; Wed, 25 May 2016 14:52:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5dv4-0006l7-BI for qemu-devel@nongnu.org; Wed, 25 May 2016 14:52:43 -0400 Received: from mail-bl2nam02on0087.outbound.protection.outlook.com ([104.47.38.87]:44496 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5dv4-0006l3-5Z for qemu-devel@nongnu.org; Wed, 25 May 2016 14:52:38 -0400 Received: from BL2NAM02FT051.eop-nam02.prod.protection.outlook.com (10.152.76.51) by BL2NAM02HT062.eop-nam02.prod.protection.outlook.com (10.152.77.39) with Microsoft SMTP Server (TLS) id 15.1.497.8; Wed, 25 May 2016 18:52:36 +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 BL2NAM02FT051.mail.protection.outlook.com (10.152.76.181) with Microsoft SMTP Server (TLS) id 15.1.497.8 via Frontend Transport; Wed, 25 May 2016 18:52:36 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:60233 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1b5dv1-0000Hb-S6; Wed, 25 May 2016 11:52:35 -0700 Received: from [127.0.0.1] (port=40841 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1b5dv1-0004Xh-Of; Wed, 25 May 2016 11:52:35 -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 u4PIkF8R014337; Wed, 25 May 2016 11:46:15 -0700 Received: from [172.19.74.182] (port=46506 helo=xsjalistai50.xlnx.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1b5dv0-0004Xe-UU; Wed, 25 May 2016 11:52:34 -0700 From: Alistair Francis To: Date: Wed, 25 May 2016 11:49:03 -0700 Message-ID: <75232c1c2c16c02b38af785a2a95afa571073c39.1464201427.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-22344.005 X-TM-AS-Result: No--3.475-7.0-31-10 X-imss-scan-details: No--3.475-7.0-31-10 X-TMASE-MatchedRID: P4k0k3s6QU3Hz0i32AeJEVVN8laWo90M9Nx/wC/5BIDny/syo1tPDxND 3wNw/alW+EKM/zGKJCyGiIhmYdu95+aMYoXPlVoJngIgpj8eDcAZ1CdBJOsoY8RB0bsfrpPInxM yeYT53Rm8Li3rxqCh+n+Nemey+WdYD0/yw1OGL58XouOb1AQmfvLA/ttNJBIjcFnYtRL8Hssd1/ ez+oOKiHf/Ug3zz8Sy8xFLgQKmWOyCvqWrFsheUcLe0zBjeZrbFQOP52BRBXJ3cGN2yNE5blZca 9RSYo/b X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.96; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(9170700003)(6806005)(50226002)(50986999)(8676002)(2950100001)(76176999)(586003)(189998001)(4326007)(118296001)(5008740100001)(110136002)(77096005)(5003940100001)(1220700001)(9786002)(8936002)(81166006)(87936001)(47776003)(2906002)(92566002)(64026002)(11100500001)(2351001)(50466002)(48376002)(36756003)(71366001)(19580395003)(33646002)(575784001)(85426001)(19580405001)(105606002)(5003600100002)(106466001)(86362001)(229853001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2NAM02HT062; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: ac337fe9-b555-4c6f-3bbd-08d384cdbd3b X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2NAM02HT062; X-Microsoft-Antispam-PRVS: <1057fc52e4cf4b94bce4953e145ede35@BL2NAM02HT062.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(13024025)(13017025)(13018025)(13023025)(13015025)(5005006)(3002001)(10201501046)(6055026); SRVR:BL2NAM02HT062; BCL:0; PCL:0; RULEID:; SRVR:BL2NAM02HT062; X-Forefront-PRVS: 09538D3531 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2016 18:52:36.5431 (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: BL2NAM02HT062 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.87 Subject: [Qemu-devel] [PATCH v7 1/3] 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: peter.maydell@linaro.org, armbru@redhat.com, alistair.francis@xilinx.com, crosthwaitepeter@gmail.com, cov@codeaurora.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- V7: - Fix typo hw/core/loader.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/core/loader.c b/hw/core/loader.c index 53e0e41..a8a372d 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -419,6 +419,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) { @@ -451,6 +452,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 an 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,