From c1435f6f35894865f4ad64f73bbe236e0cc260e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20C=C3=A1rdenas=20Rodr=C3=ADguez?= Date: Wed, 28 Oct 2026 10:25:33 +0900 Subject: [PATCH] feat(aarch64): remove awkernel_aarch64; move content to awkernel_lib --- Cargo.toml | 1 - README.md | 3 -- awkernel_aarch64/Cargo.toml | 8 ---- awkernel_drivers/Cargo.toml | 38 +++++++++---------- awkernel_drivers/src/ic/raspi/mbox.rs | 2 +- .../src/interrupt_controller/gicv3.rs | 26 ++++++------- awkernel_lib/Cargo.toml | 6 +-- awkernel_lib/src/arch/aarch64.rs | 2 + awkernel_lib/src/arch/aarch64/armv8_timer.rs | 8 ++-- awkernel_lib/src/arch/aarch64/barrier.rs | 2 +- .../src/arch/aarch64}/cache.rs | 2 +- awkernel_lib/src/arch/aarch64/cpu.rs | 4 +- awkernel_lib/src/arch/aarch64/delay.rs | 34 ++++++++--------- awkernel_lib/src/arch/aarch64/interrupt.rs | 6 +-- awkernel_lib/src/arch/aarch64/paging.rs | 4 +- .../src/arch/aarch64/utils.rs | 4 -- kernel/Cargo.toml | 5 --- kernel/src/arch/aarch64/exception.rs | 10 +++-- kernel/src/arch/aarch64/kernel_main.rs | 8 ++-- kernel/src/arch/aarch64/vm.rs | 2 +- mdbook/src/internal/arch/delay.md | 16 ++++---- mdbook/src/internal/arch/interrupt.md | 11 ++++-- 22 files changed, 92 insertions(+), 110 deletions(-) delete mode 100644 awkernel_aarch64/Cargo.toml rename {awkernel_aarch64/src => awkernel_lib/src/arch/aarch64}/cache.rs (97%) rename awkernel_aarch64/src/lib.rs => awkernel_lib/src/arch/aarch64/utils.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 1890a18c1..1af8a29a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ members = [ "awkernel_async_lib", "awkernel_async_lib_verified", "awkernel_lib", - "awkernel_aarch64", "awkernel_drivers", "applications/awkernel_services", "applications/awkernel_shell", diff --git a/README.md b/README.md index d24b011e5..9492550a3 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ $ cargo binstall mdbook-mermaid - [awkernel_macros](./awkernel_macros/) - `#[awkernel::main]` entry-point macro - [awkernel_drivers](./awkernel_drivers/) -- [awkernel_aarch64](./awkernel_aarch64/) - [userland](./userland/) - applications - [awkernel_shell](./applications/awkernel_shell/) @@ -53,13 +52,11 @@ $ cargo binstall mdbook-mermaid graph TD; awkernel_async_lib-->awkernel_async_lib_verified; awkernel_async_lib-->awkernel_futures_macro; - awkernel_lib-->awkernel_aarch64; awkernel_async_lib-->awkernel_lib; awkernel_lib-->awkernel_sync; userland-->awkernel_async_lib; kernel-->awkernel_lib; kernel-->awkernel_async_lib; - kernel-->awkernel_aarch64; kernel-->awkernel_drivers; awkernel_drivers-->awkernel_lib; userland-->kernel; diff --git a/awkernel_aarch64/Cargo.toml b/awkernel_aarch64/Cargo.toml deleted file mode 100644 index 69ac91289..000000000 --- a/awkernel_aarch64/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "awkernel_aarch64" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/awkernel_drivers/Cargo.toml b/awkernel_drivers/Cargo.toml index b596f06b6..e19849846 100644 --- a/awkernel_drivers/Cargo.toml +++ b/awkernel_drivers/Cargo.toml @@ -46,10 +46,6 @@ default-features = false [dependencies.awkernel_async_lib_verified] path = "../awkernel_async_lib_verified" -[dependencies.awkernel_aarch64] -path = "../awkernel_aarch64" -optional = true - [dependencies.bootloader_api] version = "0.11" optional = true @@ -73,12 +69,7 @@ features = [ default = [] x86 = ["awkernel_lib/x86", "dep:acpi", "dep:x86_64", "dep:bootloader_api"] rv32 = ["awkernel_lib/rv32"] -aarch64 = [ - "awkernel_lib/aarch64", - "dep:awkernel_aarch64", - "dep:embedded-hal", - "dep:embedded-hal-nb", -] +aarch64 = ["awkernel_lib/aarch64", "dep:embedded-hal", "dep:embedded-hal-nb"] spinlock = ["awkernel_lib/spinlock"] std = ["awkernel_lib/std"] @@ -99,12 +90,21 @@ genet = ["mii"] # Broadcom GENET for Raspberry Pi ## PCIe pcie = [] -all_pcie = ["pcie", "igb", "ixgbe", "igc", "rp1", "bcm2712", "virtio-net", "virtio-blk"] -igb = ["dep:memoffset"] # Intel Gigabit Ethernet -igc = [] # Intel 2.5 Gigabit Ethernet -ixgbe = ["dep:rand"] # Intel 10 Gigabit Ethernet -rp1 = [] # RP1 of Raspberry Pi 5 -bcm2712 = [] # Broadcom BCM2712 for Raspberry Pi 5 -virtio-net = [] # VirtIO Network Card -virtio-blk = [] # VirtIO Block Device -xhci = ["pcie"] # xHCI USB host controller +all_pcie = [ + "pcie", + "igb", + "ixgbe", + "igc", + "rp1", + "bcm2712", + "virtio-net", + "virtio-blk", +] +igb = ["dep:memoffset"] # Intel Gigabit Ethernet +igc = [] # Intel 2.5 Gigabit Ethernet +ixgbe = ["dep:rand"] # Intel 10 Gigabit Ethernet +rp1 = [] # RP1 of Raspberry Pi 5 +bcm2712 = [] # Broadcom BCM2712 for Raspberry Pi 5 +virtio-net = [] # VirtIO Network Card +virtio-blk = [] # VirtIO Block Device +xhci = ["pcie"] # xHCI USB host controller diff --git a/awkernel_drivers/src/ic/raspi/mbox.rs b/awkernel_drivers/src/ic/raspi/mbox.rs index 260fe7609..fe48aa2bf 100644 --- a/awkernel_drivers/src/ic/raspi/mbox.rs +++ b/awkernel_drivers/src/ic/raspi/mbox.rs @@ -3,7 +3,7 @@ //! Protocol details are as documented by the Mailbox property interface reference: //! -use awkernel_aarch64::cache::{clean_dcache_range, invalidate_dcache_range}; +use awkernel_lib::arch::aarch64::cache::{clean_dcache_range, invalidate_dcache_range}; use core::{ ptr::read_volatile, sync::atomic::{AtomicUsize, Ordering}, diff --git a/awkernel_drivers/src/interrupt_controller/gicv3.rs b/awkernel_drivers/src/interrupt_controller/gicv3.rs index 52d3d2339..69cab8fab 100644 --- a/awkernel_drivers/src/interrupt_controller/gicv3.rs +++ b/awkernel_drivers/src/interrupt_controller/gicv3.rs @@ -18,7 +18,7 @@ use alloc::{boxed::Box, collections::BTreeMap}; use awkernel_lib::{ addr::{virt_addr::VirtAddr, Addr}, - arch::aarch64::{current_affinity, get_affinity}, + arch::aarch64::{current_affinity, get_affinity, utils}, cpu::NUM_MAX_CPU, dma_pool::DMAPool, interrupt::InterruptController, @@ -283,9 +283,9 @@ impl GICv3 { wait_gicr_rwp(gicr_base); // Enable system register access. - let sre = awkernel_aarch64::icc_sre_el1::get(); + let sre = utils::icc_sre_el1::get(); if sre & 1 == 0 { - unsafe { awkernel_aarch64::icc_sre_el1::set(sre & 1) }; + unsafe { utils::icc_sre_el1::set(sre & 1) }; } registers::GICR_ISENABLER0.write(!0, sgi_base); @@ -312,17 +312,17 @@ impl GICv3 { /// EOImode (0): ICC_EOIR0 and ICC_EOIR1 provide both priority drop and interrupt deactivation functionality fn init_eoi_mode_zero() { let eoi_mode = 1 << 1; - let icc_ctlr = awkernel_aarch64::icc_ctlr_el1::get(); - unsafe { awkernel_aarch64::icc_ctlr_el1::set(icc_ctlr & !eoi_mode) }; + let icc_ctlr = utils::icc_ctlr_el1::get(); + unsafe { utils::icc_ctlr_el1::set(icc_ctlr & !eoi_mode) }; } /// Enable signaling of the interrupt group 1. fn enable_igrp() { - unsafe { awkernel_aarch64::icc_igrpen1_el1::set(1) }; + unsafe { utils::icc_igrpen1_el1::set(1) }; } fn init_priority_mask() { - unsafe { awkernel_aarch64::icc_pmr_el1::set(0xf0) }; + unsafe { utils::icc_pmr_el1::set(0xf0) }; } } @@ -389,7 +389,7 @@ impl InterruptController for GICv3 { return; }; - let (rs, target_list) = if (awkernel_aarch64::icc_ctlr_el1::get() & ICC_CTLR_RSS) != 0 + let (rs, target_list) = if (utils::icc_ctlr_el1::get() & ICC_CTLR_RSS) != 0 && registers::GICD_TYPER.read(self.gicd_base) & GICD_TYPER_RSS != 0 { // Targeted SGIs with affinity level 0 values of 0 - 255 are supported. @@ -406,7 +406,7 @@ impl InterruptController for GICv3 { | (aff1 as u64) << 16 | target_list; - unsafe { awkernel_aarch64::icc_sgi1r_el1::set(reg) } + unsafe { utils::icc_sgi1r_el1::set(reg) } } fn send_ipi_broadcast(&mut self, irq: u16) { @@ -417,9 +417,7 @@ impl InterruptController for GICv3 { fn send_ipi_broadcast_without_self(&mut self, irq: u16) { const ICC_SGI1R_EL1_IRM: u64 = 1 << 40; - unsafe { - awkernel_aarch64::icc_sgi1r_el1::set(ICC_SGI1R_EL1_IRM | ((irq as u64) & 0x0f) << 24) - } + unsafe { utils::icc_sgi1r_el1::set(ICC_SGI1R_EL1_IRM | ((irq as u64) & 0x0f) << 24) } } fn pending_irqs<'a>(&self) -> Box> { @@ -456,12 +454,12 @@ impl Iterator for PendingInterruptIterator { type Item = u16; fn next(&mut self) -> Option { - let id = awkernel_aarch64::icc_iar1_el1::get() as u16; + let id = utils::icc_iar1_el1::get() as u16; if id == ID_SPURIOUS { None } else { - unsafe { awkernel_aarch64::icc_eoir1_el1::set(id as u64) }; + unsafe { utils::icc_eoir1_el1::set(id as u64) }; Some(id) } } diff --git a/awkernel_lib/Cargo.toml b/awkernel_lib/Cargo.toml index 085e7f995..f58a11f93 100644 --- a/awkernel_lib/Cargo.toml +++ b/awkernel_lib/Cargo.toml @@ -51,10 +51,6 @@ optional = true version = "0.11" optional = true -[dependencies.awkernel_aarch64] -path = "../awkernel_aarch64" -optional = true - [dependencies.unwinding] version = "0.2" # git = "https://github.com/nbdd0121/unwinding.git" @@ -93,7 +89,7 @@ x86 = [ "awkernel_sync/x86", "awkernel_sync/x86_mwait", ] -aarch64 = ["dep:awkernel_aarch64", "awkernel_sync/aarch64"] +aarch64 = ["awkernel_sync/aarch64"] rv32 = ["dep:riscv", "awkernel_sync/rv32"] rv64 = ["dep:riscv", "awkernel_sync/rv64"] std = ["dep:libc", "dep:socket2", "awkernel_sync/std"] diff --git a/awkernel_lib/src/arch/aarch64.rs b/awkernel_lib/src/arch/aarch64.rs index 48cf58eda..07e1cddda 100644 --- a/awkernel_lib/src/arch/aarch64.rs +++ b/awkernel_lib/src/arch/aarch64.rs @@ -1,5 +1,6 @@ pub mod armv8_timer; pub mod barrier; +pub mod cache; pub(super) mod cpu; pub(super) mod delay; pub(super) mod dvfs; @@ -9,6 +10,7 @@ pub mod page_allocator; pub mod page_table; pub(super) mod paging; pub(super) mod power; +pub mod utils; pub use cpu::*; diff --git a/awkernel_lib/src/arch/aarch64/armv8_timer.rs b/awkernel_lib/src/arch/aarch64/armv8_timer.rs index da9e415fd..fa55e6403 100644 --- a/awkernel_lib/src/arch/aarch64/armv8_timer.rs +++ b/awkernel_lib/src/arch/aarch64/armv8_timer.rs @@ -57,7 +57,7 @@ impl Armv8Timer { impl crate::timer::Timer for Armv8Timer { fn reset(&self, dur: Duration) { - let hz = awkernel_aarch64::cntfrq_el0::get() as u128; + let hz = super::utils::cntfrq_el0::get() as u128; let ns = dur.as_nanos(); @@ -69,8 +69,8 @@ impl crate::timer::Timer for Armv8Timer { }; unsafe { - awkernel_aarch64::cntv_tval_el0::set(tval); - awkernel_aarch64::cntv_ctl_el0::set(1); // Enable interrupt. + super::utils::cntv_tval_el0::set(tval); + super::utils::cntv_ctl_el0::set(1); // Enable interrupt. } } @@ -79,6 +79,6 @@ impl crate::timer::Timer for Armv8Timer { } fn disable(&self) { - unsafe { awkernel_aarch64::cntv_ctl_el0::set(0) }; + unsafe { super::utils::cntv_ctl_el0::set(0) }; } } diff --git a/awkernel_lib/src/arch/aarch64/barrier.rs b/awkernel_lib/src/arch/aarch64/barrier.rs index 3ce117d40..c75e1b099 100644 --- a/awkernel_lib/src/arch/aarch64/barrier.rs +++ b/awkernel_lib/src/arch/aarch64/barrier.rs @@ -1,5 +1,5 @@ //! Memory barrier implementations for AArch64 architecture -use awkernel_aarch64::{dmb_ld, dmb_st, dmb_sy}; +use super::utils::{dmb_ld, dmb_st, dmb_sy}; pub const BUS_SPACE_BARRIER_READ: u32 = 0x01; pub const BUS_SPACE_BARRIER_WRITE: u32 = 0x02; diff --git a/awkernel_aarch64/src/cache.rs b/awkernel_lib/src/arch/aarch64/cache.rs similarity index 97% rename from awkernel_aarch64/src/cache.rs rename to awkernel_lib/src/arch/aarch64/cache.rs index 839bbe8c8..74effc9f8 100644 --- a/awkernel_aarch64/src/cache.rs +++ b/awkernel_lib/src/arch/aarch64/cache.rs @@ -1,6 +1,6 @@ //! Data cache maintenance by virtual address. -use crate::{ctr_el0, dsb_sy}; +use super::utils::{ctr_el0, dsb_sy}; use core::arch::asm; /// Smallest D-cache line size, in bytes, as reported by `CTR_EL0.DminLine`. diff --git a/awkernel_lib/src/arch/aarch64/cpu.rs b/awkernel_lib/src/arch/aarch64/cpu.rs index 74364a555..bf65c775b 100644 --- a/awkernel_lib/src/arch/aarch64/cpu.rs +++ b/awkernel_lib/src/arch/aarch64/cpu.rs @@ -1,5 +1,5 @@ +use super::utils::mpidr_el1; use crate::cpu::{CPU, NUM_MAX_CPU}; -use awkernel_aarch64::mpidr_el1; #[no_mangle] pub static mut AFF0_MAX: u64 = 0; @@ -73,7 +73,7 @@ pub const AFF0_MASK: u64 = 0xff; /// Get the current CPU affinity. pub fn current_affinity() -> (u8, u8, u8, u8) { - let mpidr_el1 = awkernel_aarch64::mpidr_el1::get(); + let mpidr_el1 = mpidr_el1::get(); ( ((mpidr_el1 & AFF3_MASK) >> 32) as u8, ((mpidr_el1 & AFF2_MASK) >> 16) as u8, diff --git a/awkernel_lib/src/arch/aarch64/delay.rs b/awkernel_lib/src/arch/aarch64/delay.rs index 03f865d1d..7886c2c0e 100644 --- a/awkernel_lib/src/arch/aarch64/delay.rs +++ b/awkernel_lib/src/arch/aarch64/delay.rs @@ -10,21 +10,21 @@ impl Delay for super::AArch64 { } fn wait_microsec(usec: u64) { - let frq = awkernel_aarch64::cntfrq_el0::get(); - let t = awkernel_aarch64::cntvct_el0::get(); + let frq = super::utils::cntfrq_el0::get(); + let t = super::utils::cntvct_el0::get(); let end = t + ((frq / 1000) * usec) / 1000; - while awkernel_aarch64::cntvct_el0::get() < end { - awkernel_aarch64::isb(); + while super::utils::cntvct_el0::get() < end { + super::utils::isb(); } } fn uptime() -> u64 { let start = unsafe { read_volatile(addr_of!(COUNT_START)) }; - let frq = awkernel_aarch64::cntfrq_el0::get(); - let now = awkernel_aarch64::cntvct_el0::get(); + let frq = super::utils::cntfrq_el0::get(); + let now = super::utils::cntvct_el0::get(); let diff = now - start; @@ -34,8 +34,8 @@ impl Delay for super::AArch64 { fn uptime_nano() -> u128 { let start = unsafe { read_volatile(addr_of!(COUNT_START)) }; - let frq = awkernel_aarch64::cntfrq_el0::get(); - let now = awkernel_aarch64::cntvct_el0::get(); + let frq = super::utils::cntfrq_el0::get(); + let now = super::utils::cntvct_el0::get(); let diff = now - start; @@ -43,35 +43,35 @@ impl Delay for super::AArch64 { } fn cpu_counter() -> u64 { - awkernel_aarch64::pmccntr_el0::get() + super::utils::pmccntr_el0::get() } } pub(super) unsafe fn init_primary() { init_pmc(); - let count = awkernel_aarch64::cntvct_el0::get(); + let count = super::utils::cntvct_el0::get(); write_volatile(addr_of_mut!(COUNT_START), count); } /// Initialize performance monitor counter. unsafe fn init_pmc() { // Enable user-mode access to cycle counters. - awkernel_aarch64::pmuserenr_el0::set(0b1101); + super::utils::pmuserenr_el0::set(0b1101); // Disable the cycle counter overflow interrupt. - awkernel_aarch64::pmintenset_el1::set(0); + super::utils::pmintenset_el1::set(0); // Enable the cycle counter. - awkernel_aarch64::pmcntenset_el0::set(1 << 31); + super::utils::pmcntenset_el0::set(1 << 31); // Clear the cycle counter and start. - let pmcr_el0 = awkernel_aarch64::pmcr_el0::get(); + let pmcr_el0 = super::utils::pmcr_el0::get(); let pmcr_el0 = pmcr_el0 | 0b111; - awkernel_aarch64::isb(); - awkernel_aarch64::pmcr_el0::set(pmcr_el0); + super::utils::isb(); + super::utils::pmcr_el0::set(pmcr_el0); - awkernel_aarch64::pmccfiltr_el0::set(1 << 27); + super::utils::pmccfiltr_el0::set(1 << 27); } pub(super) unsafe fn init_non_primary() { diff --git a/awkernel_lib/src/arch/aarch64/interrupt.rs b/awkernel_lib/src/arch/aarch64/interrupt.rs index 6fb55d5e8..745cf7e4b 100644 --- a/awkernel_lib/src/arch/aarch64/interrupt.rs +++ b/awkernel_lib/src/arch/aarch64/interrupt.rs @@ -2,7 +2,7 @@ use crate::interrupt::Interrupt; impl Interrupt for super::AArch64 { fn get_flag() -> usize { - awkernel_aarch64::daif::get() as usize + super::utils::daif::get() as usize } fn disable() { @@ -14,11 +14,11 @@ impl Interrupt for super::AArch64 { } fn are_enabled() -> bool { - let daif = awkernel_aarch64::daif::get(); + let daif = super::utils::daif::get(); (daif & (1 << 7)) == 0 } fn set_flag(flag: usize) { - unsafe { awkernel_aarch64::daif::set(flag as u64) }; + unsafe { super::utils::daif::set(flag as u64) }; } } diff --git a/awkernel_lib/src/arch/aarch64/paging.rs b/awkernel_lib/src/arch/aarch64/paging.rs index eacb0f6a2..24f5e5e44 100644 --- a/awkernel_lib/src/arch/aarch64/paging.rs +++ b/awkernel_lib/src/arch/aarch64/paging.rs @@ -74,9 +74,9 @@ impl crate::paging::Mapper for super::AArch64 { fn get_page_table(vm_addr: VirtAddr) -> PageTable { let ttbr = if vm_addr.as_usize() >= TTBR1_ADDR { - awkernel_aarch64::ttbr1_el1::get() & !1 + super::utils::ttbr1_el1::get() & !1 } else { - awkernel_aarch64::ttbr0_el1::get() & !1 + super::utils::ttbr0_el1::get() & !1 }; unsafe { PageTable::with_root(PhyAddr::new(ttbr as usize)) } diff --git a/awkernel_aarch64/src/lib.rs b/awkernel_lib/src/arch/aarch64/utils.rs similarity index 99% rename from awkernel_aarch64/src/lib.rs rename to awkernel_lib/src/arch/aarch64/utils.rs index 33ed1c490..6f6cb9de3 100644 --- a/awkernel_aarch64/src/lib.rs +++ b/awkernel_lib/src/arch/aarch64/utils.rs @@ -1,7 +1,3 @@ -#![no_std] - -pub mod cache; - use core::arch::asm; pub const ECTLR_SMP_BIT: u64 = 1 << 6; diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index b65065e90..c5997e1b7 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -58,10 +58,6 @@ default-features = false path = "../awkernel_drivers" default-features = false -[dependencies.awkernel_aarch64] -path = "../awkernel_aarch64" -optional = true - [dependencies.x86_64] version = "0.15" optional = true @@ -119,7 +115,6 @@ std = ["perf", "awkernel_lib/std", "awkernel_async_lib/std", "dep:libc"] aarch64 = [ "perf", "no_std_unwinding", - "dep:awkernel_aarch64", "awkernel_lib/aarch64", "awkernel_drivers/aarch64", ] diff --git a/kernel/src/arch/aarch64/exception.rs b/kernel/src/arch/aarch64/exception.rs index b25e80a64..238f83eea 100644 --- a/kernel/src/arch/aarch64/exception.rs +++ b/kernel/src/arch/aarch64/exception.rs @@ -1,5 +1,7 @@ use awkernel_lib::{ - arch::aarch64::exception_saved_regs::Context, console::unsafe_puts, delay::wait_forever, + arch::aarch64::{exception_saved_regs::Context, utils}, + console::unsafe_puts, + delay::wait_forever, interrupt, }; use core::str::from_utf8_unchecked; @@ -16,17 +18,17 @@ const _ESR_LE1_EC_DATA_KERN: u64 = 0b100101 << 26; pub extern "C" fn handle_data_abort() { unsafe { unsafe_puts("data abort\r\n") }; - let sp = awkernel_aarch64::get_sp(); + let sp = utils::get_sp(); unsafe { unsafe_puts("SP = 0x") }; print_hex(sp); unsafe { unsafe_puts("\r\n") }; - let elr = awkernel_aarch64::elr_el1::get(); + let elr = utils::elr_el1::get(); unsafe { unsafe_puts("ELR = 0x") }; print_hex(elr); unsafe { unsafe_puts("\r\n") }; - let far = awkernel_aarch64::far_el1::get(); + let far = utils::far_el1::get(); unsafe { unsafe_puts("FAR = 0x") }; print_hex(far); unsafe { unsafe_puts("\r\n") }; diff --git a/kernel/src/arch/aarch64/kernel_main.rs b/kernel/src/arch/aarch64/kernel_main.rs index 4b6fb8734..778d3d1c4 100644 --- a/kernel/src/arch/aarch64/kernel_main.rs +++ b/kernel/src/arch/aarch64/kernel_main.rs @@ -12,8 +12,8 @@ use crate::{ config::{BACKUP_HEAP_SIZE, DMA_SIZE, HEAP_START}, kernel_info::KernelInfo, }; -use awkernel_aarch64::{dsb_ish, dsb_ishst, dsb_sy, isb, tlbi_vmalle1is}; use awkernel_lib::{ + arch::aarch64::utils::{self, dsb_ish, dsb_ishst, dsb_sy, isb, spsel, tlbi_vmalle1is}, console::{unsafe_print_hex_u32, unsafe_puts}, delay::wait_forever, dma_pool, heap, @@ -40,7 +40,7 @@ static mut TTBR0_EL1: usize = 0; /// The entry point from `boot.S`. #[no_mangle] pub unsafe extern "C" fn kernel_main(device_tree_base: usize) -> ! { - awkernel_aarch64::init_cpacr_el1(); // Enable floating point numbers. + utils::init_cpacr_el1(); // Enable floating point numbers. awkernel_lib::delay::wait_millisec(10); @@ -73,7 +73,7 @@ unsafe fn primary_cpu(device_tree_base: usize) { wait_forever(); } - match awkernel_aarch64::get_current_el() { + match utils::get_current_el() { 0 => unsafe_puts("EL0\r\n"), 1 => unsafe_puts("EL1\r\n"), 2 => unsafe_puts("EL2\r\n"), @@ -165,7 +165,7 @@ unsafe fn primary_cpu(device_tree_base: usize) { backup_size >> 20 ); - if awkernel_aarch64::spsel::get() & 1 == 0 { + if spsel::get() & 1 == 0 { log::info!("Use SP_EL0."); } else { log::info!("Use SP_ELx."); diff --git a/kernel/src/arch/aarch64/vm.rs b/kernel/src/arch/aarch64/vm.rs index 6b8f6373e..43dc8105e 100644 --- a/kernel/src/arch/aarch64/vm.rs +++ b/kernel/src/arch/aarch64/vm.rs @@ -1,5 +1,4 @@ use crate::arch::config::HEAP_START; -use awkernel_aarch64::{dmb_sy, id_aa64mmfr0_el1, isb, sctlr_el1}; use awkernel_lib::{ addr::{phy_addr::PhyAddr, virt_addr::VirtAddr, Addr}, arch::aarch64::{ @@ -8,6 +7,7 @@ use awkernel_lib::{ self, flags::{self, FLAG_L3_CONT}, }, + utils::{dmb_sy, id_aa64mmfr0_el1, isb, sctlr_el1}, }, console::{unsafe_print_hex_u32, unsafe_print_hex_u64, unsafe_puts}, cpu::num_cpu, diff --git a/mdbook/src/internal/arch/delay.md b/mdbook/src/internal/arch/delay.md index 8677d94c9..8d7959563 100644 --- a/mdbook/src/internal/arch/delay.md +++ b/mdbook/src/internal/arch/delay.md @@ -108,7 +108,7 @@ To get the cpu cycle counter, Awkernel uses the `_rdtsc` instruction. ## AArch64 -For x86_64, the [`AArch64`](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64.rs) structure implements the `Delay` trait in [awkernel_lib/src/arch/aarch64/delay.rs](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64/delay.rs) as follows. +For aarch64, the [`AArch64`](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64.rs) structure implements the `Delay` trait in [awkernel_lib/src/arch/aarch64/delay.rs](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64/delay.rs) as follows. ```rust impl Delay for super::AArch64 { @@ -117,21 +117,21 @@ impl Delay for super::AArch64 { } fn wait_microsec(usec: u64) { - let frq = awkernel_aarch64::cntfrq_el0::get(); - let t = awkernel_aarch64::cntvct_el0::get(); + let frq = super::utils::cntfrq_el0::get(); + let t = super::utils::cntvct_el0::get(); let end = t + ((frq / 1000) * usec) / 1000; - while awkernel_aarch64::cntvct_el0::get() < end { - awkernel_aarch64::isb(); + while super::utils::cntvct_el0::get() < end { + super::utils::isb(); } } fn uptime() -> u64 { let start = unsafe { read_volatile(addr_of!(COUNT_START)) }; - let frq = awkernel_aarch64::cntfrq_el0::get(); - let now = awkernel_aarch64::cntvct_el0::get(); + let frq = super::utils::cntfrq_el0::get(); + let now = super::utils::cntvct_el0::get(); let diff = now - start; @@ -139,7 +139,7 @@ impl Delay for super::AArch64 { } fn cpu_counter() -> u64 { - awkernel_aarch64::pmccntr_el0::get() + super::utils::pmccntr_el0::get() } } ``` diff --git a/mdbook/src/internal/arch/interrupt.md b/mdbook/src/internal/arch/interrupt.md index 320a6088d..1111ea6b4 100644 --- a/mdbook/src/internal/arch/interrupt.md +++ b/mdbook/src/internal/arch/interrupt.md @@ -70,12 +70,12 @@ For x86_64, Awkernel uses the [`x86_64`](https://docs.rs/x86_64/latest/x86_64/in ## AArch64 -For x86_64, the [`AArch64`](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64.rs) structure implements the `Interrupt` trait in [awkernel_lib/src/arch/aarch64/interrupt.rs](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64/interrupt.rs) as follows. +For aarch64, the [`AArch64`](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64.rs) structure implements the `Interrupt` trait in [awkernel_lib/src/arch/aarch64/interrupt.rs](https://github.com/tier4/awkernel/blob/main/awkernel_lib/src/arch/aarch64/interrupt.rs) as follows. ```rust impl Interrupt for super::AArch64 { fn get_flag() -> usize { - awkernel_aarch64::daif::get() as usize + super::utils::daif::get() as usize } fn disable() { @@ -86,8 +86,13 @@ impl Interrupt for super::AArch64 { unsafe { core::arch::asm!("msr daifclr, #0b0010",) }; } + fn are_enabled() -> bool { + let daif = super::utils::daif::get(); + (daif & (1 << 7)) == 0 + } + fn set_flag(flag: usize) { - unsafe { awkernel_aarch64::daif::set(flag as u64) }; + unsafe { super::utils::daif::set(flag as u64) }; } } ```