diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2016-05-04 09:10:20 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-05-04 09:10:20 +0300 |
commit | 2907f2df9e86fe0830659755bb50c6f2b66ed4d1 (patch) | |
tree | 336c2035b154417a604b6bc9b44915f10452e5eb /src | |
parent | 6de337625995e5cacf0954b9bc3e9f7e74f98b0b (diff) |
Modify context related data structures for Unix AMD64 (#1228)
This change modifies PAL_LIMITED_CONTEXT, StackFrameIterator and REGDISPLAY
structs and also all related code accessing registers that are not present
for Unix.
Diffstat (limited to 'src')
-rw-r--r-- | src/Native/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Native/Runtime/EHHelpers.cpp | 13 | ||||
-rw-r--r-- | src/Native/Runtime/PalRedhawkCommon.h | 24 | ||||
-rw-r--r-- | src/Native/Runtime/RHCodeMan.cpp | 2 | ||||
-rw-r--r-- | src/Native/Runtime/StackFrameIterator.cpp | 40 | ||||
-rw-r--r-- | src/Native/Runtime/StackFrameIterator.h | 13 | ||||
-rw-r--r-- | src/Native/Runtime/amd64/AsmOffsetsCpu.h | 52 | ||||
-rw-r--r-- | src/Native/Runtime/regdisplay.h | 4 |
8 files changed, 137 insertions, 12 deletions
diff --git a/src/Native/CMakeLists.txt b/src/Native/CMakeLists.txt index 5ee7e0d17..d3a74ff05 100644 --- a/src/Native/CMakeLists.txt +++ b/src/Native/CMakeLists.txt @@ -89,6 +89,7 @@ if (CLR_CMAKE_PLATFORM_UNIX) if (CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64) # Allow 16 byte compare-exchange add_compile_options(-mcx16) + add_definitions(-DUNIX_AMD64_ABI) endif() # Disable strict warning on unused functions. diff --git a/src/Native/Runtime/EHHelpers.cpp b/src/Native/Runtime/EHHelpers.cpp index d1010754b..b385f85c4 100644 --- a/src/Native/Runtime/EHHelpers.cpp +++ b/src/Native/Runtime/EHHelpers.cpp @@ -129,7 +129,18 @@ COOP_PINVOKE_HELPER(void, RhpCopyContextFromExInfo, UNREFERENCED_PARAMETER(cbOSContext); ASSERT(cbOSContext >= sizeof(CONTEXT)); CONTEXT* pContext = (CONTEXT *)pOSContext; -#ifdef _AMD64_ +#if defined(UNIX_AMD64_ABI) + pContext->Rip = pPalContext->IP; + pContext->Rsp = pPalContext->Rsp; + pContext->Rbp = pPalContext->Rbp; + pContext->Rdx = pPalContext->Rdx; + pContext->Rax = pPalContext->Rax; + pContext->Rbx = pPalContext->Rbx; + pContext->R12 = pPalContext->R12; + pContext->R13 = pPalContext->R13; + pContext->R14 = pPalContext->R14; + pContext->R15 = pPalContext->R15; +#elif defined(_AMD64_) pContext->Rip = pPalContext->IP; pContext->Rsp = pPalContext->Rsp; pContext->Rbp = pPalContext->Rbp; diff --git a/src/Native/Runtime/PalRedhawkCommon.h b/src/Native/Runtime/PalRedhawkCommon.h index 6ce08238a..0b1eb9157 100644 --- a/src/Native/Runtime/PalRedhawkCommon.h +++ b/src/Native/Runtime/PalRedhawkCommon.h @@ -61,14 +61,30 @@ struct PAL_LIMITED_CONTEXT UIntNative GetIp() const { return IP; } UIntNative GetSp() const { return SP; } UIntNative GetFp() const { return R7; } -#elif defined(_ARM64_) +#elif defined(_TARGET_ARM64_) // @TODO: Add ARM64 registers UIntNative IP; UIntNative GetIp() const { PORTABILITY_ASSERT("@TODO: FIXME:ARM64"); } UIntNative GetSp() const { PORTABILITY_ASSERT("@TODO: FIXME:ARM64"); } UIntNative GetFp() const { PORTABILITY_ASSERT("@TODO: FIXME:ARM64"); } -#else // _ARM_ +#elif defined(UNIX_AMD64_ABI) + // Param regs: rdi, rsi, rdx, rcx, r8, r9, scratch: rax, rdx (both return val), preserved: rbp, rbx, r12-r15 + UIntNative IP; + UIntNative Rsp; + UIntNative Rbp; + UIntNative Rax; + UIntNative Rbx; + UIntNative Rdx; + UIntNative R12; + UIntNative R13; + UIntNative R14; + UIntNative R15; + + UIntNative GetIp() const { return IP; } + UIntNative GetSp() const { return Rsp; } + UIntNative GetFp() const { return Rbp; } +#else // _TARGET_ARM_ UIntNative IP; UIntNative Rsp; UIntNative Rbp; @@ -92,12 +108,12 @@ struct PAL_LIMITED_CONTEXT Fp128 Xmm13; Fp128 Xmm14; Fp128 Xmm15; -#endif // _AMD64_ +#endif // _TARGET_AMD64_ UIntNative GetIp() const { return IP; } UIntNative GetSp() const { return Rsp; } UIntNative GetFp() const { return Rbp; } -#endif // _ARM_ +#endif // _TARGET_ARM_ }; void __stdcall RuntimeThreadShutdown(void* thread); diff --git a/src/Native/Runtime/RHCodeMan.cpp b/src/Native/Runtime/RHCodeMan.cpp index cb48f18bd..9f75958a3 100644 --- a/src/Native/Runtime/RHCodeMan.cpp +++ b/src/Native/Runtime/RHCodeMan.cpp @@ -660,7 +660,7 @@ bool EECodeManager::UnwindStackFrame(EEMethodInfo * pMethodInfo, } PTR_UIntNative RSP = (PTR_UIntNative)rawRSP; -#if defined(_TARGET_AMD64_) +#if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) if (pInfoHeader->HasSavedXmmRegs()) { typedef DPTR(Fp128) PTR_Fp128; diff --git a/src/Native/Runtime/StackFrameIterator.cpp b/src/Native/Runtime/StackFrameIterator.cpp index 8ef34f043..227205c2b 100644 --- a/src/Native/Runtime/StackFrameIterator.cpp +++ b/src/Native/Runtime/StackFrameIterator.cpp @@ -352,6 +352,29 @@ void StackFrameIterator::InternalInit(Thread * pThreadToWalk, PTR_PAL_LIMITED_CO #elif defined(_TARGET_ARM64_) PORTABILITY_ASSERT("@TODO: FIXME:ARM64"); +#elif defined(UNIX_AMD64_ABI) + // + // preserved regs + // + m_RegDisplay.pRbp = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, Rbp); + m_RegDisplay.pRbx = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, Rbx); + m_RegDisplay.pR12 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, R12); + m_RegDisplay.pR13 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, R13); + m_RegDisplay.pR14 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, R14); + m_RegDisplay.pR15 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, R15); + + // + // scratch regs + // + m_RegDisplay.pRax = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, Rax); + m_RegDisplay.pRcx = NULL; + m_RegDisplay.pRdx = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pCtx, Rdx); + m_RegDisplay.pRsi = NULL; + m_RegDisplay.pRdi = NULL; + m_RegDisplay.pR8 = NULL; + m_RegDisplay.pR9 = NULL; + m_RegDisplay.pR10 = NULL; + m_RegDisplay.pR11 = NULL; #else // _TARGET_ARM_ // // preserved regs @@ -490,6 +513,14 @@ void StackFrameIterator::UpdateFromExceptionDispatch(PTR_StackFrameIterator pSou #elif defined(_TARGET_ARM64_) PORTABILITY_ASSERT("@TODO: FIXME:ARM64"); +#elif defined(UNIX_AMD64_ABI) + // Save the preserved regs portion of the REGDISPLAY across the unwind through the C# EH dispatch code. + m_RegDisplay.pRbp = thisFuncletPtrs.pRbp; + m_RegDisplay.pRbx = thisFuncletPtrs.pRbx; + m_RegDisplay.pR12 = thisFuncletPtrs.pR12; + m_RegDisplay.pR13 = thisFuncletPtrs.pR13; + m_RegDisplay.pR14 = thisFuncletPtrs.pR14; + m_RegDisplay.pR15 = thisFuncletPtrs.pR15; #else // Save the preserved regs portion of the REGDISPLAY across the unwind through the C# EH dispatch code. m_RegDisplay.pRbp = thisFuncletPtrs.pRbp; @@ -906,7 +937,14 @@ void StackFrameIterator::UnwindThrowSiteThunk() PTR_PAL_LIMITED_CONTEXT pContext = (PTR_PAL_LIMITED_CONTEXT) (m_RegDisplay.SP + SIZEOF_OutgoingScratch + STACKSIZEOF_ExInfo); -#ifdef _TARGET_AMD64_ +#if defined(UNIX_AMD64_ABI) + m_RegDisplay.pRbp = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, Rbp); + m_RegDisplay.pRbx = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, Rbx); + m_RegDisplay.pR12 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, R12); + m_RegDisplay.pR13 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, R13); + m_RegDisplay.pR14 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, R14); + m_RegDisplay.pR15 = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, R15); +#elif defined(_TARGET_AMD64_) m_RegDisplay.pRbp = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, Rbp); m_RegDisplay.pRdi = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, Rdi); m_RegDisplay.pRsi = PTR_TO_MEMBER(PAL_LIMITED_CONTEXT, pContext, Rsi); diff --git a/src/Native/Runtime/StackFrameIterator.h b/src/Native/Runtime/StackFrameIterator.h index d4855c28e..27ef0b985 100644 --- a/src/Native/Runtime/StackFrameIterator.h +++ b/src/Native/Runtime/StackFrameIterator.h @@ -157,7 +157,14 @@ private: PTR_UIntNative pR9; PTR_UIntNative pR10; PTR_UIntNative pR11; -#else +#elif defined(UNIX_AMD64_ABI) + PTR_UIntNative pRbp; + PTR_UIntNative pRbx; + PTR_UIntNative pR12; + PTR_UIntNative pR13; + PTR_UIntNative pR14; + PTR_UIntNative pR15; +#else // _TARGET_ARM_ PTR_UIntNative pRbp; PTR_UIntNative pRdi; PTR_UIntNative pRsi; @@ -167,8 +174,8 @@ private: PTR_UIntNative pR13; PTR_UIntNative pR14; PTR_UIntNative pR15; -#endif // _AMD64_ -#endif // _ARM_ +#endif // _TARGET_AMD64_ +#endif // _TARGET_ARM_ }; protected: diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index 7bf8e3384..5dd0c02ff 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -8,6 +8,7 @@ // // NOTE: the offsets MUST be in hex notation WITHOUT the 0x prefix +#ifndef UNIX_AMD64_ABI PLAT_ASM_SIZEOF(250, ExInfo) PLAT_ASM_OFFSET(0, ExInfo, m_pPrevExInfo) PLAT_ASM_OFFSET(8, ExInfo, m_pExContext) @@ -66,3 +67,54 @@ PLAT_ASM_OFFSET(60, REGDISPLAY, pR13) PLAT_ASM_OFFSET(68, REGDISPLAY, pR14) PLAT_ASM_OFFSET(70, REGDISPLAY, pR15) PLAT_ASM_OFFSET(90, REGDISPLAY, Xmm) + +#else // !UNIX_AMD64_ABI + +PLAT_ASM_SIZEOF(198, ExInfo) +PLAT_ASM_OFFSET(0, ExInfo, m_pPrevExInfo) +PLAT_ASM_OFFSET(8, ExInfo, m_pExContext) +PLAT_ASM_OFFSET(10, ExInfo, m_exception) +PLAT_ASM_OFFSET(18, ExInfo, m_kind) +PLAT_ASM_OFFSET(19, ExInfo, m_passNumber) +PLAT_ASM_OFFSET(1c, ExInfo, m_idxCurClause) +PLAT_ASM_OFFSET(20, ExInfo, m_frameIter) +PLAT_ASM_OFFSET(190, ExInfo, m_notifyDebuggerSP) + +PLAT_ASM_OFFSET(0, PInvokeTransitionFrame, m_RIP) +PLAT_ASM_OFFSET(8, PInvokeTransitionFrame, m_FramePointer) +PLAT_ASM_OFFSET(10, PInvokeTransitionFrame, m_pThread) +PLAT_ASM_OFFSET(18, PInvokeTransitionFrame, m_dwFlags) +PLAT_ASM_OFFSET(20, PInvokeTransitionFrame, m_PreservedRegs) + +PLAT_ASM_SIZEOF(170, StackFrameIterator) +PLAT_ASM_OFFSET(10, StackFrameIterator, m_FramePointer) +PLAT_ASM_OFFSET(18, StackFrameIterator, m_ControlPC) +PLAT_ASM_OFFSET(20, StackFrameIterator, m_RegDisplay) + +PLAT_ASM_SIZEOF(50, PAL_LIMITED_CONTEXT) +PLAT_ASM_OFFSET(0, PAL_LIMITED_CONTEXT, IP) + +PLAT_ASM_OFFSET(8, PAL_LIMITED_CONTEXT, Rsp) +PLAT_ASM_OFFSET(10, PAL_LIMITED_CONTEXT, Rbp) +PLAT_ASM_OFFSET(18, PAL_LIMITED_CONTEXT, Rax) +PLAT_ASM_OFFSET(20, PAL_LIMITED_CONTEXT, Rbx) +PLAT_ASM_OFFSET(28, PAL_LIMITED_CONTEXT, Rdx) + +PLAT_ASM_OFFSET(30, PAL_LIMITED_CONTEXT, R12) +PLAT_ASM_OFFSET(38, PAL_LIMITED_CONTEXT, R13) +PLAT_ASM_OFFSET(40, PAL_LIMITED_CONTEXT, R14) +PLAT_ASM_OFFSET(48, PAL_LIMITED_CONTEXT, R15) + +PLAT_ASM_SIZEOF(90, REGDISPLAY) +PLAT_ASM_OFFSET(78, REGDISPLAY, SP) + +PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) +PLAT_ASM_OFFSET(20, REGDISPLAY, pRbp) +PLAT_ASM_OFFSET(28, REGDISPLAY, pRsi) +PLAT_ASM_OFFSET(30, REGDISPLAY, pRdi) +PLAT_ASM_OFFSET(58, REGDISPLAY, pR12) +PLAT_ASM_OFFSET(60, REGDISPLAY, pR13) +PLAT_ASM_OFFSET(68, REGDISPLAY, pR14) +PLAT_ASM_OFFSET(70, REGDISPLAY, pR15) + +#endif // !UNIX_AMD64_ABI diff --git a/src/Native/Runtime/regdisplay.h b/src/Native/Runtime/regdisplay.h index b15740c17..098286b2e 100644 --- a/src/Native/Runtime/regdisplay.h +++ b/src/Native/Runtime/regdisplay.h @@ -29,12 +29,12 @@ struct REGDISPLAY PTR_PCODE pIP; PCODE IP; -#ifdef _TARGET_AMD64_ +#if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) Fp128 Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk // these need to be unwound during a stack walk // for EH, but not adjusted, so we only need // their values, not their addresses -#endif // _TARGET_AMD64_ +#endif // _TARGET_AMD64_ && !UNIX_AMD64_ABI inline PCODE GetIP() { return IP; } inline PTR_PCODE GetAddrOfIP() { return pIP; } |