From 1cd67eec0ad08e426b208bf5de202def53e94676 Mon Sep 17 00:00:00 2001 From: d0p1 Date: Sat, 31 Aug 2024 14:40:07 +0200 Subject: [PATCH] refactor(boot): defn -> DEFN --- boot/common/fat12.inc | 4 +-- boot/common/macro.inc | 12 ++++----- boot/common/mbr.inc | 2 +- boot/efi/uefi.inc | 20 +++++++------- boot/loader/Makefile | 3 ++- boot/loader/fat.inc | 1 + boot/loader/loader.asm | 20 ++++++++++++++ boot/loader/multiboot.inc | 6 ++--- boot/loader/stpdfs.inc | 55 +++++++++++++++++++++++++++++++++++++++ 9 files changed, 100 insertions(+), 23 deletions(-) create mode 100644 boot/loader/stpdfs.inc diff --git a/boot/common/fat12.inc b/boot/common/fat12.inc index 39ec1d8..48db169 100644 --- a/boot/common/fat12.inc +++ b/boot/common/fat12.inc @@ -15,7 +15,7 @@ struc fat_bpb .sects_per_track dw ? .heads_per_cyl dw ? } -defn fat_bpb +DEFN fat_bpb ;; Struct: fat_entry struc fat_entry @@ -33,7 +33,7 @@ struc fat_entry .start dw ? .size dd ? } -defn fat_entry +DEFN fat_entry ;; Constants: Attributes ;; ATTR_READ_ONLY - Read-only diff --git a/boot/common/macro.inc b/boot/common/macro.inc index 1218de9..d24d2aa 100644 --- a/boot/common/macro.inc +++ b/boot/common/macro.inc @@ -1,9 +1,9 @@ ;; File: macro.inc - ;; Macro: defn name -macro defn name -{ - virtual at 0 - name name - end virtual + ;; Macro: DEFN name +macro DEFN x { +virtual at 0 + x x + sizeof.#x: +end virtual } diff --git a/boot/common/mbr.inc b/boot/common/mbr.inc index 1c4e01d..3c1e939 100644 --- a/boot/common/mbr.inc +++ b/boot/common/mbr.inc @@ -10,6 +10,6 @@ struc Partition .lba dd ? .sectors dd ? } -defn Partition +DEFN Partition diff --git a/boot/efi/uefi.inc b/boot/efi/uefi.inc index 5bdcc4d..78cf2bc 100644 --- a/boot/efi/uefi.inc +++ b/boot/efi/uefi.inc @@ -80,7 +80,7 @@ struc EFI_TIME .Daylight UINT8 .Pad2 UINT8 } -defn EFI_TIME +DEFN EFI_TIME struc EFI_TABLE_HEADER { @@ -90,7 +90,7 @@ struc EFI_TABLE_HEADER .CRC32 UINT32 .Reserved UINT32 } -defn EFI_TABLE_HEADER +DEFN EFI_TABLE_HEADER ;; ======================================================================== ;; EFI_SYSTEM_TABLE @@ -131,7 +131,7 @@ struc EFI_SYSTEM_TABLE .NumberOfTableEntries UINTN .ConfigurationTable UINTPTR } -defn EFI_SYSTEM_TABLE +DEFN EFI_SYSTEM_TABLE ;; ======================================================================== ;; EFI_BOOT_SERVICES @@ -210,7 +210,7 @@ struc EFI_BOOT_SERVICES .SetMem UINTPTR .CreateEventEx UINTPTR } -defn EFI_BOOT_SERVICES +DEFN EFI_BOOT_SERVICES ;; ======================================================================== ;; EFI_RUNTIMES_SERVICES @@ -269,7 +269,7 @@ struc EFI_LOADED_IMAGE_PROTOCOL .ImageDataType UINT32 .Unload UINTPTR } -defn EFI_LOADED_IMAGE_PROTOCOL +DEFN EFI_LOADED_IMAGE_PROTOCOL ;; ======================================================================== ;; EFI_DEVICE_PATH_PROTOCOL @@ -282,7 +282,7 @@ struc EFI_DEVICE_PATH_PROTOCOL .SubType UINT8 .Length db 2 dup(?) } -defn EFI_DEVICE_PATH_PROTOCOL +DEFN EFI_DEVICE_PATH_PROTOCOL ;; ======================================================================== ;; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL @@ -302,7 +302,7 @@ struc EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL .EnableCursor UINTPTR .Mode UINTPTR } -defn EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL +DEFN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL struc SIMPLE_TEXT_OUTPUT_MODE { @@ -350,7 +350,7 @@ struc EFI_LOAD_FILE_PROTOCOL { .LoadFile UINTPTR } -defn EFI_LOAD_FILE_PROTOCOL +DEFN EFI_LOAD_FILE_PROTOCOL ;; ======================================================================== @@ -372,7 +372,7 @@ struc EFI_SIMPLE_FILE_SYSTEM_PROTOCOL .Revision UINT64 .OpenVolume UINTPTR } -defn EFI_SIMPLE_FILE_SYSTEM_PROTOCOL +DEFN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL ;; ======================================================================== ;; EFI_FILE_PROTOCOL @@ -400,7 +400,7 @@ struc EFI_FILE_PROTOCOL .WriteEx UINTPTR .FlushEx UINTPTR } -defn EFI_FILE_PROTOCOL +DEFN EFI_FILE_PROTOCOL ; Open Mode EFI_FILE_MODE_READ = 0x0000000000000001 diff --git a/boot/loader/Makefile b/boot/loader/Makefile index 43d6f7a..b164565 100644 --- a/boot/loader/Makefile +++ b/boot/loader/Makefile @@ -10,7 +10,8 @@ LOADER_SRCS = loader.asm \ memory.inc \ logger.inc \ a20.inc \ - multiboot.inc + multiboot.inc \ + stpdfs.inc .PHONY: all all: $(TARGET) diff --git a/boot/loader/fat.inc b/boot/loader/fat.inc index 3bad234..213e163 100644 --- a/boot/loader/fat.inc +++ b/boot/loader/fat.inc @@ -2,6 +2,7 @@ include '../common/fat12.inc' + ;; Function: fat_read_bpb fat_read_bpb: mov ax, DISK_BUFFER/0x10 mov es, ax diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 31f2a79..fc3c3a8 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -76,9 +76,23 @@ _start: cmp dword [DISK_BUFFER], STPDFS_MAGIC jne .fat_fallback + mov si, szMsgStpdFSFound + call bios_log + + call stpdfs_load_rootdir + + mov si, szKernelStpdfsFile + call stpdfs_search + + + jmp .skip_fat + ; fallback to fat12 ; for now fat12 is asumed .fat_fallback: + mov si, szMsgFatFallback + call bios_log + ; get bpb call fat_read_bpb @@ -112,6 +126,8 @@ _start: xor bx, bx call fat_load_binary +.skip_fat: + ; fetch memory map from bios call memory_get_map jc .error_memory @@ -156,6 +172,7 @@ _start: include 'a20.inc' include '../common/bios.inc' include 'fat.inc' + include 'stpdfs.inc' include 'disk.inc' include 'logger.inc' include 'memory.inc' @@ -173,6 +190,9 @@ uKernelSize dd 0 szMsgStage2 db "StupidOS Loader", 0 szKernelFile db "VMSTUPIDSYS", 0 +szKernelStpdfsFile db "vmstupid.sys", 0 +szMsgStpdFSFound db "StupidFS found", 0 +szMsgFatFallback db "Fallback to FATFS", 0 szMsgKernelFound db "Kernel found, size: %x", 0 szMsgErrorA20 db "ERROR: can't enable a20 line", 0 szMsgErrorMemory db "ERROR: can't detect available memory", 0 diff --git a/boot/loader/multiboot.inc b/boot/loader/multiboot.inc index cec1cd0..f4db7e2 100644 --- a/boot/loader/multiboot.inc +++ b/boot/loader/multiboot.inc @@ -82,7 +82,7 @@ struc MultibootData .fb_type db ? .fb_misc dw 3 dup ? } -defn MultibootData +DEFN MultibootData MULTIBOOT_DATA_MEM = 0x0001 MULTIBOOT_DATA_BOOTDEV = 0x0002 @@ -101,7 +101,7 @@ struc MultibootMMap .length dq ? .type dd ? } -defn MultibootMMap +DEFN MultibootMMap MULTIBOOT_MEMORY_AVAILABLE = 0x1 MULTIBOOT_MEMORY_RESERVED = 0x2 @@ -116,4 +116,4 @@ struc MultibootModule .cmdline dd ? .pad dd ? } -defn MultibootModule +DEFN MultibootModule diff --git a/boot/loader/stpdfs.inc b/boot/loader/stpdfs.inc new file mode 100644 index 0000000..3783a8c --- /dev/null +++ b/boot/loader/stpdfs.inc @@ -0,0 +1,55 @@ +STPDFS_NAME_MAX = 28 + + ;; Struct: inode +struc inode { + .inode dw ? + .nlink dw ? + .uid dw ? + .gid dw ? + .flags dw ? + .size dd ? + .zones dd 10 dup(?) + .actime dq ? + .modtime dq ? +} +DEFN inode + + ;; Struct: dirent +struc dirent { + .inum dd ? + .name db STPDFS_NAME_MAX dup(?) +} +DEFN dirent + + ;; Function: stpdfs_load_rootdir + ;; + ;; Out: +stpdfs_load_rootdir: + ; read first inode + mov ax, DISK_BUFFER/0x10 + mov es, ax + mov ax, 2 + mov cx, 1 + xor bx, bx + call disk_read_sectors + + ; root dir is inode 1 + mov dword eax, [DISK_BUFFER + sizeof.inode * 2 + inode.size] + + + + ret + + ;; Function: stpdfs_search + ;; + ;; In: + ;; SI - filename + ;; +stpdfs_search: + clc ; clear carry flag + + + ret + +stpdfs_copy_data: + ret