From 645e5acebbce6eec2b996688cb5f796a258d5234 Mon Sep 17 00:00:00 2001 From: ESdove Date: Mon, 30 Nov 2020 16:50:49 +0800 Subject: [PATCH] DumpMemoryAttributesTable --- .../DumpMemoryAttributesTable.c | 111 ++++++++++++++++++ .../DumpMemoryAttributesTable.cif | 10 ++ .../DumpMemoryAttributesTable.inf | 34 ++++++ .../DumpMemoryAttributesTable.sdl | 17 +++ DumpToolPkg.cif | 11 ++ DumpToolPkg.dec | 22 ++++ DumpToolPkg.sdl | 8 ++ 7 files changed, 213 insertions(+) create mode 100644 DumpMemoryAttributesTable/DumpMemoryAttributesTable.c create mode 100644 DumpMemoryAttributesTable/DumpMemoryAttributesTable.cif create mode 100644 DumpMemoryAttributesTable/DumpMemoryAttributesTable.inf create mode 100644 DumpMemoryAttributesTable/DumpMemoryAttributesTable.sdl create mode 100644 DumpToolPkg.cif create mode 100644 DumpToolPkg.dec create mode 100644 DumpToolPkg.sdl diff --git a/DumpMemoryAttributesTable/DumpMemoryAttributesTable.c b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.c new file mode 100644 index 0000000..bb1629e --- /dev/null +++ b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +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; +} diff --git a/DumpMemoryAttributesTable/DumpMemoryAttributesTable.cif b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.cif new file mode 100644 index 0000000..d868342 --- /dev/null +++ b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.cif @@ -0,0 +1,10 @@ + + name = "DumpMemoryAttributesTable" + category = ModulePart + LocalRoot = "DumpToolPkg\DumpMemoryAttributesTable\" + RefName = "DumpMemoryAttributesTable" +[INF] +"DumpMemoryAttributesTable.inf" +[files] +"DumpMemoryAttributesTable.sdl" + diff --git a/DumpMemoryAttributesTable/DumpMemoryAttributesTable.inf b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.inf new file mode 100644 index 0000000..5d1a21d --- /dev/null +++ b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.inf @@ -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 \ No newline at end of file diff --git a/DumpMemoryAttributesTable/DumpMemoryAttributesTable.sdl b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.sdl new file mode 100644 index 0000000..6fb4003 --- /dev/null +++ b/DumpMemoryAttributesTable/DumpMemoryAttributesTable.sdl @@ -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 + diff --git a/DumpToolPkg.cif b/DumpToolPkg.cif new file mode 100644 index 0000000..5cc8000 --- /dev/null +++ b/DumpToolPkg.cif @@ -0,0 +1,11 @@ + + name = "DumpToolPkg" + category = Flavor + LocalRoot = "DumpToolPkg\" + RefName = "DumpToolPkg" +[files] +"DumpToolPkg.sdl" +"DumpToolPkg.dec" +[parts] +"DumpMemoryAttributesTable" + diff --git a/DumpToolPkg.dec b/DumpToolPkg.dec new file mode 100644 index 0000000..2d3a1a7 --- /dev/null +++ b/DumpToolPkg.dec @@ -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] diff --git a/DumpToolPkg.sdl b/DumpToolPkg.sdl new file mode 100644 index 0000000..34be726 --- /dev/null +++ b/DumpToolPkg.sdl @@ -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