From patchwork Fri Aug 5 23:04:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9265785 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 EC94C6089F for ; Fri, 5 Aug 2016 23:08:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAA6828462 for ; Fri, 5 Aug 2016 23:08:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF4932848E; Fri, 5 Aug 2016 23:08:19 +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 710AF2846A for ; Fri, 5 Aug 2016 23:08:19 +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 1bVoBL-00032t-1r; Fri, 05 Aug 2016 23:05:35 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVoBJ-000313-5E for xen-devel@lists.xenproject.org; Fri, 05 Aug 2016 23:05:33 +0000 Received: from [85.158.139.211] by server-15.bemta-5.messagelabs.com id F1/F8-12460-CBB15A75; Fri, 05 Aug 2016 23:05:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsXSO6nOVXeP9NJ wgzl3+S2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxdnY3sBQ9lKhZ0H2FqYPws3MXIxSEk0Mok MbflNAuE85lRYv+Fw1DOBkaJRf8WM0M4Exklzs34ApTh5GAT0JG4+OUhO4gtIqAkcW/VZCaQI maBo0wS/yc/ZgVJCAsES6yddx2ogYODRUBVYm2zJUiYV8BN4lxjG1iJhICiRPezCWwgNqeAu8 S8jc/BbCGgmo/d86FqDCVOP9zGOIGRbwEjwypG9eLUorLUIl0LvaSizPSMktzEzBxdQwNTvdz U4uLE9NScxKRiveT83E2MwFBhAIIdjAebnQ8xSnIwKYnynr+8JFyILyk/pTIjsTgjvqg0J7X4 EKMMB4eSBK+s1NJwIcGi1PTUirTMHGDQwqQlOHiURHhXSAKleYsLEnOLM9MhUqcYFaXEeV1B+ gRAEhmleXBtsEi5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHeeJApPJl5JXDTXwEtZgJa/N FqCcjikkSElFQDY+4JLpXXPbL5tbZXY16E9pV9jJ6TaPnx6OG6+d11KxSj3k702er6o3KzuMi m3x4PEp/zPbZ83a583u7AjCNBlZNfasRd5CvxOsxtrfEozKmLt3v5AsXqjQHMO4UV/3Kc3uC7 Ms9iQrLfrd6mkKotm8/t7L529O3z45k+jLev6tp5lLc9eOZ6RomlOCPRUIu5qDgRACmWy7ePA gAA X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1470438330!37570756!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31527 invoked from network); 5 Aug 2016 23:05:31 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-13.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Aug 2016 23:05:31 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u75N5LeR005283 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2016 23:05:21 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u75N5LAS016187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2016 23:05:21 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u75N5JNX024789; Fri, 5 Aug 2016 23:05:20 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:19 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Sat, 6 Aug 2016 01:04:27 +0200 Message-Id: <1470438282-4226-5-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: userv0021.oracle.com [156.151.31.71] 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 04/19] x86/boot/reloc: reduce assembly usage as much as possible 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 Next patch will leave just required jmp instruction in xen/x86/boot/reloc.c. Signed-off-by: Daniel Kiper --- xen/arch/x86/boot/build32.lds | 1 + xen/arch/x86/boot/build32.mk | 2 +- xen/arch/x86/boot/reloc.c | 52 ++++++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/boot/build32.lds b/xen/arch/x86/boot/build32.lds index b14c7d5..a658ca8 100644 --- a/xen/arch/x86/boot/build32.lds +++ b/xen/arch/x86/boot/build32.lds @@ -24,6 +24,7 @@ SECTIONS *(.text) *(.text.*) *(.rodata) + *(.bss) } /DISCARD/ : { diff --git a/xen/arch/x86/boot/build32.mk b/xen/arch/x86/boot/build32.mk index eb02b4b..d54d259 100644 --- a/xen/arch/x86/boot/build32.mk +++ b/xen/arch/x86/boot/build32.mk @@ -23,7 +23,7 @@ CFLAGS := $(filter-out -flto,$(CFLAGS)) $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' |\ while read idx name sz rest; do \ case "$$name" in \ - .data|.data.*|.rodata.*|.bss|.bss.*) \ + .data|.data.*|.rodata.*|.bss.*) \ test $$sz != 0 || continue; \ echo "Error: non-empty $$name: 0x$$sz" >&2; \ exit $$(expr $$idx + 1);; \ diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index 63045c0..9ae42e2 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -15,39 +15,33 @@ asm ( " .text \n" " .globl _start \n" "_start: \n" - " call 1f \n" - "1: pop %ebx \n" - " mov %eax,alloc-1b(%ebx) \n" - " jmp reloc \n" - ); - -/* - * This is our data. Because the code must be relocatable, no BSS is - * allowed. All data is accessed PC-relative with inline assembly. - */ -asm ( - "alloc: \n" - " .long 0 \n" + " push %eax \n" + " push 0x8(%esp) \n" + " call reloc \n" + " ret $0x4 \n" ); typedef unsigned int u32; #include "../../../include/xen/multiboot.h" +#define __stdcall __attribute__((__stdcall__)) + +#define ALIGN_UP(arg, align) \ + (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1)) + +static u32 alloc; + static void *reloc_mbi_struct(void *old, unsigned int bytes) { void *new; - asm( - " call 1f \n" - "1: pop %%edx \n" - " mov alloc-1b(%%edx),%0 \n" - " 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; + + alloc -= ALIGN_UP(bytes, 16); + new = (void *)alloc; + + while ( bytes-- ) + *(char *)new++ = *(char *)old++; + + return (void *)alloc; } static char *reloc_mbi_string(char *old) @@ -58,11 +52,15 @@ static char *reloc_mbi_string(char *old) return reloc_mbi_struct(old, p - old + 1); } -multiboot_info_t *reloc(multiboot_info_t *mbi_old) +multiboot_info_t __stdcall *reloc(multiboot_info_t *mbi_old, u32 trampoline) { - multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi)); + multiboot_info_t *mbi; int i; + alloc = trampoline; + + mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi)); + if ( mbi->flags & MBI_CMDLINE ) mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);