Compare commits

..

No commits in common. "db96f2a59e93110709bae8c61ae8b9b333a30858" and "f84f328828db10df0d8f43aa8b27e63123c57127" have entirely different histories.

10 changed files with 108 additions and 343 deletions

1
.gitignore vendored
View file

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

View file

@ -3,26 +3,21 @@ 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 \
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS)) ../common/const.inc \
../common/fat12.inc
HDD_SRCS = hdd.asm \ HDD_SRCS = hdd.asm \
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS)) ../common/const.inc \
../common/fat12.inc
MBR_SRCS = mbr.asm \ MBR_SRCS = mbr.asm \
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS)) ../common/const.inc \
../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,10 +22,3 @@ 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,25 +1,16 @@
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 \
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS)) ../common/const.inc \
../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

@ -14,25 +14,38 @@
;; Function: efimain ;; Function: efimain
;; ;;
;; In: ;; Parameters:
;; [ESP+4] - handle
;; [ESP+8] - <EFI_SYSTEM_TABLE>
;; ;;
;; Out: ;; [esp+4] - handle
;; EAX - efi status ;; [esp+8] - <EFI_SYSTEM_TABLE>
;;
;; Returns:
;;
;; eax - efi status
;; ;;
efimain: efimain:
push ebp mov eax, [esp+4]
mov ebp, esp mov [hImage], eax
mov eax, [esp+8]
mov [pSystemTable], eax
EFI_INIT [ebp + 8], [ebp + 12] mov ebx, [eax + EFI_SYSTEM_TABLE.RuntimeServices]
mov [pRuntimeServices], ebx
call efi_log_init 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_memory_init
call efi_log_init
LOG szHelloMsg mov esi, szHelloMsg
call efi_log
call efi_fs_init call efi_fs_init
@ -70,3 +83,20 @@ 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,16 +3,21 @@
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], [hEfiImage], aFSProtoGUID, pLoadedImage, [hEfiImage], 0, 2 push 0
push [hImage]
push pLoadedImage
push aFSProtoGUID
push [hImage]
call [fnOpenProtocol]
add esp, 20
or eax, eax or eax, eax
jnz .error jnz .error
ret ret
.error: .error:
mov eax, szErrTmp mov esi, szErrTmp
call efi_log call efi_log
ret ret
@ -22,5 +27,3 @@ 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,120 +1,38 @@
;; 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:
mov eax, [pEfiSystemTable] mov eax, [pSystemTable]
mov eax, [eax + EFI_SYSTEM_TABLE.ConOut] add eax, EFI_SYSTEM_TABLE.ConOut
mov eax, [eax]
mov [pConOut], eax mov [pConOut], eax
mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset] mov ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset]
mov [fnOutputReset], edx mov [fnOutputReset], ecx
mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] mov ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
mov [fnOutputStr], edx mov [fnOutputStr], ecx
mov edx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute] mov eax, [pRuntimeServices]
mov [fnSetAttribute], edx mov ecx, [eax + EFI_RUNTIMES_SERVICES.GetTime]
mov [fnGetTime], ecx
mov eax, [pEfiRuntimeServices] push 1
mov eax, [eax + EFI_RUNTIMES_SERVICES.GetTime] push [pConOut]
mov [fnGetTime], eax call [fnOutputReset]
add esp, 8
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 push 0
push stEfiTime
call [fnGetTime]
add esp, 8
; Hours ; Hours
mov al, [stEfiTime + EFI_TIME.Hour] mov al, [stEfiTime + EFI_TIME.Hour]
@ -161,105 +79,43 @@ efi_log_time:
movzx cx, ah movzx cx, ah
mov [szTime + 16], cx mov [szTime + 16], cx
EFI_CALL [fnOutputStr], [pConOut], szTime push szTime
push [pConOut]
call [fnOutputStr]
add esp, 8
ret ret
;; Function: efi_log ;; Function: efi_log
;; ;;
;; In: ;; In:
;; EAX - string to print ;; ESI - string to print
efi_log: efi_log:
push ebp
mov ebp, esp
push esi
push edi
push ebx
mov esi, eax
mov edi, eax
lea ebx, [ebp + 8]
call efi_log_time call efi_log_time
.loop: push esi
mov dx, [edi] push [pConOut]
or dx, dx call [fnOutputStr]
jz .end add esp, 8
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 push szEndLine
push [pConOut]
call [fnOutputStr]
add esp, 8
pop ebx
pop edi
pop esi
leave
ret ret
section '.data' data readable writable 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, [pEfiBootServices] mov eax, [pBootServices]
mov ecx, [eax + EFI_BOOT_SERVICES.AllocatePool] mov ecx, [eax + EFI_BOOT_SERVICES.AllocatePool]
mov [fnAllocatePool], ecx mov [fnAllocatePool], ecx

View file

@ -1,88 +1,5 @@
;; File: uefi.inc ;; File: uefi.inc
macro EFI_CALL fn, [arg] {
common
_ARGS = 0
reverse
match anything, arg \{
_ARGS = _ARGS + 4
push dword arg
\}
common
call fn
if _ARGS
add esp, _ARGS
end if
}
macro EFI_GET_INTERFACE reg, interface {
if interface in <ConsoleInHandle,ConIn,ConsOutHandle,ConOut,StandardErrorHandle,StdErr>
mov reg, [pEfiSystemTable]
mov reg, [reg + EFI_SYSTEM_TABLE.#interface]
end if
}
macro EFI_INIT handle, table {
local efi_init_bad
local efi_init_end
clc
; image handle
mov eax, handle
or eax, eax
jz efi_init_bad
mov [hEfiImage], eax
mov eax, table
mov [pEfiSystemTable], eax
mov edx, [eax + EFI_SYSTEM_TABLE.BootServices]
mov [pEfiBootServices], edx
mov edx, [eax + EFI_SYSTEM_TABLE.RuntimeServices]
mov [pEfiRuntimeServices], edx
jmp efi_init_end
efi_init_bad:
stc
efi_init_end:
}
EFI_SUCCESS = 0x0
EFI_ERR = 0x80000000
EFI_LOAD_ERROR = (EFI_ERR or 1)
EFI_INVALID_PARAMETER = (EFI_ERR or 2)
EFI_UNSUPPORTED = (EFI_ERR or 3)
EFI_BAD_BUFFER_SIZE = (EFI_ERR or 4)
EFI_BUFFER_TOO_SMALL = (EFI_ERR or 5)
EFI_NOT_READY = (EFI_ERR or 6)
EFI_DEVICE_ERROR = (EFI_ERR or 7)
EFI_WRITE_PROTECTED = (EFI_ERR or 8)
EFI_OUT_OF_RESOURCEs = (EFI_ERR or 9)
EFI_VOLUME_CORRUPTED = (EFI_ERR or 10)
EFI_VOLUME_FULL = (EFI_ERR or 11)
EFI_NO_MEDIA = (EFI_ERR or 12)
EFI_MEDIA_CHANGED = (EFI_ERR or 13)
EFI_NOT_FOUND = (EFI_ERR or 14)
EFI_ACCESS_DEBIED = (EFI_ERR or 15)
EFI_NO_RESPONSE = (EFI_ERR or 16)
EFI_NO_MAPPING = (EFI_ERR or 17)
EFI_TIMEOUT = (EFI_ERR or 18)
EFI_NOT_STARTED = (EFI_ERR or 19)
EFI_ALREADY_STARTED = (EFI_ERR or 20)
EFI_ABORTED = (EFI_ERR or 21)
EFI_ICMP_ERROR = (EFI_ERR or 22)
EFI_TFTP_ERROR = (EFI_ERR or 23)
EFI_PROTOCOL_ERROR = (EFI_ERR or 24)
EFI_INCOMPATIBLE_VERSION = (EFI_ERR or 25)
EFI_SECURITY_VIOLATION = (EFI_ERR or 26)
EFI_CRC_ERROR = (EFI_ERR or 27)
EFI_END_OF_MEDIA = (EFI_ERR or 28)
EFI_END_OF_FILE = (EFI_ERR or 31)
EFI_INVALID_LANGUAGE = (EFI_ERR or 32)
EFI_COMPROMISED_DATA = (EFI_ERR or 33)
EFI_IP_ADDRESS_CONFLICT = (EFI_ERR or 34)
EFI_HTTP_ERROR = (EFI_ERR or 35)
struc BOOLEAN struc BOOLEAN
{ {
. db ? . db ?
@ -141,6 +58,14 @@ struc UINTPTR
. dd ? . dd ?
} }
struc EFI_GUID
{
.Data1 dd ?
.Data2 dw ?
.Data3 dw ?
.Data4 db 8 dup(?)
}
struc EFI_TIME struc EFI_TIME
{ {
.Year UINT16 .Year UINT16
@ -287,17 +212,6 @@ struc EFI_BOOT_SERVICES
} }
DEFN EFI_BOOT_SERVICES DEFN EFI_BOOT_SERVICES
EFI_LOCATE_SEARCH_ALL_HANDLES = 0x0
EFI_LOCATE_SEARCH_BY_REGISTER_NOTIFY = 0x1
EFI_LOCATE_SEARCH_BY_PROTOCOL = 0x2
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL = 0x00000001
EFI_OPEN_PROTOCOL_GET_PROTOCOL = 0x00000002
EFI_OPEN_PROTOCOL_TEST_PROTOCOL = 0x00000004
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER = 0x00000008
EFI_OPEN_PROTOCOL_BY_DRIVER = 0x00000010
EFI_OPEN_PROTOCOL_EXCLUSIVE = 0x00000020
;; ======================================================================== ;; ========================================================================
;; EFI_RUNTIMES_SERVICES ;; EFI_RUNTIMES_SERVICES
;; ======================================================================== ;; ========================================================================
@ -450,7 +364,7 @@ EFI_LOAD_FILE2_PROTOCOL equ EFI_LOAD_FILE_PROTOCOL
;; ======================================================================== ;; ========================================================================
;; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL ;; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
;; ======================================================================== ;; ========================================================================
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID equ 0x22, 0x5b, 0x4e, 0x96, 0x59, 0x64, 0xd2, 0x11, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID equ 0x022, 0x5b, 0x4e, 0x96, 0x59, 0x64, 0xd2, 0x11, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b
;EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID equ 0x0964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ;EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID equ 0x0964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION = 0x00010000 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION = 0x00010000
@ -503,10 +417,3 @@ EFI_FILE_RESERVED = 0x0000000000000008
EFI_FILE_DIRECTORY = 0x0000000000000010 EFI_FILE_DIRECTORY = 0x0000000000000010
EFI_FILE_ARCHIVE = 0x0000000000000020 EFI_FILE_ARCHIVE = 0x0000000000000020
EFI_FILE_VALID_ATTR = 0x0000000000000037 EFI_FILE_VALID_ATTR = 0x0000000000000037
section '.data' data readable writeable
hEfiImage dd 0
pEfiSystemTable dd 0
pEfiBootServices dd 0
pEfiRuntimeServices dd 0

View file

@ -1,17 +1,10 @@
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 \
$(addprefix $(COMMON_DIR)/, $(COMMON_SRCS)) \ ../common/const.inc \
$(addprefix $(SYS_DIR)/, $(SYS_SRCS)) \ ../common/bootinfo.inc \
../../kernel/sys/bootinfo.inc \
../../kernel/sys/register.inc \
fat.inc \ fat.inc \
video.inc \ video.inc \
memory.inc \ memory.inc \
@ -24,8 +17,6 @@ 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 $@