From 4cadbff15541ca09ced3321acfdf302fced29ee9 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 29 Jan 2024 19:54:04 +0100 Subject: NewBoot: Working on EFI implementation to load kernel into memory... Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'Private/NewBoot/Source') diff --git a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx index 0d44086b..9174293e 100644 --- a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx @@ -11,13 +11,33 @@ #include #include +// don't remove EfiGUID, it will call initializer_list! + EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, - EfiSystemTable *SystemTable) { + EfiSystemTable* SystemTable) { SystemTable->ConOut->OutputString(SystemTable->ConOut, L"HCoreLdr: Starting \\EPM\\HCore...\r\n"); - if (SystemTable->BootServices->ExitBootServices( - ImageHandle, kBaseHandoverStruct) != kEfiOk) { + EfiLoadImageProtocol* protocol{}; + + EfiGUID guid = EfiGUID EFI_LOADED_IMAGE_PROTOCOL_GUID; + + SystemTable->BootServices->LocateProtocol(&guid, nullptr, + (VoidPtr*)&protocol); + + if (!protocol) { + SystemTable->ConOut->OutputString( + SystemTable->ConOut, + L"HCoreLdr: Could not locate EfiLoadImageProtocol! Aborting...\r\n"); + + return kEfiFail; + } + + SystemTable->BootServices->OpenProtocol( + ImageHandle, &guid, (VoidPtr*)&protocol, ImageHandle, ImageHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + + if (SystemTable->BootServices->ExitBootServices(ImageHandle, 0) != kEfiOk) { SystemTable->ConOut->OutputString( SystemTable->ConOut, L"HCoreLdr: Could not Exit UEFI!\r\nHanging...\r\n"); -- cgit v1.2.3