Skip to content

Commit

Permalink
print memory map for log
Browse files Browse the repository at this point in the history
Signed-off-by: Slice <[email protected]>
  • Loading branch information
SergeySlice committed Nov 9, 2023
1 parent 2d5f73c commit d512413
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion rEFIt_UEFI/refit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@

// variables

EFI_PHYSICAL_ADDRESS SomePages = EFI_SYSTEM_TABLE_MAX_ADDRESS; //0xFE000000;?

XBool gGuiIsReady = false;
XBool gThemeNeedInit = true;
XBool DoHibernateWake = false;
Expand All @@ -136,6 +138,51 @@ extern EFI_AUDIO_IO_PROTOCOL *AudioIo;
extern EFI_DXE_SERVICES *gDS;


VOID
PrintMemoryMap ()
{
EFI_MEMORY_DESCRIPTOR *MemMap;
EFI_MEMORY_DESCRIPTOR *MemMapPtr;
UINTN MemMapSize;
UINTN MapKey, DescriptorSize;
UINT32 DescriptorVersion;
UINT64 Bytes;
EFI_STATUS Status;

MemMapSize = 0;
MemMap = NULL;
DescriptorSize = 0;
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
// ASSERT (Status == EFI_BUFFER_TOO_SMALL);
MemMapSize += EFI_PAGE_SIZE;
if (Status != EFI_BUFFER_TOO_SMALL) {
DBG("GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
}
Status = gBS->AllocatePool (EfiBootServicesData, MemMapSize, (void**)&MemMap);
// ASSERT (Status == EFI_SUCCESS);
if (EFI_ERROR(Status)) return;
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
// ASSERT (Status == EFI_SUCCESS);
MemMapPtr = MemMap;
DBG("GetMemStatus=%s\n", efiStrError(Status));
// ASSERT (DescriptorVersion == EFI_MEMORY_DESCRIPTOR_VERSION);

for (UINTN Index = 0; Index < MemMapSize / DescriptorSize; Index ++) {
Bytes = LShiftU64 (MemMap->NumberOfPages, 12);
DBG ("%016llX-%016llX %08llX %02llX %02llX\n",
MemMap->PhysicalStart,
MemMap->PhysicalStart + Bytes - 1,
MemMap->NumberOfPages,
MemMap->Attribute,
(UINTN)MemMap->Type);
MemMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemMap + DescriptorSize);
}

gBS->FreePool(MemMapPtr);
}



static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
IN CONST XStringW& ImageTitle,
OUT UINTN *ErrorInStep,
Expand Down Expand Up @@ -1612,6 +1659,10 @@ void LOADER_ENTRY::StartLoader()
mOpenCoreConfiguration.Kernel.Quirks.XhciPortLimit,
mOpenCoreConfiguration.Kernel.Quirks.ProvideCurrentCpuInfo);


// EFI_STATUS sta = gBS->FreePages(SomePages, 90000);
// DBG("free 90000 pages status=%s\n", efiStrError(sta));
PrintMemoryMap();
DBG("Closing log\n");
if (SavePreBootLog) {
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG);
Expand Down Expand Up @@ -2274,7 +2325,7 @@ INTN FindDefaultEntry(void)
//
// try to detect volume set by Startup Disk or previous Clover selection
// with broken nvram this requires emulation to be installed.
// enable emulation to determin efi-boot-device-data
// enable emulation to determine efi-boot-device-data
if (gEmuVariableControl != NULL) {
gEmuVariableControl->InstallEmulation(gEmuVariableControl);
}
Expand Down Expand Up @@ -2903,6 +2954,8 @@ RefitMain (IN EFI_HANDLE ImageHandle,

// DumpBiosMemoryMap();

// PrintMemoryMap();

GuiEventsInitialize();

//DBG("ScanSPD() start\n");
Expand Down

0 comments on commit d512413

Please sign in to comment.