From patchwork Fri Apr 15 12:33:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 8850661 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C6D8B9FBEA for ; Fri, 15 Apr 2016 12:35:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D956C202DD for ; Fri, 15 Apr 2016 12:35:54 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id CEA68202EB for ; Fri, 15 Apr 2016 12:35:53 +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 1ar2wg-00055Z-7B; Fri, 15 Apr 2016 12:33:58 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ar2wf-000551-61 for xen-devel@lists.xenproject.org; Fri, 15 Apr 2016 12:33:57 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 37/1D-27880-4BFD0175; Fri, 15 Apr 2016 12:33:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsUyZ7p8oO6W+wL hBk92s1t83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBk9J44yF+yTrejefoq9gfGGaBcjJ4eQwEQm idvdIV2MXED2F0aJ/rYl7BCJDYwSk6+kQSQmMkp87vjJApJgE9CRuPjlIViRiICSxL1Vk5lAi pgFzjNJTOu8DFYkLBAosfTVZjYQm0VAVeLc+zNMIDavgLvE1O8PwOISAooS3c8mgNmcAh4Sqz ubgHo5gLa5S/ybKgJRYijxeeNS5gmMfAsYGVYxahSnFpWlFukamuslFWWmZ5TkJmbm6BoamOr lphYXJ6an5iQmFesl5+duYgQGCgMQ7GC8eNrzEKMkB5OSKO/cvQLhQnxJ+SmVGYnFGfFFpTmp xYcYZTg4lCR4P9wFygkWpaanVqRl5gBDFiYtwcGjJMJreA8ozVtckJhbnJkOkTrFqCglzssOk hAASWSU5sG1weLkEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5/4Ns58nMK4Gb/gpoMRPQ4r J3vCCLSxIRUlINjNNfCPqvuvG7o061U2xWxrOwWZeeX0k/9MNtiWN4j8me6pTljWuXff3yPjN ROafo0MXNmx0KnnHJ337cJBcRqmh/XTe3WZrtN5P6xBvmF3hmhytUzjW4+aWvuyNk95605ekf 5z94eqdQyHQlv7jgZqN6D4U7L88V9l1dHjbpcd3vO3cFq6M38SqxFGckGmoxFxUnAgCguhVwj gIAAA== X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1460723634!34670612!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.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32338 invoked from network); 15 Apr 2016 12:33:55 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-6.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Apr 2016 12:33:55 -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 u3FCXoOd022723 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Apr 2016 12:33:50 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 u3FCXoji004391 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Apr 2016 12:33:50 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u3FCXnTB022353; Fri, 15 Apr 2016 12:33:49 GMT Received: from olila.local.net-space.pl (/10.175.160.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Apr 2016 05:33:48 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Fri, 15 Apr 2016 14:33:04 +0200 Message-Id: <1460723596-13261-5-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1460723596-13261-1-git-send-email-daniel.kiper@oracle.com> References: <1460723596-13261-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: jgross@suse.com, andrew.cooper3@citrix.com, stefano.stabellini@eu.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 v3 04/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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org 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 Acked-by: Jan Beulich --- 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 | 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 006f41d..d60a078 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -43,9 +43,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" @@ -53,50 +54,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) : "g" (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 |