From 33afbaadb9d75148bb12e149d0ac03651da71a50 Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Sat, 8 Jun 2024 08:45:28 +0800 Subject: [PATCH] arch/risc-v: add rv64ilp32 toolchain This adds support of rv64ilp32 toolchain available from Github repo `ruyisdk/riscv-gnu-toolchain-rv64ilp32`. With this 32-bit nuttx can be generated for RV64 devices. Signed-off-by: Yanfeng Liu --- arch/risc-v/Kconfig | 15 ++++++++++++++- arch/risc-v/src/cmake/Toolchain.cmake | 13 +++++++++++-- arch/risc-v/src/common/Toolchain.defs | 10 +++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/arch/risc-v/Kconfig b/arch/risc-v/Kconfig index 428768b320..bd370372ac 100644 --- a/arch/risc-v/Kconfig +++ b/arch/risc-v/Kconfig @@ -337,7 +337,12 @@ config ARCH_RV32 config ARCH_RV64 bool default n - select LIBC_ARCH_ELF_64BIT if LIBC_ARCH_ELF + select LIBC_ARCH_ELF_64BIT if LIBC_ARCH_ELF && !ARCH_RV64ILP32 + +config ARCH_RV64ILP32 + bool + depends on ARCH_RV64 + default n config ARCH_RV_ISA_M bool @@ -547,6 +552,14 @@ config RISCV_TOOLCHAIN_CLANG bool "LLVM Clang toolchain" select ARCH_TOOLCHAIN_CLANG +config RISCV_TOOLCHAIN_GNU_RV64ILP32 + bool "Generic GNU RV64ILP32 toolchain" + select ARCH_TOOLCHAIN_GNU + select ARCH_RV64ILP32 + ---help--- + This option work with Ruyisdk toolchain (GCC 13 or newer) + configured for riscv64-unknown-elf. + endchoice # Toolchain Selection config RISCV_SEMIHOSTING_HOSTFS diff --git a/arch/risc-v/src/cmake/Toolchain.cmake b/arch/risc-v/src/cmake/Toolchain.cmake index 05de8ac833..fb0e9d1db5 100644 --- a/arch/risc-v/src/cmake/Toolchain.cmake +++ b/arch/risc-v/src/cmake/Toolchain.cmake @@ -26,6 +26,7 @@ set(CMAKE_CXX_COMPILER_FORCED TRUE) if(CONFIG_RISCV_TOOLCHAIN_GNU_RV32 OR CONFIG_RISCV_TOOLCHAIN_GNU_RV64 + OR CONFIG_RISCV_TOOLCHAIN_GNU_RV64ILP32 OR CONFIG_RISCV_TOOLCHAIN_CLANG) if(NOT CONFIG_RISCV_TOOLCHAIN) set(CONFIG_RISCV_TOOLCHAIN GNU_RVG) @@ -184,7 +185,11 @@ if(CONFIG_ARCH_RV32) add_link_options(-Wl,-melf32lriscv) elseif(CONFIG_ARCH_RV64) add_compile_options(-mcmodel=medany) - add_link_options(-Wl,-melf64lriscv) + if(CONFIG_ARCH_RV64ILP32) + add_link_options(-Wl,-melf32lriscv) + else() + add_link_options(-Wl,-melf64lriscv) + endif() endif() if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS) @@ -268,7 +273,11 @@ if(${CONFIG_RISCV_TOOLCHAIN} STREQUAL GNU_RVG) set(LLVM_ARCHTYPE "riscv32") elseif(CONFIG_ARCH_RV64) set(ARCHTYPE "rv64") - set(ARCHABITYPE "lp64") + if(CONFIG_ARCH_RV64ILP32) + set(ARCHABITYPE "ilp32") + else() + set(ARCHABITYPE "lp64") + endif() set(LLVM_ARCHTYPE "riscv64") endif() diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs index 4600f915fb..ca7f8de05d 100644 --- a/arch/risc-v/src/common/Toolchain.defs +++ b/arch/risc-v/src/common/Toolchain.defs @@ -29,6 +29,8 @@ ifeq ($(filter y, $(CONFIG_RISCV_TOOLCHAIN_GNU_RV64)),y) CONFIG_RISCV_TOOLCHAIN ?= GNU_RVG +else ifeq ($(filter y, $(CONFIG_RISCV_TOOLCHAIN_GNU_RV64ILP32)),y) + CONFIG_RISCV_TOOLCHAIN ?= GNU_RVG else ifeq ($(filter y, $(CONFIG_RISCV_TOOLCHAIN_GNU_RV32)),y) CONFIG_RISCV_TOOLCHAIN ?= GNU_RVG else ifeq ($(filter y, $(CONFIG_RISCV_TOOLCHAIN_CLANG)),y) @@ -119,6 +121,8 @@ SHMODULEFLAGS = -Bsymbolic -G -Bdynamic --entry=__start ifeq ($(CONFIG_ARCH_RV32),y) LDFLAGS += -melf32lriscv SHMODULEFLAGS += -melf32lriscv +else ifeq ($(CONFIG_ARCH_RV64ILP32),y) +LDFLAGS += -melf32lriscv else LDFLAGS += -melf64lriscv endif @@ -231,7 +235,11 @@ ifeq ($(CONFIG_RISCV_TOOLCHAIN),GNU_RVG) LLVM_ARCHTYPE := riscv32 else ifeq ($(CONFIG_ARCH_RV64),y) ARCHTYPE = rv64 - ARCHABITYPE = lp64 + ifeq ($(CONFIG_ARCH_RV64ILP32),y) + ARCHABITYPE = ilp32 + else + ARCHABITYPE = lp64 + endif LLVM_ARCHTYPE := riscv64 # https://www.sifive.com/blog/all-aboard-part-4-risc-v-code-models ARCHCPUFLAGS = -mcmodel=medany