PRIMASK controls whether maskable interrupts are permitted. Setting it disables them globally, unlike NVIC controls for individual interrupts. This can protect critical work, but is not the favored way to create critical sections. section 4.5.5 section 5.5.3
use core::arch::asm;
// asm!(): Writes 1 to PRIMASK via MSR, which masks all exceptions except NMI
// and HardFault.
#[inline(always)]
fn disable_interrupts() {
unsafe {
core::arch::asm!(
"msr PRIMASK, {reg}",
reg = in(reg) 1u32,
options(nomem, nostack),
);
}
}
This Rust inline-assembly example writes 1 to PRIMASK with MSR; the comment notes that NMI and HardFault remain unmasked. section 5.5.3
