From 5826d58cdcd21de12c3880f3fb01404e7b1727c6 Mon Sep 17 00:00:00 2001 From: Martin Schmidt Date: Mon, 29 Jul 2024 18:45:25 +0200 Subject: [PATCH] remove unused code --- hal_aarch64/src/irq.rs | 2 +- hal_aarch64/src/mm/mod.rs | 46 --------------------------------------- hal_riscv64/src/cpu.rs | 12 ---------- hal_riscv64/src/irq.rs | 15 +++++++------ hal_riscv64/src/lib.rs | 1 - hal_riscv64/src/mm/mod.rs | 43 ------------------------------------ hal_riscv64/src/plic.rs | 1 + 7 files changed, 10 insertions(+), 110 deletions(-) delete mode 100644 hal_riscv64/src/cpu.rs diff --git a/hal_aarch64/src/irq.rs b/hal_aarch64/src/irq.rs index 53f5a62d..46ac3a1f 100644 --- a/hal_aarch64/src/irq.rs +++ b/hal_aarch64/src/irq.rs @@ -184,7 +184,7 @@ impl Aarch64Irqs { impl IrqOps for Aarch64Irqs { fn init(&'static self) { cortex_a::registers::VBAR_EL1.set(el1_vector_table as u64); - unsafe { IRQS.set(self).expect("looks like init has already been called") }; + IRQS.set(self).expect("looks like init has already been called"); } fn init_irq_chip(&self, _allocator: &impl PageAlloc) -> Result<(), Error> { diff --git a/hal_aarch64/src/mm/mod.rs b/hal_aarch64/src/mm/mod.rs index 721ad939..793f4bb1 100644 --- a/hal_aarch64/src/mm/mod.rs +++ b/hal_aarch64/src/mm/mod.rs @@ -1,47 +1 @@ -use hal_core::{ - mm::{self, PageAlloc, PageMap}, - AddressRange, Error, -}; - pub mod pgt48; - -use pgt48::PageTable; - -pub type EntryType = usize; - -pub const PAGE_SIZE: usize = PageTable::PAGE_SIZE; - -use core::cell::OnceCell; - -static mut GPT: OnceCell<&'static mut PageTable> = OnceCell::new(); - -pub fn is_pagetable_installed() -> bool { - unsafe { GPT.get_mut().is_some() } -} - -pub fn prefill_pagetable( - r: impl Iterator, - rw: impl Iterator, - rwx: impl Iterator, - pre_allocated: impl Iterator, - allocator: &impl PageAlloc, -) -> Result<(), Error> { - let pt = hal_core::mm::prefill_pagetable::(r, rw, rwx, pre_allocated, allocator)?; - - // TODO: put into into the hal_core::Error - unsafe { - if GPT.set(pt).is_err() { - panic!("GPT is already set ?"); - } - }; - - Ok(()) -} - -pub fn align_up(addr: usize) -> usize { - mm::align_up(addr, PAGE_SIZE) -} - -pub fn align_down(addr: usize) -> usize { - mm::align_down(addr, PAGE_SIZE) -} diff --git a/hal_riscv64/src/cpu.rs b/hal_riscv64/src/cpu.rs deleted file mode 100644 index 5f6e4717..00000000 --- a/hal_riscv64/src/cpu.rs +++ /dev/null @@ -1,12 +0,0 @@ -use super::registers; - -pub fn unmask_interrupts() { - registers::set_sstatus_sie(); - registers::set_sie_ssie(); - registers::set_sie_seie(); - registers::set_sie_stie(); -} - -pub fn clear_physical_timer() { - sbi::timer::set_timer(u64::MAX).unwrap(); -} diff --git a/hal_riscv64/src/irq.rs b/hal_riscv64/src/irq.rs index 098a8fcf..3bb732cb 100644 --- a/hal_riscv64/src/irq.rs +++ b/hal_riscv64/src/irq.rs @@ -1,5 +1,5 @@ use hal_core::{ - mm::{PageAlloc, PageMap, Permissions, VAddr}, + mm::PageAlloc, Error, TimerCallbackFn, IrqOps, once_lock::OnceLock, @@ -7,10 +7,8 @@ use hal_core::{ use log; -use super::mm; use super::plic::Plic; use super::registers; -use super::cpu; use core::arch::asm; use core::ptr; @@ -21,6 +19,7 @@ use sbi; static IRQS: OnceLock<&Riscv64Irqs> = OnceLock::new(); +#[derive(Debug)] pub struct Riscv64Irqs { irq_chip: OnceLock, timer_callback: AtomicPtr, @@ -31,17 +30,20 @@ unsafe impl Sync for Riscv64Irqs {} impl IrqOps for Riscv64Irqs { fn init(&'static self) { registers::set_stvec(asm_trap_handler as usize); - IRQS.set(self); + IRQS.set(self).expect("Looks like Riscv64Irqs::init has already been called, must only be called once !"); } fn unmask_interrupts(&self) { - cpu::unmask_interrupts(); + registers::set_sstatus_sie(); + registers::set_sie_ssie(); + registers::set_sie_seie(); + registers::set_sie_stie(); } fn init_irq_chip(&self, _allocator: &impl PageAlloc) -> Result<(), Error> { let base = 0xc000000; - self.irq_chip.set(Plic::new(base)); + self.irq_chip.set(Plic::new(base)).expect("Riscv64Irqs has already been called"); Ok(()) } @@ -91,7 +93,6 @@ impl Riscv64Irqs { e => panic!("getting caught by unhandler exception {:?}", e), } } - } #[derive(Debug, Copy, Clone)] diff --git a/hal_riscv64/src/lib.rs b/hal_riscv64/src/lib.rs index 60e0568b..e04deb0d 100644 --- a/hal_riscv64/src/lib.rs +++ b/hal_riscv64/src/lib.rs @@ -2,7 +2,6 @@ #![feature(fn_align)] #![feature(naked_functions)] -pub mod cpu; pub mod irq; pub mod mm; mod plic; diff --git a/hal_riscv64/src/mm/mod.rs b/hal_riscv64/src/mm/mod.rs index acad6407..e128b8c1 100644 --- a/hal_riscv64/src/mm/mod.rs +++ b/hal_riscv64/src/mm/mod.rs @@ -1,44 +1 @@ -use core::arch::asm; -use core::cell::OnceCell; -use hal_core::{ - mm::{self, PageAlloc, PageMap}, - AddressRange, Error, -}; - pub mod sv39; -use sv39::{PageTable, Satp, SatpMode}; - -pub const PAGE_SIZE: usize = PageTable::PAGE_SIZE; - -static mut GPT: OnceCell<&'static mut PageTable> = OnceCell::new(); - -pub fn current() -> &'static mut PageTable { - unsafe { GPT.get_mut().unwrap() } -} - -pub fn prefill_pagetable( - r: impl Iterator, - rw: impl Iterator, - rwx: impl Iterator, - pre_allocated: impl Iterator, - allocator: &impl PageAlloc, -) -> Result<(), Error> { - let pt = hal_core::mm::prefill_pagetable::(r, rw, rwx, pre_allocated, allocator)?; - - // TODO: put into into the hal_core::Error - unsafe { - if GPT.set(pt).is_err() { - panic!("GPT is already set ?"); - } - }; - - Ok(()) -} - -pub fn align_down(addr: usize) -> usize { - mm::align_down(addr, PageTable::PAGE_SIZE) -} - -pub fn align_up(addr: usize) -> usize { - mm::align_up(addr, PageTable::PAGE_SIZE) -} diff --git a/hal_riscv64/src/plic.rs b/hal_riscv64/src/plic.rs index df10ec07..645a4b89 100644 --- a/hal_riscv64/src/plic.rs +++ b/hal_riscv64/src/plic.rs @@ -9,6 +9,7 @@ const PLIC_NUMBER_SOURCE_REGISTER: u16 = const PLIC_MAX_CONTEXT: u16 = 0x3e00; const PLIC_CLAIM_OFFSET: usize = 0x201004; +#[derive(Debug)] pub struct Plic { base_register_address: usize, }