Merge "vmbase: Simplify println! and eprintln! impl" into main
diff --git a/vmbase/src/console.rs b/vmbase/src/console.rs
index a7d37b4..657a62b 100644
--- a/vmbase/src/console.rs
+++ b/vmbase/src/console.rs
@@ -37,36 +37,25 @@
CONSOLE.lock().replace(uart);
}
-/// Writes a string to the console.
+/// Writes a formatted string followed by a newline to the console.
///
/// Panics if [`init`] was not called first.
-pub(crate) fn write_str(s: &str) {
- CONSOLE.lock().as_mut().unwrap().write_str(s).unwrap();
+pub(crate) fn writeln(format_args: Arguments) {
+ let mut guard = CONSOLE.lock();
+ let uart = guard.as_mut().unwrap();
+
+ write(uart, format_args).unwrap();
+ let _ = uart.write_str("\n");
}
-/// Writes a formatted string to the console.
-///
-/// Panics if [`init`] was not called first.
-pub(crate) fn write_args(format_args: Arguments) {
- write(CONSOLE.lock().as_mut().unwrap(), format_args).unwrap();
-}
-
-/// Reinitializes the UART driver and writes a string to it.
+/// Reinitializes the UART driver and writes a formatted string followed by a newline to it.
///
/// This is intended for use in situations where the UART may be in an unknown state or the global
/// instance may be locked, such as in an exception handler or panic handler.
-pub fn emergency_write_str(s: &str) {
- let mut uart = create();
- let _ = uart.write_str(s);
-}
-
-/// Reinitializes the UART driver and writes a formatted string to it.
-///
-/// This is intended for use in situations where the UART may be in an unknown state or the global
-/// instance may be locked, such as in an exception handler or panic handler.
-pub fn emergency_write_args(format_args: Arguments) {
+pub fn ewriteln(format_args: Arguments) {
let mut uart = create();
let _ = write(&mut uart, format_args);
+ let _ = uart.write_str("\n");
}
/// Prints the given formatted string to the console, followed by a newline.
@@ -74,32 +63,16 @@
/// Panics if the console has not yet been initialized. May hang if used in an exception context;
/// use `eprintln!` instead.
macro_rules! println {
- () => ($crate::console::write_str("\n"));
- ($($arg:tt)*) => ({
- $crate::console::write_args(format_args!($($arg)*))};
- $crate::console::write_str("\n");
- );
+ ($($arg:tt)*) => ($crate::console::writeln(format_args!($($arg)*)));
}
pub(crate) use println; // Make it available in this crate.
-/// Prints the given string to the console in an emergency, such as an exception handler.
-///
-/// Never panics.
-#[macro_export]
-macro_rules! eprint {
- ($($arg:tt)*) => ($crate::console::emergency_write_args(format_args!($($arg)*)));
-}
-
/// Prints the given string followed by a newline to the console in an emergency, such as an
/// exception handler.
///
/// Never panics.
#[macro_export]
macro_rules! eprintln {
- () => ($crate::console::emergency_write_str("\n"));
- ($($arg:tt)*) => ({
- $crate::console::emergency_write_args(format_args!($($arg)*))};
- $crate::console::emergency_write_str("\n");
- );
+ ($($arg:tt)*) => ($crate::console::ewriteln(format_args!($($arg)*)));
}