From f476a321de4a9aa8a4467675dd53690dc4a43d65 Mon Sep 17 00:00:00 2001 From: Daniel Maslowski Date: Wed, 27 Nov 2024 19:44:57 +0100 Subject: [PATCH] arm64: use aarch64-cpu crate Signed-off-by: Daniel Maslowski --- Cargo.lock | 16 ++++++++++++++++ aarch64/Cargo.toml | 1 + aarch64/src/registers.rs | 13 +++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6da4c4c..70768ce 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" @@ -324,6 +334,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/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 {