/** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory * FILE: xtldr/protocol.c * DESCRIPTION: XT Boot Loader protocol support * DEVELOPERS: Rafal Kupiec */ #include /** * 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 = BlClearConsoleScreen; LdrProtocol.Console.DisableCursor = BlDisableConsoleCursor; LdrProtocol.Console.EnableCursor = BlEnableConsoleCursor; LdrProtocol.Console.Print = BlConsolePrint; LdrProtocol.Console.QueryMode = BlQueryConsoleMode; LdrProtocol.Console.ReadKeyStroke = BlReadKeyStroke; LdrProtocol.Console.ResetInputBuffer = BlResetConsoleInputBuffer; LdrProtocol.Console.SetAttributes = BlSetConsoleAttributes; LdrProtocol.Console.SetCursorPosition = BlSetCursorPosition; LdrProtocol.Console.Write = BlConsoleWrite; LdrProtocol.Debug.Print = BlDebugPrint; LdrProtocol.Disk.CloseVolume = BlCloseVolume; LdrProtocol.Disk.OpenVolume = BlOpenVolume; LdrProtocol.Disk.ReadFile = BlReadFile; 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.GetSecureBootStatus = BlGetSecureBootStatus; LdrProtocol.Util.SleepExecution = BlSleepExecution; LdrProtocol.Util.WaitForEfiEvent = BlWaitForEfiEvent; /* Register XTLDR loader protocol */ BlDebugPrint(L"Registering XT loader protocol\n"); return EfiSystemTable->BootServices->InstallProtocolInterface(&Handle, &Guid, EFI_NATIVE_INTERFACE, &LdrProtocol); }