Skip to content

Commit e7b62be

Browse files
committed
Add {thumb,arm}v5te-none-eabi targets
1 parent e21d771 commit e7b62be

File tree

6 files changed

+171
-0
lines changed

6 files changed

+171
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Targets the ARMv5TE, with code as `a32` code by default.
2+
3+
use crate::spec::{
4+
cvs, LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOptions
5+
};
6+
7+
pub fn target() -> Target {
8+
Target {
9+
llvm_target: "armv5te-none-eabi".into(),
10+
pointer_width: 32,
11+
arch: "arm".into(),
12+
/* Data layout args are '-' separated:
13+
* little endian
14+
* stack is 64-bit aligned (EABI)
15+
* pointers are 32-bit
16+
* i64 must be 64-bit aligned (EABI)
17+
* mangle names with ELF style
18+
* native integers are 32-bit
19+
* All other elements are default
20+
*/
21+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
22+
23+
options: TargetOptions {
24+
abi: "eabi".into(),
25+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
26+
linker: Some("rust-lld".into()),
27+
// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
28+
// * activate t32/a32 interworking
29+
// * use arch ARMv5TE
30+
// * use little-endian
31+
asm_args: cvs!["-mthumb-interwork", "-march=armv5te", "-mlittle-endian",],
32+
// minimum extra features, these cannot be disabled via -C
33+
// Also force-enable 32-bit atomics, which allows the use of atomic load/store only.
34+
// The resulting atomics are ABI incompatible with atomics backed by libatomic.
35+
features: "+soft-float,+strict-align,+atomics-32".into(),
36+
main_needs_argc_argv: false,
37+
// don't have atomic compare-and-swap
38+
atomic_cas: false,
39+
has_thumb_interworking: true,
40+
relocation_model: RelocModel::Static,
41+
panic_strategy: PanicStrategy::Abort,
42+
// from thumb_base, rust-lang/rust#44993.
43+
emit_debug_gdb_scripts: false,
44+
// from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets
45+
c_enum_min_bits: 8,
46+
47+
..Default::default()
48+
},
49+
}
50+
}

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,8 @@ supported_targets! {
10821082
("mipsel-unknown-none", mipsel_unknown_none),
10831083
("thumbv4t-none-eabi", thumbv4t_none_eabi),
10841084
("armv4t-none-eabi", armv4t_none_eabi),
1085+
("thumbv5te-none-eabi", thumbv5te_none_eabi),
1086+
("armv5te-none-eabi", armv5te_none_eabi),
10851087

10861088
("aarch64_be-unknown-linux-gnu", aarch64_be_unknown_linux_gnu),
10871089
("aarch64-unknown-linux-gnu_ilp32", aarch64_unknown_linux_gnu_ilp32),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! Targets the ARMv5TE, with code as `t32` code by default.
2+
3+
use crate::spec::{cvs, FramePointer, Target, TargetOptions};
4+
5+
pub fn target() -> Target {
6+
Target {
7+
llvm_target: "thumbv5te-none-eabi".into(),
8+
pointer_width: 32,
9+
arch: "arm".into(),
10+
/* Data layout args are '-' separated:
11+
* little endian
12+
* stack is 64-bit aligned (EABI)
13+
* pointers are 32-bit
14+
* i64 must be 64-bit aligned (EABI)
15+
* mangle names with ELF style
16+
* native integers are 32-bit
17+
* All other elements are default
18+
*/
19+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
20+
21+
options: TargetOptions {
22+
abi: "eabi".into(),
23+
// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
24+
// * activate t32/a32 interworking
25+
// * use arch ARMv5TE
26+
// * use little-endian
27+
asm_args: cvs!["-mthumb-interwork", "-march=armv5te", "-mlittle-endian",],
28+
// minimum extra features, these cannot be disabled via -C
29+
// Also force-enable 32-bit atomics, which allows the use of atomic load/store only.
30+
// The resulting atomics are ABI incompatible with atomics backed by libatomic.
31+
features: "+soft-float,+strict-align,+atomics-32".into(),
32+
frame_pointer: FramePointer::MayOmit,
33+
main_needs_argc_argv: false,
34+
// don't have atomic compare-and-swap
35+
atomic_cas: false,
36+
has_thumb_interworking: true,
37+
38+
..super::thumb_base::opts()
39+
},
40+
}
41+
}

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [\*-apple-watchos\*](platform-support/apple-watchos.md)
2020
- [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md)
2121
- [armv4t-none-eabi](platform-support/armv4t-none-eabi.md)
22+
- [armv5te-none-eabi](platform-support/armv5te-none-eabi.md)
2223
- [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md)
2324
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
2425
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)

src/doc/rustc/src/platform-support.md

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ target | std | host | notes
225225
[`arm64_32-apple-watchos`](platform-support/apple-watchos.md) | ✓ | | ARM Apple WatchOS 64-bit with 32-bit pointers
226226
`armv4t-none-eabi` | * | | ARMv4T A32
227227
`armv4t-unknown-linux-gnueabi` | ? | |
228+
[`armv5te-none-eabi`](platform-support/armv5te-none-eabi.md) | * | | ARMv5TE A32
228229
`armv5te-unknown-linux-uclibceabi` | ? | | ARMv5TE Linux with uClibc
229230
`armv6-unknown-freebsd` | ✓ | ✓ | ARMv6 FreeBSD
230231
`armv6-unknown-netbsd-eabihf` | ? | |
@@ -291,6 +292,7 @@ target | std | host | notes
291292
`sparc64-unknown-netbsd` | ✓ | ✓ | NetBSD/sparc64
292293
[`sparc64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/sparc64
293294
`thumbv4t-none-eabi` | * | | ARMv4T T32
295+
[`thumbv5te-none-eabi`](platform-support/armv5te-none-eabi.md) | * | | ARMv5TE T32
294296
`thumbv7a-pc-windows-msvc` | ? | |
295297
`thumbv7a-uwp-windows-msvc` | ✓ | |
296298
`thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7a Linux with NEON, MUSL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# `armv5te-none-eabi`
2+
3+
**Tier: 3**
4+
5+
Bare-metal target for any cpu in the ARMv5TE architecture family, supporting
6+
ARM/Thumb code interworking (aka `a32`/`t32`), with ARM code as the default code
7+
generation.
8+
9+
The `thumbv5te-none-eabi` target is the same as this one, but with THUMB code as the default.
10+
11+
In particular this supports the main CPU of the Nintendo DS, but there's nothing DS
12+
specific with this target, so any ARMv5TE device should work fine.
13+
14+
## Target Maintainers
15+
16+
* [@QuinnPainter](https://github.com/QuinnPainter)
17+
18+
## Requirements
19+
20+
The target is cross-compiled, and uses static linking.
21+
22+
By default, the `lld` linker included with Rust will be used.
23+
24+
However, you may want to use the `arm-none-eabi-ld` linker instead. This can be obtained for Windows/Mac/Linux from the [ARM
25+
Developer Website][arm-dev], or possibly from your OS's package manager. To use it, add the following to your `.cargo/config.toml`:
26+
27+
```toml
28+
[target.armv5te-none-eabi]
29+
linker = "arm-none-eabi-ld"
30+
```
31+
32+
[arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain
33+
34+
This target doesn't provide a linker script, you'll need to bring your own
35+
according to the specific device you want to target. Pass
36+
`-Clink-arg=-Tyour_script.ld` as a rustc argument to make the linker use
37+
`your_script.ld` during linking.
38+
39+
## Building Rust Programs
40+
41+
Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this target.
42+
43+
Just use the `build-std` nightly cargo feature to build the `core` library. You
44+
can pass this as a command line argument to cargo, or your `.cargo/config.toml`
45+
file might include the following lines:
46+
47+
```toml
48+
[unstable]
49+
build-std = ["core"]
50+
```
51+
52+
Most of `core` should work as expected, with the following notes:
53+
* the target is "soft float", so `f32` and `f64` operations are emulated in
54+
software.
55+
* integer division is also emulated in software.
56+
* the target is old enough that it doesn't have atomic instructions.
57+
58+
`alloc` is also supported, as long as you provide your own global allocator.
59+
60+
Rust programs are output as ELF files.
61+
62+
For running on DS hardware, you'll need to use an external tool to bundle this ELF file into an NDS binary. The `ndstool` utility included with devkitARM is one such tool that can do this for you:
63+
64+
```shell
65+
ndstool -c [out_nds] -9 [in_elf]
66+
```
67+
68+
## Testing
69+
70+
This is a cross-compiled target that you will need to emulate during testing.
71+
72+
Because this is a device-agnostic target, and the exact emulator that you'll
73+
need depends on the specific device you want to run your code on.
74+
75+
For example, when programming for the DS, you can use one of the several available DS emulators, such as [melonDS](https://melonds.kuribo64.net/).

0 commit comments

Comments
 (0)