diff --git a/src/entry.rs b/src/entry.rs index f7e3bba..40534b5 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -50,12 +50,26 @@ unsafe extern "C" fn _entry() { "li t0, (0b11 << 11) | (1 << 13)", "csrw mstatus, t0", "csrw mie, x0", - - ); - // TODO do hardware inits and wake other harts + "la t1, {kinit}", + "csrw mepc, t1", + + "la ra, 2f", + "mret", + "2:", + kinit = sym kinit, + ); } +#[no_mangle] +extern "C" fn kinit() { + use crate::uart; + uart::Device::new(0x1000_0000); +} + +#[no_mangle] +extern "C" fn kinit_hart() {} + #[inline] unsafe fn write_tp(id: &usize) { use core::arch::asm; diff --git a/src/main.rs b/src/main.rs index 3a80ade..b693c53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ extern "C" fn start() -> ! { // } // println!("This should not print because the console is not initialised."); - unsafe { uart::init_console(0x1000_0000) }; + uart::init_console(0x1000_0000); println!("Hello, world!"); // print current hartid diff --git a/src/uart.rs b/src/uart.rs index 4a1e766..b88f4af 100644 --- a/src/uart.rs +++ b/src/uart.rs @@ -14,7 +14,7 @@ impl Device { /// Create a new UART device. /// # Safety /// `base` must be the base address of a UART device. - pub unsafe fn new(base: usize) -> Self { + pub fn new(base: usize) -> Self { use core::ptr::write_volatile; let addr = base as *mut u8; // Set data size to 8 bits. @@ -64,9 +64,9 @@ impl core::fmt::Write for Device { /// Initialise the UART debugging console. /// # Safety /// `base` must point to the base address of a UART device. -pub unsafe fn init_console(base: usize) { - let mut console = CONSOLE.lock(); - *console = Some(unsafe { Device::new(base) }); +pub fn init_console(base: usize) { + let mut console: spinning_top::lock_api::MutexGuard> = CONSOLE.lock(); + *console = Some(Device::new(base)); } /// Prints a formatted string to the [CONSOLE].