From f6bbebbee3c779971d12afeb12b115b5467ca9b2 Mon Sep 17 00:00:00 2001 From: Alexander Myltsev Date: Mon, 21 Nov 2022 01:50:02 +0300 Subject: [PATCH] Add user/. --- Makefile | 9 +++++++-- user/crt.c | 6 ++++++ user/false.c | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 user/crt.c create mode 100644 user/false.c diff --git a/Makefile b/Makefile index 6333f8b..760de1a 100644 --- a/Makefile +++ b/Makefile @@ -27,15 +27,20 @@ debug: image.bin -ex "break _start" \ -ex "continue" -fs.img: kernel.bin tools/mkfs +fs.img: kernel.bin tools/mkfs user/false tools/mkfs $@ $< +LDFLAGS=-m elf_i386 + +user/%: user/%.o user/crt.o + $(LD) $(LDFLAGS) -o $@ -Ttext 0x101000 $^ + image.bin: mbr.bin fs.img cat $^ >$@ kernel.bin: kernel.o console.o drivers/vga.o drivers/keyboard.o \ string.o drivers/ata.o cpu/vectors.o cpu/idt.o drivers/uart.o - $(LD) -m elf_i386 -o $@ -Ttext 0x1000 $^ + $(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^ %.o: %.c $(CC) -m32 -ffreestanding -Wall -Werror -c -g $< -o $@ diff --git a/user/crt.c b/user/crt.c new file mode 100644 index 0000000..1a42f40 --- /dev/null +++ b/user/crt.c @@ -0,0 +1,6 @@ +int main(); + +void _start() { + int exit_status = main(); + asm("int $0x84": :"a"(exit_status)); +} diff --git a/user/false.c b/user/false.c new file mode 100644 index 0000000..6346e2d --- /dev/null +++ b/user/false.c @@ -0,0 +1,3 @@ +int main() { + return 1; +}