Skip to main content

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
8use core::sync::atomic::{AtomicBool, Ordering};
9
10// ---------------------------------------------------------------------------
11// Quiet mode : disable ALL debug output (serial, VGA, overlay)
12// ---------------------------------------------------------------------------
13
14/// Master switch to disable all debug output. When `true`, no serial,
15/// VGA, overlay, or status line output is produced. The kernel still
16/// runs, but produces zero diagnostic output. Intended for production
17/// builds and real hardware bring-up where debug output would slow boot.
18pub static QUIET_MODE: AtomicBool = AtomicBool::new(false);
19
20/// Returns `true` if quiet mode is active (all debug output disabled).
21pub fn is_quiet() -> bool {
22    QUIET_MODE.load(Ordering::Relaxed)
23}
24
25/// Enable or disable quiet mode at runtime.
26pub fn set_quiet(enabled: bool) {
27    QUIET_MODE.store(enabled, Ordering::Relaxed);
28}
29
30// ---------------------------------------------------------------------------
31// VGA live debug output
32// ---------------------------------------------------------------------------
33
34/// When `true`, every `log::info!` / `log::warn!` / etc. is drawn directly to
35/// the VGA framebuffer in real time (pixel by pixel, no buffering).
36pub static VGA_DEBUG_LIVE: AtomicBool = AtomicBool::new(true);
37
38pub fn is_vga_debug_live() -> bool {
39    !is_quiet() && VGA_DEBUG_LIVE.load(Ordering::Relaxed)
40}
41
42pub fn set_vga_debug_live(enabled: bool) {
43    VGA_DEBUG_LIVE.store(enabled, Ordering::Relaxed);
44}
45
46// ---------------------------------------------------------------------------
47// VGA circular buffer (vgabuf) : async display via status line task
48// ---------------------------------------------------------------------------
49
50/// When `true`, log lines are written into the lock-free circular buffer
51/// for async display by the status line task.
52pub static VGA_DEBUG_BUFFER: AtomicBool = AtomicBool::new(true);
53
54pub fn is_vga_debug_buffer() -> bool {
55    !is_quiet() && VGA_DEBUG_BUFFER.load(Ordering::Relaxed)
56}
57
58pub fn set_vga_debug_buffer(enabled: bool) {
59    VGA_DEBUG_BUFFER.store(enabled, Ordering::Relaxed);
60}
61
62// ---------------------------------------------------------------------------
63// Serial output
64// ---------------------------------------------------------------------------
65
66/// Master switch to enable/disable serial port output. When `false`,
67/// `serial_print!` / `serial_println!` become no-ops and `init_serial()`
68/// is skipped. The serial module is still compiled but produces no output.
69pub const SERIAL_ENABLED: bool = true;
70
71// ---------------------------------------------------------------------------
72// Future debug flags : TODO
73// ---------------------------------------------------------------------------