sel4/
printing.rs

1//
2// Copyright 2023, Colias Group, LLC
3// Copyright (c) 2020 Arm Limited
4//
5// SPDX-License-Identifier: MIT
6//
7
8use core::fmt;
9
10use crate::sys;
11
12/// Corresponds to `seL4_DebugPutChar`.
13pub fn debug_put_char(c: u8) {
14    sys::seL4_DebugPutChar(c)
15}
16
17/// Implements `core::fmt::Write` using [`debug_put_char`].
18pub struct DebugWrite;
19
20impl fmt::Write for DebugWrite {
21    fn write_str(&mut self, s: &str) -> fmt::Result {
22        for &c in s.as_bytes() {
23            debug_put_char(c)
24        }
25        Ok(())
26    }
27}
28
29#[doc(hidden)]
30pub fn debug_print_helper(args: fmt::Arguments) {
31    fmt::write(&mut DebugWrite, args).unwrap_or_else(|err| {
32        panic!("write error: {:?}", err)
33    })
34}
35
36/// Like `std::debug_print!`, except backed by `seL4_DebugPutChar`.
37#[macro_export]
38macro_rules! debug_print {
39    ($($arg:tt)*) => ($crate::_private::printing::debug_print_helper(format_args!($($arg)*)));
40}
41
42/// Like `std::debug_println!`, except backed by `seL4_DebugPutChar`.
43#[macro_export]
44macro_rules! debug_println {
45    () => ($crate::debug_println!(""));
46    ($($arg:tt)*) => ($crate::debug_print!("{}\n", format_args!($($arg)*)));
47}
48
49#[doc(hidden)]
50pub mod _private {
51    pub use super::debug_print_helper;
52}