Alotta Works been done, finally got the FAT driver in NBOOT to work with directories,

start setting up kernelparams
This commit is contained in:
Tyler McGurrin 2025-05-31 08:47:58 -04:00
parent dc7bbf2dc0
commit d9a184c0d7
6 changed files with 77 additions and 65 deletions

View File

@ -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 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 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 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" 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" mmd -i $(BUILD_DIR)/main_floppy.img "::misc"
mcopy -v -i $(BUILD_DIR)/main_floppy.img kernelparams "::misc" mcopy -v -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::boot"
mcopy -i $(BUILD_DIR)/main_floppy.img test "::misc" 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 # Bootloader

View File

@ -73,7 +73,7 @@ start:
push es push es
mov ah, 08h mov ah, 08h
int 13h int 13h
jc floppy_error jc error
pop es pop es
and cl, 0x3F ; remove top 2 bits and cl, 0x3F ; remove top 2 bits
@ -111,10 +111,29 @@ start:
mov bx, buffer ; es:bx = buffer mov bx, buffer ; es:bx = buffer
call disk_read call disk_read
; search for kernel.bin ; search for stage2
xor bx, bx xor bx, bx
mov di, buffer 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: .search_stage2:
mov si, file_stage2_bin mov si, file_stage2_bin
mov cx, 11 ; compare up to 11 characters mov cx, 11 ; compare up to 11 characters
@ -129,7 +148,7 @@ start:
jl .search_stage2 jl .search_stage2
; kernel not found ; kernel not found
jmp stage2_not_found_error jmp error
.found_stage2: .found_stage2:
@ -209,16 +228,11 @@ start:
; ;
; Error handlers ; Error handler (i needed more room.)
; ;
floppy_error: error:
mov si, msg_read_failed mov si, msg_error
call puts
jmp wait_key_and_reboot
stage2_not_found_error:
mov si, msg_no_stage2
call puts call puts
jmp wait_key_and_reboot jmp wait_key_and_reboot
@ -339,7 +353,7 @@ disk_read:
.fail: .fail:
; all attempts are exhausted ; all attempts are exhausted
jmp floppy_error jmp error
.done: .done:
popa popa
@ -362,15 +376,15 @@ disk_reset:
mov ah, 0 mov ah, 0
stc stc
int 13h int 13h
jc floppy_error jc error
popa popa
ret ret
msg_loading: db '', ENDL, 0 msg_loading: db 'Loading NBOOT...', ENDL, 0
msg_read_failed: db 'Cant Read Disk!', ENDL, 0 msg_error: db 'ERR!', ENDL, 0
msg_no_stage2: db 'Cant Find Stage 2!', ENDL, 0 file_stage2_bin: db 'NBOOT BIN'
file_stage2_bin: db 'STAGE2 BIN' boot_dir: db 'BOOT '
stage2_cluster: dw 0 stage2_cluster: dw 0
STAGE2_LOAD_SEGMENT equ 0x0 STAGE2_LOAD_SEGMENT equ 0x0

View File

@ -14,9 +14,9 @@ HEADERS_C= $(wildcard ../../libs/*.h) \
all: stage2 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) $(TARGET_LD) $(TARGET_LINKFLAGS) -Wl,-Map=$(BUILD_DIR)/stage2.map -o $@ $^ $(TARGET_LIBS)
$(BUILD_DIR)/stage2/c/%.obj: %.c always $(HEADERS_C) $(BUILD_DIR)/stage2/c/%.obj: %.c always $(HEADERS_C)
@ -30,4 +30,4 @@ always:
mkdir -p $(BUILD_DIR)/stage2/asm mkdir -p $(BUILD_DIR)/stage2/asm
clean: clean:
rm -f $(BUILD_DIR)/stage2.bin rm -f $(BUILD_DIR)/nboot.bin

View File

@ -325,7 +325,7 @@ FAT_File* FAT_Open(DISK* disk, const char* path)
// ignore leading slash // ignore leading slash
if (path[0] == '/') if (path[0] == '/')
path++; path++;
printf("Path: %s\r\n", path);
FAT_File* current = &g_Data->RootDirectory.Public; FAT_File* current = &g_Data->RootDirectory.Public;
while (*path) { while (*path) {
@ -350,17 +350,10 @@ FAT_File* FAT_Open(DISK* disk, const char* path)
// find directory entry in current directory // find directory entry in current directory
FAT_DirectoryEntry entry; FAT_DirectoryEntry entry;
if (!FAT_FindFile(disk, current, name, &entry)) if (FAT_FindFile(disk, current, name, &entry))
{ {
FAT_Close(current); 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 // check if directory
if (!isLast && entry.Attributes & FAT_ATTRIBUTE_DIRECTORY == 0) 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 // open new directory entry
current = FAT_OpenEntry(disk, &entry); current = FAT_OpenEntry(disk, &entry);
} }
else
{
FAT_Close(current);
printf("FAT: %s not found\r\n", name);
return NULL;
}
} }
return current; return current;

View File

@ -67,44 +67,42 @@ void* g_data = (void*)0x20000;
printf("Failed!\nDisk Initialization Error!\n"); printf("Failed!\nDisk Initialization Error!\n");
goto end; goto end;
} }
// printf("Done!\n"); printf("Done!\n");
// // test fat driver // test fat driver
// printf("Testing FAT Driver..."); printf("Testing FAT Driver...");
// // read test.txt // read test.txt
// FAT_File* ft = FAT_Open(&disk, "/misc"); FAT_File* ft = FAT_Open(&disk, "/test");
// char buffer[100]; char buffer[100];
// uint32_t testread; 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)))
// while ((testread = FAT_Read(&disk, ft, sizeof(buffer), buffer))) {
// { for (uint32_t i = 0; i < testread; i++)
// for (uint32_t i = 0; i < testread; i++) {
// { if (buffer[i] == '\n')
// if (buffer[i] == '\n') putc('\r');
// putc('\r'); putc(buffer[i]);
// putc(buffer[i]); }
// } }
// } FAT_Close(ft);
// FAT_Close(ft);
printf("Detecting Memory..."); printf("Detecting Memory...");
// prep boot params // prep boot params
g_BootParams.BootDevice = bootDrive; g_BootParams.BootDevice = bootDrive;
Memory_Detect(&g_BootParams.Memory); Memory_Detect(&g_BootParams.Memory);
printf("Done!\n"); printf("Done!\n");
// // kernel params... // kernel params...
// FAT_File* kp = FAT_Open(&disk, "/misc"); FAT_File* kp = FAT_Open(&disk, "/kernelparams");
// uint32_t kernelparams; char kparams;
// while ((kernelparams = FAT_Read(&disk, kp, sizeof(buffer), buffer))) uint32_t kernelparams;
// { while ((kernelparams = FAT_Read(&disk, kp, sizeof(buffer), buffer)))
// for (uint32_t i = 0; i < kernelparams; i++) {
// { for (uint32_t i = 0; i < kernelparams; i++)
// if (buffer[i] == '\n') {
// putc('\r'); memcpy();
// putc(buffer[i]); }
// } }
// } FAT_Close(kp);
// FAT_Close(kp);
// load kernel from disk // load kernel from disk
printf("Loading Kernel..."); printf("Loading Kernel...");

View File

@ -6,5 +6,5 @@
#pragma once #pragma once
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n" #define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
#define VERSION "RD-00017" #define VERSION "RD-00019"
#define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n" #define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"