diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-10 09:41:33 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-10 09:41:33 +0200 |
| commit | e50f871e6852beacb53986f930ed2d5dead84838 (patch) | |
| tree | f9a526d927e9b73a588e9c7db5cd99bf1622ca23 /dev/boot/src | |
| parent | 26932fb28c6d8724222fc80705976369f2f5dbb3 (diff) | |
kernel, boot: a lot of improvements regarding memory probing.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/boot/src')
| -rw-r--r-- | dev/boot/src/HEL/AMD64/BootEFI.cc | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index e07ad6d6..57651016 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -165,58 +165,39 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, // Fill handover header now. - // ---------------------------------------------------- // - // The following checks for an exisiting partition - // inside the disk, if it doesn't have one, - // format the disk. - // ---------------------------------------------------- // - Boot::BootTextWriter writer; - auto ret = BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); - - if (ret == kEfiFail) - { - writer.Write("BootZ: GetMemoryMap failed (x1)\r"); - Boot::Stop(); - } - - size_struct_ptr += sz_desc * 2; - BS->AllocatePool(EfiMemoryType::EfiBootServicesData, size_struct_ptr, reinterpret_cast<VoidPtr*>(&struct_ptr)); + //-------------------------------------------------------------// + // Update handover file specific table and phyiscal start field. + //-------------------------------------------------------------// - ret = BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); + handover_hdr->f_BitMapSize = gib_cast(4); /* Size of bitmap in bytes. */ + Int32 trials = 5 * 10000000; - if (ret == kEfiFail) + while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) { - writer.Write("BootZ: GetMemoryMap failed (x2)\r"); - Boot::Stop(); - } + --trials; - //-----------------------------------------------------------// - // A simple loop which finds a usable memory region for us. - //-----------------------------------------------------------// + if (!trials) + { + writer.Write("BootZ: Unable to allocate sufficent memory, trying again with 2GB...\r"); - SizeT lookup_index = 0UL; - SizeT entry_count = size_struct_ptr / sz_desc; + trials = 3 * 10000000; - for (; lookup_index < entry_count; ++lookup_index) - { - if (struct_ptr[lookup_index].Kind == EfiMemoryType::EfiConventionalMemory) - break; - } + handover_hdr->f_BitMapSize = gib_cast(2); /* Size of bitmap in bytes. */ - if (lookup_index > entry_count) - { - writer.Write("BootZ: No usable entries.\r"); - Boot::Stop(); - } + while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) + { + --trials; - //-------------------------------------------------------------// - // Update handover file specific table and phyiscal start field. - //-------------------------------------------------------------// - - handover_hdr->f_BitMapStart = (VoidPtr)(struct_ptr[lookup_index].VirtualStart); /* Start of bitmap. */ - handover_hdr->f_BitMapSize = struct_ptr[lookup_index].NumberOfPages * kib_cast(4); /* Size of bitmap in bytes. */ + if (!trials) + { + writer.Write("BootZ: Unable to allocate sufficent memory, aborting...\r"); + Boot::Stop(); + } + } + } + } handover_hdr->f_FirmwareCustomTables[0] = (VoidPtr)BS; handover_hdr->f_FirmwareCustomTables[1] = (VoidPtr)ST; |
