From 17049d7e829f562fbc9f5c1d1015201585754d1f Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Wed, 3 Jan 2024 23:15:37 +0100 Subject: [PATCH] Move BlGetXtLdrProtocol() routine into separate file to avoid linking modules with whole libxtldr.lib statically --- xtldr2/CMakeLists.txt | 1 + xtldr2/modproto.c | 80 +++++++++++++++++++++++++++++++++++++++++++ xtldr2/protocol.c | 70 ------------------------------------- 3 files changed, 81 insertions(+), 70 deletions(-) create mode 100644 xtldr2/modproto.c diff --git a/xtldr2/CMakeLists.txt b/xtldr2/CMakeLists.txt index d9f2946..61ab57e 100644 --- a/xtldr2/CMakeLists.txt +++ b/xtldr2/CMakeLists.txt @@ -18,6 +18,7 @@ list(APPEND XTLDR_SOURCE ${XTLDR_SOURCE_DIR}/globals.c ${XTLDR_SOURCE_DIR}/hardware.c ${XTLDR_SOURCE_DIR}/memory.c + ${XTLDR_SOURCE_DIR}/modproto.c ${XTLDR_SOURCE_DIR}/protocol.c ${XTLDR_SOURCE_DIR}/shell.c ${XTLDR_SOURCE_DIR}/string.c diff --git a/xtldr2/modproto.c b/xtldr2/modproto.c new file mode 100644 index 0000000..a5b8a97 --- /dev/null +++ b/xtldr2/modproto.c @@ -0,0 +1,80 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/modproto.c + * DESCRIPTION: XT Boot Loader protocol support for XTLDR modules + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/** + * Finds and opens the XT Boot Loader protocol. This routine should be called by module to access XTLDR protocol. + * + * @param SystemTable + * Provides the EFI system table. + * + * @param ImageHandle + * Firmware-allocated handle that identifies the image. + * + * @param ProtocolHandler + * Receives the pointer to the XT Boot Loader protocol. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlGetXtLdrProtocol(IN PEFI_SYSTEM_TABLE SystemTable, + IN EFI_HANDLE ImageHandle, + OUT PXTBL_LOADER_PROTOCOL *ProtocolHandler) +{ + EFI_GUID ProtocolGuid = XT_BOOT_LOADER_PROTOCOL_GUID; + PEFI_HANDLE Handles = NULL; + EFI_STATUS Status; + UINT_PTR Count; + UINT Index; + + /* Try to locate the handles */ + Status = SystemTable->BootServices->LocateHandleBuffer(ByProtocol, &ProtocolGuid, NULL, &Count, &Handles); + if(Status != STATUS_EFI_SUCCESS) + { + /* Unable to get handles */ + return Status; + } + + /* Check if any handles returned */ + if(Count > 0) + { + /* Iterate through all given handles */ + for(Index = 0; Index < Count; Index++) + { + /* Try to open protocol */ + Status = SystemTable->BootServices->OpenProtocol(Handles[Index], &ProtocolGuid, + (PVOID*)ProtocolHandler, ImageHandle, NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); + + /* Check if successfully opened the loader protocol */ + if(Status == STATUS_EFI_SUCCESS) + { + /* Protocol found and successfully opened */ + break; + } + } + } + + /* Free handles */ + SystemTable->BootServices->FreePool(Handles); + + /* Make sure the loaded protocol has been found */ + if(*ProtocolHandler == NULL) + { + /* Protocol not found */ + return STATUS_EFI_NOT_FOUND; + } + + /* Return success */ + return STATUS_EFI_SUCCESS; +} diff --git a/xtldr2/protocol.c b/xtldr2/protocol.c index 25e56e8..6f74c76 100644 --- a/xtldr2/protocol.c +++ b/xtldr2/protocol.c @@ -52,76 +52,6 @@ BlFindBootProtocol(IN PWCHAR SystemType, return STATUS_EFI_NOT_FOUND; } -/** - * Finds and opens the XT Boot Loader protocol. This routine should be called by module to access XTLDR protocol. - * - * @param SystemTable - * Provides the EFI system table. - * - * @param ImageHandle - * Firmware-allocated handle that identifies the image. - * - * @param ProtocolHandler - * Receives the pointer to the XT Boot Loader protocol. - * - * @return This routine returns a status code. - * - * @since XT 1.0 - */ -XTCDECL -EFI_STATUS -BlGetXtLdrProtocol(IN PEFI_SYSTEM_TABLE SystemTable, - IN EFI_HANDLE ImageHandle, - OUT PXTBL_LOADER_PROTOCOL *ProtocolHandler) -{ - EFI_GUID ProtocolGuid = XT_BOOT_LOADER_PROTOCOL_GUID; - PEFI_HANDLE Handles = NULL; - EFI_STATUS Status; - UINT_PTR Count; - UINT Index; - - /* Try to locate the handles */ - Status = SystemTable->BootServices->LocateHandleBuffer(ByProtocol, &ProtocolGuid, NULL, &Count, &Handles); - if(Status != STATUS_EFI_SUCCESS) - { - /* Unable to get handles */ - return Status; - } - - /* Check if any handles returned */ - if(Count > 0) - { - /* Iterate through all given handles */ - for(Index = 0; Index < Count; Index++) - { - /* Try to open protocol */ - Status = SystemTable->BootServices->OpenProtocol(Handles[Index], &ProtocolGuid, - (PVOID*)ProtocolHandler, ImageHandle, NULL, - EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); - - /* Check if successfully opened the loader protocol */ - if(Status == STATUS_EFI_SUCCESS) - { - /* Protocol found and successfully opened */ - break; - } - } - } - - /* Free handles */ - SystemTable->BootServices->FreePool(Handles); - - /* Make sure the loaded protocol has been found */ - if(*ProtocolHandler == NULL) - { - /* Protocol not found */ - return STATUS_EFI_NOT_FOUND; - } - - /* Return success */ - return STATUS_EFI_SUCCESS; -} - /** * Loads a specified XTLDR module from disk. *