2
0
mirror of https://github.com/m-labs/artiq.git synced 2025-01-23 17:08:12 +08:00
artiq/artiq/firmware/libboard/uart_console.rs

33 lines
781 B
Rust

use core::fmt;
pub struct Console;
impl fmt::Write for Console {
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
extern { fn putchar(c: i32) -> i32; }
for c in s.bytes() { unsafe { putchar(c as i32); } }
Ok(())
}
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
use core::fmt::Write;
write!($crate::uart_console::Console, $($arg)*).unwrap()
})
}
#[macro_export]
macro_rules! println {
($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}
#[no_mangle]
#[lang = "panic_fmt"]
pub extern fn panic_fmt(args: fmt::Arguments, file: &'static str, line: u32) -> ! {
println!("panic at {}:{}: {}", file, line, args);
loop {}
}