strat9_kernel/debug_cfg.rs
1//! Centralised debug configuration.
2//!
3//! All global toggles and knobs that control debug output, diagnostic
4//! behaviour, or temporary workarounds live here. When a debug feature
5//! is no longer needed, simply flip the default to `false` : no other
6//! code changes required.
7//!
8//! # Future additions
9//!
10//! - `TRACE_SYSCALLS`: log every syscall entry/exit
11//! - `TRACE_CONTEXT_SWITCH`: log every task switch
12//! - `VGA_DEBUG_LIVE`: real-time VGA framebuffer output (already here)
13//! - `PANIC_SCREENSHOT`: dump framebuffer to serial on panic
14//! - `LOG_MM`: trace memory allocations
15
16use core::sync::atomic::{AtomicBool, Ordering};
17
18// ---------------------------------------------------------------------------
19// VGA live debug output
20// ---------------------------------------------------------------------------
21
22/// When `true`, every `log::info!` / `log::warn!` / etc. is drawn directly to
23/// the VGA framebuffer **in real time** (pixel by pixel, no buffering).
24///
25/// This is intentionally linear and synchronous : it slows the boot down but
26/// guarantees you see every message, even during a panic.
27///
28/// Set to `false` (or delete the toggles) once the boot issue is resolved.
29pub static VGA_DEBUG_LIVE: AtomicBool = AtomicBool::new(true); // FALSE to disable live VGA output and rely on the lock-free circular buffer instead.
30
31/// Returns `true` if live VGA debug output is enabled.
32pub fn is_vga_debug_live() -> bool {
33 VGA_DEBUG_LIVE.load(Ordering::Relaxed)
34}
35
36/// Enable or disable live VGA debug output.
37pub fn set_vga_debug_live(enabled: bool) {
38 VGA_DEBUG_LIVE.store(enabled, Ordering::Relaxed);
39}
40
41// ---------------------------------------------------------------------------
42// VGA circular buffer (vgabuf) : async display via status line task
43// ---------------------------------------------------------------------------
44
45/// When `true` (default), log lines are also written into the lock-free
46/// circular buffer (`vgabuf`) for async display by the status line task.
47///
48/// Disable this when using `VGA_DEBUG_LIVE` to avoid duplicate output and
49/// visual clutter. Re-enable when live debug is turned off so the status
50/// line task keeps the framebuffer terminal up to date.
51pub static VGA_DEBUG_BUFFER: AtomicBool = AtomicBool::new(true);
52
53/// Returns `true` if buffered VGA output is enabled.
54pub fn is_vga_debug_buffer() -> bool {
55 VGA_DEBUG_BUFFER.load(Ordering::Relaxed)
56}
57
58/// Enable or disable buffered VGA output.
59pub fn set_vga_debug_buffer(enabled: bool) {
60 VGA_DEBUG_BUFFER.store(enabled, Ordering::Relaxed);
61}
62
63// ---------------------------------------------------------------------------
64// Future debug flags : TODO
65// ---------------------------------------------------------------------------
66// Example:
67//
68// pub static TRACE_SYSCALLS: AtomicBool = AtomicBool::new(false);
69// pub fn trace_syscalls() -> bool { TRACE_SYSCALLS.load(Ordering::Relaxed) }