Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
88: make compilable on stable r=japaric a=japaric This PR makes this crate compilable on stable when the "inline-asm" and "singleton" Cargo features are disabled (they are enabled by default to maintain backwards compatibility). The main change has been replacing almost (\*) all inline `asm!` invocations with FFI calls into external assembly files. (\*) Stuff that has not been converted into external assembly file and thus is not available on stable: - Reading the (A)PSR register (I'm not sure if this will work with the extra function call overhead) - Reading and writing the Link Register (LR) - Reading and writing the Program Counter (PC) I would appreciate if someone checked that all the stuff that's now using FFI calls has the same semantics as the inline `asm!` version. Co-authored-by: Jorge Aparicio <jorge@japaric.io>
- Loading branch information
Showing
50 changed files
with
908 additions
and
245 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.global __basepri_max | ||
.syntax unified | ||
__basepri_max: | ||
mrs r1, PRIMASK | ||
cpsid i | ||
tst.w r1, #1 | ||
msr BASEPRI_MAX, r0 | ||
it ne | ||
bxne lr | ||
cpsie i | ||
bx lr |
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,4 @@ | ||
.global __basepri_max | ||
__basepri_max: | ||
msr BASEPRI_MAX, r0 | ||
bx lr |
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,4 @@ | ||
.global __basepri_r | ||
__basepri_r: | ||
mrs r0, BASEPRI | ||
bx lr |
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,11 @@ | ||
.global __basepri_w | ||
.syntax unified | ||
__basepri_w: | ||
mrs r1, PRIMASK | ||
cpsid i | ||
tst.w r1, #1 | ||
msr BASEPRI, r0 | ||
it ne | ||
bxne lr | ||
cpsie i | ||
bx lr |
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,4 @@ | ||
.global __basepri_w | ||
__basepri_w: | ||
msr BASEPRI, r0 | ||
bx lr |
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,4 @@ | ||
.global __bkpt | ||
__bkpt: | ||
bkpt | ||
bx lr |
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,4 @@ | ||
.global __control | ||
__control: | ||
mrs r0, CONTROL | ||
bx lr |
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,4 @@ | ||
.global __cpsid | ||
__cpsid: | ||
cpsid i | ||
bx lr |
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,4 @@ | ||
.global __cpsie | ||
__cpsie: | ||
cpsie i | ||
bx lr |
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,4 @@ | ||
.global __dmb | ||
__dmb: | ||
dmb 0xF | ||
bx lr |
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,4 @@ | ||
.global __dsb | ||
__dsb: | ||
dsb 0xF | ||
bx lr |
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,4 @@ | ||
.global __faultmask | ||
__faultmask: | ||
mrs r0, FAULTMASK | ||
bx lr |
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,4 @@ | ||
.global __isb | ||
__isb: | ||
isb 0xF | ||
bx lr |
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,4 @@ | ||
.global __msp_r | ||
__msp_r: | ||
mrs r0, MSP | ||
bx lr |
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,4 @@ | ||
.global __msp_w | ||
__msp_w: | ||
msr MSP, r0 | ||
bx lr |
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,3 @@ | ||
.global __nop | ||
__nop: | ||
bx lr |
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,4 @@ | ||
.global __primask | ||
__primask: | ||
mrs r0, PRIMASK | ||
bx lr |
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,4 @@ | ||
.global __psp_r | ||
__psp_r: | ||
mrs r0, PSP | ||
bx lr |
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,4 @@ | ||
.global __psp_w | ||
__psp_w: | ||
msr PSP, r0 | ||
bx lr |
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,4 @@ | ||
.global __sev | ||
__sev: | ||
sev | ||
bx lr |
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,4 @@ | ||
.global __wfe | ||
__wfe: | ||
wfe | ||
bx lr |
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,4 @@ | ||
.global __wfi | ||
__wfi: | ||
wfi | ||
bx lr |
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 |
---|---|---|
@@ -1,18 +1,58 @@ | ||
extern crate cc; | ||
|
||
use std::env; | ||
|
||
fn main() { | ||
let target = env::var("TARGET").unwrap(); | ||
|
||
if target.starts_with("thumb") && env::var_os("CARGO_FEATURE_INLINE_ASM").is_none() { | ||
// NOTE we need to place each routine in a separate assembly file or the linker won't be | ||
// able to discard the unused routines | ||
let mut build = cc::Build::new(); | ||
build | ||
.file("asm/basepri_r.s") | ||
.file("asm/bkpt.s") | ||
.file("asm/control.s") | ||
.file("asm/cpsid.s") | ||
.file("asm/cpsie.s") | ||
.file("asm/dmb.s") | ||
.file("asm/dsb.s") | ||
.file("asm/faultmask.s") | ||
.file("asm/isb.s") | ||
.file("asm/msp_r.s") | ||
.file("asm/msp_w.s") | ||
.file("asm/nop.s") | ||
.file("asm/primask.s") | ||
.file("asm/psp_r.s") | ||
.file("asm/psp_w.s") | ||
.file("asm/sev.s") | ||
.file("asm/wfe.s") | ||
.file("asm/wfi.s"); | ||
|
||
if env::var_os("CARGO_FEATURE_CM7_R0P1").is_some() { | ||
build.file("asm/basepri_max-cm7-r0p1.s"); | ||
build.file("asm/basepri_w-cm7-r0p1.s"); | ||
} else { | ||
build.file("asm/basepri_max.s"); | ||
build.file("asm/basepri_w.s"); | ||
} | ||
|
||
build.compile("asm"); | ||
} | ||
|
||
if target.starts_with("thumbv6m-") { | ||
println!("cargo:rustc-cfg=cortex_m"); | ||
println!("cargo:rustc-cfg=armv6m"); | ||
} else if target.starts_with("thumbv7m-") { | ||
println!("cargo:rustc-cfg=cortex_m"); | ||
println!("cargo:rustc-cfg=armv7m"); | ||
} else if target.starts_with("thumbv7em-") { | ||
println!("cargo:rustc-cfg=cortex_m"); | ||
println!("cargo:rustc-cfg=armv7m"); | ||
//println!("cargo:rustc-cfg=armv7em"); | ||
} | ||
|
||
if target.ends_with("eabihf") { | ||
if target.ends_with("-eabihf") { | ||
println!("cargo:rustc-cfg=has_fpu"); | ||
} | ||
} |
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
Oops, something went wrong.