You've already forked slimbootloader
mirror of
https://github.com/Dasharo/slimbootloader.git
synced 2026-03-06 15:26:20 -08:00
134 lines
2.7 KiB
C
134 lines
2.7 KiB
C
/** @file
|
|
Shell command `mmap` to display the memory map.
|
|
|
|
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
|
This program and the accompanying materials
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
http://opensource.org/licenses/bsd-license.php.
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
**/
|
|
|
|
#include <Library/ShellLib.h>
|
|
#include <Library/HobLib.h>
|
|
#include <Guid/MemoryMapInfoGuid.h>
|
|
#include <Library/DebugLib.h>
|
|
|
|
/**
|
|
Display memory map.
|
|
|
|
@param[in] Shell shell instance
|
|
@param[in] Argc number of command line arguments
|
|
@param[in] Argv command line arguments
|
|
|
|
@retval EFI_SUCCESS
|
|
|
|
**/
|
|
STATIC
|
|
EFI_STATUS
|
|
EFIAPI
|
|
ShellCommandMmapFunc (
|
|
IN SHELL *Shell,
|
|
IN UINTN Argc,
|
|
IN CHAR16 *Argv[]
|
|
);
|
|
|
|
CONST SHELL_COMMAND ShellCommandMmap = {
|
|
L"mmap",
|
|
L"Display memory map",
|
|
&ShellCommandMmapFunc
|
|
};
|
|
|
|
/**
|
|
Get string description of memory type.
|
|
|
|
@param[in] Type Numeric memory type
|
|
|
|
@retval Type string
|
|
|
|
**/
|
|
STATIC
|
|
CONST CHAR16 *
|
|
EFIAPI
|
|
MemTypeToStr (
|
|
IN UINTN Type
|
|
)
|
|
{
|
|
switch (Type) {
|
|
case 0x01:
|
|
return L"System Memory";
|
|
case 0x02:
|
|
return L"Reserved";
|
|
case 0x03:
|
|
return L"ACPI NVS";
|
|
case 0x04:
|
|
return L"ACPI Reclaim";
|
|
default:
|
|
return L"Unknown";
|
|
}
|
|
}
|
|
|
|
/**
|
|
Get string description of MTRR type.
|
|
|
|
@param[in] Type Numeric MTRR type
|
|
|
|
@retval Memory Map Info pointer
|
|
|
|
**/
|
|
STATIC
|
|
MEMORY_MAP_INFO *
|
|
EFIAPI
|
|
GetMemoryMapInfo (
|
|
VOID
|
|
)
|
|
{
|
|
EFI_HOB_GUID_TYPE *GuidHob;
|
|
|
|
GuidHob = GetNextGuidHob (&gLoaderMemoryMapInfoGuid, GetHobList());
|
|
if (GuidHob == NULL) {
|
|
ASSERT (GuidHob);
|
|
return NULL;
|
|
}
|
|
|
|
return (MEMORY_MAP_INFO *)GET_GUID_HOB_DATA (GuidHob);
|
|
}
|
|
|
|
/**
|
|
Display memory map.
|
|
|
|
@param[in] Shell shell instance
|
|
@param[in] Argc number of command line arguments
|
|
@param[in] Argv command line arguments
|
|
|
|
@retval EFI_SUCCESS
|
|
|
|
**/
|
|
STATIC
|
|
EFI_STATUS
|
|
EFIAPI
|
|
ShellCommandMmapFunc (
|
|
IN SHELL *Shell,
|
|
IN UINTN Argc,
|
|
IN CHAR16 *Argv[]
|
|
)
|
|
{
|
|
UINT32 Index;
|
|
MEMORY_MAP_INFO *MemoryMapInfo;
|
|
|
|
MemoryMapInfo = GetMemoryMapInfo();
|
|
ASSERT (MemoryMapInfo != NULL);
|
|
|
|
for (Index = 0; Index < MemoryMapInfo->Count; Index++) {
|
|
ShellPrint (L"[0x%09llx-0x%09llx] %s\n",
|
|
MemoryMapInfo->Entry[Index].Base,
|
|
MemoryMapInfo->Entry[Index].Base + MemoryMapInfo->Entry[Index].Size - 1,
|
|
MemTypeToStr (MemoryMapInfo->Entry[Index].Type));
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
}
|