Trim unnecessary unsafe blocks

This commit is contained in:
gil 2024-05-18 23:22:04 -05:00
parent e7060b38bd
commit 304152dbeb
3 changed files with 22 additions and 8 deletions

View file

@ -51,11 +51,25 @@ unsafe extern "C" fn _entry() {
"csrw mstatus, t0", "csrw mstatus, t0",
"csrw mie, x0", "csrw mie, x0",
); "la t1, {kinit}",
"csrw mepc, t1",
// TODO do hardware inits and wake other harts "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] #[inline]
unsafe fn write_tp(id: &usize) { unsafe fn write_tp(id: &usize) {
use core::arch::asm; use core::arch::asm;

View file

@ -96,7 +96,7 @@ extern "C" fn start() -> ! {
// } // }
// println!("This should not print because the console is not initialised."); // 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!"); println!("Hello, world!");
// print current hartid // print current hartid

View file

@ -14,7 +14,7 @@ impl Device {
/// Create a new UART device. /// Create a new UART device.
/// # Safety /// # Safety
/// `base` must be the base address of a UART device. /// `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; use core::ptr::write_volatile;
let addr = base as *mut u8; let addr = base as *mut u8;
// Set data size to 8 bits. // Set data size to 8 bits.
@ -64,9 +64,9 @@ impl core::fmt::Write for Device {
/// Initialise the UART debugging console. /// Initialise the UART debugging console.
/// # Safety /// # Safety
/// `base` must point to the base address of a UART device. /// `base` must point to the base address of a UART device.
pub unsafe fn init_console(base: usize) { pub fn init_console(base: usize) {
let mut console = CONSOLE.lock(); let mut console: spinning_top::lock_api::MutexGuard<spinning_top::RawSpinlock, Option<Device>> = CONSOLE.lock();
*console = Some(unsafe { Device::new(base) }); *console = Some(Device::new(base));
} }
/// Prints a formatted string to the [CONSOLE]. /// Prints a formatted string to the [CONSOLE].