Fix keyboard stuff
diff --git a/stage23/Makefile b/stage23/Makefile
index 72d8d2f7..5f928a0a 100644
--- a/stage23/Makefile
+++ b/stage23/Makefile
@@ -125,7 +125,7 @@ limine_efi.elf: $(OBJ) font.o sys/smp_trampoline.o
-T../gnu-efi/gnuefi/elf_x86_64_efi.lds \
../gnu-efi/x86_64/gnuefi/crt0-efi-x86_64.o \
../gnu-efi/x86_64/gnuefi/libgnuefi.a \
- ../gnu-efi/lib/x86_64/efi_stub.o \
+ ../gnu-efi/x86_64/lib/x86_64/efi_stub.o \
$(OBJ) font.o sys/smp_trampoline.o -o $@
-include $(HEADER_DEPS)
diff --git a/stage23/drivers/gop.c b/stage23/drivers/gop.c
index c81156c8..7d1974b0 100644
--- a/stage23/drivers/gop.c
+++ b/stage23/drivers/gop.c
@@ -19,7 +19,8 @@ bool init_gop(struct fb_info *ret,
uefi_call_wrapper(gBS->LocateProtocol, 3, &gop_guid, NULL, (void **)&gop);
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
- UINTN mode_info_size, native_mode, modes_count;
+ UINTN mode_info_size;
+ //UINTN native_mode, modes_count;
status = uefi_call_wrapper(gop->QueryMode, 4, gop,
gop->Mode == NULL ? 0 : gop->Mode->Mode,
diff --git a/stage23/lib/blib.h b/stage23/lib/blib.h
index 9501947a..ad55a5d1 100644
--- a/stage23/lib/blib.h
+++ b/stage23/lib/blib.h
@@ -32,7 +32,7 @@ uint8_t bcd_to_int(uint8_t val);
__attribute__((noreturn)) void panic(const char *fmt, ...);
-int pit_sleep_and_quit_on_keypress(uint32_t pit_ticks);
+int pit_sleep_and_quit_on_keypress(int seconds);
uint64_t strtoui(const char *s, const char **end, int base);
diff --git a/stage23/lib/readline.c b/stage23/lib/readline.c
index 8b7b5a6d..a9b9116c 100644
--- a/stage23/lib/readline.c
+++ b/stage23/lib/readline.c
@@ -12,6 +12,7 @@
int getchar_internal(uint8_t scancode, uint8_t ascii) {
switch (scancode) {
+#if defined (bios)
case 0x44:
return GETCHAR_F10;
case 0x4b:
@@ -32,6 +33,30 @@ int getchar_internal(uint8_t scancode, uint8_t ascii) {
return GETCHAR_PGUP;
case 0x51:
return GETCHAR_PGDOWN;
+#elif defined (uefi)
+ case SCAN_F10:
+ return GETCHAR_F10;
+ case SCAN_LEFT:
+ return GETCHAR_CURSOR_LEFT;
+ case SCAN_RIGHT:
+ return GETCHAR_CURSOR_RIGHT;
+ case SCAN_UP:
+ return GETCHAR_CURSOR_UP;
+ case SCAN_DOWN:
+ return GETCHAR_CURSOR_DOWN;
+ case SCAN_DELETE:
+ return GETCHAR_DELETE;
+ case SCAN_END:
+ return GETCHAR_END;
+ case SCAN_HOME:
+ return GETCHAR_HOME;
+ case SCAN_PAGE_UP:
+ return GETCHAR_PGUP;
+ case SCAN_PAGE_DOWN:
+ return GETCHAR_PGDOWN;
+ case SCAN_ESC:
+ return '\e';
+#endif
}
switch (ascii) {
case '\r':
@@ -46,18 +71,52 @@ int getchar(void) {
rm_int(0x16, &r, &r);
return getchar_internal((r.eax >> 8) & 0xff, r.eax);
}
+
+int _pit_sleep_and_quit_on_keypress(uint32_t ticks);
+
+int pit_sleep_and_quit_on_keypress(int seconds) {
+ return _pit_sleep_and_quit_on_keypress(seconds * 18);
+}
#endif
#if defined (uefi)
int getchar(void) {
EFI_INPUT_KEY key = {0};
+
+ UINTN which;
+
+ uefi_call_wrapper(
+ gBS->WaitForEvent, 3, 1, (EFI_EVENT[]){ gST->ConIn->WaitForKey }, &which);
+
uefi_call_wrapper(gST->ConIn->ReadKeyStroke, 2, gST->ConIn, &key);
+
return getchar_internal(key.ScanCode, key.UnicodeChar);
}
-int pit_sleep_and_quit_on_keypress(uint32_t pit_ticks) {
- (void)pit_ticks;
- return getchar();
+int pit_sleep_and_quit_on_keypress(int seconds) {
+ EFI_INPUT_KEY key = {0};
+
+ UINTN which;
+
+ EFI_EVENT events[2];
+
+ events[0] = gST->ConIn->WaitForKey;
+
+ uefi_call_wrapper(
+ gBS->CreateEvent, 5, EVT_TIMER, TPL_CALLBACK, NULL, NULL, &events[1]);
+
+ uefi_call_wrapper(
+ gBS->SetTimer, 3, events[1], TimerRelative, 10000000 * seconds);
+
+ uefi_call_wrapper(gBS->WaitForEvent, 3, 2, events, &which);
+
+ if (which == 1) {
+ return 0;
+ }
+
+ uefi_call_wrapper(gST->ConIn->ReadKeyStroke, 2, gST->ConIn, &key);
+
+ return getchar_internal(key.ScanCode, key.UnicodeChar);
}
#endif
diff --git a/stage23/lib/sleep.asm b/stage23/lib/sleep.asm
index 3ba4ed01..470a429b 100644
--- a/stage23/lib/sleep.asm
+++ b/stage23/lib/sleep.asm
@@ -13,8 +13,8 @@ int_08_isr:
extern getchar_internal
-global pit_sleep_and_quit_on_keypress
-pit_sleep_and_quit_on_keypress:
+global _pit_sleep_and_quit_on_keypress
+_pit_sleep_and_quit_on_keypress:
; Hook int 0x08
mov edx, dword [0x08*4]
mov dword [int_08_callback], edx
diff --git a/stage23/menu.c b/stage23/menu.c
index 51c12455..608ae4a8 100644
--- a/stage23/menu.c
+++ b/stage23/menu.c
@@ -448,7 +448,7 @@ refresh:
for (int i = timeout; i; i--) {
print("\rBooting automatically in %u, press any key to stop the countdown...", i);
term_double_buffer_flush();
- if ((c = pit_sleep_and_quit_on_keypress(18))) {
+ if ((c = pit_sleep_and_quit_on_keypress(1))) {
skip_timeout = true;
print("\e[2K\r\e[2A");
goto timeout_aborted;
diff --git a/test/limine.cfg b/test/limine.cfg
index 57f4e628..63ecb29b 100644
--- a/test/limine.cfg
+++ b/test/limine.cfg
@@ -1,5 +1,5 @@
DEFAULT_ENTRY=2
-TIMEOUT=no
+TIMEOUT=3
GRAPHICS=yes
MENU_RESOLUTION=1024x768
MENU_FONT=boot:///boot/font.bin
