From patchwork Fri Aug 5 23:04:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9265765 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 7873C60839 for ; Fri, 5 Aug 2016 23:08:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 672FD28462 for ; Fri, 5 Aug 2016 23:08:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B05B2848E; Fri, 5 Aug 2016 23:08:03 +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 016B528462 for ; Fri, 5 Aug 2016 23:08:03 +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 1bVoBQ-00037f-LD; Fri, 05 Aug 2016 23:05:40 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVoBO-00036V-VH for xen-devel@lists.xenproject.org; Fri, 05 Aug 2016 23:05:39 +0000 Received: from [85.158.139.211] by server-10.bemta-5.messagelabs.com id 31/77-19922-2CB15A75; Fri, 05 Aug 2016 23:05:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsUyZ7p8oO5B6aX hBusnall83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnbHk9kLjgvVdG09x9rA+MSkS5GLg4hgQlM Evf37WLqYuQEcr4ySnxbxAOR2MAosenlNnYIZyKjRNvHl6wgVWwCOhIXvzxkB7FFBJQk7q2az ARSxCxwlEni/+THYEXCAoES56+9ZAOxWQRUJXbN2QgW5xVwk3h2/QPYOgkBRYnuZxPAajgF3C XmbXzOBnGGm8TH7vmsEDWGEp83LmWewMi3gJFhFaNGcWpRWWqRrpGZXlJRZnpGSW5iZo6uoYG pXm5qcXFiempOYlKxXnJ+7iZGYLDUMzAw7mC8PdnvEKMkB5OSKO/5y0vChfiS8lMqMxKLM+KL SnNSiw8xynBwKEnwykotDRcSLEpNT61Iy8wBhi1MWoKDR0mEdxZImre4IDG3ODMdInWKUVFKn NcVJCEAksgozYNrg8XKJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvJdApvBk5pXATX8FtJ gJaPFHqyUgi0sSEVJSDYwV/ep3/A/KKmhNMrNm+HHx+JGbqTnSDdWr/rM8l3nzIoX7sUXAor4 k26R/vBWuP3L02d/9frDPfU7Y8YexmhyL/1lc/MuxKlJi7zLzuBvCUlsmRIiVPbGbLxezYWMa j+X7gNLHRXwTqp5f2T+PTbvx6byIpXMDA+clsJ699eekR9XXyTwdXJeUWIozEg21mIuKEwFIk amYkAIAAA== X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1470438336!41153219!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.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30626 invoked from network); 5 Aug 2016 23:05:37 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-15.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Aug 2016 23:05:37 -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 u75N5T4Y015772 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 5 Aug 2016 23:05:29 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u75N5SFw024266 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2016 23:05:29 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u75N5Q8L031326; Fri, 5 Aug 2016 23:05:27 GMT Received: from olila.local.net-space.pl (/10.175.255.156) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Aug 2016 16:05:26 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Sat, 6 Aug 2016 01:04:29 +0200 Message-Id: <1470438282-4226-7-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1470438282-4226-1-git-send-email-daniel.kiper@oracle.com> References: <1470438282-4226-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, richard.l.maliszewski@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v4 06/19] 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 |