From b718310205436a546a8b554e3aed58c1256cf2ea Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 2 Mar 2022 15:15:22 +0100 Subject: [PATCH] readline: Unify getchar() impl for UEFI and BIOS --- common/lib/readline.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/common/lib/readline.c b/common/lib/readline.c index a94a6898..cd621bd4 100644 --- a/common/lib/readline.c +++ b/common/lib/readline.c @@ -13,6 +13,15 @@ #include #include +int getchar(void) { + for (;;) { + int ret = pit_sleep_and_quit_on_keypress(65535); + if (ret != 0) { + return ret; + } + } +} + int getchar_internal(uint8_t scancode, uint8_t ascii, uint32_t shift_state) { switch (scancode) { #if bios == 1 @@ -90,15 +99,6 @@ int getchar_internal(uint8_t scancode, uint8_t ascii, uint32_t shift_state) { } #if bios == 1 -int getchar(void) { - for (;;) { - int ret = pit_sleep_and_quit_on_keypress(65535); - if (ret != 0) { - return ret; - } - } -} - int _pit_sleep_and_quit_on_keypress(uint32_t ticks); static int input_sequence(void) { @@ -154,6 +154,10 @@ static int input_sequence(void) { } int pit_sleep_and_quit_on_keypress(int seconds) { + if (!serial) { + return _pit_sleep_and_quit_on_keypress(seconds * 18); + } + for (int i = 0; i < seconds * 18; i++) { int ret = _pit_sleep_and_quit_on_keypress(1); @@ -161,10 +165,6 @@ int pit_sleep_and_quit_on_keypress(int seconds) { return ret; } - if (!serial) { - continue; - } - ret = serial_in(); if (ret != -1) { @@ -249,15 +249,6 @@ static int input_sequence(bool ext, return 0; } -int getchar(void) { - for (;;) { - int ret = pit_sleep_and_quit_on_keypress(65535); - if (ret != 0) { - return ret; - } - } -} - int pit_sleep_and_quit_on_keypress(int seconds) { EFI_KEY_DATA kd;