Trim unnecessary unsafe
blocks
This commit is contained in:
parent
e7060b38bd
commit
304152dbeb
18
src/entry.rs
18
src/entry.rs
|
@ -51,11 +51,25 @@ unsafe extern "C" fn _entry() {
|
|||
"csrw mstatus, t0",
|
||||
"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]
|
||||
unsafe fn write_tp(id: &usize) {
|
||||
use core::arch::asm;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<spinning_top::RawSpinlock, Option<Device>> = CONSOLE.lock();
|
||||
*console = Some(Device::new(base));
|
||||
}
|
||||
|
||||
/// Prints a formatted string to the [CONSOLE].
|
||||
|
|
Loading…
Reference in a new issue