aloe/
debug.rs

1/*
2  ____                 __               __  __
3 / __ \__ _____ ____  / /___ ____ _    / / / /__ ___ ____
4/ /_/ / // / _ `/ _ \/ __/ // /  ' \  / /_/ (_-</ -_) __/
5\___\_\_,_/\_,_/_//_/\__/\_,_/_/_/_/  \____/___/\__/_/
6  Part of the Quantum OS Kernel
7
8Copyright 2025 Gavin Kellam
9
10Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
11associated documentation files (the "Software"), to deal in the Software without restriction,
12including without limitation the rights to use, copy, modify, merge, publish, distribute,
13sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in all copies or substantial
17portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
20NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
23OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24*/
25
26use core::fmt::Error;
27use core::fmt::Write;
28use vera_portal::sys_client::debug_msg;
29
30#[doc(hidden)]
31pub use lignan::set_global_debug_fn;
32
33/// Quantum OS's 'kernel' debug output.
34///
35/// This is used in the `dbug!(...)` and `dbugln!(...)` macros
36/// to give a 'println!()' like enviroment that outputs into the
37/// kernel's debug device (useally the serial port).
38pub struct DebugOut {}
39
40impl core::fmt::Write for DebugOut {
41    fn write_str(&mut self, s: &str) -> core::fmt::Result {
42        debug_msg(s).map_err(|_| Error {})
43    }
44}
45
46#[doc(hidden)]
47pub fn priv_print(args: core::fmt::Arguments) {
48    let _ = DebugOut {}.write_fmt(args);
49}
50
51/// Quantum OS's 'kernel' debug formatting macro.
52///
53/// Outputs like 'println', but instead of going to StdOut, this
54/// macro prints to the kernel's debug output (useally a serial port).
55#[macro_export]
56macro_rules! dbug {
57    ($($arg:tt)*) => {{
58        $crate::debug::priv_print(format_args!($($arg)*));
59    }};
60}
61
62/// Quantum OS's 'kernel' debug formatting macro.
63///
64/// Outputs like 'println', but instead of going to StdOut, this
65/// macro prints to the kernel's debug output (useally a serial port).
66#[macro_export]
67macro_rules! dbugln {
68    () => {{ $crate::debug::dbug!("\n") }};
69    ($($arg:tt)*) => {{
70        $crate::debug::priv_print(format_args!($($arg)*));
71        $crate::dbug!("\n");
72    }};
73}