Skip to content

Commit

Permalink
refactor(boot): defn -> DEFN
Browse files Browse the repository at this point in the history
  • Loading branch information
d0p1s4m4 committed Aug 31, 2024
1 parent c84e5b5 commit 1cd67ee
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 23 deletions.
4 changes: 2 additions & 2 deletions boot/common/fat12.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +33,7 @@ struc fat_entry
.start dw ?
.size dd ?
}
defn fat_entry
DEFN fat_entry

;; Constants: Attributes
;; ATTR_READ_ONLY - Read-only
Expand Down
12 changes: 6 additions & 6 deletions boot/common/macro.inc
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion boot/common/mbr.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ struc Partition
.lba dd ?
.sectors dd ?
}
defn Partition
DEFN Partition


20 changes: 10 additions & 10 deletions boot/efi/uefi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struc EFI_TIME
.Daylight UINT8
.Pad2 UINT8
}
defn EFI_TIME
DEFN EFI_TIME

struc EFI_TABLE_HEADER
{
Expand All @@ -90,7 +90,7 @@ struc EFI_TABLE_HEADER
.CRC32 UINT32
.Reserved UINT32
}
defn EFI_TABLE_HEADER
DEFN EFI_TABLE_HEADER

;; ========================================================================
;; EFI_SYSTEM_TABLE
Expand Down Expand Up @@ -131,7 +131,7 @@ struc EFI_SYSTEM_TABLE
.NumberOfTableEntries UINTN
.ConfigurationTable UINTPTR
}
defn EFI_SYSTEM_TABLE
DEFN EFI_SYSTEM_TABLE

;; ========================================================================
;; EFI_BOOT_SERVICES
Expand Down Expand Up @@ -210,7 +210,7 @@ struc EFI_BOOT_SERVICES
.SetMem UINTPTR
.CreateEventEx UINTPTR
}
defn EFI_BOOT_SERVICES
DEFN EFI_BOOT_SERVICES

;; ========================================================================
;; EFI_RUNTIMES_SERVICES
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -350,7 +350,7 @@ struc EFI_LOAD_FILE_PROTOCOL
{
.LoadFile UINTPTR
}
defn EFI_LOAD_FILE_PROTOCOL
DEFN EFI_LOAD_FILE_PROTOCOL


;; ========================================================================
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion boot/loader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ LOADER_SRCS = loader.asm \
memory.inc \
logger.inc \
a20.inc \
multiboot.inc
multiboot.inc \
stpdfs.inc

.PHONY: all
all: $(TARGET)
Expand Down
1 change: 1 addition & 0 deletions boot/loader/fat.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

include '../common/fat12.inc'

;; Function: fat_read_bpb
fat_read_bpb:
mov ax, DISK_BUFFER/0x10
mov es, ax
Expand Down
20 changes: 20 additions & 0 deletions boot/loader/loader.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions boot/loader/multiboot.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -101,7 +101,7 @@ struc MultibootMMap
.length dq ?
.type dd ?
}
defn MultibootMMap
DEFN MultibootMMap

MULTIBOOT_MEMORY_AVAILABLE = 0x1
MULTIBOOT_MEMORY_RESERVED = 0x2
Expand All @@ -116,4 +116,4 @@ struc MultibootModule
.cmdline dd ?
.pad dd ?
}
defn MultibootModule
DEFN MultibootModule
55 changes: 55 additions & 0 deletions boot/loader/stpdfs.inc
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1cd67ee

Please sign in to comment.