From 229ed84d9d13954eee819586c97d896c7d634fcc Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Tue, 10 Feb 2026 02:56:54 -0300 Subject: [PATCH] feat: add kgetc() to console subsystem for kernel input kgetc() reads a single character via keyboard_read_blocking(), providing a symmetric API alongside kprintf() for output. This enables the kernel console (and future kconsole) to have a generic input mechanism independent of architecture. Passes: make, cppcheck, QEMU smoke test. --- include/console.h | 2 ++ src/kernel/console.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/console.h b/include/console.h index d404edc0..4b87ae22 100644 --- a/include/console.h +++ b/include/console.h @@ -24,6 +24,8 @@ int ksnprintf(char* out, size_t out_size, const char* fmt, ...); void kprintf(const char* fmt, ...); +int kgetc(void); + size_t klog_read(char* out, size_t out_size); #endif diff --git a/src/kernel/console.c b/src/kernel/console.c index 3243b8eb..ee55be7e 100644 --- a/src/kernel/console.c +++ b/src/kernel/console.c @@ -16,6 +16,7 @@ #include "spinlock.h" #include "uart_console.h" #include "vga_console.h" +#include "keyboard.h" static spinlock_t g_console_lock = {0}; static int g_console_uart_enabled = 1; @@ -227,6 +228,13 @@ void kprintf(const char* fmt, ...) { console_write(buf); } +int kgetc(void) { + char c = 0; + int rd = keyboard_read_blocking(&c, 1); + if (rd <= 0) return -1; + return (int)(unsigned char)c; +} + size_t klog_read(char* out, size_t out_size) { if (!out || out_size == 0) return 0; -- 2.43.0