From d1927d8180f869a59cc8e18c2d4d672f80619989 Mon Sep 17 00:00:00 2001 From: d0p1 Date: Sat, 7 Sep 2024 14:40:28 +0200 Subject: [PATCH] feat(boot): simple efi logger --- Makefile | 1 - boot/efi/Makefile | 1 + boot/efi/bootia32.asm | 37 ++++--------- boot/efi/logger.inc | 119 +++++++++++++++++++++++++++++++++++++++++ boot/efi/uefi.inc | 1 + boot/loader/loader.asm | 2 +- 6 files changed, 132 insertions(+), 29 deletions(-) create mode 100644 boot/efi/logger.inc diff --git a/Makefile b/Makefile index 9f61eb8..de222bc 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,6 @@ run-iso: all .PHONY: run-efi run-efi: all OVMF32.fd qemu-system-i386 \ - $(QEMU_COMMON) \ -bios OVMF32.fd \ -drive file=fat:rw:./sysroot,if=none,id=hdd \ -device ide-hd,drive=hdd diff --git a/boot/efi/Makefile b/boot/efi/Makefile index 918ce3e..86ee1ee 100644 --- a/boot/efi/Makefile +++ b/boot/efi/Makefile @@ -2,6 +2,7 @@ TARGET = BOOTIA32.EFI BOOTIA32_EFI_SRCS = bootia32.asm \ uefi.inc \ + logger.inc \ ../common/const.inc \ ../common/macro.inc diff --git a/boot/efi/bootia32.asm b/boot/efi/bootia32.asm index a1300e8..f73ec8c 100644 --- a/boot/efi/bootia32.asm +++ b/boot/efi/bootia32.asm @@ -2,11 +2,13 @@ format PE DLL EFI at 10000000h entry efimain - section '.text' code executable readable - include '../common/const.inc' include '../common/macro.inc' include 'uefi.inc' + include '../../kernel/sys/bootinfo.inc' + include 'logger.inc' + + section '.text' code executable readable ;; Function: efimain ;; @@ -46,24 +48,10 @@ efimain: mov ecx, [ebx + EFI_BOOT_SERVICES.Exit] mov [fnExit], ecx - mov ebx, [eax + EFI_SYSTEM_TABLE.ConOut] - mov [pConOut], ebx + call efi_log_init - mov ecx, [ebx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset] - mov [fnOutputReset], ecx - mov ecx, [ebx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] - mov [fnOutputStr], ecx - - mov eax, 1 - push eax - push [pConOut] - call [fnOutputReset] - add esp, 8 - - push szHelloMsg - push [pConOut] - call [fnOutputStr] - add esp, 8 + mov esi, szHelloMsg + call efi_log ; #=======================# ; search and load kernel @@ -89,7 +77,7 @@ efimain: section '.data' data readable writeable -szHelloMsg du 'StupidOS EFI Bootloader', CR, LF, 0 +szHelloMsg du 'StupidOS EFI Bootloader', 0 ; Search path: / /boot /boot/efi aSearchPaths du '\\', 0, \ @@ -98,6 +86,8 @@ aSearchPaths du '\\', 0, \ szKernelFile du 'vmstupid.sys', 0 szConfigFile du 'stpdboot.ini', 0 +stBootInfo BootInfo + hImage dd ? pSystemTable dd ? @@ -113,13 +103,6 @@ fnExit dd ? ;; Variable: pRuntimeServices pRuntimeServices dd ? - -;; Variable: pConOut -;; Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL -pConOut dd ? -fnOutputReset dd ? -fnOutputStr dd ? - ;; Variable: pLoadFileProtocol ;; Pointer to EFI_LOAD_FILE_PROTOCOL pLoadFileProtocol dd ? diff --git a/boot/efi/logger.inc b/boot/efi/logger.inc new file mode 100644 index 0000000..f973735 --- /dev/null +++ b/boot/efi/logger.inc @@ -0,0 +1,119 @@ + section '.text' code executable readable + + ;; Function: efi_log_init +efi_log_init: + mov eax, [pSystemTable] + add eax, EFI_SYSTEM_TABLE.ConOut + mov eax, [eax] + mov [pConOut], eax + + mov ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset] + mov [fnOutputReset], ecx + + mov ecx, [eax + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] + mov [fnOutputStr], ecx + + mov eax, [pRuntimeServices] + mov ecx, [eax + EFI_RUNTIMES_SERVICES.GetTime] + mov [fnGetTime], ecx + + push 1 + push [pConOut] + call [fnOutputReset] + add esp, 8 + + ret + + ;; Function: efi_log_time +efi_log_time: + ; GetTime(EFI_TIME *time, EFI_TIME_CAPS *cap) + push 0 + push stEfiTime + call [fnGetTime] + add esp, 8 + + ; Hours + mov al, [stEfiTime + EFI_TIME.Hour] + xor ah, ah + mov cl, 10 + div cl + + add ah, 0x30 + add al, 0x30 + + movzx cx, al + mov [szTime + 2], cx + + movzx cx, ah + mov [szTime + 4], cx + + ; Minutes + mov al, [stEfiTime + EFI_TIME.Minute] + xor ah, ah + mov cl, 10 + div cl + + add ah, 0x30 + add al, 0x30 + + movzx cx, al + mov [szTime + 8], cx + + movzx cx, ah + mov [szTime + 10], cx + + ; Secondes + mov al, [stEfiTime + EFI_TIME.Second] + xor ah, ah + mov cl, 10 + div cl + + add ah, 0x30 + add al, 0x30 + + movzx cx, al + mov [szTime + 14], cx + + movzx cx, ah + mov [szTime + 16], cx + + push szTime + push [pConOut] + call [fnOutputStr] + add esp, 8 + + ret + + ;; Function: efi_log + ;; + ;; In: + ;; ESI - string to print +efi_log: + call efi_log_time + + push esi + push [pConOut] + call [fnOutputStr] + add esp, 8 + + ; print CRLF + push szEndLine + push [pConOut] + call [fnOutputStr] + add esp, 8 + + ret + +section '.data' data readable writable + +szTime du '[00:00:00] ', 0 +szEndLine du CR, LF, 0 + +;; Variable: pConOut +;; Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL +pConOut dd ? +fnOutputReset dd ? +fnOutputStr dd ? + +stEfiTime EFI_TIME +fnGetTime dd ? diff --git a/boot/efi/uefi.inc b/boot/efi/uefi.inc index 78cf2bc..490f679 100644 --- a/boot/efi/uefi.inc +++ b/boot/efi/uefi.inc @@ -242,6 +242,7 @@ struc EFI_RUNTIMES_SERVICES } +DEFN EFI_RUNTIMES_SERVICES ;; ======================================================================== ;; EFI_LOADED_IMAGE_PROTOCOL diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 363f31c..ead28b6 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -247,7 +247,7 @@ common32: cmp ecx, 1024 jb @b - mov dword [boot_page_directory], boot_0_page_table + (PDE_P or PDE_W) ; preset and writable + mov dword [boot_page_directory], boot_0_page_table + (PDE_P or PDE_W) ; present and writable mov dword [boot_page_directory + (768 * 4)], boot_0_page_table + (PDE_P or PDE_W)