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 ?
.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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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