Skip to content

Commit

Permalink
[RISC-V] Add more gcdump and gcinfo code. (#94219)
Browse files Browse the repository at this point in the history
* [RISC-V] Add more gcdump and gcinfo code.

* Add more comments.
  • Loading branch information
viewizard authored Nov 10, 2023
1 parent e7ab2f6 commit 3c5123e
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 9 deletions.
41 changes: 38 additions & 3 deletions src/coreclr/gcdump/gcdumpnonx86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,42 @@ PCSTR GetRegName (UINT32 regnum)
assert(!"unimplemented on LOONGARCH yet");
return "???";
#elif defined(TARGET_RISCV64)
assert(!"unimplemented on RISCV64 yet");
switch (regnum)
{
case 0: return "r0";
case 1: return "ra";
case 2: return "sp";
case 3: return "gp";
case 4: return "tp";
case 5: return "t0";
case 6: return "t1";
case 7: return "t2";
case 8: return "fp";
case 9: return "s1";
case 10: return "a0";
case 11: return "a1";
case 12: return "a2";
case 13: return "a3";
case 14: return "a4";
case 15: return "a5";
case 16: return "a6";
case 17: return "a7";
case 18: return "s2";
case 19: return "s3";
case 20: return "s4";
case 21: return "s5";
case 22: return "s6";
case 23: return "s7";
case 24: return "s8";
case 25: return "s9";
case 26: return "s10";
case 27: return "s11";
case 28: return "t3";
case 29: return "t4";
case 30: return "t5";
case 31: return "t6";
}

return "???";
#endif
}
Expand Down Expand Up @@ -290,7 +325,7 @@ size_t GCDump::DumpGCTable(PTR_CBYTE gcInfoBlock,
| DECODE_GC_LIFETIMES
| DECODE_PROLOG_LENGTH
| DECODE_RETURN_KIND
#if defined(TARGET_ARM) || defined(TARGET_ARM64)
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_RISCV64)
| DECODE_HAS_TAILCALLS
#endif
),
Expand Down Expand Up @@ -423,7 +458,7 @@ size_t GCDump::DumpGCTable(PTR_CBYTE gcInfoBlock,

#ifdef TARGET_AMD64
gcPrintf("Wants Report Only Leaf: %u\n", hdrdecoder.WantsReportOnlyLeaf());
#elif defined(TARGET_ARM) || defined(TARGET_ARM64)
#elif defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_RISCV64)
gcPrintf("Has tailcalls: %u\n", hdrdecoder.HasTailCalls());
#endif // TARGET_AMD64
#ifdef FIXED_STACK_PARAMETER_SCRATCH_AREA
Expand Down
88 changes: 82 additions & 6 deletions src/coreclr/gcinfo/gcinfodumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,19 @@ PORTABILITY_ASSERT("GcInfoDumper::ReportPointerRecord is not implemented on this
assert(!"unimplemented on LOONGARCH yet");
iSPRegister = 0;
#elif defined(TARGET_RISCV64)
assert(!"unimplemented on RISCV64 yet");
iSPRegister = 0;
iSPRegister = (offsetof(T_CONTEXT, Sp) - offsetof(T_CONTEXT, R0)) / sizeof(ULONGLONG);
#endif

#if defined(TARGET_ARM) || defined(TARGET_ARM64)
BYTE* pContext = (BYTE*)&(pRD->volatileCurrContextPointers);
#elif defined(TARGET_LOONGARCH64)
assert(!"unimplemented on LOONGARCH yet");
BYTE* pContext = (BYTE*)pRD->pCurrentContext;
#elif defined(TARGET_RISCV64)
assert(!"unimplemented on RISCV64 yet");
// TODO implement risc-v code, that should care about volatile registers (same as arm/arm64 architectures)
// instead of default code.
BYTE* pContext = (BYTE*)pRD->pCurrentContext;
#else
BYTE* pContext = (BYTE*)pRD->pCurrentContext;
#endif
Expand Down Expand Up @@ -365,6 +369,8 @@ PORTABILITY_ASSERT("GcInfoDumper::ReportPointerRecord is not implemented on this
}
#elif defined(TARGET_LOONGARCH64)
assert(!"unimplemented on LOONGARCH yet");
#elif defined(TARGET_RISCV64)
assert(!"unimplemented on RISCV64 yet");
#endif
{
_ASSERTE(iReg < nCONTEXTRegisters);
Expand Down Expand Up @@ -392,6 +398,11 @@ PORTABILITY_ASSERT("GcInfoDumper::ReportPointerRecord is not implemented on this
#elif defined(TARGET_LOONGARCH64)
assert(!"unimplemented on LOONGARCH yet");
pReg = (SIZE_T*)(pContext + rgRegisters[iReg].cbContextOffset);
#elif defined(TARGET_RISCV64)
assert(!"unimplemented on RISCV64 yet");
// TODO implement risc-v code, that should care about volatile registers (same as arm/arm64 architectures)
// instead of default code.
pReg = (SIZE_T*)(pContext + rgRegisters[iReg].cbContextOffset);
#else
pReg = (SIZE_T*)(pContext + rgRegisters[iReg].cbContextOffset);
#endif
Expand Down Expand Up @@ -465,6 +476,14 @@ PORTABILITY_ASSERT("GcInfoDumper::ReportPointerRecord is not implemented on this
assert(!"unimplemented on LOONGARCH yet");
//TODO: should confirm ?
base = GC_SP_REL;
#elif defined(TARGET_RISCV64)
assert(!"unimplemented on RISCV64 yet");
// TODO implement risc-v code, that should care about volatile registers (same as arm/arm64 architectures)
// instead of default code.
if (0 == ctx)
base = GC_SP_REL;
else
base = GC_CALLER_SP_REL;
#else
if (0 == ctx)
base = GC_SP_REL;
Expand Down Expand Up @@ -496,6 +515,11 @@ PORTABILITY_ASSERT("GcInfoDumper::ReportPointerRecord is not implemented on this
pContext = (BYTE*)pRD->pCurrentContextPointers;
#elif defined(TARGET_LOONGARCH64)
assert(!"unimplemented on LOONGARCH yet");
#elif defined(TARGET_RISCV64)
assert(!"unimplemented on RISCV64 yet");
// TODO implement risc-v code, that should care about volatile registers (same as arm/arm64 architectures)
// instead of default code.
pContext = (BYTE*)pRD->pCallerContext;
#else
pContext = (BYTE*)pRD->pCallerContext;
#endif
Expand Down Expand Up @@ -703,8 +727,57 @@ GcInfoDumper::EnumerateStateChangesResults GcInfoDumper::EnumerateStateChanges (
#pragma message("Unimplemented for LOONGARCH64 yet.")
assert(!"unimplemented on LOONGARCH yet");
#elif defined(TARGET_RISCV64)
#pragma message("Unimplemented for RISCV64 yet.")
assert(!"unimplemented on RISCV64 yet");
FILL_REGS(pCurrentContext->R0, 33);
FILL_REGS(pCallerContext->R0, 33);

regdisp.pCurrentContextPointers = &regdisp.ctxPtrsOne;
regdisp.pCallerContextPointers = &regdisp.ctxPtrsTwo;

// Set S1
regdisp.pCurrentContextPointers->S1 = &regdisp.pCurrentContext->S1;
regdisp.pCallerContextPointers ->S1 = &regdisp.pCallerContext ->S1;

ULONG64 **ppCurrentReg = &regdisp.pCurrentContextPointers->S2;
ULONG64 **ppCallerReg = &regdisp.pCallerContextPointers ->S2;
// Set S2-S11
for (iReg = 0; iReg < 10; iReg++)
{
*(ppCurrentReg + iReg) = &regdisp.pCurrentContext->S2 + iReg;
*(ppCallerReg + iReg) = &regdisp.pCallerContext ->S2 + iReg;
}

// Set Fp
regdisp.pCurrentContextPointers->Fp = &regdisp.pCurrentContext->Fp;
regdisp.pCallerContextPointers ->Fp = &regdisp.pCallerContext ->Fp;

// Set Gp
regdisp.pCurrentContextPointers->Gp = &regdisp.pCurrentContext->Gp;
regdisp.pCallerContextPointers ->Gp = &regdisp.pCallerContext ->Gp;

// Set Tp
regdisp.pCurrentContextPointers->Tp = &regdisp.pCurrentContext->Tp;
regdisp.pCallerContextPointers ->Tp = &regdisp.pCallerContext ->Tp;

// Set Ra
regdisp.pCurrentContextPointers->Ra = &regdisp.pCurrentContext->Ra;
regdisp.pCallerContextPointers ->Ra = &regdisp.pCallerContext ->Ra;

regdisp.volatileCurrContextPointers.R0 = &regdisp.pCurrentContext->R0;
regdisp.volatileCurrContextPointers.A0 = &regdisp.pCurrentContext->A0;
regdisp.volatileCurrContextPointers.A1 = &regdisp.pCurrentContext->A1;
regdisp.volatileCurrContextPointers.A2 = &regdisp.pCurrentContext->A2;
regdisp.volatileCurrContextPointers.A3 = &regdisp.pCurrentContext->A3;
regdisp.volatileCurrContextPointers.A4 = &regdisp.pCurrentContext->A4;
regdisp.volatileCurrContextPointers.A5 = &regdisp.pCurrentContext->A5;
regdisp.volatileCurrContextPointers.A6 = &regdisp.pCurrentContext->A6;
regdisp.volatileCurrContextPointers.A7 = &regdisp.pCurrentContext->A7;
regdisp.volatileCurrContextPointers.T0 = &regdisp.pCurrentContext->T0;
regdisp.volatileCurrContextPointers.T1 = &regdisp.pCurrentContext->T1;
regdisp.volatileCurrContextPointers.T2 = &regdisp.pCurrentContext->T2;
regdisp.volatileCurrContextPointers.T3 = &regdisp.pCurrentContext->T3;
regdisp.volatileCurrContextPointers.T4 = &regdisp.pCurrentContext->T4;
regdisp.volatileCurrContextPointers.T5 = &regdisp.pCurrentContext->T5;
regdisp.volatileCurrContextPointers.T6 = &regdisp.pCurrentContext->T6;
#else
PORTABILITY_ASSERT("GcInfoDumper::EnumerateStateChanges is not implemented on this platform.");
#endif
Expand Down Expand Up @@ -752,9 +825,9 @@ PORTABILITY_ASSERT("GcInfoDumper::EnumerateStateChanges is not implemented on th
(GcInfoDecoderFlags)( DECODE_SECURITY_OBJECT
| DECODE_CODE_LENGTH
| DECODE_VARARG
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
| DECODE_HAS_TAILCALLS
#endif // TARGET_ARM || TARGET_ARM64 || TARGET_LOONGARCH64
#endif // TARGET_ARM || TARGET_ARM64 || TARGET_LOONGARCH64 || TARGET_RISCV64

| DECODE_INTERRUPTIBILITY),
offset);
Expand All @@ -778,6 +851,9 @@ PORTABILITY_ASSERT("GcInfoDumper::EnumerateStateChanges is not implemented on th
#elif defined(TARGET_LOONGARCH64)
#pragma message("Unimplemented for LOONGARCH64 yet.")
assert(!"unimplemented on LOONGARCH yet");
#elif defined(TARGET_RISCV64)
#pragma message("Unimplemented for RISCV64 yet.")
assert(!"unimplemented on RISCV64 yet");
#endif
if(safePointDecoder.IsSafePoint(safePointOffset))
{
Expand Down

0 comments on commit 3c5123e

Please sign in to comment.