From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YHFmc-0001oy-Cq for mharc-grub-devel@gnu.org; Fri, 30 Jan 2015 12:55:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHFmZ-0001hl-39 for grub-devel@gnu.org; Fri, 30 Jan 2015 12:55:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHFmV-0007KF-1q for grub-devel@gnu.org; Fri, 30 Jan 2015 12:55:03 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:22454) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHFmU-0007KA-RA for grub-devel@gnu.org; Fri, 30 Jan 2015 12:54:58 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t0UHsmSU013381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 30 Jan 2015 17:54:49 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t0UHslwm022570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 30 Jan 2015 17:54:48 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t0UHsluk008537; Fri, 30 Jan 2015 17:54:47 GMT Received: from olila.local.net-space.pl (/10.175.253.219) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 30 Jan 2015 09:54:46 -0800 From: Daniel Kiper To: xen-devel@lists.xenproject.org, grub-devel@gnu.org Subject: [PATCH 02/18] x86/boot/reloc: create generic alloc and copy functions Date: Fri, 30 Jan 2015 18:54:06 +0100 Message-Id: <1422640462-28103-3-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1422640462-28103-1-git-send-email-daniel.kiper@oracle.com> References: <1422640462-28103-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 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, 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: Fri, 30 Jan 2015 17:55:04 -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 --- xen/arch/x86/boot/reloc.c | 52 ++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 63045c0..f964cda 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -33,9 +33,10 @@ asm ( typedef unsigned int u32; #include "../../../include/xen/multiboot.h" -static void *reloc_mbi_struct(void *old, unsigned int bytes) +static u32 alloc_struct(u32 bytes) { - void *new; + u32 s; + asm( " call 1f \n" "1: pop %%edx \n" @@ -43,50 +44,63 @@ 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 u32 copy_struct(u32 src, u32 bytes) +{ + u32 dst, dst_asm; + + dst = alloc_struct(bytes); + dst_asm = dst; + + asm volatile("rep movsb" : "+S" (src), "+D" (dst_asm), "+c" (bytes) : : "memory"); + + return dst; } -static char *reloc_mbi_string(char *old) +static u32 copy_string(u32 src) { char *p; - for ( p = old; *p != '\0'; p++ ) + + if ( src == 0 ) + return 0; + + for ( p = (char *)src; *p != '\0'; p++ ) continue; - return reloc_mbi_struct(old, p - old + 1); + + return copy_struct(src, p - (char *)src + 1); } multiboot_info_t *reloc(multiboot_info_t *mbi_old) { - multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi)); + multiboot_info_t *mbi = (multiboot_info_t *)copy_struct((u32)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 = (module_t *)copy_struct( + mbi->mods_addr, mbi->mods_count * sizeof(module_t)); mbi->mods_addr = (u32)mods; 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_struct(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