mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 16:16:16 +04:00
Early message using SBI for logging & new board rcore_vmm_guest
This commit is contained in:
parent
8107d0993c
commit
ceb679726d
14
kernel/src/arch/riscv/board/rcore_vmm_guest/mod.rs
Normal file
14
kernel/src/arch/riscv/board/rcore_vmm_guest/mod.rs
Normal file
@ -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);
|
||||||
|
}
|
@ -1,11 +1,33 @@
|
|||||||
|
use crate::drivers::SerialDriver;
|
||||||
use crate::drivers::SERIAL_DRIVERS;
|
use crate::drivers::SERIAL_DRIVERS;
|
||||||
|
use alloc::sync::Arc;
|
||||||
use core::fmt::{Arguments, Write};
|
use core::fmt::{Arguments, Write};
|
||||||
|
pub struct HeaplessWrite<T: AsRef<dyn SerialDriver>>(T);
|
||||||
|
impl<T: AsRef<dyn SerialDriver>> core::fmt::Write for HeaplessWrite<T> {
|
||||||
|
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) {
|
pub fn putfmt(fmt: Arguments) {
|
||||||
// output to serial
|
// output to serial
|
||||||
let mut drivers = SERIAL_DRIVERS.write();
|
let mut drivers = SERIAL_DRIVERS.write();
|
||||||
if let Some(serial) = drivers.first_mut() {
|
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
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ use trapframe;
|
|||||||
#[cfg(feature = "board_u540")]
|
#[cfg(feature = "board_u540")]
|
||||||
#[path = "board/u540/mod.rs"]
|
#[path = "board/u540/mod.rs"]
|
||||||
pub mod board;
|
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"]
|
#[path = "board/virt/mod.rs"]
|
||||||
pub mod board;
|
pub mod board;
|
||||||
|
|
||||||
@ -16,7 +19,7 @@ pub mod io;
|
|||||||
pub mod memory;
|
pub mod memory;
|
||||||
pub mod paging;
|
pub mod paging;
|
||||||
pub mod rand;
|
pub mod rand;
|
||||||
mod sbi;
|
pub mod sbi;
|
||||||
pub mod signal;
|
pub mod signal;
|
||||||
pub mod syscall;
|
pub mod syscall;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
|
Loading…
Reference in New Issue
Block a user