Skip to content

Commit 901c5f2

Browse files
author
Jorge Aparicio
committed
add Thumbs to the compiler
this commit adds 4 new target definitions to the compiler for easier cross compilation to ARM Cortex-M devices. - `thumbv6m-none-eabi` - For the Cortex-M0, Cortex-M0+ and Cortex-M1 - This architecture doesn't have hardware support (instructions) for atomics. Hence, the `Atomic*` structs are not available for this target. - `thumbv7m-none-eabi` - For the Cortex-M3 - `thumbv7em-none-eabi` - For the FPU-less variants of the Cortex-M4 and Cortex-M7 - On this target, all the floating point operations will be lowered software routines (intrinsics) - `thumbv7em-none-eabihf` - For the variants of the Cortex-M4 and Cortex-M7 that do have a FPU. - On this target, all the floating point operations will be lowered to hardware instructions No binary releases of standard crates, like `core`, are planned for these targets because Cargo, in the future, will compile e.g. the `core` crate on the fly as part of the `cargo build` process. In the meantime, you'll have to compile the `core` crate yourself. [Xargo] is the easiest way to do that as in handles the compilation of `core` automatically and can be used just like Cargo: `xargo build --target thumbv6m-none-eabi` is all that's needed. [Xargo]: https://crates.io/crates/xargo
1 parent 8991ffc commit 901c5f2

File tree

7 files changed

+163
-2
lines changed

7 files changed

+163
-2
lines changed

src/librustc_back/target/mod.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ mod netbsd_base;
6666
mod solaris_base;
6767
mod windows_base;
6868
mod windows_msvc_base;
69+
mod thumb_base;
6970

7071
pub type TargetResult = Result<Target, String>;
7172

7273
macro_rules! supported_targets {
73-
( $(($triple:expr, $module:ident)),+ ) => (
74+
( $(($triple:expr, $module:ident),)+ ) => (
7475
$(mod $module;)*
7576

7677
/// List of supported targets
@@ -191,7 +192,12 @@ supported_targets! {
191192

192193
("le32-unknown-nacl", le32_unknown_nacl),
193194
("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
194-
("wasm32-unknown-emscripten", wasm32_unknown_emscripten)
195+
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
196+
197+
("thumbv6m-none-eabi", thumbv6m_none_eabi),
198+
("thumbv7m-none-eabi", thumbv7m_none_eabi),
199+
("thumbv7em-none-eabi", thumbv7em_none_eabi),
200+
("thumbv7em-none-eabihf", thumbv7em_none_eabihf),
195201
}
196202

197203
/// Everything `rustc` knows about how to compile for a specific target.
@@ -401,6 +407,9 @@ impl Default for TargetOptions {
401407
allow_asm: true,
402408
has_elf_tls: false,
403409
obj_is_bitcode: false,
410+
// NOTE 0 is *not* the real default value of max_atomic_width. The default value is
411+
// actually the pointer_width of the target. This default is injected in the
412+
// Target::from_json function.
404413
max_atomic_width: 0,
405414
panic_strategy: PanicStrategy::Unwind,
406415
}
@@ -699,6 +708,10 @@ impl ToJson for Target {
699708
target_option_val!(max_atomic_width);
700709
target_option_val!(panic_strategy);
701710

711+
if self.options.max_atomic_width.to_string() != self.target_pointer_width {
712+
d.insert("max-atomic-width".to_string(), self.options.max_atomic_width.to_json());
713+
}
714+
702715
Json::Object(d)
703716
}
704717
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::TargetOptions;
12+
use std::default::Default;
13+
14+
pub fn opts() -> TargetOptions {
15+
TargetOptions {
16+
executables: true,
17+
linker: "arm-none-eabi-gcc".to_string(),
18+
.. Default::default()
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetOptions, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
Ok(Target {
15+
llvm_target: "thumbv6m-none-eabi".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
19+
arch: "arm".to_string(),
20+
target_os: "none".to_string(),
21+
target_env: "".to_string(),
22+
target_vendor: "".to_string(),
23+
24+
options: TargetOptions {
25+
// The ARMv6-M architecture doesn't support unaligned loads/stores so we disable them
26+
// with +strict-align.
27+
features: "+strict-align".to_string(),
28+
// There are no atomic instructions available in the instruction set of the ARMv6-M
29+
// architecture
30+
max_atomic_width: 0,
31+
.. super::thumb_base::opts()
32+
}
33+
})
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetOptions, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
Ok(Target {
15+
llvm_target: "thumbv7em-none-eabi".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
19+
arch: "arm".to_string(),
20+
target_os: "none".to_string(),
21+
target_env: "".to_string(),
22+
target_vendor: "".to_string(),
23+
24+
options: TargetOptions {
25+
max_atomic_width: 32,
26+
.. super::thumb_base::opts()
27+
},
28+
})
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetOptions, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
Ok(Target {
15+
llvm_target: "thumbv7em-none-eabihf".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
19+
arch: "arm".to_string(),
20+
target_os: "none".to_string(),
21+
target_env: "".to_string(),
22+
target_vendor: "".to_string(),
23+
24+
options: TargetOptions {
25+
// vfp4 lowest common denominator between the Cortex-M4 (vfp4) and the Cortex-M7 (vfp5)
26+
features: "+vfp4".to_string(),
27+
max_atomic_width: 32,
28+
.. super::thumb_base::opts()
29+
}
30+
})
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetOptions, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
Ok(Target {
15+
llvm_target: "thumbv7m-none-eabi".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
19+
arch: "arm".to_string(),
20+
target_os: "none".to_string(),
21+
target_env: "".to_string(),
22+
target_vendor: "".to_string(),
23+
24+
options: TargetOptions {
25+
max_atomic_width: 32,
26+
.. super::thumb_base::opts()
27+
},
28+
})
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
3+
# The target used below doesn't support atomic operations. Verify that's the case
4+
all:
5+
rustc --print cfg --target thumbv6m-none-eabi | grep -qv target_has_atomic

0 commit comments

Comments
 (0)