summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-05 10:42:37 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-05 10:42:37 +0200
commit6898b7a9f1cf82fb65f6b6fae88db0a0b765a924 (patch)
tree44d1fdfba6250f98aab02222601098c4cbaa6fc9 /Private/NewBoot/Source
parent715424f3caf98f3126d2f264dbbd7b3ffb859f7b (diff)
MHR-23: Fix memory detection in bootloader and new revision of the handover protocol.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx4
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx45
-rw-r--r--Private/NewBoot/Source/makefile1
3 files changed, 36 insertions, 14 deletions
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
index 0f711334..85b90e57 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
@@ -67,7 +67,6 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path,
if (efp->OpenVolume(efp, &rootFs) != kEfiOk) {
mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r");
- EFI::ThrowError(L"NoSuchVolume", L"No Such volume.");
this->mErrorCode = kNotSupported;
return;
}
@@ -79,7 +78,6 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path,
mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ")
.Write(mPath)
.Write(L"\r");
- EFI::ThrowError(L"NoSuchPath", L"No Such file on filesystem.");
this->mErrorCode = kNotSupported;
return;
}
@@ -111,7 +109,7 @@ Void BFileReader::ReadAll(SizeT until, SizeT chunk) {
if (auto err = BS->AllocatePool(EfiLoaderCode, until, (VoidPtr*)&mBlob) !=
kEfiOk) {
mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r");
- EFI::ThrowError(L"OutOfMemory", L"Allocation error.");
+ EFI::ThrowError(L"OutOfMemory", L"Out of memory.");
}
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index f3aef92d..844179da 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -11,6 +11,7 @@
#include <FirmwareKit/EFI/API.hxx>
#include <FirmwareKit/Handover.hxx>
#include <KernelKit/MSDOS.hpp>
+#include <KernelKit/PE.hxx>
#include <KernelKit/PEF.hpp>
#include <NewKit/Macros.hpp>
#include <NewKit/Ref.hpp>
@@ -133,29 +134,50 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
Descriptor = new EfiMemoryDescriptor[*SzDesc];
BS->GetMemoryMap(SizePtr, Descriptor, MapKey, SzDesc, RevDesc);
- writer.Write(L"Kernel-Memory-Map:\r");
+ writer.Write(L"Kernel-Desc-Count: ");
+ writer.Write(*SzDesc);
+ writer.Write(L"\r");
+
+ auto cDefaultMemoryMap = 0; /// The sixth entry.
+
+ /// A simple loop which finds a usable memory region for us.
+ SizeT i = 0UL;
+ for (; Descriptor[i].Kind != EfiMemoryType::EfiConventionalMemory; ++i) {
+ ;
+ }
+
+ cDefaultMemoryMap = i;
writer.Write(L"Number-Of-Pages: ")
- .Write(Descriptor->NumberOfPages)
+ .Write(Descriptor[cDefaultMemoryMap].NumberOfPages)
.Write(L"\r");
writer.Write(L"Virtual-Address: ")
- .Write(Descriptor->VirtualStart)
+ .Write(Descriptor[cDefaultMemoryMap].VirtualStart)
.Write(L"\r");
writer.Write(L"Phyiscal-Address: ")
- .Write(Descriptor->PhysicalStart)
+ .Write(Descriptor[cDefaultMemoryMap].PhysicalStart)
+ .Write(L"\r");
+ writer.Write(L"Page-Kind: ")
+ .Write(Descriptor[cDefaultMemoryMap].Kind)
+ .Write(L"\r");
+ writer.Write(L"Page-Attribute: ")
+ .Write(Descriptor[cDefaultMemoryMap].Attribute)
.Write(L"\r");
- writer.Write(L"Kind: ").Write(Descriptor->Kind).Write(L"\r");
- writer.Write(L"Attribute: ").Write(Descriptor->Attribute).Write(L"\r");
- handoverHdrPtr->f_PhysicalStart = (VoidPtr)Descriptor->PhysicalStart;
+ handoverHdrPtr->f_PhysicalStart =
+ (VoidPtr)Descriptor[cDefaultMemoryMap].PhysicalStart;
handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificAttrib] =
- Descriptor->Attribute;
+ Descriptor[cDefaultMemoryMap].Attribute;
handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificKind] =
- Descriptor->Kind;
+ Descriptor[cDefaultMemoryMap].Kind;
+ handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] =
+ (UIntPtr)Descriptor;
- handoverHdrPtr->f_VirtualStart = (VoidPtr)Descriptor->VirtualStart;
- handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */
+ handoverHdrPtr->f_VirtualStart =
+ (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart;
+ handoverHdrPtr->f_VirtualSize =
+ Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */
handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
@@ -198,6 +220,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
EFI::ExitBootServices(*MapKey, ImageHandle);
+ /// Fallback to builtin kernel.
hal_init_platform(handoverHdrPtr);
EFI::Stop();
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 15412436..a7eb0910 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -59,6 +59,7 @@ all: compile-amd64
$(LD_GNU) $(OBJ) $(LD_FLAGS) -o $(BOOT_LOADER)
$(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/BOOTX64.EFI
$(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/NEWBOOT.EFI
+ $(COPY) ../../$(KERNEL) CDROM/$(KERNEL)
ifneq ($(DEBUG_SUPPORT), )
DEBUG = -D__DEBUG__