diff options
Diffstat (limited to 'dev/boot/src')
| -rw-r--r-- | dev/boot/src/BootTextWriter.cc | 4 | ||||
| -rw-r--r-- | dev/boot/src/HEL/AMD64/BootEFI.cc | 43 |
2 files changed, 32 insertions, 15 deletions
diff --git a/dev/boot/src/BootTextWriter.cc b/dev/boot/src/BootTextWriter.cc index bc93b133..0b132f83 100644 --- a/dev/boot/src/BootTextWriter.cc +++ b/dev/boot/src/BootTextWriter.cc @@ -131,7 +131,7 @@ Boot::BootTextWriter& Boot::BootTextWriter::WriteCharacter(CharacterTypeUTF16 c) return *this; } -Boot::BootTextWriter& Boot::BootTextWriter::Write(const Long& x) +Boot::BootTextWriter& Boot::BootTextWriter::Write(const UInt64& x) { #ifdef __DEBUG__ this->_Write(x); @@ -141,7 +141,7 @@ Boot::BootTextWriter& Boot::BootTextWriter::Write(const Long& x) return *this; } -Boot::BootTextWriter& Boot::BootTextWriter::_Write(const Long& x) +Boot::BootTextWriter& Boot::BootTextWriter::_Write(const UInt64& x) { #ifdef __DEBUG__ UInt64 y = (x > 0 ? x : -x) / 16; diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 7b912025..5f89aae6 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -91,9 +91,9 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr image_handle, new HEL::BootInfoHeader(); UInt32 map_key = 0; - UInt32 size_struct_ptr = sizeof(EfiMemoryDescriptor); + UInt32 size_struct_ptr = 0; EfiMemoryDescriptor* struct_ptr = nullptr; - UInt32 sz_desc = sizeof(EfiMemoryDescriptor); + UInt32 sz_desc = 0; UInt32 rev_desc = 0; #ifdef ZBA_USE_FB @@ -176,33 +176,52 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr image_handle, // format the disk. // ---------------------------------------------------- // - BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); + Boot::BootTextWriter writer; + + auto ret = BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); - struct_ptr = new EfiMemoryDescriptor[sz_desc]; + if (ret == kEfiFail) + { + writer.Write("BootZ: GetMemoryMap failed (x1)\r"); + Boot::Stop(); + } - BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); + size_struct_ptr += sz_desc * 2; + BS->AllocatePool(EfiMemoryType::EfiBootServicesData, size_struct_ptr, reinterpret_cast<VoidPtr*>(&struct_ptr)); - auto kDefaultMemoryMap = 0; // Grab any usable entries. + ret = BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); + + if (ret == kEfiFail) + { + writer.Write("BootZ: GetMemoryMap failed (x2)\r"); + Boot::Stop(); + } //-----------------------------------------------------------// // A simple loop which finds a usable memory region for us. //-----------------------------------------------------------// SizeT lookup_index = 0UL; + SizeT entry_count = size_struct_ptr / sz_desc; - for (; struct_ptr[lookup_index].Kind != EfiMemoryType::EfiConventionalMemory; ++lookup_index) + for (; lookup_index < entry_count; ++lookup_index) { - NE_UNUSED(0); + if (struct_ptr[lookup_index].Kind == EfiMemoryType::EfiConventionalMemory) + break; } - kDefaultMemoryMap = lookup_index; + if (lookup_index > entry_count) + { + writer.Write("BootZ: No usable entries.\r"); + Boot::Stop(); + } //-------------------------------------------------------------// // Update handover file specific table and phyiscal start field. //-------------------------------------------------------------// - handover_hdr->f_BitMapStart = (VoidPtr)struct_ptr[kDefaultMemoryMap].VirtualStart; /* Start of bitmap. */ - handover_hdr->f_BitMapSize = struct_ptr[kDefaultMemoryMap].NumberOfPages * sizeof(UIntPtr); /* Size of bitmap. */ + 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. */ handover_hdr->f_FirmwareCustomTables[0] = (VoidPtr)BS; handover_hdr->f_FirmwareCustomTables[1] = (VoidPtr)ST; @@ -287,8 +306,6 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr image_handle, ST->RuntimeServices->GetVariable(L"/props/kern_ver", kEfiGlobalNamespaceVarGUID, nullptr, &sz_ver, &ver); - Boot::BootTextWriter writer; - if (ver != KERNEL_VERSION_BCD) { ver = KERNEL_VERSION_BCD; |
