diff --git a/Cargo.lock b/Cargo.lock index ea85257..9d6d75c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,11 +6,21 @@ version = 4 name = "aarch64" version = "0.1.0" dependencies = [ + "aarch64-cpu", "bitstruct", "num_enum", "port", ] +[[package]] +name = "aarch64-cpu" +version = "9.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac42a04a61c19fc8196dd728022a784baecc5d63d7e256c01ad1b3fbfab26287" +dependencies = [ + "tock-registers", +] + [[package]] name = "anstream" version = "0.6.15" @@ -308,6 +318,12 @@ version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" +[[package]] +name = "tock-registers" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "696941a0aee7e276a165a978b37918fd5d22c55c3d6bda197813070ca9c0f21c" + [[package]] name = "toml" version = "0.8.19" diff --git a/aarch64/Cargo.toml b/aarch64/Cargo.toml index 5d96155..93af126 100644 --- a/aarch64/Cargo.toml +++ b/aarch64/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" default-target = "aarch64-unknown-none" [dependencies] +aarch64-cpu = "9.4.0" bitstruct = "0.1" port = { path = "../port" } num_enum = { version = "0.7", default-features = false } diff --git a/aarch64/src/main.rs b/aarch64/src/main.rs index f568900..b2bfee9 100644 --- a/aarch64/src/main.rs +++ b/aarch64/src/main.rs @@ -22,6 +22,7 @@ mod vm; use crate::kmem::from_virt_to_physaddr; use crate::vm::kernel_root; + use core::ffi::c_void; use core::ptr; use port::fdt::DeviceTree; @@ -125,6 +126,7 @@ pub extern "C" fn main9(dtb_va: usize) { println!("r9 from the Internet"); println!("DTB found at: {:#x}", dtb_va); println!("midr_el1: {:?}", registers::MidrEl1::read()); + // registers::CNTVOFF_EL2.set(0); print_binary_sections(); print_physical_memory_info(); diff --git a/aarch64/src/registers.rs b/aarch64/src/registers.rs index 65421aa..221a5c2 100644 --- a/aarch64/src/registers.rs +++ b/aarch64/src/registers.rs @@ -1,5 +1,7 @@ #![allow(non_upper_case_globals)] +use aarch64_cpu::registers::{Readable, Writeable}; +use aarch64_cpu::{asm, registers::MIDR_EL1}; use bitstruct::bitstruct; use core::fmt; use num_enum::TryFromPrimitive; @@ -46,16 +48,7 @@ bitstruct! { impl MidrEl1 { pub fn read() -> Self { - #[cfg(not(test))] - { - let mut value: u64; - unsafe { - core::arch::asm!("mrs {value}, midr_el1", value = out(reg) value); - } - Self(value) - } - #[cfg(test)] - Self(0) + Self(if cfg!(test) { 0 } else { MIDR_EL1.extract().into() }) } pub fn partnum_enum(&self) -> Result {