diff --git a/eng/build.sh b/eng/build.sh index 91ea9dbd4783d4..84a4fd746c9177 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -17,7 +17,7 @@ scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" usage() { echo "Common settings:" - echo " --arch (-a) Target platform: x86, x64, arm, armv6, armel, arm64, loongarch64, s390x, ppc64le or wasm." + echo " --arch (-a) Target platform: x86, x64, arm, armv6, armel, arm64, loongarch64, riscv64, s390x, ppc64le or wasm." echo " [Default: Your machine's architecture.]" echo " --binaryLog (-bl) Output binary log." echo " --cross Optional argument to signify cross compilation." @@ -206,12 +206,12 @@ while [[ $# > 0 ]]; do fi passedArch="$(echo "$2" | tr "[:upper:]" "[:lower:]")" case "$passedArch" in - x64|x86|arm|armv6|armel|arm64|loongarch64|s390x|ppc64le|wasm) + x64|x86|arm|armv6|armel|arm64|loongarch64|riscv64|s390x|ppc64le|wasm) arch=$passedArch ;; *) echo "Unsupported target architecture '$2'." - echo "The allowed values are x86, x64, arm, armv6, armel, arm64, loongarch64, s390x, ppc64le and wasm." + echo "The allowed values are x86, x64, arm, armv6, armel, arm64, loongarch64, riscv64, s390x, ppc64le and wasm." exit 1 ;; esac diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 3f05aef7f53e06..4199828f2970be 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -197,7 +197,7 @@ usage() echo "" echo "Common Options:" echo "" - echo "BuildArch can be: -arm, -armv6, -armel, -arm64, -loongarch64, -s390x, -ppc64le, x64, x86, -wasm" + echo "BuildArch can be: -arm, -armv6, -armel, -arm64, -loongarch64, -riscv64, -s390x, -ppc64le, x64, x86, -wasm" echo "BuildType can be: -debug, -checked, -release" echo "-os: target OS (defaults to running OS)" echo "-bindir: output directory (defaults to $__ProjectRoot/artifacts)" @@ -384,6 +384,10 @@ while :; do __TargetArch=loongarch64 ;; + riscv64|-riscv64) + __TargetArch=riscv64 + ;; + s390x|-s390x) __TargetArch=s390x ;; diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 551a2dc7f2a2bc..0642fccae90080 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -227,6 +227,9 @@ elseif (CLR_CMAKE_HOST_ARCH_ARM64) elseif (CLR_CMAKE_HOST_ARCH_LOONGARCH64) set(ARCH_HOST_NAME loongarch64) add_definitions(-DHOST_LOONGARCH64 -DHOST_64BIT) +elseif (CLR_CMAKE_HOST_ARCH_RISCV64) + set(ARCH_HOST_NAME riscv64) + add_definitions(-DHOST_RISCV64 -DHOST_64BIT) elseif (CLR_CMAKE_HOST_ARCH_S390X) set(ARCH_HOST_NAME s390x) add_definitions(-DHOST_S390X -DHOST_64BIT -DBIGENDIAN) @@ -238,7 +241,7 @@ elseif (CLR_CMAKE_HOST_ARCH_MIPS64) add_definitions(-DHOST_MIPS64 -DHOST_64BIT=1) elseif (CLR_CMAKE_HOST_ARCH_POWERPC64) set(ARCH_HOST_NAME ppc64le) - add_definitions(-DHOST_POWERPC64 -DHOST_64BIT) + add_definitions(-DHOST_POWERPC64 -DHOST_64BIT) else () clr_unknown_arch() endif () @@ -248,13 +251,15 @@ if (CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_UNIX_AMD64) message("Detected Linux x86_64") elseif(CLR_CMAKE_HOST_UNIX_ARM) - message("Detected Linux ARM") + message("Detected Linux arm") elseif(CLR_CMAKE_HOST_UNIX_ARMV6) - message("Detected Linux ARMv6") + message("Detected Linux armv6") elseif(CLR_CMAKE_HOST_UNIX_ARM64) - message("Detected Linux ARM64") + message("Detected Linux arm64") elseif(CLR_CMAKE_HOST_UNIX_LOONGARCH64) - message("Detected Linux LOONGARCH64") + message("Detected Linux loongarch64") + elseif(CLR_CMAKE_HOST_UNIX_RISCV64) + message("Detected Linux riscv64") elseif(CLR_CMAKE_HOST_UNIX_X86) message("Detected Linux i686") elseif(CLR_CMAKE_HOST_UNIX_S390X) @@ -332,6 +337,11 @@ elseif (CLR_CMAKE_TARGET_ARCH_LOONGARCH64) set(ARCH_SOURCES_DIR loongarch64) add_compile_definitions($<$>>:TARGET_LOONGARCH64>) add_compile_definitions($<$>>:TARGET_64BIT>) +elseif (CLR_CMAKE_TARGET_ARCH_RISCV64) + set(ARCH_TARGET_NAME riscv64) + set(ARCH_SOURCES_DIR riscv64) + add_compile_definitions($<$>>:TARGET_RISCV64>) + add_compile_definitions($<$>>:TARGET_64BIT>) elseif (CLR_CMAKE_TARGET_ARCH_S390X) set(ARCH_TARGET_NAME s390x) set(ARCH_SOURCES_DIR s390x) diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 315aa480c69357..c7a38c3eee8294 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -45,8 +45,10 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) set(CLR_CMAKE_HOST_UNIX_ARMV6 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) set(CLR_CMAKE_HOST_UNIX_ARM64 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL loongarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL loongarch64) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL loongarch64) set(CLR_CMAKE_HOST_UNIX_LOONGARCH64 1) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL riscv64) + set(CLR_CMAKE_HOST_UNIX_RISCV64 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686 OR CMAKE_SYSTEM_PROCESSOR STREQUAL x86) set(CLR_CMAKE_HOST_UNIX_X86 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL s390x) @@ -243,6 +245,9 @@ elseif(CLR_CMAKE_HOST_UNIX_ARM64) elseif(CLR_CMAKE_HOST_UNIX_LOONGARCH64) set(CLR_CMAKE_HOST_ARCH_LOONGARCH64 1) set(CLR_CMAKE_HOST_ARCH "loongarch64") +elseif(CLR_CMAKE_HOST_UNIX_RISCV64) + set(CLR_CMAKE_HOST_ARCH_RISCV64 1) + set(CLR_CMAKE_HOST_ARCH "riscv64") elseif(CLR_CMAKE_HOST_UNIX_AMD64) set(CLR_CMAKE_HOST_ARCH_AMD64 1) set(CLR_CMAKE_HOST_ARCH "x64") @@ -292,29 +297,31 @@ endif() # Set target architecture variables if (CLR_CMAKE_TARGET_ARCH STREQUAL x64) set(CLR_CMAKE_TARGET_ARCH_AMD64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) set(CLR_CMAKE_TARGET_ARCH_I386 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64) set(CLR_CMAKE_TARGET_ARCH_ARM64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL loongarch64) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL loongarch64) set(CLR_CMAKE_TARGET_ARCH_LOONGARCH64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL riscv64) + set(CLR_CMAKE_TARGET_ARCH_RISCV64 1) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm) set(CLR_CMAKE_TARGET_ARCH_ARM 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armv6) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armv6) set(CLR_CMAKE_TARGET_ARCH_ARMV6 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armel) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armel) set(CLR_CMAKE_TARGET_ARCH_ARM 1) set(CLR_CMAKE_TARGET_ARCH_ARMV7L 1) set(ARM_SOFTFP 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL s390x) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL s390x) set(CLR_CMAKE_TARGET_ARCH_S390X 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL ppc64le) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL ppc64le) set(CLR_CMAKE_TARGET_ARCH_POWERPC64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL wasm) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL wasm) set(CLR_CMAKE_TARGET_ARCH_WASM 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL mips64) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL mips64) set(CLR_CMAKE_TARGET_ARCH_MIPS64 1) - else() +else() clr_unknown_arch() endif() @@ -416,6 +423,8 @@ if(CLR_CMAKE_TARGET_UNIX) set(CLR_CMAKE_TARGET_UNIX_ARM64 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL loongarch64) set(CLR_CMAKE_TARGET_UNIX_LOONGARCH64 1) + elseif(CLR_CMAKE_TARGET_ARCH STREQUAL riscv64) + set(CLR_CMAKE_TARGET_UNIX_RISCV64 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) set(CLR_CMAKE_TARGET_UNIX_X86 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL s390x) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 8c497259ad2212..efb36de6e48b2d 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -4,7 +4,7 @@ function(clr_unknown_arch) elseif(CLR_CROSS_COMPONENTS_BUILD) message(FATAL_ERROR "Only AMD64, I386 host are supported for linux cross-architecture component. Found: ${CMAKE_SYSTEM_PROCESSOR}") else() - message(FATAL_ERROR "Only AMD64, ARMV6, ARM64, LOONGARCH64 and ARM are supported. Found: ${CMAKE_SYSTEM_PROCESSOR}") + message(FATAL_ERROR "'${CMAKE_SYSTEM_PROCESSOR}' is an unsupported architecture.") endif() endfunction() @@ -167,6 +167,10 @@ function(find_unwind_libs UnwindLibs) find_library(UNWIND_ARCH NAMES unwind-loongarch64) endif() + if(CLR_CMAKE_HOST_ARCH_RISCV64) + find_library(UNWIND_ARCH NAMES unwind-riscv64) + endif() + if(CLR_CMAKE_HOST_ARCH_AMD64) find_library(UNWIND_ARCH NAMES unwind-x86_64) endif() diff --git a/eng/native/init-os-and-arch.sh b/eng/native/init-os-and-arch.sh index ded32e3f755f36..887bb3b72f786b 100644 --- a/eng/native/init-os-and-arch.sh +++ b/eng/native/init-os-and-arch.sh @@ -41,6 +41,10 @@ case "$CPUName" in arch=loongarch64 ;; + riscv64) + arch=riscv64 + ;; + amd64|x86_64) arch=x64 ;; diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index c491422ae7bcec..5c5344bd80161c 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -68,7 +68,7 @@ if(DARWIN) else() message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm64 or x64 is supported for OSX cross build!") endif() -elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|s390x|ppc64le|x86)$" OR FREEBSD OR ILLUMOS) +elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s390x|ppc64le|x86)$" OR FREEBSD OR ILLUMOS) set_cache_value(FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL_EXITCODE 1) set_cache_value(GETPWUID_R_SETS_ERRNO_EXITCODE 0) set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 0) @@ -149,6 +149,6 @@ else() message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, armv6, arm64, loongarch64, s390x, ppc64le and x86 are supported!") endif() -if(TARGET_ARCH_NAME STREQUAL "x86" OR TARGET_ARCH_NAME STREQUAL "s390x" OR TARGET_ARCH_NAME STREQUAL "armv6" OR TARGET_ARCH_NAME STREQUAL "loongarch64" OR TARGET_ARCH_NAME STREQUAL "ppc64le") +if(TARGET_ARCH_NAME MATCHES "^(x86|s390x|armv6|loongarch64|riscv64|ppc64le)$") set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0) endif() diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj index f408f011f0280c..8f27f79fc5cc67 100644 --- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -83,6 +83,10 @@ AnyCPU $(DefineConstants);TARGET_LOONGARCH64 + + AnyCPU + $(DefineConstants);TARGET_RISCV64 + diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index ecb6b8fcc0b69d..ef9f907bc87647 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -459,6 +459,7 @@ elseif(CLR_CMAKE_TARGET_ARCH_POWERPC64) elseif(CLR_CMAKE_TARGET_ARCH_LOONGARCH64) set(JIT_ARCH_SOURCES ${JIT_LOONGARCH64_SOURCES}) set(JIT_ARCH_HEADERS ${JIT_LOONGARCH64_HEADERS}) +elseif(CLR_CMAKE_TARGET_ARCH_RISCV64) else() clr_unknown_arch() endif() @@ -589,8 +590,10 @@ else() set(TARGET_OS_NAME win) endif() -create_standalone_jit(TARGET clrjit OS ${TARGET_OS_NAME} ARCH ${ARCH_TARGET_NAME} DESTINATIONS . sharedFramework) -install_clr(TARGETS clrjit DESTINATIONS . sharedFramework COMPONENT jit) +if (NOT CLR_CMAKE_TARGET_ARCH_RISCV64) + create_standalone_jit(TARGET clrjit OS ${TARGET_OS_NAME} ARCH ${ARCH_TARGET_NAME} DESTINATIONS . sharedFramework) + install_clr(TARGETS clrjit DESTINATIONS . sharedFramework COMPONENT jit) +endif() # Enable profile guided optimization add_pgo(clrjit) @@ -613,7 +616,7 @@ if (CLR_CMAKE_TARGET_ARCH_I386 AND CLR_CMAKE_TARGET_UNIX) create_standalone_jit(TARGET clrjit_unix_x86_${ARCH_HOST_NAME} OS unix ARCH x86 DESTINATIONS .) endif (CLR_CMAKE_TARGET_ARCH_I386 AND CLR_CMAKE_TARGET_UNIX) -if (CLR_CMAKE_TARGET_UNIX) +if (CLR_CMAKE_TARGET_UNIX AND NOT CLR_CMAKE_TARGET_ARCH_RISCV64) if (NOT ARCH_TARGET_NAME STREQUAL s390x AND NOT ARCH_TARGET_NAME STREQUAL armv6 AND NOT ARCH_TARGET_NAME STREQUAL ppc64le) if(CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64) install_clr(TARGETS clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME} DESTINATIONS . COMPONENT jit) diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 933333aba64a26..1315dac0cb1b94 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -52,6 +52,8 @@ elseif(CLR_CMAKE_HOST_ARCH_ARM64) set(PAL_ARCH_SOURCES_DIR arm64) elseif(CLR_CMAKE_HOST_ARCH_LOONGARCH64) set(PAL_ARCH_SOURCES_DIR loongarch64) +elseif(CLR_CMAKE_HOST_ARCH_RISCV64) + set(PAL_ARCH_SOURCES_DIR riscv64) elseif(CLR_CMAKE_HOST_ARCH_I386) set(PAL_ARCH_SOURCES_DIR i386) elseif(CLR_CMAKE_HOST_ARCH_S390X) diff --git a/src/coreclr/pal/src/arch/riscv64/activationhandlerwrapper.S b/src/coreclr/pal/src/arch/riscv64/activationhandlerwrapper.S new file mode 100644 index 00000000000000..a7cd5b6c4d2403 --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/activationhandlerwrapper.S @@ -0,0 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" +#include "asmconstants.h" + +#error "TODO-RISCV64: missing implementation" diff --git a/src/coreclr/pal/src/arch/riscv64/asmconstants.h b/src/coreclr/pal/src/arch/riscv64/asmconstants.h new file mode 100644 index 00000000000000..a278e12f95ecc6 --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/asmconstants.h @@ -0,0 +1,104 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef __PAL_RISCV64_ASMCONSTANTS_H__ +#define __PAL_RISCV64_ASMCONSTANTS_H__ + +// https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/3f81fae0412bb9ad4002a4ade508be7aa5e1599b/riscv-dwarf.adoc +// https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/442ae19a2846bca37c6416f2d347fe74bb0b0dba/riscv-cc.adoc + +#error "TODO-RISCV64: review this when other files are ported in this directory" + +#define CONTEXT_RISCV64 0x04000000L + +#define CONTEXT_CONTROL_BIT (0) +#define CONTEXT_INTEGER_BIT (1) +#define CONTEXT_FLOATING_POINT_BIT (2) +#define CONTEXT_DEBUG_REGISTERS_BIT (3) + +#define CONTEXT_CONTROL (CONTEXT_RISCV64 | (1L << CONTEXT_CONTROL_BIT)) +#define CONTEXT_INTEGER (CONTEXT_RISCV64 | (1 << CONTEXT_INTEGER_BIT)) +#define CONTEXT_FLOATING_POINT (CONTEXT_RISCV64 | (1 << CONTEXT_FLOATING_POINT_BIT)) +#define CONTEXT_DEBUG_REGISTERS (CONTEXT_RISCV64 | (1 << CONTEXT_DEBUG_REGISTERS_BIT)) + +#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT) + +#define SIZEOF_RISCV64_INTR 8 +#define SIZEOF_RISCV64_FPR 8 + +#define CONTEXT_X0 0 // hardwired zero +#define CONTEXT_X1 CONTEXT_X0 + SIZEOF_RISCV64_INTR +#define CONTEXT_X2 CONTEXT_X1 + SIZEOF_RISCV64_INTR +#define CONTEXT_X3 CONTEXT_X2 + SIZEOF_RISCV64_INTR +#define CONTEXT_X4 CONTEXT_X3 + SIZEOF_RISCV64_INTR +#define CONTEXT_X5 CONTEXT_X4 + SIZEOF_RISCV64_INTR +#define CONTEXT_X6 CONTEXT_X5 + SIZEOF_RISCV64_INTR +#define CONTEXT_X7 CONTEXT_X6 + SIZEOF_RISCV64_INTR +#define CONTEXT_X8 CONTEXT_X7 + SIZEOF_RISCV64_INTR +#define CONTEXT_X9 CONTEXT_X8 + SIZEOF_RISCV64_INTR +#define CONTEXT_X10 CONTEXT_X9 + SIZEOF_RISCV64_INTR +#define CONTEXT_X11 CONTEXT_X10 + SIZEOF_RISCV64_INTR +#define CONTEXT_X12 CONTEXT_X11 + SIZEOF_RISCV64_INTR +#define CONTEXT_X13 CONTEXT_X12 + SIZEOF_RISCV64_INTR +#define CONTEXT_X14 CONTEXT_X13 + SIZEOF_RISCV64_INTR +#define CONTEXT_X15 CONTEXT_X14 + SIZEOF_RISCV64_INTR +#define CONTEXT_X16 CONTEXT_X15 + SIZEOF_RISCV64_INTR +#define CONTEXT_X17 CONTEXT_X16 + SIZEOF_RISCV64_INTR +#define CONTEXT_X18 CONTEXT_X17 + SIZEOF_RISCV64_INTR +#define CONTEXT_X19 CONTEXT_X18 + SIZEOF_RISCV64_INTR +#define CONTEXT_X20 CONTEXT_X19 + SIZEOF_RISCV64_INTR +#define CONTEXT_X21 CONTEXT_X20 + SIZEOF_RISCV64_INTR +#define CONTEXT_X22 CONTEXT_X21 + SIZEOF_RISCV64_INTR +#define CONTEXT_X23 CONTEXT_X22 + SIZEOF_RISCV64_INTR +#define CONTEXT_X24 CONTEXT_X23 + SIZEOF_RISCV64_INTR +#define CONTEXT_X25 CONTEXT_X24 + SIZEOF_RISCV64_INTR +#define CONTEXT_X26 CONTEXT_X25 + SIZEOF_RISCV64_INTR +#define CONTEXT_X27 CONTEXT_X26 + SIZEOF_RISCV64_INTR +#define CONTEXT_X28 CONTEXT_X27 + SIZEOF_RISCV64_INTR +#define CONTEXT_X29 CONTEXT_X28 + SIZEOF_RISCV64_INTR +#define CONTEXT_X30 CONTEXT_X29 + SIZEOF_RISCV64_INTR +#define CONTEXT_X31 CONTEXT_X30 + SIZEOF_RISCV64_INTR + +#define CONTEXT_Pc CONTEXT_X31 + SIZEOF_RISCV64_INTR +#define CONTEXT_FPU_OFFSET CONTEXT_Pc + SIZEOF_RISCV64_INTR +#define CONTEXT_Sp CONTEXT_X2 +#define CONTEXT_Tp CONTEXT_X4 +#define CONTEXT_Fp CONTEXT_X8 + +#define CONTEXT_F0 0 +#define CONTEXT_F1 CONTEXT_F1 + SIZEOF_RISCV64_FPR +#define CONTEXT_F2 CONTEXT_F2 + SIZEOF_RISCV64_FPR +#define CONTEXT_F3 CONTEXT_F2 + SIZEOF_RISCV64_FPR +#define CONTEXT_F4 CONTEXT_F3 + SIZEOF_RISCV64_FPR +#define CONTEXT_F5 CONTEXT_F4 + SIZEOF_RISCV64_FPR +#define CONTEXT_F6 CONTEXT_F5 + SIZEOF_RISCV64_FPR +#define CONTEXT_F7 CONTEXT_F6 + SIZEOF_RISCV64_FPR +#define CONTEXT_F8 CONTEXT_F7 + SIZEOF_RISCV64_FPR +#define CONTEXT_F9 CONTEXT_F8 + SIZEOF_RISCV64_FPR +#define CONTEXT_F10 CONTEXT_F9 + SIZEOF_RISCV64_FPR +#define CONTEXT_F11 CONTEXT_F10 + SIZEOF_RISCV64_FPR +#define CONTEXT_F12 CONTEXT_F11 + SIZEOF_RISCV64_FPR +#define CONTEXT_F13 CONTEXT_F12 + SIZEOF_RISCV64_FPR +#define CONTEXT_F14 CONTEXT_F13 + SIZEOF_RISCV64_FPR +#define CONTEXT_F15 CONTEXT_F14 + SIZEOF_RISCV64_FPR +#define CONTEXT_F16 CONTEXT_F15 + SIZEOF_RISCV64_FPR +#define CONTEXT_F17 CONTEXT_F16 + SIZEOF_RISCV64_FPR +#define CONTEXT_F18 CONTEXT_F17 + SIZEOF_RISCV64_FPR +#define CONTEXT_F19 CONTEXT_F18 + SIZEOF_RISCV64_FPR +#define CONTEXT_F20 CONTEXT_F19 + SIZEOF_RISCV64_FPR +#define CONTEXT_F21 CONTEXT_F20 + SIZEOF_RISCV64_FPR +#define CONTEXT_F22 CONTEXT_F21 + SIZEOF_RISCV64_FPR +#define CONTEXT_F23 CONTEXT_F22 + SIZEOF_RISCV64_FPR +#define CONTEXT_F24 CONTEXT_F23 + SIZEOF_RISCV64_FPR +#define CONTEXT_F25 CONTEXT_F24 + SIZEOF_RISCV64_FPR +#define CONTEXT_F26 CONTEXT_F25 + SIZEOF_RISCV64_FPR +#define CONTEXT_F27 CONTEXT_F26 + SIZEOF_RISCV64_FPR +#define CONTEXT_F28 CONTEXT_F27 + SIZEOF_RISCV64_FPR +#define CONTEXT_F29 CONTEXT_F28 + SIZEOF_RISCV64_FPR +#define CONTEXT_F30 CONTEXT_F29 + SIZEOF_RISCV64_FPR +#define CONTEXT_F31 CONTEXT_F30 + SIZEOF_RISCV64_FPR + +#define CONTEXT_FLOAT_CONTROL_OFFSET CONTEXT_F31+SIZEOF_RISCV64_FPR +#define CONTEXT_Size ((CONTEXT_FPU_OFFSET + 8 + 8 + 0xf) & ~0xf) + +#endif diff --git a/src/coreclr/pal/src/arch/riscv64/callsignalhandlerwrapper.S b/src/coreclr/pal/src/arch/riscv64/callsignalhandlerwrapper.S new file mode 100644 index 00000000000000..a7cd5b6c4d2403 --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/callsignalhandlerwrapper.S @@ -0,0 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" +#include "asmconstants.h" + +#error "TODO-RISCV64: missing implementation" diff --git a/src/coreclr/pal/src/arch/riscv64/context.S b/src/coreclr/pal/src/arch/riscv64/context.S new file mode 100644 index 00000000000000..f6c1fb2c96ce46 --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/context.S @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" + +#error "TODO-RISCV64: missing implementation" diff --git a/src/coreclr/pal/src/arch/riscv64/context2.S b/src/coreclr/pal/src/arch/riscv64/context2.S new file mode 100644 index 00000000000000..8e3a01ac4f608a --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/context2.S @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +// Implementation of _CONTEXT_CaptureContext for the RISCV64 platform. +// This function is processor dependent. It is used by exception handling, +// and is always apply to the current thread. +// + +#include "unixasmmacros.inc" +#include "asmconstants.h" + +#error "TODO-RISCV64: missing implementation" diff --git a/src/coreclr/pal/src/arch/riscv64/debugbreak.S b/src/coreclr/pal/src/arch/riscv64/debugbreak.S new file mode 100644 index 00000000000000..93fdfd8c4c5be8 --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/debugbreak.S @@ -0,0 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" +LEAF_ENTRY DBG_DebugBreak, _TEXT + EMIT_BREAKPOINT +LEAF_END_MARKED DBG_DebugBreak, _TEXT diff --git a/src/coreclr/pal/src/arch/riscv64/dispatchexceptionwrapper.S b/src/coreclr/pal/src/arch/riscv64/dispatchexceptionwrapper.S new file mode 100644 index 00000000000000..41f5e08472dfff --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/dispatchexceptionwrapper.S @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// +// Implementation of the PAL_DispatchExceptionWrapper that is +// interposed between a function that caused a hardware fault +// and PAL_DispatchException that throws an SEH exception for +// the fault, to make the stack unwindable. +// + +#include "unixasmmacros.inc" + +#error "TODO-RISCV64: missing implementation" diff --git a/src/coreclr/pal/src/arch/riscv64/exceptionhelper.S b/src/coreclr/pal/src/arch/riscv64/exceptionhelper.S new file mode 100644 index 00000000000000..a7cd5b6c4d2403 --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/exceptionhelper.S @@ -0,0 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" +#include "asmconstants.h" + +#error "TODO-RISCV64: missing implementation" diff --git a/src/coreclr/pal/src/arch/riscv64/processor.cpp b/src/coreclr/pal/src/arch/riscv64/processor.cpp new file mode 100644 index 00000000000000..4e8998679e46a5 --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/processor.cpp @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*++ + + + +Module Name: + + processor.cpp + +Abstract: + + Implementation of processor related functions for the RISCV64 + platform. These functions are processor dependent. + + + +--*/ + +#include "pal/palinternal.h" diff --git a/src/coreclr/pal/src/arch/riscv64/signalhandlerhelper.cpp b/src/coreclr/pal/src/arch/riscv64/signalhandlerhelper.cpp new file mode 100644 index 00000000000000..a4ce803b47afdb --- /dev/null +++ b/src/coreclr/pal/src/arch/riscv64/signalhandlerhelper.cpp @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "pal/dbgmsg.h" +SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do this first + +#include "pal/palinternal.h" +#include "pal/context.h" +#include "pal/signal.hpp" +#include "pal/utils.h" +#include + +/*++ +Function : + ExecuteHandlerOnCustomStack + + Execute signal handler on a custom stack, the current stack pointer is specified by the customSp + If the customSp is 0, then the handler is executed on the original stack where the signal was fired. + It installs a fake stack frame to enable stack unwinding to the signal source location. + +Parameters : + POSIX signal handler parameter list ("man sigaction" for details) + returnPoint - context to which the function returns if the common_signal_handler returns + + (no return value) +--*/ +void ExecuteHandlerOnCustomStack(int code, siginfo_t *siginfo, void *context, size_t customSp, SignalHandlerWorkerReturnPoint* returnPoint) +{ +#error "TODO-RISCV64: missing implementation" +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.cs index d0b1eee65bbbcb..8f97a5a660cba4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.cs @@ -70,6 +70,8 @@ public static Architecture ProcessArchitecture => Architecture.LoongArch64; #elif TARGET_POWERPC64 => Architecture.Ppc64le; +#elif TARGET_RISCV64 + => (Architecture)9; // TODO-RISCV64: go though API review for RiscV64 #else #error Unknown Architecture #endif diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 8925f55b42c95b..79f4f677c994c4 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -161,6 +161,9 @@ if(NOT AOT_TARGET_TRIPLE STREQUAL "") elseif(AOT_TARGET_TRIPLE STREQUAL "aarch64-linux-gnu") set(TARGET_SYSTEM_NAME "Linux") set(TARGET_ARCH "arm64") + elseif(AOT_TARGET_TRIPLE STREQUAL "riscv64-linux-gnu") + set(TARGET_SYSTEM_NAME "Linux") + set(TARGET_ARCH "riscv64") else() message(FATAL_ERROR "AOT target '${AOT_TARGET_TRIPLE}' not supported.") endif() @@ -381,6 +384,9 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") set(HOST_ARM 1) # fixme: use separate defines for host/target set(NO_UNALIGNED_ACCESS 1) +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set(HOST_RISCV 1) + set(HOST_RISCV64 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "s390x") set(HOST_S390X 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "wasm" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "wasm32") @@ -450,6 +456,12 @@ elseif(TARGET_ARCH MATCHES "arm") set(HAVE_ARMV5 1) set(HAVE_ARMV6 1) #set(HAVE_ARMV7 1) # TODO: figure out if we should set this +elseif(TARGET_ARCH STREQUAL "riscv64") + set(TARGET_RISCV 1) + set(TARGET_RISCV64 1) + set(MONO_ARCHITECTURE "\"riscv64\"") + set(TARGET_SIZEOF_VOID_P 8) + set(SIZEOF_REGISTER 8) elseif(TARGET_ARCH STREQUAL "s390x") set(TARGET_S390X 1) set(MONO_ARCHITECTURE "\"s390x\"") diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj index 87a37c5869e25e..7eb9314c1ce629 100644 --- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -10,7 +10,7 @@ $(RuntimeBinDir)IL/ Debug;Release;Checked - x64;x86;arm;armv6;arm64;s390x;wasm;ppc64le + x64;x86;arm;armv6;arm64;riscv64;s390x;wasm;ppc64le true @@ -67,6 +67,10 @@ AnyCPU $(DefineConstants);TARGET_ARM64 + + AnyCPU + $(DefineConstants);TARGET_RISCV64 + AnyCPU $(DefineConstants);TARGET_S390X diff --git a/src/mono/mono.proj b/src/mono/mono.proj index cf693d22fe546f..38731e968660a5 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -260,6 +260,13 @@ <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/lib/pkgconfig" /> + + + <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> + <_MonoBuildEnv Include="TARGET_BUILD_ARCH=riscv64" /> + <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/riscv64-linux-gnu/pkgconfig" /> + + <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> @@ -554,16 +561,24 @@ <_Objcopy Condition="'$(Platform)' == 'arm'">arm-linux-$(_LinuxAbi)eabi$(_LinuxFloatAbi)-$(_Objcopy) <_Objcopy Condition="'$(Platform)' == 'armv6'">arm-linux-$(_LinuxAbi)eabi$(_LinuxFloatAbi)-$(_Objcopy) <_Objcopy Condition="'$(Platform)' == 'arm64'">aarch64-linux-$(_LinuxAbi)-$(_Objcopy) + <_Objcopy Condition="'$(Platform)' == 'riscv64'">riscv64-linux-$(_LinuxAbi)-$(_Objcopy) <_Objcopy Condition="'$(Platform)' == 's390x'">s390x-linux-$(_LinuxAbi)-$(_Objcopy) <_Objcopy Condition="'$(Platform)' == 'ppc64le'">powerpc64le-linux-$(_LinuxAbi)-$(_Objcopy) <_Objcopy Condition="'$(Platform)' == 'x64'">x86_64-linux-$(_LinuxAbi)-$(_Objcopy) <_Objcopy Condition="'$(Platform)' == 'x86'">i686-linux-$(_LinuxAbi)-$(_Objcopy) <_Objcopy Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true'">$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(MonoToolchainPrebuiltOS)/bin/llvm-objcopy + + <_ObjcopyPrefix Condition="'$(MonoCrossDir)' != '' and '$(Platform)' == 'riscv64'">llvm-objcopy- + + + + + <_Objcopy Condition="'$(_ObjcopyFound)' != '0'">objcopy diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 448f9ded04fd53..4760cde11a5b0e 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -209,6 +209,13 @@ set(arm_sources tramp-arm-gsharedvt.c cpu-arm.h) +set(riscv64_sources + mini-riscv.c + mini-riscv.h + exceptions-riscv.c + tramp-riscv.c + cpu-riscv64.h) + set(s390x_sources mini-s390x.c mini-s390x.h @@ -237,6 +244,8 @@ elseif(TARGET_ARM64) set(arch_sources ${arm64_sources}) elseif(TARGET_ARM) set(arch_sources ${arm_sources}) +elseif(TARGET_RISCV64) +set(arch_sources ${riscv64_sources}) elseif(TARGET_S390X) set(arch_sources ${s390x_sources}) elseif(TARGET_WASM) @@ -481,6 +490,13 @@ add_custom_command( VERBATIM ) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-riscv64.h + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py TARGET_RISCV64 ${CMAKE_CURRENT_SOURCE_DIR} cpu-riscv64.h riscv64_cpu_desc ${CMAKE_CURRENT_SOURCE_DIR}/cpu-riscv64.mdesc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py mini-ops.h ${CMAKE_CURRENT_SOURCE_DIR}/cpu-riscv64.mdesc + VERBATIM +) + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-s390x.h COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py TARGET_S390X ${CMAKE_CURRENT_SOURCE_DIR} cpu-s390x.h s390x_cpu_desc ${CMAKE_CURRENT_SOURCE_DIR}/cpu-s390x.mdesc diff --git a/src/mono/mono/mini/aot-runtime.c b/src/mono/mono/mini/aot-runtime.c index bc52200dcd70f7..353b0ee4f06f2b 100644 --- a/src/mono/mono/mini/aot-runtime.c +++ b/src/mono/mono/mini/aot-runtime.c @@ -4329,7 +4329,7 @@ find_aot_method_in_amodule (MonoAotModule *code_amodule, MonoMethod *method, gui guint32 table_size, entry_size, hash; guint32 *table, *entry; guint32 index; - static guint32 n_extra_decodes; + // static guint32 n_extra_decodes; // used for debugging // The AOT module containing the MonoMethod // The reference to the metadata amodule will differ among multiple dedup methods @@ -4385,10 +4385,10 @@ find_aot_method_in_amodule (MonoAotModule *code_amodule, MonoMethod *method, gui } /* Methods decoded needlessly */ - if (m) { + /*if (m) { //printf ("%d %s %s %p\n", n_extra_decodes, mono_method_full_name (method, TRUE), mono_method_full_name (m, TRUE), orig_p); n_extra_decodes ++; - } + }*/ if (next != 0) entry = &table [next * entry_size]; @@ -6056,9 +6056,7 @@ mono_aot_get_lazy_fetch_trampoline (guint32 slot) gpointer code; MonoAotModule *amodule = mscorlib_aot_module; guint32 index = MONO_RGCTX_SLOT_INDEX (slot); - static int count = 0; - count ++; if (index >= amodule->info.num_rgctx_fetch_trampolines) { static gpointer addr; gpointer *info; diff --git a/src/mono/mono/mini/mini-exceptions.c b/src/mono/mono/mini/mini-exceptions.c index 746d8a2556e4dc..76d6dc7baf327f 100644 --- a/src/mono/mono/mini/mini-exceptions.c +++ b/src/mono/mono/mini/mini-exceptions.c @@ -2108,8 +2108,9 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu gboolean stack_overflow = FALSE; MonoContext initial_ctx; MonoMethod *method; - int frame_count = 0; + // int frame_count = 0; // used for debugging gint32 filter_idx, first_filter_idx = 0; + MonoObject *ex_obj = NULL; MonoObject *non_exception = NULL; Unwinder unwinder; @@ -2351,8 +2352,8 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu ip = MONO_CONTEXT_GET_IP (ctx); method = jinfo_get_method (ji); - frame_count ++; - //printf ("[%d] %s.\n", frame_count, mono_method_full_name (method, TRUE)); + // frame_count ++; + // printf ("[%d] %s.\n", frame_count, mono_method_full_name (method, TRUE)); if (stack_overflow) { free_stack = (guint32)((guint8*)(MONO_CONTEXT_GET_SP (ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx))); diff --git a/src/mono/mono/mini/mini-riscv.c b/src/mono/mono/mini/mini-riscv.c index bbe02621eb94b9..c2e1b64514c099 100644 --- a/src/mono/mono/mini/mini-riscv.c +++ b/src/mono/mono/mini/mini-riscv.c @@ -269,7 +269,7 @@ void mono_arch_flush_icache (guint8 *code, gint size) { #ifndef MONO_CROSS_COMPILE - __builtin___clear_cache (code, code + size); + __builtin___clear_cache ((char *)code, (char *)code + size); #endif } @@ -685,7 +685,7 @@ mono_arch_skip_single_step (MonoContext *ctx) NOT_IMPLEMENTED; } -gpointer +SeqPointInfo* mono_arch_get_seq_point_info (guint8 *code) { NOT_IMPLEMENTED; diff --git a/src/mono/mono/mini/mini-riscv.h b/src/mono/mono/mini/mini-riscv.h index 3691718be689c2..ba078ad93a6b1a 100644 --- a/src/mono/mono/mini/mini-riscv.h +++ b/src/mono/mono/mini/mini-riscv.h @@ -149,7 +149,7 @@ #define MONO_ARCH_INTERPRETER_SUPPORTED (1) //#define MONO_ARCH_AOT_SUPPORTED (1) //#define MONO_ARCH_LLVM_SUPPORTED (1) -//#define MONO_ARCH_SOFT_DEBUG_SUPPORTED (1) +#define MONO_ARCH_SOFT_DEBUG_SUPPORTED (1) // #define MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE (1) diff --git a/src/mono/mono/mini/tramp-riscv.c b/src/mono/mono/mini/tramp-riscv.c index a77d4998c68969..56233aaff9ee83 100644 --- a/src/mono/mono/mini/tramp-riscv.c +++ b/src/mono/mono/mini/tramp-riscv.c @@ -159,7 +159,6 @@ mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info } guint8 *buf = mono_global_codeman_reserve (128 * depth), *code = buf; - guint8 **null_jumps = g_malloc0 (sizeof (guint8 *) * (depth + 2)); if (!is_mrgctx) { } else diff --git a/src/mono/mono/utils/CMakeLists.txt b/src/mono/mono/utils/CMakeLists.txt index 7f13f98f4b3aa3..7ceb82e8eed230 100644 --- a/src/mono/mono/utils/CMakeLists.txt +++ b/src/mono/mono/utils/CMakeLists.txt @@ -212,6 +212,8 @@ elseif(TARGET_ARM64) set(utils_arch_sources "${utils_arch_sources};mono-hwcap-arm64.c") elseif(TARGET_ARM) set(utils_arch_sources "${utils_arch_sources};mono-hwcap-arm.c") +elseif(TARGET_RISCV64) +set(utils_arch_sources "${utils_arch_sources};mono-hwcap-riscv.c") elseif(TARGET_S390X) set(utils_arch_sources "${utils_arch_sources};mono-hwcap-s390x.c") elseif(TARGET_WASM) diff --git a/src/native/corehost/bundle/reader.h b/src/native/corehost/bundle/reader.h index cc905a1c35d9a1..2aee7a90b97bd0 100644 --- a/src/native/corehost/bundle/reader.h +++ b/src/native/corehost/bundle/reader.h @@ -19,6 +19,8 @@ #define TARGET_CPU_TYPE CPU_TYPE_ARM64 #elif defined(TARGET_LOONGARCH64) #define TARGET_CPU_TYPE CPU_TYPE_LOONGARCH64 +#elif defined(TARGET_RISCV64) +#define TARGET_CPU_TYPE CPU_TYPE_RISCV64 #else #define TARGET_CPU_TYPE CPU_TYPE_X86_64 #endif diff --git a/src/native/corehost/hostmisc/pal.h b/src/native/corehost/hostmisc/pal.h index ddaa764ae09218..547f34404d48b5 100644 --- a/src/native/corehost/hostmisc/pal.h +++ b/src/native/corehost/hostmisc/pal.h @@ -300,6 +300,7 @@ namespace pal armv6, loongarch64, ppc64le, + riscv64, s390X, x64, x86, diff --git a/src/native/corehost/hostmisc/utils.cpp b/src/native/corehost/hostmisc/utils.cpp index 22fe218231a514..81be864190987c 100644 --- a/src/native/corehost/hostmisc/utils.cpp +++ b/src/native/corehost/hostmisc/utils.cpp @@ -203,6 +203,7 @@ namespace _X("armv6"), _X("loongarch64"), _X("ppc64le"), + _X("riscv64"), _X("s390x"), _X("x64"), _X("x86") @@ -224,6 +225,8 @@ pal::architecture get_current_arch() return pal::architecture::arm64; #elif defined(TARGET_LOONGARCH64) return pal::architecture::loongarch64; +#elif defined(TARGET_RISCV64) + return pal::architecture::riscv64; #elif defined(TARGET_S390X) return pal::architecture::s390X; #elif defined(TARGET_POWERPC64) diff --git a/src/native/external/libunwind.cmake b/src/native/external/libunwind.cmake index 058fe05b224a1c..2400d28e84b6e0 100644 --- a/src/native/external/libunwind.cmake +++ b/src/native/external/libunwind.cmake @@ -184,6 +184,33 @@ set(libunwind_loongarch_la_SOURCES_loongarch loongarch64/Gis_signal_frame.c loongarch64/Gregs.c loongarch64/Gresume.c loongarch64/Gstep.c ) +# The list of files that go into libunwind and libunwind-riscv: +set(libunwind_la_SOURCES_riscv_common + ${libunwind_la_SOURCES_common} + riscv/is_fpreg.c + riscv/regname.c +) + +# The list of files that go into libunwind: +set(libunwind_la_SOURCES_riscv + ${libunwind_la_SOURCES_riscv_common} + ${libunwind_la_SOURCES_local} + riscv/Lget_proc_info.c riscv/Linit.c riscv/Lis_signal_frame.c + riscv/Lstep.c + riscv/getcontext.S + riscv/Lget_save_loc.c + riscv/Linit_local.c riscv/Lregs.c + riscv/Lcreate_addr_space.c riscv/Lglobal.c riscv/Linit_remote.c riscv/Lresume.c +) + +set(libunwind_riscv_la_SOURCES_riscv + ${libunwind_la_SOURCES_riscv_common} + ${libunwind_la_SOURCES_generic} + riscv/Gcreate_addr_space.c riscv/Gget_proc_info.c riscv/Gget_save_loc.c + riscv/Gglobal.c riscv/Ginit.c riscv/Ginit_local.c riscv/Ginit_remote.c + riscv/Gis_signal_frame.c riscv/Gregs.c riscv/Gresume.c riscv/Gstep.c +) + # The list of files that go into libunwind and libunwind-aarch64: set(libunwind_la_SOURCES_aarch64_common ${libunwind_la_SOURCES_common} @@ -345,10 +372,10 @@ set(libunwind_la_SOURCES_ppc64le_common set(libunwind_la_SOURCES_ppc64le ${libunwind_la_SOURCES_ppc64le_common} ${libunwind_la_SOURCES_local} - ppc64/setcontext.S + ppc64/setcontext.S ppc64/Lapply_reg_state.c ppc64/Lreg_states_iterate.c ppc64/Lcreate_addr_space.c ppc/Lget_save_loc.c ppc64/Lglobal.c - ppc64/Linit.c ppc/Linit_local.c + ppc64/Linit.c ppc/Linit_local.c ppc64/Lregs.c ppc64/Lresume.c ppc/Lis_signal_frame.c ppc64/Lstep.c ) @@ -403,6 +430,11 @@ if(CLR_CMAKE_HOST_UNIX) set(libunwind_remote_la_SOURCES ${libunwind_loongarch_la_SOURCES_loongarch}) set(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) list(APPEND libunwind_setjmp_la_SOURCES loongarch64/siglongjmp.S) + elseif(CLR_CMAKE_HOST_ARCH_RISCV64) + set(libunwind_la_SOURCES ${libunwind_la_SOURCES_riscv}) + set(libunwind_remote_la_SOURCES ${libunwind_riscv_la_SOURCES_riscv}) + set(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) + list(APPEND libunwind_setjmp_la_SOURCES riscv/siglongjmp.S) endif() if(CLR_CMAKE_HOST_OSX) diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 8ac4c48a3f4dec..245bd3823169e5 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -25,6 +25,8 @@ if(CLR_CMAKE_HOST_UNIX) set(arch s390x) elseif(CLR_CMAKE_HOST_ARCH_LOONGARCH64) set(arch loongarch64) + elseif(CLR_CMAKE_HOST_ARCH_RISCV64) + set(arch riscv64) elseif(CLR_CMAKE_HOST_ARCH_POWERPC64) set(arch ppc64le) endif () @@ -71,6 +73,8 @@ if(CLR_CMAKE_HOST_UNIX) add_compile_options(-Wno-incompatible-pointer-types) elseif(CLR_CMAKE_HOST_ARCH_LOONGARCH64) ###TODO: maybe add options for LOONGARCH64 + elseif(CLR_CMAKE_HOST_ARCH_RISCV64) + ###TODO: maybe add options for RISCV64 endif() if (CLR_CMAKE_HOST_OSX) @@ -87,24 +91,19 @@ endif(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_WIN32) if (CLR_CMAKE_TARGET_ARCH_AMD64) - set(TARGET_AMD64 1) set(arch x86_64) add_definitions(-D__x86_64__) add_definitions(-D__amd64__) elseif(CLR_CMAKE_TARGET_ARCH_ARM64) - set(TARGET_AARCH64 1) set(arch aarch64) add_definitions(-D__aarch64__) elseif(CLR_CMAKE_TARGET_ARCH_ARM) - set(TARGET_ARM 1) set(arch arm) add_definitions(-D__arm__) elseif(CLR_CMAKE_TARGET_ARCH_ARMV6) - set(TARGET_ARM 1) set(arch arm) add_definitions(-D__arm__) elseif(CLR_CMAKE_TARGET_ARCH_S390X) - set(TARGET_S390X 1) set(arch s390x) add_definitions(-D__s390x__) else () diff --git a/src/native/libs/System.Native/pal_runtimeinformation.c b/src/native/libs/System.Native/pal_runtimeinformation.c index 028ae5f14f4886..24446c9e8e3243 100644 --- a/src/native/libs/System.Native/pal_runtimeinformation.c +++ b/src/native/libs/System.Native/pal_runtimeinformation.c @@ -65,6 +65,7 @@ enum ARCH_LOONGARCH64, ARCH_ARMV6, ARCH_POWERPC64, + ARCH_RISCV64, }; int32_t SystemNative_GetOSArchitecture() @@ -137,6 +138,11 @@ int32_t SystemNative_GetOSArchitecture() { result = ARCH_LOONGARCH64; } + + else if (strcmp("riscv64", isa) == 0) + { + result = ARCH_RISCV64; + } } // catch if we have missed a pattern above. diff --git a/src/tests/Common/scripts/bringup_runtest.sh b/src/tests/Common/scripts/bringup_runtest.sh index 9af6f9889b44e5..b5228105980ffc 100755 --- a/src/tests/Common/scripts/bringup_runtest.sh +++ b/src/tests/Common/scripts/bringup_runtest.sh @@ -985,9 +985,15 @@ function check_cpu_architecture { armv7l) __arch=arm ;; - aarch64) + aarch64|arm64) __arch=arm64 ;; + loongarch64) + __arch=loongarch64 + ;; + riscv64) + __arch=riscv64 + ;; *) echo "Unknown CPU $CPUName detected, configuring as if for x64" __arch=x64 diff --git a/src/tests/Common/scripts/run-corefx-tests.bat b/src/tests/Common/scripts/run-libraries-tests.bat similarity index 97% rename from src/tests/Common/scripts/run-corefx-tests.bat rename to src/tests/Common/scripts/run-libraries-tests.bat index f7a2040951bb50..8d33d314f431c6 100644 --- a/src/tests/Common/scripts/run-corefx-tests.bat +++ b/src/tests/Common/scripts/run-libraries-tests.bat @@ -3,7 +3,7 @@ setlocal ENABLEDELAYEDEXPANSION goto start :usage -echo Usage: run-corefx-tests.bat ^ ^ ^ +echo Usage: run-libraries-tests.bat ^ ^ ^ echo. echo Runs the corefx tests on a Windows ARM/ARM64 device, by searching for all relevant corefx echo RunTests.cmd files in the ^ tree, and running each one in turn. This diff --git a/src/tests/Common/scripts/run-corefx-tests.sh b/src/tests/Common/scripts/run-libraries-tests.sh similarity index 97% rename from src/tests/Common/scripts/run-corefx-tests.sh rename to src/tests/Common/scripts/run-libraries-tests.sh index 13c274599b353d..392299d8482a68 100755 --- a/src/tests/Common/scripts/run-corefx-tests.sh +++ b/src/tests/Common/scripts/run-libraries-tests.sh @@ -2,8 +2,8 @@ usage() { - echo "Runs .NET CoreFX tests on FreeBSD, Linux, NetBSD or OSX" - echo "usage: run-corefx-tests [options]" + echo "Runs .NET runtime libraries tests on FreeBSD, Linux, NetBSD or OSX" + echo "usage: run-libraries-tests [options]" echo echo "Input sources:" echo " --runtime Location of root of the binaries directory" @@ -18,7 +18,7 @@ usage() echo " default: Debug" echo " --os OS to run (FreeBSD, Linux, NetBSD, OSX, SunOS)" echo " default: detect current OS" - echo " --arch Architecture to run (x64, arm, armel, x86, arm64)" + echo " --arch Architecture to run (x64, arm, armel, x86, arm64, loongarch64, riscv64)" echo " default: detect current architecture" echo echo "Execution options:" @@ -117,10 +117,18 @@ case $CPUName in __Arch=armel ;; - aarch64) + aarch64|arm64) __Arch=arm64 ;; + loongarch64) + __Arch=loongarch64 + ;; + + riscv64) + __Arch=riscv64 + ;; + *) echo "Unknown CPU $CPUName detected, configuring as if for x64" __Arch=x64 diff --git a/src/tests/run.sh b/src/tests/run.sh index 15f696635ed995..16756ccf61f175 100755 --- a/src/tests/run.sh +++ b/src/tests/run.sh @@ -11,7 +11,7 @@ function print_usage { echo 'Optional arguments:' echo ' -h|--help : Show usage information.' echo ' -v, --verbose : Show output from each test.' - echo ' : One of x64, x86, arm, arm64, wasm. Defaults to current architecture.' + echo ' : One of x64, x86, arm, arm64, loongarch64, riscv64, wasm. Defaults to current architecture.' echo ' Android : Set build OS to Android.' echo ' --test-env= : Script to set environment variables for tests' echo ' --testRootDir= : Root directory of the test build (e.g. runtime/artifacts/tests/windows.x64.Debug).' @@ -60,6 +60,12 @@ function check_cpu_architecture { aarch64|arm64) __arch=arm64 ;; + loongarch64) + __arch=loongarch64 + ;; + riscv64) + __arch=riscv64 + ;; *) echo "Unknown CPU $CPUName detected, configuring as if for x64" __arch=x64