[elf] Fix argument passing

This commit is contained in:
Kevin Lange 2011-04-08 16:02:30 -05:00
parent e273784242
commit fe40c7bbf6
3 changed files with 19 additions and 5 deletions

View File

@ -14,7 +14,7 @@ ECHO = `which echo` -e
MODULES = $(patsubst %.c,%.o,$(wildcard kernel/core/*.c))
FILESYSTEMS = $(patsubst %.c,%.o,$(wildcard kernel/core/fs/*.c))
VIDEODRIVERS = $(patsubst %.c,%.o,$(wildcard kernel/core/video/*.c))
BINARIES = initrd/bin/test
BINARIES = initrd/bin/test initrd/bin/echo
UTILITIES = util/bin/readelf
EMU = qemu
GENEXT = genext2fs
@ -112,11 +112,10 @@ loader/crtbegin.o: loader/crtbegin.s
@${YASM} -f elf32 -o $@ $<
@${ECHO} "\r\033[32;1m yasm $<\033[0m"
initrd/bin/test: loader/test.o loader/crtbegin.o
initrd/bin/%: loader/%.o loader/crtbegin.o
@${ECHO} -n "\033[32m LD $<\033[0m"
@${LD} -T loader/link.ld -o $@ $<
@${ECHO} "\r\033[32;1m LD $<\033[0m"
@${ECHO} "\033[34;1m -- Kernel is ready!\033[0m"
loader/%.o: loader/%.c
@${ECHO} -n "\033[32m CC $<\033[0m"

View File

@ -2,8 +2,7 @@ BITS 32
global _start
_start:
push 0 ; argc
push 0 ; argv
pop eax
extern main
call main
mov ebx, eax ; return value from main

16
loader/echo.c Normal file
View File

@ -0,0 +1,16 @@
int syscall_print(const char * p1) {
int a = 0xA5ADFACE;
__asm__ __volatile__("int $0x7F" : "=a" (a) : "0" (1), "b" ((int)p1));
return a;
}
int main(int argc, char ** argv) {
for (int i = 1; i < argc; ++i) {
syscall_print(argv[i]);
if (i != argc - 1) {
syscall_print(" ");
}
}
syscall_print("\n");
return 0;
}