From 3e6d1f5389cb77055e3860c801dbcc99bb4518ec Mon Sep 17 00:00:00 2001 From: Regia König Date: Tue, 16 Aug 2022 16:54:09 +0200 Subject: Efi file outputs own image base --- GNU_efi_HelloWorld/analyse_hello.sh | 2 +- GNU_efi_HelloWorld/hello.c | 21 +++++++++++++++++++-- GNU_efi_HelloWorld/hello.efi | Bin 45555 -> 46888 bytes GNU_efi_HelloWorld/hello.o | Bin 1664 -> 2112 bytes GNU_efi_HelloWorld/hello.so | Bin 2170968 -> 2171456 bytes documentation/GNU-efi | 4 +++- test_code/OVMF_VARS.fd | Bin 540672 -> 540672 bytes 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/GNU_efi_HelloWorld/analyse_hello.sh b/GNU_efi_HelloWorld/analyse_hello.sh index cfaad73..c8b3103 100755 --- a/GNU_efi_HelloWorld/analyse_hello.sh +++ b/GNU_efi_HelloWorld/analyse_hello.sh @@ -5,4 +5,4 @@ objdump -h hello.efi echo "########################################################################" echo "peinfo hello.efi | grep text -A 5" -peinfo hello.efi | grep text -A 5 +./peinfo hello.efi | grep text -A 5 diff --git a/GNU_efi_HelloWorld/hello.c b/GNU_efi_HelloWorld/hello.c index 817c135..171db1e 100644 --- a/GNU_efi_HelloWorld/hello.c +++ b/GNU_efi_HelloWorld/hello.c @@ -5,11 +5,28 @@ EFI_STATUS EFIAPI efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { + EFI_LOADED_IMAGE *loaded_image = NULL; + EFI_STATUS status; + InitializeLib(ImageHandle, SystemTable); Print(L"Hello, world!\n"); - // TODO: get SystemTable-> ... -> ImageBase - // Print ImageBase + status = uefi_call_wrapper(SystemTable->BootServices->HandleProtocol, + 3, + ImageHandle, + &LoadedImageProtocol, + (void **)&loaded_image); + + if (EFI_ERROR(status)) { + Print(L"handleprotocol: %r\n", status); + } + + Print(L"Image base: 0x%lx\n", loaded_image->ImageBase); + + int wait = 1; + while(wait) { + __asm__ __volatile__("pause"); + } return EFI_SUCCESS; } diff --git a/GNU_efi_HelloWorld/hello.efi b/GNU_efi_HelloWorld/hello.efi index 27145e5..c8399c0 100755 Binary files a/GNU_efi_HelloWorld/hello.efi and b/GNU_efi_HelloWorld/hello.efi differ diff --git a/GNU_efi_HelloWorld/hello.o b/GNU_efi_HelloWorld/hello.o index 22a8362..21583fe 100644 Binary files a/GNU_efi_HelloWorld/hello.o and b/GNU_efi_HelloWorld/hello.o differ diff --git a/GNU_efi_HelloWorld/hello.so b/GNU_efi_HelloWorld/hello.so index bc418e3..b64f729 100755 Binary files a/GNU_efi_HelloWorld/hello.so and b/GNU_efi_HelloWorld/hello.so differ diff --git a/documentation/GNU-efi b/documentation/GNU-efi index 27c77e3..5d75960 100644 --- a/documentation/GNU-efi +++ b/documentation/GNU-efi @@ -186,5 +186,7 @@ make the same call as: ST->ConOut->OutputString(ST->ConOut, buffer); - +################################################################################# +# https://wiki.osdev.org/Debugging_UEFI_applications_with_GDB # +################################################################################# diff --git a/test_code/OVMF_VARS.fd b/test_code/OVMF_VARS.fd index 9883b80..852d584 100644 Binary files a/test_code/OVMF_VARS.fd and b/test_code/OVMF_VARS.fd differ -- cgit v1.2.3-55-g7522