From 36fd7650c34e22b26ed96a0275a1b80f8c5c7f74 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Wed, 13 Jul 2022 23:15:33 -0600 Subject: [PATCH 01/10] Create armv4t_none_eabi.rs --- .../rustc_target/src/spec/armv4t_none_eabi.rs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 compiler/rustc_target/src/spec/armv4t_none_eabi.rs diff --git a/compiler/rustc_target/src/spec/armv4t_none_eabi.rs b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs new file mode 100644 index 0000000000000..62ac144b5ea9b --- /dev/null +++ b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs @@ -0,0 +1,54 @@ +//! Targets the ARMv4T, with code as `a32` code by default. +//! +//! Primarily of use for the GBA, but usable with other devices too. +//! +//! Please ping @Lokathor if changes are needed. +//! +//! This target profile assumes that you have the ARM binutils in your path +//! (specifically the linker, `arm-none-eabi-ld`). They can be obtained for free +//! for all major OSes from the ARM developer's website, and they may also be +//! available in your system's package manager. Unfortunately, the standard +//! linker that Rust uses (`lld`) only supports as far back as `ARMv5TE`, so we +//! must use the GNU `ld` linker. +//! +//! **Important:** This target profile **does not** specify a linker script. You +//! just get the default link script when you build a binary for this target. +//! The default link script is very likely wrong, so you should use +//! `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script. + +use crate::spec::{cvs, LinkerFlavor, Target, TargetOptions}; + +pub fn target() -> Target { + Target { + llvm_target: "armv4t-none-eabi".into(), + pointer_width: 32, + arch: "arm".into(), + /* Data layout args are '-' separated: + * little endian + * stack is 64-bit aligned (EABI) + * pointers are 32-bit + * i64 must be 64-bit aligned (EABI) + * mangle names with ELF style + * native integers are 32-bit + * All other elements are default + */ + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + options: TargetOptions { + abi: "eabi".into(), + linker_flavor: LinkerFlavor::Ld, + linker: Some("arm-none-eabi-ld".into()), + asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",], + features: "+soft-float,+strict-align".into(), + main_needs_argc_argv: false, + atomic_cas: false, + has_thumb_interworking: true, + relocation_model: RelocModel::Static, + panic_strategy: PanicStrategy::Abort, + // from thumb_base, rust-lang/rust#44993. + emit_debug_gdb_scripts: false, + // from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets + c_enum_min_bits: 8, + ..Default::default() + }, + } +} From 00187ab8c7276ffdf2a269029ecaf5718ed2bed8 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Wed, 13 Jul 2022 23:38:15 -0600 Subject: [PATCH 02/10] add missing imports. --- compiler/rustc_target/src/spec/armv4t_none_eabi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/armv4t_none_eabi.rs b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs index 62ac144b5ea9b..25dd800acfd94 100644 --- a/compiler/rustc_target/src/spec/armv4t_none_eabi.rs +++ b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs @@ -16,7 +16,7 @@ //! The default link script is very likely wrong, so you should use //! `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script. -use crate::spec::{cvs, LinkerFlavor, Target, TargetOptions}; +use crate::spec::{cvs, LinkerFlavor, Target, TargetOptions, PanicStrategy, RelocModel}; pub fn target() -> Target { Target { From 3a3c877e75a7b401e05930ca44f5804714b0d83a Mon Sep 17 00:00:00 2001 From: Lokathor Date: Wed, 13 Jul 2022 23:51:00 -0600 Subject: [PATCH 03/10] conform to the tidy check --- compiler/rustc_target/src/spec/armv4t_none_eabi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/armv4t_none_eabi.rs b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs index 25dd800acfd94..a76ffe808c3b2 100644 --- a/compiler/rustc_target/src/spec/armv4t_none_eabi.rs +++ b/compiler/rustc_target/src/spec/armv4t_none_eabi.rs @@ -16,7 +16,7 @@ //! The default link script is very likely wrong, so you should use //! `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script. -use crate::spec::{cvs, LinkerFlavor, Target, TargetOptions, PanicStrategy, RelocModel}; +use crate::spec::{cvs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions}; pub fn target() -> Target { Target { From df468086f76147235b4fb8956a87704f60865090 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 14 Jul 2022 09:53:10 -0600 Subject: [PATCH 04/10] Create armv4t_none_eabi.md --- .../src/platform-support/armv4t_none_eabi.md | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/doc/rustc/src/platform-support/armv4t_none_eabi.md diff --git a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md new file mode 100644 index 0000000000000..3b886286df474 --- /dev/null +++ b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md @@ -0,0 +1,70 @@ +# armv4t-none-eabi + +Tier 3 + +Bare-metal target for any cpu in the ARMv4T architecture family, supporting +ARM/Thumb code interworking (aka `a32`/`t32`), with ARM code as the default code +generation. + +In particular this supports the Gameboy Advance (GBA), but there's nothing GBA +specific with this target, so any ARMv4T device should work fine. + +## Target Maintainers + +* [@Lokathor](https://github.com/lokathor) + +## Requirements + +The target is cross-compiled, and uses static linking. + +The linker that comes with rustc cannot link for this platform (the platform is +to old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils +compiled for ARM. This can be obtained for Windows/Mac/Linux from the [ARM +Developer Website][arm-dev], or possibly from your OS's package manager. + +[arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain + +This target doesn't provide a linker script, you'll need to bring your own +according to the specific device you want to target. Pass +`-Clink-arg=-Tyour_script.ld` as a rustc argument to make the linker use +`your_script.ld` during linking. + +## Building Rust Programs + +Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this target. + +Just use the `build-std` nightly cargo feature to build the `core` library. You +can pass this as a command line argument to cargo, or your `.cargo/config.toml` +file might include the following lines: + +```toml +[unstable] +build-std = ["core"] +``` + +Most of `core` should work as expected, with the following notes: +* the target is "soft float", so `f32` and `f64` operations are emulated in + software. +* integer division is also emulated in software. +* the target is old enough that it doesn't have atomic instructions. + +Rust programs are output as ELF files. + +For running on hardware, you'll generally need to extract the "raw" program code +out of the ELF and into a file of its own. The `objcopy` program provided as +part of the GNU Binutils can do this: + +```shell +arm-none-eabi-objcopy --output-target binary [in_file] [out_file] +``` + +## Testing + +This is a cross-compiled target that you will need to emulate during testing. + +Because this is a device-agnostic target, and the exact emulator that you'll +need depends on the specific device you want to run your code on. + +For example, when programming for the Gameboy Advance, the +[mgba-test-runner](https://github.com/agbrs/agb) program could be used to make a +normal set of rust tests be run within the `mgba` emulator. From aa083a0b04af86ce330b80289b8a6987151ba529 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 14 Jul 2022 09:54:16 -0600 Subject: [PATCH 05/10] Update SUMMARY.md --- src/doc/rustc/src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 87dc513853968..8c65a07e511e0 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -17,6 +17,7 @@ - [Template for Target-specific Documentation](platform-support/TEMPLATE.md) - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [\*-apple-watchos\*](platform-support/apple-watchos.md) + - [armv4t-none-eabi](platform-support/armv4t-none-eabi.md) - [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md) - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) From 0d96ec2ad2de141b0b7d227c6d3ad07f69ce9333 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 14 Jul 2022 09:57:38 -0600 Subject: [PATCH 06/10] wording clarification --- src/doc/rustc/src/platform-support/armv4t_none_eabi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md index 3b886286df474..564c5f5427594 100644 --- a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md +++ b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md @@ -19,7 +19,7 @@ The target is cross-compiled, and uses static linking. The linker that comes with rustc cannot link for this platform (the platform is to old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils -compiled for ARM. This can be obtained for Windows/Mac/Linux from the [ARM +targeting ARM. This can be obtained for Windows/Mac/Linux from the [ARM Developer Website][arm-dev], or possibly from your OS's package manager. [arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain From 6b1fdd04571a28d90090c40bd875d89e79d561b7 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 14 Jul 2022 10:15:25 -0600 Subject: [PATCH 07/10] one entire trailing space, tidy please --- src/doc/rustc/src/platform-support/armv4t_none_eabi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md index 564c5f5427594..70379716e4a0a 100644 --- a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md +++ b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md @@ -11,7 +11,7 @@ specific with this target, so any ARMv4T device should work fine. ## Target Maintainers -* [@Lokathor](https://github.com/lokathor) +* [@Lokathor](https://github.com/lokathor) ## Requirements From f5a19d1cd77ec8af751fc3546b42756fb8f6ce83 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 15 Jul 2022 09:09:04 -0600 Subject: [PATCH 08/10] Update SUMMARY.md --- src/doc/rustc/src/SUMMARY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 8c65a07e511e0..87dc513853968 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -17,7 +17,6 @@ - [Template for Target-specific Documentation](platform-support/TEMPLATE.md) - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [\*-apple-watchos\*](platform-support/apple-watchos.md) - - [armv4t-none-eabi](platform-support/armv4t-none-eabi.md) - [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md) - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) From 320f600b5afd093d1443d747993d3f43a5b24b3b Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 15 Jul 2022 09:10:45 -0600 Subject: [PATCH 09/10] Update SUMMARY.md --- src/doc/rustc/src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index f6348b2bddc88..1eacb2c51f851 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -18,6 +18,7 @@ - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [\*-apple-watchos\*](platform-support/apple-watchos.md) - [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md) + - [armv4t-none-eabi](platform-support/armv4t-none-eabi.md) - [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md) - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) From 77a330c60f896305aa0b32a5b9fc1a1475b87c90 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Tue, 2 Aug 2022 18:36:44 -0600 Subject: [PATCH 10/10] mistakenly used `to` instead of `too` --- src/doc/rustc/src/platform-support/armv4t_none_eabi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md index 70379716e4a0a..cf831e1595e40 100644 --- a/src/doc/rustc/src/platform-support/armv4t_none_eabi.md +++ b/src/doc/rustc/src/platform-support/armv4t_none_eabi.md @@ -18,7 +18,7 @@ specific with this target, so any ARMv4T device should work fine. The target is cross-compiled, and uses static linking. The linker that comes with rustc cannot link for this platform (the platform is -to old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils +too old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils targeting ARM. This can be obtained for Windows/Mac/Linux from the [ARM Developer Website][arm-dev], or possibly from your OS's package manager.