From fdcfd48a2404fc67959bc8df4f0daed8bf730314 Mon Sep 17 00:00:00 2001 From: "Myles \"Mellurboo\" Wilson" <102391892+Mellurboo@users.noreply.github.com> Date: Sun, 10 May 2026 10:22:18 +0100 Subject: [PATCH] pr: Removed Unnessisary Flipping on kconsole leading to Vastly Faster Boot Times & PS/2 Hardware Correctness (#12) * Flush PS/2 Devices on boot to avoid Locking dependent on the out buffer on real hardware / emulated PS2 over USB Removed Slow and Unnessisarty flipping causing kconsole write slowdowns consequently speeding up the boot process * sod wc --- src/core/kconsole.c | 6 +----- src/dev/ps2.c | 3 +++ src/dev/ps2.h | 8 ++++++++ src/input/keyboard.c | 13 +++++++++++++ src/input/keyboard.h | 3 +++ src/mem/paging.c | 3 ++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/core/kconsole.c b/src/core/kconsole.c index 7a01d2e..51f3ea5 100644 --- a/src/core/kconsole.c +++ b/src/core/kconsole.c @@ -49,7 +49,6 @@ static void kconsole_putc_nolock(char c) { cursor_x = 10; cursor_y += CHAR_HEIGHT; kconsole_scroll(); - graphics_flip_buffer(); return; } @@ -89,12 +88,9 @@ void kconsole_write(const char *s) { spinlock_release_irqrestore(&console_lock, flags); return; } - + while (*s) { kconsole_putc_nolock(*s++); } - - // Flip once after a write batch to keep console updates coherent. - graphics_flip_buffer(); spinlock_release_irqrestore(&console_lock, flags); } diff --git a/src/dev/ps2.c b/src/dev/ps2.c index ce575be..9225c3a 100644 --- a/src/dev/ps2.c +++ b/src/dev/ps2.c @@ -109,6 +109,9 @@ uint8_t mouse_read(void) { void mouse_init(void) { uint8_t status; + int limit = 128; + while (limit-- > 0 && (inb(PS2_STATUS_PORT) & PS2_STATUS_OUT_FULL)) + (void)inb(PS2_DATA_PORT); // Enable Aux Device mouse_wait(0); diff --git a/src/dev/ps2.h b/src/dev/ps2.h index 01a0a88..c483920 100644 --- a/src/dev/ps2.h +++ b/src/dev/ps2.h @@ -4,11 +4,19 @@ #ifndef PS2_H #define PS2_H +#define PS2_DATA_PORT 0x60 +#define PS2_CMD_PORT 0x64 +#define PS2_STATUS_PORT 0x64 +#define PS2_STATUS_OUT_FULL 0x01 +#define PS2_STATUS_IN_FULL 0x02 +#define PS2_STATUS_AUX_DATA 0x20 + #include void ps2_init(void); #include "process.h" + uint64_t timer_handler(registers_t *regs); uint64_t keyboard_handler(registers_t *regs); uint64_t mouse_handler(registers_t *regs); diff --git a/src/input/keyboard.c b/src/input/keyboard.c index a26d60f..a4533e6 100644 --- a/src/input/keyboard.c +++ b/src/input/keyboard.c @@ -1,5 +1,7 @@ #include "keyboard.h" #include "keymap.h" +#include "../core/io.h" +#include "../dev/ps2.h" typedef struct { bool e0_prefix; @@ -88,6 +90,17 @@ static const uint16_t set1_ext[128] = { }; void keyboard_init(void) { + /* + Flush all data in the controller output buffer + this can cause the PS/2 Keyboard device to not work + on real hardware specifically + (even when Legacy USB keyboard Emulation is emulating the PS/2 keyboard) + Myles + */ + int limit = 128; + while (limit-- > 0 && (inb(PS2_STATUS_PORT) & PS2_STATUS_OUT_FULL)) + (void)inb(KBD_DATA_PORT); + g_kb.e0_prefix = false; g_kb.left_shift = false; g_kb.right_shift = false; diff --git a/src/input/keyboard.h b/src/input/keyboard.h index d9ecd79..88a005c 100644 --- a/src/input/keyboard.h +++ b/src/input/keyboard.h @@ -1,6 +1,9 @@ #ifndef KEYBOARD_H #define KEYBOARD_H +#define KBD_DATA_PORT 0x60 +#define KBD_CMD_PORT 0x64 + #include #include #include "keycodes.h" diff --git a/src/mem/paging.c b/src/mem/paging.c index 04d2858..81a4c39 100644 --- a/src/mem/paging.c +++ b/src/mem/paging.c @@ -6,6 +6,8 @@ #include "platform.h" #include +#define MSR_WC 0x277 + static uint64_t current_pml4_phys = 0; // Get current CR3 value @@ -37,7 +39,6 @@ static uint64_t alloc_page_table_phys(void) { } void paging_init(void) { - current_pml4_phys = read_cr3() & PT_ADDR_MASK; }