summaryrefslogtreecommitdiffhomepage
path: root/Boot
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
parent34bb37c9a464ab0dfccfa5ff217a283e36b32693 (diff)
[IMP] [MHR-39] Ticket done.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Boot')
-rw-r--r--Boot/BootKit/BootKit.hxx24
-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
-rw-r--r--Boot/amd64-efi.make2
5 files changed, 66 insertions, 24 deletions
diff --git a/Boot/BootKit/BootKit.hxx b/Boot/BootKit/BootKit.hxx
index 1f6b7d95..680c9863 100644
--- a/Boot/BootKit/BootKit.hxx
+++ b/Boot/BootKit/BootKit.hxx
@@ -273,9 +273,9 @@ private:
constexpr auto cNewFSCatalogPadding = 4;
- NFS_CATALOG_STRUCT* catalogKind = (NFS_CATALOG_STRUCT*)bufCatalog;
- catalogKind->PrevSibling = startLba;
- catalogKind->NextSibling = (startLba + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding));
+ NFS_CATALOG_STRUCT* catalogKind = (NFS_CATALOG_STRUCT*)bufCatalog;
+ catalogKind->PrevSibling = startLba;
+ catalogKind->NextSibling = (startLba + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding));
/// Fill catalog kind.
catalogKind->Kind = blob->fKind;
@@ -288,6 +288,9 @@ private:
EFI::ThrowError(L"Developer-Error", L"This is caused by the developer of the bootloader.");
}
+ --partBlock.FreeCatalog;
+ --partBlock.FreeSectors;
+
writer.Write(L"newosldr: root directory: ").Write(blob->fFileName).Write(L"\r");
memcpy(catalogKind->Name, blob->fFileName, strlen(blob->fFileName));
@@ -297,11 +300,6 @@ private:
fDiskDev.Write((Char*)bufCatalog, sizeof(NFS_CATALOG_STRUCT));
- --partBlock.FreeCatalog;
- --partBlock.FreeSectors;
-
- memset(bufCatalog, 0, sizeof(NFS_CATALOG_STRUCT));
-
return true;
}
@@ -324,8 +322,8 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const char* partName,
return false; /// sanity check
/// convert the sector into something that the disk understands.
- SizeT sectorSz = BootDev::kSectorSize;
- Char buf[BootDev::kSectorSize] = {0};
+ SizeT sectorSz = BootDev::kSectorSize;
+ Char* buf = new Char[BootDev::kSectorSize];
NFS_ROOT_PARTITION_BLOCK* partBlock = reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(buf);
@@ -340,6 +338,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const char* partName,
if (GIB(fDiskDev.GetDiskSize()) < cMinimumDiskSize)
{
+ delete buf;
EFI::ThrowError(L"Disk-Too-Tiny", L"Can't format a New Filesystem partition here.");
return false;
}
@@ -382,19 +381,22 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const char* partName,
CopyMem(epmBoot->Magic, reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), StrLen(kEPMMagic));
BTextWriter writer;
- writer.Write(L"newosldr: wrote partition.\r");
+ writer.Write(L"newosldr: wrote partition with success.\r");
fDiskDev.Leak().mBase = kEpmBase;
fDiskDev.Leak().mSize = sectorSz;
fDiskDev.Write(buf, sectorSz);
+ delete buf;
return true;
}
else
{
+ delete buf;
EFI::ThrowError(L"Filesystem-Failure-Part", L"Filesystem couldn't be partitioned.");
}
+ delete buf;
return false;
}
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);
diff --git a/Boot/amd64-efi.make b/Boot/amd64-efi.make
index f11d68e3..b8d5b771 100644
--- a/Boot/amd64-efi.make
+++ b/Boot/amd64-efi.make
@@ -29,7 +29,7 @@ IMG=epm-master-1.img
IMG_2=epm-slave.img
IMG_3=epm-master-2.img
-EMU_FLAGS=-net none -smp 2 -m 4G -M q35 \
+EMU_FLAGS=-net none -smp 2 -m 6G -M q35 \
-bios $(BIOS) -device piix3-ide,id=ide \
-drive id=disk,file=$(IMG),format=raw,if=none \
-device ide-hd,drive=disk,bus=ide.0 -drive \