loader.efi: update memmap command to recognize new attributes

Also move memory type to string translation to libefi for later use.

MFC after:	2 weeks
This commit is contained in:
Toomas Soome 2019-01-03 09:03:58 +00:00
parent d42e525cbc
commit 34ada20958
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=342721
4 changed files with 72 additions and 29 deletions

View File

@ -157,23 +157,27 @@ typedef enum {
EfiMemoryMappedIO,
EfiMemoryMappedIOPortSpace,
EfiPalCode,
EfiPersistentMemory,
EfiMaxMemoryType
} EFI_MEMORY_TYPE;
// possible caching types for the memory range
#define EFI_MEMORY_UC 0x0000000000000001
#define EFI_MEMORY_WC 0x0000000000000002
#define EFI_MEMORY_WT 0x0000000000000004
#define EFI_MEMORY_WB 0x0000000000000008
#define EFI_MEMORY_UCE 0x0000000000000010
#define EFI_MEMORY_UC 0x0000000000000001
#define EFI_MEMORY_WC 0x0000000000000002
#define EFI_MEMORY_WT 0x0000000000000004
#define EFI_MEMORY_WB 0x0000000000000008
#define EFI_MEMORY_UCE 0x0000000000000010
// physical memory protection on range
#define EFI_MEMORY_WP 0x0000000000001000
#define EFI_MEMORY_RP 0x0000000000002000
#define EFI_MEMORY_XP 0x0000000000004000
#define EFI_MEMORY_WP 0x0000000000001000
#define EFI_MEMORY_RP 0x0000000000002000
#define EFI_MEMORY_XP 0x0000000000004000
#define EFI_MEMORY_NV 0x0000000000008000
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000
#define EFI_MEMORY_RO 0x0000000000020000
// range requires a runtime mapping
#define EFI_MEMORY_RUNTIME 0x8000000000000000
#define EFI_MEMORY_RUNTIME 0x8000000000000000
#define EFI_MEMORY_DESCRIPTOR_VERSION 1
typedef struct {

View File

@ -108,6 +108,9 @@ void delay(int usecs);
/* EFI environment initialization. */
void efi_init_environment(void);
/* EFI Memory type strings. */
const char *efi_memory_type(EFI_MEMORY_TYPE);
/* CHAR16 utility functions. */
int wcscmp(CHAR16 *, CHAR16 *);
void cpy8to16(const char *, CHAR16 *, size_t);

View File

@ -47,6 +47,49 @@ efi_init_environment(void)
COMMAND_SET(efishow, "efi-show", "print some or all EFI variables", command_efi_show);
const char *
efi_memory_type(EFI_MEMORY_TYPE type)
{
const char *types[] = {
"Reserved",
"LoaderCode",
"LoaderData",
"BootServicesCode",
"BootServicesData",
"RuntimeServicesCode",
"RuntimeServicesData",
"ConventionalMemory",
"UnusableMemory",
"ACPIReclaimMemory",
"ACPIMemoryNVS",
"MemoryMappedIO",
"MemoryMappedIOPortSpace",
"PalCode",
"PersistentMemory"
};
switch (type) {
case EfiReservedMemoryType:
case EfiLoaderCode:
case EfiLoaderData:
case EfiBootServicesCode:
case EfiBootServicesData:
case EfiRuntimeServicesCode:
case EfiRuntimeServicesData:
case EfiConventionalMemory:
case EfiUnusableMemory:
case EfiACPIReclaimMemory:
case EfiACPIMemoryNVS:
case EfiMemoryMappedIO:
case EfiMemoryMappedIOPortSpace:
case EfiPalCode:
case EfiPersistentMemory:
return (types[type]);
default:
return ("Unknown");
}
}
static int
efi_print_var(CHAR16 *varnamearg, EFI_GUID *matchguid, int lflag)
{

View File

@ -1041,7 +1041,7 @@ command_quit(int argc, char *argv[])
COMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
static int
command_memmap(int argc, char *argv[])
command_memmap(int argc __unused, char *argv[] __unused)
{
UINTN sz;
EFI_MEMORY_DESCRIPTOR *map, *p;
@ -1050,22 +1050,6 @@ command_memmap(int argc, char *argv[])
EFI_STATUS status;
int i, ndesc;
char line[80];
static char *types[] = {
"Reserved",
"LoaderCode",
"LoaderData",
"BootServicesCode",
"BootServicesData",
"RuntimeServicesCode",
"RuntimeServicesData",
"ConventionalMemory",
"UnusableMemory",
"ACPIReclaimMemory",
"ACPIMemoryNVS",
"MemoryMappedIO",
"MemoryMappedIOPortSpace",
"PalCode"
};
sz = 0;
status = BS->GetMemoryMap(&sz, 0, &key, &dsz, &dver);
@ -1091,9 +1075,12 @@ command_memmap(int argc, char *argv[])
for (i = 0, p = map; i < ndesc;
i++, p = NextMemoryDescriptor(p, dsz)) {
printf("%23s %012jx %012jx %08jx ", types[p->Type],
(uintmax_t)p->PhysicalStart, (uintmax_t)p->VirtualStart,
(uintmax_t)p->NumberOfPages);
snprintf(line, sizeof(line), "%23s %012jx %012jx %08jx ",
efi_memory_type(p->Type), (uintmax_t)p->PhysicalStart,
(uintmax_t)p->VirtualStart, (uintmax_t)p->NumberOfPages);
if (pager_output(line))
break;
if (p->Attribute & EFI_MEMORY_UC)
printf("UC ");
if (p->Attribute & EFI_MEMORY_WC)
@ -1110,6 +1097,12 @@ command_memmap(int argc, char *argv[])
printf("RP ");
if (p->Attribute & EFI_MEMORY_XP)
printf("XP ");
if (p->Attribute & EFI_MEMORY_NV)
printf("NV ");
if (p->Attribute & EFI_MEMORY_MORE_RELIABLE)
printf("MR ");
if (p->Attribute & EFI_MEMORY_RO)
printf("RO ");
if (pager_output("\n"))
break;
}