test: support argc/argv parameters to main()
PATCH 1/1 test: support argc/argv parameters to main()
Signed-off-by Avi Kivity <[email protected]>
--- 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
kvm/test/Makefile +1 -0
@@ -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
kvm/test/lib/argv.c new file +33 -0
@@ -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; +}
kvm/test/x86/cstart.S +6 -0
@@ -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
kvm/test/x86/cstart64.S +10 -0
@@ -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
Signature · 1 line
1.7.1