]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: add kgetc() to console subsystem for kernel input
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 05:56:54 +0000 (02:56 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 05:56:54 +0000 (02:56 -0300)
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
src/kernel/console.c

index 7bdbea4c14fffcb00745ac3ca7f4fa91556f56f7..8c616b05552832229586bd2345487e480001d5b2 100644 (file)
@@ -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
index 12d62337ff5d63569c14ae7b20be386a653991a7..08d5ee82627c31ba87e34a2fa723148aeabf070b 100644 (file)
@@ -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;