Add kernel global CONSOLE
Init it with mini_uart - nothing else is implemented yet.
This commit is contained in:
parent
ab696eca8e
commit
d342031331
|
@ -22,14 +22,20 @@ macro_rules! println {
|
|||
|
||||
#[doc(hidden)]
|
||||
#[cfg(not(any(test, qemu)))]
|
||||
pub fn _print(_args: core::fmt::Arguments) {
|
||||
// @todo real system implementation
|
||||
pub fn _print(args: core::fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
|
||||
crate::CONSOLE.lock(|c| {
|
||||
c.write_fmt(args).unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
/// qemu-based tests use semihosting write0 syscall.
|
||||
#[doc(hidden)]
|
||||
#[cfg(any(test, qemu))] // qemu feature not enabled here?? we pass --features=qemu to cargo test
|
||||
pub fn _print(args: core::fmt::Arguments) {
|
||||
use crate::{qemu, write_to};
|
||||
|
||||
let mut buf = [0u8; 512];
|
||||
qemu::semihosting::sys_write0_call(write_to::c_show(&mut buf, args).unwrap());
|
||||
}
|
||||
|
|
|
@ -45,6 +45,9 @@ mod write_to;
|
|||
|
||||
entry!(kmain);
|
||||
|
||||
/// The global console. Output of the kernel print! and println! macros goes here.
|
||||
static CONSOLE: sync::NullLock<devices::Console> = sync::NullLock::new(devices::Console::new());
|
||||
|
||||
/// The global allocator for DMA-able memory. That is, memory which is tagged
|
||||
/// non-cacheable in the page tables.
|
||||
static DMA_ALLOCATOR: sync::NullLock<mm::BumpAllocator> =
|
||||
|
@ -90,6 +93,20 @@ fn init_exception_traps() {
|
|||
println!("Exception traps set up");
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "noserial"))]
|
||||
fn init_uart_serial() {
|
||||
use crate::platform::rpi3::{gpio::GPIO, mini_uart::MiniUart};
|
||||
let gpio = GPIO::default();
|
||||
let uart = MiniUart::default();
|
||||
let uart = uart.prepare(&gpio);
|
||||
CONSOLE.lock(|c| {
|
||||
// Move uart into the global CONSOLE.
|
||||
c.replace_with(uart.into());
|
||||
});
|
||||
|
||||
println!("[0] MiniUART is live!");
|
||||
}
|
||||
|
||||
/// Kernel entry point.
|
||||
/// `arch` crate is responsible for calling it.
|
||||
#[inline]
|
||||
|
@ -100,6 +117,9 @@ pub fn kmain() -> ! {
|
|||
#[cfg(test)]
|
||||
test_main();
|
||||
|
||||
#[cfg(not(feature = "noserial"))]
|
||||
init_uart_serial();
|
||||
|
||||
endless_sleep()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue