From 3309751490abd289d97e5d810509a38f2058ba8f Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Tue, 10 Feb 2026 01:55:15 -0300 Subject: [PATCH] feat: add dmesg command to kernel shell MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reads the kernel log ring buffer via klog_read() and prints it to the UART console, allowing users to review boot messages and earlier kprintf output — just like Linux's dmesg command. Passes: make, cppcheck, QEMU smoke test. --- src/kernel/shell.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 42c6cc8..d6e91f6 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -1,6 +1,7 @@ #include "shell.h" #include "keyboard.h" #include "uart_console.h" +#include "console.h" #include "utils.h" #include "pmm.h" #include "vga_console.h" @@ -33,6 +34,7 @@ void execute_command(char* cmd) { uart_print(" ring3 - Run x86 ring3 syscall test\n"); uart_print(" reboot - Restart system\n"); uart_print(" sleep - Sleep for N ticks\n"); + uart_print(" dmesg - Show kernel log buffer\n"); } else if (strcmp(cmd, "ls") == 0) { if (!fs_root) { @@ -107,6 +109,15 @@ void execute_command(char* cmd) { uart_print("ring3 test only available on x86.\n"); #endif } + else if (strcmp(cmd, "dmesg") == 0) { + char dmesg_buf[4096]; + size_t n = klog_read(dmesg_buf, sizeof(dmesg_buf)); + if (n > 0) { + uart_print(dmesg_buf); + } else { + uart_print("(empty)\n"); + } + } else if (strcmp(cmd, "reboot") == 0) { hal_system_reboot(); } -- 2.43.0