From patchwork Sat Jul 2 01:07:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 643366 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 3rhFch52jjz9t0J for ; Sat, 2 Jul 2016 11:12:20 +1000 (AEST) Received: from localhost ([::1]:36524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ9Tm-0001nJ-JM for incoming@patchwork.ozlabs.org; Fri, 01 Jul 2016 21:12:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ9PC-0004iW-TO for qemu-devel@nongnu.org; Fri, 01 Jul 2016 21:07:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJ9P8-0001vV-NX for qemu-devel@nongnu.org; Fri, 01 Jul 2016 21:07:33 -0400 Received: from mail-cys01nam02on0056.outbound.protection.outlook.com ([104.47.37.56]:29408 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ9P8-0001vP-FB for qemu-devel@nongnu.org; Fri, 01 Jul 2016 21:07:30 -0400 Received: from CY1NAM02FT007.eop-nam02.prod.protection.outlook.com (10.152.74.53) by CY1NAM02HT154.eop-nam02.prod.protection.outlook.com (10.152.75.109) with Microsoft SMTP Server (TLS) id 15.1.523.9; Sat, 2 Jul 2016 01:07:28 +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 CY1NAM02FT007.mail.protection.outlook.com (10.152.75.5) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.534.7 via Frontend Transport; Sat, 2 Jul 2016 01:07:28 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:39534 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1bJ9P6-0006cN-1v; Fri, 01 Jul 2016 18:07:28 -0700 Received: from [127.0.0.1] (port=48374 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1bJ9P5-0003bS-VE; Fri, 01 Jul 2016 18:07:28 -0700 Received: from xsj-tvapsmtp02 (smtptest.xilinx.com [172.16.1.203]) by tsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id u6210qDK007067; Fri, 1 Jul 2016 18:00:52 -0700 Received: from [172.19.74.182] (port=38976 helo=xsjalistai50.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1bJ9P5-0003bP-4J; Fri, 01 Jul 2016 18:07:27 -0700 From: Alistair Francis To: , Date: Fri, 1 Jul 2016 18:07:09 -0700 Message-ID: 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-22424.005 X-TM-AS-Result: No--9.709-7.0-31-10 X-imss-scan-details: No--9.709-7.0-31-10 X-TMASE-MatchedRID: ZCn+RolpoOMLazoQyrpm0lVN8laWo90MUAjrAJWsTe/K99fyOVK2z5zN 93wt7ZVSIHjnztybxtUtq3jKfi+PfxLmJd2F/yFuiBA/0bBQLms0AKed0u9fB01KG1YrOQW/kyw udUpF3nLH7YzgPM428iucaISJ5PmUkKjL2IOi2LAMH4SsGvRsA8SgMQYKGHsJRTck7NznBP+ZiK kTLfbrW6EbZdvXmRYX0dNJI3SVpd5zfeCSt9MtiLYBnn2EUDXrxZ6FS4Y7LY9b8pv4L0h+IvuyZ S0hzAcmfeZdJ1XsoriAMuqetGVetnyef22ep6XYOwBXM346/+xf14SOlKk9VGmfefJOrzIOcVwD uamNC4JaqqT3CJTBwDKTfYmGCOXJ 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)(1110001)(1109001)(339900001)(199003)(189002)(8676002)(118296001)(356003)(19580405001)(50986999)(81166006)(71366001)(81156014)(76176999)(19580395003)(48376002)(86362001)(229853001)(92566002)(7696003)(5003600100003)(64026002)(586003)(575784001)(50466002)(5003940100001)(4326007)(7846002)(36756003)(2906002)(33646002)(50226002)(189998001)(77096005)(8936002)(87936001)(9786002)(106466001)(105606002)(11100500001)(305945005)(2950100001)(5001770100001)(85426001)(47776003)(49343001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1NAM02HT154; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; PTR:unknown-60-96.xilinx.com; A:1; MX:1; CAT:NONE; LANG:en; CAT:NONE; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 726b06ec-79a5-4279-8811-08d3a2153ce1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1NAM02HT154; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(60795455431006)(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13024025)(13023025)(13017025)(13015025)(13018025)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:CY1NAM02HT154; BCL:0; PCL:0; RULEID:; SRVR:CY1NAM02HT154; X-Forefront-PRVS: 0991CAB7B3 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2016 01:07:28.4892 (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: CY1NAM02HT154 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.56 Subject: [Qemu-devel] [PATCH v8 3/5] loader: Add AddressSpace loading support to ELFs 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a new function load_elf_as() that allows the caller to specify an AddressSpace to use when loading the ELF. The original load_elf() function doesn't have any change in functionality. Signed-off-by: Alistair Francis --- V8: - Introduce an RFC version of AddressSpace support hw/core/loader.c | 16 ++++++++++++++-- include/hw/elf_ops.h | 5 +++-- include/hw/loader.h | 14 +++++++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index fcbcfbf..9b25dfc 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -417,6 +417,18 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb, int data_swab) { + return load_elf_as(filename, translate_fn, translate_opaque, pentry, + lowaddr, highaddr, big_endian, elf_machine, clear_lsb, + data_swab, NULL); +} + +/* return < 0 if error, otherwise the number of bytes loaded in memory */ +int load_elf_as(const char *filename, + uint64_t (*translate_fn)(void *, uint64_t), + void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, + uint64_t *highaddr, int big_endian, int elf_machine, + int clear_lsb, int data_swab, AddressSpace *as) +{ int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED; uint8_t e_ident[EI_NIDENT]; @@ -455,11 +467,11 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), if (e_ident[EI_CLASS] == ELFCLASS64) { ret = load_elf64(filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab); + data_swab, as); } else { ret = load_elf32(filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb, - data_swab); + data_swab, as); } fail: diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index 1339677..3b8c9e9 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -263,7 +263,8 @@ static int glue(load_elf, SZ)(const char *name, int fd, void *translate_opaque, int must_swab, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, - int elf_machine, int clear_lsb, int data_swab) + int elf_machine, int clear_lsb, int data_swab, + AddressSpace *as) { struct elfhdr ehdr; struct elf_phdr *phdr = NULL, *ph; @@ -405,7 +406,7 @@ static int glue(load_elf, SZ)(const char *name, int fd, snprintf(label, sizeof(label), "phdr #%d: %s", i, name); /* rom_add_elf_program() seize the ownership of 'data' */ - rom_add_elf_program(label, data, file_size, mem_size, addr, NULL); + rom_add_elf_program(label, data, file_size, mem_size, addr, as); total_size += mem_size; if (addr < low) diff --git a/include/hw/loader.h b/include/hw/loader.h index 18eb0f2..d14eab1 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -45,7 +45,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz); #define ELF_LOAD_WRONG_ENDIAN -4 const char *load_elf_strerror(int error); -/** load_elf: +/** load_elf_as: * @filename: Path of ELF file * @translate_fn: optional function to translate load addresses * @translate_opaque: opaque data passed to @translate_fn @@ -59,6 +59,8 @@ const char *load_elf_strerror(int error); * @data_swab: Set to order of byte swapping for data. 0 for no swap, 1 * for swapping bytes within halfwords, 2 for bytes within * words and 3 for within doublewords. + * @as: The AddressSpace to load the ELF to. The value of address_space_memory + * is used if nothing is supplied here. * * Load an ELF file's contents to the emulated system's address space. * Clients may optionally specify a callback to perform address @@ -70,6 +72,16 @@ const char *load_elf_strerror(int error); * their particular values for @elf_machine are set. */ +int load_elf_as(const char *filename, + uint64_t (*translate_fn)(void *, uint64_t), + void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, + uint64_t *highaddr, int big_endian, int elf_machine, + int clear_lsb, int data_swab, AddressSpace *as); + +/** load_elf: + * Same as above, but doesn't allow the caller to specify an AddressSpace + */ + int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, int big_endian, int elf_machine,