From d9a184c0d7cce823745dbece1e7d998350122552 Mon Sep 17 00:00:00 2001 From: Tyler McGurrin Date: Sat, 31 May 2025 08:47:58 -0400 Subject: [PATCH] Alotta Works been done, finally got the FAT driver in NBOOT to work with directories, start setting up kernelparams --- Makefile | 8 ++--- src/bootloader/stage1/boot.asm | 48 +++++++++++++++++---------- src/bootloader/stage2/Makefile | 6 ++-- src/bootloader/stage2/fat.c | 18 +++++----- src/bootloader/stage2/main.c | 60 ++++++++++++++++------------------ src/libs/version.h | 2 +- 6 files changed, 77 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index acbfaf4..628ea26 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,12 @@ $(BUILD_DIR)/main_floppy.img: bootloader kernel dd if=/dev/zero of=$(BUILD_DIR)/main_floppy.img bs=512 count=2880 mkfs.fat -F 12 -n "NANITE" $(BUILD_DIR)/main_floppy.img dd if=$(BUILD_DIR)/stage1.bin of=$(BUILD_DIR)/main_floppy.img conv=notrunc - mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/stage2.bin "::stage2.bin" mmd -i $(BUILD_DIR)/main_floppy.img "::boot" - mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin" mmd -i $(BUILD_DIR)/main_floppy.img "::misc" - mcopy -v -i $(BUILD_DIR)/main_floppy.img kernelparams "::misc" - mcopy -i $(BUILD_DIR)/main_floppy.img test "::misc" + mcopy -v -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::boot" + mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/nboot.bin "::nboot.bin" + mcopy -v -i $(BUILD_DIR)/main_floppy.img kernelparams "::boot" + mcopy -v -i $(BUILD_DIR)/main_floppy.img test "::boot" # # Bootloader diff --git a/src/bootloader/stage1/boot.asm b/src/bootloader/stage1/boot.asm index 409cf6b..e5d62c2 100644 --- a/src/bootloader/stage1/boot.asm +++ b/src/bootloader/stage1/boot.asm @@ -73,7 +73,7 @@ start: push es mov ah, 08h int 13h - jc floppy_error + jc error pop es and cl, 0x3F ; remove top 2 bits @@ -111,10 +111,29 @@ start: mov bx, buffer ; es:bx = buffer call disk_read - ; search for kernel.bin + ; search for stage2 xor bx, bx mov di, buffer +; .search_boot_dir: +; mov si, boot_dir +; mov cx, 11 ; compare up to 11 characters +; push di +; repe cmpsb +; pop di +; je .found_boot_dir + +; add di, 32 +; inc bx +; cmp bx, [bdb_dir_entries_count] +; jl .search_boot_dir + +; ; kernel not found +; jmp error + +; .found_boot_dir: +; hlt + .search_stage2: mov si, file_stage2_bin mov cx, 11 ; compare up to 11 characters @@ -129,7 +148,7 @@ start: jl .search_stage2 ; kernel not found - jmp stage2_not_found_error + jmp error .found_stage2: @@ -209,16 +228,11 @@ start: ; -; Error handlers +; Error handler (i needed more room.) ; -floppy_error: - mov si, msg_read_failed - call puts - jmp wait_key_and_reboot - -stage2_not_found_error: - mov si, msg_no_stage2 +error: + mov si, msg_error call puts jmp wait_key_and_reboot @@ -339,7 +353,7 @@ disk_read: .fail: ; all attempts are exhausted - jmp floppy_error + jmp error .done: popa @@ -362,15 +376,15 @@ disk_reset: mov ah, 0 stc int 13h - jc floppy_error + jc error popa ret -msg_loading: db '', ENDL, 0 -msg_read_failed: db 'Cant Read Disk!', ENDL, 0 -msg_no_stage2: db 'Cant Find Stage 2!', ENDL, 0 -file_stage2_bin: db 'STAGE2 BIN' +msg_loading: db 'Loading NBOOT...', ENDL, 0 +msg_error: db 'ERR!', ENDL, 0 +file_stage2_bin: db 'NBOOT BIN' +boot_dir: db 'BOOT ' stage2_cluster: dw 0 STAGE2_LOAD_SEGMENT equ 0x0 diff --git a/src/bootloader/stage2/Makefile b/src/bootloader/stage2/Makefile index c5f162c..fc8fda7 100644 --- a/src/bootloader/stage2/Makefile +++ b/src/bootloader/stage2/Makefile @@ -14,9 +14,9 @@ HEADERS_C= $(wildcard ../../libs/*.h) \ all: stage2 -stage2: $(BUILD_DIR)/stage2.bin +stage2: $(BUILD_DIR)/nboot.bin -$(BUILD_DIR)/stage2.bin: $(OBJECTS_ASM) $(OBJECTS_C) +$(BUILD_DIR)/nboot.bin: $(OBJECTS_ASM) $(OBJECTS_C) $(TARGET_LD) $(TARGET_LINKFLAGS) -Wl,-Map=$(BUILD_DIR)/stage2.map -o $@ $^ $(TARGET_LIBS) $(BUILD_DIR)/stage2/c/%.obj: %.c always $(HEADERS_C) @@ -30,4 +30,4 @@ always: mkdir -p $(BUILD_DIR)/stage2/asm clean: - rm -f $(BUILD_DIR)/stage2.bin \ No newline at end of file + rm -f $(BUILD_DIR)/nboot.bin \ No newline at end of file diff --git a/src/bootloader/stage2/fat.c b/src/bootloader/stage2/fat.c index ee76b93..3a8916a 100644 --- a/src/bootloader/stage2/fat.c +++ b/src/bootloader/stage2/fat.c @@ -325,7 +325,7 @@ FAT_File* FAT_Open(DISK* disk, const char* path) // ignore leading slash if (path[0] == '/') path++; - printf("Path: %s\r\n", path); + FAT_File* current = &g_Data->RootDirectory.Public; while (*path) { @@ -350,17 +350,10 @@ FAT_File* FAT_Open(DISK* disk, const char* path) // find directory entry in current directory FAT_DirectoryEntry entry; - if (!FAT_FindFile(disk, current, name, &entry)) + if (FAT_FindFile(disk, current, name, &entry)) { FAT_Close(current); - printf("FAT: %s not found\r\n", name); - return NULL; - } else - { - FAT_Close(current); - printf("We make it here.\r\n"); - // check if directory if (!isLast && entry.Attributes & FAT_ATTRIBUTE_DIRECTORY == 0) { @@ -371,6 +364,13 @@ FAT_File* FAT_Open(DISK* disk, const char* path) // open new directory entry current = FAT_OpenEntry(disk, &entry); } + else + { + FAT_Close(current); + + printf("FAT: %s not found\r\n", name); + return NULL; + } } return current; diff --git a/src/bootloader/stage2/main.c b/src/bootloader/stage2/main.c index 1c1bb7b..0e832ad 100644 --- a/src/bootloader/stage2/main.c +++ b/src/bootloader/stage2/main.c @@ -67,44 +67,42 @@ void* g_data = (void*)0x20000; printf("Failed!\nDisk Initialization Error!\n"); goto end; } - // printf("Done!\n"); + printf("Done!\n"); - // // test fat driver - // printf("Testing FAT Driver..."); - // // read test.txt - // FAT_File* ft = FAT_Open(&disk, "/misc"); - // char buffer[100]; - // uint32_t testread; - // ft = FAT_Open(&disk, "test"); // move test.txt in MISC folder later (TM) - // while ((testread = FAT_Read(&disk, ft, sizeof(buffer), buffer))) - // { - // for (uint32_t i = 0; i < testread; i++) - // { - // if (buffer[i] == '\n') - // putc('\r'); - // putc(buffer[i]); - // } - // } - // FAT_Close(ft); + // test fat driver + printf("Testing FAT Driver..."); + // read test.txt + FAT_File* ft = FAT_Open(&disk, "/test"); + char buffer[100]; + uint32_t testread; + while ((testread = FAT_Read(&disk, ft, sizeof(buffer), buffer))) + { + for (uint32_t i = 0; i < testread; i++) + { + if (buffer[i] == '\n') + putc('\r'); + putc(buffer[i]); + } + } + FAT_Close(ft); printf("Detecting Memory..."); // prep boot params g_BootParams.BootDevice = bootDrive; Memory_Detect(&g_BootParams.Memory); printf("Done!\n"); - // // kernel params... - // FAT_File* kp = FAT_Open(&disk, "/misc"); - // uint32_t kernelparams; - // while ((kernelparams = FAT_Read(&disk, kp, sizeof(buffer), buffer))) - // { - // for (uint32_t i = 0; i < kernelparams; i++) - // { - // if (buffer[i] == '\n') - // putc('\r'); - // putc(buffer[i]); - // } - // } - // FAT_Close(kp); + // kernel params... + FAT_File* kp = FAT_Open(&disk, "/kernelparams"); + char kparams; + uint32_t kernelparams; + while ((kernelparams = FAT_Read(&disk, kp, sizeof(buffer), buffer))) + { + for (uint32_t i = 0; i < kernelparams; i++) + { + memcpy(); + } + } + FAT_Close(kp); // load kernel from disk printf("Loading Kernel..."); diff --git a/src/libs/version.h b/src/libs/version.h index 19cdf80..d3082dd 100644 --- a/src/libs/version.h +++ b/src/libs/version.h @@ -6,5 +6,5 @@ #pragma once #define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n" -#define VERSION "RD-00017" +#define VERSION "RD-00019" #define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"