From 9d7491c73211997681df0eed9607a0fd1528133d Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 3 Aug 2022 22:36:31 +0200 Subject: [PATCH] EFI default console support --- xtldr/CMakeLists.txt | 1 + xtldr/console.c | 75 +++++++++++++++++++++++++++++++++++++++++++ xtldr/includes/xtbl.h | 9 ++++++ xtldr/xtldr.c | 10 ++++++ 4 files changed, 95 insertions(+) create mode 100644 xtldr/console.c diff --git a/xtldr/CMakeLists.txt b/xtldr/CMakeLists.txt index 5aa7134..525ff1e 100644 --- a/xtldr/CMakeLists.txt +++ b/xtldr/CMakeLists.txt @@ -8,6 +8,7 @@ include_directories( # Specify list of source code files list(APPEND XTLDR_SOURCE + ${XTLDR_SOURCE_DIR}/console.c ${XTLDR_SOURCE_DIR}/xtldr.c) # Add executable diff --git a/xtldr/console.c b/xtldr/console.c new file mode 100644 index 0000000..7d7f9cc --- /dev/null +++ b/xtldr/console.c @@ -0,0 +1,75 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/console.c + * DESCRIPTION: EFI console support + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/** + * This routine clears the UEFI console screen. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +VOID +BlConsoleClearScreen() +{ + EfiSystemTable->ConOut->ClearScreen(EfiSystemTable->ConOut); +} + +/** + * This routine initializes the EFI console. + * + * @return This routine returns status code. + * + * @since XT 1.0 + */ +EFI_STATUS +BlConsoleInitialize() +{ + /* Check the console support */ + if(!EfiSystemTable->ConOut) + { + return STATUS_EFI_UNSUPPORTED; + } + + /* Clear console buffers */ + EfiSystemTable->ConIn->Reset(EfiSystemTable->ConIn, TRUE); + EfiSystemTable->ConOut->Reset(EfiSystemTable->ConOut, TRUE); + EfiSystemTable->StdErr->Reset(EfiSystemTable->StdErr, TRUE); + + /* Clear screen */ + BlConsoleClearScreen(); + + /* Enable cursor */ + EfiSystemTable->ConOut->EnableCursor(EfiSystemTable->ConOut, TRUE); + + /* Return success */ + return STATUS_EFI_SUCCESS; +} + +/** + * Writes a character to the default EFI console. + * + * @param Character + * The integer promotion of the character to be written. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +VOID +BlConsolePutChar(IN USHORT Character) +{ + USHORT Buffer[2]; + + /* Write character to the screen console */ + Buffer[0] = Character; + Buffer[1] = 0; + EfiSystemTable->ConOut->OutputString(EfiSystemTable->ConOut, Buffer); +} diff --git a/xtldr/includes/xtbl.h b/xtldr/includes/xtbl.h index d4fc6d2..32f5faa 100644 --- a/xtldr/includes/xtbl.h +++ b/xtldr/includes/xtbl.h @@ -18,6 +18,15 @@ EXTERN EFI_HANDLE EfiImageHandle; /* EFI System Table */ EXTERN EFI_SYSTEM_TABLE *EfiSystemTable; +VOID +BlConsoleClearScreen(); + +EFI_STATUS +BlConsoleInitialize(); + +VOID +BlConsolePutChar(IN USHORT Character); + EFI_STATUS XtLoaderStartup(IN EFI_HANDLE ImageHandle, IN PEFI_SYSTEM_TABLE SystemTable); diff --git a/xtldr/xtldr.c b/xtldr/xtldr.c index 9e2638f..53c4d8c 100644 --- a/xtldr/xtldr.c +++ b/xtldr/xtldr.c @@ -32,10 +32,20 @@ EFI_STATUS XtLoaderStartup(IN EFI_HANDLE ImageHandle, IN PEFI_SYSTEM_TABLE SystemTable) { + EFI_STATUS Status; + /* Set the system table and image handle */ EfiImageHandle = ImageHandle; EfiSystemTable = SystemTable; + /* Initialize EFI console */ + Status = BlConsoleInitialize(); + if(Status != STATUS_EFI_SUCCESS) { + /* TODO: Display error message on the serial console */ + /* Temporarily return error code */ + return STATUS_EFI_INCOMPATIBLE_VERSION; + } + /* Infinite bootloader loop */ for(;;);