From 0f9e02874d97cee7d688b54f6b6fb54ff763ce66 Mon Sep 17 00:00:00 2001 From: "Esteban \"Skallwar\" Blanc" Date: Thu, 3 Aug 2023 17:26:51 +0200 Subject: [PATCH] misc: Cleanup warnings Signed-off-by: Esteban Blanc --- aarch64_qemuvirt/src/main.rs | 2 - hal_aarch64/src/lib.rs | 2 +- hal_riscv64/src/irq.rs | 2 +- hal_riscv64/src/lib.rs | 1 - hal_riscv64/src/mm/mod.rs | 2 +- hal_riscv64/src/mm/sv39.rs | 10 +++-- hal_riscv64/src/plic.rs | 2 - kernel/Cargo.toml | 2 +- kernel/src/error.rs | 9 ---- kernel/src/globals.rs | 10 ++--- kernel/src/kernel_console.rs | 2 +- kernel/src/tests.rs | 2 +- kernel/src/utils/init_cell.rs | 25 ----------- kernel/src/utils/init_once.rs | 81 ----------------------------------- kernel/src/utils/mod.rs | 4 +- riscv64_qemuvirt/src/main.rs | 20 +-------- 16 files changed, 21 insertions(+), 155 deletions(-) delete mode 100644 kernel/src/utils/init_cell.rs delete mode 100644 kernel/src/utils/init_once.rs diff --git a/aarch64_qemuvirt/src/main.rs b/aarch64_qemuvirt/src/main.rs index 21d16aeb..d00e485a 100644 --- a/aarch64_qemuvirt/src/main.rs +++ b/aarch64_qemuvirt/src/main.rs @@ -37,6 +37,4 @@ extern "C" fn k_main(_device_tree_ptr: usize) -> ! { let device_tree = kernel::device_tree::DeviceTree::new(DTB_ADDR).unwrap(); kernel::generic_main::generic_main::(device_tree, &[&PL011]); - - unreachable!(); } diff --git a/hal_aarch64/src/lib.rs b/hal_aarch64/src/lib.rs index 4033402f..36359160 100644 --- a/hal_aarch64/src/lib.rs +++ b/hal_aarch64/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![feature(once_cell)] #![feature(naked_functions)] use cortex_a::registers::*; @@ -13,6 +12,7 @@ pub mod mm; mod devices; +#[allow(dead_code)] #[derive(Debug)] pub struct PanicInfo { esr_el1: u64, diff --git a/hal_riscv64/src/irq.rs b/hal_riscv64/src/irq.rs index 2dd2bf37..f8603b88 100644 --- a/hal_riscv64/src/irq.rs +++ b/hal_riscv64/src/irq.rs @@ -7,7 +7,7 @@ use super::mm; use super::plic::Plic; use super::registers; -use riscv::asm::delay; + use core::arch::asm; use core::ptr; diff --git a/hal_riscv64/src/lib.rs b/hal_riscv64/src/lib.rs index 572ed448..84dfa306 100644 --- a/hal_riscv64/src/lib.rs +++ b/hal_riscv64/src/lib.rs @@ -1,7 +1,6 @@ #![no_std] #![feature(fn_align)] #![feature(naked_functions)] -#![feature(once_cell)] pub mod cpu; pub mod irq; diff --git a/hal_riscv64/src/mm/mod.rs b/hal_riscv64/src/mm/mod.rs index baed4868..449b0a8b 100644 --- a/hal_riscv64/src/mm/mod.rs +++ b/hal_riscv64/src/mm/mod.rs @@ -2,7 +2,7 @@ use core::arch::asm; use core::cell::OnceCell; use hal_core::{ - mm::{self, PageAllocFn, PageMap, Permissions, VAddr}, + mm::{PageAllocFn, PageMap}, Error, Range, }; diff --git a/hal_riscv64/src/mm/sv39.rs b/hal_riscv64/src/mm/sv39.rs index dfed7851..ac0c6dc6 100644 --- a/hal_riscv64/src/mm/sv39.rs +++ b/hal_riscv64/src/mm/sv39.rs @@ -1,5 +1,5 @@ -use core::arch::asm; -use core::convert::TryInto; + + use modular_bitfield::{bitfield, prelude::*}; use hal_core::mm::{self, PageAllocFn, PageEntry, PageMap}; @@ -93,9 +93,13 @@ impl PAddr { #[bitfield] pub struct PageTableEntry { v: B1, + #[skip(getters)] r: B1, + #[skip(getters)] w: B1, + #[skip(getters)] x: B1, + #[skip(getters)] u: B1, #[skip] g: B1, @@ -222,7 +226,7 @@ impl PageMap for PageTable { #[repr(u8)] pub(crate) enum SatpMode { - Bare = 0, + _Bare = 0, Sv39 = 8, _Sv48 = 9, _Sv57 = 10, diff --git a/hal_riscv64/src/plic.rs b/hal_riscv64/src/plic.rs index 5a847434..df10ec07 100644 --- a/hal_riscv64/src/plic.rs +++ b/hal_riscv64/src/plic.rs @@ -9,8 +9,6 @@ const PLIC_NUMBER_SOURCE_REGISTER: u16 = const PLIC_MAX_CONTEXT: u16 = 0x3e00; const PLIC_CLAIM_OFFSET: usize = 0x201004; -static mut PLIC: Option = None; - pub struct Plic { base_register_address: usize, } diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index d9d58bf8..53c05965 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -18,9 +18,9 @@ goblin = { version = "0.6", default-features = false, features = ["elf64"] } qemu-exit = "3.0" hal_core = { path = "../hal_core" } arrayvec = { version = "0.7", default-features = false } -tests = { path = "../tests", artifact = "bin" } align-data = "0.1" log = "0.4" +tests = { path = "../tests", artifact = "bin" } [dev-dependencies] diff --git a/kernel/src/error.rs b/kernel/src/error.rs index eefcfcf9..97c4398b 100644 --- a/kernel/src/error.rs +++ b/kernel/src/error.rs @@ -1,25 +1,16 @@ use super::mm; -use crate::utils::init_once; - #[derive(Debug)] pub enum Error { DeviceNotFound(&'static str), NoMatchingDriver(&'static str), InvalidFdtNode, FdtError(fdt::FdtError), - InitOnce(init_once::Error), Allocator(mm::AllocatorError), Hal(hal_core::Error), SetLoggerError(log::SetLoggerError), } -impl From for Error { - fn from(e: init_once::Error) -> Self { - Self::InitOnce(e) - } -} - impl From for Error { fn from(e: fdt::FdtError) -> Self { Self::FdtError(e) diff --git a/kernel/src/globals.rs b/kernel/src/globals.rs index 93c2dd73..401405ea 100644 --- a/kernel/src/globals.rs +++ b/kernel/src/globals.rs @@ -2,12 +2,12 @@ use crate::lock::Lock; use crate::mm; -use crate::drivers; -use crate::utils; -use utils::init_cell::InitCell; -use utils::init_once::InitOnce; -use alloc::sync::Arc; + + + + + pub static PHYSICAL_MEMORY_MANAGER: Lock = Lock::new(mm::PhysicalMemoryManager::new()); diff --git a/kernel/src/kernel_console.rs b/kernel/src/kernel_console.rs index 87e36a36..56762c61 100644 --- a/kernel/src/kernel_console.rs +++ b/kernel/src/kernel_console.rs @@ -5,7 +5,7 @@ use crate::Error; use alloc::sync::Arc; -use log::{error, Level, LevelFilter, Metadata, Record}; +use log::{Level, LevelFilter, Metadata, Record}; use spin::Mutex; struct KernelConsole { diff --git a/kernel/src/tests.rs b/kernel/src/tests.rs index add251f3..996cf48b 100644 --- a/kernel/src/tests.rs +++ b/kernel/src/tests.rs @@ -3,7 +3,7 @@ use log::{debug, info, trace}; use core::slice; use core::sync::atomic::{AtomicUsize, Ordering}; -use super::drivers::{pl011::Pl011, Console}; + use crate::executable::elf::Elf; use crate::hal; use crate::mm::{alloc_pages, alloc_pages_for_hal}; diff --git a/kernel/src/utils/init_cell.rs b/kernel/src/utils/init_cell.rs deleted file mode 100644 index 25526893..00000000 --- a/kernel/src/utils/init_cell.rs +++ /dev/null @@ -1,25 +0,0 @@ -use core::cell::UnsafeCell; - -pub struct InitCell { - data: UnsafeCell, -} - -impl InitCell { - pub const fn new(data: T) -> Self { - Self { - data: UnsafeCell::new(data), - } - } - - pub fn set<'a>(&'a self, f: impl FnOnce(&'a mut T)) { - let data = unsafe { &mut *self.data.get() }; - f(data) - } - - pub fn get(&self) -> &T { - unsafe { &*self.data.get() } - } -} - -unsafe impl Send for InitCell {} -unsafe impl Sync for InitCell {} diff --git a/kernel/src/utils/init_once.rs b/kernel/src/utils/init_once.rs deleted file mode 100644 index 7caf6458..00000000 --- a/kernel/src/utils/init_once.rs +++ /dev/null @@ -1,81 +0,0 @@ -use core::cell::UnsafeCell; -use core::sync::atomic::{self, AtomicBool}; - -#[derive(Debug)] -pub enum Error { - AlreadyInitialized, -} - -pub struct InitOnce { - locked: AtomicBool, - val: UnsafeCell>, -} - -impl InitOnce { - pub const fn new() -> Self { - Self { - locked: AtomicBool::new(false), - val: UnsafeCell::new(None), - } - } - - pub fn set(&self, val: T) -> Result<(), Error> { - if self.is_initialized() { - return Err(Error::AlreadyInitialized); - } - - while self - .locked - .compare_exchange( - false, - true, - atomic::Ordering::Acquire, - atomic::Ordering::Relaxed, - ) - .is_err() - {} - - // Safety: We hold exclusive access to the UnsafeCell. - unsafe { - *self.val.get() = Some(val); - } - - self.locked.store(false, atomic::Ordering::Release); - - Ok(()) - } - - pub fn is_initialized(&self) -> bool { - while self - .locked - .compare_exchange( - false, - true, - atomic::Ordering::Acquire, - atomic::Ordering::Relaxed, - ) - .is_err() - {} - - // Safety: We hold exclusive access to the UnsafeCell. - let initialized: bool = unsafe { &*self.val.get() }.is_some(); - - self.locked.store(false, atomic::Ordering::Release); - - initialized - } - - pub fn get<'a>(&'a self) -> Option<&'a T> { - if !self.is_initialized() { - return None; - } - - // Safety: We know it is initialized some the UnsafeCell MUST contain an Option that - // contains a value. - // Since that value is Sync, we can safely pass references to it. - let val: Option<&T> = unsafe { &*self.val.get() }.as_ref(); - val - } -} - -unsafe impl Sync for InitOnce {} diff --git a/kernel/src/utils/mod.rs b/kernel/src/utils/mod.rs index 68626033..101043bd 100644 --- a/kernel/src/utils/mod.rs +++ b/kernel/src/utils/mod.rs @@ -1,5 +1,5 @@ -pub mod init_cell; -pub mod init_once; +// pub mod init_cell; +// pub mod init_once; pub mod lock; // pub use init_cell; diff --git a/riscv64_qemuvirt/src/main.rs b/riscv64_qemuvirt/src/main.rs index 6a6870cb..c5f39505 100644 --- a/riscv64_qemuvirt/src/main.rs +++ b/riscv64_qemuvirt/src/main.rs @@ -1,19 +1,11 @@ #![no_std] #![no_main] #![feature(naked_functions)] -// #![feature(custom_test_frameworks)] -// #![test_runner(kernel::super::kernel_tests::runner)] -// #![reexport_test_harness_main = "ktests_launch"] #[cfg(not(target_arch = "riscv64"))] compile_error!("Must be compiled as riscv64"); -use core::arch::asm; use kernel::drivers::ns16550::*; -use kernel::drivers::qemuexit::QemuExit; -use kernel::executable::elf::Elf; - -use align_data::{include_aligned, Align4K}; use log::info; @@ -31,18 +23,8 @@ extern "C" fn k_main(_core_id: usize, device_tree_ptr: usize) -> ! { info!("GoOSe is booting"); - // #[cfg(test)] - // { - // kernel::kernel_tests::init(device_tree_ptr); - // ktests_launch(); - // } - - unsafe { - kernel::hal::irq::init_exception_handlers(); - } + kernel::hal::irq::init_exception_handlers(); let device_tree = kernel::device_tree::DeviceTree::new(device_tree_ptr).unwrap(); kernel::generic_main::generic_main::(device_tree, &[&NS16550]); - - unreachable!(); }