Skip to content

Commit

Permalink
arch/risc-v: add rv64ilp32 toolchain
Browse files Browse the repository at this point in the history
This introduces the rv64ilp32 toolchain from RuyiSDK for building
initial nuttx binary using 32-bit pointers. Behavior of existing
toolchains are unaffected.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed Jun 6, 2024
1 parent c1f3245 commit 8b8a09e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 8 additions & 1 deletion arch/risc-v/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ 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 && !RISCV_TOOLCHAIN_GNU_RV64ILP32

config ARCH_RV_ISA_M
bool
Expand Down Expand Up @@ -547,6 +547,13 @@ 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
---help---
This option work with Ruyisdk toolchain (GCC 13 or newer)
configured for riscv64-unknown-elf.

endchoice # Toolchain Selection

config RISCV_SEMIHOSTING_HOSTFS
Expand Down
6 changes: 6 additions & 0 deletions arch/risc-v/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ typedef unsigned short _uint16_t;
typedef signed int _int32_t;
typedef unsigned int _uint32_t;

#ifdef CONFIG_RISCV_TOOLCHAIN_GNU_RV64ILP32
typedef signed long long _int64_t;
typedef unsigned long long _uint64_t;
#else
typedef signed long _int64_t;
typedef unsigned long _uint64_t;
#endif

#else /* CONFIG_ARCH_RV64 */
typedef signed long _int32_t;
typedef unsigned long _uint32_t;
Expand Down
13 changes: 11 additions & 2 deletions arch/risc-v/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_RISCV_TOOLCHAIN_GNU_RV64ILP32)
add_link_options(-Wl,-melf32lriscv)
else()
add_link_options(-Wl,-melf64lriscv)
endif()
endif()

if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
Expand Down Expand Up @@ -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_RISCV_TOOLCHAIN_GNU_RV64ILP32)
set(ARCHABITYPE "ilp32")
else()
set(ARCHABITYPE "lp64")
endif()
set(LLVM_ARCHTYPE "riscv64")
endif()

Expand Down

0 comments on commit 8b8a09e

Please sign in to comment.