From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZHC5F-0004P5-13 for mharc-grub-devel@gnu.org; Mon, 20 Jul 2015 10:30:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHC58-000499-6P for grub-devel@gnu.org; Mon, 20 Jul 2015 10:30:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZHC4z-0000ZN-6r for grub-devel@gnu.org; Mon, 20 Jul 2015 10:30:13 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:48285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHC4y-0000WG-PU for grub-devel@gnu.org; Mon, 20 Jul 2015 10:30:04 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t6KETtTe007745 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 20 Jul 2015 14:29:56 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t6KETtnp004981 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 20 Jul 2015 14:29:55 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t6KETtZT027443; Mon, 20 Jul 2015 14:29:55 GMT Received: from olila.local.net-space.pl (/10.175.255.176) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 20 Jul 2015 07:29:54 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org, grub-devel@gnu.org Subject: [PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions Date: Mon, 20 Jul 2015 16:29:00 +0200 Message-Id: <1437402558-7313-6-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437402558-7313-1-git-send-email-daniel.kiper@oracle.com> References: <1437402558-7313-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 Cc: jgross@suse.com, keir@xen.org, ian.campbell@citrix.com, andrew.cooper3@citrix.com, stefano.stabellini@eu.citrix.com, roy.franz@linaro.org, ning.sun@intel.com, david.vrabel@citrix.com, jbeulich@suse.com, phcoder@gmail.com, wei.liu2@citrix.com, qiaowei.ren@intel.com, richard.l.maliszewski@intel.com, gang.wei@intel.com, fu.wei@linaro.org X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jul 2015 14:30:19 -0000 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 Reviewed-by: Andrew Cooper --- 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 | 59 ++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 708898f..09fd540 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -45,9 +45,10 @@ asm ( typedef unsigned int u32; #include "../../../include/xen/multiboot.h" -static void *reloc_mbi_struct(void *old, unsigned int bytes) +static u32 alloc_mem(u32 bytes) { - void *new; + u32 s; + asm( " call 1f \n" "1: pop %%edx \n" @@ -55,50 +56,64 @@ static void *reloc_mbi_struct(void *old, unsigned int bytes) " sub %1,%0 \n" " and $~15,%0 \n" " mov %0,alloc-1b(%%edx) \n" - " mov %0,%%edi \n" - " rep movsb \n" - : "=&r" (new), "+c" (bytes), "+S" (old) - : : "edx", "edi", "memory"); - return new; + : "=&r" (s) : "r" (bytes) : "edx", "memory"); + + return s; } -static char *reloc_mbi_string(char *old) +static u32 copy_mem(u32 src, u32 bytes) { - char *p; - for ( p = old; *p != '\0'; p++ ) + u32 dst, dst_asm; + + dst = alloc_mem(bytes); + dst_asm = dst; + + asm volatile("rep movsb" : "+S" (src), "+D" (dst_asm), "+c" (bytes) : : "memory"); + + return dst; +} + +static u32 copy_string(u32 src) +{ + 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 *reloc(multiboot_info_t *mbi_old) +multiboot_info_t *reloc(u32 mbi_old) { - multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi)); + multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi)); int i; 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 | -- 1.7.10.4