From 5d420b0d68b1cbaf73fc6946eeb75b8031092a2d Mon Sep 17 00:00:00 2001 From: Tom-on64 Date: Sat, 26 Oct 2024 14:40:18 +0200 Subject: [PATCH] Fixed everything to work with the new libc --- boot/{stage3.ld => linker.ld} | 2 ++ boot/makefile | 30 ++++++++++++++++++++++-------- boot/{stage1.asm => stage1.s} | 0 boot/{stage2.asm => stage2.s} | 0 boot/stage3.c | 1 - kernel/kernel.c | 12 ++++++------ kernel/{kernel.ld => linker.ld} | 2 ++ kernel/makefile | 2 +- libk/fs/impl.c | 2 +- libk/makefile | 4 ++-- libk/syscalls/sys_read.c | 2 +- libk/syscalls/syscalls.c | 4 ++-- make.defaults | 6 +++--- makefile | 3 +-- 14 files changed, 43 insertions(+), 27 deletions(-) rename boot/{stage3.ld => linker.ld} (90%) rename boot/{stage1.asm => stage1.s} (100%) rename boot/{stage2.asm => stage2.s} (100%) rename kernel/{kernel.ld => linker.ld} (88%) diff --git a/boot/stage3.ld b/boot/linker.ld similarity index 90% rename from boot/stage3.ld rename to boot/linker.ld index 4d10518..e6feb9b 100644 --- a/boot/stage3.ld +++ b/boot/linker.ld @@ -1,4 +1,6 @@ /* Third stage "prekernel" */ +OUTPUT_FORMAT("binary") + SECTIONS { .text 0x50000 : { *(entry); diff --git a/boot/makefile b/boot/makefile index 62259bf..6fe311d 100644 --- a/boot/makefile +++ b/boot/makefile @@ -4,12 +4,26 @@ include make.defaults -bootloader: $(BOOT_DIR)/stage1.asm $(BOOT_DIR)/stage2.asm $(BOOT_DIR)/stage3.c $(LIBC) $(LIBK) - @echo "Assembling $(BOOT_DIR)/stage1.asm..." - $(AS) -fbin -o $(BIN)/stage1.bin $(BOOT_DIR)/stage1.asm $(ASFLAGS) - @echo "Assembling $(BOOT_DIR)/stage2.asm..." - $(AS) -fbin -o $(BIN)/stage2.bin $(BOOT_DIR)/stage2.asm $(ASFLAGS) - @echo "Compiling $(BOOT_DIR)/stage3.c..." - $(CC) $(CFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/boot/stage3.o -c $(BOOT_DIR)/stage3.c - $(LD) $(LDFLAGS) -T$(BOOT_DIR)/stage3.ld --oformat binary -o $(BIN)/stage3.bin $(BIN)/boot/stage3.o $(LIBC) $(LIBK) +STAGE1 = $(BIN)/stage1.bin +STAGE2 = $(BIN)/stage2.bin +STAGE3 = $(BIN)/stage3.bin +STAGE1_SRC = $(BOOT_DIR)/stage1.s +STAGE2_SRC = $(BOOT_DIR)/stage2.s +STAGE3_SRC = $(BOOT_DIR)/stage3.c +STAGE3_OBJ = $(BIN)/boot/stage3.o + +bootloader: $(STAGE1) $(STAGE2) $(STAGE3) + +$(STAGE1): $(STAGE1_SRC) + @echo "Assembling $<..." + $(AS) -fbin -o $@ $< $(ASFLAGS) + +$(STAGE2): $(STAGE2_SRC) + @echo "Assembling $<..." + $(AS) -fbin -o $@ $< $(ASFLAGS) + +$(STAGE3): $(STAGE3_SRC) + @echo "Compiling $(STAGE3_SRC)..." + $(CC) $(CFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(STAGE3_OBJ) -c $< + $(LD) $(LDFLAGS) -T$(BOOT_DIR)/linker.ld -o $@ $(STAGE3_OBJ) $(LIBK) diff --git a/boot/stage1.asm b/boot/stage1.s similarity index 100% rename from boot/stage1.asm rename to boot/stage1.s diff --git a/boot/stage2.asm b/boot/stage2.s similarity index 100% rename from boot/stage2.asm rename to boot/stage2.s diff --git a/boot/stage3.c b/boot/stage3.c index 4860862..580a297 100644 --- a/boot/stage3.c +++ b/boot/stage3.c @@ -7,7 +7,6 @@ #include #include #include -#include __attribute__ ((section("entry"))) void main() { diff --git a/kernel/kernel.c b/kernel/kernel.c index dc59502..9aa01bf 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -119,7 +119,7 @@ void main() { char input[256]; char* inPtr = &input[0]; - reads(inPtr); + gets(inPtr, 256); } } @@ -131,7 +131,7 @@ int _m() { char input[256]; char* inputPtr = input; - reads(input); + gets(input, 256); if (*input == '\0') continue; @@ -210,7 +210,7 @@ int _m() { drawCircle(1500, 600, 300, WHITE); fillCircle(950, 750, 75, rgb(0xa2, 0xd6, 0xf9)); - getc(); // Wait until we get a keystroke + getc(stdin); // Wait until we get a keystroke printf("\x1b[J"); } else if (strcmp(argv[0], "help") == 0) { printf("Available Commands:\n"); @@ -286,7 +286,7 @@ int _m() { char c = fp->_ptr[i++]; printf("%c", c < 32 ? '.' : c); } - putc('\n'); + putc('\n', stdout); } printf("%04x: ", i); } @@ -321,14 +321,14 @@ void listFiles() { uint32_t total = 0; while ((dentry + total)->name[0] != '\0') { total++; } - putc(' '); // TODO + putc(' ', stdout); // TODO printf("\bTotal %d\n", total); while (dentry->name[0] != '\0') { inode_t* inode = (inode_t*)BOOT_FIRST_INODE_LOC + dentry->id; printf("%s", dentry->name); - for (uint32_t pad = (16 - strlen(dentry->name)); pad > 0; pad--) { putc(' '); } + for (uint32_t pad = (16 - strlen(dentry->name)); pad > 0; pad--) { putc(' ', stdout); } switch (inode->type) { case FT_FILE: printf("%dB\n", inode->sizeBytes); break; diff --git a/kernel/kernel.ld b/kernel/linker.ld similarity index 88% rename from kernel/kernel.ld rename to kernel/linker.ld index 3eb2768..e2b5b05 100644 --- a/kernel/kernel.ld +++ b/kernel/linker.ld @@ -1,3 +1,5 @@ +OUTPUT_FORMAT("binary") + SECTIONS { .text 0xC0000000 : { *(entry); diff --git a/kernel/makefile b/kernel/makefile index 06cd3f1..4dfddd9 100644 --- a/kernel/makefile +++ b/kernel/makefile @@ -7,5 +7,5 @@ include make.defaults $(KERNEL): $(KERNEL_SRC) $(LIBC) $(LIBK) @echo "Compiling $(KERNEL_SRC)..." $(CC) $(CFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/kernel/kernel.o -c $(KERNEL_SRC) - $(LD) $(LDFLAGS) -T$(KERNEL_DIR)/kernel.ld --oformat binary -o $(BIN)/kernel.bin $(BIN)/kernel/kernel.o $(LIBC) $(LIBK) + $(LD) $(LDFLAGS) -T$(KERNEL_DIR)/linker.ld -o $@ $(BIN)/kernel/kernel.o $(LIBK) diff --git a/libk/fs/impl.c b/libk/fs/impl.c index e83540f..be4e342 100644 --- a/libk/fs/impl.c +++ b/libk/fs/impl.c @@ -2,10 +2,10 @@ #include #include #include -#include #include #include #include +#include superblock_t* impl_superblock = (superblock_t*)SUPERBLOCK_LOC; fsInfo_t* fsInfo = (fsInfo_t*)FS_INFO_LOC; diff --git a/libk/makefile b/libk/makefile index 257bf15..93bcdd9 100644 --- a/libk/makefile +++ b/libk/makefile @@ -6,12 +6,12 @@ include make.defaults LIBK_ASM=$(LIBK_DIR)/interrupt/isr.s -$(LIBK): $(LIBK_SRC) $(LIBK_ASM) +$(LIBK): $(LIBK_SRC) $(LIBK_ASM) $(LIBC) @echo "Building $(LIBK)..." nasm -felf32 -o $(BIN)/libk/isr_asm.o $(LIBK_ASM) for f in $(LIBK_SRC); do\ filename=$$(basename $$f .c);\ $(CC) $(CFLAGS) -I$(LIBC_INC) -I$(LIBK_INC) -o $(BIN)/libk/$$filename.o -c $$f;\ done - $(LD) $(LDFLAGS) -r -o $(LIBK) $(BIN)/libk/**.o + $(LD) $(LDFLAGS) -r -o $(LIBK) $(LIBC) $(BIN)/libk/**.o diff --git a/libk/syscalls/sys_read.c b/libk/syscalls/sys_read.c index e48214d..3b9ab83 100644 --- a/libk/syscalls/sys_read.c +++ b/libk/syscalls/sys_read.c @@ -4,7 +4,7 @@ int sys_read(intFrame_t* iframe) { char* s = (char*)iframe->ebx; - reads(s); + gets(s, 0xffffffff); return 0; } diff --git a/libk/syscalls/syscalls.c b/libk/syscalls/syscalls.c index f539130..d39946a 100644 --- a/libk/syscalls/syscalls.c +++ b/libk/syscalls/syscalls.c @@ -4,7 +4,7 @@ #include // System call table -int (*syscalls[MAX_SYSCALLS])(intFrame_t*) = { +int (*syscalls[SYSCALL_COUNT])(intFrame_t*) = { [SYS_EXIT] = sys_exit, [SYS_READ] = sys_read, [SYS_WRITE] = sys_write, @@ -18,7 +18,7 @@ int (*syscalls[MAX_SYSCALLS])(intFrame_t*) = { // Syscall handler int syscallHandler(intFrame_t* iframe) { - if (iframe->eax > MAX_SYSCALLS-1) { // Syscall doesn't exist + if (iframe->eax > SYSCALL_COUNT-1) { // Syscall doesn't exist debugf("Error: Syscall(%d) does not exist!\n", iframe->eax); return -1; } diff --git a/make.defaults b/make.defaults index 375d5ef..8d43cfb 100644 --- a/make.defaults +++ b/make.defaults @@ -1,5 +1,5 @@ # -# Makfile variables +# Makefile variables # # Tools @@ -13,8 +13,8 @@ MAKE = make CFLAGS = -Wall -Wextra -Wno-pointer-sign -Wno-pointer-arith -Wno-unused-parameter\ -Os -std=c17 -nostdinc -g -Werror\ -ffreestanding -fno-stack-protector -fno-builtin -fno-pie -fcommon\ - -m32 -march=i386 -LDFLAGS = -z notext -melf_i386 -nostdlib + -m32 -march=i386 +LDFLAGS = -z notext -nostdlib -melf_i386 ASFLAGS = # Directories diff --git a/makefile b/makefile index d9ffb50..e71c4e7 100644 --- a/makefile +++ b/makefile @@ -2,8 +2,7 @@ # Main kern makefile # -# Version -export VERSION = 0.2.0 +export VERSION = 0.2.1 # Configurable variables (eg. CC, CFLAGS, ...) include make.defaults