From ceb679726d4022a21bf48ba73f84379a5eef63af Mon Sep 17 00:00:00 2001 From: gjz010 Date: Tue, 11 May 2021 02:08:35 +0800 Subject: [PATCH] Early message using SBI for logging & new board rcore_vmm_guest --- .../arch/riscv/board/rcore_vmm_guest/mod.rs | 14 ++++++++++ kernel/src/arch/riscv/io.rs | 26 +++++++++++++++++-- kernel/src/arch/riscv/mod.rs | 7 +++-- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 kernel/src/arch/riscv/board/rcore_vmm_guest/mod.rs diff --git a/kernel/src/arch/riscv/board/rcore_vmm_guest/mod.rs b/kernel/src/arch/riscv/board/rcore_vmm_guest/mod.rs new file mode 100644 index 00000000..4486638a --- /dev/null +++ b/kernel/src/arch/riscv/board/rcore_vmm_guest/mod.rs @@ -0,0 +1,14 @@ +use crate::drivers::*; +use crate::memory::phys_to_virt; +use riscv::register::sie; + +/// Enable external interrupt +pub unsafe fn init_external_interrupt() { + sie::set_sext(); +} + +pub fn init(dtb: usize) { + serial::uart16550::driver_init(); + irq::plic::driver_init(); + device_tree::init(dtb); +} diff --git a/kernel/src/arch/riscv/io.rs b/kernel/src/arch/riscv/io.rs index e4b706d0..0b2cc9b7 100644 --- a/kernel/src/arch/riscv/io.rs +++ b/kernel/src/arch/riscv/io.rs @@ -1,11 +1,33 @@ +use crate::drivers::SerialDriver; use crate::drivers::SERIAL_DRIVERS; +use alloc::sync::Arc; use core::fmt::{Arguments, Write}; +pub struct HeaplessWrite>(T); +impl> core::fmt::Write for HeaplessWrite { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + self.0.as_ref().write(s.as_bytes()); + Ok(()) + } +} +pub struct HeaplessSBIWrite; +impl core::fmt::Write for HeaplessSBIWrite { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + for ch in s.as_bytes() { + super::sbi::console_putchar(*ch as usize); + } + Ok(()) + } +} pub fn putfmt(fmt: Arguments) { // output to serial let mut drivers = SERIAL_DRIVERS.write(); if let Some(serial) = drivers.first_mut() { - serial.write(format!("{}", fmt).as_bytes()); + HeaplessWrite(&serial).write_fmt(fmt).unwrap(); + } else { + // might miss some early messages. + // no no no i don't accept it. + // note that we can't use heap here. + HeaplessSBIWrite.write_fmt(fmt).unwrap(); } - // might miss some early messages, but it's okay } diff --git a/kernel/src/arch/riscv/mod.rs b/kernel/src/arch/riscv/mod.rs index 4fb8d529..f7156928 100644 --- a/kernel/src/arch/riscv/mod.rs +++ b/kernel/src/arch/riscv/mod.rs @@ -3,7 +3,10 @@ use trapframe; #[cfg(feature = "board_u540")] #[path = "board/u540/mod.rs"] pub mod board; -#[cfg(not(feature = "board_u540"))] +#[cfg(feature = "board_rcore_vmm_guest")] +#[path = "board/rcore_vmm_guest/mod.rs"] +pub mod board; +#[cfg(not(any(feature = "board_u540", feature = "board_rcore_vmm_guest")))] #[path = "board/virt/mod.rs"] pub mod board; @@ -16,7 +19,7 @@ pub mod io; pub mod memory; pub mod paging; pub mod rand; -mod sbi; +pub mod sbi; pub mod signal; pub mod syscall; pub mod timer;