From 37dbb99f509305dbf76ec7a4abe8d2c198595aee Mon Sep 17 00:00:00 2001 From: "brice.boisson" Date: Wed, 11 Oct 2023 09:38:29 +0900 Subject: [PATCH] Add: userland hello world code --- Makefile | 4 ++-- Makefile.common | 1 + app/hello_world.c | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 app/hello_world.c diff --git a/Makefile b/Makefile index b87473f..252c1bb 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,8 @@ install: bin: $(MAKE) -C $(LIB) - gcc -c test.c -Ilibk -Llibk -lk -m32 - ld -m elf_i386 -Ttext=0x6000000 --entry=main test.o -L./libk/ -lk + gcc -c ./app/$(APP).c -Ilibk -Llibk -lk -m32 + ld -m elf_i386 -Ttext=0x6000000 --entry=main ./$(APP).o -L./libk/ -lk objcopy --input binary --output elf32-i386 --binary-architecture i386 --rename-section .data=.rodata,CONTENTS,ALLOC,LOAD,READONLY,DATA a.out myfile.o cp myfile.o $(SOURCEDIR)/myfile.o diff --git a/Makefile.common b/Makefile.common index 92ed0b0..561c3fb 100644 --- a/Makefile.common +++ b/Makefile.common @@ -5,3 +5,4 @@ GRUBDIR = iso SOURCEDIR = src TARGET = kernel LIB=libk +APP=hello_world diff --git a/app/hello_world.c b/app/hello_world.c new file mode 100644 index 0000000..6c98f9c --- /dev/null +++ b/app/hello_world.c @@ -0,0 +1,10 @@ +#include + +static char s[] = "Hello from userland!\n"; + +int main(void) +{ + write(1, s, 21); + while (1); + return 0; +}