From a7781c4b0bc7d05c6e41618db2245dd08c2bcd4d Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Mon, 18 Dec 2023 23:27:49 +0100 Subject: [PATCH] Implement BlInitializeBootMenuList() --- sdk/xtdk/bltypes.h | 25 +++++++---- sdk/xtdk/xtstruct.h | 1 + xtldr2/includes/bootman.h | 6 +++ xtldr2/protocol.c | 1 + xtldr2/xtldr.c | 87 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 8 deletions(-) diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index 5574831..f28f763 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -45,6 +45,7 @@ /* Boot 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_BOOTMENU_INITIALIZE_OS_LIST)(OUT PXTBL_BOOTMENU_ITEM MenuEntries, OUT PULONG EntriesCount, OUT PULONG DefaultId); typedef EFI_STATUS (*PBL_CLOSE_VOLUME)(IN PEFI_HANDLE VolumeHandle); typedef VOID (*PBL_CONSOLE_CLEAR_SCREEN)(); typedef VOID (*PBL_CONSOLE_DISABLE_CURSOR)(); @@ -71,6 +72,13 @@ typedef XTBL_DIALOG_HANDLE (*PBL_TUI_DISPLAY_PROGRESS_DIALOG)(IN PWCHAR Caption, typedef VOID (*PBL_TUI_UPDATE_PROGRESS_BAR)(IN PXTBL_DIALOG_HANDLE Handle, IN PWCHAR Message, IN UCHAR Percentage); typedef EFI_STATUS (*PBL_WAIT_FOR_EFI_EVENT)(IN UINT_PTR NumberOfEvents, IN PEFI_EVENT Event, OUT PUINT_PTR Index); +/* Boot menu list structure */ +typedef struct _XTBL_BOOTMENU_ITEM +{ + PWCHAR EntryName; + PLIST_ENTRY Options; +} XTBL_BOOTMENU_ITEM, *PXTBL_BOOTMENU_ITEM; + /* XTLDR Configuration data */ typedef struct _XTBL_CONFIG_ENTRY { @@ -101,14 +109,6 @@ typedef struct _XTBL_DIALOG_HANDLE UINT_PTR Height; } XTBL_DIALOG_HANDLE, *PXTBL_DIALOG_HANDLE; -/* XTLDR Status data */ -typedef struct _XTBL_STATUS -{ - BOOLEAN BootServices; - ULONG DebugPort; - CPPORT SerialPort; -} XTBL_STATUS, *PXTBL_STATUS; - /* XTLDR Loader protocol */ typedef struct _XTBL_LOADER_PROTOCOL { @@ -144,6 +144,7 @@ typedef struct _XTBL_LOADER_PROTOCOL } Memory; struct { + PBL_BOOTMENU_INITIALIZE_OS_LIST InitializeBootMenuList; PBL_OPEN_XT_PROTOCOL OpenProtocol; } Protocol; struct @@ -162,4 +163,12 @@ typedef struct _XTBL_LOADER_PROTOCOL } Util; } XTBL_LOADER_PROTOCOL, *PXTBL_LOADER_PROTOCOL; +/* XTLDR Status data */ +typedef struct _XTBL_STATUS +{ + BOOLEAN BootServices; + ULONG DebugPort; + CPPORT SerialPort; +} XTBL_STATUS, *PXTBL_STATUS; + #endif /* __XTDK_BLTYPES_H */ diff --git a/sdk/xtdk/xtstruct.h b/sdk/xtdk/xtstruct.h index 30f30dc..b005bfd 100644 --- a/sdk/xtdk/xtstruct.h +++ b/sdk/xtdk/xtstruct.h @@ -264,6 +264,7 @@ typedef struct _UEFI_FIRMWARE_INFORMATION UEFI_FIRMWARE_INFORMATION, *PUEFI_FIRM typedef struct _UNICODE_STRING UNICODE_STRING, *PUNICODE_STRING; typedef struct _UNICODE_STRING32 UNICODE_STRING32, *PUNICODE_STRING32; typedef struct _UNICODE_STRING64 UNICODE_STRING64, *PUNICODE_STRING64; +typedef struct _XTBL_BOOTMENU_ITEM XTBL_BOOTMENU_ITEM, *PXTBL_BOOTMENU_ITEM; typedef struct _XTBL_CONFIG_ENTRY XTBL_CONFIG_ENTRY, *PXTBL_CONFIG_ENTRY; typedef struct _XTBL_CONFIG_SECTION XTBL_CONFIG_SECTION, *PXTBL_CONFIG_SECTION; typedef struct _XTBL_DIALOG_HANDLE XTBL_DIALOG_HANDLE, *PXTBL_DIALOG_HANDLE; diff --git a/xtldr2/includes/bootman.h b/xtldr2/includes/bootman.h index 6e727bc..b1173d8 100644 --- a/xtldr2/includes/bootman.h +++ b/xtldr2/includes/bootman.h @@ -91,6 +91,12 @@ BlGetVolumeDevicePath(IN PCHAR SystemPath, OUT PCHAR *ArcName, OUT PCHAR *Path); +XTCDECL +VOID +BlInitializeBootMenuList(OUT PXTBL_BOOTMENU_ITEM MenuEntries, + OUT PULONG EntriesCount, + OUT PULONG DefaultId); + XTCDECL EFI_STATUS BlMemoryAllocatePages(IN UINT64 Pages, diff --git a/xtldr2/protocol.c b/xtldr2/protocol.c index f17349d..e7f133e 100644 --- a/xtldr2/protocol.c +++ b/xtldr2/protocol.c @@ -109,6 +109,7 @@ BlpRegisterXtLoaderProtocol() LdrProtocol.Memory.FreePages = BlMemoryFreePages; LdrProtocol.Memory.FreePool = BlMemoryFreePool; LdrProtocol.Protocol.OpenProtocol = BlOpenXtProtocol; + LdrProtocol.Protocol.InitializeBootMenuList = BlInitializeBootMenuList; LdrProtocol.Tui.DisplayErrorDialog = BlDisplayErrorDialog; LdrProtocol.Tui.DisplayInfoDialog = BlDisplayInfoDialog; LdrProtocol.Tui.DisplayProgressDialog = BlDisplayProgressDialog; diff --git a/xtldr2/xtldr.c b/xtldr2/xtldr.c index 1ea99b4..3bb9bf6 100644 --- a/xtldr2/xtldr.c +++ b/xtldr2/xtldr.c @@ -9,6 +9,93 @@ #include +/** + * Initializes a list of operating systems for XTLDR boot menu. + * + * @param MenuEntries + * Supplies a pointer to memory area where operating systems list will be stored. + * + * @param EntriesCount + * Supplies a pointer to memory area where number of menu entries will be stored. + * + * @param DefaultId + * Supplies a pointer to memory area where ID of default menu entry will be stored. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCDECL +VOID +BlInitializeBootMenuList(OUT PXTBL_BOOTMENU_ITEM MenuEntries, + OUT PULONG EntriesCount, + OUT PULONG DefaultId) +{ + PWCHAR DefaultMenuEntry, MenuEntryName; + PLIST_ENTRY MenuEntrySectionList, MenuEntryList; + PXTBL_CONFIG_SECTION MenuEntrySection; + PXTBL_CONFIG_ENTRY MenuEntryOption; + PXTBL_BOOTMENU_ITEM OsList; + ULONG DefaultOS, NumberOfEntries; + + /* Set default values */ + DefaultOS = 0; + NumberOfEntries = 0; + OsList = NULL; + + /* Get default menu entry from configuration */ + DefaultMenuEntry = BlGetConfigValue(L"DEFAULT"); + + /* Iterate through all menu sections */ + MenuEntrySectionList = BlpMenuList->Flink; + while(MenuEntrySectionList != BlpMenuList) + { + /* NULLify menu entry name */ + MenuEntryName = NULL; + + /* Get menu section */ + MenuEntrySection = CONTAIN_RECORD(MenuEntrySectionList, XTBL_CONFIG_SECTION, Flink); + + /* Check if this is the default menu entry */ + if(RtlCompareWideStringInsensitive(MenuEntrySection->SectionName, DefaultMenuEntry, 0) == 0) + { + /* Set default OS ID */ + DefaultOS = NumberOfEntries; + } + + /* Iterate through all entry parameters */ + MenuEntryList = MenuEntrySection->Options.Flink; + while(MenuEntryList != &MenuEntrySection->Options) + { + /* Get menu entry parameter */ + MenuEntryOption = CONTAIN_RECORD(MenuEntryList, XTBL_CONFIG_ENTRY, Flink); + + /* Check if this is the menu entry display name */ + if(RtlCompareWideStringInsensitive(MenuEntryOption->Name, L"SYSTEMNAME", 0) == 0) + { + /* Set menu entry display name */ + MenuEntryName = MenuEntryOption->Value; + } + + /* Get next parameter for this menu entry */ + MenuEntryList = MenuEntryList->Flink; + } + + /* Add OS to the boot menu list */ + OsList[NumberOfEntries].EntryName = MenuEntryName; + OsList[NumberOfEntries].Options = &MenuEntrySection->Options; + + /* Get next menu entry */ + MenuEntrySectionList = MenuEntrySectionList->Flink; + NumberOfEntries++; + } + + /* Set return values */ + *DefaultId = DefaultOS; + *EntriesCount = NumberOfEntries; + MenuEntries = OsList; +} + /** * This routine is the entry point of the XT EFI boot loader. *