refactor(boot): add macro in efi/logger.inc and rework makefiles

This commit is contained in:
d0p1 🏳️‍⚧️ 2025-01-29 12:46:46 +01:00
parent a9863cbd52
commit db96f2a59e
9 changed files with 217 additions and 65 deletions

1
.gitignore vendored
View file

@ -36,3 +36,4 @@ bochsrc.bxrc
webring.json webring.json
webring.txt webring.txt
kernel/const.inc kernel/const.inc
boot/common/const.inc

View file

@ -3,21 +3,26 @@ TARGET = boot_floppy1440.bin \
boot_mbr.bin \ boot_mbr.bin \
boot_hdd.bin boot_hdd.bin
COMMON_DIR = ../common
COMMON_SRCS = const.inc \
fat12.inc
FLOPPY_SRCS = floppy.asm \ FLOPPY_SRCS = floppy.asm \
../common/const.inc \ $(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
../common/fat12.inc
HDD_SRCS = hdd.asm \ HDD_SRCS = hdd.asm \
../common/const.inc \ $(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
../common/fat12.inc
MBR_SRCS = mbr.asm \ MBR_SRCS = mbr.asm \
../common/const.inc \ $(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
../common/fat12.inc
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)
%.inc: %.inc.in
sh $(TOOLSDIR)/version.sh $< $@
boot_floppy1440.bin: $(FLOPPY_SRCS) boot_floppy1440.bin: $(FLOPPY_SRCS)
$(AS) floppy.asm $@ $(AS) floppy.asm $@

View file

@ -22,3 +22,10 @@ STPDFS_MAGIC = 0x44505453
VIDEO_WIDTH = 1024 VIDEO_WIDTH = 1024
VIDEO_HEIGHT = 768 VIDEO_HEIGHT = 768
VIDEO_DEPTH = 32 VIDEO_DEPTH = 32
; --------- Version -----------
VERSION_MAJOR = @MAJOR@
VERSION_MINOR = @MINOR@
VERSION_COMMIT equ "@COMMIT@"
VERSION_FULL equ "@FULLVERSION@"
BUILD_DATE equ "@DATE@"

View file

@ -1,16 +1,25 @@
TARGET = BOOTIA32.EFI TARGET = BOOTIA32.EFI
COMMON_DIR = ../common
COMMON_SRCS = const.inc \
macro.inc
BOOTIA32_EFI_SRCS = bootia32.asm \ BOOTIA32_EFI_SRCS = bootia32.asm \
uefi.inc \ uefi.inc \
logger.inc \ logger.inc \
memory.inc \ memory.inc \
fs.inc \ fs.inc \
../common/const.inc \ $(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
../common/macro.inc
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)
%.inc: %.inc.in
sh $(TOOLSDIR)/version.sh $< $@
BOOTIA32.EFI: $(BOOTIA32_EFI_SRCS) BOOTIA32.EFI: $(BOOTIA32_EFI_SRCS)
$(AS) bootia32.asm $@ $(AS) bootia32.asm $@

View file

@ -27,28 +27,12 @@ efimain:
EFI_INIT [ebp + 8], [ebp + 12] EFI_INIT [ebp + 8], [ebp + 12]
mov eax, [esp+8]
mov [hImage], eax
mov eax, [esp+12]
mov [pSystemTable], eax
mov ebx, [eax + EFI_SYSTEM_TABLE.RuntimeServices]
mov [pRuntimeServices], ebx
mov ebx, [eax + EFI_SYSTEM_TABLE.BootServices]
mov [pBootServices], ebx
mov ecx, [ebx + EFI_BOOT_SERVICES.OpenProtocol]
mov [fnOpenProtocol], ecx
mov ecx, [ebx + EFI_BOOT_SERVICES.Exit]
mov [fnExit], ecx
call efi_memory_init
call efi_log_init call efi_log_init
mov eax, szHelloMsg call efi_memory_init
call efi_log
LOG szHelloMsg
call efi_fs_init call efi_fs_init
@ -86,20 +70,3 @@ szKernelFile du 'vmstupid.sys', 0
szConfigFile du 'stpdboot.ini', 0 szConfigFile du 'stpdboot.ini', 0
stBootInfo BootInfo stBootInfo BootInfo
hImage dd ?
pSystemTable dd ?
;; Variable: pBootServices
pBootServices dd ?
fnOpenProtocol dd ?
fnCloseProtocol dd ?
fnExit dd ?
;; Variable: pRuntimeServices
pRuntimeServices dd ?
;; Variable: pLoadFileProtocol
;; Pointer to EFI_LOAD_FILE_PROTOCOL
pLoadFileProtocol dd ?
fnLoadFile dd ?

View file

@ -3,9 +3,10 @@
section '.text' code executable readable section '.text' code executable readable
efi_fs_init: efi_fs_init:
mov eax, [pEfiBootServices + EFI_BOOT_SERVICES.OpenProtocol]
; OpenProtocol(EFI_HANDLE Handle, EFI_GUID *proto, VOID **Interface, EFI_HANDLE AgentHandle, UINT32 Attrs) ; OpenProtocol(EFI_HANDLE Handle, EFI_GUID *proto, VOID **Interface, EFI_HANDLE AgentHandle, UINT32 Attrs)
EFI_CALL [fnOpenProtocol], [hImage], aFSProtoGUID, pLoadedImage, [hImage], 0, 2 EFI_CALL [fnOpenProtocol], [hEfiImage], aFSProtoGUID, pLoadedImage, [hEfiImage], 0, 2
or eax, eax or eax, eax
jnz .error jnz .error
@ -21,3 +22,5 @@ efi_fs_init:
szErrTmp du "Can't OpenProtocol(Simple fs)", 0 szErrTmp du "Can't OpenProtocol(Simple fs)", 0
aFSProtoGUID db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID aFSProtoGUID db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
pLoadedImage dd 0 pLoadedImage dd 0
hSimpleFSProtocol dd 0
fnOpenProtocol dd 0

View file

@ -1,30 +1,119 @@
;; File: logger.inc ;; File: logger.inc
macro LOG msg, [arg] {
common
_ARGS = 0
reverse
match anything, arg \{
_ARGS = _ARGS + 4
push dword arg
\}
common
mov eax, msg
call efi_log
if _ARGS
add esp, _ARGS
end if
}
;; XXX: use StdErr instead of ConOut
macro ERROR msg, [arg] {
common
_ARGS = 0
reverse
match anything, arg \{
_ARGS = _ARGS + 4
push dword arg
\}
common
EFI_CALL [fnSetAttribute], [pConOut], EFI_RED
mov eax, msg
call efi_log
if _ARGS
add esp, _ARGS
end if
EFI_CALL [fnSetAttribute], [pConOut], EFI_LIGHTGRAY
}
macro WARN msg, [arg] {
common
_ARGS = 0
reverse
match anything, arg \{
_ARGS = _ARGS + 4
push dword arg
\}
common
EFI_CALL [fnSetAttribute], [pConOut], EFI_YELLOW
mov eax, msg
call efi_log
if _ARGS
add esp, _ARGS
end if
EFI_CALL [fnSetAttribute], [pConOut], EFI_LIGHTGRAY
}
section '.text' code executable readable section '.text' code executable readable
;; Function: efi_log_init ;; Function: efi_log_init
efi_log_init: efi_log_init:
EFI_GET_INTERFACE eax, ConOut mov eax, [pEfiSystemTable]
mov eax, [eax + EFI_SYSTEM_TABLE.ConOut]
mov [pConOut], eax mov [pConOut], eax
mov ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset] mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset]
mov [fnOutputReset], ecx mov [fnOutputReset], edx
mov ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
mov [fnOutputStr], ecx mov [fnOutputStr], edx
mov eax, [pRuntimeServices] mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute]
mov [fnSetAttribute], edx
mov eax, [pEfiRuntimeServices]
mov eax, [eax + EFI_RUNTIMES_SERVICES.GetTime] mov eax, [eax + EFI_RUNTIMES_SERVICES.GetTime]
mov [fnGetTime], eax mov [fnGetTime], eax
EFI_CALL [fnOutputReset], [pConOut], 1 EFI_CALL [fnOutputReset], [pConOut], 1
EFI_CALL [fnSetAttribute], [pConOut], EFI_LIGHTGRAY
EFI_CALL [fnOutputStr], [pConOut], szBanner
ret
efi_log_hex:
push ebp
mov ebp, esp
push edi
mov edi, eax
mov eax, szHexPrefix
EFI_CALL [fnOutputStr], [pConOut], szHexPrefix
xor ecx, ecx
@@:
cmp ecx, 16
je @f
rol edi, 4
mov eax, edi
and eax, 0xF
shl eax, 1
mov ax, [sDigit + eax]
mov [szLogBuffer + ecx], ax
add ecx, 2
jmp @b
@@:
mov [szLogBuffer + ecx], word 0
EFI_CALL [fnOutputStr], [pConOut], szLogBuffer
pop edi
leave
ret ret
;; Function: efi_log_time ;; Function: efi_log_time
efi_log_time: efi_log_time:
; GetTime(EFI_TIME *time, EFI_TIME_CAPS *cap) ; GetTime(EFI_TIME *time, EFI_TIME_CAPS *cap)
EFI_CALL [fnGetTime], stEfiTime, 0 EFI_CALL [fnGetTime], stEfiTime, 0
; Hours ; Hours
@ -85,15 +174,71 @@ efi_log:
mov ebp, esp mov ebp, esp
push esi push esi
push edi
push ebx
mov esi, eax mov esi, eax
mov edi, eax
lea ebx, [ebp + 8]
call efi_log_time call efi_log_time
EFI_CALL [fnOutputStr], [pConOut], esi .loop:
mov dx, [edi]
or dx, dx
jz .end
cmp dx, '%'
jne .next
mov word [edi], 0
EFI_CALL [fnOutputStr], [pConOut], esi
add edi, 2
mov esi, edi
mov dx, [edi]
; check if another '%'
cmp dx, '%'
je .next
; check string format
cmp dx, 's'
jne @f
EFI_CALL [fnOutputStr], [pConOut], [ebx]
add esi, 2
add ebx, 4
jmp .next
; check if hex format
@@:
cmp dx, 'x'
jne @f
mov eax, [ebx]
call efi_log_hex
add esi, 2
add ebx, 4
jmp .next
; unknown format
@@:
mov dx, '?'
mov [edi], dx
.next:
add edi, 2
jmp .loop
.end:
mov dx, [esi]
or dx, dx
jz @f
EFI_CALL [fnOutputStr], [pConOut], esi
@@:
; print CRLF ; print CRLF
EFI_CALL [fnOutputStr], [pConOut], szEndLine EFI_CALL [fnOutputStr], [pConOut], szEndLine
pop ebx
pop edi
pop esi pop esi
leave leave
@ -103,12 +248,18 @@ section '.data' data readable writable
szTime du '[00:00:00] ', 0 szTime du '[00:00:00] ', 0
szEndLine du CR, LF, 0 szEndLine du CR, LF, 0
szBanner du 0x2554, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2557 , CR, LF, \
0x2551, ' ', 'S', 't', 'u', 'p', 'i', 'd', ' ', 'L', 'o', 'a', 'd', 'e', 'r', ' ', 0x2551 , CR, LF, \
0x255a, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x2550, 0x255d , CR, LF, 0
szHexPrefix du '0x', 0
sDigit du '0123456789ABCDEF'
szLogBuffer du '00000000', 0
;; Variable: pConOut ;; Variable: pConOut
;; Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL ;; Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
pConOut dd ? pConOut dd ?
fnOutputReset dd ? fnOutputReset dd ?
fnOutputStr dd ? fnOutputStr dd ?
fnSetAttribute dd ?
stEfiTime EFI_TIME stEfiTime EFI_TIME
fnGetTime dd ? fnGetTime dd ?

View file

@ -3,7 +3,7 @@
section '.text' code executable readable section '.text' code executable readable
efi_memory_init: efi_memory_init:
mov eax, [pBootServices] mov eax, [pEfiBootServices]
mov ecx, [eax + EFI_BOOT_SERVICES.AllocatePool] mov ecx, [eax + EFI_BOOT_SERVICES.AllocatePool]
mov [fnAllocatePool], ecx mov [fnAllocatePool], ecx

View file

@ -1,10 +1,17 @@
TARGET = stpdldr.sys TARGET = stpdldr.sys
COMMON_DIR = ../common
SYS_DIR = ../../kernel/sys
COMMON_SRCS = const.inc \
bootinfo.inc
SYS_SRCS = bootinfo.inc \
register.inc
LOADER_SRCS = loader.asm \ LOADER_SRCS = loader.asm \
../common/const.inc \ $(addprefix $(COMMON_DIR)/, $(COMMON_SRCS)) \
../common/bootinfo.inc \ $(addprefix $(SYS_DIR)/, $(SYS_SRCS)) \
../../kernel/sys/bootinfo.inc \
../../kernel/sys/register.inc \
fat.inc \ fat.inc \
video.inc \ video.inc \
memory.inc \ memory.inc \
@ -17,6 +24,8 @@ LOADER_SRCS = loader.asm \
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)
%.inc: %.inc.in
sh $(TOOLSDIR)/version.sh $< $@
stpdldr.sys: $(LOADER_SRCS) stpdldr.sys: $(LOADER_SRCS)
$(AS) loader.asm $@ $(AS) loader.asm $@