[FREELDR] Add UEFI Console input support. CORE-11954 (#5426)

Co-authored-by: Stanislav Motylkov <x86corez@gmail.com>
This commit is contained in:
Justin Miller 2023-07-11 11:07:31 -07:00 committed by GitHub
parent d144f3d3bb
commit e505394466
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 12 deletions

View file

@ -55,18 +55,6 @@ UefiPcBeep(VOID)
/* Not possible on UEFI, for now */ /* Not possible on UEFI, for now */
} }
BOOLEAN
UefiConsKbHit(VOID)
{
return FALSE;
}
int
UefiConsGetCh(void)
{
return 0;
}
VOID VOID
UefiHwIdle(VOID) UefiHwIdle(VOID)
{ {

View file

@ -16,6 +16,9 @@ extern EFI_SYSTEM_TABLE* GlobalSystemTable;
static unsigned CurrentCursorX = 0; static unsigned CurrentCursorX = 0;
static unsigned CurrentCursorY = 0; static unsigned CurrentCursorY = 0;
static unsigned CurrentAttr = 0x0f; static unsigned CurrentAttr = 0x0f;
static EFI_INPUT_KEY Key;
static BOOLEAN ExtendedKey = FALSE;
static char ExtendedScanCode = 0;
/* FUNCTIONS ******************************************************************/ /* FUNCTIONS ******************************************************************/
@ -59,3 +62,82 @@ UefiConsPutChar(int c)
CurrentCursorY++; CurrentCursorY++;
} }
} }
static
UCHAR
ConvertToBiosExtValue(UCHAR KeyIn)
{
switch (KeyIn)
{
case SCAN_UP:
return KEY_UP;
case SCAN_DOWN:
return KEY_DOWN;
case SCAN_RIGHT:
return KEY_RIGHT;
case SCAN_LEFT:
return KEY_LEFT;
case SCAN_F1:
return KEY_F1;
case SCAN_F2:
return KEY_F2;
case SCAN_F3:
return KEY_F3;
case SCAN_F4:
return KEY_F4;
case SCAN_F5:
return KEY_F5;
case SCAN_F6:
return KEY_F6;
case SCAN_F7:
return KEY_F7;
case SCAN_F8:
return KEY_F8;
case SCAN_F9:
return KEY_F9;
case SCAN_F10:
return KEY_F10;
case SCAN_ESC:
return KEY_ESC;
case SCAN_DELETE:
return KEY_DELETE;
}
return 0;
}
BOOLEAN
UefiConsKbHit(VOID)
{
return (GlobalSystemTable->ConIn->ReadKeyStroke(GlobalSystemTable->ConIn, &Key) != EFI_NOT_READY);
}
int
UefiConsGetCh(VOID)
{
UCHAR KeyOutput = 0;
/* If an extended key press was detected the last time we were called
* then return the scan code of that key. */
if (ExtendedKey)
{
ExtendedKey = FALSE;
return ExtendedScanCode;
}
if (Key.UnicodeChar != 0)
{
KeyOutput = Key.UnicodeChar;
}
else
{
ExtendedKey = TRUE;
ExtendedScanCode = ConvertToBiosExtValue(Key.ScanCode);
KeyOutput = KEY_EXTENDED;
}
/* UEFI will stack input requests, we have to clear it */
Key.UnicodeChar = 0;
Key.ScanCode = 0;
GlobalSystemTable->ConIn->Reset(GlobalSystemTable->ConIn, FALSE);
return KeyOutput;
}