Signed-off-by: Avi Kivity <avi@xxxxxxxxxx> --- kvm/test/Makefile | 1 + kvm/test/lib/argv.c | 33 +++++++++++++++++++++++++++++++++ kvm/test/x86/cstart.S | 6 ++++++ kvm/test/x86/cstart64.S | 10 ++++++++++ 4 files changed, 50 insertions(+), 0 deletions(-) create mode 100644 kvm/test/lib/argv.c diff --git a/kvm/test/Makefile b/kvm/test/Makefile index 456ceae..5347ce8 100644 --- a/kvm/test/Makefile +++ b/kvm/test/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/kvm/test/lib/argv.c b/kvm/test/lib/argv.c new file mode 100644 index 0000000..4ee54a6 --- /dev/null +++ b/kvm/test/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/kvm/test/x86/cstart.S b/kvm/test/x86/cstart.S index 0471b92..1bdf789 100644 --- a/kvm/test/x86/cstart.S +++ b/kvm/test/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/kvm/test/x86/cstart64.S b/kvm/test/x86/cstart64.S index f1a9d09..0b7de66 100644 --- a/kvm/test/x86/cstart64.S +++ b/kvm/test/x86/cstart64.S @@ -70,6 +70,8 @@ i = i + 1 .endr tss_end: +mb_boot_info: .quad 0 + .section .init .code32 @@ -79,6 +81,7 @@ mb_flags = 0x0 # multiboot header .long mb_magic, mb_flags, 0 - (mb_magic + mb_flags) +mb_cmdline = 16 MSR_GS_BASE = 0xc0000101 @@ -91,6 +94,7 @@ MSR_GS_BASE = 0xc0000101 .globl start start: + mov %ebx, mb_boot_info mov $stacktop, %esp setup_percpu_area call prepare_64 @@ -174,6 +178,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 -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html