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

barrier functions wrap unsafe behaviour #47

Closed
wants to merge 1 commit into from
Closed
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
39 changes: 18 additions & 21 deletions src/asm/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@

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")]
() => {
core::arch::asm!(concat!("DMB ", stringify!($A)), options(nostack))
unsafe {
core::arch::asm!(concat!("DMB ", stringify!($A)), options(nostack))
}
}

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

#[cfg(not(target_arch = "aarch64"))]
Expand All @@ -64,11 +68,13 @@ 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"))]
Expand All @@ -77,33 +83,24 @@ impl sealed::Isb for SY {
}
}

/// # Safety
///
/// In your own hands, this is hardware land!
#[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!
#[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!
#[inline(always)]
pub unsafe fn isb<A>(arg: A)
pub fn isb<A>(arg: A)
where
A: sealed::Isb,
{
Expand Down