From 0b269f33f4d848b57cd2bb44ce22c1d305ae32ea Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 8 Jan 2022 14:21:38 +0100 Subject: [PATCH 1/8] add kernel target for RustyHermit Currently, we are thinking to use *-unknown-none targets instead to define for every platform our own one (see hermitcore/rusty-hermit#197). However, the current target aarch64-unknown-none-softfloat doesn't support dynamic relocation. Our kernel uses this feature and consequently we define a new target aarch64-unknown-hermitkernel to support it. --- .../src/spec/aarch64_unknown_hermit.rs | 1 + .../src/spec/aarch64_unknown_hermitkernel.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs b/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs index 44beb2f6ad8d3..f8e1e1b02f5a2 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs @@ -3,6 +3,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::hermit_base::opts(); base.max_atomic_width = Some(128); + base.features = "+strict-align,+neon,+fp-armv8".to_string(); Target { llvm_target: "aarch64-unknown-hermit".to_string(), diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs b/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs new file mode 100644 index 0000000000000..6e9d6c6221ccc --- /dev/null +++ b/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs @@ -0,0 +1,16 @@ +use crate::spec::Target; + +pub fn target() -> Target { + let mut base = super::hermit_kernel_base::opts(); + base.max_atomic_width = Some(128); + base.abi = "softfloat".to_string(); + base.features = "+strict-align,-neon,-fp-armv8".to_string(); + + Target { + llvm_target: "aarch64-unknown-hermit".to_string(), + pointer_width: 64, + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + options: base, + } +} From 10ae04a157125445ff2e2d10d142d81e3cc8acad Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 00:13:45 +0100 Subject: [PATCH 2/8] add missing description of the target aarch64-unknown-none-hermitkernel --- src/doc/rustc/src/platform-support.md | 7 +- .../aarch64-unknown-none-hermitkernel.md | 77 +++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index b6ae8c9333f31..1cdc1372c2127 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -204,7 +204,8 @@ target | std | host | notes `aarch64-apple-tvos` | * | | ARM64 tvOS [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD -`aarch64-unknown-hermit` | ? | | +`aarch64_unknown_hermit` | ✓ | |ARM64 HermitCore +[`aarch64_unknown_none_hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) `aarch64-unknown-netbsd` | ✓ | ✓ | @@ -286,10 +287,10 @@ target | std | host | notes `x86_64-sun-solaris` | ? | | Deprecated target for 64-bit Solaris 10/11, illumos `x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD `x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku -`x86_64-unknown-hermit` | ? | | +`x86_64-unknown-hermit` | ✓ | | HermitCore `x86_64-unknown-l4re-uclibc` | ? | | [`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | | Freestanding/bare-metal x86_64, softfloat -`x86_64-unknown-none-hermitkernel` | ? | | HermitCore kernel +`x86_64-unknown-none-hermitkernel` | * | | HermitCore kernel `x86_64-unknown-none-linuxkernel` | * | | Linux kernel modules [`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD `x86_64-unknown-uefi` | * | | 64-bit UEFI diff --git a/src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md b/src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md new file mode 100644 index 0000000000000..b8967f631878c --- /dev/null +++ b/src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md @@ -0,0 +1,77 @@ +# `aarch64-unknown-none-hermitkernel` + +**Tier: 3** + +Required to build the kernel for [HermitCore](https://github.com/hermitcore/hermit-playground) +or [RustyHermit](https://github.com/hermitcore/rusty-hermit). +The result is a bare-metal aarch64 binary in ELF format. + +## Target maintainers + +- Stefan Lankes, https://github.com/stlankes + +## Requirements + +This target is cross-compiled. There is no support for `std`, but the +library operating system provides a simple allocator to use `alloc`. + +By default, Rust code generated for this target does not use any vector or +floating-point registers. This allows the generated code to build the library +operaring system, which may need to avoid the use of such +registers or which may have special considerations about the use of such +registers (e.g. saving and restoring them to avoid breaking userspace code +using the same registers). In contrast to `aarch64-unknown-none-softfloat`, +the target is completly relocatable, which is a required feature of RustyHermit. + +By default, code generated with this target should run on any `aarch64` +hardware; enabling additional target features may raise this baseline. +On `aarch64-unknown-none-hermitkernel`, `extern "C"` uses the [standard System V calling +convention](https://github.com/ARM-software/abi-aa/releases/download/2021Q3/sysvabi64.pdf), +without red zones. + +This target generated binaries in the ELF format. + +## Building the target + +Typical you should not use the target directly. The target `aarch64-unknown-hermit` +builds the _user space_ of RustyHermit and supports red zones and floating-point +operations. +To build and link the kernel to the application, the crate +[hermit-sys](https://github.com/hermitcore/rusty-hermit/tree/master/hermit-sys) +should be used by adding the following lines to the `Cargo.toml` file of +your application. + +```toml +[target.'cfg(target_os = "hermit")'.dependencies] +hermit-sys = "0.1.*" +``` + +The crate `hermit-sys` uses the target `aarch64-unknown-none-hermitkernel` +to build the kernel. + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for this target. To compile for +this target, you need to build the crate `hermit-sys` (see +"Building the target" above). + +## Testing + +As `aarch64-unknown-none-hermitkernel` does not support `std` +and does not support running any Rust testsuite. + +## Cross-compilation toolchains and C code + +If you want to compile C code along with Rust you will need an +appropriate `aarch64` toolchain. + +Rust *may* be able to use an `aarch64-linux-gnu-` toolchain with appropriate +standalone flags to build for this toolchain (depending on the assumptions of +that toolchain, see below), or you may wish to use a separate +`aarch64-unknown-none` (or `aarch64-elf-`) toolchain. + +On some `aarch64` hosts that use ELF binaries, you *may* be able to use the host +C toolchain, if it does not introduce assumptions about the host environment +that don't match the expectations of a standalone environment. Otherwise, you +may need a separate toolchain for standalone/freestanding development, just as +when cross-compiling from a non-`aarch64` platform. From 9225df3ca7c69a2d8d78e88f32020207e185a8ce Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 07:44:32 +0100 Subject: [PATCH 3/8] remove typos --- src/doc/rustc/src/platform-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 1cdc1372c2127..dc3a1f2a0e2f2 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -205,7 +205,7 @@ target | std | host | notes [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD `aarch64_unknown_hermit` | ✓ | |ARM64 HermitCore -[`aarch64_unknown_none_hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel +[`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) `aarch64-unknown-netbsd` | ✓ | ✓ | From 1acf739563611909e2857ff971c138c8ac6ac911 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 07:45:04 +0100 Subject: [PATCH 4/8] add missing link --- 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 2cf2660327384..aecd892ce8b3b 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -17,6 +17,7 @@ - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) + - [aarch64-unknown-none-hermitkernel](platform-support/aarch64-unknown-none-hermitkernel.md) - [\*-kmc-solid_\*](platform-support/kmc-solid.md) - [*-unknown-openbsd](platform-support/openbsd.md) - [x86_64-unknown-none](platform-support/x86_64-unknown-none.md) From c7f65ae401411c78e353f96eb4e03cc98efd9733 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 09:09:50 +0100 Subject: [PATCH 5/8] remove typo --- src/doc/rustc/src/platform-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index dc3a1f2a0e2f2..0685a39fa7065 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -204,7 +204,7 @@ target | std | host | notes `aarch64-apple-tvos` | * | | ARM64 tvOS [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD -`aarch64_unknown_hermit` | ✓ | |ARM64 HermitCore +`aarch64-unknown-hermit` | ✓ | |ARM64 HermitCore [`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) From beb042ae8fb70d503130537e295825ae352c8301 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 15:43:54 +0100 Subject: [PATCH 6/8] add missing targert for library operating system RustyHermit --- compiler/rustc_target/src/spec/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4407f22b90599..d735f3d41fdb0 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -964,6 +964,7 @@ supported_targets! { ("aarch64-unknown-hermit", aarch64_unknown_hermit), ("x86_64-unknown-hermit", x86_64_unknown_hermit), + ("aarch64-unknown-none-hermitkernel", aarch64_unknown_none_hermitkernel), ("x86_64-unknown-none-hermitkernel", x86_64_unknown_none_hermitkernel), ("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf), From b5c1dc09fc03392756cfbebead053d5908a3c3d2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 16:30:06 +0100 Subject: [PATCH 7/8] rename file to use the correct naming convention --- ...known_hermitkernel.rs => aarch64_unknown_none_hermitkernel.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename compiler/rustc_target/src/spec/{aarch64_unknown_hermitkernel.rs => aarch64_unknown_none_hermitkernel.rs} (100%) diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs b/compiler/rustc_target/src/spec/aarch64_unknown_none_hermitkernel.rs similarity index 100% rename from compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs rename to compiler/rustc_target/src/spec/aarch64_unknown_none_hermitkernel.rs From df70adffcee10ed3f5c050642e7e027259652dab Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 8 Feb 2022 09:26:11 +0100 Subject: [PATCH 8/8] add missing space --- src/doc/rustc/src/platform-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 0685a39fa7065..d4a5f0e5a98c2 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -204,7 +204,7 @@ target | std | host | notes `aarch64-apple-tvos` | * | | ARM64 tvOS [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD -`aarch64-unknown-hermit` | ✓ | |ARM64 HermitCore +`aarch64-unknown-hermit` | ✓ | | ARM64 HermitCore [`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI)