diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-29 19:54:04 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-29 19:56:13 +0100 |
| commit | 4cadbff15541ca09ced3321acfdf302fced29ee9 (patch) | |
| tree | 279a18b8268add19ad9ac1010d3d70c39a102e7b /Private/NewBoot | |
| parent | 65254486efff0fd1bb78a48ff90b7713a5ce539f (diff) | |
NewBoot: Working on EFI implementation to load kernel into memory...
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot')
| -rw-r--r-- | Private/NewBoot/BootKit/Protocol.hxx | 38 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx | 26 |
2 files changed, 39 insertions, 25 deletions
diff --git a/Private/NewBoot/BootKit/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx index c2dc1a9d..68b837b4 100644 --- a/Private/NewBoot/BootKit/Protocol.hxx +++ b/Private/NewBoot/BootKit/Protocol.hxx @@ -11,41 +11,35 @@ #include <EFIKit/EFI.hxx> -namespace HEL -{ -using namespace hCore; - +namespace hCore::HEL { /** @brief the kind of executable we're loading. */ -enum -{ - kTypeKernel = 100, - kTypeKernelDriver = 101, - kTypeRsrc = 102, - kTypeCount = 3, +enum { + kTypeKernel = 100, + kTypeKernelDriver = 101, + kTypeRsrc = 102, + kTypeCount = 3, }; /** @brief The executable architecture. */ -enum -{ - kArchAmd64 = 122, - kArchCount = 2, +enum { + kArchAmd64 = 122, + kArchCount = 2, }; -struct __attribute__((packed)) HandoverHeader final -{ - Int32 targetMagic; - Int32 targetType; - Int32 targetArch; - UIntPtr protocolHeaderTable; +struct __attribute__((packed)) HandoverHeader final { + Int32 targetMagic; + Int32 targetType; + Int32 targetArch; + UIntPtr startAddress; }; -} // namespace HEL +} // namespace hCore::HEL #define kHandoverMagic 0xBAD55 -#define kBaseHandoverStruct 0x10000000 +#define kBaseHandoverStruct 0x80000000 #define kHandoverStructSz sizeof(HEL::HandoverHeader) 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 <BootKit/Processor.hxx> #include <BootKit/Protocol.hxx> +// 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"); |
