Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions src/arch/arm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use core::arch::asm;

/// Bit 7: IRQ disable bit in CPSR
const IRQ_DISABLE_BIT: usize = 1 << 7;

#[inline]
pub fn local_irq_save_and_disable() -> usize {
let flags: usize;
unsafe {
// Save CPSR and disable IRQs by setting the I bit
asm!(
"mrs {0}, cpsr",
"cpsid i",
out(reg) flags,
options(nomem, nostack, preserves_flags)
);
}
flags & IRQ_DISABLE_BIT
}

#[inline]
pub fn local_irq_restore(flags: usize) {
if flags & IRQ_DISABLE_BIT == 0 {
// IRQs were enabled before, re-enable them
unsafe {
asm!("cpsie i", options(nomem, nostack));
}
}
}
3 changes: 3 additions & 0 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ cfg_if::cfg_if! {
} else if #[cfg(target_arch = "loongarch64")] {
mod loongarch64;
pub use self::loongarch64::*;
} else if #[cfg(target_arch = "arm")] {
mod arm;
pub use self::arm::*;
}
}