From 48ec236c8c7c5a32077c465eb254646a9860f802 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 07:05:08 -0600 Subject: [PATCH 01/12] start GBA file. --- .../spec/thumbv4t_nintendo_gba.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/librustc_target/spec/thumbv4t_nintendo_gba.rs diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs new file mode 100644 index 0000000000000..b7e70167c0d09 --- /dev/null +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -0,0 +1,30 @@ +//! Targets the Nintendo Game Boy Advance (GBA). +//! +//! The GBA is a handheld game device from 2001. Inside, the CPU is an ARM7TDMI. +//! That's in the ARMv4T architecture family. +//! +//! Technically the device has no OS, however we're going to copy the +//! `mipsel_sony_psp` target setup and set the OS string to be "GBA". Other than +//! the setting of the `target_os` and `target_vendor` values, this target is a +//! fairly standard configuration for `thumbv4t` + +use crate::spec::{LinkerFlavor, LldFlavor, Target, TargetOptions, TargetResult}; + +pub fn target() -> TargetResult { + Ok(Target { + llvm_target: "thumbv4t-none-eabi".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), + target_os: "gba".to_string(), + target_env: String::new(), + target_vendor: "nintendo".to_string(), + arch: "arm".to_string(), + data_layout: "TODO".to_string(), + linker_flavor: LinkerFlavor::Ld, + options: TargetOptions { + // TODO + ..TargetOptions::default() + }, + }) +} From e190bdf710101d8fdf12195dcc73749719a57e72 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 16:40:50 -0600 Subject: [PATCH 02/12] fill in all those options. --- .../spec/thumbv4t_nintendo_gba.rs | 72 ++++++++++++++++--- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs index b7e70167c0d09..2b3aa33dfa3d6 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -1,12 +1,11 @@ -//! Targets the Nintendo Game Boy Advance (GBA). +//! Targets the Nintendo Game Boy Advance (GBA), a handheld game device from 2001. //! -//! The GBA is a handheld game device from 2001. Inside, the CPU is an ARM7TDMI. -//! That's in the ARMv4T architecture family. +//! Please ping @Lokathor if changes are needed. //! -//! Technically the device has no OS, however we're going to copy the -//! `mipsel_sony_psp` target setup and set the OS string to be "GBA". Other than -//! the setting of the `target_os` and `target_vendor` values, this target is a -//! fairly standard configuration for `thumbv4t` +//! Important: This target **does not** specify a linker script or the ROM +//! header. You'll still need to provide these yourself to construct a final +//! binary. Generally you'd do this with something like +//! `-Clink-arg=-Tmy_script.ld` and `-Clink-arg=my_crt.o`. use crate::spec::{LinkerFlavor, LldFlavor, Target, TargetOptions, TargetResult}; @@ -16,14 +15,65 @@ pub fn target() -> TargetResult { target_endian: "little".to_string(), target_pointer_width: "32".to_string(), target_c_int_width: "32".to_string(), - target_os: "gba".to_string(), - target_env: String::new(), + target_os: "none".to_string(), + target_env: "gba".to_string(), target_vendor: "nintendo".to_string(), arch: "arm".to_string(), - data_layout: "TODO".to_string(), + /* 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-S64-p:32:32-i64:64-m:e-n32".to_string(), linker_flavor: LinkerFlavor::Ld, options: TargetOptions { - // TODO + linker: Some("arm-none-eabi-ld".to_string()), + linker_is_gnu: true, + + // extra args passed to the external assembler + asm_args: vec!["-mcpu=arm7tdmi".to_string(), "-mthumb-interwork".to_string()], + + cpu: "arm7tdmi".to_string(), + + // minimum extra features, these cannot be disabled via -C + features: "+soft-float,+strict-align".to_string(), + + executables: true, + + relocation_model: RelocModel::Static, + + //function_sections: bool, + //exe_suffix: String, + main_needs_argc_argv: false, + + // if we have thread-local storage + has_elf_tls: false, + + // don't have atomic compare-and-swap + atomic_cas: false, + + // always just abort + panic_strategy: PanicStrategy::Abort, + + // ABIs to not use + unsupported_abis: super::arm_base::unsupported_abis(), + + // The minimum alignment for global symbols. + min_global_align: Some(4), + + // no threads here + singlethread: true, + + // GBA has no builtins + no_builtins: true, + + // this is off just like in the `thumb_base` + emit_debug_gdb_scripts: false, + ..TargetOptions::default() }, }) From 9c4ac7395953435a5f39cfaf93c7679df068bade Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 17:24:36 -0600 Subject: [PATCH 03/12] Docs clarifications. --- src/librustc_target/spec/thumbv4t_nintendo_gba.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs index 2b3aa33dfa3d6..1be6c4a9ff875 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -1,11 +1,11 @@ -//! Targets the Nintendo Game Boy Advance (GBA), a handheld game device from 2001. +//! Targets the Nintendo Game Boy Advance (GBA), +//! a handheld game device from 2001. //! //! Please ping @Lokathor if changes are needed. //! -//! Important: This target **does not** specify a linker script or the ROM -//! header. You'll still need to provide these yourself to construct a final -//! binary. Generally you'd do this with something like -//! `-Clink-arg=-Tmy_script.ld` and `-Clink-arg=my_crt.o`. +//! The 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 +//! +//! **Important:** This target profile **does not** specify a linker script or the ROM header. You'll still need to provide these yourself to construct a final binary. Generally you'd do this with something like `-Clink-arg=-Tmy_script.ld` and `-Clink-arg=my_crt.o`. use crate::spec::{LinkerFlavor, LldFlavor, Target, TargetOptions, TargetResult}; From 72fa7f82503d4eb3c09e5dce600ac044c2835688 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 17:24:58 -0600 Subject: [PATCH 04/12] Add to supported_targets list. --- src/librustc_target/spec/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 4a2dd8913185f..d1c3fc5847851 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -676,6 +676,7 @@ supported_targets! { ("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks), ("mipsel-sony-psp", mipsel_sony_psp), + ("thumbv4t-nintendo-gba", thumbv4t_nintendo_gba), } /// Everything `rustc` knows about how to compile for a specific target. From 66a3d6859ba8cca6eab614014c001a0ef4be9809 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 17:37:47 -0600 Subject: [PATCH 05/12] fix the imports. --- src/librustc_target/spec/thumbv4t_nintendo_gba.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs index 1be6c4a9ff875..6af2716623c3e 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -7,7 +7,7 @@ //! //! **Important:** This target profile **does not** specify a linker script or the ROM header. You'll still need to provide these yourself to construct a final binary. Generally you'd do this with something like `-Clink-arg=-Tmy_script.ld` and `-Clink-arg=my_crt.o`. -use crate::spec::{LinkerFlavor, LldFlavor, Target, TargetOptions, TargetResult}; +use crate::spec::{LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { Ok(Target { From 7cbff846edcedc7ab9d0dfd82e6f711fe99e2520 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 18:39:15 -0600 Subject: [PATCH 06/12] Resolve https://github.com/rust-lang/rust/pull/74419#discussion_r456141344 --- src/librustc_target/spec/thumbv4t_nintendo_gba.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs index 6af2716623c3e..2399ac9b91df7 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -65,9 +65,6 @@ pub fn target() -> TargetResult { // The minimum alignment for global symbols. min_global_align: Some(4), - // no threads here - singlethread: true, - // GBA has no builtins no_builtins: true, From 888077bf105568f59fba5b76086ac902588fd58c Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 18:39:56 -0600 Subject: [PATCH 07/12] Resolve https://github.com/rust-lang/rust/pull/74419#discussion_r456142514 --- src/librustc_target/spec/thumbv4t_nintendo_gba.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs index 2399ac9b91df7..d8ac53ccb4143 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -65,9 +65,6 @@ pub fn target() -> TargetResult { // The minimum alignment for global symbols. min_global_align: Some(4), - // GBA has no builtins - no_builtins: true, - // this is off just like in the `thumb_base` emit_debug_gdb_scripts: false, From dbfe8fc61c9420aca1679249749df6b9cd1c00df Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 18:41:39 -0600 Subject: [PATCH 08/12] resolve https://github.com/rust-lang/rust/pull/74419#discussion_r456140272 --- src/librustc_target/spec/thumbv4t_nintendo_gba.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs index d8ac53ccb4143..1602296eb6977 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -62,9 +62,6 @@ pub fn target() -> TargetResult { // ABIs to not use unsupported_abis: super::arm_base::unsupported_abis(), - // The minimum alignment for global symbols. - min_global_align: Some(4), - // this is off just like in the `thumb_base` emit_debug_gdb_scripts: false, From fba90f9c3f6fb6eb66b661708f569e8c15c0b282 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 16 Jul 2020 18:42:26 -0600 Subject: [PATCH 09/12] Resolve https://github.com/rust-lang/rust/pull/74419#discussion_r456139741 --- src/librustc_target/spec/thumbv4t_nintendo_gba.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs index 1602296eb6977..a3ab0c9e2deb3 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_nintendo_gba.rs @@ -46,8 +46,6 @@ pub fn target() -> TargetResult { relocation_model: RelocModel::Static, - //function_sections: bool, - //exe_suffix: String, main_needs_argc_argv: false, // if we have thread-local storage From 5c63bffe2d893123da0a54410fe7b9bad324c58c Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 17 Jul 2020 18:59:24 -0600 Subject: [PATCH 10/12] Make the new target a general thumbv4t target. --- src/librustc_target/spec/mod.rs | 2 +- ..._nintendo_gba.rs => thumbv4t_none_eabi.rs} | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) rename src/librustc_target/spec/{thumbv4t_nintendo_gba.rs => thumbv4t_none_eabi.rs} (56%) diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index d1c3fc5847851..7605fa3bab951 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -676,7 +676,7 @@ supported_targets! { ("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks), ("mipsel-sony-psp", mipsel_sony_psp), - ("thumbv4t-nintendo-gba", thumbv4t_nintendo_gba), + ("thumbv4t-none-eabi", thumbv4t_none_eabi), } /// Everything `rustc` knows about how to compile for a specific target. diff --git a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs b/src/librustc_target/spec/thumbv4t_none_eabi.rs similarity index 56% rename from src/librustc_target/spec/thumbv4t_nintendo_gba.rs rename to src/librustc_target/spec/thumbv4t_none_eabi.rs index a3ab0c9e2deb3..04a272cb4ae77 100644 --- a/src/librustc_target/spec/thumbv4t_nintendo_gba.rs +++ b/src/librustc_target/spec/thumbv4t_none_eabi.rs @@ -1,11 +1,12 @@ -//! Targets the Nintendo Game Boy Advance (GBA), -//! a handheld game device from 2001. +//! Targets the ARMv4T, with code as `t32` code by default. +//! +//! Primarily of use for the GBA, but usable with other devices too. //! //! Please ping @Lokathor if changes are needed. //! -//! The 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 +//! 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 or the ROM header. You'll still need to provide these yourself to construct a final binary. Generally you'd do this with something like `-Clink-arg=-Tmy_script.ld` and `-Clink-arg=my_crt.o`. +//! **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::{LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions, TargetResult}; @@ -16,8 +17,8 @@ pub fn target() -> TargetResult { target_pointer_width: "32".to_string(), target_c_int_width: "32".to_string(), target_os: "none".to_string(), - target_env: "gba".to_string(), - target_vendor: "nintendo".to_string(), + target_env: "".to_string(), + target_vendor: "".to_string(), arch: "arm".to_string(), /* Data layout args are '-' separated: * little endian @@ -34,10 +35,15 @@ pub fn target() -> TargetResult { linker: Some("arm-none-eabi-ld".to_string()), linker_is_gnu: true, - // extra args passed to the external assembler - asm_args: vec!["-mcpu=arm7tdmi".to_string(), "-mthumb-interwork".to_string()], - - cpu: "arm7tdmi".to_string(), + // extra args passed to the external assembler (assuming `arm-none-eabi-as`): + // * activate t32/a32 interworking + // * use arch ARMv4T + // * use little-endian + asm_args: vec![ + "-mthumb-interwork".to_string(), + "-march=armv4t".to_string(), + "-mlittle-endian".to_string(), + ], // minimum extra features, these cannot be disabled via -C features: "+soft-float,+strict-align".to_string(), @@ -48,7 +54,7 @@ pub fn target() -> TargetResult { main_needs_argc_argv: false, - // if we have thread-local storage + // No thread-local storage (just use a static Cell) has_elf_tls: false, // don't have atomic compare-and-swap @@ -60,7 +66,7 @@ pub fn target() -> TargetResult { // ABIs to not use unsupported_abis: super::arm_base::unsupported_abis(), - // this is off just like in the `thumb_base` + // this is turned off just like in the `thumb_base` module emit_debug_gdb_scripts: false, ..TargetOptions::default() From 4c8e62b43313136d41a55340032ba02a81ac941c Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sat, 18 Jul 2020 21:57:37 -0600 Subject: [PATCH 11/12] Resolve https://github.com/rust-lang/rust/pull/74419#issuecomment-660518936 --- src/librustc_target/spec/thumbv4t_none_eabi.rs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/librustc_target/spec/thumbv4t_none_eabi.rs b/src/librustc_target/spec/thumbv4t_none_eabi.rs index 04a272cb4ae77..1e55efbb59fba 100644 --- a/src/librustc_target/spec/thumbv4t_none_eabi.rs +++ b/src/librustc_target/spec/thumbv4t_none_eabi.rs @@ -48,10 +48,6 @@ pub fn target() -> TargetResult { // minimum extra features, these cannot be disabled via -C features: "+soft-float,+strict-align".to_string(), - executables: true, - - relocation_model: RelocModel::Static, - main_needs_argc_argv: false, // No thread-local storage (just use a static Cell) @@ -60,16 +56,7 @@ pub fn target() -> TargetResult { // don't have atomic compare-and-swap atomic_cas: false, - // always just abort - panic_strategy: PanicStrategy::Abort, - - // ABIs to not use - unsupported_abis: super::arm_base::unsupported_abis(), - - // this is turned off just like in the `thumb_base` module - emit_debug_gdb_scripts: false, - - ..TargetOptions::default() + ..super::thumb_base::opts() }, }) } From ec9c8d81f65cf4a1d8ce720bfe06b8312903f845 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sat, 18 Jul 2020 23:01:01 -0600 Subject: [PATCH 12/12] remove unused imports --- src/librustc_target/spec/thumbv4t_none_eabi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_target/spec/thumbv4t_none_eabi.rs b/src/librustc_target/spec/thumbv4t_none_eabi.rs index 1e55efbb59fba..31417b0154759 100644 --- a/src/librustc_target/spec/thumbv4t_none_eabi.rs +++ b/src/librustc_target/spec/thumbv4t_none_eabi.rs @@ -8,7 +8,7 @@ //! //! **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::{LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions, TargetResult}; +use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { Ok(Target {