-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28: interrupt: Support no-std pre-v6 ARM targets r=taiki-e a=taiki-e Closes #26 This currently disables only IRQs. This is explained in the document on safety requirements: > - On pre-v6 ARM, this currently disables only IRQs. > Enabling this cfg in an environment where FIQs must also be disabled is also considered **unsound**. I have a few questions: - ~~Should we also disable FIQs? [The emulation of atomic operation on Linux seemed to disable only IRQs](https://github.com/torvalds/linux/blob/eb555cb5b794f4e12a9897f3d46d5a72104cd4a7/arch/arm/include/asm/atomic.h#L156-L170), but they may have disabled FIQs globally.~~ EDIT: see #28 (comment) - Is there a way to test this target on CI? Co-authored-by: Taiki Endo <te316e89@gmail.com>
- Loading branch information
Showing
12 changed files
with
428 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Refs: https://developer.arm.com/documentation/ddi0406/cb/System-Level-Architecture/The-System-Level-Programmers--Model/ARM-processor-modes-and-ARM-core-registers/Program-Status-Registers--PSRs-?lang=en#CIHJBHJA | ||
|
||
#[cfg(not(portable_atomic_no_asm))] | ||
use core::arch::asm; | ||
|
||
#[derive(Clone, Copy)] | ||
pub(super) struct State(u32); | ||
|
||
/// Disables interrupts and returns the previous interrupt state. | ||
#[inline] | ||
#[instruction_set(arm::a32)] | ||
pub(super) fn disable() -> State { | ||
let cpsr: u32; | ||
// SAFETY: reading CPSR and disabling interrupts are 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!( | ||
"mrs {0}, cpsr", | ||
// We disable only IRQs. See also https://github.com/taiki-e/portable-atomic/pull/28#issuecomment-1214146912. | ||
"orr {1}, {0}, 0x80", | ||
"msr cpsr_c, {1}", | ||
out(reg) cpsr, | ||
out(reg) _, | ||
options(nostack), | ||
); | ||
} | ||
State(cpsr) | ||
} | ||
|
||
/// Restores the previous interrupt state. | ||
#[inline] | ||
#[instruction_set(arm::a32)] | ||
pub(super) unsafe fn restore(State(prev): State) { | ||
// SAFETY: the caller must guarantee that the state was retrieved by the previous `disable`, | ||
unsafe { | ||
// Do not use `nomem` and `readonly` because prevent preceding memory accesses from being reordered after interrupts are enabled. | ||
asm!( | ||
"msr cpsr_c, {0}", | ||
in(reg) prev, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[build] | ||
target-dir = "../../target" | ||
|
||
[target.thumbv4t-none-eabi] | ||
runner = "mgba -l 4" | ||
|
||
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
rustflags = ["-C", "link-arg=-Tlinker.ld"] |
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,20 @@ | ||
[package] | ||
name = "gba-test" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[workspace] | ||
resolver = "2" | ||
|
||
[dependencies] | ||
portable-atomic = { path = "../.." } | ||
|
||
gba = "0.5" | ||
paste = "1" | ||
|
||
[profile.dev] | ||
panic = "abort" | ||
|
||
[profile.release] | ||
panic = "abort" |
Oops, something went wrong.