-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcon.rs
48 lines (40 loc) · 1022 Bytes
/
con.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::con::_print(format_args!($($arg)*)));
}
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}
#[macro_export]
macro_rules! eprint {
() => ();
($($arg:tt)*) => ($crate::print!("\x1B[91m{}\x1B[0m", format_args!($($arg)*)));
}
#[macro_export]
macro_rules! eprintln {
() => ($crate::eprint!("\n"));
($($arg:tt)*) => ($crate::eprint!("{}\n", format_args!($($arg)*)));
}
pub fn write_str(s: &str) {
s.bytes().for_each(crate::arch::putchar);
}
pub struct Con;
impl core::fmt::Write for Con {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
write_str(s);
Ok(())
}
}
pub fn _print(args: core::fmt::Arguments) {
use core::fmt::Write;
Con.write_fmt(args).unwrap();
}
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
eprintln!("{}", info);
loop {
crate::arch::wait();
}
}