From 9f9d0aed3e15aabf8cda73a41e9cb1996a10d042 Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Wed, 3 Nov 2021 14:47:44 +0000 Subject: file rename --- loader/Makefile | 2 +- loader/entry_efi.c | 129 ----------------------------------------------------- loader/main_efi.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 130 deletions(-) delete mode 100644 loader/entry_efi.c create mode 100644 loader/main_efi.c (limited to 'loader') diff --git a/loader/Makefile b/loader/Makefile index 4905554..975c2ce 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -10,7 +10,7 @@ CPPFLAGS += -I../api all: $(BUILD) -OBJS := entry_efi.o loader_efi.o paging_efi.o memory_efi.o image_efi.o \ +OBJS := main_efi.o loader_efi.o paging_efi.o memory_efi.o image_efi.o \ memcmp.o memmove.o DEPS := $(OBJS:.o=.d) diff --git a/loader/entry_efi.c b/loader/entry_efi.c deleted file mode 100644 index 070cc16..0000000 --- a/loader/entry_efi.c +++ /dev/null @@ -1,129 +0,0 @@ -#include "loader_efi.h" - -#include -#include - -EFI_SYSTEM_TABLE *e_st; -EFI_BOOT_SERVICES *e_bs; -EFI_RUNTIME_SERVICES *e_rt; - -EFI_HANDLE e_image_handle; -EFI_LOADED_IMAGE_PROTOCOL *e_loaded_image; -EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *e_system_partition; -EFI_GRAPHICS_OUTPUT_PROTOCOL *e_graphics_output; -EFI_STATUS e_last_error; - -extern int _text; -extern int _data; - -static EFI_LOADED_IMAGE_PROTOCOL *open_loaded_image(void); -static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *open_system_partition(void); -static EFI_GRAPHICS_OUTPUT_PROTOCOL *open_graphics_output(void); - -EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) -{ - e_image_handle = image_handle; - e_st = system_table; - e_bs = e_st->BootServices; - e_rt = e_st->RuntimeServices; - - InitializeLib(e_image_handle, e_st); - Print(L"loader starting\r\n"); - - e_loaded_image = open_loaded_image(); - e_system_partition = open_system_partition(); - e_graphics_output = open_graphics_output(); - - WaitForSingleEvent(e_st->ConIn->WaitForKey, 0); - - loader_main(); - - efi_exit(EFI_ABORTED); -} - -noreturn void efi_exit(EFI_STATUS status) -{ - if (EFI_ERROR(status)) - { - Print(L"loader exited: %r\r\n", status); - } - - e_bs->Exit(e_image_handle, status, 0, NULL); - - while (true); -} - -static EFI_LOADED_IMAGE_PROTOCOL *open_loaded_image(void) -{ - Print(L"opening loaded image\r\n"); - - EFI_STATUS status; - EFI_LOADED_IMAGE_PROTOCOL *image; - - status = e_bs->OpenProtocol(e_image_handle, - &LoadedImageProtocol, - (void **)&image, - e_image_handle, - NULL, - EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); - - if (EFI_ERROR(status)) - { - Print(L"failed opening loaded image\r\n"); - efi_exit(status); - } - - Print(L"image base: 0x%16.0x\r\n", image->ImageBase); - Print(L"image .text segment: 0x%16.0x\r\n", &_text); - Print(L"image .data segment: 0x%16.0x\r\n", &_data); - - return image; -} - -static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *open_system_partition(void) -{ - Print(L"opening system partition\r\n"); - - EFI_STATUS status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *partition; - - status = e_bs->OpenProtocol(e_loaded_image->DeviceHandle, - &FileSystemProtocol, - (void **)&partition, - e_image_handle, - NULL, - EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); - - if (EFI_ERROR(status)) - { - Print(L"failed opening system partition\r\n"); - efi_exit(status); - } - - Print(L"opened system partition\r\n"); - - return partition; -} - -static EFI_GRAPHICS_OUTPUT_PROTOCOL *open_graphics_output(void) -{ - EFI_STATUS status; - EFI_GRAPHICS_OUTPUT_PROTOCOL *graphics; - - Print(L"opening graphics output\r\n"); - - status = e_bs->LocateProtocol(&GraphicsOutputProtocol, - NULL, - (VOID **)&graphics); - - if (EFI_ERROR(status)) - { - Print(L"failed opening graphics output: %r\r\n", status); - return NULL; - } - - Print(L"graphics output opened\r\n"); - - return graphics; -} - diff --git a/loader/main_efi.c b/loader/main_efi.c new file mode 100644 index 0000000..070cc16 --- /dev/null +++ b/loader/main_efi.c @@ -0,0 +1,129 @@ +#include "loader_efi.h" + +#include +#include + +EFI_SYSTEM_TABLE *e_st; +EFI_BOOT_SERVICES *e_bs; +EFI_RUNTIME_SERVICES *e_rt; + +EFI_HANDLE e_image_handle; +EFI_LOADED_IMAGE_PROTOCOL *e_loaded_image; +EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *e_system_partition; +EFI_GRAPHICS_OUTPUT_PROTOCOL *e_graphics_output; +EFI_STATUS e_last_error; + +extern int _text; +extern int _data; + +static EFI_LOADED_IMAGE_PROTOCOL *open_loaded_image(void); +static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *open_system_partition(void); +static EFI_GRAPHICS_OUTPUT_PROTOCOL *open_graphics_output(void); + +EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) +{ + e_image_handle = image_handle; + e_st = system_table; + e_bs = e_st->BootServices; + e_rt = e_st->RuntimeServices; + + InitializeLib(e_image_handle, e_st); + Print(L"loader starting\r\n"); + + e_loaded_image = open_loaded_image(); + e_system_partition = open_system_partition(); + e_graphics_output = open_graphics_output(); + + WaitForSingleEvent(e_st->ConIn->WaitForKey, 0); + + loader_main(); + + efi_exit(EFI_ABORTED); +} + +noreturn void efi_exit(EFI_STATUS status) +{ + if (EFI_ERROR(status)) + { + Print(L"loader exited: %r\r\n", status); + } + + e_bs->Exit(e_image_handle, status, 0, NULL); + + while (true); +} + +static EFI_LOADED_IMAGE_PROTOCOL *open_loaded_image(void) +{ + Print(L"opening loaded image\r\n"); + + EFI_STATUS status; + EFI_LOADED_IMAGE_PROTOCOL *image; + + status = e_bs->OpenProtocol(e_image_handle, + &LoadedImageProtocol, + (void **)&image, + e_image_handle, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); + + if (EFI_ERROR(status)) + { + Print(L"failed opening loaded image\r\n"); + efi_exit(status); + } + + Print(L"image base: 0x%16.0x\r\n", image->ImageBase); + Print(L"image .text segment: 0x%16.0x\r\n", &_text); + Print(L"image .data segment: 0x%16.0x\r\n", &_data); + + return image; +} + +static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *open_system_partition(void) +{ + Print(L"opening system partition\r\n"); + + EFI_STATUS status; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *partition; + + status = e_bs->OpenProtocol(e_loaded_image->DeviceHandle, + &FileSystemProtocol, + (void **)&partition, + e_image_handle, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); + + if (EFI_ERROR(status)) + { + Print(L"failed opening system partition\r\n"); + efi_exit(status); + } + + Print(L"opened system partition\r\n"); + + return partition; +} + +static EFI_GRAPHICS_OUTPUT_PROTOCOL *open_graphics_output(void) +{ + EFI_STATUS status; + EFI_GRAPHICS_OUTPUT_PROTOCOL *graphics; + + Print(L"opening graphics output\r\n"); + + status = e_bs->LocateProtocol(&GraphicsOutputProtocol, + NULL, + (VOID **)&graphics); + + if (EFI_ERROR(status)) + { + Print(L"failed opening graphics output: %r\r\n", status); + return NULL; + } + + Print(L"graphics output opened\r\n"); + + return graphics; +} + -- cgit v1.3.1-1-g115d