Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoongArch64] Remove the register tp from callee saved registers in coreclr. #108696

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class AsmOffsets
public const int OFFSETOF__REGDISPLAY__SP = 0x628;
public const int OFFSETOF__REGDISPLAY__ControlPC = 0x630;
#elif TARGET_LOONGARCH64
public const int SIZEOF__REGDISPLAY = 0xc70;
public const int OFFSETOF__REGDISPLAY__SP = 0xbb8;
public const int OFFSETOF__REGDISPLAY__ControlPC = 0xbc0;
public const int SIZEOF__REGDISPLAY = 0xc60;
public const int OFFSETOF__REGDISPLAY__SP = 0xba8;
public const int OFFSETOF__REGDISPLAY__ControlPC = 0xbb0;
#endif

#if TARGET_64BIT
Expand Down Expand Up @@ -99,9 +99,9 @@ class AsmOffsets
public const int OFFSETOF__REGDISPLAY__SP = 0x620;
public const int OFFSETOF__REGDISPLAY__ControlPC = 0x628;
#elif TARGET_LOONGARCH64
public const int SIZEOF__REGDISPLAY = 0xc60;
public const int OFFSETOF__REGDISPLAY__SP = 0xbb0;
public const int OFFSETOF__REGDISPLAY__ControlPC = 0xbb8;
public const int SIZEOF__REGDISPLAY = 0xc50;
public const int OFFSETOF__REGDISPLAY__SP = 0xba0;
public const int OFFSETOF__REGDISPLAY__ControlPC = 0xba8;
#endif

#if TARGET_64BIT
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/debug/createdump/threadinfounix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ ThreadInfo::GetThreadContext(uint32_t flags, CONTEXT* context) const
}
if (flags & CONTEXT_INTEGER)
{
context->Tp = m_gpRegisters.regs[2];
memcpy(&context->A0, &m_gpRegisters.regs[4], sizeof(context->A0)*(21 - 4 + 1));
memcpy(&context->S0, &m_gpRegisters.regs[23], sizeof(context->S0)*9);
}
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/debug/di/loongarch64/cordbregisterset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ void CordbRegisterSet::InternalCopyRDToContext(DT_CONTEXT *pInputContext)
*pDest++ = *pSrc++;
}

pInputContext->Tp = m_rd->TP;
pInputContext->Ra = m_rd->RA;
}

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/debug/ee/debugger.inl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ inline void FuncEvalFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFl
pRD->pCurrentContextPointers->S6 = &(pDE->m_context.S6);
pRD->pCurrentContextPointers->S7 = &(pDE->m_context.S7);
pRD->pCurrentContextPointers->S8 = &(pDE->m_context.S8);
pRD->pCurrentContextPointers->Tp = &(pDE->m_context.Tp);
pRD->pCurrentContextPointers->Fp = &(pDE->m_context.Fp);
pRD->pCurrentContextPointers->Ra = &(pDE->m_context.Ra);

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/debug/shared/loongarch64/primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ void SetDebuggerREGDISPLAYFromREGDISPLAY(DebuggerREGDISPLAY* pDRD, REGDISPLAY* p

if ((flags & DT_CONTEXT_INTEGER) == DT_CONTEXT_INTEGER)
{
pDRD->TP = pContext->Tp;
memcpy(&pDRD->A0, &pContext->A0, sizeof(pDRD->A0)*(21 - 4 + 1));
memcpy(&pDRD->S0, &pContext->S0, sizeof(pDRD->S0)* 9);
}
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/gcinfo/gcinfodumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ BOOL GcInfoDumper::ReportPointerRecord (
#define vREG(reg, field) { offsetof(LoongArch64VolatileContextPointer, field) }
vREG(zero, R0),
REG(ra, Ra),
REG(tp, Tp),
{ offsetof(T_CONTEXT, Sp) },
vREG(a0, A0),
vREG(a1, A1),
Expand Down Expand Up @@ -727,11 +726,9 @@ GcInfoDumper::EnumerateStateChangesResults GcInfoDumper::EnumerateStateChanges (
*(ppCallerReg + iReg) = &regdisp.pCallerContext->S0 + iReg;
}

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

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/inc/crosscomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS {
PDWORD64 S7;
PDWORD64 S8;
PDWORD64 Fp;
PDWORD64 Tp;
PDWORD64 Ra;

PDWORD64 F24;
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/inc/regdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ inline void FillContextPointers(PT_KNONVOLATILE_CONTEXT_POINTERS pCtxPtrs, PT_CO
*(&pCtxPtrs->S6) = &pCtx->S6;
*(&pCtxPtrs->S7) = &pCtx->S7;
*(&pCtxPtrs->S8) = &pCtx->S8;
*(&pCtxPtrs->Tp) = &pCtx->Tp;
*(&pCtxPtrs->Fp) = &pCtx->Fp;
*(&pCtxPtrs->Ra) = &pCtx->Ra;
#elif defined(TARGET_ARM) // TARGET_LOONGARCH64
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,6 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
PDWORD64 S7;
PDWORD64 S8;
PDWORD64 Fp;
PDWORD64 Tp;
PDWORD64 Ra;

PDWORD64 F24;
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/arch/loongarch64/exceptionhelper.S
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ LEAF_ENTRY ThrowExceptionFromContextInternal, _TEXT
.cfi_rel_offset 22, 0
.cfi_rel_offset 1, 8

ld.d $tp, $a0, CONTEXT_Tp
ld.d $s0, $a0, CONTEXT_S0
ld.d $s1, $a0, CONTEXT_S1
ld.d $s2, $a0, CONTEXT_S2
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/pal/src/exception/remote-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,6 @@ static void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext,
GetContextPointer(cursor, unwContext, UNW_AARCH64_X29, (SIZE_T**)&contextPointers->Fp);
#elif defined(TARGET_LOONGARCH64)
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R1, (SIZE_T **)&contextPointers->Ra);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R2, (SIZE_T **)&contextPointers->Tp);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R22, (SIZE_T **)&contextPointers->Fp);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R23, (SIZE_T **)&contextPointers->S0);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R24, (SIZE_T **)&contextPointers->S1);
Expand Down Expand Up @@ -1963,7 +1962,6 @@ static void UnwindContextToContext(unw_cursor_t *cursor, CONTEXT *winContext)
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Pc);
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->Sp);
unw_get_reg(cursor, UNW_LOONGARCH64_R1, (unw_word_t *) &winContext->Ra);
unw_get_reg(cursor, UNW_LOONGARCH64_R2, (unw_word_t *) &winContext->Tp);
unw_get_reg(cursor, UNW_LOONGARCH64_R22, (unw_word_t *) &winContext->Fp);
unw_get_reg(cursor, UNW_LOONGARCH64_R23, (unw_word_t *) &winContext->S0);
unw_get_reg(cursor, UNW_LOONGARCH64_R24, (unw_word_t *) &winContext->S1);
Expand All @@ -1974,7 +1972,7 @@ static void UnwindContextToContext(unw_cursor_t *cursor, CONTEXT *winContext)
unw_get_reg(cursor, UNW_LOONGARCH64_R29, (unw_word_t *) &winContext->S6);
unw_get_reg(cursor, UNW_LOONGARCH64_R30, (unw_word_t *) &winContext->S7);
unw_get_reg(cursor, UNW_LOONGARCH64_R31, (unw_word_t *) &winContext->S8);
TRACE("sp %p pc %p fp %p tp %p ra %p\n", winContext->Sp, winContext->Pc, winContext->Fp, winContext->Tp, winContext->Ra);
TRACE("sp %p pc %p fp %p ra %p\n", winContext->Sp, winContext->Pc, winContext->Fp, winContext->Ra);
#elif defined(TARGET_S390X)
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->PSWAddr);
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->R15);
Expand Down Expand Up @@ -2118,7 +2116,6 @@ access_reg(unw_addr_space_t as, unw_regnum_t regnum, unw_word_t *valp, int write
case UNW_AARCH64_PC: *valp = (unw_word_t)winContext->Pc; break;
#elif defined(TARGET_LOONGARCH64)
case UNW_LOONGARCH64_R1: *valp = (unw_word_t)winContext->Ra; break;
case UNW_LOONGARCH64_R2: *valp = (unw_word_t)winContext->Tp; break;
case UNW_LOONGARCH64_R3: *valp = (unw_word_t)winContext->Sp; break;
case UNW_LOONGARCH64_R22: *valp = (unw_word_t)winContext->Fp; break;
case UNW_LOONGARCH64_R23: *valp = (unw_word_t)winContext->S0; break;
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/pal/src/exception/seh-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ enum
#elif (defined(HOST_UNIX) && defined(HOST_LOONGARCH64))
#define ASSIGN_UNWIND_REGS \
ASSIGN_REG(Pc) \
ASSIGN_REG(Tp) \
ASSIGN_REG(Sp) \
ASSIGN_REG(Fp) \
ASSIGN_REG(Ra) \
Expand Down Expand Up @@ -448,7 +447,6 @@ void UnwindContextToWinContext(unw_cursor_t *cursor, CONTEXT *winContext)
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Pc);
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->Sp);
unw_get_reg(cursor, UNW_LOONGARCH64_R1, (unw_word_t *) &winContext->Ra);
unw_get_reg(cursor, UNW_LOONGARCH64_R2, (unw_word_t *) &winContext->Tp);
unw_get_reg(cursor, UNW_LOONGARCH64_R22, (unw_word_t *) &winContext->Fp);
unw_get_reg(cursor, UNW_LOONGARCH64_R23, (unw_word_t *) &winContext->S0);
unw_get_reg(cursor, UNW_LOONGARCH64_R24, (unw_word_t *) &winContext->S1);
Expand Down Expand Up @@ -586,7 +584,6 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL
GetContextPointer(cursor, unwContext, UNW_S390X_R15, (SIZE_T **)&contextPointers->R15);
#elif (defined(HOST_UNIX) && defined(HOST_LOONGARCH64))
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R1, (SIZE_T **)&contextPointers->Ra);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R2, (SIZE_T **)&contextPointers->Tp);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R22, (SIZE_T **)&contextPointers->Fp);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R23, (SIZE_T **)&contextPointers->S0);
GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R24, (SIZE_T **)&contextPointers->S1);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/thread/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ typedef int __ptrace_request;

#define ASSIGN_INTEGER_REGS \
ASSIGN_REG(R0) \
ASSIGN_REG(Tp) \
ASSIGN_REG(A0) \
ASSIGN_REG(A1) \
ASSIGN_REG(A2) \
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ class ResumableFrame : public Frame
Object** firstIntReg = (Object**)&this->GetContext()->X0;
Object** lastIntReg = (Object**)&this->GetContext()->X28;
#elif defined(TARGET_LOONGARCH64)
Object** firstIntReg = (Object**)&this->GetContext()->Tp;
Object** firstIntReg = (Object**)&this->GetContext()->A0;
Object** lastIntReg = (Object**)&this->GetContext()->S8;
#elif defined(TARGET_RISCV64)
Object** firstIntReg = (Object**)&this->GetContext()->Gp;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/loongarch64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ ASMCONSTANTS_C_ASSERT(FpStruct__BothFloat == (int)FpStruct::BothFloat)
ASMCONSTANTS_C_ASSERT(MachState__captureCalleeSavedRegisters == offsetof(MachState, captureCalleeSavedRegisters))

// Offset of the array containing the address of preserved registers in MachState
#define MachState__ptrCalleeSavedRegisters 0x58
#define MachState__ptrCalleeSavedRegisters 0x50
ASMCONSTANTS_C_ASSERT(MachState__ptrCalleeSavedRegisters == offsetof(MachState, ptrCalleeSavedRegisters))

#define MachState__isValid 0xc0
#define MachState__isValid 0xb0
ASMCONSTANTS_C_ASSERT(MachState__isValid == offsetof(MachState, _isValid))

#define LazyMachState_captureCalleeSavedRegisters MachState__captureCalleeSavedRegisters
Expand Down
18 changes: 6 additions & 12 deletions src/coreclr/vm/loongarch64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ LEAF_ENTRY HelperMethodFrameRestoreState, _TEXT
RestoreRegMS 30, s7
RestoreRegMS 31, s8
RestoreRegMS 32, fp //NOTE: here 32 is not the real fp register number.
RestoreRegMS 33, tp //NOTE: here 33 is not the real tp register number.
LOCAL_LABEL(Done):
// Its imperative that the return value of HelperMethodFrameRestoreState is zero
// as it is used in the state machine to loop until it becomes zero.
Expand Down Expand Up @@ -455,7 +454,6 @@ LEAF_ENTRY LazyMachStateCaptureState, _TEXT
st.d $s7, $a1, 56
st.d $s8, $a1, 64
st.d $fp, $a1, 72
st.d $tp, $a1, 80

jirl $r0, $ra, 0
LEAF_END LazyMachStateCaptureState, _TEXT
Expand Down Expand Up @@ -773,7 +771,7 @@ NESTED_ENTRY OnHijackTripThread, _TEXT, NoHandler
PROLOG_SAVE_REG_PAIR 25, 26, 32
PROLOG_SAVE_REG_PAIR 27, 28, 48
PROLOG_SAVE_REG_PAIR 29, 30, 64
PROLOG_SAVE_REG_PAIR 31, 2, 80
PROLOG_SAVE_REG 31, 80

// save any integral return value(s)
st.d $a0, $sp, 96
Expand All @@ -800,7 +798,7 @@ NESTED_ENTRY OnHijackTripThread, _TEXT, NoHandler
EPILOG_RESTORE_REG_PAIR 25, 26, 32
EPILOG_RESTORE_REG_PAIR 27, 28, 48
EPILOG_RESTORE_REG_PAIR 29, 30, 64
EPILOG_RESTORE_REG_PAIR 31, 2, 80
EPILOG_RESTORE_REG 31, 80
// $fp,$ra
EPILOG_RESTORE_REG_PAIR_INDEXED 22, 1, 0x80
EPILOG_RETURN
Expand Down Expand Up @@ -843,14 +841,11 @@ NESTED_ENTRY CallEHFunclet, _TEXT, NoHandler
PROLOG_SAVE_REG_PAIR 25, 26, 32
PROLOG_SAVE_REG_PAIR 27, 28, 48
PROLOG_SAVE_REG_PAIR 29, 30, 64
// $s8,$tp
PROLOG_SAVE_REG_PAIR 31, 2, 80
//PROLOG_SAVE_REG 31, 80
PROLOG_SAVE_REG 31, 80

// Save the SP of this function
st.d $sp, $a3, 0

ld.d $tp, $a2, -168 // offset of tp in PCONTEXT relative to S0.
ld.d $fp, $a2, -8 // offset of fp in PCONTEXT relative to S0.
ld.d $s0, $a2, 0
ld.d $s1, $a2, 8
Expand All @@ -860,7 +855,7 @@ NESTED_ENTRY CallEHFunclet, _TEXT, NoHandler
ld.d $s5, $a2, 40
ld.d $s6, $a2, 48
ld.d $s7, $a2, 56
ld.d $s8, $a2, 64 // offset of fp in PCONTEXT relative to S0.
ld.d $s8, $a2, 64

// Invoke the funclet
jirl $ra, $a1, 0
Expand All @@ -869,8 +864,7 @@ NESTED_ENTRY CallEHFunclet, _TEXT, NoHandler
EPILOG_RESTORE_REG_PAIR 25, 26, 32
EPILOG_RESTORE_REG_PAIR 27, 28, 48
EPILOG_RESTORE_REG_PAIR 29, 30, 64
EPILOG_RESTORE_REG_PAIR 31, 2, 80
//EPILOG_RESTORE_REG 31, 80
EPILOG_RESTORE_REG 31, 80
// $fp,$ra
EPILOG_RESTORE_REG_PAIR_INDEXED 22, 1, 96
EPILOG_RETURN
Expand All @@ -890,7 +884,7 @@ NESTED_ENTRY CallEHFilterFunclet, _TEXT, NoHandler
// $a3 = address of the location where the SP of funclet's caller (i.e. this helper) should be saved.
//
// Save the SP of this function
st.d $fp, $a3, 0
st.d $fp, $a3, 0
// Invoke the filter funclet
jirl $ra, $a2, 0

Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/vm/loongarch64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
CALLEE_SAVED_REGISTER(S5) \
CALLEE_SAVED_REGISTER(S6) \
CALLEE_SAVED_REGISTER(S7) \
CALLEE_SAVED_REGISTER(S8) \
CALLEE_SAVED_REGISTER(Tp)
CALLEE_SAVED_REGISTER(S8)

#define ENUM_FP_CALLEE_SAVED_REGISTERS() \
CALLEE_SAVED_REGISTER(F[24]) \
Expand Down Expand Up @@ -471,7 +470,7 @@ struct HijackArgs
DWORD64 Ra;
size_t ReturnAddress;
};
DWORD64 S0, S1, S2, S3, S4, S5, S6, S7, S8, Tp;
DWORD64 S0, S1, S2, S3, S4, S5, S6, S7, S8;
union
{
struct {
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/loongarch64/gmscpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#define __gmscpu_h__

// S0 - S8, FP, TP
#define NUM_CALLEESAVED_REGISTERS 11
// S0 - S8, FP
#define NUM_CALLEESAVED_REGISTERS 10

struct MachState {
ULONG64 captureCalleeSavedRegisters[NUM_CALLEESAVED_REGISTERS]; // preserved registers
Expand Down
Loading
Loading