summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-06 11:30:56 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-06 11:30:56 +0100
commit61492dc648412818e1f0e96dbc9522514b1fed2a (patch)
tree068fd8cca5e27cbe48990dae2e10cc618e6ae155 /Private/NewBoot/Source
parent55eb89dde91318a6b7f37e824d383e0625cd53f1 (diff)
HCR-15 : Load kernel into memory.
Progess have been done regarding PE/MZ support, also updated PEF impl to not rely on compiler feature __attribute__ Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
-rw-r--r--Private/NewBoot/Source/FileReader.cxx22
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx36
2 files changed, 40 insertions, 18 deletions
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index efd53020..2bed60ef 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -92,10 +92,6 @@ BFileReader::BFileReader(const CharacterType* path, EfiHandlePtr ImageHandle) {
}
BFileReader::~BFileReader() {
- if (this->mBlob) {
- BS->FreePool(this->mBlob);
- }
-
if (this->mFile) {
this->mFile->Close(this->mFile);
this->mFile = nullptr;
@@ -115,17 +111,21 @@ Void BFileReader::ReadAll() {
/// Allocate Handover page.
- UInt8* blob = (UInt8*)kHandoverStartKernel;
+ if (mBlob == nullptr) {
+ UInt8* blob = (UInt8*)kHandoverStartKernel;
+
+ if (BS->AllocatePages(AllocateAnyPages, EfiLoaderData, 1,
+ (EfiPhysicalAddress*)&blob) != kEfiOk) {
+ EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error.");
+ }
- if (BS->AllocatePages(AllocateAnyPages, EfiLoaderData, 1,
- (EfiPhysicalAddress*)&blob) != kEfiOk) {
- EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error.");
+ mBlob = blob;
}
- mBlob = blob;
- mSizeFile = KIB(kMaxReadSize);
+ mErrorCode = kNotSupported;
- if (mFile->Read(mFile, &mSizeFile, mBlob) != kEfiOk) return;
+ if (mFile->Read(mFile, &mSizeFile, (VoidPtr)((UIntPtr)mBlob)) != kEfiOk)
+ return;
mErrorCode = kOperationOkay;
}
diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index 6feefea5..ff6eb730 100644
--- a/Private/NewBoot/Source/RuntimeMain.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -15,6 +15,16 @@
#include <KernelKit/PE.hpp>
#include <NewKit/Ref.hpp>
+namespace Detail {
+constexpr Int32 kReadSz = 2048;
+
+auto FindPEHeader(DosHeaderPtr ptrDos) -> ExecHeaderPtr {
+ if (!ptrDos) return nullptr;
+
+ return (ExecHeaderPtr)(&ptrDos->eLfanew + 1);
+}
+} // namespace Detail
+
EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
InitEFI(SystemTable);
@@ -39,21 +49,33 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
.WriteString(L"\r\n");
BFileReader img(L"HCOREKRNL.EXE", ImageHandle);
+
+ img.Size() = Detail::kReadSz;
img.ReadAll();
if (img.Error() == BFileReader::kOperationOkay) {
- VoidPtr blob = img.Blob();
+ UInt8* blob = (UInt8*)img.Blob();
- UInt64 MapKey = 0;
+ DosHeaderPtr ptrDos = reinterpret_cast<DosHeaderPtr>(blob);
+ ExecHeaderPtr ptrHdr = Detail::FindPEHeader(ptrDos);
- EFI::ExitBootServices(MapKey, ImageHandle);
- EFI::Stop();
+ if (ptrDos->eMagic[0] == kMagMz0 && ptrDos->eMagic[1] == kMagMz1 &&
+ ptrHdr->mMachine == EFI::Platform() && ptrHdr->mMagic == kPeMagic) {
+ UInt64 MapKey = 0;
- return kEfiOk;
+ writer.WriteString(L"HCoreLdr: Booting...").WriteString(L"\r\n");
+
+ EFI::ExitBootServices(MapKey, ImageHandle);
+
+ // Launch PE app.
+
+ EFI::Stop();
+
+ return kEfiOk;
+ }
}
- writer.WriteString(
- L"HCoreLdr: Missing HCOREKRNL.EXE! Your system is damaged.\r\n");
+ writer.WriteString(L"HCoreLdr: Error! HCOREKRNL.EXE missing or invalid!\r\n");
EFI::Stop();