summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-16 14:00:12 +0000
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-16 14:00:12 +0000
commit82f0a2da77af7d79e53f5e65e46c527c1fe92765 (patch)
tree319ef7dd933367d64911c0ed9a53f91565002b00 /Private/NewBoot
parent544d0cadfc371bcfb54d9f7ec15464bc6a79af21 (diff)
parent4c7aebf1b8964b99b89a25da0965b30fe6c7e6b3 (diff)
Merge branch 'HCR-18' into 'trunk'
HCR-18: First commit, bringing HCoreKrnl.exe into memory. See merge request mahrouss-logic/micro-kernel!6
Diffstat (limited to 'Private/NewBoot')
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx7
-rw-r--r--Private/NewBoot/Source/FileReader.cxx2
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx98
3 files changed, 87 insertions, 20 deletions
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 0c747643..dcb8daf4 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -64,7 +64,7 @@ class BFileReader final {
explicit BFileReader(const CharacterType *path, EfiHandlePtr ImageHandle);
~BFileReader();
- Void Read();
+ Void ReadAll();
enum {
kOperationOkay,
@@ -80,6 +80,11 @@ class BFileReader final {
EfiFileProtocolPtr File() { return mFile; }
UInt64 &Size() { return mSizeFile; }
+ UInt64 &Size(const UInt64 &Sz) {
+ mSizeFile = Sz;
+ return mSizeFile;
+ }
+
public:
BFileReader &operator=(const BFileReader &) = default;
BFileReader(const BFileReader &) = default;
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index 5768cae0..d81248ea 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -103,7 +103,7 @@ BFileReader::~BFileReader() {
@brief this reads all of the buffer.
@param ImageHandle used internally.
*/
-Void BFileReader::Read() {
+Void BFileReader::ReadAll() {
/// Allocate Handover page.
if (mBlob == nullptr) {
diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index 3c55c06b..38eb0ea8 100644
--- a/Private/NewBoot/Source/RuntimeMain.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -15,7 +15,14 @@
#include <KernelKit/PE.hpp>
#include <NewKit/Ref.hpp>
-#define kBufferReadSz 2048
+#ifdef __x86_64__
+#include <HALKit/AMD64/HalPageAlloc.hpp>
+#else
+#error Unknown CPU.
+#endif // ifdef __x86_64__
+
+#define kHeadersSz \
+ (sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader))
EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
@@ -26,36 +33,28 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
#ifndef __DEBUG__
- writer.WriteString(
- L"MahroussLogic (R) HCore Version 1.00 (Release Channel)\r\n");
+ writer.WriteString(L"HCoreLdr: Version 1.00 (Release Channel)\r\n");
#else
- writer.WriteString(
- L"MahroussLogic (R) HCore Version 1.00 (Insiders Channel)\r\n");
+ writer.WriteString(L"HCoreLdr: Version 1.00 (Insiders Channel)\r\n");
#endif
const char strDate[] = __DATE__;
- writer.WriteString(L"Build Date: ");
+ writer.WriteString(L"HCoreLdr: Build date: ");
- for (auto& ch : strDate) {
- writer.WriteCharacter(ch);
- }
+ for (auto& ch : strDate) writer.WriteCharacter(ch);
writer.WriteString(L"\r\nHCoreLdr: Firmware Vendor: ")
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
- writer.WriteString(L"HCoreLdr: Reading: ")
- .WriteString(L"HCOREKRNL.EXE")
- .WriteString(L"\r\n");
-
BFileReader img(L"HCOREKRNL.EXE", ImageHandle);
- img.Size() = kBufferReadSz;
- img.Read();
+ img.Size(kHeadersSz);
+ img.ReadAll();
if (img.Error() == BFileReader::kOperationOkay) {
BlobType blob = (BlobType)img.Blob();
@@ -66,11 +65,72 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
if (ptrHdr && ptrHdr->mMachine == EFI::Platform() &&
ptrHdr->mMagic == kPeMagic) {
if (ptrHdr->mNumberOfSections > 1) {
- UInt64 MapKey = 0;
+ ExecOptionalHeaderPtr optHdr = reinterpret_cast<ExecOptionalHeaderPtr>(
+ ptrHdr + sizeof(ExecHeader));
+
+ UInt32 MapKey = 0;
+ UInt32* Size;
+ EfiMemoryDescriptor* Descriptor;
+ UInt32 SzDesc = 0;
+ UInt32 RevDesc = 0;
+
+ if (BS->AllocatePool(EfiLoaderData, sizeof(UInt64), (VoidPtr*)&Size) !=
+ kEfiOk) {
+ EFI::RaiseHardError(
+ L"HCoreLdr-BadAlloc",
+ L"The bootloader ran out of memory! Please check your specs.");
+ }
+
+ *Size = sizeof(EfiMemoryDescriptor);
+
+ if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
+ (VoidPtr*)&Descriptor) != kEfiOk) {
+ EFI::RaiseHardError(
+ L"HCoreLdr-BadAlloc",
+ L"The bootloader ran out of memory! Please check your specs.");
+ }
+
+ if (BS->GetMemoryMap(Size, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
+ kEfiOk) {
+ EFI::RaiseHardError(
+ L"HCoreLdr-GetMemoryMap",
+ L"GetMemoryMap returned a value which isn't kEfiOk!");
+ }
+
+ HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
+
+ BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
+ (VoidPtr*)&handoverHdrPtr);
+
+ handoverHdrPtr->f_GOP = (voidPtr)kGop->Mode->FrameBufferBase;
+ handoverHdrPtr->f_GOPSize = kGop->Mode->FrameBufferSize;
+
+ handoverHdrPtr->f_PhysicalStart =
+ reinterpret_cast<voidPtr>(Descriptor->PhysicalStart);
+ handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages * kPTESize;
+
+ handoverHdrPtr->f_VirtualStart =
+ reinterpret_cast<voidPtr>(Descriptor->VirtualStart);
+
+ handoverHdrPtr->f_VirtualSize =
+ Descriptor->NumberOfPages; /* # of pages */
+
+ handoverHdrPtr->f_FirmwareVendorLen =
+ BStrLen(SystemTable->FirmwareVendor);
+
+ BCopyMem(handoverHdrPtr->f_FirmwareVendorName,
+ SystemTable->FirmwareVendor,
+ handoverHdrPtr->f_FirmwareVendorLen);
+
+ writer.WriteString(L"HCoreLdr: Leaving it to kernel...\r\n");
EFI::ExitBootServices(MapKey, ImageHandle);
- // Launch PE app.
+ HCore::HEL::HandoverProc proc =
+ reinterpret_cast<HCore::HEL::HandoverProc>(
+ optHdr->mAddressOfEntryPoint);
+
+ proc(handoverHdrPtr);
EFI::Stop();
@@ -78,9 +138,11 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
} else {
writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0001\r\n");
}
+ } else {
+ writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0002\r\n");
}
} else {
- writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0002\r\n");
+ writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0003\r\n");
}
EFI::Stop();