feat(libkos): add print!/println! macros via debug_putchar

This commit is contained in:
2026-10-19 00:53:52 +02:00
parent dbec3842fa
commit 25a4c9415b
2 changed files with 29 additions and 0 deletions

28
crates/libkos/src/io.rs Normal file
View File

@@ -0,0 +1,28 @@
use core::fmt;
struct Writer;
impl fmt::Write for Writer {
fn write_str(&mut self, s: &str) -> fmt::Result {
for &b in s.as_bytes() {
crate::syscall::debug_putchar(b);
}
Ok(())
}
}
pub fn _print(args: fmt::Arguments) {
use fmt::Write;
Writer.write_fmt(args).ok();
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
}
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}

View File

@@ -5,6 +5,7 @@ extern crate alloc;
mod arch; mod arch;
pub mod syscall; pub mod syscall;
pub mod alloc_impl; pub mod alloc_impl;
pub mod io;
mod rt; mod rt;
#[cfg(target_os = "none")] #[cfg(target_os = "none")]