-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Refs: | ||
// - Xtensa Instruction Set Architecture (ISA) Reference Manual https://0x04.net/~mwk/doc/xtensa.pdf | ||
// - Linux kernel's Xtensa atomic implementation https://github.com/torvalds/linux/blob/v6.1/arch/xtensa/include/asm/atomic.h | ||
|
||
#[cfg(not(portable_atomic_no_asm))] | ||
use core::arch::asm; | ||
|
||
pub(super) use core::sync::atomic; | ||
|
||
pub(super) type State = u32; | ||
|
||
/// Disables interrupts and returns the previous interrupt state. | ||
#[inline] | ||
pub(super) fn disable() -> State { | ||
let r: u32; | ||
// SAFETY: reading mstatus and disabling interrupts is safe. | ||
// (see module-level comments of interrupt/mod.rs on the safety of using privileged instructions) | ||
unsafe { | ||
// Do not use `nomem` and `readonly` because prevent subsequent memory accesses from being reordered before interrupts are disabled. | ||
asm!("rsil {0}, 15", out(reg) r, options(nostack)); | ||
} | ||
r | ||
} | ||
|
||
/// Restores the previous interrupt state. | ||
#[inline] | ||
pub(super) unsafe fn restore(r: State) { | ||
// SAFETY: the caller must guarantee that the state was retrieved by the previous `disable`, | ||
// and we've checked that interrupts were enabled before disabling interrupts. | ||
unsafe { | ||
// Do not use `nomem` and `readonly` because prevent preceding memory accesses from being reordered after interrupts are enabled. | ||
asm!( | ||
"wsr.ps {0}", | ||
"rsync", | ||
in(reg) r, | ||
options(nostack), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters