Commit ea7d43d0 authored by Avi Kivity's avatar Avi Kivity
Browse files

Parse multiboot command line into argc/argv


Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 0d4c7614
......@@ -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
......
#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;
}
......@@ -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
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment