Skip to content

Commit

Permalink
Add options to asm blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Sep 6, 2024
1 parent 1dc44c7 commit 50a4d9e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions aarch64-dit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ use core::arch::asm;
#[target_feature(enable = "dit")]
pub unsafe fn get_dit_enabled() -> bool {
let mut dit: u64;
asm!("mrs {dit}, DIT", dit = out(reg) dit);
asm!(
"mrs {dit}, DIT",
dit = out(reg) dit,
options(nomem, nostack, preserves_flags)
);
(dit >> 24) & 1 != 0
}

/// Enable DIT for the current thread.
#[target_feature(enable = "dit")]
pub unsafe fn set_dit_enabled() {
asm!("msr DIT, #1");
asm!("msr DIT, #1", options(nomem, nostack, preserves_flags));
}

/// Restore DIT state depending on the enabled bit.
#[target_feature(enable = "dit")]
pub unsafe fn restore_dit(enabled: bool) {
if !enabled {
// Disable DIT
asm!("msr DIT, #0");
asm!("msr DIT, #0", options(nomem, nostack, preserves_flags));
}
}

Expand Down

0 comments on commit 50a4d9e

Please sign in to comment.