Skip to content

Commit

Permalink
DumpMemoryAttributesTable
Browse files Browse the repository at this point in the history
  • Loading branch information
ESdove committed Nov 30, 2020
1 parent 064cb7c commit 645e5ac
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
111 changes: 111 additions & 0 deletions DumpMemoryAttributesTable/DumpMemoryAttributesTable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <AmiDxeLib.h>
#include <PiDxe.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>

#include <Guid/MemoryAttributesTable.h>

CHAR16 *mMemoryTypeShortName[] = {
L"Reserved",
L"LoaderCode",
L"LoaderData",
L"BS_Code",
L"BS_Data",
L"RT_Code",
L"RT_Data",
L"Available",
L"Unusable",
L"ACPI_Recl",
L"ACPI_NVS",
L"MMIO",
L"MMIO_Port",
L"PalCode",
L"Persistent",
};

CHAR16 mUnknownStr[11];

CHAR16 *
ShortNameOfMemoryType(
IN UINT32 Type
)
{
if (Type < sizeof(mMemoryTypeShortName) / sizeof(mMemoryTypeShortName[0])) {
return mMemoryTypeShortName[Type];
} else {
UnicodeSPrint(mUnknownStr, sizeof(mUnknownStr), L"%08x", Type);
return mUnknownStr;
}
}


VOID
DumpMemoryAttributesTable (
IN EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable
)
{
UINTN Index;
EFI_MEMORY_DESCRIPTOR *Entry;
UINT64 RTDataPages;
UINT64 RTCodePages;

RTDataPages = 0;
RTCodePages = 0;


Print (L"MemoryAttributesTable - %016LX\n", MemoryAttributesTable);
Print (L"Version - 0x%08x\n", MemoryAttributesTable->Version);
Print (L"NumberOfEntries - 0x%08x\n", MemoryAttributesTable->NumberOfEntries);
Print (L"DescriptorSize - 0x%08x\n", MemoryAttributesTable->DescriptorSize);
Print (L"\n");
Entry = (EFI_MEMORY_DESCRIPTOR *)(MemoryAttributesTable + 1);
Print (L"Type Start End # Pages Attributes\n");
for (Index = 0; Index < MemoryAttributesTable->NumberOfEntries; Index++) {
Print(L"% -10s %016LX-%016LX %016LX %016LX\n",
ShortNameOfMemoryType(Entry->Type),
Entry->PhysicalStart,
Entry->PhysicalStart + EFI_PAGES_TO_SIZE((UINTN)Entry->NumberOfPages) - 1,
Entry->NumberOfPages,
Entry->Attribute
);
switch (Entry->Type) {
case EfiRuntimeServicesCode:
RTCodePages += Entry->NumberOfPages;
break;
case EfiRuntimeServicesData:
RTDataPages += Entry->NumberOfPages;
break;
default:
break;
}
Entry = NEXT_MEMORY_DESCRIPTOR (Entry, MemoryAttributesTable->DescriptorSize);
}

Print (L"\n");
Print (L" RT_Code : %,16ld Pages (%,ld Bytes)\n", RTCodePages, MultU64x64(SIZE_4KB, RTCodePages));
Print (L" RT_Data : %,16ld Pages (%,ld Bytes)\n", RTDataPages, MultU64x64(SIZE_4KB, RTDataPages));

}

EFI_STATUS
EFIAPI
DumpMemoryAttributesTableEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
VOID *MemoryAttributesTable;

Status = EfiGetSystemConfigurationTable (&gEfiMemoryAttributesTableGuid, &MemoryAttributesTable);
if (!EFI_ERROR (Status)) {
DumpMemoryAttributesTable(MemoryAttributesTable);
}

return EFI_SUCCESS;
}
10 changes: 10 additions & 0 deletions DumpMemoryAttributesTable/DumpMemoryAttributesTable.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<component>
name = "DumpMemoryAttributesTable"
category = ModulePart
LocalRoot = "DumpToolPkg\DumpMemoryAttributesTable\"
RefName = "DumpMemoryAttributesTable"
[INF]
"DumpMemoryAttributesTable.inf"
[files]
"DumpMemoryAttributesTable.sdl"
<endComponent>
34 changes: 34 additions & 0 deletions DumpMemoryAttributesTable/DumpMemoryAttributesTable.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[Defines]
INF_VERSION = 0x00010015
VERSION_STRING = 1.0
BASE_NAME = DumpMemoryAttributesTable
MODULE_TYPE = UEFI_APPLICATION
FILE_GUID = 57d203e7-4fdb-472e-9c1b-a60a02da8c7f
ENTRY_POINT = DumpMemoryAttributesTableEntryPoint

[Sources]
DumpMemoryAttributesTable.c

[Packages]
MdePkg/MdePkg.dec
AmiCompatibilityPkg/AmiCompatibilityPkg.dec
AmiModulePkg/AmiModulePkg.dec
DumpToolPkg/DumpToolPkg.dec
AmiTsePkg/AmiTsePkg.dec

[LibraryClasses]
UefiApplicationEntryPoint
UefiBootServicesTableLib
AmiDxeLib
UefiLib
DebugLib
MemoryAllocationLib
BaseMemoryLib
PrintLib
BaseLib

[Guids]
gEfiMemoryAttributesTableGuid

[Depex]
TRUE
17 changes: 17 additions & 0 deletions DumpMemoryAttributesTable/DumpMemoryAttributesTable.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
TOKEN
Name = "DumpMemoryAttributesTable_INF_SUPPORT"
Value = "1"
Help = "Main switch to enable DumpMemoryAttributesTable support in Project"
TokenType = Boolean
TargetMAK = Yes
Master = Yes
End

INFComponent
Name = "DumpMemoryAttributesTable"
File = "DumpMemoryAttributesTable.inf"
Package = "DumpMemoryAttributesTable"
ModuleTypes = "UEFI_APPLICATION"
Token = "DumpMemoryAttributesTable_INF_SUPPORT" "=" "1"
End

11 changes: 11 additions & 0 deletions DumpToolPkg.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component>
name = "DumpToolPkg"
category = Flavor
LocalRoot = "DumpToolPkg\"
RefName = "DumpToolPkg"
[files]
"DumpToolPkg.sdl"
"DumpToolPkg.dec"
[parts]
"DumpMemoryAttributesTable"
<endComponent>
22 changes: 22 additions & 0 deletions DumpToolPkg.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[Defines]
DEC_SPECIFICATION = 0x00010005
PACKAGE_NAME = DumpToolPkg
PACKAGE_GUID = 9C52A38A-5BF4-4af8-BB04-2F85C4EFDD06
PACKAGE_VERSION = 0.1


[Includes]


[LibraryClasses]


[Protocols]


[Ppis]


[Guids]

[PcdsFixedAtBuild]
8 changes: 8 additions & 0 deletions DumpToolPkg.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TOKEN
Name = "DumpToolPkg_SUPPORT"
Value = "1"
Help = "Main switch to enable DumpToolPkg support in Project"
TokenType = Boolean
TargetMAK = Yes
Master = Yes
End

0 comments on commit 645e5ac

Please sign in to comment.