Skip to content

Commit c2ea804

Browse files
committed
restore status details in efi ui
1 parent 4813d86 commit c2ea804

1 file changed

Lines changed: 101 additions & 4 deletions

File tree

efi/edk2/elfhvPkg/Boot/BootMenu.c

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <Library/BaseLib.h>
88
#include <Library/BaseMemoryLib.h>
99
#include <Library/PrintLib.h>
10+
#include <Library/DevicePathLib.h>
11+
#include <Protocol/LoadedImage.h>
1012
#include "Boot.h"
1113
#include "BootLog.h"
1214

@@ -383,18 +385,112 @@ static VOID UiDrawLogPanel(UINTN Left, UINTN Top, UINTN Width, UINTN Height, CON
383385
}
384386
}
385387

388+
static const CHAR16* UiMemTypeStr(EFI_MEMORY_TYPE Type) {
389+
switch (Type) {
390+
case EfiReservedMemoryType: return L"reserved";
391+
case EfiLoaderCode: return L"loader_code";
392+
case EfiLoaderData: return L"loader_data";
393+
case EfiBootServicesCode: return L"boot_code";
394+
case EfiBootServicesData: return L"boot_data";
395+
case EfiRuntimeServicesCode: return L"rt_code";
396+
case EfiRuntimeServicesData: return L"rt_data";
397+
case EfiConventionalMemory: return L"conventional";
398+
case EfiUnusableMemory: return L"unusable";
399+
case EfiACPIReclaimMemory: return L"acpi_reclaim";
400+
case EfiACPIMemoryNVS: return L"acpi_nvs";
401+
case EfiMemoryMappedIO: return L"mmio";
402+
case EfiMemoryMappedIOPortSpace: return L"mmio_port";
403+
case EfiPalCode: return L"pal";
404+
case EfiPersistentMemory: return L"persistent";
405+
default: return L"unknown";
406+
}
407+
}
408+
409+
static VOID UiDrawMemMap(UINTN Left, UINTN Top, UINTN Height) {
410+
UINTN mmap_size = 0;
411+
UINTN map_key = 0;
412+
UINTN desc_size = 0;
413+
UINT32 desc_version = 0;
414+
EFI_STATUS Status = gBS->GetMemoryMap(&mmap_size, NULL, &map_key, &desc_size, &desc_version);
415+
if (Status != EFI_BUFFER_TOO_SMALL || desc_size == 0) {
416+
UiPrintAt(Left + 2, Top, L"memory map unavailable");
417+
return;
418+
}
419+
420+
mmap_size += desc_size * 8;
421+
EFI_MEMORY_DESCRIPTOR* mmap = AllocatePool(mmap_size);
422+
if (!mmap) {
423+
UiPrintAt(Left + 2, Top, L"memory map alloc failed");
424+
return;
425+
}
426+
427+
Status = gBS->GetMemoryMap(&mmap_size, mmap, &map_key, &desc_size, &desc_version);
428+
if (EFI_ERROR(Status)) {
429+
FreePool(mmap);
430+
UiPrintAt(Left + 2, Top, L"memory map read failed: %r", Status);
431+
return;
432+
}
433+
434+
UINTN count = mmap_size / desc_size;
435+
UINTN show = (count > 5) ? 5 : count;
436+
UINTN start = (count > show) ? (count - show) : 0;
437+
UINTN row = Top;
438+
439+
UiPrintAt(Left + 2, row++, L"memory map (last %u of %u)", (UINT32)show, (UINT32)count);
440+
for (UINTN i = start; i < count && row < (Top + Height); ++i) {
441+
EFI_MEMORY_DESCRIPTOR* d = (EFI_MEMORY_DESCRIPTOR*)((UINT8*)mmap + (i * desc_size));
442+
UiPrintAt(Left + 2, row++, L"[%u] %-12s %08lx %08lx %016lx",
443+
(UINT32)i, UiMemTypeStr(d->Type),
444+
(UINT64)d->PhysicalStart,
445+
(UINT64)d->NumberOfPages,
446+
(UINT64)d->Attribute);
447+
}
448+
449+
FreePool(mmap);
450+
}
451+
386452
static VOID UiRenderStatus(UI_CONTEXT* Ctx, UINTN Left, UINTN Top, UINTN Width, UINTN Height) {
387453
UiDrawContentHeader(Left, Top, Width, L"status / diagnostics");
388454
UINTN row = Top + 3;
389455
CHAR16 vendor[16];
390456
AsciiToLowerUtf16(Ctx->Handoff->Vendor, vendor, 16);
391457

458+
EFI_LOADED_IMAGE_PROTOCOL* LoadedImage = NULL;
459+
CHAR16* file_path = NULL;
460+
if (!EFI_ERROR(gBS->HandleProtocol(Ctx->ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID**)&LoadedImage)) && LoadedImage) {
461+
file_path = ConvertDevicePathToText(LoadedImage->FilePath, TRUE, TRUE);
462+
}
463+
392464
UiPrintAt(Left + 2, row++, L"platform");
393465
UiPrintAt(Left + 4, row++, L"cpu vendor: %s", vendor);
394466
UiPrintAt(Left + 4, row++, L"virtualization: %s", (Ctx->Handoff->Features.Vmx || Ctx->Handoff->Features.Svm) ? L"supported" : L"unavailable");
395467
UiPrintAt(Left + 4, row++, L"ept support: %s", Ctx->Handoff->Features.Ept ? L"yes" : L"no");
396468
UiPrintAt(Left + 4, row++, L"npt support: %s", Ctx->Handoff->Features.Npt ? L"yes" : L"no");
397469

470+
row++;
471+
UiPrintAt(Left + 2, row++, L"loader image");
472+
if (LoadedImage) {
473+
UiPrintAt(Left + 4, row++, L"image handle: %p", Ctx->ImageHandle);
474+
UiPrintAt(Left + 4, row++, L"image base : %p", LoadedImage->ImageBase);
475+
UiPrintAt(Left + 4, row++, L"image size : 0x%lx", (UINT64)LoadedImage->ImageSize);
476+
UiPrintAt(Left + 4, row++, L"device : %p", LoadedImage->DeviceHandle);
477+
UiPrintAt(Left + 4, row++, L"file path : %s", file_path ? file_path : L"(unknown)");
478+
} else {
479+
UiPrintAt(Left + 4, row++, L"loaded image protocol unavailable");
480+
}
481+
482+
row++;
483+
UiPrintAt(Left + 2, row++, L"handoff");
484+
UiPrintAt(Left + 4, row++, L"handoff ptr : %p", Ctx->Handoff);
485+
UiPrintAt(Left + 4, row++, L"config ptr : %p", Ctx->Config);
486+
UiPrintAt(Left + 4, row++, L"features : vmx=%u ept=%u vpid=%u svm=%u npt=%u",
487+
(UINT32)Ctx->Handoff->Features.Vmx,
488+
(UINT32)Ctx->Handoff->Features.Ept,
489+
(UINT32)Ctx->Handoff->Features.Vpid,
490+
(UINT32)Ctx->Handoff->Features.Svm,
491+
(UINT32)Ctx->Handoff->Features.Npt);
492+
UiPrintAt(Left + 4, row++, L"cr3 (pml4) : 0x%llx", (UINT64)AsmReadCr3());
493+
398494
row++;
399495
UiPrintAt(Left + 2, row++, L"current config");
400496
UiPrintAt(Left + 4, row++, L"hypervisor: %s", Ctx->Config->EnableHv ? L"enabled" : L"disabled");
@@ -420,11 +516,12 @@ static VOID UiRenderStatus(UI_CONTEXT* Ctx, UINTN Left, UINTN Top, UINTN Width,
420516
UiPrintAt(Left + 4, row++, L"no previous boot status found");
421517
}
422518

423-
if (Height > 20) {
424-
UINTN log_top = Top + (Height > 10 ? (Height - 10) : (Top + row));
425-
if (log_top < row + 1) log_top = row + 1;
426-
UiDrawLogPanel(Left, log_top, Width, Height - (log_top - Top), L"boot log (latest)");
519+
row++;
520+
if (row + 6 < Top + Height) {
521+
UiDrawMemMap(Left, row, (Top + Height) - row);
427522
}
523+
524+
if (file_path) FreePool(file_path);
428525
}
429526

430527
static VOID UiRenderLogs(UI_CONTEXT* Ctx, UINTN Left, UINTN Top, UINTN Width, UINTN Height) {

0 commit comments

Comments
 (0)