From 02cd8efde9be09117f716b3b5ed9958b694f13c5 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Mon, 4 Dec 2023 18:49:34 +0100 Subject: [PATCH] Add XTLDR protocol support --- sdk/xtdk/bltypes.h | 56 ++++++++++++++++++++++++++++++++++++--- xtldr2/CMakeLists.txt | 1 + xtldr2/efiutils.c | 28 ++++++++++++++++++++ xtldr2/includes/bootman.h | 8 ++++++ 4 files changed, 90 insertions(+), 3 deletions(-) diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index 59ff5ab..e3590e3 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -13,11 +13,27 @@ #include -/* XTLDR Debug port type definitions */ +/* XTLDR Debug Port type definitions */ #define XTBL_DEBUGPORT_SCREEN 1 #define XTBL_DEBUGPORT_SERIAL 2 -/* XTLDR configuration data */ +/* Loader protocol routine pointers */ +typedef EFI_STATUS (*PBL_ALLOCATE_PAGES)(IN UINT64 Size, OUT PEFI_PHYSICAL_ADDRESS Memory); +typedef EFI_STATUS (*PBL_ALLOCATE_POOL)(IN UINT_PTR Size, OUT PVOID *Memory); +typedef VOID (*PBL_CONSOLE_CLEAR_SCREEN)(); +typedef VOID (*PBL_CONSOLE_DISABLE_CURSOR)(); +typedef VOID (*PBL_CONSOLE_ENABLE_CURSOR)(); +typedef VOID (*PBL_CONSOLE_PRINT)(IN PUINT16 Format, IN ...); +typedef VOID (*PBL_DEBUG_PRINT)(IN PUINT16 Format, IN ...); +typedef EFI_STATUS (*PBL_EXIT_BOOT_SERVICES)(IN UINT_PTR MapKey); +typedef EFI_STATUS (*PBL_FREE_PAGES)(IN UINT64 Size, IN EFI_PHYSICAL_ADDRESS Memory); +typedef EFI_STATUS (*PBL_FREE_POOL)(IN PVOID Memory); +typedef EFI_HANDLE (*PBL_GET_EFI_IMAGE_HANDLE)(); +typedef PEFI_SYSTEM_TABLE (*PBL_GET_EFI_SYSTEM_TABLE)(); +typedef EFI_STATUS (*PBL_OPEN_XT_PROTOCOL)(OUT PVOID *ProtocolHandler, IN PEFI_GUID ProtocolGuid); +typedef VOID (*PBL_SLEEP_EXECUTION)(IN ULONG_PTR Milliseconds); + +/* XTLDR Configuration data */ typedef struct _XTBL_CONFIGURATION { PWCHAR Default; @@ -29,7 +45,7 @@ typedef struct _XTBL_CONFIGURATION PWCHAR Tune; } XTBL_CONFIGURATION, *PXTBL_CONFIGURATION; -/* XTLDR status data */ +/* XTLDR Status data */ typedef struct _XTBL_STATUS { BOOLEAN BootServices; @@ -37,4 +53,38 @@ typedef struct _XTBL_STATUS PEFI_SYSTEM_TABLE SystemTable; } XTBL_STATUS, *PXTBL_STATUS; +/* XTLDR Loader protocol */ +typedef struct _XTBL_LOADER_PROTOCOL +{ + struct + { + PBL_CONSOLE_CLEAR_SCREEN ClearScreen; + PBL_CONSOLE_DISABLE_CURSOR DisableCursor; + PBL_CONSOLE_ENABLE_CURSOR EnableCursor; + PBL_CONSOLE_PRINT Print; + } Console; + struct + { + PBL_DEBUG_PRINT Print; + } Debug; + struct + { + PBL_ALLOCATE_PAGES AllocatePages; + PBL_ALLOCATE_POOL AllocatePool; + PBL_FREE_PAGES FreePages; + PBL_FREE_POOL FreePool; + } Memory; + struct + { + PBL_OPEN_XT_PROTOCOL Open; + } Protocol; + struct + { + PBL_EXIT_BOOT_SERVICES ExitBootServices; + PBL_GET_EFI_IMAGE_HANDLE GetImageHandle; + PBL_GET_EFI_SYSTEM_TABLE GetSystemTable; + PBL_SLEEP_EXECUTION SleepExecution; + } Util; +} XTBL_LOADER_PROTOCOL, *PXTBL_LOADER_PROTOCOL; + #endif /* __XTDK_BMTYPES_H */ diff --git a/xtldr2/CMakeLists.txt b/xtldr2/CMakeLists.txt index 465b1c7..2004d41 100644 --- a/xtldr2/CMakeLists.txt +++ b/xtldr2/CMakeLists.txt @@ -15,6 +15,7 @@ list(APPEND XTLDR_SOURCE ${XTLDR_SOURCE_DIR}/globals.c ${XTLDR_SOURCE_DIR}/hardware.c ${XTLDR_SOURCE_DIR}/memory.c + ${XTLDR_SOURCE_DIR}/protocol.c ${XTLDR_SOURCE_DIR}/string.c ${XTLDR_SOURCE_DIR}/xtldr.c) diff --git a/xtldr2/efiutils.c b/xtldr2/efiutils.c index 104db69..5c1f3f0 100644 --- a/xtldr2/efiutils.c +++ b/xtldr2/efiutils.c @@ -44,6 +44,34 @@ BlExitBootServices(IN UINT_PTR MapKey) return Status; } +/** + * Returns the EFI image handle. + * + * @return This routine returns the current EFI image handle. + * + * @since XT 1.0 + */ +XTCDECL +EFI_HANDLE +BlGetEfiImageHandle() +{ + return BlpStatus.ImageHandle; +} + +/** + * Returns the EFI system table. + * + * @return This routine returns the current EFI system table. + * + * @since XT 1.0 + */ +XTCDECL +PEFI_SYSTEM_TABLE +BlGetEfiSystemTable() +{ + return BlpStatus.SystemTable; +} + /** * Puts the system to sleep for the specified number of milliseconds. * diff --git a/xtldr2/includes/bootman.h b/xtldr2/includes/bootman.h index 961718f..dea207d 100644 --- a/xtldr2/includes/bootman.h +++ b/xtldr2/includes/bootman.h @@ -52,6 +52,14 @@ VOID BlDebugPrint(IN PUINT16 Format, IN ...); +XTCDECL +EFI_HANDLE +BlGetEfiImageHandle(); + +XTCDECL +PEFI_SYSTEM_TABLE +BlGetEfiSystemTable(); + XTCDECL EFI_STATUS BlMemoryFreePages(IN UINT64 Pages,