From patchwork Sat Jun 28 01:25:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 32661 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 712F5200B9 for ; Sat, 28 Jun 2014 01:28:07 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kq14sf24407457pab.8 for ; Fri, 27 Jun 2014 18:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=tV6Krpr83deaTlaOPiJ7XVd7+32Y0Z4bsOcAZjZIpXg=; b=RRCVDSo4mfuRhCa1adLP7eEuuM/SpOsKCQd8iiko+i1Z21fv2mx4t+pz0okUDavcTf 2y2EmYWv1J6Fsyua+BHDP+Y13GUgjXffMIAnjeZLBBgotHyBdoeOAfF5Qy+DHzOPAZyc eqHS1JJFkHd7qmCkiJYZJQpW1NC+/P5VIOUhnHnAZ+rx9hQ67g4ykW05STXW82ZwqVvk +SlIoQrHg4BYMcb19SS89Fj8d5YNNboj0X24qkjo3IJ7iETDgK6UlsCwmFCEC6pBqG65 znrp+Wc+W2skDaEGUT/3QBA8NkaKnPTFChGyy5XpL8D1cI3Q05Kez2suqsn4F3e7QvOP lmIA== X-Gm-Message-State: ALoCoQm3FfOG1ACfHzcOWDPFa10H8DM1ZTXBYEUKJ1IxO8xk3rjGGmMlA2PELWJmCBo8yi0vBhsD X-Received: by 10.67.5.163 with SMTP id cn3mr13366582pad.25.1403918886744; Fri, 27 Jun 2014 18:28:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.163 with SMTP id p32ls815107qgd.42.gmail; Fri, 27 Jun 2014 18:28:06 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr23163027vcg.16.1403918886648; Fri, 27 Jun 2014 18:28:06 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id c2si7219389vcn.74.2014.06.27.18.28.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id i13so6036676veh.22 for ; Fri, 27 Jun 2014 18:28:06 -0700 (PDT) X-Received: by 10.52.17.129 with SMTP id o1mr19254596vdd.0.1403918886501; Fri, 27 Jun 2014 18:28:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp147875vcb; Fri, 27 Jun 2014 18:28:06 -0700 (PDT) X-Received: by 10.50.23.109 with SMTP id l13mr16427814igf.46.1403918885898; Fri, 27 Jun 2014 18:28:05 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id l9si897179igx.34.2014.06.27.18.28.04 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:28:05 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hOo-0007EF-Tm; Sat, 28 Jun 2014 01:25:50 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hOn-0007EA-R3 for xen-devel@lists.xen.org; Sat, 28 Jun 2014 01:25:50 +0000 Received: from [85.158.139.211:30804] by server-2.bemta-5.messagelabs.com id D5/1B-01647-D991EA35; Sat, 28 Jun 2014 01:25:49 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-16.tower-206.messagelabs.com!1403918746!9582128!1 X-Originating-IP: [209.85.220.45] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4899 invoked from network); 28 Jun 2014 01:25:47 -0000 Received: from mail-pa0-f45.google.com (HELO mail-pa0-f45.google.com) (209.85.220.45) by server-16.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jun 2014 01:25:47 -0000 Received: by mail-pa0-f45.google.com with SMTP id rd3so5365289pab.32 for ; Fri, 27 Jun 2014 18:25:45 -0700 (PDT) X-Received: by 10.66.121.197 with SMTP id lm5mr35147122pab.118.1403918745921; Fri, 27 Jun 2014 18:25:45 -0700 (PDT) Received: from rfranz-t520.local (c-24-10-97-91.hsd1.ca.comcast.net. [24.10.97.91]) by mx.google.com with ESMTPSA id eh4sm16637918pbc.79.2014.06.27.18.25.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jun 2014 18:25:45 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com, keir@xen.org Date: Sat, 28 Jun 2014 02:25:18 +0100 Message-Id: <1403918735-30027-3-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> References: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH RFC 02/19] Create efi-shared.[ch], and move string functions X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: Create the files for EFI code that will be shared with the ARM stub, and move string functions and some global variables. TODO: proper sharing of file (with proper -fshort-char compile option) Signed-off-by: Roy Franz --- xen/arch/x86/Makefile | 4 +- xen/arch/x86/efi/Makefile | 2 +- xen/arch/x86/efi/boot.c | 127 +++--------------------------------------- xen/arch/x86/efi/efi-shared.c | 122 ++++++++++++++++++++++++++++++++++++++++ xen/include/efi/efi-shared.h | 39 +++++++++++++ 5 files changed, 171 insertions(+), 123 deletions(-) create mode 100644 xen/arch/x86/efi/efi-shared.c create mode 100644 xen/include/efi/efi-shared.h diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 6c90b1b..7504780 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -87,13 +87,13 @@ prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(LD) $(LDFLAGS) -r -o $@ $^ -prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o +prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o efi/efi-shared.o $(guard) $(LD) $(LDFLAGS) -r -o $@ $^ else prelink.o: $(ALL_OBJS) $(LD) $(LDFLAGS) -r -o $@ $^ -prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o +prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o efi/efi-shared.o $(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^) endif diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile index 1daa7ac..9c198d2 100644 --- a/xen/arch/x86/efi/Makefile +++ b/xen/arch/x86/efi/Makefile @@ -9,6 +9,6 @@ efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c che efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y)) efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o))) -extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o +extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o efi-shared.o stub.o: $(extra-y) diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c index 2b515f2..2b6bea3 100644 --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -1,6 +1,7 @@ #include "efi.h" #include #include +#include #include #include #include @@ -44,25 +45,16 @@ typedef struct { extern char start[]; extern u32 cpuid_ext_features; -union string { - CHAR16 *w; - char *s; - const char *cs; -}; -struct file { - UINTN size; - union { - EFI_PHYSICAL_ADDRESS addr; - void *ptr; - }; -}; +/* Variables supplied/used by shared EFI code. */ +extern CHAR16 __initdata newline[]; +extern EFI_BOOT_SERVICES *__initdata efi_bs; +extern SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut; +extern SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; + -static EFI_BOOT_SERVICES *__initdata efi_bs; static EFI_HANDLE __initdata efi_ih; -static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut; -static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; static UINT32 __initdata mdesc_ver; @@ -77,111 +69,6 @@ static multiboot_info_t __initdata mbi = { }; static module_t __initdata mb_modules[3]; -static CHAR16 __initdata newline[] = L"\r\n"; - -#define PrintStr(s) StdOut->OutputString(StdOut, s) -#define PrintErr(s) StdErr->OutputString(StdErr, s) - -static CHAR16 *__init FormatDec(UINT64 Val, CHAR16 *Buffer) -{ - if ( Val >= 10 ) - Buffer = FormatDec(Val / 10, Buffer); - *Buffer = (CHAR16)(L'0' + Val % 10); - return Buffer + 1; -} - -static CHAR16 *__init FormatHex(UINT64 Val, UINTN Width, CHAR16 *Buffer) -{ - if ( Width > 1 || Val >= 0x10 ) - Buffer = FormatHex(Val >> 4, Width ? Width - 1 : 0, Buffer); - *Buffer = (CHAR16)((Val &= 0xf) < 10 ? L'0' + Val : L'a' + Val - 10); - return Buffer + 1; -} - -static void __init DisplayUint(UINT64 Val, INTN Width) -{ - CHAR16 PrintString[32], *end; - - if (Width < 0) - end = FormatDec(Val, PrintString); - else - { - PrintStr(L"0x"); - end = FormatHex(Val, Width, PrintString); - } - *end = 0; - PrintStr(PrintString); -} - -static CHAR16 *__init wstrcpy(CHAR16 *d, const CHAR16 *s) -{ - CHAR16 *r = d; - - while ( (*d++ = *s++) != 0 ) - ; - return r; -} - -static int __init wstrcmp(const CHAR16 *s1, const CHAR16 *s2) -{ - while ( *s1 && *s1 == *s2 ) - { - ++s1; - ++s2; - } - return *s1 - *s2; -} - -static int __init wstrncmp(const CHAR16 *s1, const CHAR16 *s2, UINTN n) -{ - while ( n && *s1 && *s1 == *s2 ) - { - --n; - ++s1; - ++s2; - } - return n ? *s1 - *s2 : 0; -} - -static CHAR16 *__init s2w(union string *str) -{ - const char *s = str->s; - CHAR16 *w; - void *ptr; - - if ( efi_bs->AllocatePool(EfiLoaderData, (strlen(s) + 1) * sizeof(*w), - &ptr) != EFI_SUCCESS ) - return NULL; - - w = str->w = ptr; - do { - *w = *s++; - } while ( *w++ ); - - return str->w; -} - -static char *__init w2s(const union string *str) -{ - const CHAR16 *w = str->w; - char *s = str->s; - - do { - if ( *w > 0x007f ) - return NULL; - *s = *w++; - } while ( *s++ ); - - return str->s; -} - -static bool_t __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2) -{ - return guid1->Data1 == guid2->Data1 && - guid1->Data2 == guid2->Data2 && - guid1->Data3 == guid2->Data3 && - !memcmp(guid1->Data4, guid2->Data4, sizeof(guid1->Data4)); -} static void __init noreturn blexit(const CHAR16 *str) { diff --git a/xen/arch/x86/efi/efi-shared.c b/xen/arch/x86/efi/efi-shared.c new file mode 100644 index 0000000..b9c563a --- /dev/null +++ b/xen/arch/x86/efi/efi-shared.c @@ -0,0 +1,122 @@ +/* EFI code shared between architectures. */ + +#include "efi.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut; +SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; +EFI_BOOT_SERVICES *__initdata efi_bs; + + +CHAR16 __initdata newline[] = L"\r\n"; + +CHAR16 *__init FormatDec(UINT64 Val, CHAR16 *Buffer) +{ + if ( Val >= 10 ) + Buffer = FormatDec(Val / 10, Buffer); + *Buffer = (CHAR16)(L'0' + Val % 10); + return Buffer + 1; +} + +CHAR16 *__init FormatHex(UINT64 Val, UINTN Width, CHAR16 *Buffer) +{ + if ( Width > 1 || Val >= 0x10 ) + Buffer = FormatHex(Val >> 4, Width ? Width - 1 : 0, Buffer); + *Buffer = (CHAR16)((Val &= 0xf) < 10 ? L'0' + Val : L'a' + Val - 10); + return Buffer + 1; +} + + +void __init DisplayUint(UINT64 Val, INTN Width) +{ + CHAR16 PrintString[32], *end; + + if (Width < 0) + end = FormatDec(Val, PrintString); + else + { + PrintStr(L"0x"); + end = FormatHex(Val, Width, PrintString); + } + *end = 0; + PrintStr(PrintString); +} + +CHAR16 *__init wstrcpy(CHAR16 *d, const CHAR16 *s) +{ + CHAR16 *r = d; + + while ( (*d++ = *s++) != 0 ) + ; + return r; +} + +int __init wstrcmp(const CHAR16 *s1, const CHAR16 *s2) +{ + while ( *s1 && *s1 == *s2 ) + { + ++s1; + ++s2; + } + return *s1 - *s2; +} + +int __init wstrncmp(const CHAR16 *s1, const CHAR16 *s2, UINTN n) +{ + while ( n && *s1 && *s1 == *s2 ) + { + --n; + ++s1; + ++s2; + } + return n ? *s1 - *s2 : 0; +} + +CHAR16 *__init s2w(union string *str) +{ + const char *s = str->s; + CHAR16 *w; + void *ptr; + + if ( efi_bs->AllocatePool(EfiLoaderData, (strlen(s) + 1) * sizeof(*w), + &ptr) != EFI_SUCCESS ) + return NULL; + + w = str->w = ptr; + do { + *w = *s++; + } while ( *w++ ); + + return str->w; +} + +char *__init w2s(const union string *str) +{ + const CHAR16 *w = str->w; + char *s = str->s; + + do { + if ( *w > 0x007f ) + return NULL; + *s = *w++; + } while ( *s++ ); + + return str->s; +} + +bool_t __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2) +{ + return guid1->Data1 == guid2->Data1 && + guid1->Data2 == guid2->Data2 && + guid1->Data3 == guid2->Data3 && + !memcmp(guid1->Data4, guid2->Data4, sizeof(guid1->Data4)); +} diff --git a/xen/include/efi/efi-shared.h b/xen/include/efi/efi-shared.h new file mode 100644 index 0000000..b4c7ac5 --- /dev/null +++ b/xen/include/efi/efi-shared.h @@ -0,0 +1,39 @@ +#ifndef __EFI_SHARED_H__ +#define __EFI_SHARED_H__ + +#include +#include + + +union string { + CHAR16 *w; + char *s; + const char *cs; +}; + +struct file { + UINTN size; + union { + EFI_PHYSICAL_ADDRESS addr; + void *ptr; + }; +}; + + +#define PrintStr(s) StdOut->OutputString(StdOut, s) +#define PrintErr(s) StdErr->OutputString(StdErr, s) + + + +CHAR16 * FormatDec(UINT64 Val, CHAR16 *Buffer); +CHAR16 * FormatHex(UINT64 Val, UINTN Width, CHAR16 *Buffer); + +void __init DisplayUint(UINT64 Val, INTN Width); +CHAR16 *__init wstrcpy(CHAR16 *d, const CHAR16 *s); +int __init wstrcmp(const CHAR16 *s1, const CHAR16 *s2); +int __init wstrncmp(const CHAR16 *s1, const CHAR16 *s2, UINTN n); +CHAR16 *__init s2w(union string *str); +char *__init w2s(const union string *str); +bool_t __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2); + +#endif