From patchwork Sat Jun 28 01:25:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 32650 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6766621309 for ; Sat, 28 Jun 2014 01:27:33 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id hn18sf9360967igb.3 for ; Fri, 27 Jun 2014 18:27:33 -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=JGhFYh2oWdFVzwatCD1I7awlzQSJTO5dI8tGvakuRnw=; b=RBSTN3AdiIQrSg1r6BnjV+pmENq9u1yN5WYXq+3Q7s0SLmBTf6noB6+3/Opbz5htTg T0hl+q6BHHYPDPHvlx3KMKpyflHO7eFEXdDT3hdG1VzsjWpp2XRbYkB6JVIQrrV1/vxc fdHnzv1kG86sd1ZozA11SVm/mhKUdm/KzmD7qT/Y7Iaam2zuRnN7YNs7dqy50XmRoT96 eroCX0kx7/T+HMsQ0LAlD34EEBwsqb+NOWMjDIu/JGFW5hOq4CGDJFr+0CKqNAJdpb7L GazZ5OHDGdLdnn2KW55at/4lrETnn5xGpjLeQjy0I5NMg3GScPhmjQid4Msr/BsJeza7 yQFw== X-Gm-Message-State: ALoCoQmdpd8xS1ya6C+JH8MCN5a0ieGRuOOY3ylVSEA0aKyVy+40stRkG8v7Ba4UAAo5LxgDzrLF X-Received: by 10.42.94.8 with SMTP id z8mr13003246icm.3.1403918853018; Fri, 27 Jun 2014 18:27:33 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.70 with SMTP id 64ls768384qgs.14.gmail; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) X-Received: by 10.221.63.195 with SMTP id xf3mr269827vcb.36.1403918852935; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id d9si7222446vcq.66.2014.06.27.18.27.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:27:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so6065553veb.41 for ; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) X-Received: by 10.52.69.172 with SMTP id f12mr19446546vdu.26.1403918852793; Fri, 27 Jun 2014 18:27:32 -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 tc5csp147850vcb; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) X-Received: by 10.221.9.72 with SMTP id ov8mr23011199vcb.27.1403918852401; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id cz8si7214985vcb.88.2014.06.27.18.27.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:27:32 -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 1X0hP7-0007Rp-Gz; Sat, 28 Jun 2014 01:26:09 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hP5-0007PO-Sg for xen-devel@lists.xen.org; Sat, 28 Jun 2014 01:26:08 +0000 Received: from [193.109.254.147:28543] by server-4.bemta-14.messagelabs.com id F1/A4-02781-FA91EA35; Sat, 28 Jun 2014 01:26:07 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-5.tower-27.messagelabs.com!1403918762!9581937!1 X-Originating-IP: [209.85.220.54] 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 3439 invoked from network); 28 Jun 2014 01:26:03 -0000 Received: from mail-pa0-f54.google.com (HELO mail-pa0-f54.google.com) (209.85.220.54) by server-5.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jun 2014 01:26:03 -0000 Received: by mail-pa0-f54.google.com with SMTP id et14so5372658pad.13 for ; Fri, 27 Jun 2014 18:26:01 -0700 (PDT) X-Received: by 10.69.30.74 with SMTP id kc10mr34745013pbd.111.1403918761845; Fri, 27 Jun 2014 18:26:01 -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.26.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jun 2014 18:26:01 -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:30 +0100 Message-Id: <1403918735-30027-15-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 14/19] Move get_argv() and handle_cmdline() to efi-shared.c 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.182 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: Move get_argv() and handle_cmdline() to efi-shared.c now that both are shareable. No functional changes, only moving of code in this changeset. Signed-off-by: Roy Franz --- xen/arch/x86/efi/boot.c | 114 ------------------------------------------ xen/arch/x86/efi/efi-shared.c | 113 +++++++++++++++++++++++++++++++++++++++++ xen/include/efi/efi-shared.h | 7 +++ 3 files changed, 120 insertions(+), 114 deletions(-) diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c index 49e0c15..38edd5e 100644 --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -117,53 +117,6 @@ static void __init place_string(u32 *addr, const char *s) *addr = (long)alloc; } -static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv, - CHAR16 *cmdline, UINTN cmdsize, - CHAR16 **cmdline_remain) -{ - CHAR16 *ptr = (CHAR16 *)(argv + argc + 1), *prev = NULL; - bool_t prev_sep = TRUE; - - for ( ; cmdsize > sizeof(*cmdline) && *cmdline; - cmdsize -= sizeof(*cmdline), ++cmdline ) - { - bool_t cur_sep = *cmdline == L' ' || *cmdline == L'\t'; - - if ( !prev_sep ) - { - if ( cur_sep ) - ++ptr; - else if ( argv ) - { - *ptr = *cmdline; - *++ptr = 0; - } - } - else if ( !cur_sep ) - { - if ( !argv ) - ++argc; - else if ( prev && wstrcmp(prev, L"--") == 0 ) - { - --argv; - if (**cmdline_remain) - *cmdline_remain = cmdline; - break; - } - else - { - *argv++ = prev = ptr; - *ptr = *cmdline; - *++ptr = 0; - } - } - prev_sep = cur_sep; - } - if ( argv ) - *argv = NULL; - return argc; -} - /* Only call with non-config files. */ void __init load_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, struct file *file) @@ -346,73 +299,6 @@ static void __init relocate_image(unsigned long delta) } -void __init handle_cmdline(EFI_LOADED_IMAGE *loaded_image, - CHAR16 **cfg_file_name, bool_t *base_video, - CHAR16 **image_name, CHAR16 **section_name, - CHAR16 **cmdline_remain) -{ - - unsigned int i, argc; - CHAR16 **argv; - - - if ( !cfg_file_name || !base_video || !image_name ) - { - PrintStr(L"Invalid args to handle_cmdline\r\n"); - blexit(NULL); - } - - argc = get_argv(0, NULL, loaded_image->LoadOptions, - loaded_image->LoadOptionsSize, NULL); - if ( argc > 0 && - efi_bs->AllocatePool(EfiLoaderData, - (argc + 1) * sizeof(*argv) + - loaded_image->LoadOptionsSize, - (void **)&argv) == EFI_SUCCESS ) - get_argv(argc, argv, loaded_image->LoadOptions, - loaded_image->LoadOptionsSize, cmdline_remain); - else - argc = 0; - - for ( i = 1; i < argc; ++i ) - { - CHAR16 *ptr = argv[i]; - - if ( !ptr ) - break; - if ( *ptr == L'/' || *ptr == L'-' ) - { - if ( wstrcmp(ptr + 1, L"basevideo") == 0 ) - *base_video = 1; - else if ( wstrncmp(ptr + 1, L"cfg=", 4) == 0 ) - *cfg_file_name = ptr + 5; - else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") == 0 ) - *cfg_file_name = argv[++i]; - else if ( wstrcmp(ptr + 1, L"help") == 0 || - (ptr[1] == L'?' && !ptr[2]) ) - { - PrintStr(L"Xen EFI Loader options:\r\n"); - PrintStr(L"-basevideo retain current video mode\r\n"); - PrintStr(L"-cfg= specify configuration file\r\n"); - PrintStr(L"-help, -? display this help\r\n"); - blexit(NULL); - } - else - { - PrintStr(L"WARNING: Unknown command line option '"); - PrintStr(ptr); - PrintStr(L"' ignored\r\n"); - } - } - else - *section_name = ptr; - } - - if ( argc ) - { - *image_name = *argv; - } -} extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[]; extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[]; diff --git a/xen/arch/x86/efi/efi-shared.c b/xen/arch/x86/efi/efi-shared.c index 43601fe..f392ec4 100644 --- a/xen/arch/x86/efi/efi-shared.c +++ b/xen/arch/x86/efi/efi-shared.c @@ -185,6 +185,119 @@ void __init PrintErrMesgExit(const CHAR16 *mesg, EFI_STATUS ErrCode) blexit(mesg); } +unsigned int __init get_argv(unsigned int argc, CHAR16 **argv, + CHAR16 *cmdline, UINTN cmdsize, + CHAR16 **cmdline_remain) +{ + CHAR16 *ptr = (CHAR16 *)(argv + argc + 1), *prev = NULL; + bool_t prev_sep = TRUE; + + for ( ; cmdsize > sizeof(*cmdline) && *cmdline; + cmdsize -= sizeof(*cmdline), ++cmdline ) + { + bool_t cur_sep = *cmdline == L' ' || *cmdline == L'\t'; + + if ( !prev_sep ) + { + if ( cur_sep ) + ++ptr; + else if ( argv ) + { + *ptr = *cmdline; + *++ptr = 0; + } + } + else if ( !cur_sep ) + { + if ( !argv ) + ++argc; + else if ( prev && wstrcmp(prev, L"--") == 0 ) + { + --argv; + if (**cmdline_remain) + *cmdline_remain = cmdline; + break; + } + else + { + *argv++ = prev = ptr; + *ptr = *cmdline; + *++ptr = 0; + } + } + prev_sep = cur_sep; + } + if ( argv ) + *argv = NULL; + return argc; +} + + +void __init handle_cmdline(EFI_LOADED_IMAGE *loaded_image, + CHAR16 **cfg_file_name, bool_t *base_video, + CHAR16 **image_name, CHAR16 **section_name, + CHAR16 **cmdline_remain) +{ + + unsigned int i, argc; + CHAR16 **argv; + + + if ( !cfg_file_name || !base_video || !image_name ) + blexit(L"Invalid args to handle_cmdline\r\n"); + + argc = get_argv(0, NULL, loaded_image->LoadOptions, + loaded_image->LoadOptionsSize, NULL); + if ( argc > 0 && + efi_bs->AllocatePool(EfiLoaderData, + (argc + 1) * sizeof(*argv) + + loaded_image->LoadOptionsSize, + (void **)&argv) == EFI_SUCCESS ) + get_argv(argc, argv, loaded_image->LoadOptions, + loaded_image->LoadOptionsSize, cmdline_remain); + else + argc = 0; + + for ( i = 1; i < argc; ++i ) + { + CHAR16 *ptr = argv[i]; + + if ( !ptr ) + break; + if ( *ptr == L'/' || *ptr == L'-' ) + { + if ( wstrcmp(ptr + 1, L"basevideo") == 0 ) + *base_video = 1; + else if ( wstrncmp(ptr + 1, L"cfg=", 4) == 0 ) + *cfg_file_name = ptr + 5; + else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") == 0 ) + *cfg_file_name = argv[++i]; + else if ( wstrcmp(ptr + 1, L"help") == 0 || + (ptr[1] == L'?' && !ptr[2]) ) + { + PrintStr(L"Xen EFI Loader options:\r\n"); + PrintStr(L"-basevideo retain current video mode\r\n"); + PrintStr(L"-cfg= specify configuration file\r\n"); + PrintStr(L"-help, -? display this help\r\n"); + blexit(NULL); + } + else + { + PrintStr(L"WARNING: Unknown command line option '"); + PrintStr(ptr); + PrintStr(L"' ignored\r\n"); + } + } + else + *section_name = ptr; + } + + if ( argc ) + { + *image_name = *argv; + } +} + /* Truncate string at first space, and return pointer * to remainder of string. */ diff --git a/xen/include/efi/efi-shared.h b/xen/include/efi/efi-shared.h index a1028d1..b21793b 100644 --- a/xen/include/efi/efi-shared.h +++ b/xen/include/efi/efi-shared.h @@ -48,6 +48,9 @@ CHAR16 *__init point_tail(CHAR16 *fn); void __init pre_parse(const struct file *cfg); char *__init get_value(const struct file *cfg, const char *section, const char *item); +unsigned int __init get_argv(unsigned int argc, CHAR16 **argv, + CHAR16 *cmdline, UINTN cmdsize, + CHAR16 **cmdline_remain); @@ -61,4 +64,8 @@ void __init read_config_file(EFI_FILE_HANDLE *cfg_dir_handle, struct file *cfg, CHAR16 *cfg_file_name, union string *section, CHAR16 *xen_file_name); +void __init handle_cmdline(EFI_LOADED_IMAGE *loaded_image, + CHAR16 **cfg_file_name, bool_t *base_video, + CHAR16 **image_name, CHAR16 **section_name, + CHAR16 **cmdline_remain); #endif