exectos/xtldr2/protocol.c
Rafal Kupiec c4f1429a3b
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 28s
Builds / ExectOS (i686) (push) Successful in 28s
Not really needed as each module will get both ImageHandle and SystemTable
2023-12-04 18:58:00 +01:00

110 lines
3.3 KiB
C

/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/protocol.c
* DESCRIPTION: XT Boot Loader protocol support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtldr.h>
/**
* This routine locates and opens the requested XT boot loader protocol.
*
* @param ProtocolHandler
* Supplies the address where a pointer to the opened protocol is returned.
*
* @param ProtocolGuid
* Supplies a pointer to the unique protocol GUID.
*
* @return This routine returns status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlOpenXtProtocol(OUT PVOID *ProtocolHandler,
IN PEFI_GUID ProtocolGuid)
{
PEFI_HANDLE Handles = NULL;
EFI_STATUS Status;
UINT_PTR Count;
UINT Index;
/* Try to locate the handles */
Status = EfiSystemTable->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 = EfiSystemTable->BootServices->OpenProtocol(Handles[Index], ProtocolGuid,
ProtocolHandler, EfiImageHandle, 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 */
EfiSystemTable->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;
}
/**
* This routine registers XTLDR protocol for further usage by modules.
*
* @return This routine returns status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlpRegisterXtLoaderProtocol()
{
EFI_GUID Guid = XT_BOOT_LOADER_PROTOCOL_GUID;
XTBL_LOADER_PROTOCOL LdrProtocol;
EFI_HANDLE Handle = NULL;
/* Set all routines available via loader protocol */
LdrProtocol.Console.ClearScreen = BlConsoleClearScreen;
LdrProtocol.Console.DisableCursor = BlConsoleDisableCursor;
LdrProtocol.Console.EnableCursor = BlConsoleEnableCursor;
LdrProtocol.Console.Print = BlConsolePrint;
LdrProtocol.Debug.Print = BlDebugPrint;
LdrProtocol.Memory.AllocatePages = BlMemoryAllocatePages;
LdrProtocol.Memory.AllocatePool = BlMemoryAllocatePool;
LdrProtocol.Memory.FreePages = BlMemoryFreePages;
LdrProtocol.Memory.FreePool = BlMemoryFreePool;
LdrProtocol.Protocol.Open = BlOpenXtProtocol;
LdrProtocol.Util.ExitBootServices = BlExitBootServices;
LdrProtocol.Util.SleepExecution = BlSleepExecution;
/* Register XTLDR loader protocol */
BlDebugPrint(L"Registering XT loader protocol\n");
return EfiSystemTable->BootServices->InstallProtocolInterface(&Handle, &Guid, EFI_NATIVE_INTERFACE, &LdrProtocol);
}