]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ARM: 9441/1: rust: Enable Rust support for ARMv7
authorChristian Schrrefl <chrisi.schrefl@gmail.com>
Thu, 30 Jan 2025 23:03:45 +0000 (00:03 +0100)
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Wed, 26 Mar 2025 13:31:16 +0000 (13:31 +0000)
This commit allows building ARMv7 kernels with Rust support.

The rust core library expects some __eabi_... functions
that are not implemented in the kernel.
Those functions are some float operations and __aeabi_uldivmod.
For now those are implemented with define_panicking_intrinsics!.

This is based on the code by Sven Van Asbroeck from the original
rust branch and inspired by the AArch version by Jamie Cunliffe.

I have tested the rust samples and a custom simple MMIO module
on hardware (De1SoC FPGA + Arm A9 CPU).

Tested-by: Rudraksha Gupta <guptarud@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Christian Schrefl <chrisi.schrefl@gmail.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Documentation/rust/arch-support.rst
arch/arm/Kconfig
arch/arm/Makefile
rust/Makefile
rust/compiler_builtins.rs
scripts/generate_rust_target.rs

index 54be7ddf3e57a732dbbca85541b137c62e834d7d..6e6a515d08991a130a8e79dc4ad7ad09da244020 100644 (file)
@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
 =============  ================  ==============================================
 Architecture   Level of support  Constraints
 =============  ================  ==============================================
+``arm``        Maintained        ARMv7 Little Endian only.
 ``arm64``      Maintained        Little Endian only.
 ``loongarch``  Maintained        \-
 ``riscv``      Maintained        ``riscv64`` and LLVM/Clang only.
index 835b5f100e926e54bab4be7802aeada4af37a145..202dbd17ad2ff455eb9fc214f7e4b1de967ea9e1 100644 (file)
@@ -133,6 +133,7 @@ config ARM
        select MMU_GATHER_RCU_TABLE_FREE if SMP && ARM_LPAE
        select HAVE_REGS_AND_STACK_ACCESS_API
        select HAVE_RSEQ
+       select HAVE_RUST if CPU_LITTLE_ENDIAN && CPU_32v7
        select HAVE_STACKPROTECTOR
        select HAVE_SYSCALL_TRACEPOINTS
        select HAVE_UID16
index 00ca7886b18efe2d01f33bc079eda2483ec807a7..4808d3ed98e42d39afc676f2654381f288d1b5b7 100644 (file)
@@ -150,6 +150,7 @@ endif
 KBUILD_CPPFLAGS        +=$(cpp-y)
 KBUILD_CFLAGS  +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
 KBUILD_AFLAGS  +=$(CFLAGS_ABI) $(AFLAGS_ISA) -Wa,$(arch-y) $(tune-y) -include asm/unified.h -msoft-float
+KBUILD_RUSTFLAGS += --target=arm-unknown-linux-gnueabi
 
 CHECKFLAGS     += -D__arm__
 
index 8fcfd60447bc89ba2c66a4f341288db2387b0956..5b45f760f4620cd66cd012b25086fad16dd55d7e 100644 (file)
@@ -245,6 +245,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
 # Derived from `scripts/Makefile.clang`.
 BINDGEN_TARGET_x86     := x86_64-linux-gnu
 BINDGEN_TARGET_arm64   := aarch64-linux-gnu
+BINDGEN_TARGET_arm     := arm-linux-gnueabi
 BINDGEN_TARGET         := $(BINDGEN_TARGET_$(SRCARCH))
 
 # All warnings are inhibited since GCC builds are very experimental,
@@ -397,6 +398,13 @@ redirect-intrinsics = \
        __muloti4 __multi3 \
        __udivmodti4 __udivti3 __umodti3
 
+ifdef CONFIG_ARM
+       # Add eabi initrinsics for ARM 32-bit
+       redirect-intrinsics += \
+               __aeabi_fadd __aeabi_fmul __aeabi_fcmpeq __aeabi_fcmple __aeabi_fcmplt __aeabi_fcmpun \
+               __aeabi_dadd __aeabi_dmul __aeabi_dcmple __aeabi_dcmplt __aeabi_dcmpun \
+               __aeabi_uldivmod
+endif
 ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
        # These intrinsics are defined for ARM64 and RISCV64
        redirect-intrinsics += \
index f14b8d7caf89964198313deace1bcb06fea82964..dd16c1dc899cbc755630ef3bae71e6eb0fd2c62a 100644 (file)
@@ -73,5 +73,29 @@ define_panicking_intrinsics!("`u128` should not be used", {
     __umodti3,
 });
 
+#[cfg(target_arch = "arm")]
+define_panicking_intrinsics!("`f32` should not be used", {
+    __aeabi_fadd,
+    __aeabi_fmul,
+    __aeabi_fcmpeq,
+    __aeabi_fcmple,
+    __aeabi_fcmplt,
+    __aeabi_fcmpun,
+});
+
+#[cfg(target_arch = "arm")]
+define_panicking_intrinsics!("`f64` should not be used", {
+    __aeabi_dadd,
+    __aeabi_dmul,
+    __aeabi_dcmple,
+    __aeabi_dcmplt,
+    __aeabi_dcmpun,
+});
+
+#[cfg(target_arch = "arm")]
+define_panicking_intrinsics!("`u64` division/modulo should not be used", {
+    __aeabi_uldivmod,
+});
+
 // NOTE: if you are adding a new intrinsic here, you should also add it to
 // `redirect-intrinsics` in `rust/Makefile`.
index 0d00ac3723b5e5971acb47478d6c2a63bc4ed6c6..f8e7fb38bf160ab35c9331a732fcd2fe4023fead 100644 (file)
@@ -172,7 +172,9 @@ fn main() {
     let mut ts = TargetSpec::new();
 
     // `llvm-target`s are taken from `scripts/Makefile.clang`.
-    if cfg.has("ARM64") {
+    if cfg.has("ARM") {
+        panic!("arm uses the builtin rustc target");
+    } else if cfg.has("ARM64") {
         panic!("arm64 uses the builtin rustc aarch64-unknown-none target");
     } else if cfg.has("RISCV") {
         if cfg.has("64BIT") {