From d3b3d5d462261606afd979fc909c0e3819417a6a Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 10 Apr 2024 00:01:27 +0100 Subject: [PATCH] bolts: add time ticks method for arm (#2032) --- libafl_bolts/src/cpu.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libafl_bolts/src/cpu.rs b/libafl_bolts/src/cpu.rs index c8be696d02..d885d84ceb 100644 --- a/libafl_bolts/src/cpu.rs +++ b/libafl_bolts/src/cpu.rs @@ -1,12 +1,13 @@ //! Architecture agnostic processor features -#[cfg(target_arch = "aarch64")] +#[cfg(any(target_arch = "aarch64", target_arch = "arm"))] use core::arch::asm; #[cfg(not(any( target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64", + target_arch = "arm", target_arch = "riscv64", target_arsch = "riscv32" )))] @@ -50,6 +51,16 @@ pub fn read_time_counter() -> u64 { v } +#[cfg(target_arch = "arm")] +#[must_use] +pub fn read_time_counter() -> u64 { + let mut v: u32; + unsafe { + asm!("mrc p15, 0, {v}, c9, c13, 0", v = out(reg) v); + } + u64::from(v) +} + /// Read a timestamp for measurements /// /// Fetches the full 64 bits of the cycle counter in one instruction. @@ -99,6 +110,7 @@ pub fn read_time_counter() -> u64 { target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64", + target_arch = "arm", target_arch = "riscv64", target_arch = "riscv32" )))]