diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-05 10:42:37 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-05 10:42:37 +0200 |
| commit | 6898b7a9f1cf82fb65f6b6fae88db0a0b765a924 (patch) | |
| tree | 44d1fdfba6250f98aab02222601098c4cbaa6fc9 | |
| parent | 715424f3caf98f3126d2f264dbbd7b3ffb859f7b (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>
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | Private/FirmwareKit/Handover.hxx | 9 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMain.cxx | 10 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx | 4 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 45 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 1 | ||||
| -rw-r--r-- | Private/makefile | 2 |
7 files changed, 57 insertions, 21 deletions
@@ -3,6 +3,13 @@ syntax: glob html/ latex/ +# NewKernel image +NewKernel + +# Alternative kernel image +AltKernel +PatchKernel + .cmake/ .qtc_clangd/ CMakeCache.txt diff --git a/Private/FirmwareKit/Handover.hxx b/Private/FirmwareKit/Handover.hxx index da9a3bbf..5a3d8d1e 100644 --- a/Private/FirmwareKit/Handover.hxx +++ b/Private/FirmwareKit/Handover.hxx @@ -22,10 +22,9 @@ /* useful macros */ #define kHandoverMagic 0xBADCC -#define kHandoverVersion 0x1011 +#define kHandoverVersion 0x112 #define kHandoverStructSz sizeof(HEL::HandoverHeader) -#define kHandoverHeapStart (0xfffffff80000000) namespace NewOS::HEL { /** @@ -65,12 +64,15 @@ struct HandoverInformationHeader { voidPtr f_VirtualStart; SizeT f_VirtualSize; voidPtr f_PhysicalStart; + WideChar f_FirmwareVendorName[32]; SizeT f_FirmwareVendorLen; + struct { VoidPtr f_SmBios; VoidPtr f_RsdPtr; } f_HardwareTables; + struct { UIntPtr f_The; SizeT f_Size; @@ -79,10 +81,11 @@ struct HandoverInformationHeader { UInt32 f_PixelFormat; UInt32 f_PixelPerLine; } f_GOP; + UInt64 f_FirmwareSpecific[8]; }; -enum { kHandoverSpecificKind, kHandoverSpecificAttrib, }; +enum { kHandoverSpecificKind, kHandoverSpecificAttrib, kHandoverSpecificMemoryEfi, }; /// @brief Bootloader main type. typedef void (*BootMainKind)(NewOS::HEL::HandoverInformationHeader* handoverInfo); diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index d6b4ab76..ab80e5c8 100644 --- a/Private/HALKit/AMD64/HalKernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -22,17 +22,21 @@ namespace NewOS::HAL { /// @brief Gets the system cores using the MADT. /// @param rsdPtr the RSD PTR. extern void hal_system_get_cores(NewOS::voidPtr rsdPtr); -} // namespace NewOS::HAL +} // namespace NewOS::HAL EXTERN_C void hal_init_platform( NewOS::HEL::HandoverInformationHeader* HandoverHeader) { kHandoverHeader = HandoverHeader; + if (kHandoverHeader->f_Magic != kHandoverMagic && + kHandoverHeader->f_Version != kHandoverVersion) { + return; + } + /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = reinterpret_cast<NewOS::VoidPtr>( - reinterpret_cast<NewOS::UIntPtr>(HandoverHeader->f_VirtualStart) + - kVirtualAddressStartOffset); + reinterpret_cast<NewOS::UIntPtr>(HandoverHeader->f_VirtualStart)); kKernelPhysicalStart = HandoverHeader->f_PhysicalStart; 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__ diff --git a/Private/makefile b/Private/makefile index 977e33ac..88a0f165 100644 --- a/Private/makefile +++ b/Private/makefile @@ -29,7 +29,7 @@ COPY = cp # Add assembler, linker, and object files variables. ASMFLAGS = -f win64 -# NewOS subsystem is 17. +# NewOS subsystem is 17 and entrypoint is __ImageStart LDFLAGS = -e __ImageStart --subsystem=17 LDOBJ = Objects/*.obj |
