refactor(boot): add macro in efi/logger.inc and rework makefiles
This commit is contained in:
parent
a9863cbd52
commit
db96f2a59e
9 changed files with 217 additions and 65 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -36,3 +36,4 @@ bochsrc.bxrc
|
|||
webring.json
|
||||
webring.txt
|
||||
kernel/const.inc
|
||||
boot/common/const.inc
|
||||
|
|
|
@ -3,21 +3,26 @@ TARGET = boot_floppy1440.bin \
|
|||
boot_mbr.bin \
|
||||
boot_hdd.bin
|
||||
|
||||
COMMON_DIR = ../common
|
||||
|
||||
COMMON_SRCS = const.inc \
|
||||
fat12.inc
|
||||
|
||||
FLOPPY_SRCS = floppy.asm \
|
||||
../common/const.inc \
|
||||
../common/fat12.inc
|
||||
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
|
||||
|
||||
HDD_SRCS = hdd.asm \
|
||||
../common/const.inc \
|
||||
../common/fat12.inc
|
||||
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
|
||||
|
||||
MBR_SRCS = mbr.asm \
|
||||
../common/const.inc \
|
||||
../common/fat12.inc
|
||||
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
|
||||
|
||||
.PHONY: all
|
||||
all: $(TARGET)
|
||||
|
||||
%.inc: %.inc.in
|
||||
sh $(TOOLSDIR)/version.sh $< $@
|
||||
|
||||
boot_floppy1440.bin: $(FLOPPY_SRCS)
|
||||
$(AS) floppy.asm $@
|
||||
|
||||
|
|
|
@ -22,3 +22,10 @@ STPDFS_MAGIC = 0x44505453
|
|||
VIDEO_WIDTH = 1024
|
||||
VIDEO_HEIGHT = 768
|
||||
VIDEO_DEPTH = 32
|
||||
|
||||
; --------- Version -----------
|
||||
VERSION_MAJOR = @MAJOR@
|
||||
VERSION_MINOR = @MINOR@
|
||||
VERSION_COMMIT equ "@COMMIT@"
|
||||
VERSION_FULL equ "@FULLVERSION@"
|
||||
BUILD_DATE equ "@DATE@"
|
|
@ -1,16 +1,25 @@
|
|||
TARGET = BOOTIA32.EFI
|
||||
|
||||
|
||||
COMMON_DIR = ../common
|
||||
|
||||
COMMON_SRCS = const.inc \
|
||||
macro.inc
|
||||
|
||||
|
||||
BOOTIA32_EFI_SRCS = bootia32.asm \
|
||||
uefi.inc \
|
||||
logger.inc \
|
||||
memory.inc \
|
||||
fs.inc \
|
||||
../common/const.inc \
|
||||
../common/macro.inc
|
||||
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS))
|
||||
|
||||
.PHONY: all
|
||||
all: $(TARGET)
|
||||
|
||||
%.inc: %.inc.in
|
||||
sh $(TOOLSDIR)/version.sh $< $@
|
||||
|
||||
BOOTIA32.EFI: $(BOOTIA32_EFI_SRCS)
|
||||
$(AS) bootia32.asm $@
|
||||
|
||||
|
|
|
@ -26,29 +26,13 @@ efimain:
|
|||
mov ebp, esp
|
||||
|
||||
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
|
||||
|
||||
mov eax, szHelloMsg
|
||||
call efi_log
|
||||
call efi_memory_init
|
||||
|
||||
LOG szHelloMsg
|
||||
|
||||
|
||||
call efi_fs_init
|
||||
|
||||
|
@ -86,20 +70,3 @@ szKernelFile du 'vmstupid.sys', 0
|
|||
szConfigFile du 'stpdboot.ini', 0
|
||||
|
||||
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 ?
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
section '.text' code executable readable
|
||||
|
||||
efi_fs_init:
|
||||
mov eax, [pEfiBootServices + EFI_BOOT_SERVICES.OpenProtocol]
|
||||
|
||||
; 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
|
||||
jnz .error
|
||||
|
@ -21,3 +22,5 @@ efi_fs_init:
|
|||
szErrTmp du "Can't OpenProtocol(Simple fs)", 0
|
||||
aFSProtoGUID db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
||||
pLoadedImage dd 0
|
||||
hSimpleFSProtocol dd 0
|
||||
fnOpenProtocol dd 0
|
||||
|
|
|
@ -1,30 +1,119 @@
|
|||
;; File: logger.inc
|
||||
|
||||
section '.text' code executable readable
|
||||
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
|
||||
|
||||
;; Function: 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 ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset]
|
||||
mov [fnOutputReset], ecx
|
||||
mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset]
|
||||
mov [fnOutputReset], edx
|
||||
|
||||
mov ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
|
||||
mov [fnOutputStr], ecx
|
||||
mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
|
||||
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 [fnGetTime], eax
|
||||
|
||||
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
|
||||
|
||||
;; Function: efi_log_time
|
||||
efi_log_time:
|
||||
; GetTime(EFI_TIME *time, EFI_TIME_CAPS *cap)
|
||||
|
||||
EFI_CALL [fnGetTime], stEfiTime, 0
|
||||
|
||||
; Hours
|
||||
|
@ -85,15 +174,71 @@ efi_log:
|
|||
mov ebp, esp
|
||||
|
||||
push esi
|
||||
push edi
|
||||
push ebx
|
||||
|
||||
mov esi, eax
|
||||
mov edi, eax
|
||||
lea ebx, [ebp + 8]
|
||||
|
||||
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
|
||||
EFI_CALL [fnOutputStr], [pConOut], szEndLine
|
||||
|
||||
pop ebx
|
||||
pop edi
|
||||
pop esi
|
||||
|
||||
leave
|
||||
|
@ -103,12 +248,18 @@ section '.data' data readable writable
|
|||
|
||||
szTime du '[00:00:00] ', 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
|
||||
;; Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
|
||||
pConOut dd ?
|
||||
fnOutputReset dd ?
|
||||
fnOutputStr dd ?
|
||||
pConOut dd ?
|
||||
fnOutputReset dd ?
|
||||
fnOutputStr dd ?
|
||||
fnSetAttribute dd ?
|
||||
|
||||
stEfiTime EFI_TIME
|
||||
fnGetTime dd ?
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
section '.text' code executable readable
|
||||
|
||||
efi_memory_init:
|
||||
mov eax, [pBootServices]
|
||||
mov eax, [pEfiBootServices]
|
||||
mov ecx, [eax + EFI_BOOT_SERVICES.AllocatePool]
|
||||
mov [fnAllocatePool], ecx
|
||||
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
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 \
|
||||
../common/const.inc \
|
||||
../common/bootinfo.inc \
|
||||
../../kernel/sys/bootinfo.inc \
|
||||
../../kernel/sys/register.inc \
|
||||
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS)) \
|
||||
$(addprefix $(SYS_DIR)/, $(SYS_SRCS)) \
|
||||
fat.inc \
|
||||
video.inc \
|
||||
memory.inc \
|
||||
|
@ -17,6 +24,8 @@ LOADER_SRCS = loader.asm \
|
|||
.PHONY: all
|
||||
all: $(TARGET)
|
||||
|
||||
%.inc: %.inc.in
|
||||
sh $(TOOLSDIR)/version.sh $< $@
|
||||
|
||||
stpdldr.sys: $(LOADER_SRCS)
|
||||
$(AS) loader.asm $@
|
||||
|
|
Loading…
Reference in a new issue