1
0
Fork 0
forked from AbleOS/ableos
ableos_time/ableos/src/print.rs

78 lines
2 KiB
Rust
Raw Normal View History

2022-02-07 07:33:40 -06:00
// TODO: refactor this file
// TODO: make STDOUT redirect to a socket owned
// by the process named "stdout"
2022-04-11 17:23:11 -05:00
2021-11-23 05:53:06 -06:00
use core::fmt::{Arguments, Error};
2022-04-11 17:23:11 -05:00
pub struct Stdout;
2021-11-16 00:09:27 -06:00
impl Stdout {
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
{
2021-12-24 07:03:15 -06:00
let _ = core::fmt::Write::write_fmt(self, arg);
2021-11-16 00:09:27 -06:00
// Ok(())
}
}
2022-04-11 17:23:11 -05:00
2021-11-16 00:09:27 -06:00
impl core::fmt::Write for Stdout {
#[cfg(target_arch = "aarch64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
// Don't actually print anything yet lmao
Ok(())
}
#[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
2022-07-31 05:22:39 -05:00
// use mini_backtrace::Backtrace;
2022-07-31 01:54:01 -05:00
use crate::TERM;
2022-07-31 05:22:39 -05:00
// Capture up to 16 frames. This is returned using an ArrayVec that doesn't
// perform any dynamic memory allocation.
/*
let bt = Backtrace::<16>::capture();
trace!("Backtrace:");
for frame in bt.frames {
trace!(" {:#x}", frame);
}
if bt.frames_omitted {
trace!(" ... <frames omitted>");
}
*/
2022-07-31 06:21:50 -05:00
// trace!("printing");
2022-07-31 03:03:59 -05:00
// x86_64::instructions::interrupts::without_interrupts(|| {
let mut term = TERM.lock();
term.set_dirty(true);
term.print(s);
2022-07-31 03:03:59 -05:00
drop(term);
// });
2022-07-31 06:21:50 -05:00
// trace!("Finished printing");
2021-11-16 00:09:27 -06:00
Ok(())
}
#[cfg(target_arch = "riscv64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
Ok(())
}
2021-11-27 09:19:08 -06:00
fn write_char(&mut self, c: char) -> core::fmt::Result {
self.write_str(c.encode_utf8(&mut [0; 4]))
}
fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> core::fmt::Result {
core::fmt::write(&mut self, args)
}
2021-11-16 00:09:27 -06:00
}
2022-04-11 17:23:11 -05:00
2021-11-16 00:09:27 -06:00
#[macro_export]
macro_rules! print {
() => {
::core::writeln!($crate::print::Stdout, "")
};
($($tt:tt)*) => {
::core::write!($crate::print::Stdout, $($tt)*)
};
}
#[macro_export]
macro_rules! println {
($($tt:tt)*) => {
::core::writeln!($crate::print::Stdout, $($tt)*)
};
}