feat: EFI 'hello, world'
Some checks are pending
Build / test (push) Waiting to run
Docs / test (push) Waiting to run

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-03-21 11:42:18 +01:00
parent 03c95cb0a4
commit e9ec779ca0
5 changed files with 230 additions and 32 deletions

2
.gitignore vendored
View file

@ -28,3 +28,5 @@ bochsrc.bxrc
/tmp
*.tar.gz
*.sys
*.obj
*.efi

Binary file not shown.

View file

@ -1,7 +1,7 @@
AS = fasm
RM = rm
TARGET = bootsector.bin stpdboot.sys
TARGET = bootsector.bin stpdboot.sys bootia32.efi
STAGE0_SRCS = boot0.asm \
const.inc \
@ -12,6 +12,9 @@ STAGE1_SRCS = boot1.asm \
a20.inc \
multiboot.inc
BOOTIA32_EFI_SRCS = bootia32.asm \
uefi.inc
.PHONY: all
all: $(TARGET)
@ -21,6 +24,9 @@ bootsector.bin: $(STAGE0_SRCS)
stpdboot.sys: $(STAGE1_SRCS)
$(AS) boot1.asm $@
bootia32.efi: $(BOOTIA32_EFI_SRCS)
$(AS) bootia32.asm $@
.PHONY: clean
clean:
$(RM) $(TARGET)
@ -29,4 +35,5 @@ clean:
install: $(TARGET)
@ mkdir -p $(DESTDIR)
install stpdboot.sys $(DESTDIR)
@ mkdir -p $(DESTDIR)/EFI/BOOT
install bootia32.efi $(DESTDIR)/EFI/BOOT

42
boot/bootia32.asm Normal file
View file

@ -0,0 +1,42 @@
format PE DLL EFI at 10000000h
entry efimain
section '.text' code executable readable
include 'uefi.inc'
; ESP => return address
; ESP + 4 => Handle
; ESP + 8 => SysTable
efimain:
mov eax, [esp+4]
mov [handle], eax
mov eax, [esp+8]
mov [system_table], eax
mov ebx, [eax + EFI_SYSTEM_TABLE.ConOut]
mov eax, 1
push eax
push ebx
call [ebx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset]
add esp, 8
push hello_msg
push ebx
call [ebx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
add esp, 8
jmp $
ret
section '.reloc' fixups data discardable
section '.data' data readable writeable
hello_msg du 'StupidOS EFI Bootloader', 13, 10, 0
handle dd ?
system_table dd ?

147
boot/uefi.inc Normal file
View file

@ -0,0 +1,147 @@
macro defn name
{
virtual at 0
name name
end virtual
}
struc BOOLEAN
{
. db ?
}
struc UINT64
{
align 8
. dq ?
}
struc UINT32
{
align 4
. dd ?
}
struc INT32
{
align 4
. dd ?
}
struc UINTN
{
align 4
. dd ?
}
struc EFI_HANDLE
{
align 4
. dd ?
}
struc UINTPTR
{
align 4
. dd ?
}
struc EFI_TABLE_HEADER
{
.Signature UINT64
.Revision UINT32
.HeaderSize UINT32
.CRC32 UINT32
.Reserved UINT32
}
defn EFI_TABLE_HEADER
;; ========================================================================
;; EFI_SYSTEM_TABLE
;; ========================================================================
EFI_SYSTEM_TABLE_SIGNATURE = 0x5453595320494249
EFI_2_90_SYSTEM_TABLE_REVISION = ((2 shl 16) or (90))
EFI_2_80_SYSTEM_TABLE_REVISION = ((2 shl 16) or (80))
EFI_2_70_SYSTEM_TABLE_REVISION = ((2 shl 16) or (70))
EFI_2_60_SYSTEM_TABLE_REVISION = ((2 shl 16) or (60))
EFI_2_50_SYSTEM_TABLE_REVISION = ((2 shl 16) or (50))
EFI_2_40_SYSTEM_TABLE_REVISION = ((2 shl 16) or (40))
EFI_2_31_SYSTEM_TABLE_REVISION = ((2 shl 16) or (31))
EFI_2_30_SYSTEM_TABLE_REVISION = ((2 shl 16) or (30))
EFI_2_20_SYSTEM_TABLE_REVISION = ((2 shl 16) or (20))
EFI_2_10_SYSTEM_TABLE_REVISION = ((2 shl 16) or (10))
EFI_2_00_SYSTEM_TABLE_REVISION = ((2 shl 16) or (00))
EFI_1_10_SYSTEM_TABLE_REVISION = ((1 shl 16) or (10))
EFI_1_02_SYSTEM_TABLE_REVISION = ((1 shl 16) or (02))
EFI_SYSTEM_TABLE_REVISION = EFI_2_90_SYSTEM_TABLE_REVISION
EFI_SPECIFICATION_VERSION = EFI_SYSTEM_TABLE_REVISION
struc EFI_SYSTEM_TABLE
{
.Hdr EFI_TABLE_HEADER
.FirmwareVendor UINTPTR
.FirmwareRevision UINT32
.ConsoleInHandle EFI_HANDLE
.ConIn UINTPTR
.ConsoleOutHandle EFI_HANDLE
.ConOut UINTPTR
.StandardErrorHandle EFI_HANDLE
.StdErr UINTPTR
.RuntimeServices UINTPTR
.BootServices UINTPTR
.NumberOfTableEntries UINTN
.ConfigurationTable UINTPTR
}
defn EFI_SYSTEM_TABLE
;; ========================================================================
;; EFI_BOOT_SERVICES
;; ========================================================================
EFI_BOOT_SERVICES_SIGNATURE = 0x56524553544f4f42
EFI_BOOT_SERVICES_REVISION = EFI_SPECIFICATION_VERSION
struc EFI_BOOT_SERVICES
{
.Hdr EFI_TABLE_HEADER
}
;; ========================================================================
;; EFI_RUNTIMES_SERVICES
;; ========================================================================
EFI_RUNTIMES_SERVICES_SIGNATURE = 0x56524553544e5552
EFI_RUNTIMES_SERVICES_REVISION = EFI_SPECIFICATION_VERSION
struc EFI_RUNTIMES_SERVICES
{
.Hdr EFI_TABLE_HEADER
}
;; ========================================================================
;; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
;; ========================================================================
struc EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
{
.Reset UINTPTR
.OutputString UINTPTR
.TestString UINTPTR
.QueryMode UINTPTR
.SetMode UINTPTR
.SetAttribute UINTPTR
.ClearScreen UINTPTR
.SetCursorPosition UINTPTR
.EnableCursor UINTPTR
.Mode UINTPTR
}
defn EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
struc SIMPLE_TEXT_OUTPUT_MODE
{
.MaxMode INT32
.Mode INT32
.Attribute INT32
.CursorColumn INT32
.CursorRow INT32
.CursorVisible BOOLEAN
}