From: Avi Kivity <[email protected]>

Signed-off-by: Avi Kivity <[email protected]>

diff --git a/Makefile b/Makefile
index 456ceae..5347ce8 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@ cflatobjs := \
        lib/panic.o \
        lib/printf.o \
        lib/string.o
+cflatobjs += lib/argv.o
 
 #include architecure specific make rules
 include config-$(ARCH).mak
diff --git a/lib/argv.c b/lib/argv.c
new file mode 100644
index 0000000..4ee54a6
--- /dev/null
+++ b/lib/argv.c
@@ -0,0 +1,33 @@
+#include "libcflat.h"
+
+int __argc;
+char *__argv[100];
+char *__args;
+char __args_copy[1000];
+
+static bool isblank(char p)
+{
+    return p == ' ' || p == '\t';
+}
+
+static char *skip_blanks(char *p)
+{
+    while (isblank(*p))
+        ++p;
+    return p;
+}
+
+void __setup_args(void)
+{
+    char *args = __args;
+    char **argv = __argv;
+    char *p = __args_copy;
+
+    while (*(args = skip_blanks(args)) != '\0') {
+        *argv++ = p;
+        while (*args != '\0' && !isblank(*args))
+            *p++ = *args++;
+        *p++ = '\0';
+    }
+    __argc = argv - __argv;
+}
diff --git a/x86/cstart.S b/x86/cstart.S
index 0471b92..1bdf789 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -9,9 +9,15 @@ mb_flags = 0x0
 
        # multiboot header
        .long mb_magic, mb_flags, 0 - (mb_magic + mb_flags)
+mb_cmdline = 16
 
 .globl start
 start:
+       mov mb_cmdline(%ebx), %eax
+       mov %eax, __args
+       call __setup_args
+       pushl $__argv
+       pushl __argc
        call main
        push %eax
        call exit
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 46e9d5c..cc4c80f 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -75,6 +75,8 @@ i = i + 1
        .endr
 tss_end:
 
+mb_boot_info:  .quad 0
+
 .section .init
 
 .code32
@@ -84,6 +86,7 @@ mb_flags = 0x0
 
        # multiboot header
        .long mb_magic, mb_flags, 0 - (mb_magic + mb_flags)
+mb_cmdline = 16
 
 MSR_GS_BASE = 0xc0000101
 
@@ -96,6 +99,7 @@ MSR_GS_BASE = 0xc0000101
 
 .globl start
 start:
+       mov %ebx, mb_boot_info
        mov $stacktop, %esp
        setup_percpu_area
        call prepare_64
@@ -179,6 +183,12 @@ start64:
        call enable_apic
        call smp_init
        call enable_x2apic
+       mov mb_boot_info(%rip), %rax
+       mov mb_cmdline(%rax), %rax
+       mov %rax, __args(%rip)
+       call __setup_args
+       mov __argc(%rip), %edi
+       lea __argv(%rip), %rsi
        call main
        mov %eax, %edi
        call exit
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to