From a8b445404769fab8c4497e13a00e03c55e5928ef Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 7 Aug 2022 12:40:41 -0600 Subject: [PATCH 1/3] 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..a76ffe808c3b2 --- /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, PanicStrategy, RelocModel, 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 008ce49944897225537b2f45e0a8d3a39c5dccf5 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 7 Aug 2022 12:41:38 -0600 Subject: [PATCH 2/3] 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..cf831e1595e40 --- /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 +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. + +[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 b4a82998e5c0a35b9ccf935a86cc300a8f29bdd3 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 7 Aug 2022 12:42:25 -0600 Subject: [PATCH 3/3] 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 d168af60c2df0..4e6bc41daa712 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)