Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add armv4t-none-eabi take2 #100244

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions compiler/rustc_target/src/spec/armv4t_none_eabi.rs
Original file line number Diff line number Diff line change
@@ -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()
},
}
}
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
70 changes: 70 additions & 0 deletions src/doc/rustc/src/platform-support/armv4t_none_eabi.md
Original file line number Diff line number Diff line change
@@ -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.