From: Tulio A M Mendes Date: Tue, 10 Feb 2026 05:56:54 +0000 (-0300) Subject: feat: add kgetc() to console subsystem for kernel input X-Git-Url: https://projects.tadryanom.me/sitemap.xml?a=commitdiff_plain;h=46ed0e29216a5158979e70f246aab3f1d5b5f7a4;p=AdrOS.git 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. --- diff --git a/include/console.h b/include/console.h index 7bdbea4..8c616b0 100644 --- a/include/console.h +++ b/include/console.h @@ -15,6 +15,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 12d6233..08d5ee8 100644 --- a/src/kernel/console.c +++ b/src/kernel/console.c @@ -7,6 +7,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; @@ -218,6 +219,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;