Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Remove unsafe from barrier instructions #48

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 17 additions & 25 deletions src/asm/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@

mod sealed {
pub trait Dmb {
unsafe fn __dmb(&self);
fn __dmb(&self);
}

pub trait Dsb {
unsafe fn __dsb(&self);
fn __dsb(&self);
}

pub trait Isb {
unsafe fn __isb(&self);
fn __isb(&self);
}
}

macro_rules! dmb_dsb {
($A:ident) => {
impl sealed::Dmb for $A {
#[inline(always)]
unsafe fn __dmb(&self) {
fn __dmb(&self) {
match () {
#[cfg(target_arch = "aarch64")]
() => {
() => unsafe {
core::arch::asm!(concat!("DMB ", stringify!($A)), options(nostack))
}
},

#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
Expand All @@ -39,12 +39,12 @@ macro_rules! dmb_dsb {
}
impl sealed::Dsb for $A {
#[inline(always)]
unsafe fn __dsb(&self) {
fn __dsb(&self) {
match () {
#[cfg(target_arch = "aarch64")]
() => {
() => unsafe {
core::arch::asm!(concat!("DSB ", stringify!($A)), options(nostack))
}
},

#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
Expand All @@ -64,46 +64,38 @@ dmb_dsb!(SY);

impl sealed::Isb for SY {
#[inline(always)]
unsafe fn __isb(&self) {
fn __isb(&self) {
match () {
#[cfg(target_arch = "aarch64")]
() => {
core::arch::asm!("ISB SY", options(nostack))
}
() => unsafe { core::arch::asm!("ISB SY", options(nostack)) },

#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
}
}
}

/// # Safety
///
/// In your own hands, this is hardware land!
/// Data Memory Barrier.
#[inline(always)]
pub unsafe fn dmb<A>(arg: A)
pub fn dmb<A>(arg: A)
where
A: sealed::Dmb,
{
arg.__dmb()
}

/// # Safety
///
/// In your own hands, this is hardware land!
/// Data Synchronization Barrier.
#[inline(always)]
pub unsafe fn dsb<A>(arg: A)
pub fn dsb<A>(arg: A)
where
A: sealed::Dsb,
{
arg.__dsb()
}

/// # Safety
///
/// In your own hands, this is hardware land!
/// Instruction Synchronization Barrier.
#[inline(always)]
pub unsafe fn isb<A>(arg: A)
pub fn isb<A>(arg: A)
where
A: sealed::Isb,
{
Expand Down