mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
OcAppleBootCompatLib: Added free memory debugging
This commit is contained in:
parent
53ea852bc3
commit
af3b167177
@ -200,6 +200,18 @@ CountRuntimePages (
|
||||
OUT UINTN *DescriptorCount OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Calculate number of free pages in the memory map.
|
||||
|
||||
@param[out] LowerMemory Number of free pages below 4 GB, optional.
|
||||
|
||||
@retval Number of free pages.
|
||||
**/
|
||||
UINTN
|
||||
CountFreePages (
|
||||
OUT UINTN *LowerMemory OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Return pointer to PML4 table in PageTable and PWT and PCD flags in Flags.
|
||||
|
||||
|
||||
@ -101,12 +101,24 @@ OcAbcInitialize (
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
BOOT_COMPAT_CONTEXT *BootCompat;
|
||||
UINTN LowMemory;
|
||||
UINTN TotalMemory;
|
||||
|
||||
Status = InstallAbcProtocol ();
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
DEBUG_CODE_BEGIN ();
|
||||
TotalMemory = CountFreePages (&LowMemory);
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"OCABC: Firmware has %Lu free pages (%Lu in lower 4 GB)\n",
|
||||
(UINT64) TotalMemory,
|
||||
(UINT64) LowMemory
|
||||
));
|
||||
DEBUG_CODE_END ();
|
||||
|
||||
BootCompat = GetBootCompatContext ();
|
||||
|
||||
CopyMem (
|
||||
|
||||
@ -380,3 +380,51 @@ CountRuntimePages (
|
||||
|
||||
return PageNum;
|
||||
}
|
||||
|
||||
UINTN
|
||||
CountFreePages (
|
||||
OUT UINTN *LowerMemory OPTIONAL
|
||||
)
|
||||
{
|
||||
UINTN MemoryMapSize;
|
||||
UINTN DescriptorSize;
|
||||
EFI_MEMORY_DESCRIPTOR *MemoryMap;
|
||||
EFI_MEMORY_DESCRIPTOR *EntryWalker;
|
||||
UINTN FreePages;
|
||||
|
||||
FreePages = 0;
|
||||
if (LowerMemory != NULL) {
|
||||
*LowerMemory = 0;
|
||||
}
|
||||
|
||||
MemoryMap = GetCurrentMemoryMap (&MemoryMapSize, &DescriptorSize, NULL, NULL);
|
||||
if (MemoryMap == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (
|
||||
EntryWalker = MemoryMap;
|
||||
(UINT8 *) EntryWalker < ((UINT8 *) MemoryMap + MemoryMapSize);
|
||||
EntryWalker = NEXT_MEMORY_DESCRIPTOR (EntryWalker, DescriptorSize)) {
|
||||
|
||||
if (EntryWalker->Type != EfiConventionalMemory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FreePages += EntryWalker->NumberOfPages;
|
||||
|
||||
if (LowerMemory == NULL || EntryWalker->PhysicalStart >= BASE_4GB) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (EntryWalker->PhysicalStart + EFI_PAGES_TO_SIZE (EntryWalker->NumberOfPages) > BASE_4GB) {
|
||||
*LowerMemory += EFI_SIZE_TO_PAGES (BASE_4GB - EntryWalker->PhysicalStart);
|
||||
} else {
|
||||
*LowerMemory += EntryWalker->NumberOfPages;
|
||||
}
|
||||
}
|
||||
|
||||
FreePool (MemoryMap);
|
||||
|
||||
return FreePages;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user