|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
|
|
|
|
|
|
|
|
//! BSP console facilities.
|
|
|
|
|
|
|
|
use crate::console;
|
|
|
|
use core::fmt;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Private Definitions
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/// A mystical, magical device for generating QEMU output out of the void.
|
|
|
|
struct QEMUOutput;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Private Code
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/// Implementing `core::fmt::Write` enables usage of the `format_args!` macros, which in turn are
|
|
|
|
/// used to implement the `kernel`'s `print!` and `println!` macros. By implementing `write_str()`,
|
|
|
|
/// we get `write_fmt()` automatically.
|
|
|
|
///
|
|
|
|
/// See [`src/print.rs`].
|
|
|
|
///
|
|
|
|
/// [`src/print.rs`]: ../../print/index.html
|
|
|
|
impl fmt::Write for QEMUOutput {
|
|
|
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
|
|
for c in s.chars() {
|
|
|
|
unsafe {
|
|
|
|
core::ptr::write_volatile(0x3F20_1000 as *mut u8, c as u8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Public Code
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/// Return a reference to the console.
|
|
|
|
pub fn console() -> impl console::interface::Write {
|
|
|
|
QEMUOutput {}
|
|
|
|
}
|