diff mbox

[Xen-devel,RFC,14/19] Move get_argv() and handle_cmdline() to efi-shared.c

Message ID 1403918735-30027-15-git-send-email-roy.franz@linaro.org
State New
Headers show

Commit Message

Roy Franz June 28, 2014, 1:25 a.m. UTC
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 <roy.franz@linaro.org>
---
 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 mbox

Patch

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=<file>  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=<file>  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