diff options
author | 2018-05-11 17:58:13 +0000 | |
---|---|---|
committer | 2018-05-11 17:58:13 +0000 | |
commit | e3217ad94d6c941796c2d7ee8735e7b250a69387 (patch) | |
tree | 6488e7d0ad3910d30077f3fdd7eee553b1839f27 /build.rs | |
parent | 00d6faae149c062e79a822b8d46b6b5e7e972f57 (diff) | |
parent | 05bbc3b815703a0654d2e37966547e392f856161 (diff) | |
download | cortex-m-e3217ad94d6c941796c2d7ee8735e7b250a69387.tar.gz cortex-m-e3217ad94d6c941796c2d7ee8735e7b250a69387.tar.zst cortex-m-e3217ad94d6c941796c2d7ee8735e7b250a69387.zip |
Merge #88
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>
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -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"); } } |