From 5ee6377080d9740d9fa74f4bff398c988865e2be Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Thu, 21 Dec 2023 22:57:11 +0100 Subject: [PATCH] Implement BlSetConsoleMode() and forcibly set mode to 80x25 to avoid offscreen --- xtldr2/console.c | 25 +++++++++++++++++++++++++ xtldr2/includes/bootman.h | 22 +++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/xtldr2/console.c b/xtldr2/console.c index 1e7a277..0703d8a 100644 --- a/xtldr2/console.c +++ b/xtldr2/console.c @@ -179,6 +179,23 @@ BlSetConsoleAttributes(IN ULONGLONG Attributes) EfiSystemTable->ConOut->SetAttribute(EfiSystemTable->ConOut, Attributes); } +/** + * Sets the output console device to the requested mode. + * + * @param Mode + * Supplies a text mode number to set. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlSetConsoleMode(IN ULONGLONG Mode) +{ + return EfiSystemTable->ConOut->SetMode(EfiSystemTable->ConOut, Mode); +} + /** * Sets new coordinates of the console cursor position. * @@ -238,6 +255,14 @@ BlpInitializeConsole() EfiSystemTable->ConOut->Reset(EfiSystemTable->ConOut, TRUE); EfiSystemTable->StdErr->Reset(EfiSystemTable->StdErr, TRUE); + /* Make sure that current console mode is 80x25 characters, as some broken EFI implementations might + * set different mode that do not fit on the screen, causing a text to be displayed offscreen */ + if(EfiSystemTable->ConOut->Mode->Mode != 0) + { + /* Set console mode to 0, which is standard, 80x25 text mode */ + BlSetConsoleMode(0); + } + /* Clear screen and enable cursor */ BlClearConsoleScreen(); BlEnableConsoleCursor(); diff --git a/xtldr2/includes/bootman.h b/xtldr2/includes/bootman.h index c08f963..e81566a 100644 --- a/xtldr2/includes/bootman.h +++ b/xtldr2/includes/bootman.h @@ -107,6 +107,15 @@ EFI_STATUS BlMemoryAllocatePool(IN UINT_PTR Size, OUT PVOID *Memory); +XTCDECL +EFI_STATUS +BlMemoryFreePages(IN UINT64 Pages, + IN EFI_PHYSICAL_ADDRESS Memory); + +XTCDECL +EFI_STATUS +BlMemoryFreePool(IN PVOID Memory); + XTCDECL EFI_STATUS BlOpenVolume(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath, @@ -133,15 +142,6 @@ XTCDECL VOID BlResetConsoleInputBuffer(); -XTCDECL -EFI_STATUS -BlMemoryFreePages(IN UINT64 Pages, - IN EFI_PHYSICAL_ADDRESS Memory); - -XTCDECL -EFI_STATUS -BlMemoryFreePool(IN PVOID Memory); - XTCDECL EFI_STATUS BlOpenXtProtocol(OUT PVOID *ProtocolHandler, @@ -156,6 +156,10 @@ XTCDECL VOID BlSetConsoleAttributes(IN ULONGLONG Attributes); +XTCDECL +EFI_STATUS +BlSetConsoleMode(IN ULONGLONG Mode); + XTCDECL VOID BlSetCursorPosition(IN ULONGLONG PosX,