Skip to content

Commit e73d7fc

Browse files
authored
[RISC-V] coreclr-pal and coreclr-debug directories (#82380)
* [RISC-V] coreclr-pal and coreclr-debug directories - Successfully cross-build for RISC-V. - Run A simple application "helloworld" - Fail a test in clr.paltest * Fix * [PAL] Update * [PAL] Update * [PAL] Updated based on reviews * [PAL] Update REGISTER_RISCV64_X0 * [PAL] Fix a mistake * [PAL] Fix by reviews * [PAL] Restore EPILOG_STACK_FREE
1 parent 42c6bcf commit e73d7fc

38 files changed

+1470
-173
lines changed

eng/native/tryrun.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ else()
161161
message(FATAL_ERROR "Unsupported platform. OS: ${CMAKE_SYSTEM_NAME}, arch: ${TARGET_ARCH_NAME}")
162162
endif()
163163

164-
if(TARGET_ARCH_NAME MATCHES "^(x86|x64|s390x|armv6|loongarch64|riscv64|ppc64le)$")
164+
if(TARGET_ARCH_NAME MATCHES "^(x86|x64|s390x|armv6|loongarch64|ppc64le)$")
165165
set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0)
166+
elseif (TARGET_ARCH_NAME STREQUAL "riscv64")
167+
set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1)
166168
endif()

src/coreclr/debug/createdump/createdumpunix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "createdump.h"
55

6-
#if defined(__arm__) || defined(__aarch64__) || defined(__loongarch64)
6+
#if defined(__arm__) || defined(__aarch64__) || defined(__loongarch64) || defined(__riscv)
77
long g_pageSize = 0;
88
#endif
99

@@ -19,7 +19,7 @@ CreateDump(const CreateDumpOptions& options)
1919
bool result = false;
2020

2121
// Initialize PAGE_SIZE
22-
#if defined(__arm__) || defined(__aarch64__) || defined(__loongarch64)
22+
#if defined(__arm__) || defined(__aarch64__) || defined(__loongarch64) || defined(__riscv)
2323
g_pageSize = sysconf(_SC_PAGESIZE);
2424
#endif
2525
TRACE("PAGE_SIZE %d\n", PAGE_SIZE);

src/coreclr/debug/createdump/datatarget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ DumpDataTarget::GetMachineType(
7777
*machine = IMAGE_FILE_MACHINE_I386;
7878
#elif HOST_LOONGARCH64
7979
*machine = IMAGE_FILE_MACHINE_LOONGARCH64;
80+
#elif HOST_RISCV64
81+
*machine = IMAGE_FILE_MACHINE_RISCV64;
8082
#else
8183
#error Unsupported architecture
8284
#endif
@@ -87,7 +89,7 @@ HRESULT STDMETHODCALLTYPE
8789
DumpDataTarget::GetPointerSize(
8890
/* [out] */ ULONG32 *size)
8991
{
90-
#if defined(HOST_AMD64) || defined(HOST_ARM64) || defined(HOST_LOONGARCH64)
92+
#if defined(HOST_AMD64) || defined(HOST_ARM64) || defined(HOST_LOONGARCH64) || defined(HOST_RISCV64)
9193
*size = 8;
9294
#elif defined(HOST_ARM) || defined(HOST_X86)
9395
*size = 4;

src/coreclr/debug/createdump/dumpwriterelf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define ELF_ARCH EM_ARM
2424
#elif defined(__loongarch64)
2525
#define ELF_ARCH EM_LOONGARCH
26+
#elif defined(__riscv)
27+
#define ELF_ARCH EM_RISCV
2628
#endif
2729

2830
#define PH_HDR_CANARY 0xFFFF

src/coreclr/debug/createdump/memoryregion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#if !defined(PAGE_SIZE) && (defined(__arm__) || defined(__aarch64__) || defined(__loongarch64))
4+
#if !defined(PAGE_SIZE) && (defined(__arm__) || defined(__aarch64__) || defined(__loongarch64)) || defined(__riscv)
55
extern long g_pageSize;
66
#define PAGE_SIZE g_pageSize
77
#endif

src/coreclr/debug/createdump/threadinfo.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ class CrashInfo;
2020
#define MCREG_Pc(mc) ((mc).pc)
2121
#endif
2222

23+
#if defined(__riscv)
24+
// See src/coreclr/pal/src/include/pal/context.h
25+
#define MCREG_Ra(mc) ((mc).ra)
26+
#define MCREG_Fp(mc) ((mc).s0)
27+
#define MCREG_Sp(mc) ((mc).sp)
28+
#define MCREG_Pc(mc) ((mc).pc)
29+
#endif
30+
2331
#define FPREG_ErrorOffset(fpregs) *(DWORD*)&((fpregs).rip)
2432
#define FPREG_ErrorSelector(fpregs) *(((WORD*)&((fpregs).rip)) + 2)
2533
#define FPREG_DataOffset(fpregs) *(DWORD*)&((fpregs).rdp)
@@ -30,6 +38,12 @@ class CrashInfo;
3038
#elif defined(__loongarch64)
3139
// struct user_regs_struct {} defined `/usr/include/loongarch64-linux-gnu/sys/user.h`
3240

41+
struct user_fpregs_struct
42+
{
43+
unsigned long long fpregs[32];
44+
unsigned long fpscr;
45+
} __attribute__((__packed__));
46+
#elif defined(__riscv)
3347
struct user_fpregs_struct
3448
{
3549
unsigned long long fpregs[32];
@@ -154,6 +168,10 @@ class ThreadInfo
154168
inline const uint64_t GetInstructionPointer() const { return m_gpRegisters.ARM_pc; }
155169
inline const uint64_t GetStackPointer() const { return m_gpRegisters.ARM_sp; }
156170
inline const uint64_t GetFramePointer() const { return m_gpRegisters.ARM_fp; }
171+
#elif defined(__riscv)
172+
inline const uint64_t GetInstructionPointer() const { return MCREG_Pc(m_gpRegisters); }
173+
inline const uint64_t GetStackPointer() const { return MCREG_Sp(m_gpRegisters); }
174+
inline const uint64_t GetFramePointer() const { return MCREG_Fp(m_gpRegisters); }
157175
#endif
158176
#endif // __APPLE__
159177
bool IsCrashThread() const;

src/coreclr/debug/createdump/threadinfounix.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ ThreadInfo::Initialize()
5959
TRACE("Thread %04x RIP %016llx RSP %016llx\n", m_tid, (unsigned long long)m_gpRegisters.rip, (unsigned long long)m_gpRegisters.rsp);
6060
#elif defined(__loongarch64)
6161
TRACE("Thread %04x PC %016llx SP %016llx\n", m_tid, (unsigned long long)m_gpRegisters.pc, (unsigned long long)m_gpRegisters.gpr[3]);
62+
#elif defined(__riscv)
63+
TRACE("Thread %04x PC %016llx SP %016llx\n", m_tid, (unsigned long long)m_gpRegisters.pc, (unsigned long long)m_gpRegisters.sp);
6264
#else
6365
#error "Unsupported architecture"
6466
#endif
@@ -243,6 +245,8 @@ ThreadInfo::GetThreadContext(uint32_t flags, CONTEXT* context) const
243245
memcpy(context->F, m_fpRegisters.fpregs, sizeof(context->F));
244246
context->Fcsr = m_fpRegisters.fpscr;
245247
}
248+
#elif defined(__riscv)
249+
_ASSERTE(!"TODO RISCV64 NYI");
246250
#else
247251
#error Platform not supported
248252
#endif

src/coreclr/debug/daccess/daccess.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5450,6 +5450,8 @@ ClrDataAccess::Initialize(void)
54505450
CorDebugPlatform hostPlatform = CORDB_PLATFORM_POSIX_ARM64;
54515451
#elif defined(TARGET_LOONGARCH64)
54525452
CorDebugPlatform hostPlatform = CORDB_PLATFORM_POSIX_LOONGARCH64;
5453+
#elif defined(TARGET_RISCV64)
5454+
CorDebugPlatform hostPlatform = CORDB_PLATFORM_POSIX_RISCV64;
54535455
#else
54545456
#error Unknown Processor.
54555457
#endif

src/coreclr/debug/daccess/request.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,18 @@ ClrDataAccess::GetRegisterName(int regNum, unsigned int count, _Inout_updates_z_
559559
W("S6"), W("S7"), W("K0"), W("K1"),
560560
W("GP"), W("SP"), W("FP"), W("RA")
561561
};
562+
#elif defined(TARGET_RISCV64)
563+
static const WCHAR *regs[] =
564+
{
565+
W("R0"), W("RA"), W("SP"), W("GP"),
566+
W("TP"), W("T0"), W("T1"), W("T2"),
567+
W("FP"), W("S1"), W("A0"), W("A1"),
568+
W("A2"), W("A3"), W("A4"), W("A5"),
569+
W("A6"), W("A7"), W("S2"), W("S3"),
570+
W("S4"), W("S5"), W("S6"), W("S7"),
571+
W("S8"), W("S9"), W("S10"), W("S11"),
572+
W("T3"), W("T4"), W("T5"), W("T6")
573+
};
562574
#endif
563575

564576
// Caller frame registers are encoded as "-(reg+1)".

src/coreclr/debug/di/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if(CLR_CMAKE_HOST_WIN32)
6666
endif()
6767
elseif(CLR_CMAKE_HOST_UNIX)
6868

69-
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_LOONGARCH64)
69+
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_LOONGARCH64 OR CLR_CMAKE_TARGET_ARCH_RISCV64)
7070
set(CORDBDI_SOURCES_ASM_FILE
7171
${ARCH_SOURCES_DIR}/floatconversion.S
7272
)

0 commit comments

Comments
 (0)