From patchwork Fri Aug 19 22:43:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9291291 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 50E03600CB for ; Fri, 19 Aug 2016 22:46:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 577C2295CE for ; Fri, 19 Aug 2016 22:46:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BEC9295D6; Fri, 19 Aug 2016 22:46:24 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E625A295CE for ; Fri, 19 Aug 2016 22:46:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1basWZ-0002Sc-9i; Fri, 19 Aug 2016 22:44:27 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1basWY-0002Ry-17 for xen-devel@lists.xenproject.org; Fri, 19 Aug 2016 22:44:26 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 9F/39-08498-9CB87B75; Fri, 19 Aug 2016 22:44:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHLMWRWlGSWpSXmKPExsUyZ7p8oO6J7u3 hBu8nKVt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnbHk9kLjgvVdG09x9rA+MSkS5GLg4hgYlM Ei3rp7JAOF8YJfZemcwM4WwEclb8ZocqY5TY8/gHWxcjJwebgI7ExS8P2UFsEQEliXurJjOBF DELzGGSuNq7iwkkISwQKPHu8UZGEJtFQFXi+atfYHFeAXeJfc8Ogw2SEFCU6H42AczmFPCQ+L PpEViNEFDN4z8/oGoMJT5vXMo8gZFvASPDKkaN4tSistQiXSMTvaSizPSMktzEzBxdQwMzvdz U4uLE9NScxKRiveT83E2MwHBhAIIdjCvXBR5ilORgUhLl9VPbHi7El5SfUpmRWJwRX1Sak1p8 iFGGg0NJgrehCygnWJSanlqRlpkDDFyYtAQHj5II7w+QNG9xQWJucWY6ROoUo6KUOG80SEIAJ JFRmgfXBouWS4yyUsK8jECHCPEUpBblZpagyr9iFOdgVBLm3Q0yhSczrwRu+iugxUxAi3n5t4 AsLklESEk1MOqIPX6gXrhvst5mOS6+zq/9HJ8vPg8Sv33zjXekZm+E8A6veJawEyoy9bG7Jx5 KnxvhusJBLfCJvsw/iyn7r/Pf/+94td4wfec7hpjCl5eNv8VZh0utXas4Z5M7s6mAyktLK3+J a0bHqlauzr0f6hayYJfojGNnK54LujdVMtc8P7Lj24uFD5RYijMSDbWYi4oTAZtt62qRAgAA X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1471646662!54962321!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55000 invoked from network); 19 Aug 2016 22:44:24 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-6.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Aug 2016 22:44:24 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7JMiFKg032577 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Aug 2016 22:44:15 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u7JMiEZg029965 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 19 Aug 2016 22:44:15 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u7JMiDaP017281; Fri, 19 Aug 2016 22:44:14 GMT Received: from olila.local.net-space.pl (/10.175.190.131) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 19 Aug 2016 15:44:13 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Sat, 20 Aug 2016 00:43:16 +0200 Message-Id: <1471646606-28519-7-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1471646606-28519-1-git-send-email-daniel.kiper@oracle.com> References: <1471646606-28519-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: jgross@suse.com, sstabellini@kernel.org, andrew.cooper3@citrix.com, cardoe@cardoe.com, pgnet.dev@gmail.com, ning.sun@intel.com, david.vrabel@citrix.com, jbeulich@suse.com, qiaowei.ren@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Create generic alloc and copy functions. We need separate tools for memory allocation and copy to provide multiboot2 protocol support. Signed-off-by: Daniel Kiper --- v4 - suggestions/fixes: - avoid assembly usage. v3 - suggestions/fixes: - use "g" constraint instead of "r" for alloc_mem() bytes argument (suggested by Jan Beulich). v2 - suggestions/fixes: - generalize new functions names (suggested by Jan Beulich), - reduce number of casts (suggested by Jan Beulich). --- xen/arch/x86/boot/reloc.c | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 28c6cea..21b1f32 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -32,60 +32,69 @@ typedef unsigned int u32; static u32 alloc; -static void *reloc_mbi_struct(void *old, unsigned int bytes) +static u32 alloc_mem(u32 bytes) { - void *new; + return alloc -= ALIGN_UP(bytes, 16); +} - alloc -= ALIGN_UP(bytes, 16); - new = (void *)alloc; +static u32 copy_mem(u32 src, u32 bytes) +{ + u32 dst, dst_ret; + + dst = alloc_mem(bytes); + dst_ret = dst; while ( bytes-- ) - *(char *)new++ = *(char *)old++; + *(char *)dst++ = *(char *)src++; - return (void *)alloc; + return dst_ret; } -static char *reloc_mbi_string(char *old) +static u32 copy_string(u32 src) { - char *p; - for ( p = old; *p != '\0'; p++ ) + u32 p; + + if ( src == 0 ) + return 0; + + for ( p = src; *(char *)p != '\0'; p++ ) continue; - return reloc_mbi_struct(old, p - old + 1); + + return copy_mem(src, p - src + 1); } -multiboot_info_t __stdcall *reloc(multiboot_info_t *mbi_old, u32 trampoline) +multiboot_info_t __stdcall *reloc(u32 mbi_old, u32 trampoline) { multiboot_info_t *mbi; int i; alloc = trampoline; - mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi)); + mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi)); if ( mbi->flags & MBI_CMDLINE ) - mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline); + mbi->cmdline = copy_string(mbi->cmdline); if ( mbi->flags & MBI_MODULES ) { - module_t *mods = reloc_mbi_struct( - (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t)); + module_t *mods; - mbi->mods_addr = (u32)mods; + mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t)); + + mods = (module_t *)mbi->mods_addr; for ( i = 0; i < mbi->mods_count; i++ ) { if ( mods[i].string ) - mods[i].string = (u32)reloc_mbi_string((char *)mods[i].string); + mods[i].string = copy_string(mods[i].string); } } if ( mbi->flags & MBI_MEMMAP ) - mbi->mmap_addr = (u32)reloc_mbi_struct( - (memory_map_t *)mbi->mmap_addr, mbi->mmap_length); + mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length); if ( mbi->flags & MBI_LOADERNAME ) - mbi->boot_loader_name = (u32)reloc_mbi_string( - (char *)mbi->boot_loader_name); + mbi->boot_loader_name = copy_string(mbi->boot_loader_name); /* Mask features we don't understand or don't relocate. */ mbi->flags &= (MBI_MEMLIMITS |