Skip to content

Commit 00236a0

Browse files
authored
Rollup merge of #150138 - thejpster:add-armv6-bare-metal, r=madsmtm,davidtwco,wesleywiser
Add new Tier 3 targets for ARMv6 Adds three new targets to support ARMv6 processors running bare-metal: * `armv6-none-eabi` - Arm ISA, soft-float * `armv6-none-eabihf` - Arm ISA, hard-float * `thumbv6-none-eabi` - Thumb-1 ISA, soft-float There is no `thumbv6-none-eabihf` target because as far as I can tell, hard-float isn't support with the Thumb-1 instruction set (and you need the ARMv6T2 extension to enable Thumb-2 support). The targets require ARMv6K as a minimum, which allows the two Arm ISA targets to have full CAS atomics. LLVM has a bug which means it emits some ARMv6K instructions even if you only call for ARMv6, and as no-one else has noticed the bug, and because basically all ARMv6 processors have ARMv6K, I think this is fine. The Thumb target also doesn't have any kind of atomics, just like the Armv5TE and Armv4 targets, because LLVM was emitting library calls to emulate them. Testing will be added to https://github.com/rust-embedded/aarch32 once the target is accepted. I already have tests for the other non-M arm-none-eabi targets, and those tests pass on these targets. > A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.) I have listed myself. If accepted, I'll talk to the Embedded Devices Working Group about adding this one to the rosta with all the others they support. > Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target. You might prefer `arm-none-eabi`, because `arm-unknown-linux-gnu` is an ARMv6 target - the implicit rule seems to be that if the Arm architecture version isn't specified, it's assumed to be v6. However, `armv6-none-eabi` seemed to fit better between `armv5te-none-eabi` and `armv7a/armv7r-none-eabi`. The hamming distance between `thumbv6-none-eabi` and `thumbv6m-none-eabi` is unfortunately low, but I don't know how to make it better. They *are* the ARMv6 and ARMv6-M targets, and its perhaps not worse than `armv7a-none-eabi` and `armv7r-none-eabi`. > Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users. No different to any other arm-none-eabi target. > Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions. Noted. > Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate... Same as other arm-none-eabi targets. > The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. Same as other arm-none-eabi targets. > Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via @) to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages. Noted. > Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target. Noted > Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.) Noted
2 parents df4fe86 + 7cc102a commit 00236a0

16 files changed

Lines changed: 170 additions & 10 deletions

File tree

compiler/rustc_target/src/spec/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,10 +1746,14 @@ supported_targets! {
17461746
("mipsel-unknown-none", mipsel_unknown_none),
17471747
("mips-mti-none-elf", mips_mti_none_elf),
17481748
("mipsel-mti-none-elf", mipsel_mti_none_elf),
1749-
("thumbv4t-none-eabi", thumbv4t_none_eabi),
1749+
17501750
("armv4t-none-eabi", armv4t_none_eabi),
1751-
("thumbv5te-none-eabi", thumbv5te_none_eabi),
17521751
("armv5te-none-eabi", armv5te_none_eabi),
1752+
("armv6-none-eabi", armv6_none_eabi),
1753+
("armv6-none-eabihf", armv6_none_eabihf),
1754+
("thumbv4t-none-eabi", thumbv4t_none_eabi),
1755+
("thumbv5te-none-eabi", thumbv5te_none_eabi),
1756+
("thumbv6-none-eabi", thumbv6_none_eabi),
17531757

17541758
("aarch64_be-unknown-linux-gnu", aarch64_be_unknown_linux_gnu),
17551759
("aarch64-unknown-linux-gnu_ilp32", aarch64_unknown_linux_gnu_ilp32),

compiler/rustc_target/src/spec/targets/armv4t_none_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Targets the ARMv4T, with code as `a32` code by default.
1+
//! Targets the ARMv4T architecture, with `a32` code by default.
22
//!
33
//! Primarily of use for the GBA, but usable with other devices too.
44
//!

compiler/rustc_target/src/spec/targets/armv5te_none_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Targets the ARMv5TE, with code as `a32` code by default.
1+
//! Targets the ARMv5TE architecture, with `a32` code by default.
22
33
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
44

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Targets the ARMv6K architecture, with `a32` code by default.
2+
3+
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
4+
5+
pub(crate) fn target() -> Target {
6+
Target {
7+
llvm_target: "armv6-none-eabi".into(),
8+
metadata: TargetMetadata {
9+
description: Some("Bare ARMv6 soft-float".into()),
10+
tier: Some(3),
11+
host_tools: Some(false),
12+
std: Some(false),
13+
},
14+
pointer_width: 32,
15+
arch: Arch::Arm,
16+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
17+
options: TargetOptions {
18+
abi: Abi::Eabi,
19+
llvm_floatabi: Some(FloatAbi::Soft),
20+
asm_args: cvs!["-mthumb-interwork", "-march=armv6", "-mlittle-endian",],
21+
features: "+soft-float,+strict-align,+v6k".into(),
22+
atomic_cas: true,
23+
has_thumb_interworking: true,
24+
// LDREXD/STREXD available as of ARMv6K
25+
max_atomic_width: Some(64),
26+
..base::arm_none::opts()
27+
},
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Targets the ARMv6K architecture, with `a32` code by default, and hard-float ABI
2+
3+
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
4+
5+
pub(crate) fn target() -> Target {
6+
Target {
7+
llvm_target: "armv6-none-eabihf".into(),
8+
metadata: TargetMetadata {
9+
description: Some("Bare ARMv6 hard-float".into()),
10+
tier: Some(3),
11+
host_tools: Some(false),
12+
std: Some(false),
13+
},
14+
pointer_width: 32,
15+
arch: Arch::Arm,
16+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
17+
options: TargetOptions {
18+
abi: Abi::EabiHf,
19+
llvm_floatabi: Some(FloatAbi::Hard),
20+
asm_args: cvs!["-mthumb-interwork", "-march=armv6", "-mlittle-endian",],
21+
features: "+strict-align,+v6k,+vfp2,-d32".into(),
22+
atomic_cas: true,
23+
has_thumb_interworking: true,
24+
// LDREXD/STREXD available as of ARMv6K
25+
max_atomic_width: Some(64),
26+
..base::arm_none::opts()
27+
},
28+
}
29+
}

compiler/rustc_target/src/spec/targets/thumbv4t_none_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Targets the ARMv4T, with code as `t32` code by default.
1+
//! Targets the ARMv4T architecture, with `t32` code by default.
22
//!
33
//! Primarily of use for the GBA, but usable with other devices too.
44
//!

compiler/rustc_target/src/spec/targets/thumbv5te_none_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Targets the ARMv5TE, with code as `t32` code by default.
1+
//! Targets the ARMv5TE architecture, with `t32` code by default.
22
33
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
44

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! Targets the ARMv6K architecture, with `t32` code by default.
2+
3+
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
4+
5+
pub(crate) fn target() -> Target {
6+
Target {
7+
llvm_target: "thumbv6-none-eabi".into(),
8+
metadata: TargetMetadata {
9+
description: Some("Thumb-mode Bare ARMv6 soft-float".into()),
10+
tier: Some(3),
11+
host_tools: Some(false),
12+
std: Some(false),
13+
},
14+
pointer_width: 32,
15+
arch: Arch::Arm,
16+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
17+
options: TargetOptions {
18+
abi: Abi::Eabi,
19+
llvm_floatabi: Some(FloatAbi::Soft),
20+
asm_args: cvs!["-mthumb-interwork", "-march=armv6", "-mlittle-endian",],
21+
features: "+soft-float,+strict-align,+v6k".into(),
22+
// CAS atomics are implemented in LLVM on this target using __sync* functions,
23+
// which were added to compiler-builtins in https://github.com/rust-lang/compiler-builtins/pull/1050
24+
atomic_cas: true,
25+
has_thumb_interworking: true,
26+
max_atomic_width: Some(32),
27+
..base::arm_none::opts()
28+
},
29+
}
30+
}

library/core/src/hint.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,18 @@ pub fn spin_loop() {
292292
// SAFETY: the `cfg` attr ensures that we only execute this on aarch64 targets.
293293
unsafe { crate::arch::aarch64::__isb(crate::arch::aarch64::SY) }
294294
}
295-
all(target_arch = "arm", target_feature = "v6") => {
296-
// SAFETY: the `cfg` attr ensures that we only execute this on arm targets
297-
// with support for the v6 feature.
295+
all(
296+
target_arch = "arm",
297+
any(
298+
all(target_feature = "v6k", not(target_feature = "thumb-mode")),
299+
target_feature = "v6t2",
300+
all(target_feature = "v6", target_feature = "mclass"),
301+
)
302+
) => {
303+
// SAFETY: the `cfg` attr ensures that we only execute this on arm
304+
// targets with support for the this feature. On ARMv6 in Thumb
305+
// mode, T2 is required (see Arm DDI0406C Section A8.8.427),
306+
// otherwise ARMv6-M or ARMv6K is enough
298307
unsafe { crate::arch::arm::__yield() }
299308
}
300309
target_arch = "loongarch32" => crate::arch::loongarch32::ibar::<0>(),

library/stdarch/crates/core_arch/src/arm_shared/hints.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ pub unsafe fn __sevl() {
8383
/// improve overall system performance.
8484
// Section 10.1 of ACLE says that the supported arches are: 8, 6K, 6-M
8585
// LLVM says "instruction requires: armv6k"
86+
// On ARMv6 in Thumb mode, T2 is required (see Arm DDI0406C Section A8.8.427)
8687
#[cfg(any(
87-
target_feature = "v6",
88+
all(target_feature = "v6k", not(target_feature = "thumb-mode")),
89+
target_feature = "v6t2",
90+
all(target_feature = "v6", target_feature = "mclass"),
8891
target_arch = "aarch64",
8992
target_arch = "arm64ec",
9093
doc

0 commit comments

Comments
 (0)