I test the code on QEMU. My issue is whenever I press a key my program/system shutsdown immediately. Somehow I found a way to wait for a key and print a text but still I am doing it wrong. I want to re-wait for new keys unless that is "ESC" key. If key is esc program will exit. This is my first purpose. Second, if possible I want to print all characters when they are pressed.
Here is code:
Code: Select all
/*
* UEFI:SIMPLE - UEFI development made easy
* Copyright © 2014-2018 Pete Batard <[email protected]> - Public Domain
* See COPYING for the full licensing terms.
*/
#include <efi.h>
#include <efilib.h>
#include <stdio.h>
// Application entrypoint (must be set to 'efi_main' for gnu-efi crt0 compatibility)
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
UINTN Event;
#if defined(_GNU_EFI)
InitializeLib(ImageHandle, SystemTable);
#endif
/*
* In addition to the standard %-based flags, Print() supports the following:
* %N Set output attribute to normal
* %H Set output attribute to highlight
* %E Set output attribute to error
* %B Set output attribute to blue color
* %V Set output attribute to green color
* %r Human readable version of a status code
*/
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_BACKGROUND_MAGENTA); //SET BACK COLOR
Print(L"\n***DO NOT DISPLAY THIS***%N\n\n");
uefi_call_wrapper(SystemTable->ConOut->ClearScreen, 1, SystemTable->ConOut); //CLEAR SCREEN
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_YELLOW); //SET TEXT COLOR
Print(L"\n*** UEFI:HELLO MY FRIEND, bla bla and some other very necessary messages... ***%N\n\n");
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_RED); //SET TEXT COLOR
Print(L"PRESS ESC KEY TO EXIT.%N\n");
SystemTable->ConIn->Reset(SystemTable->ConIn, FALSE);
#if defined(_DEBUG)
// If running in debug mode, use the EFI shut down call to close QEMU
SystemTable->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
#endif
return EFI_SUCCESS;
}
I found methods but I do not know how to use them, at least it does not work for debug mode but works on release mode:
Code: Select all
SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &Event);
SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->ReadKeyStroke, &Event);
uefi_call_wrapper(SystemTable->ConOut->OutputString,1, SystemTable->ConOut , L"test\n");