From patchwork Fri Jun 7 22:30:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schrefl X-Patchwork-Id: 13690686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B251C27C55 for ; Fri, 7 Jun 2024 22:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:From:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=jhbgEX8vNDwI2/9d9J0vFFtRp+wYCy1UScCGlVMHiqA=; b=PyYF3qi1MF9oBD rWN9RZqC0LQmab71+1VR2NvEmVulXsEDUIaeOuPuk5KeQ8CQCfl7/vl1BzygVF0hvjKCafMXBhzt1 IcyZahVyHfe3Y4URzal/B+p6GLEcNXSdDQUjG+chzwn0JYktWQDfM+YfNpowTES7bp7/EJZRVXb91 hFofhdZjkIC/cRKYS0DUPT4ObDREMq9r/XmW7E68QcC8lVMxXUximzi52EvoJmhtuaLbVS0xYfg8g BQNU1pKjcAvrMo13UOInjzQG6cSiqGX3/Ejy9+5q4PVLPYG2kDHOAwJFTqAWpfzY3+i4Y3wZliSZ1 q7YzUE1rDJmsltxIuKPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sFi6H-0000000FrHx-2IMf; Fri, 07 Jun 2024 22:30:21 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sFi6E-0000000FrEB-1lR2 for linux-arm-kernel@lists.infradead.org; Fri, 07 Jun 2024 22:30:20 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a68ca4d6545so467874366b.0 for ; Fri, 07 Jun 2024 15:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717799414; x=1718404214; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:subject:from:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=+CN4Fagcr9kw1yaYPk5eRmX9Rl/PBb8fEu5udOKhfOY=; b=ALlhVBrQ78v4lmk80CMaYgTrj4sDvx09IU2g8tA8bEkPTRORQfs30U1qUgFAoTpXlP +9kQossr+2AIZ53R4o+M4Xiu7Hrudc9P18mnJfmUU8YuhkEUNyVve0UDlvwsUfU3/G1i jRw6WfRfjJRnMjwDRZ93FupzK4u0axG1RElF+xSm2Fdt9hCQpISpVYtvLE4WVDC23ODu yiErvtX5fGqjbdbSzey9isZ3OryQX8lhOoiRd1LlHB7OXZ0HR20lRwDIcd+hltEc4rwy ty0VqSoG1z7nXvpfeiKHdFLDcVJVVVsKWGlROEcuR4BwtdpbX/lQ4NM/O3VQAUiWR8/t tDgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717799414; x=1718404214; h=content-transfer-encoding:cc:to:subject:from:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=+CN4Fagcr9kw1yaYPk5eRmX9Rl/PBb8fEu5udOKhfOY=; b=sBmpaUd+bXen985dvyJuE8Wjk4gMdbFWqUEIREu5W81QqMfZg7sfNlyITE1/3fQpgZ r6kv4mmBkxof+/c5mzT3CjTYlHu1782nS8l8yJjqugocmTHPUYnnblng8Cjsh8lJWjTr w4mTF7d5c1KWslikvfH8A2h/LO0zpL/xsyuP/XnJJmZyQlIS9zF1bVQz4u3GRDuE6wgJ Nnqa/FstSkxWMY/S98sET/3JEU4bn7hN0YC9ZSMiRaUBq4MYHoyE594GKMgadQ20MBUY 7+GJrwTfV1kpal/Bm9ZRWHnZkFy2CedWBJXmRTpUWxg7kb3D7weXFy6QoE6IVDFjUSyk orlA== X-Forwarded-Encrypted: i=1; AJvYcCVkUqJ8CKl00LNabV4d04Z4cLGCLznwTznhVkUPBz3y3qEgJr8BQD3uaf3G57sNdXGCmtGEYIu+zk1PtrynIhheoS8ODpRTQlmarOdmx1HcVqERLwA= X-Gm-Message-State: AOJu0YwfILMbdOHQ9aX77JvMje2gYviAcAiikHICM5DnHaIaCQ6trEkV 6Gyf4sJzONJ12jvPcejzg3Gmwm9myd6CoKqqaHq53vkFbWE4obLv X-Google-Smtp-Source: AGHT+IHPgEwmpOZ+rHjWFDdF79iPXCV9lwQCFpy9QbdOdMW+rl+644y2eM/xOb5ilZlXNNr/KU/z4w== X-Received: by 2002:a17:906:c8c1:b0:a6d:fbed:7953 with SMTP id a640c23a62f3a-a6dfbed7a3cmr238081466b.27.1717799414057; Fri, 07 Jun 2024 15:30:14 -0700 (PDT) Received: from [10.5.1.156] (188-22-218-164.adsl.highway.telekom.at. [188.22.218.164]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6c8070bfcbsm305295866b.145.2024.06.07.15.30.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jun 2024 15:30:13 -0700 (PDT) Message-ID: <4e0f5932-c7bc-4878-862c-1186cbecd71d@gmail.com> Date: Sat, 8 Jun 2024 00:30:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Christian Schrefl Subject: [PATCH 1/1] arm: rust: Enable Rust support for ARMv7 To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Jamie Cunliffe , Sven Van Asbroeck X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240607_153018_509457_E3A272AA X-CRM114-Status: GOOD ( 19.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. 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 on hardware (De1SoC FPGA + Arm A9 CPU). Signed-off-by: Christian Schrefl --- Documentation/rust/arch-support.rst | 1 + arch/arm/Kconfig | 1 + arch/arm/Makefile | 1 + rust/Makefile | 10 +++++++++- rust/bindgen_parameters | 4 ++++ rust/compiler_builtins.rs | 24 ++++++++++++++++++++++++ scripts/generate_rust_target.rs | 4 +++- 7 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst index b13e19d84744..4bf5205f526d 100644 --- a/Documentation/rust/arch-support.rst +++ b/Documentation/rust/arch-support.rst @@ -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`` only. diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index ee5115252aac..f07149fe078b 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -126,6 +126,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 diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 71afdd98ddf2..9cc10e32e8be 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -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__ diff --git a/rust/Makefile b/rust/Makefile index f70d5e244fee..ef177ffb68a8 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -286,7 +286,8 @@ 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_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, @@ -413,6 +414,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 += \ diff --git a/rust/bindgen_parameters b/rust/bindgen_parameters index a721d466bee4..bf0148b3019e 100644 --- a/rust/bindgen_parameters +++ b/rust/bindgen_parameters @@ -24,3 +24,7 @@ # These functions use the `__preserve_most` calling convention, which neither bindgen # nor Rust currently understand, and which Clang currently declares to be unstable. --blocklist-function __list_.*_report + +# Depending on how the architecute defines ARCH_SLAB_MINALIGN, bindgen might generate a binding. +# Disable this here as there is a const that will always be generated in bindings_helper.c +--blocklist-item ARCH_SLAB_MINALIGN diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs index bba2922c6ef7..c37142b16a45 100644 --- a/rust/compiler_builtins.rs +++ b/rust/compiler_builtins.rs @@ -70,5 +70,29 @@ pub extern "C" fn $ident() { __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`. diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 641b713a033a..acfcf2e22e28 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -148,7 +148,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") {