refactor(boot): defn -> DEFN

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-08-31 14:40:07 +02:00
parent c84e5b55e4
commit 1cd67eec0a
9 changed files with 100 additions and 23 deletions

View file

@ -15,7 +15,7 @@ struc fat_bpb
.sects_per_track dw ? .sects_per_track dw ?
.heads_per_cyl dw ? .heads_per_cyl dw ?
} }
defn fat_bpb DEFN fat_bpb
;; Struct: fat_entry ;; Struct: fat_entry
struc fat_entry struc fat_entry
@ -33,7 +33,7 @@ struc fat_entry
.start dw ? .start dw ?
.size dd ? .size dd ?
} }
defn fat_entry DEFN fat_entry
;; Constants: Attributes ;; Constants: Attributes
;; ATTR_READ_ONLY - Read-only ;; ATTR_READ_ONLY - Read-only

View file

@ -1,9 +1,9 @@
;; File: macro.inc ;; File: macro.inc
;; Macro: defn name ;; Macro: DEFN name
macro defn name macro DEFN x {
{ virtual at 0
virtual at 0 x x
name name sizeof.#x:
end virtual end virtual
} }

View file

@ -10,6 +10,6 @@ struc Partition
.lba dd ? .lba dd ?
.sectors dd ? .sectors dd ?
} }
defn Partition DEFN Partition

View file

@ -80,7 +80,7 @@ struc EFI_TIME
.Daylight UINT8 .Daylight UINT8
.Pad2 UINT8 .Pad2 UINT8
} }
defn EFI_TIME DEFN EFI_TIME
struc EFI_TABLE_HEADER struc EFI_TABLE_HEADER
{ {
@ -90,7 +90,7 @@ struc EFI_TABLE_HEADER
.CRC32 UINT32 .CRC32 UINT32
.Reserved UINT32 .Reserved UINT32
} }
defn EFI_TABLE_HEADER DEFN EFI_TABLE_HEADER
;; ======================================================================== ;; ========================================================================
;; EFI_SYSTEM_TABLE ;; EFI_SYSTEM_TABLE
@ -131,7 +131,7 @@ struc EFI_SYSTEM_TABLE
.NumberOfTableEntries UINTN .NumberOfTableEntries UINTN
.ConfigurationTable UINTPTR .ConfigurationTable UINTPTR
} }
defn EFI_SYSTEM_TABLE DEFN EFI_SYSTEM_TABLE
;; ======================================================================== ;; ========================================================================
;; EFI_BOOT_SERVICES ;; EFI_BOOT_SERVICES
@ -210,7 +210,7 @@ struc EFI_BOOT_SERVICES
.SetMem UINTPTR .SetMem UINTPTR
.CreateEventEx UINTPTR .CreateEventEx UINTPTR
} }
defn EFI_BOOT_SERVICES DEFN EFI_BOOT_SERVICES
;; ======================================================================== ;; ========================================================================
;; EFI_RUNTIMES_SERVICES ;; EFI_RUNTIMES_SERVICES
@ -269,7 +269,7 @@ struc EFI_LOADED_IMAGE_PROTOCOL
.ImageDataType UINT32 .ImageDataType UINT32
.Unload UINTPTR .Unload UINTPTR
} }
defn EFI_LOADED_IMAGE_PROTOCOL DEFN EFI_LOADED_IMAGE_PROTOCOL
;; ======================================================================== ;; ========================================================================
;; EFI_DEVICE_PATH_PROTOCOL ;; EFI_DEVICE_PATH_PROTOCOL
@ -282,7 +282,7 @@ struc EFI_DEVICE_PATH_PROTOCOL
.SubType UINT8 .SubType UINT8
.Length db 2 dup(?) .Length db 2 dup(?)
} }
defn EFI_DEVICE_PATH_PROTOCOL DEFN EFI_DEVICE_PATH_PROTOCOL
;; ======================================================================== ;; ========================================================================
;; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL ;; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
@ -302,7 +302,7 @@ struc EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
.EnableCursor UINTPTR .EnableCursor UINTPTR
.Mode UINTPTR .Mode UINTPTR
} }
defn EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL DEFN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
struc SIMPLE_TEXT_OUTPUT_MODE struc SIMPLE_TEXT_OUTPUT_MODE
{ {
@ -350,7 +350,7 @@ struc EFI_LOAD_FILE_PROTOCOL
{ {
.LoadFile UINTPTR .LoadFile UINTPTR
} }
defn EFI_LOAD_FILE_PROTOCOL DEFN EFI_LOAD_FILE_PROTOCOL
;; ======================================================================== ;; ========================================================================
@ -372,7 +372,7 @@ struc EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
.Revision UINT64 .Revision UINT64
.OpenVolume UINTPTR .OpenVolume UINTPTR
} }
defn EFI_SIMPLE_FILE_SYSTEM_PROTOCOL DEFN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
;; ======================================================================== ;; ========================================================================
;; EFI_FILE_PROTOCOL ;; EFI_FILE_PROTOCOL
@ -400,7 +400,7 @@ struc EFI_FILE_PROTOCOL
.WriteEx UINTPTR .WriteEx UINTPTR
.FlushEx UINTPTR .FlushEx UINTPTR
} }
defn EFI_FILE_PROTOCOL DEFN EFI_FILE_PROTOCOL
; Open Mode ; Open Mode
EFI_FILE_MODE_READ = 0x0000000000000001 EFI_FILE_MODE_READ = 0x0000000000000001

View file

@ -10,7 +10,8 @@ LOADER_SRCS = loader.asm \
memory.inc \ memory.inc \
logger.inc \ logger.inc \
a20.inc \ a20.inc \
multiboot.inc multiboot.inc \
stpdfs.inc
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)

View file

@ -2,6 +2,7 @@
include '../common/fat12.inc' include '../common/fat12.inc'
;; Function: fat_read_bpb
fat_read_bpb: fat_read_bpb:
mov ax, DISK_BUFFER/0x10 mov ax, DISK_BUFFER/0x10
mov es, ax mov es, ax

View file

@ -76,9 +76,23 @@ _start:
cmp dword [DISK_BUFFER], STPDFS_MAGIC cmp dword [DISK_BUFFER], STPDFS_MAGIC
jne .fat_fallback 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 ; fallback to fat12
; for now fat12 is asumed ; for now fat12 is asumed
.fat_fallback: .fat_fallback:
mov si, szMsgFatFallback
call bios_log
; get bpb ; get bpb
call fat_read_bpb call fat_read_bpb
@ -112,6 +126,8 @@ _start:
xor bx, bx xor bx, bx
call fat_load_binary call fat_load_binary
.skip_fat:
; fetch memory map from bios ; fetch memory map from bios
call memory_get_map call memory_get_map
jc .error_memory jc .error_memory
@ -156,6 +172,7 @@ _start:
include 'a20.inc' include 'a20.inc'
include '../common/bios.inc' include '../common/bios.inc'
include 'fat.inc' include 'fat.inc'
include 'stpdfs.inc'
include 'disk.inc' include 'disk.inc'
include 'logger.inc' include 'logger.inc'
include 'memory.inc' include 'memory.inc'
@ -173,6 +190,9 @@ uKernelSize dd 0
szMsgStage2 db "StupidOS Loader", 0 szMsgStage2 db "StupidOS Loader", 0
szKernelFile db "VMSTUPIDSYS", 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 szMsgKernelFound db "Kernel found, size: %x", 0
szMsgErrorA20 db "ERROR: can't enable a20 line", 0 szMsgErrorA20 db "ERROR: can't enable a20 line", 0
szMsgErrorMemory db "ERROR: can't detect available memory", 0 szMsgErrorMemory db "ERROR: can't detect available memory", 0

View file

@ -82,7 +82,7 @@ struc MultibootData
.fb_type db ? .fb_type db ?
.fb_misc dw 3 dup ? .fb_misc dw 3 dup ?
} }
defn MultibootData DEFN MultibootData
MULTIBOOT_DATA_MEM = 0x0001 MULTIBOOT_DATA_MEM = 0x0001
MULTIBOOT_DATA_BOOTDEV = 0x0002 MULTIBOOT_DATA_BOOTDEV = 0x0002
@ -101,7 +101,7 @@ struc MultibootMMap
.length dq ? .length dq ?
.type dd ? .type dd ?
} }
defn MultibootMMap DEFN MultibootMMap
MULTIBOOT_MEMORY_AVAILABLE = 0x1 MULTIBOOT_MEMORY_AVAILABLE = 0x1
MULTIBOOT_MEMORY_RESERVED = 0x2 MULTIBOOT_MEMORY_RESERVED = 0x2
@ -116,4 +116,4 @@ struc MultibootModule
.cmdline dd ? .cmdline dd ?
.pad dd ? .pad dd ?
} }
defn MultibootModule DEFN MultibootModule

55
boot/loader/stpdfs.inc Normal file
View file

@ -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