Add support for boot protocols
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 30s
Builds / ExectOS (i686) (push) Successful in 28s

This commit is contained in:
2023-12-31 00:21:41 +01:00
parent aa4f917fa7
commit b4ef1932ab
8 changed files with 192 additions and 17 deletions

View File

@@ -9,6 +9,49 @@
#include <xtldr.h>
/**
* Finds a boot protocol for specified system type.
*
* @param SystemType
* Specifies the system type to search for.
*
* @param BootProtocolGuid
* Receives the GUID of the registered boot protocol, that supports specified system.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlFindBootProtocol(IN PWCHAR SystemType,
OUT PEFI_GUID BootProtocolGuid)
{
PXTBL_KNOWN_BOOT_PROTOCOL ProtocolEntry;
PLIST_ENTRY ProtocolListEntry;
ProtocolListEntry = BlpBootProtocols.Flink;
while(ProtocolListEntry != &BlpBootProtocols)
{
/* Get boot protocol entry */
ProtocolEntry = CONTAIN_RECORD(ProtocolListEntry, XTBL_KNOWN_BOOT_PROTOCOL, Flink);
/* Check if this boot protocol supports specified system */
if(RtlCompareWideStringInsensitive(ProtocolEntry->SystemType, SystemType, 0) == 0)
{
/* Boot protocol matched, return success */
BootProtocolGuid = &ProtocolEntry->Guid;
return STATUS_EFI_SUCCESS;
}
/* Move to the next registered boot protocol */
ProtocolListEntry = ProtocolListEntry->Flink;
}
/* Boot protocol not found, return error */
return STATUS_EFI_NOT_FOUND;
}
/**
* Loads a specified XTLDR module from disk.
*
@@ -287,7 +330,7 @@ BlLoadModules(IN PWCHAR ModulesList)
* @param ProtocolGuid
* Supplies a pointer to the unique protocol GUID.
*
* @return This routine returns status code.
* @return This routine returns a status code.
*
* @since XT 1.0
*/
@@ -361,10 +404,66 @@ BlRegisterBootMenu(PVOID BootMenuRoutine)
BlpStatus.BootMenu = BootMenuRoutine;
}
/**
* Registers a known boot protocol for a specified OS.
*
* @param SystemType
* Supplies the type of the OS, such as "LINUX", "XTOS", etc. that is supported by the boot protocol.
*
* @param BootProtocolGuid
* Supplies a pointer to the unique protocol GUID.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlRegisterBootProtocol(IN PWCHAR SystemType,
IN PEFI_GUID BootProtocolGuid)
{
PXTBL_KNOWN_BOOT_PROTOCOL ProtocolEntry;
PLIST_ENTRY ProtocolListEntry;
EFI_STATUS Status;
ProtocolListEntry = BlpBootProtocols.Flink;
while(ProtocolListEntry != &BlpBootProtocols)
{
/* Get boot protocol entry */
ProtocolEntry = CONTAIN_RECORD(ProtocolListEntry, XTBL_KNOWN_BOOT_PROTOCOL, Flink);
/* Check if boot protocol already registered for specified system */
if(RtlCompareWideStringInsensitive(ProtocolEntry->SystemType, SystemType, 0) == 0)
{
/* Boot protocol already registered */
return STATUS_EFI_ABORTED;
}
/* Move to the next registered boot protocol */
ProtocolListEntry = ProtocolListEntry->Flink;
}
/* Create new boot protocol entry */
Status = BlMemoryAllocatePool(sizeof(XTBL_BOOT_PROTOCOL), (PVOID *)&ProtocolEntry);
if(Status != STATUS_EFI_SUCCESS)
{
/* Memory allocation failure */
return STATUS_EFI_OUT_OF_RESOURCES;
}
/* Set protocol properties and add it to the list */
ProtocolEntry->SystemType = SystemType;
ProtocolEntry->Guid = *BootProtocolGuid;
RtlInsertTailList(&BlpBootProtocols, &ProtocolEntry->Flink);
/* Return success */
return STATUS_EFI_SUCCESS;
}
/**
* This routine registers XTLDR protocol for further usage by modules.
*
* @return This routine returns status code.
* @return This routine returns a status code.
*
* @since XT 1.0
*/
@@ -377,6 +476,11 @@ BlpRegisterXtLoaderProtocol()
EFI_HANDLE Handle = NULL;
/* Set all routines available via loader protocol */
LdrProtocol.Boot.FindProtocol = BlFindBootProtocol;
LdrProtocol.Boot.InitializeMenuList = BlInitializeBootMenuList;
LdrProtocol.Boot.InvokeProtocol = BlInvokeBootProtocol;
LdrProtocol.Boot.RegisterMenu = BlRegisterBootMenu;
LdrProtocol.Boot.RegisterProtocol = BlRegisterBootProtocol;
LdrProtocol.Console.ClearLine = BlClearConsoleLine;
LdrProtocol.Console.ClearScreen = BlClearConsoleScreen;
LdrProtocol.Console.DisableCursor = BlDisableConsoleCursor;
@@ -396,9 +500,7 @@ BlpRegisterXtLoaderProtocol()
LdrProtocol.Memory.AllocatePool = BlMemoryAllocatePool;
LdrProtocol.Memory.FreePages = BlMemoryFreePages;
LdrProtocol.Memory.FreePool = BlMemoryFreePool;
LdrProtocol.Protocol.InitializeBootMenuList = BlInitializeBootMenuList;
LdrProtocol.Protocol.OpenProtocol = BlOpenXtProtocol;
LdrProtocol.Protocol.RegisterBootMenu = BlRegisterBootMenu;
LdrProtocol.Protocol.Open = BlOpenXtProtocol;
LdrProtocol.Tui.DisplayErrorDialog = BlDisplayErrorDialog;
LdrProtocol.Tui.DisplayInfoDialog = BlDisplayInfoDialog;
LdrProtocol.Tui.DisplayProgressDialog = BlDisplayProgressDialog;