Skip to content

Commit ccb8ce5

Browse files
onestackedRussell King (Oracle)
authored and
Russell King (Oracle)
committed
ARM: 9441/1: rust: Enable Rust support for ARMv7
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 <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Tested-by: Miguel Ojeda <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Christian Schrefl <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent f9733aa commit ccb8ce5

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

Documentation/rust/arch-support.rst

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
1515
============= ================ ==============================================
1616
Architecture Level of support Constraints
1717
============= ================ ==============================================
18+
``arm`` Maintained ARMv7 Little Endian only.
1819
``arm64`` Maintained Little Endian only.
1920
``loongarch`` Maintained \-
2021
``riscv`` Maintained ``riscv64`` and LLVM/Clang only.

arch/arm/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ config ARM
133133
select MMU_GATHER_RCU_TABLE_FREE if SMP && ARM_LPAE
134134
select HAVE_REGS_AND_STACK_ACCESS_API
135135
select HAVE_RSEQ
136+
select HAVE_RUST if CPU_LITTLE_ENDIAN && CPU_32v7
136137
select HAVE_STACKPROTECTOR
137138
select HAVE_SYSCALL_TRACEPOINTS
138139
select HAVE_UID16

arch/arm/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ endif
150150
KBUILD_CPPFLAGS +=$(cpp-y)
151151
KBUILD_CFLAGS +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
152152
KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) -Wa,$(arch-y) $(tune-y) -include asm/unified.h -msoft-float
153+
KBUILD_RUSTFLAGS += --target=arm-unknown-linux-gnueabi
153154

154155
CHECKFLAGS += -D__arm__
155156

rust/Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
245245
# Derived from `scripts/Makefile.clang`.
246246
BINDGEN_TARGET_x86 := x86_64-linux-gnu
247247
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
248+
BINDGEN_TARGET_arm := arm-linux-gnueabi
248249
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
249250

250251
# All warnings are inhibited since GCC builds are very experimental,
@@ -397,6 +398,13 @@ redirect-intrinsics = \
397398
__muloti4 __multi3 \
398399
__udivmodti4 __udivti3 __umodti3
399400

401+
ifdef CONFIG_ARM
402+
# Add eabi initrinsics for ARM 32-bit
403+
redirect-intrinsics += \
404+
__aeabi_fadd __aeabi_fmul __aeabi_fcmpeq __aeabi_fcmple __aeabi_fcmplt __aeabi_fcmpun \
405+
__aeabi_dadd __aeabi_dmul __aeabi_dcmple __aeabi_dcmplt __aeabi_dcmpun \
406+
__aeabi_uldivmod
407+
endif
400408
ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
401409
# These intrinsics are defined for ARM64 and RISCV64
402410
redirect-intrinsics += \

rust/compiler_builtins.rs

+24
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,29 @@ define_panicking_intrinsics!("`u128` should not be used", {
7373
__umodti3,
7474
});
7575

76+
#[cfg(target_arch = "arm")]
77+
define_panicking_intrinsics!("`f32` should not be used", {
78+
__aeabi_fadd,
79+
__aeabi_fmul,
80+
__aeabi_fcmpeq,
81+
__aeabi_fcmple,
82+
__aeabi_fcmplt,
83+
__aeabi_fcmpun,
84+
});
85+
86+
#[cfg(target_arch = "arm")]
87+
define_panicking_intrinsics!("`f64` should not be used", {
88+
__aeabi_dadd,
89+
__aeabi_dmul,
90+
__aeabi_dcmple,
91+
__aeabi_dcmplt,
92+
__aeabi_dcmpun,
93+
});
94+
95+
#[cfg(target_arch = "arm")]
96+
define_panicking_intrinsics!("`u64` division/modulo should not be used", {
97+
__aeabi_uldivmod,
98+
});
99+
76100
// NOTE: if you are adding a new intrinsic here, you should also add it to
77101
// `redirect-intrinsics` in `rust/Makefile`.

scripts/generate_rust_target.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ fn main() {
172172
let mut ts = TargetSpec::new();
173173

174174
// `llvm-target`s are taken from `scripts/Makefile.clang`.
175-
if cfg.has("ARM64") {
175+
if cfg.has("ARM") {
176+
panic!("arm uses the builtin rustc target");
177+
} else if cfg.has("ARM64") {
176178
panic!("arm64 uses the builtin rustc aarch64-unknown-none target");
177179
} else if cfg.has("RISCV") {
178180
if cfg.has("64BIT") {

0 commit comments

Comments
 (0)