summaryrefslogtreecommitdiffstats
path: root/rsnix/src/serial.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-01 14:09:14 +0200
committersalmonik <salmonik@tuta.io>2026-08-01 14:09:14 +0200
commitc7540c31d45dac68fa1852f5d25645d569b2da9d (patch)
treec102aacb40f99d4f9bb87ab2a996cb08df0dfae0 /rsnix/src/serial.rs
parentshell: cat <path> TIL <marker> sugar + precise ordering errors (diff)
downloadrs-dos-c7540c31d45dac68fa1852f5d25645d569b2da9d.tar.gz
rs-dos-c7540c31d45dac68fa1852f5d25645d569b2da9d.zip
klog: kernel log ring + /dev/klog + klog shell command
- rsnix/src/klog.rs: RAM ring of the last 128 serial log lines (128 chars each), fed by serial_println! so every boot/low-level message is captured for free. Sequence numbers per line, wrap/drop accounting; the ring never allocates (const-constructible static). - /dev/klog char device; shell 'klog' is a thin alias for cat /dev/klog with the same filters/redirection, so 'klog -t 5', 'klog -g fat' and 'klog WRITING /disk/.../boot.log' all work. klog rejects positional args (usage) and input keywords. - Shell user-facing output (banner, prompt, term_print/term_println, pipeline sink, halt/poweroff) now writes to serial directly instead of through serial_println!, keeping echo/cat output out of the boot log (a streaming cat /dev/mem would otherwise wrap the ring). - serial_println! macro hooks klog::append_fmt via format_args! (no alloc at call sites); klog::dump formats the log for the device. Verified in QEMU: 28 boot lines captured (seq 0..27), shell output absent from the ring, klog WRITING persists a boot log (mtype-checked), wrap verified with a temporary 140-line boot loop (128 kept / 40 dropped, seq 40..167, oldest-live correct; loop reverted); full test-disk round trip still fsck-clean.
Diffstat (limited to '')
-rw-r--r--rsnix/src/serial.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/rsnix/src/serial.rs b/rsnix/src/serial.rs
index 03fa570..484a114 100644
--- a/rsnix/src/serial.rs
+++ b/rsnix/src/serial.rs
@@ -91,12 +91,21 @@ macro_rules! serial_print {
91 }}; 91 }};
92} 92}
93 93
94/// Prints a line to serial and appends it to the kernel log ring
95/// (klog — see /dev/klog). Every kernel-side message funnels through
96/// here, so the ring captures the whole boot sequence for free.
97/// User-facing shell output must NOT use this macro (shell output would
98/// pollute the boot log); it writes to the serial port directly.
94#[macro_export] 99#[macro_export]
95macro_rules! serial_println { 100macro_rules! serial_println {
96 () => { $crate::serial::write_str("\r\n"); }; 101 () => {
102 $crate::serial::write_str("\r\n");
103 $crate::klog::append_fmt(core::format_args!(""));
104 };
97 ($($arg:tt)*) => {{ 105 ($($arg:tt)*) => {{
98 $crate::serial_print!($($arg)*); 106 $crate::serial_print!($($arg)*);
99 $crate::serial::write_str("\r\n"); 107 $crate::serial::write_str("\r\n");
108 $crate::klog::append_fmt(core::format_args!($($arg)*));
100 }}; 109 }};
101} 110}
102 111