diff --git a/Cargo.lock b/Cargo.lock index 7e6945bb..c2ab1e66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,12 +54,6 @@ dependencies = [ "spinning_top", ] -[[package]] -name = "array-init" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc" - [[package]] name = "arrayvec" version = "0.5.2" @@ -1050,7 +1044,6 @@ dependencies = [ "acpi", "align_ext", "aml", - "array-init", "bit_field", "bitflags 1.3.2", "bitvec", diff --git a/ostd/Cargo.toml b/ostd/Cargo.toml index 6fa985a1..edbbbd5b 100644 --- a/ostd/Cargo.toml +++ b/ostd/Cargo.toml @@ -16,7 +16,6 @@ targets = ["x86_64-unknown-none"] [dependencies] align_ext = { path = "libs/align_ext", version = "0.1.0" } -array-init = "2.0" bit_field = "0.10.1" buddy_system_allocator = "0.9.0" bitflags = "1.3" diff --git a/ostd/src/boot/smp.rs b/ostd/src/boot/smp.rs index b442cd97..33a52daa 100644 --- a/ostd/src/boot/smp.rs +++ b/ostd/src/boot/smp.rs @@ -15,7 +15,6 @@ use crate::{ page::{self, meta::KernelMeta, ContPages}, PAGE_SIZE, }, - trap, }; pub(crate) static AP_BOOT_INFO: Once = Once::new(); @@ -120,7 +119,10 @@ fn ap_early_entry(local_apic_id: u32) -> ! { cpu::set_this_cpu_id(local_apic_id); } - trap::init(); + // SAFETY: this function is only called once on this AP. + unsafe { + trapframe::init(); + } crate::arch::irq::enable_local(); // Mark the AP as started. diff --git a/ostd/src/lib.rs b/ostd/src/lib.rs index ff7a8096..b35bb245 100644 --- a/ostd/src/lib.rs +++ b/ostd/src/lib.rs @@ -86,7 +86,9 @@ pub unsafe fn init() { mm::kspace::init_kernel_page_table(mm::init_page_meta()); mm::misc_init(); - trap::init(); + trapframe::init(); + // SAFETY: This function is called only once in the entire system. + unsafe { trap::softirq::init() }; arch::init_on_bsp(); bus::init(); diff --git a/ostd/src/trap/mod.rs b/ostd/src/trap/mod.rs index 358cf045..3c99972b 100644 --- a/ostd/src/trap/mod.rs +++ b/ostd/src/trap/mod.rs @@ -12,10 +12,3 @@ pub use trapframe::TrapFrame; pub(crate) use self::handler::call_irq_callback_functions; pub use self::irq::{disable_local, DisabledLocalIrqGuard, IrqCallbackFunction, IrqLine}; - -pub(crate) fn init() { - unsafe { - trapframe::init(); - } - softirq::init(); -} diff --git a/ostd/src/trap/softirq.rs b/ostd/src/trap/softirq.rs index 3d9a136c..6efa8ec5 100644 --- a/ostd/src/trap/softirq.rs +++ b/ostd/src/trap/softirq.rs @@ -95,9 +95,14 @@ impl SoftIrqLine { /// A slice that stores the [`SoftIrqLine`]s, whose ID is equal to its offset in the slice. static LINES: Once<[SoftIrqLine; SoftIrqLine::NR_LINES as usize]> = Once::new(); -pub(super) fn init() { +/// Initializes the softirq lines. +/// +/// # Safety +/// +/// This function must be called only once. +pub unsafe fn init() { let lines: [SoftIrqLine; SoftIrqLine::NR_LINES as usize] = - array_init::array_init(|i| SoftIrqLine::new(i as u8)); + core::array::from_fn(|i| SoftIrqLine::new(i as u8)); LINES.call_once(|| lines); }