]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: add dmesg command to kernel shell
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:55:15 +0000 (01:55 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:55:15 +0000 (01:55 -0300)
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

index 42c6cc8efb806e829812a47ad255ed6c420ada75..d6e91f676f7a06ce212ea4513481617f6c2d96e5 100644 (file)
@@ -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 <num> - 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();
     }