From cd2e2307d230341ad9e0c692aebe7b0c0610b055 Mon Sep 17 00:00:00 2001 From: Yu Chen Date: Tue, 3 Jan 2023 09:32:36 +0800 Subject: [PATCH] explicitly UART.init() in rust_main --- os/src/drivers/chardev/mod.rs | 1 + os/src/drivers/chardev/ns16550a.rs | 8 +++++++- os/src/main.rs | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/os/src/drivers/chardev/mod.rs b/os/src/drivers/chardev/mod.rs index de1446d5..64c168f3 100644 --- a/os/src/drivers/chardev/mod.rs +++ b/os/src/drivers/chardev/mod.rs @@ -6,6 +6,7 @@ use lazy_static::*; pub use ns16550a::NS16550a; pub trait CharDevice { + fn init(&self); fn read(&self) -> u8; fn write(&self, ch: u8); fn handle_irq(&self); diff --git a/os/src/drivers/chardev/ns16550a.rs b/os/src/drivers/chardev/ns16550a.rs index da290633..d10dd909 100644 --- a/os/src/drivers/chardev/ns16550a.rs +++ b/os/src/drivers/chardev/ns16550a.rs @@ -135,7 +135,7 @@ impl NS16550a { ns16550a: NS16550aRaw::new(BASE_ADDR), read_buffer: VecDeque::new(), }; - inner.ns16550a.init(); + //inner.ns16550a.init(); Self { inner: unsafe { UPIntrFreeCell::new(inner) }, condvar: Condvar::new(), @@ -144,6 +144,12 @@ impl NS16550a { } impl CharDevice for NS16550a { + fn init(&self){ + let mut inner = self.inner.exclusive_access(); + inner.ns16550a.init(); + drop(inner); + } + fn read(&self) -> u8 { loop { let mut inner = self.inner.exclusive_access(); diff --git a/os/src/main.rs b/os/src/main.rs index 299e4cf2..6e910852 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -28,6 +28,8 @@ mod task; mod timer; mod trap; +use crate::drivers::chardev::CharDevice; +use crate::drivers::chardev::UART; //use syscall::create_desktop; //for test core::arch::global_asm!(include_str!("entry.asm")); @@ -55,6 +57,7 @@ lazy_static! { pub fn rust_main() -> ! { clear_bss(); mm::init(); + UART.init(); println!("KERN: init gpu"); let _gpu = GPU_DEVICE.clone(); println!("KERN: init keyboard");