summaryrefslogtreecommitdiffhomepage
path: root/Boot/Sources
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-04 17:47:13 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-04 17:48:40 +0200
commitfb0ca452cda3bdc4a13f278c115f2dcd9360d818 (patch)
tree788411aebd30ed446cb8c4bb5756a3e937c08f0a /Boot/Sources
parent34bb37c9a464ab0dfccfa5ff217a283e36b32693 (diff)
[IMP] [MHR-39] Ticket done.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Boot/Sources')
-rw-r--r--Boot/Sources/HEL/AMD64/BootMain.cxx58
-rw-r--r--Boot/Sources/HEL/AMD64/New+Delete.cxx4
-rw-r--r--Boot/Sources/ProgramLoader.cxx2
3 files changed, 52 insertions, 12 deletions
diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx
index 6aec67f5..2bc2aca1 100644
--- a/Boot/Sources/HEL/AMD64/BootMain.cxx
+++ b/Boot/Sources/HEL/AMD64/BootMain.cxx
@@ -7,6 +7,7 @@
#include <BootKit/BootKit.hxx>
#include <BootKit/Rsrc/NewBoot.rsrc>
#include <Modules/CoreCG/FbRenderer.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
#include <FirmwareKit/EFI.hxx>
#include <FirmwareKit/EFI/API.hxx>
#include <FirmwareKit/Handover.hxx>
@@ -16,7 +17,6 @@
#include <NewKit/Macros.hxx>
#include <NewKit/Ref.hxx>
#include <BootKit/ProgramLoader.hxx>
-#include <Modules/CoreCG/TextRenderer.hxx>
#include <cstring>
// make the compiler shut up.
@@ -97,14 +97,11 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
.Write(BVersionString::The())
.Write("\r");
- UInt32* MapKey = new UInt32();
- UInt32* SizePtr = new UInt32();
+ UInt32 MapKey = 0;
+ UInt32 SizePtr = sizeof(EfiMemoryDescriptor);
EfiMemoryDescriptor* Descriptor = nullptr;
- UInt32* SzDesc = new UInt32();
- UInt32* RevDesc = new UInt32();
-
- *MapKey = 0;
- *SizePtr = 0;
+ UInt32 SzDesc = sizeof(EfiMemoryDescriptor);
+ UInt32 RevDesc = 0;
HEL::HandoverInformationHeader* handoverHdrPtr =
new HEL::HandoverInformationHeader();
@@ -130,6 +127,47 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
// Fill handover header now.
+ BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc);
+
+ Descriptor = new EfiMemoryDescriptor[SzDesc];
+ BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc);
+
+ auto cDefaultMemoryMap = 0; // The sixth entry.
+
+ //-----------------------------------------------------------//
+ // A simple loop which finds a usable memory region for us.
+ //-----------------------------------------------------------//
+
+ SizeT lookIndex = 0UL;
+
+ for (; Descriptor[lookIndex].Kind != EfiMemoryType::EfiConventionalMemory; ++lookIndex)
+ {
+ ;
+ }
+
+ cDefaultMemoryMap = lookIndex;
+
+ //-----------------------------------------------------------//
+ // Update handover file specific table and phyiscal start field.
+ //-----------------------------------------------------------//
+
+ handoverHdrPtr->f_PhysicalStart =
+ (VoidPtr)Descriptor[cDefaultMemoryMap].PhysicalStart;
+
+ handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificAttrib] =
+ Descriptor[cDefaultMemoryMap].Attribute;
+ handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificKind] =
+ Descriptor[cDefaultMemoryMap].Kind;
+ handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] =
+ (UIntPtr)Descriptor;
+
+ handoverHdrPtr->f_VirtualStart =
+ (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart;
+ handoverHdrPtr->f_VirtualSize =
+ Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */
+
+ handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+
handoverHdrPtr->f_Magic = kHandoverMagic;
handoverHdrPtr->f_Version = kHandoverVersion;
@@ -164,7 +202,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
// ---------------------------------------------------- //
BFileReader readerKernel(L"newoskrnl.dll", ImageHandle);
-
+
readerKernel.ReadAll(0);
Boot::ProgramLoader* loader = nullptr;
@@ -185,7 +223,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
- EFI::ExitBootServices(*MapKey, ImageHandle);
+ EFI::ExitBootServices(MapKey, ImageHandle);
// ---------------------------------------------------- //
// Call kernel.
diff --git a/Boot/Sources/HEL/AMD64/New+Delete.cxx b/Boot/Sources/HEL/AMD64/New+Delete.cxx
index 62dcda35..b651f091 100644
--- a/Boot/Sources/HEL/AMD64/New+Delete.cxx
+++ b/Boot/Sources/HEL/AMD64/New+Delete.cxx
@@ -19,7 +19,9 @@ EXTERN EfiBootServices* BS;
void* operator new(size_t sz)
{
void* buf = nullptr;
- BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf);
+
+ while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) == kBufferTooSmall)
+ BS->FreePool(buf);
return buf;
}
diff --git a/Boot/Sources/ProgramLoader.cxx b/Boot/Sources/ProgramLoader.cxx
index 6568f0aa..bdd54383 100644
--- a/Boot/Sources/ProgramLoader.cxx
+++ b/Boot/Sources/ProgramLoader.cxx
@@ -41,7 +41,7 @@ namespace Boot
if (firstBytes[0] == kMagMz0 &&
firstBytes[1] == kMagMz1)
{
- writer.Write("newosldr: Windows executable detected.\r");
+ writer.Write("newosldr: PE32+ executable detected.\r");
ExecHeaderPtr hdrPtr = ldr_find_exec_header(firstBytes);
ExecOptionalHeaderPtr optHdr = ldr_find_opt_exec_header(firstBytes);