From b5cc973c2661d434b144d8d11b685dcfa8c63e55 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 27 Apr 2019 04:05:04 +0200 Subject: [PATCH] Parse the command-line arguments in uLoader too --- src/arch/i386/kernel.S | 1 + src/arch/i386/loader.S | 53 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/arch/i386/kernel.S b/src/arch/i386/kernel.S index 51dddc3..2933394 100644 --- a/src/arch/i386/kernel.S +++ b/src/arch/i386/kernel.S @@ -95,6 +95,7 @@ _start: mov %esp, %ebp push $0x0 /* argc */ + /* FIXME mi->cmdline may be NULL */ mov %ebx, %ecx /* ecx = mi->cmdline; */ add $0x10, %ecx mov (%ecx), %ecx /* ecx = *ecx; */ diff --git a/src/arch/i386/loader.S b/src/arch/i386/loader.S index a0aa908..2e2af7f 100644 --- a/src/arch/i386/loader.S +++ b/src/arch/i386/loader.S @@ -88,19 +88,52 @@ _start: call multiboot add $0x4, %esp - /* start the loader */ + /* parse the command line */ push %ebp mov %esp, %ebp + push $0x0 /* argc */ + + /* FIXME mi->cmdline may be NULL */ + mov %ebx, %ecx /* ecx = mi->cmdline; */ + add $0x10, %ecx + mov (%ecx), %ecx /* ecx = *ecx; */ + mov %ecx, %edx /* edx = ecx; */ +3: + mov (%edx), %al /* al = *edx; */ + cmp $0x0, %al /* if(al == '\0') */ + je 4f /* goto 4f; */ + inc %edx /* edx++; */ + jmp 3b /* goto 3b; */ +4: + push $0x0 /* argv[] = NULL; */ +5: + cmp %ecx, %edx /* if(ecx == edx) */ + je 7f /* goto 7f; */ + mov (%edx), %al /* al = *edx; */ + cmp $0x20, %al /* if(al != ' ') */ + jne 6f /* goto 6f; */ + movb $0x0, (%edx) /* *edx = '\0'; */ + inc %edx + push %edx /* argv[] = edx; */ + DEBUG_STRING(%edx) + dec %edx + incl -0x4(%ebp) /* argc++; */ +6: + dec %edx /* edx--; */ + jmp 5b /* goto 4b; */ +7: + push %edx /* argv[] = edx; */ + DEBUG_STRING(%edx) + incl -0x4(%ebp) /* argc++; */ + + /* prepare the arguments */ + mov %esp, %eax /* eax = &argv; */ + push %esp + push %ebx /* auxv */ + push $0x0 /* envp */ + push %eax /* argv */ + push -0x4(%ebp) /* argc */ - push $0x0 - push $0x0 - mov %ebx, %eax - add $0x10, %eax - push %eax - push $0x1 - call main - mov %ebp, %esp - pop %ebp jmp 2f 1: