diff --git a/src/coreclr/debug/ee/arm64/dbghelpers.S b/src/coreclr/debug/ee/arm64/dbghelpers.S index 4b9504efec859d..0a52a085a675e8 100644 --- a/src/coreclr/debug/ee/arm64/dbghelpers.S +++ b/src/coreclr/debug/ee/arm64/dbghelpers.S @@ -24,7 +24,7 @@ NESTED_ENTRY FuncEvalHijack, _TEXT, UnhandledExceptionHandlerUnix // FuncEvalHijackWorker returns the address we should jump to. bl C_FUNC(FuncEvalHijackWorker) - EPILOG_STACK_FREE 32 + add sp, sp, 32 EPILOG_BRANCH_REG x0 NESTED_END FuncEvalHijack diff --git a/src/coreclr/inc/eetwain.h b/src/coreclr/inc/eetwain.h index 27fb800306ed25..92c9fc6be40db2 100644 --- a/src/coreclr/inc/eetwain.h +++ b/src/coreclr/inc/eetwain.h @@ -280,7 +280,7 @@ virtual unsigned int GetFrameSize(GCInfoToken gcInfoToken) = 0; /* Debugger API */ -virtual DWORD_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter) = 0; +virtual UINT_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter) = 0; virtual void ResumeAfterCatch(CONTEXT *pContext, size_t targetSSP, bool fIntercepted) = 0; #if defined(HOST_AMD64) && defined(HOST_WINDOWS) virtual void UpdateSSP(PREGDISPLAY pRD) = 0; @@ -493,7 +493,7 @@ unsigned int GetFrameSize(GCInfoToken gcInfoToken); #ifndef DACCESS_COMPILE -virtual DWORD_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter); +virtual UINT_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter); virtual void ResumeAfterCatch(CONTEXT *pContext, size_t targetSSP, bool fIntercepted); #if defined(HOST_AMD64) && defined(HOST_WINDOWS) @@ -651,7 +651,7 @@ unsigned int GetFrameSize(GCInfoToken gcInfoToken) #ifndef DACCESS_COMPILE -virtual DWORD_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter); +virtual UINT_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter); virtual void ResumeAfterCatch(CONTEXT *pContext, size_t targetSSP, bool fIntercepted); #if defined(HOST_AMD64) && defined(HOST_WINDOWS) virtual void UpdateSSP(PREGDISPLAY pRD); diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index df59aad2f2d3ff..4e8ec4aa2ff46f 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -3924,7 +3924,7 @@ void CodeGen::genCreateAndStoreGCInfo(unsigned codeSize, if (m_compiler->info.compIsVarArgs) { - // Varargs save all int registers between saved registers and PSP. + // Varargs save all integer argument registers. preservedAreaSize += MAX_REG_ARG * REGSIZE_BYTES; } diff --git a/src/coreclr/nativeaot/Common/src/Internal/Runtime/TransitionBlock.cs b/src/coreclr/nativeaot/Common/src/Internal/Runtime/TransitionBlock.cs deleted file mode 100644 index e306485a07ebb4..00000000000000 --- a/src/coreclr/nativeaot/Common/src/Internal/Runtime/TransitionBlock.cs +++ /dev/null @@ -1,603 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// -// This file is a line by line port of callingconvention.h from the CLR with the intention that we may wish to merge -// changes from the CLR in at a later time. As such, the normal coding conventions are ignored. -// - -// -#if TARGET_ARM -#define HAS_FLOAT_ARGUMENT_REGISTERS // Calling convention has floating-point argument registers -#define ENREGISTERED_RETURNTYPE_MAXSIZE -#define ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE -#define FEATURE_HFA -#elif TARGET_ARM64 -#define HAS_FLOAT_ARGUMENT_REGISTERS // Calling convention has floating-point argument registers -#define ENREGISTERED_RETURNTYPE_MAXSIZE -#define ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE -#define ENREGISTERED_PARAMTYPE_MAXSIZE -#define FEATURE_HFA -#elif TARGET_X86 -#define ENREGISTERED_RETURNTYPE_MAXSIZE -#define ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE -#elif TARGET_AMD64 -#if TARGET_UNIX -#define UNIX_AMD64_ABI -#else -#endif -#define HAS_FLOAT_ARGUMENT_REGISTERS // Calling convention has floating-point argument registers -#define ENREGISTERED_RETURNTYPE_MAXSIZE -#define ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE -#define ENREGISTERED_PARAMTYPE_MAXSIZE -#elif TARGET_WASMARCH -#elif TARGET_LOONGARCH64 || TARGET_RISCV64 -#define HAS_FLOAT_ARGUMENT_REGISTERS // Calling convention has floating-point argument registers -#define ENREGISTERED_RETURNTYPE_MAXSIZE -#define ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE -#define ENREGISTERED_PARAMTYPE_MAXSIZE -#else -#error Unknown architecture! -#endif - -// Provides an abstraction over platform specific calling conventions (specifically, the calling convention -// utilized by the JIT on that platform). The caller enumerates each argument of a signature in turn, and is -// provided with information mapping that argument into registers and/or stack locations. - -using System; -using System.Runtime.InteropServices; - -namespace Internal.Runtime -{ -#if TARGET_AMD64 -#if UNIX_AMD64_ABI - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - private IntPtr returnValue; - private IntPtr returnValue2; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - private IntPtr rdi; - private IntPtr rsi; - private IntPtr rdx; - private IntPtr rcx; - private IntPtr r8; - private IntPtr r9; - } -#else // UNIX_AMD64_ABI - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - private IntPtr returnValue; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - private IntPtr rdx; - private IntPtr rcx; - private IntPtr r8; - private IntPtr r9; - } -#endif // UNIX_AMD64_ABI - [StructLayout(LayoutKind.Sequential)] - internal struct M128A - { - private IntPtr a; - private IntPtr b; - } - [StructLayout(LayoutKind.Sequential)] - internal struct FloatArgumentRegisters - { - private M128A d0; - private M128A d1; - private M128A d2; - private M128A d3; -#if UNIX_AMD64_ABI - private M128A d4; - private M128A d5; - private M128A d6; - private M128A d7; -#endif - } - - internal struct ArchitectureConstants - { - // To avoid corner case bugs, limit maximum size of the arguments with sufficient margin - public const int MAX_ARG_SIZE = 0xFFFFFF; - -#if UNIX_AMD64_ABI - public const int NUM_ARGUMENT_REGISTERS = 6; -#else - public const int NUM_ARGUMENT_REGISTERS = 4; -#endif - public const int ARGUMENTREGISTERS_SIZE = NUM_ARGUMENT_REGISTERS * 8; - public const int ENREGISTERED_RETURNTYPE_MAXSIZE = 8; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE = 8; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE_PRIMITIVE = 8; - public const int ENREGISTERED_PARAMTYPE_MAXSIZE = 8; - public const int STACK_ELEM_SIZE = 8; - public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); } - } -#elif TARGET_ARM64 - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - private IntPtr returnValue; - private IntPtr returnValue2; - private IntPtr returnValue3; - private IntPtr returnValue4; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - private IntPtr x0; - private IntPtr x1; - private IntPtr x2; - private IntPtr x3; - private IntPtr x4; - private IntPtr x5; - private IntPtr x6; - private IntPtr x7; - private IntPtr x8; - public static unsafe int GetOffsetOfx8() - { - return sizeof(IntPtr) * 8; - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct FloatArgumentRegisters - { - private double d0; - private double d1; - private double d2; - private double d3; - private double d4; - private double d5; - private double d6; - private double d7; - } - - internal struct ArchitectureConstants - { - // To avoid corner case bugs, limit maximum size of the arguments with sufficient margin - public const int MAX_ARG_SIZE = 0xFFFFFF; - - public const int NUM_ARGUMENT_REGISTERS = 8; - public const int ARGUMENTREGISTERS_SIZE = NUM_ARGUMENT_REGISTERS * 8; - public const int ENREGISTERED_RETURNTYPE_MAXSIZE = 32; // bytes (four FP registers: d0,d1,d2 and d3) - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE = 16; // bytes (two int registers: x0 and x1) - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE_PRIMITIVE = 8; - public const int ENREGISTERED_PARAMTYPE_MAXSIZE = 16; // bytes (max value type size that can be passed by value) - public const int STACK_ELEM_SIZE = 8; - public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); } - } -#elif TARGET_X86 - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - public IntPtr returnValue; - public IntPtr returnValue2; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - public IntPtr edx; - public static unsafe int GetOffsetOfEdx() - { - return 0; - } - public IntPtr ecx; - public static unsafe int GetOffsetOfEcx() - { - return sizeof(IntPtr); - } - } - // Floating-point arguments are stack-passed on x86; keep an empty placeholder for the shared ABI abstraction. - [StructLayout(LayoutKind.Sequential)] - internal struct FloatArgumentRegisters - { - } - - internal struct ArchitectureConstants - { - // To avoid corner case bugs, limit maximum size of the arguments with sufficient margin - public const int MAX_ARG_SIZE = 0xFFFFFF; - - public const int NUM_ARGUMENT_REGISTERS = 2; - public const int ARGUMENTREGISTERS_SIZE = NUM_ARGUMENT_REGISTERS * 4; - public const int ENREGISTERED_RETURNTYPE_MAXSIZE = 8; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE = 4; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE_PRIMITIVE = 4; - public const int STACK_ELEM_SIZE = 4; - public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); } - } -#elif TARGET_ARM - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - private IntPtr returnValue; - private IntPtr returnValue2; - private IntPtr returnValue3; - private IntPtr returnValue4; - private IntPtr returnValue5; - private IntPtr returnValue6; - private IntPtr returnValue7; - private IntPtr returnValue8; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - private IntPtr r0; - private IntPtr r1; - private IntPtr r2; - private IntPtr r3; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct FloatArgumentRegisters - { - private double d0; - private double d1; - private double d2; - private double d3; - private double d4; - private double d5; - private double d6; - private double d7; - } - - internal struct ArchitectureConstants - { - // To avoid corner case bugs, limit maximum size of the arguments with sufficient margin - public const int MAX_ARG_SIZE = 0xFFFFFF; - - public const int NUM_ARGUMENT_REGISTERS = 4; - public const int ARGUMENTREGISTERS_SIZE = NUM_ARGUMENT_REGISTERS * 4; - public const int ENREGISTERED_RETURNTYPE_MAXSIZE = 32; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE = 4; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE_PRIMITIVE = 8; - public const int STACK_ELEM_SIZE = 4; - public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); } - } - -#elif TARGET_WASMARCH - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - private IntPtr returnValue; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - // No registers on WASM - } - - [StructLayout(LayoutKind.Sequential)] - internal struct FloatArgumentRegisters - { - // No registers on WASM - } - - internal struct ArchitectureConstants - { - // To avoid corner case bugs, limit maximum size of the arguments with sufficient margin - public const int MAX_ARG_SIZE = 0xFFFFFF; - - public const int NUM_ARGUMENT_REGISTERS = 0; - public const int ARGUMENTREGISTERS_SIZE = NUM_ARGUMENT_REGISTERS * 4; - public const int ENREGISTERED_RETURNTYPE_MAXSIZE = 32; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE = 4; - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE_PRIMITIVE = 8; - public const int STACK_ELEM_SIZE = 4; - public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); } - } -#elif TARGET_LOONGARCH64 - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - private IntPtr returnValue; - private IntPtr returnValue2; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - private IntPtr r4; - private IntPtr r5; - private IntPtr r6; - private IntPtr r7; - private IntPtr r8; - private IntPtr r9; - private IntPtr r10; - private IntPtr r11; - public static unsafe int GetOffsetOfr11() - { - return sizeof(IntPtr) * 7; - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct FloatArgumentRegisters - { - private double f0; - private double f1; - private double f2; - private double f3; - private double f4; - private double f5; - private double f6; - private double f7; - } - - internal struct ArchitectureConstants - { - // To avoid corner case bugs, limit maximum size of the arguments with sufficient margin - public const int MAX_ARG_SIZE = 0xFFFFFF; - - public const int NUM_ARGUMENT_REGISTERS = 8; - public const int ARGUMENTREGISTERS_SIZE = NUM_ARGUMENT_REGISTERS * 8; - public const int ENREGISTERED_RETURNTYPE_MAXSIZE = 16; // bytes (two FP registers: f0, f1) - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE = 16; // bytes (two int registers: a0, a1) - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE_PRIMITIVE = 8; - public const int ENREGISTERED_PARAMTYPE_MAXSIZE = 16; // bytes (max value type size that can be passed by value) - public const int STACK_ELEM_SIZE = 8; - public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); } - } -#elif TARGET_RISCV64 - [StructLayout(LayoutKind.Sequential)] - internal struct ReturnBlock - { - private IntPtr returnValue; - private IntPtr returnValue2; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct ArgumentRegisters - { - private IntPtr a0; - private IntPtr a1; - private IntPtr a2; - private IntPtr a3; - private IntPtr a4; - private IntPtr a5; - private IntPtr a6; - private IntPtr a7; - public static unsafe int GetOffsetOfa7() - { - return sizeof(IntPtr) * 7; - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct FloatArgumentRegisters - { - private double fa0; - private double fa1; - private double fa2; - private double fa3; - private double fa4; - private double fa5; - private double fa6; - private double fa7; - } - - internal struct ArchitectureConstants - { - // To avoid corner case bugs, limit maximum size of the arguments with sufficient margin - public const int MAX_ARG_SIZE = 0xFFFFFF; - - public const int NUM_ARGUMENT_REGISTERS = 8; - public const int ARGUMENTREGISTERS_SIZE = NUM_ARGUMENT_REGISTERS * 8; - public const int ENREGISTERED_RETURNTYPE_MAXSIZE = 32; // bytes (four FP registers: fa0, fa1, fa2, and fa3) - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE = 16; // bytes (two int registers: a0 and a1) - public const int ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE_PRIMITIVE = 8; - public const int ENREGISTERED_PARAMTYPE_MAXSIZE = 16; // bytes (max value type size that can be passed by value) - public const int STACK_ELEM_SIZE = 8; - public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); } - } -#endif - - // - // TransitionBlock is layout of stack frame of method call, saved argument registers and saved callee saved registers. Even though not - // all fields are used all the time, we use uniform form for simplicity. - // - [StructLayout(LayoutKind.Sequential)] - internal struct TransitionBlock - { -#if TARGET_X86 - public ArgumentRegisters m_argumentRegisters; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return 0; - } - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return sizeof(ArgumentRegisters); - } - private IntPtr m_ebp; - private IntPtr m_ReturnAddress; -#elif TARGET_AMD64 - -#if UNIX_AMD64_ABI - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return 0; - } - - public ArgumentRegisters m_argumentRegisters; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return sizeof(ReturnBlock); - } - - private IntPtr m_alignmentPadding; - private IntPtr m_ReturnAddress; -#else // UNIX_AMD64_ABI - private IntPtr m_returnBlockPadding; - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return sizeof(IntPtr); - } - private IntPtr m_alignmentPadding; - private IntPtr m_ReturnAddress; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return sizeof(TransitionBlock); - } -#endif // UNIX_AMD64_ABI - -#elif TARGET_ARM - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return 0; - } - - public ArgumentRegisters m_argumentRegisters; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return sizeof(ReturnBlock); - } -#elif TARGET_ARM64 - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return 0; - } - - public ArgumentRegisters m_argumentRegisters; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return sizeof(ReturnBlock); - } - - public IntPtr m_alignmentPad; -#elif TARGET_WASMARCH - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return 0; - } - - public ArgumentRegisters m_argumentRegisters; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return sizeof(ReturnBlock); - } -#elif TARGET_LOONGARCH64 - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return 0; - } - - public ArgumentRegisters m_argumentRegisters; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return sizeof(ReturnBlock); - } - - public IntPtr m_alignmentPad; -#elif TARGET_RISCV64 - public ReturnBlock m_returnBlock; - public static unsafe int GetOffsetOfReturnValuesBlock() - { - return 0; - } - - public ArgumentRegisters m_argumentRegisters; - public static unsafe int GetOffsetOfArgumentRegisters() - { - return sizeof(ReturnBlock); - } - - public IntPtr m_alignmentPad; -#else -#error Portability problem -#endif - - // The transition block should define everything pushed by callee. The code assumes in number of places that - // end of the transition block is caller's stack pointer. - - public static unsafe byte GetOffsetOfArgs() - { - return (byte)sizeof(TransitionBlock); - } - - - public static bool IsStackArgumentOffset(int offset) - { - int ofsArgRegs = GetOffsetOfArgumentRegisters(); - - return offset >= (int)(ofsArgRegs + ArchitectureConstants.ARGUMENTREGISTERS_SIZE); - } - - public static bool IsArgumentRegisterOffset(int offset) - { - int ofsArgRegs = GetOffsetOfArgumentRegisters(); - - return offset >= ofsArgRegs && offset < (int)(ofsArgRegs + ArchitectureConstants.ARGUMENTREGISTERS_SIZE); - } - -#if !TARGET_X86 - public static unsafe int GetArgumentIndexFromOffset(int offset) - { - return ((offset - GetOffsetOfArgumentRegisters()) / IntPtr.Size); - } - - public static int GetStackArgumentIndexFromOffset(int offset) - { - return (offset - GetOffsetOfArgs()) / ArchitectureConstants.STACK_ELEM_SIZE; - } -#endif - -#if HAS_FLOAT_ARGUMENT_REGISTERS - public static bool IsFloatArgumentRegisterOffset(int offset) - { - return offset < 0; - } - - public static int GetOffsetOfFloatArgumentRegisters() - { - return -GetNegSpaceSize(); - } -#endif - - public static unsafe int GetNegSpaceSize() - { - int negSpaceSize = 0; -#if HAS_FLOAT_ARGUMENT_REGISTERS - negSpaceSize += sizeof(FloatArgumentRegisters); -#endif - return negSpaceSize; - } - - public static int GetThisOffset() - { - // This pointer is in the first argument register by default - int ret = TransitionBlock.GetOffsetOfArgumentRegisters(); - -#if TARGET_X86 - // x86 is special as always - ret += ArgumentRegisters.GetOffsetOfEcx(); -#endif - - return ret; - } - - public const int InvalidOffset = -1; - }; -} diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs index 7c52e60ea1035f..dbbbe7b24d40b8 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs @@ -63,16 +63,7 @@ public override bool Equals(object obj) #endif [RuntimeExport("RhpCidResolve")] - private static IntPtr RhpCidResolve(IntPtr callerTransitionBlockParam, IntPtr pCell) - { - IntPtr locationOfThisPointer = callerTransitionBlockParam + TransitionBlock.GetThisOffset(); - object pObject = *(object*)locationOfThisPointer; - IntPtr dispatchResolveTarget = RhpCidResolve_Worker(pObject, pCell); - return dispatchResolveTarget; - } - - [RuntimeExport("RhpCidResolve_Worker")] - private static IntPtr RhpCidResolve_Worker(object pObject, IntPtr pCell) + private static IntPtr RhpCidResolve(object pObject, IntPtr pCell) { var resolver = (delegate*)InternalCalls.RhpGetClasslibFunctionFromEEType(pObject.GetMethodTable(), ClassLibFunctionId.ResolveDispatch); IntPtr pTargetCode = resolver(pObject, pCell); @@ -157,7 +148,7 @@ private static IntPtr RhpResolveInterfaceMethod(object pObject, IntPtr pCell) if (pTargetCode == IntPtr.Zero) { // Otherwise call the version of this method that knows how to resolve the method manually. - pTargetCode = RhpCidResolve_Worker(pObject, pCell); + pTargetCode = RhpCidResolve(pObject, pCell); } return pTargetCode; diff --git a/src/coreclr/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/CMakeLists.txt index f0356d30d683f0..86e42539222762 100644 --- a/src/coreclr/nativeaot/Runtime/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/CMakeLists.txt @@ -63,7 +63,6 @@ set(COMMON_RUNTIME_SOURCES SyncClean.cpp thread.cpp threadstore.cpp - UniversalTransitionHelpers.cpp yieldprocessornormalized.cpp ${GC_DIR}/gceventstatus.cpp @@ -311,7 +310,6 @@ if(NOT FEATURE_PORTABLE_HELPERS) ${ARCH_SOURCES_DIR}/GcProbe.${ASM_SUFFIX} ${RUNTIME_DIR}/${ARCH_SOURCES_DIR}/MiscStubs.${ASM_SUFFIX} ${ARCH_SOURCES_DIR}/PInvoke.${ASM_SUFFIX} - ${ARCH_SOURCES_DIR}/UniversalTransition.${ASM_SUFFIX} ${RUNTIME_DIR}/${ARCH_SOURCES_DIR}/WriteBarriers.${ASM_SUFFIX} ) diff --git a/src/coreclr/nativeaot/Runtime/EHHelpers.cpp b/src/coreclr/nativeaot/Runtime/EHHelpers.cpp index 479cdea4c78f73..52eb50cc4a56ae 100644 --- a/src/coreclr/nativeaot/Runtime/EHHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/EHHelpers.cpp @@ -619,4 +619,25 @@ FCIMPL0(void, RhpFallbackFailFast) } FCIMPLEND +#ifndef FEATURE_PORTABLE_HELPERS + +// Called by the throw helpers (RhpThrowEx, RhpThrowExact, RhpRethrow and RhpThrowHwEx) to initialize the ExInfo +// in their frame and link it into the ExInfo chain of the thread. Returns the previously active ExInfo. +EXTERN_C ExInfo* FASTCALL RhpPushExInfo(ExInfo* pExInfo, PAL_LIMITED_CONTEXT* pContext, uint32_t kind) +{ + Thread* pThread = ThreadStore::GetCurrentThread(); + ExInfo* pActiveExInfo = pThread->GetCurExInfo(); + + pExInfo->m_pExContext = pContext; + pExInfo->m_exception = nullptr; + pExInfo->m_kind = (ExKind)kind; + pExInfo->m_passNumber = 1; + pExInfo->m_idxCurClause = UINT32_MAX; + pThread->PushExInfo(pExInfo); + + return pActiveExInfo; +} + +#endif // !FEATURE_PORTABLE_HELPERS + #endif // !DACCESS_COMPILE diff --git a/src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp b/src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp index 3b9fddec0d64a2..2641195bd56d60 100644 --- a/src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp +++ b/src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp @@ -32,9 +32,9 @@ #pragma warning(disable:4061) #if !defined(FEATURE_PORTABLE_HELPERS) // @TODO: these are (currently) only implemented in assembly helpers -EXTERN_C CODE_LOCATION ReturnFromUniversalTransitionTailCall; +EXTERN_C CODE_LOCATION ReturnFromInterfaceDispatchSlow; #if defined(TARGET_WINDOWS) && (defined(TARGET_AMD64) || defined(TARGET_ARM64)) -EXTERN_C CODE_LOCATION ReturnFromUniversalTransitionGuardedTailCall; +EXTERN_C CODE_LOCATION ReturnFromInterfaceDispatchSlowGuarded; #endif EXTERN_C CODE_LOCATION CallEHFunclet2; @@ -658,7 +658,7 @@ void StackFrameIterator::InternalInit(Thread * pThreadToWalk, NATIVE_CONTEXT* pC // This codepath is used by the hijack stackwalk. The IP must be in managed code // or in a conservatively reported assembly thunk. - ASSERT(IsValidReturnAddress((void*)pCtx->GetIp())); + ASSERT(IsValidReturnAddress((void*)pCtx->GetIp(), true)); // // control state @@ -1366,70 +1366,81 @@ void StackFrameIterator::UnwindFuncletInvokeThunk() } // For a given target architecture, the layout of this structure must precisely match the -// stack frame layout used by the associated architecture-specific RhpUniversalTransition +// stack frame layout used by the associated architecture-specific RhpInterfaceDispatchSlow // implementation. -struct UniversalTransitionStackFrame +struct InterfaceDispatchSlowStackFrame { // In DAC builds, the "this" pointer refers to an object in the DAC host. #define GET_POINTER_TO_FIELD(_FieldName) \ - (PTR_uintptr_t)PTR_HOST_MEMBER_TADDR(UniversalTransitionStackFrame, this, _FieldName) + (PTR_uintptr_t)PTR_HOST_MEMBER_TADDR(InterfaceDispatchSlowStackFrame, this, _FieldName) #if defined(UNIX_AMD64_ABI) - // Conservative GC reporting must be applied to everything between the base of the - // ReturnBlock and the top of the StackPassedArgs. + // The frame created by PROLOG_WITH_TRANSITION_BLOCK. Conservative GC reporting must be applied to everything + // between the base of the TransitionBlock and the top of the StackPassedArgs. private: - Fp128 m_fpArgRegs[8]; // ChildSP+000 CallerSP-0D0 (0x80 bytes) (xmm0-xmm7) - uintptr_t m_returnBlock[2]; // ChildSP+080 CallerSP-050 (0x10 bytes) - uintptr_t m_intArgRegs[6]; // ChildSP+090 CallerSP-040 (0x30 bytes) (rdi,rsi,rcx,rdx,r8,r9) - uintptr_t m_alignmentPad; // ChildSP+0C0 CallerSP-010 (0x8 bytes) - uintptr_t m_callerRetaddr; // ChildSP+0C8 CallerSP-008 (0x8 bytes) - uintptr_t m_stackPassedArgs[1]; // ChildSP+0D0 CallerSP+000 (unknown size) + Fp128 m_fpArgRegs[8]; // ChildSP+000 CallerSP-0F0 (0x80 bytes) (xmm0-xmm7) + uintptr_t m_alignmentPad; // ChildSP+080 CallerSP-070 (0x8 bytes) + uintptr_t m_intArgRegs[6]; // ChildSP+088 CallerSP-068 (0x30 bytes) (rdi,rsi,rdx,rcx,r8,r9) + uintptr_t m_calleeSavedRegs[6]; // ChildSP+0B8 CallerSP-038 (0x30 bytes) (r12,r13,r14,r15,rbx,rbp) + uintptr_t m_callerRetaddr; // ChildSP+0E8 CallerSP-008 (0x8 bytes) + uintptr_t m_stackPassedArgs[1]; // ChildSP+0F0 CallerSP+000 (unknown size) public: PTR_uintptr_t get_CallerSP() { return GET_POINTER_TO_FIELD(m_stackPassedArgs[0]); } PTR_uintptr_t get_AddressOfPushedCallerIP() { return GET_POINTER_TO_FIELD(m_callerRetaddr); } - PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_returnBlock[0]); } + PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_intArgRegs[0]); } void UnwindNonVolatileRegisters(REGDISPLAY * pRegisterSet) { - // RhpUniversalTransition does not touch any non-volatile state on amd64. - UNREFERENCED_PARAMETER(pRegisterSet); + pRegisterSet->pR12 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[0]); + pRegisterSet->pR13 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[1]); + pRegisterSet->pR14 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[2]); + pRegisterSet->pR15 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[3]); + pRegisterSet->pRbx = GET_POINTER_TO_FIELD(m_calleeSavedRegs[4]); + pRegisterSet->pRbp = GET_POINTER_TO_FIELD(m_calleeSavedRegs[5]); } void UnwindVolatileArgRegisters(REGDISPLAY * pRegisterSet) { pRegisterSet->pRdi = GET_POINTER_TO_FIELD(m_intArgRegs[0]); pRegisterSet->pRsi = GET_POINTER_TO_FIELD(m_intArgRegs[1]); - pRegisterSet->pRcx = GET_POINTER_TO_FIELD(m_intArgRegs[2]); - pRegisterSet->pRdx = GET_POINTER_TO_FIELD(m_intArgRegs[3]); + pRegisterSet->pRdx = GET_POINTER_TO_FIELD(m_intArgRegs[2]); + pRegisterSet->pRcx = GET_POINTER_TO_FIELD(m_intArgRegs[3]); pRegisterSet->pR8 = GET_POINTER_TO_FIELD(m_intArgRegs[4]); pRegisterSet->pR9 = GET_POINTER_TO_FIELD(m_intArgRegs[5]); } #elif defined(TARGET_AMD64) - // Conservative GC reporting must be applied to everything between the base of the - // ReturnBlock and the top of the StackPassedArgs. + // The frame created by PROLOG_WITH_TRANSITION_BLOCK. Conservative GC reporting must be applied to everything + // between the homed argument registers and the top of the StackPassedArgs. private: - uintptr_t m_calleeArgumentHomes[4]; // ChildSP+000 CallerSP-080 (0x20 bytes) - Fp128 m_fpArgRegs[4]; // ChildSP+020 CallerSP-060 (0x40 bytes) (xmm0-xmm3) - uintptr_t m_returnBlock[2]; // ChildSP+060 CallerSP-020 (0x10 bytes) - uintptr_t m_alignmentPad; // ChildSP+070 CallerSP-010 (0x8 bytes) - uintptr_t m_callerRetaddr; // ChildSP+078 CallerSP-008 (0x8 bytes) - uintptr_t m_intArgRegs[4]; // ChildSP+080 CallerSP+000 (0x20 bytes) (rcx,rdx,r8,r9) - uintptr_t m_stackPassedArgs[1]; // ChildSP+0a0 CallerSP+020 (unknown size) + uintptr_t m_calleeArgumentHomes[4]; // ChildSP+000 CallerSP-0B0 (0x20 bytes) + Fp128 m_fpArgRegs[4]; // ChildSP+020 CallerSP-090 (0x40 bytes) (xmm0-xmm3) + uintptr_t m_alignmentPad; // ChildSP+060 CallerSP-050 (0x8 bytes) + uintptr_t m_calleeSavedRegs[8]; // ChildSP+068 CallerSP-048 (0x40 bytes) (rdi,rsi,rbx,rbp,r12-r15) + uintptr_t m_callerRetaddr; // ChildSP+0A8 CallerSP-008 (0x8 bytes) + uintptr_t m_intArgRegs[4]; // ChildSP+0B0 CallerSP+000 (0x20 bytes) (rcx,rdx,r8,r9) + uintptr_t m_stackPassedArgs[1]; // ChildSP+0D0 CallerSP+020 (unknown size) public: PTR_uintptr_t get_CallerSP() { return GET_POINTER_TO_FIELD(m_intArgRegs[0]); } PTR_uintptr_t get_AddressOfPushedCallerIP() { return GET_POINTER_TO_FIELD(m_callerRetaddr); } - PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_returnBlock[0]); } + // The lower bound must be below CallerSP, where the argument registers are homed. + PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_callerRetaddr); } void UnwindNonVolatileRegisters(REGDISPLAY * pRegisterSet) { - // RhpUniversalTransition does not touch any non-volatile state on amd64. - UNREFERENCED_PARAMETER(pRegisterSet); + pRegisterSet->pRdi = GET_POINTER_TO_FIELD(m_calleeSavedRegs[0]); + pRegisterSet->pRsi = GET_POINTER_TO_FIELD(m_calleeSavedRegs[1]); + pRegisterSet->pRbx = GET_POINTER_TO_FIELD(m_calleeSavedRegs[2]); + pRegisterSet->pRbp = GET_POINTER_TO_FIELD(m_calleeSavedRegs[3]); + pRegisterSet->pR12 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[4]); + pRegisterSet->pR13 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[5]); + pRegisterSet->pR14 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[6]); + pRegisterSet->pR15 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[7]); } void UnwindVolatileArgRegisters(REGDISPLAY * pRegisterSet) @@ -1442,24 +1453,31 @@ struct UniversalTransitionStackFrame #elif defined(TARGET_ARM) - // Conservative GC reporting must be applied to everything between the base of the - // ReturnBlock and the top of the StackPassedArgs. + // The frame created by PROLOG_WITH_TRANSITION_BLOCK. Conservative GC reporting must be applied to everything + // between the base of the TransitionBlock and the top of the StackPassedArgs. private: - uintptr_t m_pushedR11; // ChildSP+000 CallerSP-078 (0x4 bytes) (r11) - uintptr_t m_pushedLR; // ChildSP+004 CallerSP-074 (0x4 bytes) (lr) - uint64_t m_fpArgRegs[8]; // ChildSP+008 CallerSP-070 (0x40 bytes) (d0-d7) - uint64_t m_returnBlock[4]; // ChildSP+048 CallerSP-030 (0x20 bytes) + uint64_t m_fpArgRegs[8]; // ChildSP+000 CallerSP-078 (0x40 bytes) (d0-d7) + uintptr_t m_alignmentPad; // ChildSP+040 CallerSP-038 (0x4 bytes) + uintptr_t m_calleeSavedRegs[8]; // ChildSP+044 CallerSP-034 (0x20 bytes) (r4-r11) + uintptr_t m_pushedLR; // ChildSP+064 CallerSP-014 (0x4 bytes) (lr) uintptr_t m_intArgRegs[4]; // ChildSP+068 CallerSP-010 (0x10 bytes) (r0-r3) uintptr_t m_stackPassedArgs[1]; // ChildSP+078 CallerSP+000 (unknown size) public: PTR_uintptr_t get_CallerSP() { return GET_POINTER_TO_FIELD(m_stackPassedArgs[0]); } PTR_uintptr_t get_AddressOfPushedCallerIP() { return GET_POINTER_TO_FIELD(m_pushedLR); } - PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_returnBlock[0]); } + PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_calleeSavedRegs[0]); } void UnwindNonVolatileRegisters(REGDISPLAY * pRegisterSet) { - pRegisterSet->pR11 = GET_POINTER_TO_FIELD(m_pushedR11); + pRegisterSet->pR4 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[0]); + pRegisterSet->pR5 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[1]); + pRegisterSet->pR6 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[2]); + pRegisterSet->pR7 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[3]); + pRegisterSet->pR8 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[4]); + pRegisterSet->pR9 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[5]); + pRegisterSet->pR10 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[6]); + pRegisterSet->pR11 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[7]); } void UnwindVolatileArgRegisters(REGDISPLAY * pRegisterSet) @@ -1475,11 +1493,11 @@ struct UniversalTransitionStackFrame // Conservative GC reporting must be applied to everything between the base of the // IntArgRegs and the top of the StackPassedArgs. private: - uintptr_t m_intArgRegs[2]; // ChildSP+000 CallerSP-018 (0x8 bytes) (edx,ecx) - uintptr_t m_returnBlock[2]; // ChildSP+008 CallerSP-010 (0x8 bytes) - uintptr_t m_pushedEBP; // ChildSP+010 CallerSP-008 (0x4 bytes) - uintptr_t m_callerRetaddr; // ChildSP+014 CallerSP-004 (0x4 bytes) - uintptr_t m_stackPassedArgs[1]; // ChildSP+018 CallerSP+000 (unknown size) + uintptr_t m_intArgRegs[2]; // ChildSP+000 CallerSP-014 (0x8 bytes) (edx,ecx) + uintptr_t m_dispatchCell; // ChildSP+008 CallerSP-00C (0x4 bytes) + uintptr_t m_pushedEBP; // ChildSP+00C CallerSP-008 (0x4 bytes) + uintptr_t m_callerRetaddr; // ChildSP+010 CallerSP-004 (0x4 bytes) + uintptr_t m_stackPassedArgs[1]; // ChildSP+014 CallerSP+000 (unknown size) public: PTR_uintptr_t get_CallerSP() { return GET_POINTER_TO_FIELD(m_stackPassedArgs[0]); } @@ -1499,25 +1517,36 @@ struct UniversalTransitionStackFrame #elif defined(TARGET_ARM64) - // Conservative GC reporting must be applied to everything between the base of the - // ReturnBlock and the top of the StackPassedArgs. + // The frame created by PROLOG_WITH_TRANSITION_BLOCK. Conservative GC reporting must be applied to everything + // between the base of the TransitionBlock and the top of the StackPassedArgs. private: - uintptr_t m_pushedFP; // ChildSP+000 CallerSP-100 (0x08 bytes) (fp) - uintptr_t m_pushedLR; // ChildSP+008 CallerSP-0F8 (0x08 bytes) (lr) - Fp128 m_fpArgRegs[8]; // ChildSP+010 CallerSP-0F0 (0x80 bytes) (q0-q7) - uintptr_t m_returnBlock[4]; // ChildSP+090 CallerSP-070 (0x20 bytes) - uintptr_t m_intArgRegs[9]; // ChildSP+0B0 CallerSP-050 (0x48 bytes) (x0-x8) - uintptr_t m_alignmentPad; // ChildSP+0F8 CallerSP-008 (0x08 bytes) - uintptr_t m_stackPassedArgs[1]; // ChildSP+100 CallerSP+000 (unknown size) + Fp128 m_fpArgRegs[8]; // ChildSP+000 CallerSP-130 (0x80 bytes) (q0-q7) + uintptr_t m_pushedFP; // ChildSP+080 CallerSP-0B0 (0x08 bytes) (fp) + uintptr_t m_pushedLR; // ChildSP+088 CallerSP-0A8 (0x08 bytes) (lr) + uintptr_t m_calleeSavedRegs[10]; // ChildSP+090 CallerSP-0A0 (0x50 bytes) (x19-x28) + uintptr_t m_alignmentPad; // ChildSP+0E0 CallerSP-050 (0x08 bytes) + uintptr_t m_x8; // ChildSP+0E8 CallerSP-048 (0x08 bytes) (x8) + uintptr_t m_intArgRegs[8]; // ChildSP+0F0 CallerSP-040 (0x40 bytes) (x0-x7) + uintptr_t m_stackPassedArgs[1]; // ChildSP+130 CallerSP+000 (unknown size) public: PTR_uintptr_t get_CallerSP() { return GET_POINTER_TO_FIELD(m_stackPassedArgs[0]); } PTR_uintptr_t get_AddressOfPushedCallerIP() { return GET_POINTER_TO_FIELD(m_pushedLR); } - PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_returnBlock[0]); } + PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_pushedFP); } void UnwindNonVolatileRegisters(REGDISPLAY * pRegisterSet) { - pRegisterSet->pFP = GET_POINTER_TO_FIELD(m_pushedFP); + pRegisterSet->pFP = GET_POINTER_TO_FIELD(m_pushedFP); + pRegisterSet->pX19 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[0]); + pRegisterSet->pX20 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[1]); + pRegisterSet->pX21 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[2]); + pRegisterSet->pX22 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[3]); + pRegisterSet->pX23 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[4]); + pRegisterSet->pX24 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[5]); + pRegisterSet->pX25 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[6]); + pRegisterSet->pX26 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[7]); + pRegisterSet->pX27 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[8]); + pRegisterSet->pX28 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[9]); } void UnwindVolatileArgRegisters(REGDISPLAY * pRegisterSet) @@ -1530,29 +1559,39 @@ struct UniversalTransitionStackFrame pRegisterSet->pX5 = GET_POINTER_TO_FIELD(m_intArgRegs[5]); pRegisterSet->pX6 = GET_POINTER_TO_FIELD(m_intArgRegs[6]); pRegisterSet->pX7 = GET_POINTER_TO_FIELD(m_intArgRegs[7]); - pRegisterSet->pX8 = GET_POINTER_TO_FIELD(m_intArgRegs[8]); + pRegisterSet->pX8 = GET_POINTER_TO_FIELD(m_x8); } #elif defined(TARGET_LOONGARCH64) - // Conservative GC reporting must be applied to everything between the base of the - // ReturnBlock and the top of the StackPassedArgs. + // The frame created by PROLOG_WITH_TRANSITION_BLOCK. Conservative GC reporting must be applied to everything + // between the base of the TransitionBlock and the top of the StackPassedArgs. private: - uintptr_t m_pushedFP; // ChildSP+000 CallerSP-0A0 (0x08 bytes) (fp) - uintptr_t m_pushedRA; // ChildSP+008 CallerSP-098 (0x08 bytes) (ra) - uint64_t m_fpArgRegs[8]; // ChildSP+010 CallerSP-090 (0x40 bytes) (fa0-fa7) - uintptr_t m_returnBlock[2]; // ChildSP+050 CallerSP-050 (0x10 bytes) - uintptr_t m_intArgRegs[8]; // ChildSP+060 CallerSP-040 (0x40 bytes) (a0-a7) - uintptr_t m_stackPassedArgs[1]; // ChildSP+0A0 CallerSP+000 (unknown size) + uint64_t m_fpArgRegs[8]; // ChildSP+000 CallerSP-0E0 (0x40 bytes) (fa0-fa7) + uintptr_t m_pushedFP; // ChildSP+040 CallerSP-0A0 (0x08 bytes) (fp) + uintptr_t m_pushedRA; // ChildSP+048 CallerSP-098 (0x08 bytes) (ra) + uintptr_t m_calleeSavedRegs[9]; // ChildSP+050 CallerSP-090 (0x48 bytes) (s0-s8) + uintptr_t m_alignmentPad; // ChildSP+098 CallerSP-048 (0x08 bytes) + uintptr_t m_intArgRegs[8]; // ChildSP+0A0 CallerSP-040 (0x40 bytes) (a0-a7) + uintptr_t m_stackPassedArgs[1]; // ChildSP+0E0 CallerSP+000 (unknown size) public: PTR_uintptr_t get_CallerSP() { return GET_POINTER_TO_FIELD(m_stackPassedArgs[0]); } PTR_uintptr_t get_AddressOfPushedCallerIP() { return GET_POINTER_TO_FIELD(m_pushedRA); } - PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_returnBlock[0]); } + PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_pushedFP); } void UnwindNonVolatileRegisters(REGDISPLAY * pRegisterSet) { - pRegisterSet->pFP = GET_POINTER_TO_FIELD(m_pushedFP); + pRegisterSet->pFP = GET_POINTER_TO_FIELD(m_pushedFP); + pRegisterSet->pR23 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[0]); + pRegisterSet->pR24 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[1]); + pRegisterSet->pR25 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[2]); + pRegisterSet->pR26 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[3]); + pRegisterSet->pR27 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[4]); + pRegisterSet->pR28 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[5]); + pRegisterSet->pR29 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[6]); + pRegisterSet->pR30 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[7]); + pRegisterSet->pR31 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[8]); } void UnwindVolatileArgRegisters(REGDISPLAY * pRegisterSet) @@ -1569,24 +1608,40 @@ struct UniversalTransitionStackFrame #elif defined(TARGET_RISCV64) - // Conservative GC reporting must be applied to everything between the base of the - // ReturnBlock and the top of the StackPassedArgs. + // The frame created by PROLOG_WITH_TRANSITION_BLOCK. Conservative GC reporting must be applied to everything + // between the base of the TransitionBlock and the top of the StackPassedArgs. private: - uintptr_t m_pushedFP; // ChildSP+000 CallerSP-0A0 (0x08 bytes) (fp) - uintptr_t m_pushedRA; // ChildSP+008 CallerSP-098 (0x08 bytes) (ra) - uint64_t m_fpArgRegs[8]; // ChildSP+010 CallerSP-090 (0x40 bytes) (fa0-fa7) - uintptr_t m_returnBlock[2]; // ChildSP+050 CallerSP-050 (0x10 bytes) - uintptr_t m_intArgRegs[8]; // ChildSP+060 CallerSP-040 (0x40 bytes) (a0-a7) - uintptr_t m_stackPassedArgs[1]; // ChildSP+0A0 CallerSP+000 (unknown size) + uint64_t m_fpArgRegs[8]; // ChildSP+000 CallerSP-100 (0x40 bytes) (fa0-fa7) + uintptr_t m_pushedFP; // ChildSP+040 CallerSP-0C0 (0x08 bytes) (fp) + uintptr_t m_pushedRA; // ChildSP+048 CallerSP-0B8 (0x08 bytes) (ra) + uintptr_t m_calleeSavedRegs[11]; // ChildSP+050 CallerSP-0B0 (0x58 bytes) (s1-s11) + uintptr_t m_pushedTP; // ChildSP+0A8 CallerSP-058 (0x08 bytes) (tp) + uintptr_t m_pushedGP; // ChildSP+0B0 CallerSP-050 (0x08 bytes) (gp) + uintptr_t m_alignmentPad; // ChildSP+0B8 CallerSP-048 (0x08 bytes) + uintptr_t m_intArgRegs[8]; // ChildSP+0C0 CallerSP-040 (0x40 bytes) (a0-a7) + uintptr_t m_stackPassedArgs[1]; // ChildSP+100 CallerSP+000 (unknown size) public: PTR_uintptr_t get_CallerSP() { return GET_POINTER_TO_FIELD(m_stackPassedArgs[0]); } PTR_uintptr_t get_AddressOfPushedCallerIP() { return GET_POINTER_TO_FIELD(m_pushedRA); } - PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_returnBlock[0]); } + PTR_uintptr_t get_LowerBoundForConservativeReporting() { return GET_POINTER_TO_FIELD(m_pushedFP); } void UnwindNonVolatileRegisters(REGDISPLAY * pRegisterSet) { - pRegisterSet->pFP = GET_POINTER_TO_FIELD(m_pushedFP); + pRegisterSet->pFP = GET_POINTER_TO_FIELD(m_pushedFP); + pRegisterSet->pS1 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[0]); + pRegisterSet->pS2 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[1]); + pRegisterSet->pS3 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[2]); + pRegisterSet->pS4 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[3]); + pRegisterSet->pS5 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[4]); + pRegisterSet->pS6 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[5]); + pRegisterSet->pS7 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[6]); + pRegisterSet->pS8 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[7]); + pRegisterSet->pS9 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[8]); + pRegisterSet->pS10 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[9]); + pRegisterSet->pS11 = GET_POINTER_TO_FIELD(m_calleeSavedRegs[10]); + pRegisterSet->pTP = GET_POINTER_TO_FIELD(m_pushedTP); + pRegisterSet->pGP = GET_POINTER_TO_FIELD(m_pushedGP); } void UnwindVolatileArgRegisters(REGDISPLAY * pRegisterSet) @@ -1629,7 +1684,7 @@ struct UniversalTransitionStackFrame }; -typedef DPTR(UniversalTransitionStackFrame) PTR_UniversalTransitionStackFrame; +typedef DPTR(InterfaceDispatchSlowStackFrame) PTR_InterfaceDispatchSlowStackFrame; // NOTE: This function always publishes a non-NULL conservative stack range lower bound. // @@ -1637,21 +1692,21 @@ typedef DPTR(UniversalTransitionStackFrame) PTR_UniversalTransitionStackFrame; // of stack-passed argument space to be callee-popped before control returns (or unwinds) to the // callsite. Since the callsite signature (and thus the amount of callee-popped space) is unknown, // the recovered SP does not account for the callee-popped space is therefore "wrong" for the -// purposes of unwind. This implies that any x86 function which calls into RhpUniversalTransition +// purposes of unwind. This implies that any x86 function which calls into RhpInterfaceDispatchSlow // must have a frame pointer to ensure that the incorrect SP value is ignored and does not break the // unwind. -void StackFrameIterator::UnwindUniversalTransitionThunk() +void StackFrameIterator::UnwindInterfaceDispatchSlowThunk() { ASSERT((m_dwFlags & MethodStateCalculated) == 0); #if defined(FEATURE_PORTABLE_HELPERS) // @TODO: Corresponding helper code is only defined in assembly code return; #else // defined(FEATURE_PORTABLE_HELPERS) - ASSERT(CategorizeUnadjustedReturnAddress(m_ControlPC) == InUniversalTransitionThunk); + ASSERT(CategorizeUnadjustedReturnAddress(m_ControlPC) == InInterfaceDispatchSlowThunk); - // The current PC is within RhpUniversalTransition, so establish a view of the surrounding stack frame. + // The current PC is within RhpInterfaceDispatchSlow, so establish a view of the surrounding stack frame. // NOTE: In DAC builds, the pointer will refer to a newly constructed object in the DAC host. - UniversalTransitionStackFrame * stackFrame = (PTR_UniversalTransitionStackFrame)m_RegDisplay.SP; + InterfaceDispatchSlowStackFrame * stackFrame = (PTR_InterfaceDispatchSlowStackFrame)m_RegDisplay.SP; stackFrame->UnwindNonVolatileRegisters(&m_RegDisplay); stackFrame->UnwindVolatileArgRegisters(&m_RegDisplay); @@ -2073,9 +2128,9 @@ void StackFrameIterator::UnwindNonEHThunkSequence() { ASSERT(m_pConservativeStackRangeLowerBound == NULL); - if (category == InUniversalTransitionThunk) + if (category == InInterfaceDispatchSlowThunk) { - UnwindUniversalTransitionThunk(); + UnwindInterfaceDispatchSlowThunk(); ASSERT(m_pConservativeStackRangeLowerBound != NULL); } else @@ -2150,7 +2205,7 @@ void StackFrameIterator::PrepareToYieldFrame() // flowed into a managed callsite which called into the runtime. The runtime has no // knowledge of the callsite signature in these cases, and unwind through these callsites // is only possible via the associated assembly thunk (e.g., the ManagedCalloutThunk or - // UniversalTransitionThunk). + // RhpInterfaceDispatchSlow). // // The iterator is currently positioned on the managed frame which contains the callsite of // interest. The lower bound of the argument set was already computed while unwinding @@ -2292,13 +2347,16 @@ bool StackFrameIterator::IsNonEHThunk(ReturnAddressCategory category) { default: return false; - case InUniversalTransitionThunk: + case InInterfaceDispatchSlowThunk: return true; } } -bool StackFrameIterator::IsValidReturnAddress(PTR_VOID pvAddress) +bool StackFrameIterator::IsValidReturnAddress(PTR_VOID pvAddress, bool isCanonicalPC) { + if (!isCanonicalPC) + pvAddress = dac_cast(ReturnAddressToCanonicalPC(dac_cast(pvAddress))); + // These are return addresses into functions that call into managed (non-funclet) code, so we might see // them as hijacked return addresses. ReturnAddressCategory category = CategorizeUnadjustedReturnAddress(pvAddress); @@ -2369,13 +2427,13 @@ StackFrameIterator::ReturnAddressCategory StackFrameIterator::CategorizeUnadjust return InManagedCode; #else // defined(FEATURE_PORTABLE_HELPERS) - if (EQUALS_RETURN_ADDRESS(returnAddress, ReturnFromUniversalTransitionTailCall) + if (EQUALS_RETURN_ADDRESS(returnAddress, ReturnFromInterfaceDispatchSlow) #if defined(TARGET_WINDOWS) && (defined(TARGET_AMD64) || defined(TARGET_ARM64)) - || EQUALS_RETURN_ADDRESS(returnAddress, ReturnFromUniversalTransitionGuardedTailCall) + || EQUALS_RETURN_ADDRESS(returnAddress, ReturnFromInterfaceDispatchSlowGuarded) #endif ) { - return InUniversalTransitionThunk; + return InInterfaceDispatchSlowThunk; } if (EQUALS_RETURN_ADDRESS(returnAddress, RhpThrowImpl2) || diff --git a/src/coreclr/nativeaot/Runtime/StackFrameIterator.h b/src/coreclr/nativeaot/Runtime/StackFrameIterator.h index 3f124feb7b4455..8651665dddd40b 100644 --- a/src/coreclr/nativeaot/Runtime/StackFrameIterator.h +++ b/src/coreclr/nativeaot/Runtime/StackFrameIterator.h @@ -68,7 +68,7 @@ class StackFrameIterator void SetControlPC(PTR_VOID controlPC); PTR_VOID GetControlPC() { return m_ControlPC; } - static bool IsValidReturnAddress(PTR_VOID pvAddress); + static bool IsValidReturnAddress(PTR_VOID pvAddress, bool isCanonicalPC); // Support for conservatively reporting GC references in a stack range. This is used when managed methods // with an unknown signature potentially including GC references call into the runtime and we need to let @@ -95,7 +95,7 @@ class StackFrameIterator // If our control PC indicates that we're in the universal transition thunk that we use to generically // dispatch arbitrary managed calls, then handle the stack walk specially. // NOTE: This function always publishes a non-NULL conservative stack range lower bound. - void UnwindUniversalTransitionThunk(); + void UnwindInterfaceDispatchSlowThunk(); void EnterInitialInvalidState(Thread * pThreadToWalk); @@ -130,7 +130,7 @@ class StackFrameIterator InThrowSiteThunk, InFuncletInvokeThunk, InFilterFuncletInvokeThunk, - InUniversalTransitionThunk, + InInterfaceDispatchSlowThunk, }; static ReturnAddressCategory CategorizeUnadjustedReturnAddress(PTR_VOID returnAddress); diff --git a/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp b/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp deleted file mode 100644 index aabf45392313ae..00000000000000 --- a/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include "common.h" -#include "CommonTypes.h" -#include "CommonMacros.h" -#include "PalLimitedContext.h" -#include "Pal.h" - -#ifdef _DEBUG -#define TRASH_SAVED_ARGUMENT_REGISTERS -#endif - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - -// -// Define tables of predictable distinguished values that RhpUniversalTransition can use to -// trash argument registers after they have been saved into the transition frame. -// -// Trashing these registers is a testability aid that makes it easier to detect bugs where -// the transition frame content is not correctly propagated to the eventual callee. -// -// In the absence of trashing, such bugs can become undetectable if the code that -// dispatches the call happens to never touch the impacted argument register (e.g., xmm3 on -// amd64 or q5 on arm64). In such a case, the original enregistered argument will flow -// unmodified into the eventual callee, obscuring the fact that the dispatcher failed to -// propagate the transition frame copy of this register. -// -// These tables are manually aligned as a conservative safeguard to ensure that the -// consumers can use arbitrary access widths without ever needing to worry about alignment. -// The comments in each table show the %d/%f renderings of each 32-bit value, plus the -// %I64d/%f rendering of the combined 64-bit value of each aligned pair of 32-bit values. -// - -#define TRASH_VALUE_ALIGNMENT 16 - -EXTERN_C -DECLSPEC_ALIGN(TRASH_VALUE_ALIGNMENT) -const uint32_t RhpIntegerTrashValues[] = { - // Lo32 Hi32 Lo32 Hi32 Hi32:Lo32 - // ----------- ----------- --------- --------- ------------------ - 0x07801001U, 0x07802002U, // (125833217, 125837314) (540467148372316161) - 0x07803003U, 0x07804004U, // (125841411, 125845508) (540502341334347779) - 0x07805005U, 0x07806006U, // (125849605, 125853702) (540537534296379397) - 0x07807007U, 0x07808008U, // (125857799, 125861896) (540572727258411015) - 0x07809009U, 0x0780a00aU, // (125865993, 125870090) (540607920220442633) - 0x0780b00bU, 0x0780c00cU, // (125874187, 125878284) (540643113182474251) - 0x0780d00dU, 0x0780e00eU, // (125882381, 125886478) (540678306144505869) - 0x0780f00fU, 0x07810010U, // (125890575, 125894672) (540713499106537487) -}; - -EXTERN_C -DECLSPEC_ALIGN(TRASH_VALUE_ALIGNMENT) -const uint32_t RhpFpTrashValues[] = { - // Lo32 Hi32 Lo32 Hi32 Hi32:Lo32 - // ----------- ----------- ------------------- ------------------- ------------------- - 0x42001001U, 0x42002002U, // (32.0156288146972660, 32.0312576293945310) (8657061952.00781440) - 0x42003003U, 0x42004004U, // (32.0468864440917970, 32.0625152587890630) (8724187200.02344320) - 0x42005005U, 0x42006006U, // (32.0781440734863280, 32.0937728881835940) (8791312448.03907200) - 0x42007007U, 0x42008008U, // (32.1094017028808590, 32.1250305175781250) (8858437696.05470090) - 0x42009009U, 0x4200a00aU, // (32.1406593322753910, 32.1562881469726560) (8925562944.07032970) - 0x4200b00bU, 0x4200c00cU, // (32.1719169616699220, 32.1875457763671880) (8992688192.08595850) - 0x4200d00dU, 0x4200e00eU, // (32.2031745910644530, 32.2188034057617190) (9059813440.10158730) - 0x4200f00fU, 0x42010010U, // (32.2344322204589840, 32.2500610351562500) (9126938688.11721610) -}; - -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - diff --git a/src/coreclr/nativeaot/Runtime/amd64/AsmMacros.inc b/src/coreclr/nativeaot/Runtime/amd64/AsmMacros.inc index 8427928cddb273..8066e3a9a4d621 100644 --- a/src/coreclr/nativeaot/Runtime/amd64/AsmMacros.inc +++ b/src/coreclr/nativeaot/Runtime/amd64/AsmMacros.inc @@ -141,6 +141,7 @@ EXTERN RhExceptionHandling_FailedAllocation : PROC EXTERN RhThrowHwEx : PROC EXTERN RhThrowEx : PROC EXTERN RhRethrow : PROC +EXTERN RhpPushExInfo : PROC EXTERN RhpGcPoll2 : PROC EXTERN RhpTrapThreads : DWORD diff --git a/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.S b/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.S index 0f4d768c5b48fc..540e9c65ab558e 100644 --- a/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.S +++ b/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.S @@ -114,7 +114,7 @@ LOCAL_LABEL(ProbeMiss\@): LOCAL_LABEL(CacheMiss\@): .if \ReturnTarget - jmp C_FUNC(RhpCidResolve_Worker) + jmp C_FUNC(RhpCidResolve) .else mov r9, [rsp - 32] mov r8, [rsp - 24] @@ -122,8 +122,7 @@ LOCAL_LABEL(CacheMiss\@): mov rcx, [rsp - 8] // DispatchCellReg contains indirection cell address - lea r10, [C_VAR(RhpCidResolve)] - jmp C_FUNC(RhpUniversalTransitionTailCall) + jmp C_FUNC(RhpInterfaceDispatchSlow) .endif LEAF_END \DispatchName, _TEXT @@ -132,3 +131,20 @@ LEAF_END \DispatchName, _TEXT INTERFACE_DISPATCH RhpInterfaceDispatch, 0, r11 INTERFACE_DISPATCH RhpDispatchResolve, 1, rsi + +// r11: interface dispatch cell, arguments passed in registers and stack space as normal +NESTED_ENTRY RhpInterfaceDispatchSlow, _TEXT, NoHandler + + // NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout + PROLOG_WITH_TRANSITION_BLOCK + + // rdi still contains 'this' + mov rsi, r11 + call C_FUNC(RhpCidResolve) + +ALTERNATE_ENTRY ReturnFromInterfaceDispatchSlow + + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + TAILJMP_RAX + +NESTED_END RhpInterfaceDispatchSlow, _TEXT diff --git a/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.asm b/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.asm index 722e67b3e2b128..e8c61240278497 100644 --- a/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.asm +++ b/src/coreclr/nativeaot/Runtime/amd64/DispatchResolve.asm @@ -5,13 +5,11 @@ include AsmMacros.inc EXTERN RhpCidResolve : PROC -EXTERN RhpCidResolve_Worker : PROC -EXTERN RhpUniversalTransitionTailCall : PROC -EXTERN RhpUniversalTransitionGuardedTailCall : PROC EXTERN g_pDispatchCache : QWORD EXTERN __guard_dispatch_icall_fptr : QWORD +EXTERN __guard_check_icall_fptr : QWORD ;; Macro that generates an interface dispatch or dispatch resolve stub. ;; DispatchName: the name of the dispatch entry point @@ -144,7 +142,7 @@ endif if ReturnTarget ne 0 mov rcx, [rsp + 8h] mov rdx, DispatchCellReg - jmp RhpCidResolve_Worker + jmp RhpCidResolve else mov r9, [rsp + 20h] mov r8, [rsp + 18h] @@ -153,11 +151,10 @@ else SlowPath: ;; DispatchCellReg contains indirection cell address - lea r10, RhpCidResolve if Guarded ne 0 - jmp RhpUniversalTransitionGuardedTailCall + jmp RhpInterfaceDispatchSlowGuarded else - jmp RhpUniversalTransitionTailCall + jmp RhpInterfaceDispatchSlow endif endif @@ -169,4 +166,38 @@ LEAF_END DispatchName, _TEXT INTERFACE_DISPATCH RhpInterfaceDispatchGuarded, 1, 0, r11, edx INTERFACE_DISPATCH RhpDispatchResolve, 0, 1, rdx, r11d +;; Macro that generates slow path for an interface dispatch. +;; FunctionName: the name of the dispatch entry point +;; Guarded: if non-zero, validate indirect call targets using Control Flow Guard +INTERFACE_DISPATCH_SLOW macro FunctionName, Guarded + +;; r11: interface dispatch cell, arguments passed in registers and stack space as normal +NESTED_ENTRY Rhp&FunctionName, _TEXT + + ;; NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout + PROLOG_WITH_TRANSITION_BLOCK + + ;; rcx still contains 'this' + mov rdx, r11 + call RhpCidResolve + +ALTERNATE_ENTRY ReturnFrom&FunctionName + +if Guarded ne 0 + ;; The validator takes the target in rcx and preserves rcx, r10, and all float registers. + mov rcx, rax + call [__guard_check_icall_fptr] + mov rax, rcx +endif + + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + TAILJMP_RAX + +NESTED_END Rhp&FunctionName, _TEXT + + endm + + INTERFACE_DISPATCH_SLOW InterfaceDispatchSlow, 0 + INTERFACE_DISPATCH_SLOW InterfaceDispatchSlowGuarded, 1 + end diff --git a/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S index 5166d17801e32a..d0a491b07dcb61 100644 --- a/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S @@ -44,29 +44,15 @@ NESTED_ENTRY RhpThrowHwEx, _TEXT, NoHandler END_PROLOGUE - mov rbx, rdi - INLINE_GETTHREAD - mov rdi, rbx + mov ebx, edi // ebx <- exception code - mov rsi, rsp // rsi <- ExInfo* + mov rdi, rsp // rdi <- ExInfo* + lea rsi, [rsp + rsp_offsetof_Context] // rsi <- PAL_LIMITED_CONTEXT* + mov edx, 2 // edx <- ExKind.HardwareFault + call C_FUNC(RhpPushExInfo) - xor rdx, rdx - mov [rsi + OFFSETOF__ExInfo__m_exception], rdx // init the exception object to null - mov byte ptr [rsi + OFFSETOF__ExInfo__m_passNumber], 1 // init to the first pass - mov dword ptr [rsi + OFFSETOF__ExInfo__m_idxCurClause], 0xFFFFFFFF - mov byte ptr [rsi + OFFSETOF__ExInfo__m_kind], 2 // ExKind.HardwareFault - - // link the ExInfo into the thread's ExInfo chain - mov rdx, [rax + OFFSETOF__Thread__m_pExInfoStackHead] - mov [rsi + OFFSETOF__ExInfo__m_pPrevExInfo], rdx // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [rax + OFFSETOF__Thread__m_pExInfoStackHead], rsi // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - lea rdx, [rsp + rsp_offsetof_Context] // rdx <- PAL_LIMITED_CONTEXT* - mov [rsi + OFFSETOF__ExInfo__m_pExContext], rdx // init ExInfo.m_pExContext - - // rdi still contains the exception code - // rsi contains the address of the ExInfo + mov edi, ebx // edi <- exception code + mov rsi, rsp // rsi <- ExInfo* call EXTERNAL_C_FUNC(RhThrowHwEx) ALTERNATE_ENTRY RhpThrowHwEx2 @@ -141,39 +127,15 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler END_PROLOGUE - mov rbx, rdi - mov r12, r8 // Save ExKind - INLINE_GETTHREAD - mov rdi, rbx - - lea rbx, [rsp + rsp_offsetof_Context + SIZEOF__PAL_LIMITED_CONTEXT + 0x8] // rbx <- addr of return address + mov rbx, rdi // rbx <- exception object - // There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return - // address could have been hijacked when we were in that C# code and we must remove the hijack and - // reflect the correct return address in our exception context record. The other throw helpers don't - // need this because they cannot be tail-called from C#. - INLINE_THREAD_UNHIJACK rax, rcx, rsi // trashes RCX, RSI - mov rsi, [rbx] // rdx <- return address - mov [rsp + rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP], rsi // set 'faulting' IP after unhijack + mov rdi, rsp // rdi <- ExInfo* + lea rsi, [rsp + rsp_offsetof_Context] // rsi <- PAL_LIMITED_CONTEXT* + mov edx, r8d // edx <- ExKind + call C_FUNC(RhpPushExInfo) + mov rdi, rbx // rdi <- exception object mov rsi, rsp // rsi <- ExInfo* - - mov [rsi + OFFSETOF__ExInfo__m_exception], rdx // init the exception object to null - mov byte ptr [rsi + OFFSETOF__ExInfo__m_passNumber], 1 // init to the first pass - mov dword ptr [rsi + OFFSETOF__ExInfo__m_idxCurClause], 0xFFFFFFFF - mov byte ptr [rsi + OFFSETOF__ExInfo__m_kind], r12b // ExKind - - // link the ExInfo into the thread's ExInfo chain - mov rdx, [rax + OFFSETOF__Thread__m_pExInfoStackHead] - mov [rsi + OFFSETOF__ExInfo__m_pPrevExInfo], rdx // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [rax + OFFSETOF__Thread__m_pExInfoStackHead], rsi // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - lea rdx, [rsp + rsp_offsetof_Context] // rdx <- PAL_LIMITED_CONTEXT* - mov [rsi + OFFSETOF__ExInfo__m_pExContext], rdx // init ExInfo.m_pExContext - - // rdi still contains the exception object - // rsi contains the address of the ExInfo call EXTERNAL_C_FUNC(RhThrowEx) ALTERNATE_ENTRY RhpThrowImpl2 @@ -224,27 +186,13 @@ NESTED_ENTRY RhpRethrow, _TEXT, NoHandler END_PROLOGUE - INLINE_GETTHREAD + mov rdi, rsp // rdi <- ExInfo* + lea rsi, [rsp + rsp_offsetof_Context] // rsi <- PAL_LIMITED_CONTEXT* + xor edx, edx // edx <- ExKind.None + call C_FUNC(RhpPushExInfo) + mov rdi, rax // rdi <- currently active ExInfo mov rsi, rsp // rsi <- ExInfo* - - mov [rsi + OFFSETOF__ExInfo__m_exception], rdx // init the exception object to null - mov byte ptr [rsi + OFFSETOF__ExInfo__m_passNumber], 1 // init to the first pass - mov dword ptr [rsi + OFFSETOF__ExInfo__m_idxCurClause], 0xFFFFFFFF - mov byte ptr [rsi + OFFSETOF__ExInfo__m_kind], 0 // init to a deterministic value (ExKind.None) - - - // link the ExInfo into the thread's ExInfo chain - mov rdi, [rax + OFFSETOF__Thread__m_pExInfoStackHead] // rdi <- currently active ExInfo - mov [rsi + OFFSETOF__ExInfo__m_pPrevExInfo], rdi // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [rax + OFFSETOF__Thread__m_pExInfoStackHead], rsi // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - lea rdx, [rsp + rsp_offsetof_Context] // rdx <- PAL_LIMITED_CONTEXT* - mov [rsi + OFFSETOF__ExInfo__m_pExContext], rdx // init ExInfo.m_pExContext - - // rdi contains the currently active ExInfo - // rsi contains the address of the new ExInfo call EXTERNAL_C_FUNC(RhRethrow) ALTERNATE_ENTRY RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.asm b/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.asm index 59d1f8b7b1c8f4..a635ade026bc5e 100644 --- a/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.asm +++ b/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.asm @@ -75,27 +75,15 @@ ALTERNATE_ENTRY RhpThrowHwExGEHCONT ; this needs to be an EHCONT target since we END_PROLOGUE - INLINE_GETTHREAD rax, rbx ;; rax <- Thread*, rbx is trashed + mov ebx, ecx ;; ebx <- exception code - lea rdx, [rsp + rsp_offsetof_ExInfo] ;; rdx <- ExInfo* + lea rcx, [rsp + rsp_offsetof_ExInfo] ;; rcx <- ExInfo* + lea rdx, [rsp + rsp_offsetof_Context] ;; rdx <- PAL_LIMITED_CONTEXT* + mov r8d, 2 ;; r8d <- ExKind.HardwareFault + call RhpPushExInfo - xor r8, r8 - mov [rdx + OFFSETOF__ExInfo__m_exception], r8 ;; init the exception object to null - mov byte ptr [rdx + OFFSETOF__ExInfo__m_passNumber], 1 ;; init to the first pass - mov dword ptr [rdx + OFFSETOF__ExInfo__m_idxCurClause], 0FFFFFFFFh - mov byte ptr [rdx + OFFSETOF__ExInfo__m_kind], 2 ;; ExKind.HardwareFault - - ;; link the ExInfo into the thread's ExInfo chain - mov r8, [rax + OFFSETOF__Thread__m_pExInfoStackHead] - mov [rdx + OFFSETOF__ExInfo__m_pPrevExInfo], r8 ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [rax + OFFSETOF__Thread__m_pExInfoStackHead], rdx ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - lea r8, [rsp + rsp_offsetof_Context] ;; r8 <- PAL_LIMITED_CONTEXT* - mov [rdx + OFFSETOF__ExInfo__m_pExContext], r8 ;; init ExInfo.m_pExContext - - ;; rcx still contains the exception code - ;; rdx contains the address of the ExInfo + mov ecx, ebx ;; ecx <- exception code + lea rdx, [rsp + rsp_offsetof_ExInfo] ;; rdx <- ExInfo* call RhThrowHwEx ALTERNATE_ENTRY RhpThrowHwEx2 @@ -189,36 +177,15 @@ NESTED_ENTRY RhpThrowImpl, _TEXT END_PROLOGUE - INLINE_GETTHREAD rax, rbx ;; rax <- Thread*, rbx is trashed - - lea rbx, [rsp + rsp_offsetof_Context + SIZEOF__PAL_LIMITED_CONTEXT + 8h] ;; rbx <- addr of return address + mov rbx, rcx ;; rbx <- exception object - ;; There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return - ;; address could have been hijacked when we were in that C# code and we must remove the hijack and - ;; reflect the correct return address in our exception context record. The other throw helpers don't - ;; need this because they cannot be tail-called from C#. - INLINE_THREAD_UNHIJACK rax, r10, rdx ;; trashes R10, RDX - mov rdx, [rbx] ;; rdx <- return address - mov [rsp + rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP], rdx ;; set 'faulting' IP after unhijack + lea rcx, [rsp + rsp_offsetof_ExInfo] ;; rcx <- ExInfo* + lea rdx, [rsp + rsp_offsetof_Context] ;; rdx <- PAL_LIMITED_CONTEXT* + mov r8d, r9d ;; r8d <- ExKind + call RhpPushExInfo + mov rcx, rbx ;; rcx <- exception object lea rdx, [rsp + rsp_offsetof_ExInfo] ;; rdx <- ExInfo* - - mov [rdx + OFFSETOF__ExInfo__m_exception], r8 ;; init the exception object to null - mov byte ptr [rdx + OFFSETOF__ExInfo__m_passNumber], 1 ;; init to the first pass - mov dword ptr [rdx + OFFSETOF__ExInfo__m_idxCurClause], 0FFFFFFFFh - mov byte ptr [rdx + OFFSETOF__ExInfo__m_kind], r9b ;; ExKind (from r9b) - - ;; link the ExInfo into the thread's ExInfo chain - mov r8, [rax + OFFSETOF__Thread__m_pExInfoStackHead] - mov [rdx + OFFSETOF__ExInfo__m_pPrevExInfo], r8 ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [rax + OFFSETOF__Thread__m_pExInfoStackHead], rdx ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - lea r8, [rsp + rsp_offsetof_Context] ;; r8 <- PAL_LIMITED_CONTEXT* - mov [rdx + OFFSETOF__ExInfo__m_pExContext], r8 ;; init ExInfo.m_pExContext - - ;; rcx still contains the exception object - ;; rdx contains the address of the ExInfo call RhThrowEx ALTERNATE_ENTRY RhpThrowImpl2 @@ -289,27 +256,13 @@ NESTED_ENTRY RhpRethrow, _TEXT END_PROLOGUE - INLINE_GETTHREAD rax, rbx ;; rax <- Thread*, rbx is trashed + lea rcx, [rsp + rsp_offsetof_ExInfo] ;; rcx <- ExInfo* + lea rdx, [rsp + rsp_offsetof_Context] ;; rdx <- PAL_LIMITED_CONTEXT* + xor r8d, r8d ;; r8d <- ExKind.None + call RhpPushExInfo + mov rcx, rax ;; rcx <- currently active ExInfo lea rdx, [rsp + rsp_offsetof_ExInfo] ;; rdx <- ExInfo* - - mov [rdx + OFFSETOF__ExInfo__m_exception], r8 ;; init the exception object to null - mov byte ptr [rdx + OFFSETOF__ExInfo__m_passNumber], 1 ;; init to the first pass - mov dword ptr [rdx + OFFSETOF__ExInfo__m_idxCurClause], 0FFFFFFFFh - mov byte ptr [rdx + OFFSETOF__ExInfo__m_kind], 0 ;; init to a deterministic value (ExKind.None) - - - ;; link the ExInfo into the thread's ExInfo chain - mov rcx, [rax + OFFSETOF__Thread__m_pExInfoStackHead] ;; rcx <- currently active ExInfo - mov [rdx + OFFSETOF__ExInfo__m_pPrevExInfo], rcx ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [rax + OFFSETOF__Thread__m_pExInfoStackHead], rdx ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - lea r8, [rsp + rsp_offsetof_Context] ;; r8 <- PAL_LIMITED_CONTEXT* - mov [rdx + OFFSETOF__ExInfo__m_pExContext], r8 ;; init ExInfo.m_pExContext - - ;; rcx contains the currently active ExInfo - ;; rdx contains the address of the new ExInfo call RhRethrow ALTERNATE_ENTRY RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.S b/src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.S deleted file mode 100644 index f4d9de929f50b8..00000000000000 --- a/src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.S +++ /dev/null @@ -1,156 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -.intel_syntax noprefix -#include - -#ifdef _DEBUG -#define TRASH_SAVED_ARGUMENT_REGISTERS 1 -#endif - -#define SIZEOF_RETADDR 8 - -#define SIZEOF_RETURN_BLOCK 0x10 // for 16 bytes of conservatively reported space that the callee can - // use to manage the return value that the call eventually generates - -#define SIZEOF_ARGUMENT_REGISTERS 0x30 // Callee register spill - -#define SIZEOF_FP_REGS 0x80 // xmm0-7 - -// -// From CallerSP to ChildSP, the stack frame is composed of the following adjacent regions: -// -// SIZEOF_RETADDR -// SIZEOF_ARGUMENT_REGISTERS -// SIZEOF_RETURN_BLOCK -// SIZEOF_FP_REGS -// - -#define DISTANCE_FROM_CHILDSP_TO_FP_REGS 0 - -#define DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK SIZEOF_FP_REGS - -#define DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS (SIZEOF_FP_REGS + SIZEOF_RETURN_BLOCK) - -#define DISTANCE_FROM_CHILDSP_TO_RETADDR (SIZEOF_FP_REGS + SIZEOF_RETURN_BLOCK + SIZEOF_ARGUMENT_REGISTERS + 8) - -// -// Defines an assembly thunk used to make a transition from managed code to a callee, -// then (based on the return value from the callee), either returning or jumping to -// a new location while preserving the input arguments. The usage of this thunk also -// ensures arguments passed are properly reported. -// -// TODO: This code currently only tailcalls, and does not return. -// -// Inputs: -// rdi, esi, rcx, rdx, r8, r9, stack space: arguments as normal -// r10: The location of the target code the UniversalTransition thunk will call -// r11: The only parameter to the target function (passed in rdx to callee) -// - -// -// Frame layout is: -// -// {StackPassedArgs} ChildSP+0D0 CallerSP+000 -// {CallerRetaddr} ChildSP+0C8 CallerSP-008 -// {AlignmentPad (0x8 bytes)} ChildSP+0C0 CallerSP-010 -// {IntArgRegs (0x30 bytes)} ChildSP+090 CallerSP-040 -// {ReturnBlock (0x10 bytes)} ChildSP+080 CallerSP-050 -// {FpArgRegs (xmm0-xmm7) (0x80 bytes)} ChildSP+000 CallerSP-0D0 -// {CalleeRetaddr} ChildSP-008 CallerSP-0D8 -// -// NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -// must be updated as well. -// -// NOTE: The callee receives a pointer to the base of the ReturnBlock, and the callee has -// knowledge of the exact layout of all pieces of the frame that lie at or above the pushed -// FpArgRegs. -// -// NOTE: The stack walker guarantees that conservative GC reporting will be applied to -// everything between the base of the ReturnBlock and the top of the StackPassedArgs. -// - -.macro UNIVERSAL_TRANSITION FunctionName - -NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler - - alloc_stack DISTANCE_FROM_CHILDSP_TO_RETADDR - - // save integer argument registers - mov [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x00], rdi - mov [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x08], rsi - mov [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x10], rcx - mov [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x18], rdx - mov [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x20], r8 - mov [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x28], r9 - - // save fp argument registers - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x00], xmm0 - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x10], xmm1 - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x20], xmm2 - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x30], xmm3 - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x40], xmm4 - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x50], xmm5 - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x60], xmm6 - movdqa [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x70], xmm7 - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - - // Before calling out, trash all of the argument registers except the ones (rdi, rsi) that - // hold outgoing arguments. All of these registers have been saved to the transition - // frame, and the code at the call target is required to use only the transition frame - // copies when dispatching this call to the eventual callee. - - movsd xmm0, [C_VAR(RhpFpTrashValues) + 0x0] - movsd xmm1, [C_VAR(RhpFpTrashValues) + 0x8] - movsd xmm2, [C_VAR(RhpFpTrashValues) + 0x10] - movsd xmm3, [C_VAR(RhpFpTrashValues) + 0x18] - movsd xmm4, [C_VAR(RhpFpTrashValues) + 0x20] - movsd xmm5, [C_VAR(RhpFpTrashValues) + 0x28] - movsd xmm6, [C_VAR(RhpFpTrashValues) + 0x30] - movsd xmm7, [C_VAR(RhpFpTrashValues) + 0x38] - - mov rcx, qword ptr [C_VAR(RhpIntegerTrashValues) + 0x10] - mov rdx, qword ptr [C_VAR(RhpIntegerTrashValues) + 0x18] - mov r8, qword ptr [C_VAR(RhpIntegerTrashValues) + 0x20] - mov r9, qword ptr [C_VAR(RhpIntegerTrashValues) + 0x28] - -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - - // - // Call out to the target, while storing and reporting arguments to the GC. - // - mov rsi, r11 - lea rdi, [rsp + DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK] - call r10 - -ALTERNATE_ENTRY ReturnFrom\FunctionName - - // restore fp argument registers - movdqa xmm0, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x00] - movdqa xmm1, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x10] - movdqa xmm2, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x20] - movdqa xmm3, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x30] - movdqa xmm4, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x40] - movdqa xmm5, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x50] - movdqa xmm6, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x60] - movdqa xmm7, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x70] - - // restore integer argument registers - mov rdi, [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x00] - mov rsi, [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x08] - mov rcx, [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x10] - mov rdx, [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x18] - mov r8, [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x20] - mov r9, [rsp + DISTANCE_FROM_CHILDSP_TO_ARGUMENT_REGISTERS + 0x28] - - // Pop the space that was allocated between the ChildSP and the caller return address. - free_stack DISTANCE_FROM_CHILDSP_TO_RETADDR - - jmp rax - -NESTED_END Rhp\FunctionName, _TEXT - -.endm // UNIVERSAL_TRANSITION - - UNIVERSAL_TRANSITION UniversalTransitionTailCall diff --git a/src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.asm b/src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.asm deleted file mode 100644 index 5bee48744ca349..00000000000000 --- a/src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.asm +++ /dev/null @@ -1,166 +0,0 @@ -;; Licensed to the .NET Foundation under one or more agreements. -;; The .NET Foundation licenses this file to you under the MIT license. - -include AsmMacros.inc - -ifdef _DEBUG -TRASH_SAVED_ARGUMENT_REGISTERS equ 1 -else -TRASH_SAVED_ARGUMENT_REGISTERS equ 0 -endif - -if TRASH_SAVED_ARGUMENT_REGISTERS ne 0 -EXTERN RhpIntegerTrashValues : QWORD -EXTERN RhpFpTrashValues : QWORD -endif ;; TRASH_SAVED_ARGUMENT_REGISTERS - -SIZEOF_RETADDR equ 8h - -SIZEOF_ALIGNMENT_PADDING equ 8h - -SIZEOF_RETURN_BLOCK equ 10h ; for 16 bytes of conservatively reported space that the callee can - ; use to manage the return value that the call eventually generates - -SIZEOF_FP_REGS equ 40h ; xmm0-3 - -SIZEOF_OUT_REG_HOMES equ 20h ; Callee register spill - -; -; From CallerSP to ChildSP, the stack frame is composed of the following adjacent regions: -; -; SIZEOF_RETADDR -; SIZEOF_ALIGNMENT_PADDING -; SIZEOF_RETURN_BLOCK -; SIZEOF_FP_REGS -; SIZEOF_OUT_REG_HOMES -; - -DISTANCE_FROM_CHILDSP_TO_FP_REGS equ SIZEOF_OUT_REG_HOMES - -DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK equ DISTANCE_FROM_CHILDSP_TO_FP_REGS + SIZEOF_FP_REGS - -DISTANCE_FROM_CHILDSP_TO_RETADDR equ DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK + SIZEOF_RETURN_BLOCK + SIZEOF_ALIGNMENT_PADDING - -DISTANCE_FROM_CHILDSP_TO_CALLERSP equ DISTANCE_FROM_CHILDSP_TO_RETADDR + SIZEOF_RETADDR - -.errnz DISTANCE_FROM_CHILDSP_TO_CALLERSP mod 16 - -;; -;; Defines an assembly thunk used to make a transition from managed code to a callee, -;; then (based on the return value from the callee), either returning or jumping to -;; a new location while preserving the input arguments. The usage of this thunk also -;; ensures arguments passed are properly reported. -;; -;; TODO: This code currently only tailcalls, and does not return. -;; -;; Inputs: -;; rcx, rdx, r8, r9, stack space: arguments as normal -;; r10: The location of the target code the UniversalTransition thunk will call -;; r11: The only parameter to the target function (passed in rdx to callee) -;; - -; -; Frame layout is: -; -; {StackPassedArgs} ChildSP+0a0 CallerSP+020 -; {IntArgRegs (rcx,rdx,r8,r9) (0x20 bytes)} ChildSP+080 CallerSP+000 -; {CallerRetaddr} ChildSP+078 CallerSP-008 -; {AlignmentPad (0x8 bytes)} ChildSP+070 CallerSP-010 -; {ReturnBlock (0x10 bytes)} ChildSP+060 CallerSP-020 -; {FpArgRegs (xmm0-xmm3) (0x40 bytes)} ChildSP+020 CallerSP-060 -; {CalleeArgumentHomes (0x20 bytes)} ChildSP+000 CallerSP-080 -; {CalleeRetaddr} ChildSP-008 CallerSP-088 -; -; NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -; must be updated as well. -; -; NOTE: The callee receives a pointer to the base of the ReturnBlock, and the callee has -; knowledge of the exact layout of all pieces of the frame that lie at or above the pushed -; FpArgRegs. -; -; NOTE: The stack walker guarantees that conservative GC reporting will be applied to -; everything between the base of the ReturnBlock and the top of the StackPassedArgs. -; - -EXTERN __guard_check_icall_fptr : QWORD - -UNIVERSAL_TRANSITION macro FunctionName, ValidateTarget - -NESTED_ENTRY Rhp&FunctionName, _TEXT - - alloc_stack DISTANCE_FROM_CHILDSP_TO_RETADDR - - save_reg_postrsp rcx, 0h + DISTANCE_FROM_CHILDSP_TO_CALLERSP - save_reg_postrsp rdx, 8h + DISTANCE_FROM_CHILDSP_TO_CALLERSP - save_reg_postrsp r8, 10h + DISTANCE_FROM_CHILDSP_TO_CALLERSP - save_reg_postrsp r9, 18h + DISTANCE_FROM_CHILDSP_TO_CALLERSP - - save_xmm128_postrsp xmm0, DISTANCE_FROM_CHILDSP_TO_FP_REGS - save_xmm128_postrsp xmm1, DISTANCE_FROM_CHILDSP_TO_FP_REGS + 10h - save_xmm128_postrsp xmm2, DISTANCE_FROM_CHILDSP_TO_FP_REGS + 20h - save_xmm128_postrsp xmm3, DISTANCE_FROM_CHILDSP_TO_FP_REGS + 30h - - END_PROLOGUE - -if TRASH_SAVED_ARGUMENT_REGISTERS ne 0 - - ; Before calling out, trash all of the argument registers except the ones (rcx, rdx) that - ; hold outgoing arguments. All of these registers have been saved to the transition - ; frame, and the code at the call target is required to use only the transition frame - ; copies when dispatching this call to the eventual callee. - - movsd xmm0, mmword ptr [RhpFpTrashValues + 0h] - movsd xmm1, mmword ptr [RhpFpTrashValues + 8h] - movsd xmm2, mmword ptr [RhpFpTrashValues + 10h] - movsd xmm3, mmword ptr [RhpFpTrashValues + 18h] - - mov r8, qword ptr [RhpIntegerTrashValues + 10h] - mov r9, qword ptr [RhpIntegerTrashValues + 18h] - -endif ; TRASH_SAVED_ARGUMENT_REGISTERS - - ; - ; Call out to the target, while storing and reporting arguments to the GC. - ; - mov rdx, r11 - lea rcx, [rsp + DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK] - call r10 - -ALTERNATE_ENTRY ReturnFrom&FunctionName - -if ValidateTarget ne 0 - ; Validate the target address using Control Flow Guard before tail-calling it. - ; The validator takes the target in rcx and preserves rcx, r10, and all float registers. - mov rcx, rax - call [__guard_check_icall_fptr] - mov rax, rcx -endif ; ValidateTarget - - ; restore fp argument registers - movdqa xmm0, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS ] - movdqa xmm1, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 10h] - movdqa xmm2, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 20h] - movdqa xmm3, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 30h] - - ; restore integer argument registers - mov rcx, [rsp + 0h + DISTANCE_FROM_CHILDSP_TO_CALLERSP] - mov rdx, [rsp + 8h + DISTANCE_FROM_CHILDSP_TO_CALLERSP] - mov r8, [rsp + 10h + DISTANCE_FROM_CHILDSP_TO_CALLERSP] - mov r9, [rsp + 18h + DISTANCE_FROM_CHILDSP_TO_CALLERSP] - - ; epilog - nop - - ; Pop the space that was allocated between the ChildSP and the caller return address. - add rsp, DISTANCE_FROM_CHILDSP_TO_RETADDR - - TAILJMP_RAX - -NESTED_END Rhp&FunctionName, _TEXT - - endm - - UNIVERSAL_TRANSITION UniversalTransitionTailCall, 0 - UNIVERSAL_TRANSITION UniversalTransitionGuardedTailCall, 1 - -end diff --git a/src/coreclr/nativeaot/Runtime/arm/DispatchResolve.S b/src/coreclr/nativeaot/Runtime/arm/DispatchResolve.S index d64a9ac06a8e09..d907ea70e5dc20 100644 --- a/src/coreclr/nativeaot/Runtime/arm/DispatchResolve.S +++ b/src/coreclr/nativeaot/Runtime/arm/DispatchResolve.S @@ -114,14 +114,8 @@ LOCAL_LABEL(CacheMiss): EPILOG_POP "{r3,r4,r5,r6,r8}" EPILOG_POP "{r1,r2}" - // Push args for RhpUniversalTransitionTailCall: - // [sp+0] = extra arg (indirection cell), [sp+4] = target fn (RhpCidResolve) - PROLOG_STACK_ALLOC 8 - str r12, [sp, #0] - PREPARE_EXTERNAL_VAR RhpCidResolve, r12 - str r12, [sp, #4] - - b C_FUNC(RhpUniversalTransitionTailCall) + // r12 contains the indirection cell address + b C_FUNC(RhpInterfaceDispatchSlow) NESTED_END RhpInterfaceDispatch, _TEXT @@ -148,3 +142,27 @@ LOCAL_LABEL(ResolveInterfaceMethod): b C_FUNC(RhpResolveInterfaceMethod) LEAF_END RhpDispatchResolve, _TEXT + +// r12: interface dispatch cell, arguments passed in registers and stack space as normal +NESTED_ENTRY RhpInterfaceDispatchSlow, _TEXT, NoHandler + + // NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout + PROLOG_WITH_TRANSITION_BLOCK + + // r0 still contains 'this' + mov r1, r12 + + // Make the ReturnFromInterfaceDispatchSlow label 4 byte aligned + .balign 4 + bl C_FUNC(RhpCidResolve) + +GLOBAL_LABEL ReturnFromInterfaceDispatchSlow + + // Move the result (the target address) to r12 so it doesn't get overridden when we restore the + // argument registers. Additionally make sure the thumb2 bit is set. + orr r12, r0, #1 + + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + EPILOG_BRANCH_REG r12 + +NESTED_END RhpInterfaceDispatchSlow, _TEXT diff --git a/src/coreclr/nativeaot/Runtime/arm/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/arm/ExceptionHandling.S index b20377007568fc..47bc4acdb491a6 100644 --- a/src/coreclr/nativeaot/Runtime/arm/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/arm/ExceptionHandling.S @@ -42,32 +42,13 @@ NESTED_ENTRY RhpThrowHwEx, _TEXT, NoHandler // lr: IP of fault site (as a 'return address') mov r4, r2 // save exception code of fault - // r0 = GetThread() - INLINE_GETTHREAD - - // r1 <- ExInfo* - add r1, sp, #rsp_offsetof_ExInfo - mov r3, #0 - str r3, [r1, #OFFSETOF__ExInfo__m_exception] // pExInfo->m_exception = null - mov r3, #1 - strb r3, [r1, #OFFSETOF__ExInfo__m_passNumber] // pExInfo->m_passNumber = 1 - mov r3, #0xFFFFFFFF - str r3, [r1, #OFFSETOF__ExInfo__m_idxCurClause] // pExInfo->m_idxCurClause = MaxTryRegionIdx - mov r3, #2 - strb r3, [r1, #OFFSETOF__ExInfo__m_kind] // pExInfo->m_kind = ExKind.HardwareFault - - // link the ExInfo into the thread's ExInfo chain - ldr r3, [r0, #OFFSETOF__Thread__m_pExInfoStackHead] - str r3, [r1, #OFFSETOF__ExInfo__m_pPrevExInfo] // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str r1, [r0, #OFFSETOF__Thread__m_pExInfoStackHead] // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - add r2, sp, #rsp_offsetof_Context // r2 <- PAL_LIMITED_CONTEXT* - str r2, [r1, #OFFSETOF__ExInfo__m_pExContext] // pExInfo->m_pExContext = pContext - - mov r0, r4 // restore the exception code - // r0 contains the exception code - // r1 contains the address of the ExInfo + add r0, sp, #rsp_offsetof_ExInfo // r0 <- ExInfo* + add r1, sp, #rsp_offsetof_Context // r1 <- PAL_LIMITED_CONTEXT* + mov r2, #2 // r2 <- ExKind.HardwareFault + bl C_FUNC(RhpPushExInfo) + + mov r0, r4 // r0 <- exception code + add r1, sp, #rsp_offsetof_ExInfo // r1 <- ExInfo* bl C_FUNC(RhThrowHwEx) GLOBAL_LABEL RhpThrowHwEx2 @@ -126,77 +107,14 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler str r4, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__SP)] mov r4, r0 // Save exception object - mov r5, r2 // Save ExKind - // r0 = GetThread() - INLINE_GETTHREAD - - // There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return - // address could have been hijacked when we were in that C# code and we must remove the hijack and - // reflect the correct return address in our exception context record. The other throw helpers don't - // need this because they cannot be tail-called from C#. - // NOTE: we cannot use INLINE_THREAD_UNHIJACK because it will write into the stack at the location - // where the tail-calling thread had saved LR, which may not match where we have saved LR. - - ldr r1, [r0, #OFFSETOF__Thread__m_pvHijackedReturnAddress] - cbz r1, LOCAL_LABEL(NotHiJacked) - - ldr r3, [r0, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] - - // r4: exception object - // r5: ExKind - // r1: hijacked return address - // r0: pThread - // r3: hijacked return address location - - add r12, sp, #(STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) // re-compute SP at callsite - cmp r3, r12 // if (m_ppvHijackedReturnAddressLocation < SP at callsite) - blo LOCAL_LABEL(TailCallWasHijacked) - - // normal case where a valid return address location is hijacked - str r1, [r3] - b LOCAL_LABEL(ClearThreadState) - -LOCAL_LABEL(TailCallWasHijacked): - // Abnormal case where the return address location is now invalid because we ended up here via a tail - // call. In this case, our hijacked return address should be the correct caller of this method. - // - - // stick the previous return address in LR as well as in the right spots in our PAL_LIMITED_CONTEXT. - mov lr, r1 - str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__LR)] - str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP)] - -LOCAL_LABEL(ClearThreadState): - - // clear the Thread's hijack state - mov r3, #0 - str r3, [r0, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] - str r3, [r0, #OFFSETOF__Thread__m_pvHijackedReturnAddress] - -LOCAL_LABEL(NotHiJacked): + add r0, sp, #rsp_offsetof_ExInfo // r0 <- ExInfo* + add r1, sp, #rsp_offsetof_Context // r1 <- PAL_LIMITED_CONTEXT* + // r2 contains the ExKind + bl C_FUNC(RhpPushExInfo) + mov r0, r4 // r0 <- exception object add r1, sp, #rsp_offsetof_ExInfo // r1 <- ExInfo* - mov r3, #0 - str r3, [r1, #OFFSETOF__ExInfo__m_exception] // init the exception object to null - mov r3, #1 - strb r3, [r1, #OFFSETOF__ExInfo__m_passNumber] // init to the first pass - strb r5, [r1, #OFFSETOF__ExInfo__m_kind] // ExKind - mov r3, #0xFFFFFFFF - str r3, [r1, #OFFSETOF__ExInfo__m_idxCurClause] - - // link the ExInfo into the thread's ExInfo chain - ldr r3, [r0, #OFFSETOF__Thread__m_pExInfoStackHead] - str r3, [r1, #OFFSETOF__ExInfo__m_pPrevExInfo] // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str r1, [r0, #OFFSETOF__Thread__m_pExInfoStackHead] // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - add r3, sp, #rsp_offsetof_Context // r3 <- PAL_LIMITED_CONTEXT* - str r3, [r1, #OFFSETOF__ExInfo__m_pExContext] // init ExInfo.m_pExContext - - mov r0, r4 // Restore exception object - // r0 contains the exception object - // r1 contains the address of the new ExInfo bl C_FUNC(RhThrowEx) GLOBAL_LABEL RhpThrowImpl2 @@ -232,32 +150,13 @@ NESTED_ENTRY RhpRethrow, _TEXT, NoHandler add r1, sp, #(STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) str r1, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__SP)] - // r0 = GetThread(); - INLINE_GETTHREAD - - // r1 <- ExInfo* - add r1, sp, #rsp_offsetof_ExInfo + add r0, sp, #rsp_offsetof_ExInfo // r0 <- ExInfo* + add r1, sp, #rsp_offsetof_Context // r1 <- PAL_LIMITED_CONTEXT* + mov r2, #0 // r2 <- ExKind.None + bl C_FUNC(RhpPushExInfo) - mov r3, #0 - str r3, [r1, #OFFSETOF__ExInfo__m_exception] // init the exception object to null - strb r3, [r1, #OFFSETOF__ExInfo__m_kind] // init to a deterministic value (ExKind.None) - mov r3, #1 - strb r3, [r1, #OFFSETOF__ExInfo__m_passNumber] // pExInfo->m_passNumber = 1 - mov r3, #0xFFFFFFFF - str r3, [r1, #OFFSETOF__ExInfo__m_idxCurClause] - - // link the ExInfo into the thread's ExInfo chain - ldr r3, [r0, #OFFSETOF__Thread__m_pExInfoStackHead] // r3 <- currently active ExInfo - str r3, [r1, #OFFSETOF__ExInfo__m_pPrevExInfo] // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str r1, [r0, #OFFSETOF__Thread__m_pExInfoStackHead] // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - add r2, sp, #rsp_offsetof_Context // r2 <- PAL_LIMITED_CONTEXT* - str r2, [r1, #OFFSETOF__ExInfo__m_pExContext] // init ExInfo.m_pExContext - - mov r0, r3 // r0 contains the currently active ExInfo - // r1 contains the address of the new ExInfo + add r1, sp, #rsp_offsetof_ExInfo // r1 <- ExInfo* blx C_FUNC(RhRethrow) GLOBAL_LABEL RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/arm/UniversalTransition.S b/src/coreclr/nativeaot/Runtime/arm/UniversalTransition.S deleted file mode 100644 index 8d942868421597..00000000000000 --- a/src/coreclr/nativeaot/Runtime/arm/UniversalTransition.S +++ /dev/null @@ -1,144 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -.syntax unified -.thumb - -#include // generated by the build from AsmOffsets.cpp -#include - -#ifdef _DEBUG -#define TRASH_SAVED_ARGUMENT_REGISTERS -#endif - -#define COUNT_ARG_REGISTERS (4) -#define INTEGER_REGISTER_SIZE (4) -#define ARGUMENT_REGISTERS_SIZE (COUNT_ARG_REGISTERS * INTEGER_REGISTER_SIZE) - -// Largest return block is 4 doubles -#define RETURN_BLOCK_SIZE (32) - -#define COUNT_FLOAT_ARG_REGISTERS (8) -#define FLOAT_REGISTER_SIZE (8) -#define FLOAT_ARG_REGISTERS_SIZE (COUNT_FLOAT_ARG_REGISTERS * FLOAT_REGISTER_SIZE) - -#define PUSHED_LR_SIZE (4) -#define PUSHED_R11_SIZE (4) - -// -// From CallerSP to ChildSP, the stack frame is composed of the following adjacent regions: -// -// ARGUMENT_REGISTERS_SIZE -// RETURN_BLOCK_SIZE -// FLOAT_ARG_REGISTERS_SIZE -// PUSHED_LR -// PUSHED_R11 - - -#define DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK (PUSHED_R11_SIZE + PUSHED_LR_SIZE + FLOAT_ARG_REGISTERS_SIZE) - -////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// RhpUniversalTransition -// -// At input to this function, r0-3, d0-7 and the stack may contain any number of arguments. -// -// In addition, there are 2 extra arguments passed on the stack. The caller pushes them -// (sp adjusted by -8 before branching here): -// [sp+4] = managed function to be called -// [sp+0] = pointer sized extra argument -// -// When invoking the callee: -// -// r0 shall contain a pointer to the TransitionBlock -// r1 shall contain the value that was in [sp+0] at entry to this function -// -// Frame layout is: -// -// {StackPassedArgs} ChildSP+078 CallerSP+000 -// {IntArgRegs (r0-r3) (0x10 bytes)} ChildSP+068 CallerSP-010 -// {ReturnBlock (0x20 bytes)} ChildSP+048 CallerSP-030 -// -- The base address of the Return block is the TransitionBlock pointer, the floating point args are -// in the neg space of the TransitionBlock pointer. Note that the callee has knowledge of the exact -// layout of all pieces of the frame that lie at or above the pushed floating point registers. -// {FpArgRegs (d0-d7) (0x40 bytes)} ChildSP+008 CallerSP-070 -// {PushedLR} ChildSP+004 CallerSP-074 -// {PushedR11} ChildSP+000 CallerSP-078 -// -// NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -// must be updated as well. -// -// NOTE: The callee receives a pointer to the base of the ReturnBlock, and the callee has -// knowledge of the exact layout of all pieces of the frame that lie at or above the pushed -// FpArgRegs. -// -// NOTE: The stack walker guarantees that conservative GC reporting will be applied to -// everything between the base of the ReturnBlock and the top of the StackPassedArgs. -// -////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -.macro UNIVERSAL_TRANSITION FunctionName - -NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler - // Save argument registers (including floating point) and the return address. - // Caller pushed 8 bytes: [sp]=extra arg, [sp+4]=target fn - .pad #8 - PROLOG_PUSH "{r0-r1}" - ldr r12, [sp, #12] // Capture target function (caller's [sp+4], now at sp+8+4) - ldr r1, [sp, #8] // Capture extra arg (caller's [sp], now at sp+8) - str r3, [sp, #12] // Store remaining arg registers into the space used for the hidden args - str r2, [sp, #8] - PROLOG_STACK_ALLOC RETURN_BLOCK_SIZE // Save space a buffer to be used to hold return buffer data. - PROLOG_VPUSH {d0-d7} // Capture the floating point argument registers - PROLOG_PUSH "{r11,lr}" // Save caller's frame chain pointer and PC - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - - // Before calling out, trash all of the argument registers except the ones (r0, r1) that - // hold outgoing arguments. All of these registers have been saved to the transition - // frame, and the code at the call target is required to use only the transition frame - // copies when dispatching this call to the eventual callee. - - PREPARE_EXTERNAL_VAR RhpFpTrashValues, r3 - vldr d0, [r3, #(0 * 8)] - vldr d1, [r3, #(1 * 8)] - vldr d2, [r3, #(2 * 8)] - vldr d3, [r3, #(3 * 8)] - vldr d4, [r3, #(4 * 8)] - vldr d5, [r3, #(5 * 8)] - vldr d6, [r3, #(6 * 8)] - vldr d7, [r3, #(7 * 8)] - - PREPARE_EXTERNAL_VAR RhpIntegerTrashValues, r3 - ldr r2, [r3, #(2 * 4)] - ldr r3, [r3, #(3 * 4)] - -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - - // Make the ReturnFromUniversalTransition alternate entry 4 byte aligned - .balign 4 - add r0, sp, #DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK // First parameter to target function is a pointer to the return block - blx r12 - -GLOBAL_LABEL ReturnFrom\FunctionName - - // Move the result (the target address) to r12 so it doesn't get overridden when we restore the - // argument registers. Additionally make sure the thumb2 bit is set. - orr r12, r0, #1 - - // Restore caller's frame chain pointer and PC. - EPILOG_POP "{r11,lr}" - - // Restore the argument registers. - EPILOG_VPOP {d0-d7} - EPILOG_STACK_FREE RETURN_BLOCK_SIZE // pop return block conservatively reported area - EPILOG_POP "{r0-r3}" - - // Tailcall to the target address. - EPILOG_BRANCH_REG r12 - -NESTED_END Rhp\FunctionName, _TEXT - -.endm - -UNIVERSAL_TRANSITION UniversalTransitionTailCall diff --git a/src/coreclr/nativeaot/Runtime/arm64/AsmMacros.h b/src/coreclr/nativeaot/Runtime/arm64/AsmMacros.h index e608af355c3b7b..9b10bd86a5f6f9 100644 --- a/src/coreclr/nativeaot/Runtime/arm64/AsmMacros.h +++ b/src/coreclr/nativeaot/Runtime/arm64/AsmMacros.h @@ -6,6 +6,9 @@ ;; generated by the build from AsmOffsets.cpp #include "AsmOffsets.inc" +;; Size of the q0-q7 save area of PROLOG_WITH_TRANSITION_BLOCK +#define SIZEOF__FloatArgumentRegisters 0x80 + #include "arm64/AsmMacros_Windows.h" ;; @@ -77,6 +80,7 @@ OFFSETOF__ee_alloc_context equ OFFSETOF__Thread__m_eeAllocCont EXTERN RhThrowHwEx EXTERN RhThrowEx EXTERN RhRethrow + EXTERN RhpPushExInfo EXTERN RhpTrapThreads EXTERN g_lowest_address diff --git a/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.S b/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.S index 653de0d7613a16..774ab503d1332d 100644 --- a/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.S +++ b/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.S @@ -114,11 +114,10 @@ LOCAL_LABEL(ProbeMiss\@): LOCAL_LABEL(CacheMiss\@): .if \ReturnTarget - b C_FUNC(RhpCidResolve_Worker) + b C_FUNC(RhpCidResolve) .else - PREPARE_EXTERNAL_VAR RhpCidResolve, xip0 - mov xip1, \DispatchCellReg - b C_FUNC(RhpUniversalTransitionTailCall) + // DispatchCellReg (x11) contains the indirection cell address + b C_FUNC(RhpInterfaceDispatchSlow) .endif LEAF_END \DispatchName, _TEXT @@ -127,3 +126,22 @@ LEAF_END \DispatchName, _TEXT INTERFACE_DISPATCH RhpInterfaceDispatch, 0, x11 INTERFACE_DISPATCH RhpDispatchResolve, 1, x1 + +// x11: interface dispatch cell, arguments passed in registers and stack space as normal + NESTED_ENTRY RhpInterfaceDispatchSlow, _TEXT, NoHandler + + // NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout + PROLOG_WITH_TRANSITION_BLOCK + + // x0 still contains 'this' + mov x1, x11 + bl C_FUNC(RhpCidResolve) + +ALTERNATE_ENTRY ReturnFromInterfaceDispatchSlow + + mov x9, x0 + + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + EPILOG_BRANCH_REG x9 + + NESTED_END RhpInterfaceDispatchSlow, _TEXT diff --git a/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.asm b/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.asm index 5ae00eca70b1ab..7f366398262139 100644 --- a/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.asm +++ b/src/coreclr/nativeaot/Runtime/arm64/DispatchResolve.asm @@ -6,11 +6,9 @@ TEXTAREA EXTERN RhpCidResolve - EXTERN RhpCidResolve_Worker - EXTERN RhpUniversalTransitionTailCall - EXTERN RhpUniversalTransitionGuardedTailCall EXTERN __guard_dispatch_icall_fptr + EXTERN __guard_check_icall_fptr EXTERN g_pDispatchCache ;; Macro that generates an interface dispatch or dispatch resolve stub. @@ -142,14 +140,12 @@ 4 ;; CacheMiss / SlowPath IF "$ReturnTarget" != "0" - b RhpCidResolve_Worker + b RhpCidResolve ELSE - ldr xip0, =RhpCidResolve - mov xip1, $DispatchCellReg IF "$Guarded" != "0" - b RhpUniversalTransitionGuardedTailCall + b RhpInterfaceDispatchSlowGuarded ELSE - b RhpUniversalTransitionTailCall + b RhpInterfaceDispatchSlow ENDIF ENDIF @@ -161,4 +157,43 @@ INTERFACE_DISPATCH RhpInterfaceDispatchGuarded, 1, 0, x11 INTERFACE_DISPATCH RhpDispatchResolve, 0, 1, x1 +;; Macro that generates slow path for an interface dispatch. +;; FunctionName: the name of the dispatch entry point +;; Guarded: if non-zero, validate indirect call targets using Control Flow Guard + MACRO + INTERFACE_DISPATCH_SLOW $FunctionName, $Guarded + +;; x11: interface dispatch cell, arguments passed in registers and stack space as normal + NESTED_ENTRY Rhp$FunctionName + + ;; NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout + PROLOG_WITH_TRANSITION_BLOCK + + ;; x0 still contains 'this' + mov x1, x11 + bl RhpCidResolve + + ALTERNATE_ENTRY ReturnFrom$FunctionName + + IF "$Guarded" != "0" + ;; The validator takes the target in x15 and preserves x0-x8, x15, and all float registers. + mov x15, x0 + adrp x16, __guard_check_icall_fptr + ldr x16, [x16, __guard_check_icall_fptr] + blr x16 + mov x0, x15 + ENDIF + + mov x9, x0 + + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + EPILOG_BRANCH_REG x9 + + NESTED_END Rhp$FunctionName + + MEND + + INTERFACE_DISPATCH_SLOW InterfaceDispatchSlow, 0 + INTERFACE_DISPATCH_SLOW InterfaceDispatchSlowGuarded, 1 + END diff --git a/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S index 7d8d14a505b9ec..b74ad73d524b6d 100644 --- a/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S @@ -17,13 +17,10 @@ mov x3, sp // Setup a PAL_LIMITED_CONTEXT on the stack { + PROLOG_STACK_ALLOC 0x50 .if \exceptionType == HARDWARE_EXCEPTION - sub sp,sp,#0x50 - .cfi_adjust_cfa_offset 0x50 stp x3, x1, [sp] // x3 is the SP and x1 is the IP of the fault site .else - PROLOG_STACK_ALLOC 0x50 - .cfi_adjust_cfa_offset 0x50 stp x3, lr, [sp] // x3 is the SP and lr is the IP of the fault site .endif stp d8, d9, [sp, #0x10] @@ -39,16 +36,9 @@ PROLOG_SAVE_REG_PAIR x27, x28, 0x60 // } end PAL_LIMITED_CONTEXT - PROLOG_STACK_ALLOC STACKSIZEOF_ExInfo + sub sp, sp, STACKSIZEOF_ExInfo .endm -.macro GetThreadX2 - stp x0, x1, [sp, -16]! - bl C_FUNC(RhpGetThread) - mov x2, x0 - ldp x0, x1, [sp], 16 -.endm - #define rsp_offsetof_ExInfo 0 #define rsp_offsetof_Context STACKSIZEOF_ExInfo @@ -64,28 +54,15 @@ ALLOC_THROW_FRAME HARDWARE_EXCEPTION - GetThreadX2 + mov w19, w0 // w19 <- exception code + + add x0, sp, #rsp_offsetof_ExInfo // x0 <- ExInfo* + add x1, sp, #rsp_offsetof_Context // x1 <- PAL_LIMITED_CONTEXT* + mov w2, #2 // w2 <- ExKind.HardwareFault + bl C_FUNC(RhpPushExInfo) + mov w0, w19 // w0 <- exception code add x1, sp, #rsp_offsetof_ExInfo // x1 <- ExInfo* - str xzr, [x1, #OFFSETOF__ExInfo__m_exception] // pExInfo->m_exception = null - mov w3, #1 - strb w3, [x1, #OFFSETOF__ExInfo__m_passNumber] // pExInfo->m_passNumber = 1 - mov w3, #0xFFFFFFFF - str w3, [x1, #OFFSETOF__ExInfo__m_idxCurClause] // pExInfo->m_idxCurClause = MaxTryRegionIdx - mov w3, #2 - strb w3, [x1, #OFFSETOF__ExInfo__m_kind] // pExInfo->m_kind = ExKind.HardwareFault - - // link the ExInfo into the thread's ExInfo chain - ldr x3, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] - str x3, [x1, #OFFSETOF__ExInfo__m_pPrevExInfo] // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str x1, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - add x2, sp, #rsp_offsetof_Context // x2 <- PAL_LIMITED_CONTEXT* - str x2, [x1, #OFFSETOF__ExInfo__m_pExContext] // pExInfo->m_pExContext = pContext - - // w0: exception code - // x1: ExInfo* bl C_FUNC(RhThrowHwEx) ALTERNATE_ENTRY RhpThrowHwEx2 @@ -130,74 +107,16 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - mov x19, x4 // Save ExKind - - GetThreadX2 - - // There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return - // address could have been hijacked when we were in that C# code and we must remove the hijack and - // reflect the correct return address in our exception context record. The other throw helpers don't - // need this because they cannot be tail-called from C#. - - // NOTE: we cannot use INLINE_THREAD_UNHIJACK because it will write into the stack at the location - // where the tail-calling thread had saved LR, which may not match where we have saved LR. - - ldr x1, [x2, #OFFSETOF__Thread__m_pvHijackedReturnAddress] - cbz x1, LOCAL_LABEL(NotHijacked) - - ldr x3, [x2, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] - - // x0: exception object - // x1: hijacked return address - // x2: pThread - // x3: hijacked return address location - - add x12, sp, #(STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) // re-compute SP at callsite - cmp x3, x12 // if (m_ppvHijackedReturnAddressLocation < SP at callsite) - blo LOCAL_LABEL(TailCallWasHijacked) - // normal case where a valid return address location is hijacked - str x1, [x3] - b LOCAL_LABEL(ClearThreadState) + mov x19, x0 // x19 <- exception object -LOCAL_LABEL(TailCallWasHijacked): - - // Abnormal case where the return address location is now invalid because we ended up here via a tail - // call. In this case, our hijacked return address should be the correct caller of this method. - - // stick the previous return address in LR as well as in the right spots in our PAL_LIMITED_CONTEXT. - mov lr, x1 - str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__LR)] - str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP)] - -LOCAL_LABEL(ClearThreadState): - - // clear the Thread's hijack state - str xzr, [x2, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] - str xzr, [x2, #OFFSETOF__Thread__m_pvHijackedReturnAddress] - str xzr, [x2, #OFFSETOF__Thread__m_pSpForPacSign] - -LOCAL_LABEL(NotHijacked): + add x0, sp, #rsp_offsetof_ExInfo // x0 <- ExInfo* + add x1, sp, #rsp_offsetof_Context // x1 <- PAL_LIMITED_CONTEXT* + mov w2, w4 // w2 <- ExKind + bl C_FUNC(RhpPushExInfo) + mov x0, x19 // x0 <- exception object add x1, sp, #rsp_offsetof_ExInfo // x1 <- ExInfo* - str xzr, [x1, #OFFSETOF__ExInfo__m_exception] // pExInfo->m_exception = null - mov w3, #1 - strb w3, [x1, #OFFSETOF__ExInfo__m_passNumber] // pExInfo->m_passNumber = 1 - mov w3, #0xFFFFFFFF - str w3, [x1, #OFFSETOF__ExInfo__m_idxCurClause] // pExInfo->m_idxCurClause = MaxTryRegionIdx - strb w19, [x1, #OFFSETOF__ExInfo__m_kind] // pExInfo->m_kind = ExKind - - // link the ExInfo into the thread's ExInfo chain - ldr x3, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] - str x3, [x1, #OFFSETOF__ExInfo__m_pPrevExInfo] // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str x1, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - add x2, sp, #rsp_offsetof_Context // x2 <- PAL_LIMITED_CONTEXT* - str x2, [x1, #OFFSETOF__ExInfo__m_pExContext] // pExInfo->m_pExContext = pContext - - // x0: exception object - // x1: ExInfo* bl C_FUNC(RhThrowEx) ALTERNATE_ENTRY RhpThrowImpl2 @@ -220,28 +139,13 @@ LOCAL_LABEL(NotHijacked): ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - GetThreadX2 - - add x1, sp, #rsp_offsetof_ExInfo // x1 <- ExInfo* - str xzr, [x1, #OFFSETOF__ExInfo__m_exception] // pExInfo->m_exception = null - strb wzr, [x1, #OFFSETOF__ExInfo__m_kind] // init to a deterministic value (ExKind.None) - mov w3, #1 - strb w3, [x1, #OFFSETOF__ExInfo__m_passNumber] // pExInfo->m_passNumber = 1 - mov w3, #0xFFFFFFFF - str w3, [x1, #OFFSETOF__ExInfo__m_idxCurClause] // pExInfo->m_idxCurClause = MaxTryRegionIdx - - // link the ExInfo into the thread's ExInfo chain - ldr x3, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] - mov x0, x3 // x0 <- current ExInfo - str x3, [x1, #OFFSETOF__ExInfo__m_pPrevExInfo] // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str x1, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - add x2, sp, #rsp_offsetof_Context // x2 <- PAL_LIMITED_CONTEXT* - str x2, [x1, #OFFSETOF__ExInfo__m_pExContext] // pExInfo->m_pExContext = pContext + add x0, sp, #rsp_offsetof_ExInfo // x0 <- ExInfo* + add x1, sp, #rsp_offsetof_Context // x1 <- PAL_LIMITED_CONTEXT* + mov w2, #0 // w2 <- ExKind.None + bl C_FUNC(RhpPushExInfo) // x0 contains the currently active ExInfo - // x1 contains the address of the new ExInfo + add x1, sp, #rsp_offsetof_ExInfo // x1 <- ExInfo* bl C_FUNC(RhRethrow) ALTERNATE_ENTRY RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.asm b/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.asm index 4ad95c9a0ab1e8..a7e74f4aa48971 100644 --- a/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.asm +++ b/src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.asm @@ -59,29 +59,15 @@ ALLOC_THROW_FRAME HARDWARE_EXCEPTION - ;; x2 = GetThread(), TRASHES x1 - INLINE_GETTHREAD x2, x1 + mov w19, w0 ;; w19 <- exception code + add x0, sp, #rsp_offsetof_ExInfo ;; x0 <- ExInfo* + add x1, sp, #rsp_offsetof_Context ;; x1 <- PAL_LIMITED_CONTEXT* + mov w2, #2 ;; w2 <- ExKind.HardwareFault + bl RhpPushExInfo + + mov w0, w19 ;; w0 <- exception code add x1, sp, #rsp_offsetof_ExInfo ;; x1 <- ExInfo* - str xzr, [x1, #OFFSETOF__ExInfo__m_exception] ;; pExInfo->m_exception = null - mov w3, #1 - strb w3, [x1, #OFFSETOF__ExInfo__m_passNumber] ;; pExInfo->m_passNumber = 1 - mov w3, #0xFFFFFFFF - str w3, [x1, #OFFSETOF__ExInfo__m_idxCurClause] ;; pExInfo->m_idxCurClause = MaxTryRegionIdx - mov w3, #2 - strb w3, [x1, #OFFSETOF__ExInfo__m_kind] ;; pExInfo->m_kind = ExKind.HardwareFault - - ;; link the ExInfo into the thread's ExInfo chain - ldr x3, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] - str x3, [x1, #OFFSETOF__ExInfo__m_pPrevExInfo] ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str x1, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - add x2, sp, #rsp_offsetof_Context ;; x2 <- PAL_LIMITED_CONTEXT* - str x2, [x1, #OFFSETOF__ExInfo__m_pExContext] ;; pExInfo->m_pExContext = pContext - - ;; w0: exception code - ;; x1: ExInfo* bl RhThrowHwEx ALTERNATE_ENTRY RhpThrowHwEx2 @@ -129,74 +115,15 @@ ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - ;; x2 = GetThread(), TRASHES x1 - INLINE_GETTHREAD x2, x1 - - ;; There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return - ;; address could have been hijacked when we were in that C# code and we must remove the hijack and - ;; reflect the correct return address in our exception context record. The other throw helpers don't - ;; need this because they cannot be tail-called from C#. - - ;; NOTE: we cannot use INLINE_THREAD_UNHIJACK because it will write into the stack at the location - ;; where the tail-calling thread had saved LR, which may not match where we have saved LR. - - ldr x1, [x2, #OFFSETOF__Thread__m_pvHijackedReturnAddress] - cbz x1, NotHijacked - - ldr x3, [x2, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] - - ;; x0: exception object - ;; x1: hijacked return address - ;; x2: pThread - ;; x3: hijacked return address location - - add x12, sp, #(STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) ;; re-compute SP at callsite - cmp x3, x12 ;; if (m_ppvHijackedReturnAddressLocation < SP at callsite) - blo TailCallWasHijacked - - ;; normal case where a valid return address location is hijacked - str x1, [x3] - b ClearThreadState + mov x19, x0 ;; x19 <- exception object -TailCallWasHijacked - - ;; Abnormal case where the return address location is now invalid because we ended up here via a tail - ;; call. In this case, our hijacked return address should be the correct caller of this method. - ;; - - ;; stick the previous return address in LR as well as in the right spots in our PAL_LIMITED_CONTEXT. - mov lr, x1 - str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__LR)] - str lr, [sp, #(rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP)] - -ClearThreadState - - ;; clear the Thread's hijack state - str xzr, [x2, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation] - str xzr, [x2, #OFFSETOF__Thread__m_pvHijackedReturnAddress] - str xzr, [x2, #OFFSETOF__Thread__m_pSpForPacSign] - -NotHijacked + add x0, sp, #rsp_offsetof_ExInfo ;; x0 <- ExInfo* + add x1, sp, #rsp_offsetof_Context ;; x1 <- PAL_LIMITED_CONTEXT* + mov w2, w4 ;; w2 <- ExKind + bl RhpPushExInfo + mov x0, x19 ;; x0 <- exception object add x1, sp, #rsp_offsetof_ExInfo ;; x1 <- ExInfo* - str xzr, [x1, #OFFSETOF__ExInfo__m_exception] ;; pExInfo->m_exception = null - mov w3, #1 - strb w3, [x1, #OFFSETOF__ExInfo__m_passNumber] ;; pExInfo->m_passNumber = 1 - mov w3, #0xFFFFFFFF - str w3, [x1, #OFFSETOF__ExInfo__m_idxCurClause] ;; pExInfo->m_idxCurClause = MaxTryRegionIdx - strb w4, [x1, #OFFSETOF__ExInfo__m_kind] ;; pExInfo->m_kind = ExKind (from w4) - - ;; link the ExInfo into the thread's ExInfo chain - ldr x3, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] - str x3, [x1, #OFFSETOF__ExInfo__m_pPrevExInfo] ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str x1, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - add x2, sp, #rsp_offsetof_Context ;; x2 <- PAL_LIMITED_CONTEXT* - str x2, [x1, #OFFSETOF__ExInfo__m_pExContext] ;; pExInfo->m_pExContext = pContext - - ;; x0: exception object - ;; x1: ExInfo* bl RhThrowEx ALTERNATE_ENTRY RhpThrowImpl2 @@ -220,29 +147,13 @@ NotHijacked ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - ;; x2 = GetThread(), TRASHES x1 - INLINE_GETTHREAD x2, x1 - - add x1, sp, #rsp_offsetof_ExInfo ;; x1 <- ExInfo* - str xzr, [x1, #OFFSETOF__ExInfo__m_exception] ;; pExInfo->m_exception = null - strb wzr, [x1, #OFFSETOF__ExInfo__m_kind] ;; init to a deterministic value (ExKind.None) - mov w3, #1 - strb w3, [x1, #OFFSETOF__ExInfo__m_passNumber] ;; pExInfo->m_passNumber = 1 - mov w3, #0xFFFFFFFF - str w3, [x1, #OFFSETOF__ExInfo__m_idxCurClause] ;; pExInfo->m_idxCurClause = MaxTryRegionIdx - - ;; link the ExInfo into the thread's ExInfo chain - ldr x3, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] - mov x0, x3 ;; x0 <- current ExInfo - str x3, [x1, #OFFSETOF__ExInfo__m_pPrevExInfo] ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - str x1, [x2, #OFFSETOF__Thread__m_pExInfoStackHead] ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - add x2, sp, #rsp_offsetof_Context ;; x2 <- PAL_LIMITED_CONTEXT* - str x2, [x1, #OFFSETOF__ExInfo__m_pExContext] ;; pExInfo->m_pExContext = pContext + add x0, sp, #rsp_offsetof_ExInfo ;; x0 <- ExInfo* + add x1, sp, #rsp_offsetof_Context ;; x1 <- PAL_LIMITED_CONTEXT* + mov w2, #0 ;; w2 <- ExKind.None + bl RhpPushExInfo ;; x0 contains the currently active ExInfo - ;; x1 contains the address of the new ExInfo + add x1, sp, #rsp_offsetof_ExInfo ;; x1 <- ExInfo* bl RhRethrow ALTERNATE_ENTRY RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/arm64/UniversalTransition.S b/src/coreclr/nativeaot/Runtime/arm64/UniversalTransition.S deleted file mode 100644 index 9dcd758059d44b..00000000000000 --- a/src/coreclr/nativeaot/Runtime/arm64/UniversalTransition.S +++ /dev/null @@ -1,156 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include - -#ifdef _DEBUG -#define TRASH_SAVED_ARGUMENT_REGISTERS -#endif - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - .global RhpIntegerTrashValues - .global RhpFpTrashValues -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - -// Padding to account for the odd number of saved integer registers -#define ALIGNMENT_PADDING_SIZE (8) - -#define COUNT_ARG_REGISTERS (9) -#define INTEGER_REGISTER_SIZE (8) -#define ARGUMENT_REGISTERS_SIZE (COUNT_ARG_REGISTERS * INTEGER_REGISTER_SIZE) - -// Largest return block is 4 doubles -#define RETURN_BLOCK_SIZE (32) - -#define COUNT_FLOAT_ARG_REGISTERS (8) -#define FLOAT_REGISTER_SIZE (16) -#define FLOAT_ARG_REGISTERS_SIZE (COUNT_FLOAT_ARG_REGISTERS * FLOAT_REGISTER_SIZE) - -#define PUSHED_LR_SIZE (8) -#define PUSHED_FP_SIZE (8) - -// -// From CallerSP to ChildSP, the stack frame is composed of the following adjacent regions: -// -// ALIGNMENT_PADDING_SIZE -// ARGUMENT_REGISTERS_SIZE -// RETURN_BLOCK_SIZE -// FLOAT_ARG_REGISTERS_SIZE -// PUSHED_LR_SIZE -// PUSHED_FP_SIZE -// - -#define DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK (PUSHED_FP_SIZE + PUSHED_LR_SIZE + FLOAT_ARG_REGISTERS_SIZE) - -#define STACK_SIZE (ALIGNMENT_PADDING_SIZE + ARGUMENT_REGISTERS_SIZE + RETURN_BLOCK_SIZE + FLOAT_ARG_REGISTERS_SIZE + PUSHED_LR_SIZE + PUSHED_FP_SIZE) - -#define FLOAT_ARG_OFFSET (PUSHED_FP_SIZE + PUSHED_LR_SIZE) -#define ARGUMENT_REGISTERS_OFFSET (FLOAT_ARG_OFFSET + FLOAT_ARG_REGISTERS_SIZE + RETURN_BLOCK_SIZE) - -// -// RhpUniversalTransition -// -// At input to this function, x0-8, q0-7 and the stack may contain any number of arguments. -// -// In addition, there are 2 extra arguments passed in the intra-procedure-call scratch register: -// xip0 will contain the managed function that is to be called by this transition function -// xip1 will contain the pointer sized extra argument to the managed function -// -// When invoking the callee: -// -// x0 shall contain a pointer to the TransitionBlock -// x1 shall contain the value that was in xip1 at entry to this function -// -// Frame layout is: -// -// {StackPassedArgs} ChildSP+100 CallerSP+000 -// {AlignmentPad (0x8 bytes)} ChildSP+0F8 CallerSP-008 -// {IntArgRegs (x0-x8) (0x48 bytes)} ChildSP+0B0 CallerSP-050 -// {ReturnBlock (0x20 bytes)} ChildSP+090 CallerSP-070 -// -- The base address of the Return block is the TransitionBlock pointer, the floating point args are -// in the neg space of the TransitionBlock pointer. Note that the callee has knowledge of the exact -// layout of all pieces of the frame that lie at or above the pushed floating point registers. -// {FpArgRegs (q0-q7) (0x80 bytes)} ChildSP+010 CallerSP-0F0 -// {PushedLR} ChildSP+008 CallerSP-0F8 -// {PushedFP} ChildSP+000 CallerSP-100 -// -// NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -// must be updated as well. -// -// NOTE: The callee receives a pointer to the base of the ReturnBlock, and the callee has -// knowledge of the exact layout of all pieces of the frame that lie at or above the pushed -// FpArgRegs. -// -// NOTE: The stack walker guarantees that conservative GC reporting will be applied to -// everything between the base of the ReturnBlock and the top of the StackPassedArgs. -// - - .text - - .macro UNIVERSAL_TRANSITION FunctionName - - NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler - - // FP and LR registers - PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -STACK_SIZE // ;; Push down stack pointer and store FP and LR - - // Floating point registers - SAVE_FLOAT_ARGUMENT_REGISTERS sp, FLOAT_ARG_OFFSET - - // Space for return buffer data (0x40 bytes) - - // Save argument registers - stp x0, x1, [sp, #(ARGUMENT_REGISTERS_OFFSET )] - stp x2, x3, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x10)] - stp x4, x5, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x20)] - stp x6, x7, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x30)] - stp x8, xzr, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x40)] - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - PREPARE_EXTERNAL_VAR RhpFpTrashValues, x1 - - ldp q0,q1, [x1, 0x0] - ldp q2,q3, [x1, 0x20] - ldp q4,q5, [x1, 0x40] - ldp q6,q7, [x1, 0x60] - - PREPARE_EXTERNAL_VAR RhpIntegerTrashValues, x1 - - ldp x2,x3, [x1, 0x10] - ldp x4,x5, [x1, 0x20] - ldp x6,x7, [x1, 0x30] -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - - add x0, sp, #DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK // First parameter to target function is a pointer to the return block - mov x8, x0 // Arm64 calling convention: Address of return block shall be passed in x8 - mov x1, xip1 // Second parameter to target function - blr xip0 - -ALTERNATE_ENTRY ReturnFrom\FunctionName - - // Move the result (the target address) to x12 so it doesn't get overridden when we restore the - // argument registers. - mov x12, x0 - - // Restore floating point registers - RESTORE_FLOAT_ARGUMENT_REGISTERS sp, FLOAT_ARG_OFFSET - - // Restore the argument registers - ldp x0, x1, [sp, #(ARGUMENT_REGISTERS_OFFSET )] - ldp x2, x3, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x10)] - ldp x4, x5, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x20)] - ldp x6, x7, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x30)] - ldr x8, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x40)] - - // Restore FP and LR registers, and free the allocated stack block - EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, STACK_SIZE - - // Tailcall to the target address. - br x12 - - NESTED_END Rhp\FunctionName, _TEXT - - .endm - - UNIVERSAL_TRANSITION UniversalTransitionTailCall - diff --git a/src/coreclr/nativeaot/Runtime/arm64/UniversalTransition.asm b/src/coreclr/nativeaot/Runtime/arm64/UniversalTransition.asm deleted file mode 100644 index a5fc214995799c..00000000000000 --- a/src/coreclr/nativeaot/Runtime/arm64/UniversalTransition.asm +++ /dev/null @@ -1,166 +0,0 @@ -;; Licensed to the .NET Foundation under one or more agreements. -;; The .NET Foundation licenses this file to you under the MIT license. - -#include "AsmMacros.h" - -#ifdef _DEBUG -#define TRASH_SAVED_ARGUMENT_REGISTERS -#endif - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - EXTERN RhpIntegerTrashValues - EXTERN RhpFpTrashValues -#endif ;; TRASH_SAVED_ARGUMENT_REGISTERS - -;; Padding to account for the odd number of saved integer registers -#define ALIGNMENT_PADDING_SIZE (8) - -#define COUNT_ARG_REGISTERS (9) -#define INTEGER_REGISTER_SIZE (8) -#define ARGUMENT_REGISTERS_SIZE (COUNT_ARG_REGISTERS * INTEGER_REGISTER_SIZE) - -;; Largest return block is 4 doubles -#define RETURN_BLOCK_SIZE (32) - -#define COUNT_FLOAT_ARG_REGISTERS (8) -#define FLOAT_REGISTER_SIZE (16) -#define FLOAT_ARG_REGISTERS_SIZE (COUNT_FLOAT_ARG_REGISTERS * FLOAT_REGISTER_SIZE) - -#define PUSHED_LR_SIZE (8) -#define PUSHED_FP_SIZE (8) - -;; -;; From CallerSP to ChildSP, the stack frame is composed of the following adjacent regions: -;; -;; ALIGNMENT_PADDING_SIZE -;; ARGUMENT_REGISTERS_SIZE -;; RETURN_BLOCK_SIZE -;; FLOAT_ARG_REGISTERS_SIZE -;; PUSHED_LR_SIZE -;; PUSHED_FP_SIZE -;; - -#define DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK (PUSHED_FP_SIZE + PUSHED_LR_SIZE + FLOAT_ARG_REGISTERS_SIZE) - -#define STACK_SIZE (ALIGNMENT_PADDING_SIZE + ARGUMENT_REGISTERS_SIZE + RETURN_BLOCK_SIZE + FLOAT_ARG_REGISTERS_SIZE + \ - PUSHED_LR_SIZE + PUSHED_FP_SIZE) - -#define FLOAT_ARG_OFFSET (PUSHED_FP_SIZE + PUSHED_LR_SIZE) -#define ARGUMENT_REGISTERS_OFFSET (FLOAT_ARG_OFFSET + FLOAT_ARG_REGISTERS_SIZE + RETURN_BLOCK_SIZE) - -;; -;; RhpUniversalTransition -;; -;; At input to this function, x0-8, q0-7 and the stack may contain any number of arguments. -;; -;; In addition, there are 2 extra arguments passed in the intra-procedure-call scratch register: -;; xip0 will contain the managed function that is to be called by this transition function -;; xip1 will contain the pointer sized extra argument to the managed function -;; -;; When invoking the callee: -;; -;; x0 shall contain a pointer to the TransitionBlock -;; x1 shall contain the value that was in xip1 at entry to this function -;; -;; Frame layout is: -;; -;; {StackPassedArgs} ChildSP+100 CallerSP+000 -;; {AlignmentPad (0x8 bytes)} ChildSP+0F8 CallerSP-008 -;; {IntArgRegs (x0-x8) (0x48 bytes)} ChildSP+0A0 CallerSP-050 -;; {ReturnBlock (0x20 bytes)} ChildSP+090 CallerSP-070 -;; -- The base address of the Return block is the TransitionBlock pointer, the floating point args are -;; in the neg space of the TransitionBlock pointer. Note that the callee has knowledge of the exact -;; layout of all pieces of the frame that lie at or above the pushed floating point registers. -;; {FpArgRegs (q0-q7) (0x80 bytes)} ChildSP+010 CallerSP-0F0 -;; {PushedLR} ChildSP+008 CallerSP-0F8 -;; {PushedFP} ChildSP+000 CallerSP-100 -;; -;; NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -;; must be updated as well. -;; -;; NOTE: The callee receives a pointer to the base of the ReturnBlock, and the callee has -;; knowledge of the exact layout of all pieces of the frame that lie at or above the pushed -;; FpArgRegs. -;; -;; NOTE: The stack walker guarantees that conservative GC reporting will be applied to -;; everything between the base of the ReturnBlock and the top of the StackPassedArgs. -;; - - EXTERN __guard_check_icall_fptr - - TEXTAREA - - MACRO - UNIVERSAL_TRANSITION $FunctionName, $ValidateTarget - - NESTED_ENTRY Rhp$FunctionName - - ;; FP and LR registers - PROLOG_SAVE_REG_PAIR fp, lr, #-STACK_SIZE! ;; Push down stack pointer and store FP and LR - - ;; Floating point registers - stp q0, q1, [sp, #(FLOAT_ARG_OFFSET )] - stp q2, q3, [sp, #(FLOAT_ARG_OFFSET + 0x20)] - stp q4, q5, [sp, #(FLOAT_ARG_OFFSET + 0x40)] - stp q6, q7, [sp, #(FLOAT_ARG_OFFSET + 0x60)] - - ;; Space for return buffer data (0x40 bytes) - - ;; Save argument registers - stp x0, x1, [sp, #(ARGUMENT_REGISTERS_OFFSET )] - stp x2, x3, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x10)] - stp x4, x5, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x20)] - stp x6, x7, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x30)] - stp x8, xzr, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x40)] - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - ;; ARM64TODO -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - - add x0, sp, #DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK ;; First parameter to target function is a pointer to the return block - mov x8, x0 ;; Arm64 calling convention: Address of return block shall be passed in x8 - mov x1, xip1 ;; Second parameter to target function - blr xip0 - - ALTERNATE_ENTRY ReturnFrom$FunctionName - - IF "$ValidateTarget" != "" - ;; Validate the target address using Control Flow Guard before tail-calling it. - ;; The validator takes the target in x15 and preserves x0-x8, x15, and all float registers. - mov x15, x0 - adrp x16, __guard_check_icall_fptr - ldr x16, [x16, __guard_check_icall_fptr] - blr x16 - ENDIF - - ;; Move the result (the target address) to x12 so it doesn't get overridden when we restore the - ;; argument registers. - mov x12, x0 - - ;; Restore floating point registers - ldp q0, q1, [sp, #(FLOAT_ARG_OFFSET )] - ldp q2, q3, [sp, #(FLOAT_ARG_OFFSET + 0x20)] - ldp q4, q5, [sp, #(FLOAT_ARG_OFFSET + 0x40)] - ldp q6, q7, [sp, #(FLOAT_ARG_OFFSET + 0x60)] - - ;; Restore the argument registers - ldp x0, x1, [sp, #(ARGUMENT_REGISTERS_OFFSET )] - ldp x2, x3, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x10)] - ldp x4, x5, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x20)] - ldp x6, x7, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x30)] - ldr x8, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x40)] - - ;; Restore FP and LR registers, and free the allocated stack block - EPILOG_RESTORE_REG_PAIR fp, lr, #STACK_SIZE! - - ;; Tailcall to the target address. - EPILOG_NOP br x12 - - NESTED_END Rhp$FunctionName - - MEND - - UNIVERSAL_TRANSITION UniversalTransitionTailCall - UNIVERSAL_TRANSITION UniversalTransitionGuardedTailCall, ValidateTarget - - END diff --git a/src/coreclr/nativeaot/Runtime/i386/AsmMacros.inc b/src/coreclr/nativeaot/Runtime/i386/AsmMacros.inc index 8f11e67a9557bb..097891ae694dad 100644 --- a/src/coreclr/nativeaot/Runtime/i386/AsmMacros.inc +++ b/src/coreclr/nativeaot/Runtime/i386/AsmMacros.inc @@ -142,6 +142,7 @@ G_EPHEMERAL_LOW equ _g_ephemeral_low G_EPHEMERAL_HIGH equ _g_ephemeral_high G_CARD_TABLE equ _g_card_table RhpWaitForGC2 equ @RhpWaitForGC2@4 +RhpPushExInfo equ @RhpPushExInfo@12 RhpTrapThreads equ _RhpTrapThreads RhpGcPoll2 equ @RhpGcPoll2@4 RhHandleGet equ @RhHandleGet@4 @@ -159,6 +160,7 @@ EXTERN RhExceptionHandling_FailedAllocation : PROC EXTERN RhThrowHwEx : PROC EXTERN RhThrowEx : PROC EXTERN RhRethrow : PROC +EXTERN RhpPushExInfo : PROC EXTERN RhpGcPoll2 : PROC ;; The following imports are not used in the assembly helpers. Due to the diff --git a/src/coreclr/nativeaot/Runtime/i386/DispatchResolve.asm b/src/coreclr/nativeaot/Runtime/i386/DispatchResolve.asm index 2e05141e65816d..773f11d67fca6d 100644 --- a/src/coreclr/nativeaot/Runtime/i386/DispatchResolve.asm +++ b/src/coreclr/nativeaot/Runtime/i386/DispatchResolve.asm @@ -9,8 +9,6 @@ include AsmMacros.inc EXTERN RhpCidResolve : PROC -EXTERN RhpCidResolve_Worker : PROC -EXTERN _RhpUniversalTransitionTailCall@0 : PROC EXTERN _g_pDispatchCache : DWORD @@ -130,14 +128,12 @@ ALTERNATE_ENTRY _RhpInterfaceDispatch pop esi pop ebx - ;; Setup call to Universal Transition thunk + ;; Setup call to RhpInterfaceDispatchSlow push ebp mov ebp, esp - push eax - lea eax, [RhpCidResolve] - push eax + push eax ;; interface dispatch cell - jmp _RhpUniversalTransitionTailCall@0 + jmp _RhpInterfaceDispatchSlow@0 FASTCALL_ENDFUNC @@ -249,8 +245,35 @@ ALTERNATE_ENTRY _RhpDispatchResolve pop edi pop esi pop ebx - jmp RhpCidResolve_Worker + jmp RhpCidResolve RhpDispatchResolve ENDP +;; [esp]: interface dispatch cell, [esp+4]: caller's ebp, followed by the return address. Arguments are passed in +;; ecx, edx and stack space as normal. This must be jumped to, the fake entrypoint makes the stack walker see a +;; normal framed function. +;; +;; NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout +FASTCALL_FUNC RhpInterfaceDispatchSlow_FAKE_ENTRY, 0 + push ebp + mov ebp, esp + push eax +ALTERNATE_ENTRY _RhpInterfaceDispatchSlow@0 + push ecx + push edx + + ;; ecx still contains 'this' + mov edx, [ebp-4] ; Get the interface dispatch cell + call RhpCidResolve + +ALTERNATE_ENTRY _ReturnFromInterfaceDispatchSlow + + pop edx + pop ecx + add esp, 4 + pop ebp + jmp eax + +FASTCALL_ENDFUNC + end diff --git a/src/coreclr/nativeaot/Runtime/i386/ExceptionHandling.asm b/src/coreclr/nativeaot/Runtime/i386/ExceptionHandling.asm index 1bc2bc60dd2415..310c9780e169fb 100644 --- a/src/coreclr/nativeaot/Runtime/i386/ExceptionHandling.asm +++ b/src/coreclr/nativeaot/Runtime/i386/ExceptionHandling.asm @@ -46,27 +46,15 @@ FASTCALL_FUNC RhpThrowHwEx, 8 sub esp, SIZEOF__ExInfo - INLINE_GETTHREAD eax, edx ;; eax <- thread, edx <- trashed + mov ebx, ecx ;; ebx <- exception code - lea edx, [esp + esp_offsetof_ExInfo] ;; edx <- ExInfo* - - xor esi, esi - mov [edx + OFFSETOF__ExInfo__m_exception], esi ;; init the exception object to null - mov byte ptr [edx + OFFSETOF__ExInfo__m_passNumber], 1 ;; init to the first pass - mov dword ptr [edx + OFFSETOF__ExInfo__m_idxCurClause], 0FFFFFFFFh - mov byte ptr [edx + OFFSETOF__ExInfo__m_kind], 2 ;; ExKind.HardwareFault - - ;; link the ExInfo into the thread's ExInfo chain - mov ebx, [eax + OFFSETOF__Thread__m_pExInfoStackHead] - mov [edx + OFFSETOF__ExInfo__m_pPrevExInfo], ebx ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [eax + OFFSETOF__Thread__m_pExInfoStackHead], edx ;; m_pExInfoStackHead = pExInfo + lea ecx, [esp + esp_offsetof_ExInfo] ;; ecx <- ExInfo* + lea edx, [esp + esp_offsetof_Context] ;; edx <- PAL_LIMITED_CONTEXT* + push 2 ;; ExKind.HardwareFault + call RhpPushExInfo - ;; set the exception context field on the ExInfo - lea ebx, [esp + esp_offsetof_Context] ;; ebx <- PAL_LIMITED_CONTEXT* - mov [edx + OFFSETOF__ExInfo__m_pExContext], ebx ;; init ExInfo.m_pExContext - - ;; ecx still contains the exception code - ;; edx contains the address of the ExInfo + mov ecx, ebx ;; ecx <- exception code + lea edx, [esp + esp_offsetof_ExInfo] ;; edx <- ExInfo* call RhThrowHwEx ALTERNATE_ENTRY _RhpThrowHwEx2 @@ -134,41 +122,15 @@ FASTCALL_FUNC RhpThrowImpl, 8 sub esp, SIZEOF__ExInfo - ;; ------------------------- - - lea ebx, [ebp+4] ;; ebx <- addr of return address - INLINE_GETTHREAD eax, edi ;; eax <- thread, edi <- trashed - - ;; There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return - ;; address could have been hijacked when we were in that C# code and we must remove the hijack and - ;; reflect the correct return address in our exception context record. The other throw helpers don't - ;; need this because they cannot be tail-called from C#. - - INLINE_THREAD_UNHIJACK eax, esi, edi ;; trashes esi, edi - - mov edi, [ebx] ;; edi <- return address - mov [esp + esp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP], edi ;; set 'faulting' IP after unhijack + mov ebx, ecx ;; ebx <- exception object - lea edi, [esp + esp_offsetof_ExInfo] ;; edi <- ExInfo* + lea ecx, [esp + esp_offsetof_ExInfo] ;; ecx <- ExInfo* + push edx ;; ExKind + lea edx, [esp + 4 + esp_offsetof_Context] ;; edx <- PAL_LIMITED_CONTEXT* + call RhpPushExInfo - xor esi, esi - mov [edi + OFFSETOF__ExInfo__m_exception], esi ;; init the exception object to null - mov byte ptr [edi + OFFSETOF__ExInfo__m_passNumber], 1 ;; init to the first pass - mov dword ptr [edi + OFFSETOF__ExInfo__m_idxCurClause], 0FFFFFFFFh - mov byte ptr [edi + OFFSETOF__ExInfo__m_kind], dl ;; ExKind - - ;; link the ExInfo into the thread's ExInfo chain - mov ebx, [eax + OFFSETOF__Thread__m_pExInfoStackHead] - mov [edi + OFFSETOF__ExInfo__m_pPrevExInfo], ebx ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [eax + OFFSETOF__Thread__m_pExInfoStackHead], edi ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - lea ebx, [esp + esp_offsetof_Context] ;; ebx <- PAL_LIMITED_CONTEXT* - mov [edi + OFFSETOF__ExInfo__m_pExContext], ebx ;; init ExInfo.m_pExContext - mov edx, edi - - ;; ecx still contains the exception object - ;; edx contains the address of the ExInfo + mov ecx, ebx ;; ecx <- exception object + lea edx, [esp + esp_offsetof_ExInfo] ;; edx <- ExInfo* call RhThrowEx ALTERNATE_ENTRY _RhpThrowImpl2 @@ -216,28 +178,13 @@ FASTCALL_FUNC RhpRethrow, 0 ;; ------------------------- - lea ebx, [eax-4] ;; ebx <- addr of return address - INLINE_GETTHREAD eax, edx ;; eax <- thread, edx <- trashed - - lea edx, [esp + esp_offsetof_ExInfo] ;; edx <- ExInfo* + lea ecx, [esp + esp_offsetof_ExInfo] ;; ecx <- ExInfo* + lea edx, [esp + esp_offsetof_Context] ;; edx <- PAL_LIMITED_CONTEXT* + push 0 ;; ExKind.None + call RhpPushExInfo - xor esi, esi - mov [edx + OFFSETOF__ExInfo__m_exception], esi ;; init the exception object to null - mov byte ptr [edx + OFFSETOF__ExInfo__m_passNumber], 1 ;; init to the first pass - mov dword ptr [edx + OFFSETOF__ExInfo__m_idxCurClause], 0FFFFFFFFh - mov byte ptr [edx + OFFSETOF__ExInfo__m_kind], 0 ;; init to a deterministic value (ExKind.None) - - ;; link the ExInfo into the thread's ExInfo chain - mov ecx, [eax + OFFSETOF__Thread__m_pExInfoStackHead] ;; ecx <- currently active ExInfo - mov [edx + OFFSETOF__ExInfo__m_pPrevExInfo], ecx ;; pExInfo->m_pPrevExInfo = m_pExInfoStackHead - mov [eax + OFFSETOF__Thread__m_pExInfoStackHead], edx ;; m_pExInfoStackHead = pExInfo - - ;; set the exception context field on the ExInfo - lea ebx, [esp + esp_offsetof_Context] ;; ebx <- PAL_LIMITED_CONTEXT* - mov [edx + OFFSETOF__ExInfo__m_pExContext], ebx ;; init ExInfo.m_pExContext - - ;; ecx contains the currently active ExInfo - ;; edx contains the address of the new ExInfo + mov ecx, eax ;; ecx <- currently active ExInfo + lea edx, [esp + esp_offsetof_ExInfo] ;; edx <- ExInfo* call RhRethrow ALTERNATE_ENTRY _RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/i386/UniversalTransition.asm b/src/coreclr/nativeaot/Runtime/i386/UniversalTransition.asm deleted file mode 100644 index 7e780380bdc737..00000000000000 --- a/src/coreclr/nativeaot/Runtime/i386/UniversalTransition.asm +++ /dev/null @@ -1,89 +0,0 @@ -;; Licensed to the .NET Foundation under one or more agreements. -;; The .NET Foundation licenses this file to you under the MIT license. - - .586 - .model flat - option casemap:none - .code - -include AsmMacros.inc - -;; -;; Defines an assembly thunk used to make a transition from managed code to a callee, -;; then (based on the return value from the callee), either returning or jumping to -;; a new location while preserving the input arguments. The usage of this thunk also -;; ensures arguments passed are properly reported. -;; -;; TODO: This code currently only tailcalls, and does not return. -;; -;; Inputs: -;; ecx, edx, stack space three pops down: arguments as normal -;; first register sized fields on the stack is the location of the target code -;; the UniversalTransitionThunk will call -;; second register sized field on the stack is the parameter to the target function -;; followed by the return address of the whole method. (This method cannot be called -;; via a call instruction, it must be jumped to.) The fake entrypoint is in place to -;; convince the stack walker this is a normal framed function. -;; -;; NOTE! FOR CORRECTNESS THIS FUNCTION REQUIRES THAT ALL NON-LEAF MANAGED FUNCTIONS HAVE -;; FRAME POINTERS, OR THE STACK WALKER CAN'T STACKWALK OUT OF HERE -;; - -; -; Frame layout is: -; -; {StackPassedArgs} ChildSP+018 CallerSP+000 -; {CallerRetaddr} ChildSP+014 CallerSP-004 -; {CallerEBP} ChildSP+010 CallerSP-008 -; {ReturnBlock (0x8 bytes)} ChildSP+008 CallerSP-010 -; -- On input (i.e., when control jumps to RhpUniversalTransition), the low 4 bytes of -; the ReturnBlock area holds the address of the callee and the high 4 bytes holds the -; extra argument to pass to the callee. -; {IntArgRegs (edx,ecx) (0x8 bytes)} ChildSP+000 CallerSP-018 -; {CalleeRetaddr} ChildSP-004 CallerSP-01c -; -; NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -; must be updated as well. -; -; NOTE: The callee receives a pointer to the base of the pushed IntArgRegs, and the callee -; has knowledge of the exact layout of the entire frame. -; -; NOTE: The stack walker guarantees that conservative GC reporting will be applied to -; everything between the base of the IntArgRegs and the top of the StackPassedArgs. -; - -UNIVERSAL_TRANSITION macro FunctionName - -FASTCALL_FUNC Rhp&FunctionName&_FAKE_ENTRY, 0 - ; Set up an ebp frame - push ebp - mov ebp, esp - push eax - push eax -ALTERNATE_ENTRY _Rhp&FunctionName&@0 - push ecx - push edx - - ; - ; Call out to the target, while storing and reporting arguments to the GC. - ; - mov eax, [ebp-8] ; Get the address of the callee - mov edx, [ebp-4] ; Get the extra argument to pass to the callee - lea ecx, [ebp-10h] ; Get pointer to edx value pushed above - call eax - -ALTERNATE_ENTRY _ReturnFrom&FunctionName - - pop edx - pop ecx - add esp, 8 - pop ebp - jmp eax - -FASTCALL_ENDFUNC - - endm - - UNIVERSAL_TRANSITION UniversalTransitionTailCall - -end diff --git a/src/coreclr/nativeaot/Runtime/loongarch64/DispatchResolve.S b/src/coreclr/nativeaot/Runtime/loongarch64/DispatchResolve.S index b352e3371e11a9..60588f033ed49a 100644 --- a/src/coreclr/nativeaot/Runtime/loongarch64/DispatchResolve.S +++ b/src/coreclr/nativeaot/Runtime/loongarch64/DispatchResolve.S @@ -13,12 +13,8 @@ LEAF_ENTRY RhpInterfaceDispatch, _TEXT // to a NullReferenceException at the callsite. ld.d $zero, $a0, 0 - // $t8 currently contains the indirection cell address. - // Calling convention of the universal thunk is: - // $t7: target address for the thunk to call - // $t8: parameter of the thunk's target - PREPARE_EXTERNAL_VAR RhpCidResolve, $t7 - b C_FUNC(RhpUniversalTransitionTailCall) + // $t8 contains the indirection cell address + b C_FUNC(RhpInterfaceDispatchSlow) LEAF_END RhpInterfaceDispatch, _TEXT @@ -33,3 +29,25 @@ LEAF_ENTRY RhpDispatchResolve, _TEXT b C_FUNC(RhpResolveInterfaceMethod) LEAF_END RhpDispatchResolve, _TEXT + +// t8: interface dispatch cell, arguments passed in registers and stack space as normal + NESTED_ENTRY RhpInterfaceDispatchSlow, _TEXT, NoHandler + + // NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout + PROLOG_WITH_TRANSITION_BLOCK + + // a0 still contains 'this' + ori $a1, $t8, 0 + bl C_FUNC(RhpCidResolve) + + ALTERNATE_ENTRY ReturnFromInterfaceDispatchSlow + + // Move the result (the target address) to t3 so it doesn't get overridden when we restore the + // argument registers. + ori $t3, $a0, 0 + + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + + jirl $r0, $t3, 0 + + NESTED_END RhpInterfaceDispatchSlow, _TEXT diff --git a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S index d33d5926f3c5bc..636f55d84729cc 100644 --- a/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/loongarch64/ExceptionHandling.S @@ -52,17 +52,6 @@ addi.d $sp, $sp, -STACKSIZEOF_ExInfo .endm -.macro GetThreadA2 - addi.d $sp, $sp, -16 - st.d $a0, $sp, 0 - st.d $a1, $sp, 8 - bl C_FUNC(RhpGetThread) - ori $a2, $a0, 0 - ld.d $a0, $sp, 0 - ld.d $a1, $sp, 8 - addi.d $sp, $sp, 16 -.endm - #define rsp_offsetof_ExInfo 0 #define rsp_offsetof_Context STACKSIZEOF_ExInfo @@ -78,28 +67,15 @@ ALLOC_THROW_FRAME HARDWARE_EXCEPTION - GetThreadA2 + ori $r23, $a0, 0 // r23 <- exception code + + addi.d $a0, $sp, rsp_offsetof_ExInfo // a0 <- ExInfo* + addi.d $a1, $sp, rsp_offsetof_Context // a1 <- PAL_LIMITED_CONTEXT* + ori $a2, $zero, 2 // a2 <- ExKind.HardwareFault + bl C_FUNC(RhpPushExInfo) + ori $a0, $r23, 0 // a0 <- exception code addi.d $a1, $sp, rsp_offsetof_ExInfo // a1 <- ExInfo* - st.d $zero, $a1, OFFSETOF__ExInfo__m_exception // pExInfo->m_exception = null - ori $a3, $zero, 1 - st.b $a3, $a1, OFFSETOF__ExInfo__m_passNumber // pExInfo->m_passNumber = 1 - addi.w $a3, $zero, -1 - st.w $a3, $a1, OFFSETOF__ExInfo__m_idxCurClause // pExInfo->m_idxCurClause = MaxTryRegionIdx - ori $a3, $zero, 2 - st.b $a3, $a1, OFFSETOF__ExInfo__m_kind // pExInfo->m_kind = ExKind.HardwareFault - - // link the ExInfo into the thread's ExInfo chain - ld.d $a3, $a2, OFFSETOF__Thread__m_pExInfoStackHead - st.d $a3, $a1, OFFSETOF__ExInfo__m_pPrevExInfo // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - st.d $a1, $a2, OFFSETOF__Thread__m_pExInfoStackHead // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - addi.d $a2, $sp, rsp_offsetof_Context // a2 <- PAL_LIMITED_CONTEXT* - st.d $a2, $a1, OFFSETOF__ExInfo__m_pExContext // pExInfo->m_pExContext = pContext - - // a0[31:0]: exception code - // a1: ExInfo* bl C_FUNC(RhThrowHwEx) ALTERNATE_ENTRY RhpThrowHwEx2 @@ -144,72 +120,16 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - ori $r23, $a4, 0 // Save ExKind - - GetThreadA2 - - // There is runtime C# code that can tail call to RhpThrowEx using a binder intrinsic. So the return - // address could have been hijacked when we were in that C# code and we must remove the hijack and - // reflect the correct return address in our exception context record. The other throw helpers don't - // need this because they cannot be tail-called from C#. - - // NOTE: we cannot use INLINE_THREAD_UNHIJACK because it will write into the stack at the location - // where the tail-calling thread had saved RA, which may not match where we have saved RA. - - ld.d $a1, $a2, OFFSETOF__Thread__m_pvHijackedReturnAddress - beqz $a1, LOCAL_LABEL(NotHijacked) - - ld.d $a3, $a2, OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation - - // a0: exception object - // a1: hijacked return address - // a2: pThread - // a3: hijacked return address location - - addi.d $t3, $sp, (STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) // re-compute SP at callsite - bltu $a3, $t3, LOCAL_LABEL(TailCallWasHijacked) // if (m_ppvHijackedReturnAddressLocation < SP at callsite) - // normal case where a valid return address location is hijacked - st.d $a1, $a3, 0 - b LOCAL_LABEL(ClearThreadState) + ori $r23, $a0, 0 // r23 <- exception object -LOCAL_LABEL(TailCallWasHijacked): - - // Abnormal case where the return address location is now invalid because we ended up here via a tail - // call. In this case, our hijacked return address should be the correct caller of this method. - - // stick the previous return address in RA as well as in the right spots in our PAL_LIMITED_CONTEXT. - ori $ra, $a1, 0 - st.d $ra, $sp, (rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__RA) - st.d $ra, $sp, (rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP) - -LOCAL_LABEL(ClearThreadState): - - // clear the Thread's hijack state - st.d $zero, $a2, OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation - st.d $zero, $a2, OFFSETOF__Thread__m_pvHijackedReturnAddress - -LOCAL_LABEL(NotHijacked): + addi.d $a0, $sp, rsp_offsetof_ExInfo // a0 <- ExInfo* + addi.d $a1, $sp, rsp_offsetof_Context // a1 <- PAL_LIMITED_CONTEXT* + ori $a2, $a4, 0 // a2 <- ExKind + bl C_FUNC(RhpPushExInfo) + ori $a0, $r23, 0 // a0 <- exception object addi.d $a1, $sp, rsp_offsetof_ExInfo // a1 <- ExInfo* - st.d $zero, $a1, OFFSETOF__ExInfo__m_exception // pExInfo->m_exception = null - ori $a3, $zero, 1 - st.b $a3, $a1, OFFSETOF__ExInfo__m_passNumber // pExInfo->m_passNumber = 1 - addi.w $a3, $zero, -1 - st.w $a3, $a1, OFFSETOF__ExInfo__m_idxCurClause // pExInfo->m_idxCurClause = MaxTryRegionIdx - st.b $r23, $a1, OFFSETOF__ExInfo__m_kind // pExInfo->m_kind = ExKind - - // link the ExInfo into the thread's ExInfo chain - ld.d $a3, $a2, OFFSETOF__Thread__m_pExInfoStackHead - st.d $a3, $a1, OFFSETOF__ExInfo__m_pPrevExInfo // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - st.d $a1, $a2, OFFSETOF__Thread__m_pExInfoStackHead // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - addi.d $a2, $sp, rsp_offsetof_Context // a2 <- PAL_LIMITED_CONTEXT* - st.d $a2, $a1, OFFSETOF__ExInfo__m_pExContext // pExInfo->m_pExContext = pContext - - // a0: exception object - // a1: ExInfo* bl C_FUNC(RhThrowEx) ALTERNATE_ENTRY RhpThrowImpl2 @@ -232,28 +152,13 @@ LOCAL_LABEL(NotHijacked): ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - GetThreadA2 - - addi.d $a1, $sp, rsp_offsetof_ExInfo // a1 <- ExInfo* - st.d $zero, $a1, OFFSETOF__ExInfo__m_exception // pExInfo->m_exception = null - st.b $zero, $a1, OFFSETOF__ExInfo__m_kind // init to a deterministic value (ExKind.None) - ori $a3, $zero, 1 - st.b $a3, $a1, OFFSETOF__ExInfo__m_passNumber // pExInfo->m_passNumber = 1 - addi.w $a3, $zero, -1 - st.w $a3, $a1, OFFSETOF__ExInfo__m_idxCurClause // pExInfo->m_idxCurClause = MaxTryRegionIdx - - // link the ExInfo into the thread's ExInfo chain - ld.d $a3, $a2, OFFSETOF__Thread__m_pExInfoStackHead - ori $a0, $a3, 0 // a0 <- current ExInfo - st.d $a3, $a1, OFFSETOF__ExInfo__m_pPrevExInfo // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - st.d $a1, $a2, OFFSETOF__Thread__m_pExInfoStackHead // m_pExInfoStackHead = pExInfo - - // set the exception context field on the ExInfo - addi.d $a2, $sp, rsp_offsetof_Context // a2 <- PAL_LIMITED_CONTEXT* - st.d $a2, $a1, OFFSETOF__ExInfo__m_pExContext // pExInfo->m_pExContext = pContext + addi.d $a0, $sp, rsp_offsetof_ExInfo // a0 <- ExInfo* + addi.d $a1, $sp, rsp_offsetof_Context // a1 <- PAL_LIMITED_CONTEXT* + ori $a2, $zero, 0 // a2 <- ExKind.None + bl C_FUNC(RhpPushExInfo) // a0 contains the currently active ExInfo - // a1 contains the address of the new ExInfo + addi.d $a1, $sp, rsp_offsetof_ExInfo // a1 <- ExInfo* bl C_FUNC(RhRethrow) ALTERNATE_ENTRY RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/loongarch64/UniversalTransition.S b/src/coreclr/nativeaot/Runtime/loongarch64/UniversalTransition.S deleted file mode 100644 index 92b7c2131f218d..00000000000000 --- a/src/coreclr/nativeaot/Runtime/loongarch64/UniversalTransition.S +++ /dev/null @@ -1,162 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include - -#ifdef _DEBUG -#define TRASH_SAVED_ARGUMENT_REGISTERS -#endif - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - .global RhpIntegerTrashValues - .global RhpFpTrashValues -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - -#define COUNT_ARG_REGISTERS (8) -#define INTEGER_REGISTER_SIZE (8) -#define ARGUMENT_REGISTERS_SIZE (COUNT_ARG_REGISTERS * INTEGER_REGISTER_SIZE) - -// Largest return block is 2 doubles -#define RETURN_BLOCK_SIZE (16) - -#define COUNT_FLOAT_ARG_REGISTERS (8) -#define FLOAT_REGISTER_SIZE (8) -#define FLOAT_ARG_REGISTERS_SIZE (COUNT_FLOAT_ARG_REGISTERS * FLOAT_REGISTER_SIZE) - -#define PUSHED_RA_SIZE (8) -#define PUSHED_FP_SIZE (8) - -// -// From CallerSP to ChildSP, the stack frame is composed of the following adjacent regions: -// -// ARGUMENT_REGISTERS_SIZE -// RETURN_BLOCK_SIZE -// FLOAT_ARG_REGISTERS_SIZE -// PUSHED_RA_SIZE -// PUSHED_FP_SIZE -// - -#define DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK (PUSHED_FP_SIZE + PUSHED_RA_SIZE + FLOAT_ARG_REGISTERS_SIZE) - -#define STACK_SIZE (ARGUMENT_REGISTERS_SIZE + RETURN_BLOCK_SIZE + FLOAT_ARG_REGISTERS_SIZE + PUSHED_RA_SIZE + PUSHED_FP_SIZE) - -#define FLOAT_ARG_OFFSET (PUSHED_FP_SIZE + PUSHED_RA_SIZE) -#define ARGUMENT_REGISTERS_OFFSET (FLOAT_ARG_OFFSET + FLOAT_ARG_REGISTERS_SIZE + RETURN_BLOCK_SIZE) - -// -// RhpUniversalTransition -// -// At input to this function, a0-a7, f0-f7 and the stack may contain any number of arguments. -// -// In addition, there are 2 extra arguments passed in the intra-procedure-call scratch register: -// t7 will contain the managed function that is to be called by this transition function -// t8 will contain the pointer sized extra argument to the managed function -// -// When invoking the callee: -// -// a0 shall contain a pointer to the TransitionBlock -// a1 shall contain the value that was in t8 at entry to this function -// -// Frame layout is: -// -// {StackPassedArgs} ChildSP+0A0 CallerSP+000 -// {IntArgRegs (a0-a7) (0x40 bytes)} ChildSP+060 CallerSP-040 -// {ReturnBlock (0x10 bytes)} ChildSP+050 CallerSP-050 -// -- The base address of the Return block is the TransitionBlock pointer, the floating point args are -// in the neg space of the TransitionBlock pointer. Note that the callee has knowledge of the exact -// layout of all pieces of the frame that lie at or above the pushed floating point registers. -// {FpArgRegs (f0-f7) (0x40 bytes)} ChildSP+010 CallerSP-090 -// {PushedRA} ChildSP+008 CallerSP-098 -// {PushedFP} ChildSP+000 CallerSP-0A0 -// -// NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -// must be updated as well. -// -// NOTE: The callee receives a pointer to the base of the ReturnBlock, and the callee has -// knowledge of the exact layout of all pieces of the frame that lie at or above the pushed -// FpArgRegs. -// -// NOTE: The stack walker guarantees that conservative GC reporting will be applied to -// everything between the base of the ReturnBlock and the top of the StackPassedArgs. -// - - .text - - .macro UNIVERSAL_TRANSITION FunctionName - - NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler - - // FP and RA registers - PROLOG_SAVE_REG_PAIR_INDEXED 22, 1, STACK_SIZE // ;; Push down stack pointer and store FP and RA - - // Floating point registers - SAVE_FLOAT_ARGUMENT_REGISTERS $sp, FLOAT_ARG_OFFSET - - // Space for return buffer data (0x10 bytes) - - // Save argument registers - SAVE_ARGUMENT_REGISTERS $sp, ARGUMENT_REGISTERS_OFFSET - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - PREPARE_EXTERNAL_VAR RhpFpTrashValues, $a1 - - fld.d $f0, $a1, 0 - fld.d $f1, $a1, 0x08 - fld.d $f2, $a1, 0x10 - fld.d $f3, $a1, 0x18 - fld.d $f4, $a1, 0x20 - fld.d $f5, $a1, 0x28 - fld.d $f6, $a1, 0x30 - fld.d $f7, $a1, 0x38 - - PREPARE_EXTERNAL_VAR RhpIntegerTrashValues, $a1 - - ld.d $a2, $a1, 0x10 - ld.d $a3, $a1, 0x18 - ld.d $a4, $a1, 0x20 - ld.d $a5, $a1, 0x28 - ld.d $a6, $a1, 0x30 - ld.d $a7, $a1, 0x38 -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - - addi.d $a0, $sp, DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK // First parameter to target function is a pointer to the return block - ori $a1, $t8, 0 // Second parameter to target function - jirl $ra, $t7, 0 - - ALTERNATE_ENTRY ReturnFrom\FunctionName - - // Move the result (the target address) to t3 so it doesn't get overridden when we restore the - // argument registers. - ori $t3, $a0, 0 - - // Restore floating point registers - fld.d $f0, $sp, FLOAT_ARG_OFFSET - fld.d $f1, $sp, FLOAT_ARG_OFFSET + 0x08 - fld.d $f2, $sp, FLOAT_ARG_OFFSET + 0x10 - fld.d $f3, $sp, FLOAT_ARG_OFFSET + 0x18 - fld.d $f4, $sp, FLOAT_ARG_OFFSET + 0x20 - fld.d $f5, $sp, FLOAT_ARG_OFFSET + 0x28 - fld.d $f6, $sp, FLOAT_ARG_OFFSET + 0x30 - fld.d $f7, $sp, FLOAT_ARG_OFFSET + 0x38 - - // Restore the argument registers - ld.d $a0, $sp, ARGUMENT_REGISTERS_OFFSET - ld.d $a1, $sp, ARGUMENT_REGISTERS_OFFSET + 0x08 - ld.d $a2, $sp, ARGUMENT_REGISTERS_OFFSET + 0x10 - ld.d $a3, $sp, ARGUMENT_REGISTERS_OFFSET + 0x18 - ld.d $a4, $sp, ARGUMENT_REGISTERS_OFFSET + 0x20 - ld.d $a5, $sp, ARGUMENT_REGISTERS_OFFSET + 0x28 - ld.d $a6, $sp, ARGUMENT_REGISTERS_OFFSET + 0x30 - ld.d $a7, $sp, ARGUMENT_REGISTERS_OFFSET + 0x38 - - // Restore FP and RA registers, and free the allocated stack block - EPILOG_RESTORE_REG_PAIR_INDEXED 22, 1, STACK_SIZE - - // Tailcall to the target address. - jirl $r0, $t3, 0 - - NESTED_END Rhp\FunctionName, _TEXT - - .endm - - UNIVERSAL_TRANSITION UniversalTransitionTailCall diff --git a/src/coreclr/nativeaot/Runtime/portable.cpp b/src/coreclr/nativeaot/Runtime/portable.cpp index 19c3feb209334c..e407ff3a2e0eef 100644 --- a/src/coreclr/nativeaot/Runtime/portable.cpp +++ b/src/coreclr/nativeaot/Runtime/portable.cpp @@ -33,9 +33,9 @@ #include "GCMemoryHelpers.inl" #if defined(FEATURE_PORTABLE_HELPERS) -// @TODO Implement UniversalTransitionTailCall -EXTERN_C void * ReturnFromUniversalTransitionTailCall; -void * ReturnFromUniversalTransitionTailCall; +// @TODO Implement RhpInterfaceDispatchSlow +EXTERN_C void * ReturnFromInterfaceDispatchSlow; +void * ReturnFromInterfaceDispatchSlow; #if !defined(HOST_WASMARCH) FCIMPL2_RAW(void, RhpAssignRef, Object ** dst, Object * ref) diff --git a/src/coreclr/nativeaot/Runtime/ppc64le/UniversalTransition.S b/src/coreclr/nativeaot/Runtime/ppc64le/UniversalTransition.S deleted file mode 100644 index 8ccdf87b55e2b2..00000000000000 --- a/src/coreclr/nativeaot/Runtime/ppc64le/UniversalTransition.S +++ /dev/null @@ -1,4 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include diff --git a/src/coreclr/nativeaot/Runtime/riscv64/DispatchResolve.S b/src/coreclr/nativeaot/Runtime/riscv64/DispatchResolve.S index 3c7a07e1078938..65297850b2a570 100644 --- a/src/coreclr/nativeaot/Runtime/riscv64/DispatchResolve.S +++ b/src/coreclr/nativeaot/Runtime/riscv64/DispatchResolve.S @@ -134,18 +134,10 @@ LOCAL_LABEL(ProbeMiss\@): LOCAL_LABEL(CacheMiss\@): .if \ReturnTarget - tail C_FUNC(RhpCidResolve_Worker) + tail C_FUNC(RhpCidResolve) .else - // Calling convention of the universal thunk is: - // t0: target address for the thunk to call - // t1: parameter of the thunk's target - PREPARE_EXTERNAL_VAR RhpCidResolve, t0 - mv t1, \DispatchCellReg - // The tail call is written out by hand because the "tail" pseudo-instruction - // expands through t1, which is carrying the thunk parameter set just above. -1: - auipc t2, %pcrel_hi(C_FUNC(RhpUniversalTransitionTailCall)) - jalr x0, t2, %pcrel_lo(1b) + // DispatchCellReg (t5) contains the indirection cell address + tail C_FUNC(RhpInterfaceDispatchSlow) .endif LEAF_END \DispatchName, _TEXT @@ -154,3 +146,25 @@ LEAF_END \DispatchName, _TEXT INTERFACE_DISPATCH RhpInterfaceDispatch, 0, t5 INTERFACE_DISPATCH RhpDispatchResolve, 1, a1 + +// t5: interface dispatch cell, arguments passed in registers and stack space as normal + NESTED_ENTRY RhpInterfaceDispatchSlow, _TEXT, NoHandler + + // NOTE: StackFrameIterator::UnwindInterfaceDispatchSlowThunk hard-codes the frame layout + PROLOG_WITH_TRANSITION_BLOCK + + // a0 still contains 'this' + mv a1, t5 + call C_FUNC(RhpCidResolve) + +ALTERNATE_ENTRY ReturnFromInterfaceDispatchSlow + + // Move the result (the target address) to t2 so it doesn't get overridden when we restore the + // argument registers. + mv t2, a0 + + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + + jr t2 + + NESTED_END RhpInterfaceDispatchSlow, _TEXT diff --git a/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S b/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S index fcc19b5a5206a7..a18790f32be13a 100644 --- a/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S +++ b/src/coreclr/nativeaot/Runtime/riscv64/ExceptionHandling.S @@ -58,17 +58,6 @@ addi sp, sp, -STACKSIZEOF_ExInfo .endm -.macro GetThreadA2 - addi sp, sp, -16 - sd a0, 0(sp) - sd a1, 8(sp) - call C_FUNC(RhpGetThread) - mv a2, a0 - ld a0, 0(sp) - ld a1, 8(sp) - addi sp, sp, 16 -.endm - #define rsp_offsetof_ExInfo 0 #define rsp_offsetof_Context STACKSIZEOF_ExInfo @@ -85,29 +74,15 @@ ALLOC_THROW_FRAME HARDWARE_EXCEPTION - GetThreadA2 + mv s1, a0 // s1 <- exception code - // Compute address for ExInfo* + addi a0, sp, rsp_offsetof_ExInfo // a0 <- ExInfo* + addi a1, sp, rsp_offsetof_Context // a1 <- PAL_LIMITED_CONTEXT* + li a2, 2 // a2 <- ExKind.HardwareFault + call C_FUNC(RhpPushExInfo) + + mv a0, s1 // a0 <- exception code addi a1, sp, rsp_offsetof_ExInfo // a1 <- ExInfo* - sd zero, OFFSETOF__ExInfo__m_exception(a1) // pExInfo->m_exception = null - li a3, 1 - sb a3, OFFSETOF__ExInfo__m_passNumber(a1) // pExInfo->m_passNumber = 1 - addiw a3, zero, -1 - sw a3, OFFSETOF__ExInfo__m_idxCurClause(a1) // pExInfo->m_idxCurClause = MaxTryRegionIdx - li a3, 2 - sb a3, OFFSETOF__ExInfo__m_kind(a1) // pExInfo->m_kind = ExKind.HardwareFault - - // Link the ExInfo into the thread's ExInfo chain - ld a3, OFFSETOF__Thread__m_pExInfoStackHead(a2) - sd a3, OFFSETOF__ExInfo__m_pPrevExInfo(a1) // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - sd a1, OFFSETOF__Thread__m_pExInfoStackHead(a2) // m_pExInfoStackHead = pExInfo - - // Set the exception context field on the ExInfo - addi a2, sp, rsp_offsetof_Context // a2 <- PAL_LIMITED_CONTEXT* - sd a2, OFFSETOF__ExInfo__m_pExContext(a1) // pExInfo->m_pExContext = pContext - - // a0[31:0]: exception code - // a1: ExInfo* call C_FUNC(RhThrowHwEx) ALTERNATE_ENTRY RhpThrowHwEx2 @@ -152,63 +127,16 @@ NESTED_ENTRY RhpThrowImpl, _TEXT, NoHandler ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - mv s1, a4 // Save ExKind - - GetThreadA2 - - ld a1, OFFSETOF__Thread__m_pvHijackedReturnAddress(a2) - beq a1, zero, LOCAL_LABEL(NotHijacked) - - ld a3, OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation(a2) - - // Recompute SP at callsite - addi t3, sp, (STACKSIZEOF_ExInfo + SIZEOF__PAL_LIMITED_CONTEXT) - bltu a3, t3, LOCAL_LABEL(TailCallWasHijacked) // if (m_ppvHijackedReturnAddressLocation < SP at callsite) - // Normal case where a valid return address location is hijacked - sd a1, 0(a3) - j LOCAL_LABEL(ClearThreadState) + mv s1, a0 // s1 <- exception object -LOCAL_LABEL(TailCallWasHijacked): + addi a0, sp, rsp_offsetof_ExInfo // a0 <- ExInfo* + addi a1, sp, rsp_offsetof_Context // a1 <- PAL_LIMITED_CONTEXT* + mv a2, a4 // a2 <- ExKind + call C_FUNC(RhpPushExInfo) - // Abnormal case where the return address location is now invalid because we ended up here via a tail - // call. In this case, our hijacked return address should be the correct caller of this method. - - // Stick the previous return address in RA as well as in the right spots in our PAL_LIMITED_CONTEXT. - mv ra, a1 - - // Compute offsets for PAL_LIMITED_CONTEXT - sd ra, (rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__RA)(sp) - sd ra, (rsp_offsetof_Context + OFFSETOF__PAL_LIMITED_CONTEXT__IP)(sp) - -LOCAL_LABEL(ClearThreadState): - - // Clear the Thread's hijack state - sd zero, OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation(a2) - sd zero, OFFSETOF__Thread__m_pvHijackedReturnAddress(a2) - -LOCAL_LABEL(NotHijacked): - - // Compute the offset for ExInfo + mv a0, s1 // a0 <- exception object addi a1, sp, rsp_offsetof_ExInfo // a1 <- ExInfo* - sd zero, OFFSETOF__ExInfo__m_exception(a1) // pExInfo->m_exception = null - li a3, 1 - sb a3, OFFSETOF__ExInfo__m_passNumber(a1) // pExInfo->m_passNumber = 1 - addiw a3, zero, -1 - sw a3, OFFSETOF__ExInfo__m_idxCurClause(a1) // pExInfo->m_idxCurClause = MaxTryRegionIdx - sb s1, OFFSETOF__ExInfo__m_kind(a1) // pExInfo->m_kind = ExKind - - // Link the ExInfo into the thread's ExInfo chain - ld a3, OFFSETOF__Thread__m_pExInfoStackHead(a2) - sd a3, OFFSETOF__ExInfo__m_pPrevExInfo(a1) // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - sd a1, OFFSETOF__Thread__m_pExInfoStackHead(a2) // m_pExInfoStackHead = pExInfo - - // Set the exception context field on the ExInfo - addi a2, sp, rsp_offsetof_Context // a2 <- PAL_LIMITED_CONTEXT* - sd a2, OFFSETOF__ExInfo__m_pExContext(a1) // pExInfo->m_pExContext = pContext - - // a0: exception object - // a1: ExInfo* call C_FUNC(RhThrowEx) ALTERNATE_ENTRY RhpThrowImpl2 @@ -230,38 +158,13 @@ LOCAL_LABEL(NotHijacked): ALLOC_THROW_FRAME SOFTWARE_EXCEPTION - GetThreadA2 - - // a1 <- ExInfo* - addi a1, sp, rsp_offsetof_ExInfo - // pExInfo->m_exception = null - sd zero, OFFSETOF__ExInfo__m_exception(a1) - // init to a deterministic value (ExKind.None) - sb zero, OFFSETOF__ExInfo__m_kind(a1) - // pExInfo->m_passNumber = 1 - li a3, 1 - sb a3, OFFSETOF__ExInfo__m_passNumber(a1) - // pExInfo->m_idxCurClause = MaxTryRegionIdx - addiw a3, zero, -1 - sw a3, OFFSETOF__ExInfo__m_idxCurClause(a1) - - // link the ExInfo into the thread's ExInfo chain - ld a3, OFFSETOF__Thread__m_pExInfoStackHead(a2) - // a0 <- current ExInfo - mv a0, a3 - // pExInfo->m_pPrevExInfo = m_pExInfoStackHead - sd a3, OFFSETOF__ExInfo__m_pPrevExInfo(a1) - // m_pExInfoStackHead = pExInfo - sd a1, OFFSETOF__Thread__m_pExInfoStackHead(a2) - - // set the exception context field on the ExInfo - // a2 <- PAL_LIMITED_CONTEXT* - addi a2, sp, rsp_offsetof_Context - // pExInfo->m_pExContext = pContext - sd a2, OFFSETOF__ExInfo__m_pExContext(a1) + addi a0, sp, rsp_offsetof_ExInfo // a0 <- ExInfo* + addi a1, sp, rsp_offsetof_Context // a1 <- PAL_LIMITED_CONTEXT* + li a2, 0 // a2 <- ExKind.None + call C_FUNC(RhpPushExInfo) // a0 contains the currently active ExInfo - // a1 contains the address of the new ExInfo + addi a1, sp, rsp_offsetof_ExInfo // a1 <- ExInfo* call C_FUNC(RhRethrow) ALTERNATE_ENTRY RhpRethrow2 diff --git a/src/coreclr/nativeaot/Runtime/riscv64/UniversalTransition.S b/src/coreclr/nativeaot/Runtime/riscv64/UniversalTransition.S deleted file mode 100644 index db695646a127e9..00000000000000 --- a/src/coreclr/nativeaot/Runtime/riscv64/UniversalTransition.S +++ /dev/null @@ -1,149 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include - -#ifdef _DEBUG -#define TRASH_SAVED_ARGUMENT_REGISTERS -#endif - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - .global RhpIntegerTrashValues - .global RhpFpTrashValues -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - -#define COUNT_ARG_REGISTERS (8) -#define INTEGER_REGISTER_SIZE (8) -#define ARGUMENT_REGISTERS_SIZE (COUNT_ARG_REGISTERS * INTEGER_REGISTER_SIZE) - -// Largest return block is 4 doubles -#define RETURN_BLOCK_SIZE 16 - -#define COUNT_FLOAT_ARG_REGISTERS (8) -#define FLOAT_REGISTER_SIZE (8) -#define FLOAT_ARG_REGISTERS_SIZE (COUNT_FLOAT_ARG_REGISTERS * FLOAT_REGISTER_SIZE) - -#define PUSHED_RA_SIZE (8) -#define PUSHED_FP_SIZE (8) - -// From CallerSP to ChildSP, the stack frame is composed of the following adjacent regions: -// -// ARGUMENT_REGISTERS_SIZE -// RETURN_BLOCK_SIZE -// FLOAT_ARG_REGISTERS_SIZE -// PUSHED_RA_SIZE -// PUSHED_FP_SIZE -// - -#define DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK (PUSHED_FP_SIZE + PUSHED_RA_SIZE + FLOAT_ARG_REGISTERS_SIZE) - -#define STACK_SIZE (ARGUMENT_REGISTERS_SIZE + RETURN_BLOCK_SIZE + FLOAT_ARG_REGISTERS_SIZE + PUSHED_RA_SIZE + PUSHED_FP_SIZE) - -#define FLOAT_ARG_OFFSET (PUSHED_FP_SIZE + PUSHED_RA_SIZE) -#define ARGUMENT_REGISTERS_OFFSET (FLOAT_ARG_OFFSET + FLOAT_ARG_REGISTERS_SIZE + RETURN_BLOCK_SIZE) - -// -// RhpUniversalTransition -// -// At input to this function, a0-a7, fa0-fa7, and the stack may contain any number of arguments. -// -// In addition, there are 2 extra arguments passed in the intra-procedure-call scratch register: -// t0 will contain the managed function that is to be called by this transition function -// t1 will contain the pointer-sized extra argument to the managed function -// -// When invoking the callee: -// -// a0 shall contain a pointer to the TransitionBlock -// a1 shall contain the value that was in t1 at entry to this function -// -// Frame layout is: -// -// {StackPassedArgs} ChildSP+100 CallerSP+000 -// {IntArgRegs (a0-a7) (0x40 bytes)} ChildSP+0B8 CallerSP-048 -// {ReturnBlock (0x10 bytes)} ChildSP+098 CallerSP-068 -// -- The base address of the Return block is the TransitionBlock pointer, the floating point args are -// in the neg space of the TransitionBlock pointer. Note that the callee has knowledge of the exact -// layout of all pieces of the frame that lie at or above the pushed floating point registers. -// {FpArgRegs (fa0-fa7) (0x40 bytes)} ChildSP+058 CallerSP-0A8 -// {PushedRA} ChildSP+008 CallerSP-0F8 -// {PushedFP} ChildSP+000 CallerSP-100 -// -// NOTE: If the frame layout ever changes, the C++ UniversalTransitionStackFrame structure -// must be updated as well. -// -// NOTE: The callee receives a pointer to the base of the ReturnBlock, and the callee has -// knowledge of the exact layout of all pieces of the frame that lie at or above the pushed -// FpArgRegs. -// -// NOTE: The stack walker guarantees that conservative GC reporting will be applied to -// everything between the base of the ReturnBlock and the top of the StackPassedArgs. -// - - .text - - .macro UNIVERSAL_TRANSITION FunctionName - - NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler - - # FP and RA registers - PROLOG_SAVE_REG_PAIR_INDEXED fp, ra, STACK_SIZE - - # Floating point registers - SAVE_FLOAT_ARGUMENT_REGISTERS sp, FLOAT_ARG_OFFSET - - # Space for return block data (0x10 bytes) - - # Save argument registers - SAVE_ARGUMENT_REGISTERS sp, ARGUMENT_REGISTERS_OFFSET - -#ifdef TRASH_SAVED_ARGUMENT_REGISTERS - PREPARE_EXTERNAL_VAR RhpFpTrashValues, a1 - - fld fa0, 0x00(a1) - fld fa1, 0x08(a1) - fld fa2, 0x10(a1) - fld fa3, 0x18(a1) - fld fa4, 0x20(a1) - fld fa5, 0x28(a1) - fld fa6, 0x30(a1) - fld fa7, 0x38(a1) - - PREPARE_EXTERNAL_VAR RhpIntegerTrashValues, a1 - - ld a2, 0x10(a1) - ld a3, 0x18(a1) - ld a4, 0x20(a1) - ld a5, 0x28(a1) - ld a6, 0x30(a1) - ld a7, 0x38(a1) -#endif // TRASH_SAVED_ARGUMENT_REGISTERS - - add a0, sp, DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK # First parameter to target function is a pointer to the return block - mv a1, t1 # Second parameter to target function - jalr ra, t0, 0 - -ALTERNATE_ENTRY ReturnFrom\FunctionName - - # Move the result (the target address) to a2 so it doesn't get overridden when we restore the - # argument registers. - mv t2, a0 - - # Restore floating point registers - RESTORE_FLOAT_ARGUMENT_REGISTERS sp, FLOAT_ARG_OFFSET - - # Restore the argument registers - RESTORE_ARGUMENT_REGISTERS sp, ARGUMENT_REGISTERS_OFFSET - - # Restore FP and RA registers, and free the allocated stack block - ld ra, 0x08(sp) - ld s0, 0x0(sp) - addi sp, sp, STACK_SIZE - - # Tailcall to the target address. - jr t2 - - NESTED_END Rhp\FunctionName, _TEXT - - .endm - - UNIVERSAL_TRANSITION UniversalTransitionTailCall diff --git a/src/coreclr/nativeaot/Runtime/s390x/UniversalTransition.S b/src/coreclr/nativeaot/Runtime/s390x/UniversalTransition.S deleted file mode 100644 index 8ccdf87b55e2b2..00000000000000 --- a/src/coreclr/nativeaot/Runtime/s390x/UniversalTransition.S +++ /dev/null @@ -1,4 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include diff --git a/src/coreclr/nativeaot/Runtime/thread.cpp b/src/coreclr/nativeaot/Runtime/thread.cpp index 7105a070e1c013..b1158ae951c2ab 100644 --- a/src/coreclr/nativeaot/Runtime/thread.cpp +++ b/src/coreclr/nativeaot/Runtime/thread.cpp @@ -690,11 +690,7 @@ void Thread::HijackReturnAddressWorker(StackFrameIterator* frameIterator, Hijack ASSERT(pvRetAddr != NULL); -#if defined(TARGET_ARM64) - ASSERT(StackFrameIterator::IsValidReturnAddress(PacStripPtr(pvRetAddr))); -#else - ASSERT(StackFrameIterator::IsValidReturnAddress(pvRetAddr)); -#endif // TARGET_ARM64 + ASSERT(StackFrameIterator::IsValidReturnAddress(pvRetAddr, false)); m_ppvHijackedReturnAddressLocation = ppvRetAddrLocation; m_pvHijackedReturnAddress = pvRetAddr; diff --git a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc index a23a40c644a567..cb92152c7de283 100644 --- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc +++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc @@ -3,20 +3,28 @@ #include "AsmOffsets.inc" +// Size of the q0-q7 save area of PROLOG_WITH_TRANSITION_BLOCK +#define SIZEOF__FloatArgumentRegisters 0x80 + #include // Inlined version of RhpGetThread. Target cannot be x0. // Preserves all other general-purpose registers, except x16 and x17 on Apple. // Can trash volatile FP/SIMD registers. -// Only for functions whose CFA is sp-based (no fp frame): the x0/lr save adjusts the CFA offset. +// Only for functions whose CFA is sp-based since the x0/lr save adjusts the CFA offset. The function may have +// saved fp and lr itself (e.g. CallEHFunclet), as long as fp is not the CFA register. .macro INLINE_GETTHREAD target + // The caller may have saved lr already, so restore its unwind rules instead of resetting + // them to the state at function entry. + .cfi_remember_state PROLOG_SAVE_REG_PAIR_INDEXED x0, lr, -0x10 INLINE_GET_TLS_VAR \target, C_FUNC(tls_CurrentThread) EPILOG_RESTORE_REG_PAIR_INDEXED x0, lr, 0x10 + .cfi_restore_state .endm // Target cannot be x0 or x2. Preserves x0-x2, which the allocation helpers keep live across it. -// Only for functions whose CFA is sp-based (no fp frame), see INLINE_GETTHREAD. +// Only for functions whose CFA is sp-based, see INLINE_GETTHREAD. .macro INLINE_GET_ALLOC_CONTEXT_BASE target .ifc \target, x0 .error "target cannot be x0" diff --git a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosloongarch64.inc b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosloongarch64.inc index 7e5ec9c20b1934..2b309278f28e9f 100644 --- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosloongarch64.inc +++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosloongarch64.inc @@ -3,6 +3,9 @@ #include "AsmOffsets.inc" +// Size of the float argument register save area of PROLOG_WITH_TRANSITION_BLOCK +#define SIZEOF__FloatArgumentRegisters 0x40 + #include // Inlined version of RhpGetThread. Target cannot be a0. diff --git a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosriscv64.inc b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosriscv64.inc index 0d82343f9e027c..d3b2febfcf2555 100644 --- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosriscv64.inc +++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosriscv64.inc @@ -3,6 +3,9 @@ #include "AsmOffsets.inc" +// Size of the float argument register save area of PROLOG_WITH_TRANSITION_BLOCK +#define SIZEOF__FloatArgumentRegisters 0x40 + #include // Inlined version of RhpGetThread. Target cannot be x0. diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index 8da33992e35420..a5f33a447473fc 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -530,9 +530,6 @@ Runtime.Base\src\System\Runtime\TypeCast.cs - - Common\TransitionBlock.cs - diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj index ca850192b0e69a..75f792d044f856 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj @@ -34,9 +34,6 @@ RuntimeConstants.cs - - TransitionBlock.cs - MetadataBlob.cs diff --git a/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj b/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj index acccde8d8fd8f2..3cfe6a5ff8946b 100644 --- a/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj +++ b/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj @@ -54,9 +54,6 @@ Runtime.Base\src\System\Runtime\TypeCast.cs - - Common\TransitionBlock.cs - Common\Interop\Windows\Interop.BOOL.cs diff --git a/src/coreclr/pal/inc/unixasmmacrosamd64.inc b/src/coreclr/pal/inc/unixasmmacrosamd64.inc index 6dc262ae0ecff2..4528875fd1f839 100644 --- a/src/coreclr/pal/inc/unixasmmacrosamd64.inc +++ b/src/coreclr/pal/inc/unixasmmacrosamd64.inc @@ -3,118 +3,6 @@ #include -// Stack layout: -// -// (stack parameters) -// ... -// return address -// CalleeSavedRegisters::rbp -// CalleeSavedRegisters::rbx -// CalleeSavedRegisters::r15 -// CalleeSavedRegisters::r14 -// CalleeSavedRegisters::r13 -// CalleeSavedRegisters::r12 -// ArgumentRegisters::r9 -// ArgumentRegisters::r8 -// ArgumentRegisters::rcx -// ArgumentRegisters::rdx -// ArgumentRegisters::rsi -// ArgumentRegisters::rdi <- __PWTB_StackAlloc, __PWTB_TransitionBlock -// padding to align xmm save area -// xmm7 -// xmm6 -// xmm5 -// xmm4 -// xmm3 -// xmm2 -// xmm1 -// xmm0 <- __PWTB_FloatArgumentRegisters -// extra locals + padding to qword align -.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, stackAllocOnEntry = 0, stackAllocSpill1, stackAllocSpill2, stackAllocSpill3 - - set_cfa_register rsp, 8 - - __PWTB_FloatArgumentRegisters = \extraLocals - - .if ((__PWTB_FloatArgumentRegisters % 16) != 0) - __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8 - .endif - - __PWTB_StackAlloc = __PWTB_FloatArgumentRegisters + 8 * 16 + 8 // 8 floating point registers - __PWTB_TransitionBlock = __PWTB_StackAlloc - __PWTB_ArgumentRegisters = __PWTB_TransitionBlock - - .if \stackAllocOnEntry >= 4*8 - .error "Max supported stackAllocOnEntry is 3*8" - .endif - - .if \stackAllocOnEntry > 0 - .cfi_adjust_cfa_offset \stackAllocOnEntry - .endif - - // PUSH_CALLEE_SAVED_REGISTERS expanded here - - .if \stackAllocOnEntry < 8 - push_nonvol_reg rbp - mov rbp, rsp - .endif - - .if \stackAllocOnEntry < 2*8 - push_nonvol_reg rbx - .endif - - .if \stackAllocOnEntry < 3*8 - push_nonvol_reg r15 - .endif - - push_nonvol_reg r14 - push_nonvol_reg r13 - push_nonvol_reg r12 - - // ArgumentRegisters - PUSH_ARGUMENT_REGISTERS - - .if \stackAllocOnEntry >= 3*8 - mov \stackAllocSpill3, [rsp + 0x48] - save_reg_postrsp r15, 0x48 - .endif - - .if \stackAllocOnEntry >= 2*8 - mov \stackAllocSpill2, [rsp + 0x50] - save_reg_postrsp rbx, 0x50 - .endif - - .if \stackAllocOnEntry >= 8 - mov \stackAllocSpill1, [rsp + 0x58] - save_reg_postrsp rbp, 0x58 - lea rbp, [rsp + 0x58] - .endif - - alloc_stack __PWTB_StackAlloc - SAVE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters - - END_PROLOGUE - -.endm - -.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN - - free_stack __PWTB_StackAlloc - SKIP_ARGUMENT_REGISTERS - POP_CALLEE_SAVED_REGISTERS - ret - -.endm - -.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - - RESTORE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters - free_stack __PWTB_StackAlloc - POP_ARGUMENT_REGISTERS - POP_CALLEE_SAVED_REGISTERS - -.endm - // Inlined version of GetThreadEEAllocContext. Trashes volatile registers. .macro INLINE_GET_ALLOC_CONTEXT_BASE #ifdef FEATURE_EMULATED_TLS diff --git a/src/coreclr/pal/inc/unixasmmacrosarm.inc b/src/coreclr/pal/inc/unixasmmacrosarm.inc index 97476a130da971..93507015ad752e 100644 --- a/src/coreclr/pal/inc/unixasmmacrosarm.inc +++ b/src/coreclr/pal/inc/unixasmmacrosarm.inc @@ -3,128 +3,6 @@ #include -// Stack layout: -// -// (stack parameters) -// ... -// ArgumentRegisters::r3 -// ArgumentRegisters::r2 -// ArgumentRegisters::r1 -// ArgumentRegisters::r0 -// CalleeSavedRegisters::lr -// CalleeSavedRegisters::r11 -// CalleeSavedRegisters::r10 -// CalleeSavedRegisters::r9 -// CalleeSavedRegisters::r8 -// CalleeSavedRegisters::r7 <- r7 -// CalleeSavedRegisters::r6 -// CalleeSavedRegisters::r5 -// CalleeSavedRegisters::r4 <- __PWTB_StackAlloc, __PWTB_TransitionBlock -// padding to align float save area -// d7 -// d6 -// d5 -// d4 -// d3 -// d2 -// d1 -// d0 <- __PWTB_FloatArgumentRegisters -// Optional: Callee saved floating point registers (if pushCalleeSavedFloatRegs=1) -// d15 -// d14 -// d13 -// d12 -// d11 -// d10 -// d9 -// d8 <- __PWTB_FloatCalleeSavedRegisters -// -// pushCalleeSavedFloatRegs - Optional parameter. If set to 1, the macro will also save -// the callee-saved floating point registers (d8-d15) to the stack. -// These registers are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. -// -.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, saveFpArgs = 1, pushArgRegs = 0, pushCalleeSavedFloatRegs = 0 - - __PWTB_FloatCalleeSavedRegisters = \extraLocals - __PWTB_SaveFPArgs = \saveFpArgs - __PWTB_PushCalleeSavedFloatRegs = \pushCalleeSavedFloatRegs - - // If pushCalleeSavedFloatRegs is specified, reserve space for d8-d15 (8 registers * 8 bytes = 64 bytes) - .if (__PWTB_PushCalleeSavedFloatRegs == 1) - .if ((__PWTB_FloatCalleeSavedRegisters % 8) != 0) - __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatCalleeSavedRegisters + 4 - .endif - __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + 64 - .else - __PWTB_FloatArgumentRegisters = \extraLocals - .endif - - .if (__PWTB_SaveFPArgs == 1) - .if ((__PWTB_FloatArgumentRegisters % 8) != 0) - __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 4 - .endif - - __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters + 8 * 8 + 4 // 8 floating point registers + padding - .else - .if ((__PWTB_FloatArgumentRegisters % 8) == 0) - __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 4 - .endif - - __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters - .endif - - __PWTB_StackAlloc = __PWTB_TransitionBlock - __PWTB_ArgumentRegisters = __PWTB_StackAlloc + 36 - - .ifnc \pushArgRegs, DoNotPushArgRegs - PUSH_ARGUMENT_REGISTERS - .endif - - PUSH_CALLEE_SAVED_REGISTERS - PROLOG_STACK_SAVE_OFFSET r7, #12 - // let r7 point the saved r7 in the stack (clang FP style) - - alloc_stack __PWTB_StackAlloc - - .if (__PWTB_SaveFPArgs == 1) - add r6, sp, #(__PWTB_FloatArgumentRegisters) - vstm r6, {d0-d7} - .endif - - // Save callee-saved floating point registers if requested - .if (__PWTB_PushCalleeSavedFloatRegs == 1) - add r6, sp, #(__PWTB_FloatCalleeSavedRegisters) - vstm r6, {d8-d15} - .endif - - CHECK_STACK_ALIGNMENT - - END_PROLOGUE - -.endm - -.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN - - free_stack __PWTB_StackAlloc - POP_CALLEE_SAVED_REGISTERS - free_stack 16 - bx lr - -.endm - -.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - - .if (__PWTB_SaveFPArgs == 1) - add r6, sp, #(__PWTB_FloatArgumentRegisters) - vldm r6, {d0-d7} - .endif - - free_stack __PWTB_StackAlloc - POP_CALLEE_SAVED_REGISTERS - POP_ARGUMENT_REGISTERS - -.endm - .macro INLINE_GET_ALLOC_CONTEXT_BASE bl C_FUNC(GetThreadEEAllocContext) .endm diff --git a/src/coreclr/pal/inc/unixasmmacrosarm64.inc b/src/coreclr/pal/inc/unixasmmacrosarm64.inc index 04c9e2ac8dc147..e4070c3c804f00 100644 --- a/src/coreclr/pal/inc/unixasmmacrosarm64.inc +++ b/src/coreclr/pal/inc/unixasmmacrosarm64.inc @@ -3,169 +3,6 @@ #include -//----------------------------------------------------------------------------- -// Define the prolog for a TransitionFrame-based method. This macro should be called first in the method and -// comprises the entire prolog (i.e. don't modify SP after calling this).The locals must be 8 byte aligned -// -// Stack layout: -// -// (stack parameters) -// ... -// fp -// lr -// CalleeSavedRegisters::x28 -// CalleeSavedRegisters::x27 -// CalleeSavedRegisters::x26 -// CalleeSavedRegisters::x25 -// CalleeSavedRegisters::x24 -// CalleeSavedRegisters::x23 -// CalleeSavedRegisters::x22 -// CalleeSavedRegisters::x21 -// CalleeSavedRegisters::x20 -// CalleeSavedRegisters::x19 -// CalleeSavedRegisters::x30 (Lr) -// CalleeSavedRegisters::x29 (Fp) -// ArgumentRegisters::x7 -// ArgumentRegisters::x6 -// ArgumentRegisters::x5 -// ArgumentRegisters::x4 -// ArgumentRegisters::x3 -// ArgumentRegisters::x2 -// ArgumentRegisters::x1 -// ArgumentRegisters::x0 -// ArgumentRegisters::x8 -// FloatRegisters::q7 -// FloatRegisters::q6 -// FloatRegisters::q5 -// FloatRegisters::q4 -// FloatRegisters::q3 -// FloatRegisters::q2 -// FloatRegisters::q1 -// FloatRegisters::q0 -// Optional: Callee saved floating point registers (if pushCalleeSavedFloatRegs=1) -// d15 -// d14 -// d13 -// d12 -// d11 -// d10 -// d9 -// d8 -// -// pushCalleeSavedFloatRegs - Optional parameter. If set to 1, the macro will also save -// the callee-saved floating point registers (d8-d15) to the stack. -// These registers are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. -// -.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, SaveFPArgs = 1, SaveGPArgs = 1, pushCalleeSavedFloatRegs = 0 - - __PWTB_FloatCalleeSavedRegisters = \extraLocals - __PWTB_SaveFPArgs = \SaveFPArgs - __PWTB_PushCalleeSavedFloatRegs = \pushCalleeSavedFloatRegs - - .if ((__PWTB_FloatCalleeSavedRegisters % 16) != 0) - __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatCalleeSavedRegisters + 8 - .endif - - // If pushCalleeSavedFloatRegs is specified, reserve space for d8-d15 (8 registers * 8 bytes = 64 bytes) - .if (__PWTB_PushCalleeSavedFloatRegs == 1) - __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + 64 - .else - __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters - .endif - - __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters - - // Always reserve space for the FP arg regs, even if they are not saved in the PROLOG_WITH_TRANSITION_BLOCK - // Some code using this macro saves them optionally - __PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters - - __PWTB_StackAlloc = __PWTB_TransitionBlock - __PWTB_ArgumentRegisters = __PWTB_StackAlloc + 104 - __PWTB_ArgumentRegister_FirstArg = __PWTB_ArgumentRegisters + 8 - - PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -176 - // Spill callee saved registers - PROLOG_SAVE_REG_PAIR x19, x20, 16 - PROLOG_SAVE_REG_PAIR x21, x22, 32 - PROLOG_SAVE_REG_PAIR x23, x24, 48 - PROLOG_SAVE_REG_PAIR x25, x26, 64 - PROLOG_SAVE_REG_PAIR x27, x28, 80 - - // Allocate space for the rest of the frame - PROLOG_STACK_ALLOC __PWTB_StackAlloc - - .if (\SaveGPArgs == 1) - // Spill argument registers. - SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters - .endif - - .if (__PWTB_SaveFPArgs == 1) - SAVE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters - .endif - - // Save callee-saved floating point registers if requested - .if (__PWTB_PushCalleeSavedFloatRegs == 1) - PROLOG_SAVE_REG_PAIR d8, d9, __PWTB_FloatCalleeSavedRegisters - PROLOG_SAVE_REG_PAIR d10, d11, __PWTB_FloatCalleeSavedRegisters + 16 - PROLOG_SAVE_REG_PAIR d12, d13, __PWTB_FloatCalleeSavedRegisters + 32 - PROLOG_SAVE_REG_PAIR d14, d15, __PWTB_FloatCalleeSavedRegisters + 48 - .endif - -.endm - -.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN - - EPILOG_STACK_FREE __PWTB_StackAlloc - - EPILOG_RESTORE_REG_PAIR x19, x20, 16 - EPILOG_RESTORE_REG_PAIR x21, x22, 32 - EPILOG_RESTORE_REG_PAIR x23, x24, 48 - EPILOG_RESTORE_REG_PAIR x25, x26, 64 - EPILOG_RESTORE_REG_PAIR x27, x28, 80 - EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 176 - ret - -.endm - -// Same as EPILOG_WITH_TRANSITION_BLOCK_RETURN but skips restoring x21 (SwiftError) -.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN_SKIP_SWIFT_ERROR - - EPILOG_STACK_FREE __PWTB_StackAlloc - - EPILOG_RESTORE_REG_PAIR x19, x20, 16 - EPILOG_RESTORE_REG x22, 40 - EPILOG_RESTORE_REG_PAIR x23, x24, 48 - EPILOG_RESTORE_REG_PAIR x25, x26, 64 - EPILOG_RESTORE_REG_PAIR x27, x28, 80 - EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 176 - ret - -.endm - -//----------------------------------------------------------------------------- -// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. -// Since this is a tail call argument registers are restored. -// -.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - - .if (__PWTB_SaveFPArgs == 1) - RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters - .endif - - RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters - - EPILOG_STACK_FREE __PWTB_StackAlloc - - EPILOG_RESTORE_REG_PAIR x19, x20, 16 - EPILOG_RESTORE_REG_PAIR x21, x22, 32 - EPILOG_RESTORE_REG_PAIR x23, x24, 48 - EPILOG_RESTORE_REG_PAIR x25, x26, 64 - EPILOG_RESTORE_REG_PAIR x27, x28, 80 - EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 176 - -.endm - - // Inlined version of GetThreadEEAllocContext. Target cannot be x0 or x1. .macro INLINE_GET_ALLOC_CONTEXT_BASE target .ifc \target, x0 @@ -250,7 +87,7 @@ PROLOG_SAVE_REG_PAIR x27, x28, 80 // Allocate space for FloatArgumentRegisters (128) + FP callee-saved (64) = 192 bytes - PROLOG_STACK_ALLOC 192 + sub sp, sp, 192 // Save argument registers (x8, x0-x7) at offset 296 from sp (192 + 104) SAVE_ARGUMENT_REGISTERS sp, 296 diff --git a/src/coreclr/pal/inc/unixasmmacrosloongarch64.inc b/src/coreclr/pal/inc/unixasmmacrosloongarch64.inc index 3160785ccbd6f9..ccb9cc91b1ed15 100644 --- a/src/coreclr/pal/inc/unixasmmacrosloongarch64.inc +++ b/src/coreclr/pal/inc/unixasmmacrosloongarch64.inc @@ -3,116 +3,6 @@ #include -//----------------------------------------------------------------------------- -// Define the prolog for a TransitionBlock-based method. This macro should be called first in the method and -// comprises the entire prolog.The locals must be 8 byte aligned -// -// Save_argument_registers: -// GPR_a7 -// GPR_a6 -// GPR_a5 -// GPR_a4 -// GPR_a3 -// GPR_a2 -// GPR_a1 -// GPR_a0 -// -// General Registers: -// GPR_s8 -// GPR_s7 -// GPR_s6 -// GPR_s5 -// GPR_s4 -// GPR_s3 -// GPR_s2 -// GPR_s1 -// GPR_s0 -// GPR_ra -// GPR_fp -// -// Float Point: -// FPR_f31 / fs7 -// FPR_f30 / fs6 -// FPR_f29 / fs5 -// FPR_f28 / fs4 -// FPR_f27 / fs3 -// FPR_f26 / fs2 -// FPR_f25 / fs1 -// FPR_f24 / fs0 -// Extra: -// -.macro PROLOG_WITH_TRANSITION_BLOCK extraParameters = 0, extraLocals = 0, SaveFPRegs = 1 - - __PWTB_SaveFPArgs = \SaveFPRegs - - __PWTB_FloatArgumentRegisters = \extraLocals - - .if ((__PWTB_FloatArgumentRegisters % 16) != 0) - __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8 - .endif - - __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters - - .if (__PWTB_SaveFPArgs == 1) - __PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters - .endif - - - __PWTB_CalleeSavedRegisters = __PWTB_TransitionBlock - __PWTB_ArgumentRegisters = __PWTB_TransitionBlock + 96 - - // Including fp, ra, s0-s8, padding, and (a0-a7)arguments. (1+1+9+1)*8 + 8*8. - __PWTB_StackAlloc = __PWTB_TransitionBlock + 96 + 64 - PROLOG_STACK_ALLOC __PWTB_StackAlloc - // $fp,$ra - PROLOG_SAVE_REG_PAIR 22, 1, __PWTB_CalleeSavedRegisters, 1 - - // First, Spill argument registers. - SAVE_ARGUMENT_REGISTERS $sp, __PWTB_ArgumentRegisters - - // Then, Spill callee saved registers. $sp=$r3. - SAVE_CALLEESAVED_REGISTERS 3, __PWTB_CalleeSavedRegisters - - // saving is f12-19. - .if (__PWTB_SaveFPArgs == 1) - SAVE_FLOAT_ARGUMENT_REGISTERS $sp, __PWTB_FloatArgumentRegisters - .endif - -.endm - -.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN - - RESTORE_CALLEESAVED_REGISTERS 3, __PWTB_CalleeSavedRegisters - - EPILOG_RESTORE_REG_PAIR 22, 1, __PWTB_CalleeSavedRegisters - - EPILOG_STACK_FREE __PWTB_StackAlloc - - jirl $r0, $ra, 0 - -.endm - - -//----------------------------------------------------------------------------- -// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. -// Since this is a tail call argument registers are restored. -// -.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - - .if (__PWTB_SaveFPArgs == 1) - RESTORE_FLOAT_ARGUMENT_REGISTERS $sp, __PWTB_FloatArgumentRegisters - .endif - - RESTORE_CALLEESAVED_REGISTERS 3, __PWTB_CalleeSavedRegisters - - RESTORE_ARGUMENT_REGISTERS $sp, __PWTB_ArgumentRegisters - - EPILOG_RESTORE_REG_PAIR 22, 1, __PWTB_CalleeSavedRegisters - - EPILOG_STACK_FREE __PWTB_StackAlloc - -.endm - // Inlined version of GetThreadEEAllocContext. Target cannot be a0. .macro INLINE_GET_ALLOC_CONTEXT_BASE target .ifc \target, $a0 diff --git a/src/coreclr/pal/inc/unixasmmacrosriscv64.inc b/src/coreclr/pal/inc/unixasmmacrosriscv64.inc index 0449565f00958f..ae418806ff6ea6 100644 --- a/src/coreclr/pal/inc/unixasmmacrosriscv64.inc +++ b/src/coreclr/pal/inc/unixasmmacrosriscv64.inc @@ -3,147 +3,6 @@ #include -//----------------------------------------------------------------------------- -// Define the prolog for a TransitionBlock-based method. This macro should be called first in the method and -// comprises the entire prolog.The locals must be 8 byte aligned -// -// Save_argument_registers: -// GPR_a7 -// GPR_a6 -// GPR_a5 -// GPR_a4 -// GPR_a3 -// GPR_a2 -// GPR_a1 -// GPR_a0 -// -// Callee Saved Registers: -// GPR_gp -// GPR_tp -// GPR_s11 -// GPR_s10 -// GPR_s9 -// GPR_s8 -// GPR_s7 -// GPR_s6 -// GPR_s5 -// GPR_s4 -// GPR_s3 -// GPR_s2 -// GPR_s1 -// GPR_ra -// GPR_fp -// -// Float Point: -// FPR_f27 / fs11 -// FPR_f26 / fs10 -// FPR_f25 / fs9 -// FPR_f24 / fs8 -// FPR_f23 / fs7 -// FPR_f22 / fs6 -// FPR_f21 / fs5 -// FPR_f20 / fs4 -// FPR_f19 / fs3 -// FPR_f18 / fs2 -// FPR_f9 / fs1 -// FPR_f8 / fs0 -// Extra: -// -// pushCalleeSavedFloatRegs - Optional parameter. If set to 1, the macro will also save -// the callee-saved floating point registers (fs0-fs11) to the stack. -// These registers are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. -// -.macro PROLOG_WITH_TRANSITION_BLOCK extraParameters = 0, extraLocals = 0, SaveFPRegs = 1, pushCalleeSavedFloatRegs = 0 - __PWTB_SaveFPArgs = \SaveFPRegs - __PWTB_PushCalleeSavedFloatRegs = \pushCalleeSavedFloatRegs - - __PWTB_FloatCalleeSavedRegisters = \extraLocals - - // Note, stack (see __PWTB_StackAlloc variable) must be 16 byte aligned. - .if ((__PWTB_FloatCalleeSavedRegisters % 16) != 0) - __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatCalleeSavedRegisters + 8 - .endif - - // If pushCalleeSavedFloatRegs is specified, reserve space for fs0-fs11 (12 registers * 8 bytes = 96 bytes) - .if (__PWTB_PushCalleeSavedFloatRegs == 1) - __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + 96 - .else - __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters - .endif - - __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters - - .if (__PWTB_SaveFPArgs == 1) - __PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters - .endif - - - __PWTB_CalleeSavedRegisters = __PWTB_TransitionBlock - __PWTB_ArgumentRegisters = __PWTB_TransitionBlock + 120 + 8 - - // Including fp, ra, s1-s11, tp, gp, padding and (a0-a7)arguments. (1+1+11+1+1)*8 + 8 + 8*8. - __PWTB_StackAlloc = __PWTB_TransitionBlock + 120 + 8 + 64 - PROLOG_STACK_ALLOC __PWTB_StackAlloc - PROLOG_SAVE_REG_PAIR fp, ra, __PWTB_CalleeSavedRegisters, 1 - - // First, Spill argument registers. - SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters - - // Then, Spill callee saved registers. sp=r2. - SAVE_CALLEESAVED_REGISTERS sp, __PWTB_CalleeSavedRegisters - - // saving is f10-17. - .if (__PWTB_SaveFPArgs == 1) - SAVE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters - .endif - - // Save callee-saved floating point registers if requested (fs0-fs11) - .if (__PWTB_PushCalleeSavedFloatRegs == 1) - fsd fs0, (__PWTB_FloatCalleeSavedRegisters)(sp) - fsd fs1, (__PWTB_FloatCalleeSavedRegisters + 8)(sp) - fsd fs2, (__PWTB_FloatCalleeSavedRegisters + 16)(sp) - fsd fs3, (__PWTB_FloatCalleeSavedRegisters + 24)(sp) - fsd fs4, (__PWTB_FloatCalleeSavedRegisters + 32)(sp) - fsd fs5, (__PWTB_FloatCalleeSavedRegisters + 40)(sp) - fsd fs6, (__PWTB_FloatCalleeSavedRegisters + 48)(sp) - fsd fs7, (__PWTB_FloatCalleeSavedRegisters + 56)(sp) - fsd fs8, (__PWTB_FloatCalleeSavedRegisters + 64)(sp) - fsd fs9, (__PWTB_FloatCalleeSavedRegisters + 72)(sp) - fsd fs10, (__PWTB_FloatCalleeSavedRegisters + 80)(sp) - fsd fs11, (__PWTB_FloatCalleeSavedRegisters + 88)(sp) - .endif - -.endm - -.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN - RESTORE_CALLEESAVED_REGISTERS sp, __PWTB_CalleeSavedRegisters - - EPILOG_RESTORE_REG_PAIR fp, ra, __PWTB_CalleeSavedRegisters - - EPILOG_STACK_FREE __PWTB_StackAlloc - - ret -.endm - - -//----------------------------------------------------------------------------- -// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. -// Since this is a tail call argument registers are restored. -// -.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - .if (__PWTB_SaveFPArgs == 1) - RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters - .endif - - RESTORE_CALLEESAVED_REGISTERS sp, __PWTB_CalleeSavedRegisters - - RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters - - EPILOG_RESTORE_REG_PAIR fp, ra, __PWTB_CalleeSavedRegisters - - EPILOG_STACK_FREE __PWTB_StackAlloc -.endm - // Inlined version of GetThreadEEAllocContext .macro INLINE_GET_ALLOC_CONTEXT_BASE call C_FUNC(GetThreadEEAllocContext) diff --git a/src/coreclr/pal/src/arch/arm64/callsignalhandlerwrapper.S b/src/coreclr/pal/src/arch/arm64/callsignalhandlerwrapper.S index 67a88fbb2e6fbb..b0080bae2552f1 100644 --- a/src/coreclr/pal/src/arch/arm64/callsignalhandlerwrapper.S +++ b/src/coreclr/pal/src/arch/arm64/callsignalhandlerwrapper.S @@ -16,7 +16,6 @@ C_FUNC(SignalHandlerWorkerReturnOffset\Alignment): NESTED_ENTRY CallSignalHandlerWrapper\Alignment, _TEXT, NoHandler __StackAllocationSize = (128 + 8 + 8 + \Alignment) // red zone + fp + lr + alignment PROLOG_STACK_ALLOC __StackAllocationSize - .cfi_adjust_cfa_offset __StackAllocationSize PROLOG_SAVE_REG_PAIR fp, lr, 0 bl EXTERNAL_C_FUNC(signal_handler_worker) LOCAL_LABEL(SignalHandlerWorkerReturn\Alignment): diff --git a/src/coreclr/pal/src/arch/arm64/context2.S b/src/coreclr/pal/src/arch/arm64/context2.S index 65ace16e47a98b..38cd7bc60939db 100644 --- a/src/coreclr/pal/src/arch/arm64/context2.S +++ b/src/coreclr/pal/src/arch/arm64/context2.S @@ -15,7 +15,6 @@ .arch_extension sve LEAF_ENTRY CONTEXT_CaptureContext, _TEXT PROLOG_STACK_ALLOC 32 - .cfi_adjust_cfa_offset 32 // save x1, x2 and x3 on stack so we can use them as scratch stp x1, x2, [sp] @@ -157,7 +156,6 @@ LEAF_END CONTEXT_CaptureContext, _TEXT LEAF_ENTRY RtlCaptureContext, _TEXT PROLOG_STACK_ALLOC 16 - .cfi_adjust_cfa_offset 16 str x1, [sp] // same as above, clang doesn't like mov with #imm32 // keep this in sync if CONTEXT_FULL changes diff --git a/src/coreclr/runtime/amd64/AsmMacros_Unix.inc b/src/coreclr/runtime/amd64/AsmMacros_Unix.inc index 418bae14c03614..3f923e317e37c4 100644 --- a/src/coreclr/runtime/amd64/AsmMacros_Unix.inc +++ b/src/coreclr/runtime/amd64/AsmMacros_Unix.inc @@ -290,3 +290,107 @@ C_FUNC(\Name\()_End): .byte 0xFF .byte 0xE0 .endm + +//----------------------------------------------------------------------------- +// The following group of macros assist in implementing prologs and epilogs for methods that set up TransitionFrame. +// +// PROLOG_WITH_TRANSITION_BLOCK should be called first in the method and comprises the entire prolog +// (i.e. don't modify RSP after calling this). The locals must be 8 byte aligned. +// +// Stack layout: +// +// extra locals +// FloatArgumentRegisters (xmm0 - xmm7) +// padding +// struct TransitionBlock +// { +// ArgumentRegisters (rdi, rsi, rdx, rcx, r8, r9) +// CalleeSavedRegisters (r12 - r15, rbx, rbp) +// return address +// } +// Stack arguments +// +.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, stackAllocOnEntry = 0, stackAllocSpill1, stackAllocSpill2, stackAllocSpill3 + + set_cfa_register rsp, 8 + + __PWTB_FloatArgumentRegisters = \extraLocals + + .if ((__PWTB_FloatArgumentRegisters % 16) != 0) + __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8 + .endif + + __PWTB_StackAlloc = __PWTB_FloatArgumentRegisters + 8 * 16 + 8 // 8 floating point registers + __PWTB_TransitionBlock = __PWTB_StackAlloc + __PWTB_ArgumentRegisters = __PWTB_TransitionBlock + + .if \stackAllocOnEntry >= 4*8 + .error "Max supported stackAllocOnEntry is 3*8" + .endif + + .if \stackAllocOnEntry > 0 + .cfi_adjust_cfa_offset \stackAllocOnEntry + .endif + + // PUSH_CALLEE_SAVED_REGISTERS expanded here + + .if \stackAllocOnEntry < 8 + push_nonvol_reg rbp + mov rbp, rsp + .endif + + .if \stackAllocOnEntry < 2*8 + push_nonvol_reg rbx + .endif + + .if \stackAllocOnEntry < 3*8 + push_nonvol_reg r15 + .endif + + push_nonvol_reg r14 + push_nonvol_reg r13 + push_nonvol_reg r12 + + // ArgumentRegisters + PUSH_ARGUMENT_REGISTERS + + .if \stackAllocOnEntry >= 3*8 + mov \stackAllocSpill3, [rsp + 0x48] + save_reg_postrsp r15, 0x48 + .endif + + .if \stackAllocOnEntry >= 2*8 + mov \stackAllocSpill2, [rsp + 0x50] + save_reg_postrsp rbx, 0x50 + .endif + + .if \stackAllocOnEntry >= 8 + mov \stackAllocSpill1, [rsp + 0x58] + save_reg_postrsp rbp, 0x58 + lea rbp, [rsp + 0x58] + .endif + + alloc_stack __PWTB_StackAlloc + SAVE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters + + END_PROLOGUE + +.endm + +.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN + + free_stack __PWTB_StackAlloc + SKIP_ARGUMENT_REGISTERS + POP_CALLEE_SAVED_REGISTERS + ret + +.endm + +.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + + RESTORE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters + free_stack __PWTB_StackAlloc + POP_ARGUMENT_REGISTERS + POP_CALLEE_SAVED_REGISTERS + +.endm diff --git a/src/coreclr/runtime/amd64/AsmMacros_Windows.inc b/src/coreclr/runtime/amd64/AsmMacros_Windows.inc index a7a9fb910ef52b..bf7c8d9e9148bd 100644 --- a/src/coreclr/runtime/amd64/AsmMacros_Windows.inc +++ b/src/coreclr/runtime/amd64/AsmMacros_Windows.inc @@ -1,6 +1,9 @@ ; Licensed to the .NET Foundation under one or more agreements. ; The .NET Foundation licenses this file to you under the MIT license. +; Size of the home area for the register arguments that the Windows x64 ABI requires callers to allocate +SIZEOF_ARGUMENT_SHADOW_SPACE equ 20h + ; ; Define macros to build unwind data for prologues. ; @@ -343,3 +346,127 @@ endm ;; GC type flags GC_ALLOC_FINALIZE equ 1 + +;----------------------------------------------------------------------------- +; The following group of macros assist in implementing prologs and epilogs for methods that set up TransitionFrame. +; +; PROLOG_WITH_TRANSITION_BLOCK should be called first in the method and comprises the entire prolog +; (i.e. don't modify RSP after calling this). The locals must be 8 byte aligned. +; +; Stack layout: +; +; outgoing argument shadow space (rcx, rdx, r8, r9) +; extra locals +; FloatCalleeSavedRegisters (xmm6 - xmm15) if calleeSavedFloatRegs=PushCalleeSavedFloatRegs +; FloatArgumentRegisters (xmm0 - xmm3) +; padding +; struct TransitionBlock +; { +; CalleeSavedRegisters (rdi, rsi, rbx, rbp, r12 - r15) +; return address +; } +; ArgumentRegisters (rcx, rdx, r8, r9) in the caller's shadow space +; Stack arguments +; +PROLOG_WITH_TRANSITION_BLOCK macro extraLocals := <0>, calleeSavedFloatRegs := , stackAllocOnEntry := <0>, stackAllocSpill1, stackAllocSpill2, stackAllocSpill3 + + __PWTB_FloatArgumentRegisters = SIZEOF_ARGUMENT_SHADOW_SPACE + extraLocals + + if (__PWTB_FloatArgumentRegisters mod 16) ne 0 + __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8 + endif + + ifidn , + __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatArgumentRegisters + __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 10 * 16 + endif + + __PWTB_StackAlloc = __PWTB_FloatArgumentRegisters + 4 * 16 + 8 + __PWTB_TransitionBlock = __PWTB_StackAlloc + __PWTB_ArgumentRegisters = __PWTB_StackAlloc + 9 * 8 + + .errnz stackAllocOnEntry ge 4*8, Max supported stackAllocOnEntry is 3*8 + + if stackAllocOnEntry gt 0 + .allocstack stackAllocOnEntry + endif + + ; PUSH_CALLEE_SAVED_REGISTERS expanded here + + if stackAllocOnEntry lt 8 + push_nonvol_reg r15 + endif + + if stackAllocOnEntry lt 2*8 + push_nonvol_reg r14 + endif + + if stackAllocOnEntry lt 3*8 + push_nonvol_reg r13 + endif + + push_nonvol_reg r12 + push_nonvol_reg rbp + push_nonvol_reg rbx + push_nonvol_reg rsi + push_nonvol_reg rdi + + alloc_stack __PWTB_StackAlloc + SAVE_ARGUMENT_REGISTERS __PWTB_ArgumentRegisters + SAVE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters + + ifidn , + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters], xmm6 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 10h], xmm7 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 20h], xmm8 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 30h], xmm9 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 40h], xmm10 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 50h], xmm11 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 60h], xmm12 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 70h], xmm13 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 80h], xmm14 + movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 90h], xmm15 + endif + + if stackAllocOnEntry ge 3*8 + mov stackAllocSpill3, [rsp + __PWTB_StackAlloc + 28h] + save_reg_postrsp r13, __PWTB_StackAlloc + 28h + endif + + if stackAllocOnEntry ge 2*8 + mov stackAllocSpill2, [rsp + __PWTB_StackAlloc + 30h] + save_reg_postrsp r14, __PWTB_StackAlloc + 30h + endif + + if stackAllocOnEntry ge 8 + mov stackAllocSpill1, [rsp + __PWTB_StackAlloc + 38h] + save_reg_postrsp r15, __PWTB_StackAlloc + 38h + endif + + END_PROLOGUE + + endm + +EPILOG_WITH_TRANSITION_BLOCK macro + + add rsp, __PWTB_StackAlloc + POP_CALLEE_SAVED_REGISTERS + + endm + +EPILOG_WITH_TRANSITION_BLOCK_RETURN macro + + add rsp, __PWTB_StackAlloc + POP_CALLEE_SAVED_REGISTERS + ret + + endm + +EPILOG_WITH_TRANSITION_BLOCK_TAILCALL macro + + RESTORE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters + RESTORE_ARGUMENT_REGISTERS __PWTB_ArgumentRegisters + add rsp, __PWTB_StackAlloc + POP_CALLEE_SAVED_REGISTERS + + endm diff --git a/src/coreclr/runtime/arm/AsmMacros_Unix.inc b/src/coreclr/runtime/arm/AsmMacros_Unix.inc index 4291e92e462d16..b038086c4a1691 100644 --- a/src/coreclr/runtime/arm/AsmMacros_Unix.inc +++ b/src/coreclr/runtime/arm/AsmMacros_Unix.inc @@ -232,3 +232,110 @@ C_FUNC(\Name): .long \Var(TLSGD) + (2b - 1b - 4) 3: .endm + +//----------------------------------------------------------------------------- +// The following group of macros assist in implementing prologs and epilogs for methods that set up TransitionFrame. +// +// PROLOG_WITH_TRANSITION_BLOCK should be called first in the method and comprises the entire prolog +// (i.e. don't modify SP after calling this). +// +// Stack layout: +// +// extra locals +// FloatCalleeSavedRegisters (d8 - d15) if pushCalleeSavedFloatRegs=1 +// FloatArgumentRegisters (d0 - d7) if saveFpArgs=1 +// padding +// struct TransitionBlock +// { +// CalleeSavedRegisters (r4 - r11, lr) +// ArgumentRegisters (r0 - r3) +// } +// Stack arguments +// +// r7 points at the saved r7 in CalleeSavedRegisters. +// +// pushCalleeSavedFloatRegs - Optional parameter. If set to 1, the macro will also save +// the callee-saved floating point registers (d8-d15) to the stack. +// These registers are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. +// +.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, saveFpArgs = 1, pushArgRegs = 0, pushCalleeSavedFloatRegs = 0 + + __PWTB_FloatCalleeSavedRegisters = \extraLocals + __PWTB_SaveFPArgs = \saveFpArgs + __PWTB_PushCalleeSavedFloatRegs = \pushCalleeSavedFloatRegs + + // If pushCalleeSavedFloatRegs is specified, reserve space for d8-d15 (8 registers * 8 bytes = 64 bytes) + .if (__PWTB_PushCalleeSavedFloatRegs == 1) + .if ((__PWTB_FloatCalleeSavedRegisters % 8) != 0) + __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatCalleeSavedRegisters + 4 + .endif + __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + 64 + .else + __PWTB_FloatArgumentRegisters = \extraLocals + .endif + + .if (__PWTB_SaveFPArgs == 1) + .if ((__PWTB_FloatArgumentRegisters % 8) != 0) + __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 4 + .endif + + __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters + 8 * 8 + 4 // 8 floating point registers + padding + .else + .if ((__PWTB_FloatArgumentRegisters % 8) == 0) + __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 4 + .endif + + __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters + .endif + + __PWTB_StackAlloc = __PWTB_TransitionBlock + __PWTB_ArgumentRegisters = __PWTB_StackAlloc + 36 + + .ifnc \pushArgRegs, DoNotPushArgRegs + PUSH_ARGUMENT_REGISTERS + .endif + + PUSH_CALLEE_SAVED_REGISTERS + PROLOG_STACK_SAVE_OFFSET r7, #12 + // let r7 point the saved r7 in the stack (clang FP style) + + alloc_stack __PWTB_StackAlloc + + .if (__PWTB_SaveFPArgs == 1) + add r6, sp, #(__PWTB_FloatArgumentRegisters) + vstm r6, {d0-d7} + .endif + + // Save callee-saved floating point registers if requested + .if (__PWTB_PushCalleeSavedFloatRegs == 1) + add r6, sp, #(__PWTB_FloatCalleeSavedRegisters) + vstm r6, {d8-d15} + .endif + + CHECK_STACK_ALIGNMENT + + END_PROLOGUE + +.endm + +.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN + + free_stack __PWTB_StackAlloc + POP_CALLEE_SAVED_REGISTERS + free_stack 16 + bx lr + +.endm + +.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + + .if (__PWTB_SaveFPArgs == 1) + add r6, sp, #(__PWTB_FloatArgumentRegisters) + vldm r6, {d0-d7} + .endif + + free_stack __PWTB_StackAlloc + POP_CALLEE_SAVED_REGISTERS + POP_ARGUMENT_REGISTERS + +.endm diff --git a/src/coreclr/runtime/arm64/AsmMacros_Unix.inc b/src/coreclr/runtime/arm64/AsmMacros_Unix.inc index 299062b619f573..d3492fe16039d2 100644 --- a/src/coreclr/runtime/arm64/AsmMacros_Unix.inc +++ b/src/coreclr/runtime/arm64/AsmMacros_Unix.inc @@ -130,6 +130,7 @@ C_FUNC(\Name): .macro PROLOG_STACK_ALLOC Size sub sp, sp, \Size + .cfi_adjust_cfa_offset \Size .endm .macro EPILOG_STACK_FREE Size @@ -187,6 +188,9 @@ C_FUNC(\Name): .endm .macro EPILOG_RESTORE_REG_PAIR_INDEXED reg1, reg2, ofs + .ifc \reg1, fp + .cfi_def_cfa_register sp + .endif ldp \reg1, \reg2, [sp], \ofs .cfi_restore \reg1 .cfi_restore \reg2 @@ -305,3 +309,135 @@ C_FUNC(\Name): #endif .endm + +//----------------------------------------------------------------------------- +// The following group of macros assist in implementing prologs and epilogs for methods that set up TransitionFrame. +// +// PROLOG_WITH_TRANSITION_BLOCK should be called first in the method and comprises the entire prolog +// (i.e. don't modify SP after calling this). The locals must be 8 byte aligned. +// +// Stack layout: +// +// extra locals +// FloatCalleeSavedRegisters (d8 - d15) if pushCalleeSavedFloatRegs=1 +// FloatArgumentRegisters (q0 - q7) +// struct TransitionBlock +// { +// CalleeSavedRegisters (fp, lr, x19 - x28) +// padding +// RetBuffReg (x8) +// ArgumentRegisters (x0 - x7) +// } +// Stack arguments +// +// pushCalleeSavedFloatRegs - Optional parameter. If set to 1, the macro will also save +// the callee-saved floating point registers (d8-d15) to the stack. +// These registers are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. +// +.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, SaveFPArgs = 1, SaveGPArgs = 1, pushCalleeSavedFloatRegs = 0 + + __PWTB_FloatCalleeSavedRegisters = \extraLocals + __PWTB_SaveFPArgs = \SaveFPArgs + __PWTB_PushCalleeSavedFloatRegs = \pushCalleeSavedFloatRegs + + .if ((__PWTB_FloatCalleeSavedRegisters % 16) != 0) + __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatCalleeSavedRegisters + 8 + .endif + + // If pushCalleeSavedFloatRegs is specified, reserve space for d8-d15 (8 registers * 8 bytes = 64 bytes) + .if (__PWTB_PushCalleeSavedFloatRegs == 1) + __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + 64 + .else + __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + .endif + + // Always reserve space for the FP arg regs, even if they are not saved in the PROLOG_WITH_TRANSITION_BLOCK + // Some code using this macro saves them optionally + __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters + SIZEOF__FloatArgumentRegisters + + __PWTB_StackAlloc = __PWTB_TransitionBlock + __PWTB_ArgumentRegisters = __PWTB_StackAlloc + 12 * 8 + 8 // CalleeSavedRegisters + padding + __PWTB_ArgumentRegister_FirstArg = __PWTB_ArgumentRegisters + 8 + __PWTB_TransitionBlockSize = __PWTB_ArgumentRegister_FirstArg + 8 * 8 - __PWTB_StackAlloc + + PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -__PWTB_TransitionBlockSize + // Spill callee saved registers + PROLOG_SAVE_REG_PAIR x19, x20, 16 + PROLOG_SAVE_REG_PAIR x21, x22, 32 + PROLOG_SAVE_REG_PAIR x23, x24, 48 + PROLOG_SAVE_REG_PAIR x25, x26, 64 + PROLOG_SAVE_REG_PAIR x27, x28, 80 + + // Allocate space for the rest of the frame + sub sp, sp, __PWTB_StackAlloc + + .if (\SaveGPArgs == 1) + // Spill argument registers. + SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters + .endif + + .if (__PWTB_SaveFPArgs == 1) + SAVE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters + .endif + + // Save callee-saved floating point registers if requested + .if (__PWTB_PushCalleeSavedFloatRegs == 1) + stp d8, d9, [sp, __PWTB_FloatCalleeSavedRegisters] + stp d10, d11, [sp, __PWTB_FloatCalleeSavedRegisters + 16] + stp d12, d13, [sp, __PWTB_FloatCalleeSavedRegisters + 32] + stp d14, d15, [sp, __PWTB_FloatCalleeSavedRegisters + 48] + .endif + +.endm + +.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN + + add sp, sp, __PWTB_StackAlloc + + EPILOG_RESTORE_REG_PAIR x19, x20, 16 + EPILOG_RESTORE_REG_PAIR x21, x22, 32 + EPILOG_RESTORE_REG_PAIR x23, x24, 48 + EPILOG_RESTORE_REG_PAIR x25, x26, 64 + EPILOG_RESTORE_REG_PAIR x27, x28, 80 + EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, __PWTB_TransitionBlockSize + ret + +.endm + +// Same as EPILOG_WITH_TRANSITION_BLOCK_RETURN but skips restoring x21 (SwiftError) +.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN_SKIP_SWIFT_ERROR + + add sp, sp, __PWTB_StackAlloc + + EPILOG_RESTORE_REG_PAIR x19, x20, 16 + EPILOG_RESTORE_REG x22, 40 + EPILOG_RESTORE_REG_PAIR x23, x24, 48 + EPILOG_RESTORE_REG_PAIR x25, x26, 64 + EPILOG_RESTORE_REG_PAIR x27, x28, 80 + EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, __PWTB_TransitionBlockSize + ret + +.endm + +//----------------------------------------------------------------------------- +// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. +// Since this is a tail call argument registers are restored. +// +.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + + .if (__PWTB_SaveFPArgs == 1) + RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters + .endif + + RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters + + add sp, sp, __PWTB_StackAlloc + + EPILOG_RESTORE_REG_PAIR x19, x20, 16 + EPILOG_RESTORE_REG_PAIR x21, x22, 32 + EPILOG_RESTORE_REG_PAIR x23, x24, 48 + EPILOG_RESTORE_REG_PAIR x25, x26, 64 + EPILOG_RESTORE_REG_PAIR x27, x28, 80 + EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, __PWTB_TransitionBlockSize + +.endm diff --git a/src/coreclr/runtime/arm64/AsmMacros_Windows.h b/src/coreclr/runtime/arm64/AsmMacros_Windows.h index 9482e60f200c36..ed6b60e3807fdd 100644 --- a/src/coreclr/runtime/arm64/AsmMacros_Windows.h +++ b/src/coreclr/runtime/arm64/AsmMacros_Windows.h @@ -255,3 +255,150 @@ __PWTB_RESTORE_FLOAT_ARGUMENT_REGISTERS_OFFSET SETA 0 GC_ALLOC_FINALIZE equ 1 GC_ALLOC_ALIGN8_BIAS equ 4 GC_ALLOC_ALIGN8 equ 8 + +;----------------------------------------------------------------------------- +; The following group of macros assist in implementing prologs and epilogs for methods that set up TransitionFrame. +; +; PROLOG_WITH_TRANSITION_BLOCK should be called first in the method and comprises the entire prolog +; (i.e. don't modify SP after calling this). The locals must be 8 byte aligned. +; +; Stack layout: +; +; extra locals +; FloatCalleeSavedRegisters (d8 - d15) if $pushCalleeSavedFloatRegs=PushCalleeSavedFloatRegs +; FloatArgumentRegisters (q0 - q7) if $SaveFPArgs +; struct TransitionBlock +; { +; CalleeSavedRegisters (fp, lr, x19 - x28) +; padding +; RetBuffReg (x8) +; ArgumentRegisters (x0 - x7) +; } +; Stack arguments +; +; $pushCalleeSavedFloatRegs - Optional parameter. If set to PushCalleeSavedFloatRegs, the macro will also save +; the callee-saved floating point registers (d8-d15) to the stack. These registers +; are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. +; + MACRO + PROLOG_WITH_TRANSITION_BLOCK $extraLocals, $SaveFPArgs, $pushCalleeSavedFloatRegs + + GBLA __PWTB_FloatArgumentRegisters + GBLA __PWTB_FloatCalleeSavedRegisters + GBLA __PWTB_ArgumentRegisters + GBLA __PWTB_ArgumentRegister_FirstArg ; We save the x8 register ahead of the first argument, so this + ; is different from the start of the argument register save area. + GBLA __PWTB_StackAlloc + GBLA __PWTB_TransitionBlock + GBLA __PWTB_TransitionBlockSize + GBLL __PWTB_SaveFPArgs + + IF "$SaveFPArgs" != "" +__PWTB_SaveFPArgs SETL $SaveFPArgs + ELSE +__PWTB_SaveFPArgs SETL {true} + ENDIF + + IF "$extraLocals" != "" +__PWTB_FloatCalleeSavedRegisters SETA $extraLocals + ELSE +__PWTB_FloatCalleeSavedRegisters SETA 0 + ENDIF + + IF __PWTB_FloatCalleeSavedRegisters:MOD:16 != 0 +__PWTB_FloatCalleeSavedRegisters SETA __PWTB_FloatCalleeSavedRegisters + 8 + ENDIF + + ; If PushCalleeSavedFloatRegs is specified, reserve space for d8-d15 (8 registers * 8 bytes = 64 bytes) + IF "$pushCalleeSavedFloatRegs" == "PushCalleeSavedFloatRegs" +__PWTB_FloatArgumentRegisters SETA __PWTB_FloatCalleeSavedRegisters + 64 + ELSE +__PWTB_FloatArgumentRegisters SETA __PWTB_FloatCalleeSavedRegisters + ENDIF + + IF __PWTB_SaveFPArgs +__PWTB_TransitionBlock SETA __PWTB_FloatArgumentRegisters + SIZEOF__FloatArgumentRegisters + ELSE +__PWTB_TransitionBlock SETA __PWTB_FloatArgumentRegisters + ENDIF + +__PWTB_StackAlloc SETA __PWTB_TransitionBlock +__PWTB_ArgumentRegisters SETA __PWTB_StackAlloc + 12 * 8 + 8 ; CalleeSavedRegisters + padding +__PWTB_ArgumentRegister_FirstArg SETA __PWTB_ArgumentRegisters + 8 +__PWTB_TransitionBlockSize SETA __PWTB_ArgumentRegister_FirstArg + 8 * 8 - __PWTB_StackAlloc + + PROLOG_SAVE_REG_PAIR fp, lr, #-(__PWTB_TransitionBlockSize)! + ; Spill callee saved registers + PROLOG_SAVE_REG_PAIR x19, x20, #16 + PROLOG_SAVE_REG_PAIR x21, x22, #32 + PROLOG_SAVE_REG_PAIR x23, x24, #48 + PROLOG_SAVE_REG_PAIR x25, x26, #64 + PROLOG_SAVE_REG_PAIR x27, x28, #80 + + ; Allocate space for the rest of the frame + PROLOG_STACK_ALLOC __PWTB_StackAlloc + + ; Spill argument registers. + SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters + + IF __PWTB_SaveFPArgs + SAVE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters + ENDIF + + ; Save callee-saved floating point registers if requested + IF "$pushCalleeSavedFloatRegs" == "PushCalleeSavedFloatRegs" + stp d8, d9, [sp, #__PWTB_FloatCalleeSavedRegisters] + stp d10, d11, [sp, #(__PWTB_FloatCalleeSavedRegisters + 16)] + stp d12, d13, [sp, #(__PWTB_FloatCalleeSavedRegisters + 32)] + stp d14, d15, [sp, #(__PWTB_FloatCalleeSavedRegisters + 48)] + ENDIF + + MEND + +;----------------------------------------------------------------------------- +; Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK. +; + MACRO + EPILOG_WITH_TRANSITION_BLOCK + + EPILOG_STACK_FREE __PWTB_StackAlloc + + EPILOG_RESTORE_REG_PAIR x19, x20, #16 + EPILOG_RESTORE_REG_PAIR x21, x22, #32 + EPILOG_RESTORE_REG_PAIR x23, x24, #48 + EPILOG_RESTORE_REG_PAIR x25, x26, #64 + EPILOG_RESTORE_REG_PAIR x27, x28, #80 + EPILOG_RESTORE_REG_PAIR fp, lr, #(__PWTB_TransitionBlockSize)! + MEND + +;----------------------------------------------------------------------------- +; Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and returns to caller. +; + MACRO + EPILOG_WITH_TRANSITION_BLOCK_RETURN + + EPILOG_WITH_TRANSITION_BLOCK + EPILOG_RETURN + MEND + +;----------------------------------------------------------------------------- +; Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. +; Since this is a tail call argument registers are restored. +; + MACRO + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + + IF __PWTB_SaveFPArgs + RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters + ENDIF + + RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters + EPILOG_STACK_FREE __PWTB_StackAlloc + + EPILOG_RESTORE_REG_PAIR x19, x20, #16 + EPILOG_RESTORE_REG_PAIR x21, x22, #32 + EPILOG_RESTORE_REG_PAIR x23, x24, #48 + EPILOG_RESTORE_REG_PAIR x25, x26, #64 + EPILOG_RESTORE_REG_PAIR x27, x28, #80 + EPILOG_RESTORE_REG_PAIR fp, lr, #(__PWTB_TransitionBlockSize)! + MEND diff --git a/src/coreclr/runtime/loongarch64/AsmMacros_Unix.inc b/src/coreclr/runtime/loongarch64/AsmMacros_Unix.inc index 405f2337f6eef0..a7d33a6b410747 100644 --- a/src/coreclr/runtime/loongarch64/AsmMacros_Unix.inc +++ b/src/coreclr/runtime/loongarch64/AsmMacros_Unix.inc @@ -308,3 +308,90 @@ C_FUNC(\Name\()_End): ld.d $ra, $sp, 8 addi.d $sp, $sp, 16 .endm + +//----------------------------------------------------------------------------- +// The following group of macros assist in implementing prologs and epilogs for methods that set up TransitionFrame. +// +// PROLOG_WITH_TRANSITION_BLOCK should be called first in the method and comprises the entire prolog +// (i.e. don't modify SP after calling this). The locals must be 8 byte aligned. +// +// Stack layout: +// +// extra locals +// FloatArgumentRegisters (fa0 - fa7) if SaveFPRegs=1 +// struct TransitionBlock +// { +// CalleeSavedRegisters (fp, ra, s0 - s8) +// padding +// ArgumentRegisters (a0 - a7) +// } +// Stack arguments +// +.macro PROLOG_WITH_TRANSITION_BLOCK extraParameters = 0, extraLocals = 0, SaveFPRegs = 1 + + __PWTB_SaveFPArgs = \SaveFPRegs + + __PWTB_FloatArgumentRegisters = \extraLocals + + .if ((__PWTB_FloatArgumentRegisters % 16) != 0) + __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8 + .endif + + __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters + + .if (__PWTB_SaveFPArgs == 1) + __PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters + .endif + + + __PWTB_CalleeSavedRegisters = __PWTB_TransitionBlock + __PWTB_ArgumentRegisters = __PWTB_TransitionBlock + 11 * 8 + 8 // CalleeSavedRegisters + padding + __PWTB_StackAlloc = __PWTB_ArgumentRegisters + 8 * 8 + + PROLOG_STACK_ALLOC __PWTB_StackAlloc + // $fp,$ra + PROLOG_SAVE_REG_PAIR 22, 1, __PWTB_CalleeSavedRegisters, 1 + + SAVE_ARGUMENT_REGISTERS $sp, __PWTB_ArgumentRegisters + + // $sp + SAVE_CALLEESAVED_REGISTERS 3, __PWTB_CalleeSavedRegisters + + .if (__PWTB_SaveFPArgs == 1) + SAVE_FLOAT_ARGUMENT_REGISTERS $sp, __PWTB_FloatArgumentRegisters + .endif + +.endm + +.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN + + RESTORE_CALLEESAVED_REGISTERS 3, __PWTB_CalleeSavedRegisters + + EPILOG_RESTORE_REG_PAIR 22, 1, __PWTB_CalleeSavedRegisters + + EPILOG_STACK_FREE __PWTB_StackAlloc + + jirl $r0, $ra, 0 + +.endm + + +//----------------------------------------------------------------------------- +// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. +// Since this is a tail call argument registers are restored. +// +.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + + .if (__PWTB_SaveFPArgs == 1) + RESTORE_FLOAT_ARGUMENT_REGISTERS $sp, __PWTB_FloatArgumentRegisters + .endif + + RESTORE_CALLEESAVED_REGISTERS 3, __PWTB_CalleeSavedRegisters + + RESTORE_ARGUMENT_REGISTERS $sp, __PWTB_ArgumentRegisters + + EPILOG_RESTORE_REG_PAIR 22, 1, __PWTB_CalleeSavedRegisters + + EPILOG_STACK_FREE __PWTB_StackAlloc + +.endm diff --git a/src/coreclr/runtime/riscv64/AsmMacros_Unix.inc b/src/coreclr/runtime/riscv64/AsmMacros_Unix.inc index c8152f22cf72f7..1fbf9fbb834766 100644 --- a/src/coreclr/runtime/riscv64/AsmMacros_Unix.inc +++ b/src/coreclr/runtime/riscv64/AsmMacros_Unix.inc @@ -340,3 +340,113 @@ C_FUNC(\Name): */ .endm + +//----------------------------------------------------------------------------- +// The following group of macros assist in implementing prologs and epilogs for methods that set up TransitionFrame. +// +// PROLOG_WITH_TRANSITION_BLOCK should be called first in the method and comprises the entire prolog +// (i.e. don't modify SP after calling this). The locals must be 8 byte aligned. +// +// Stack layout: +// +// extra locals +// FloatCalleeSavedRegisters (fs0 - fs11) if pushCalleeSavedFloatRegs=1 +// FloatArgumentRegisters (fa0 - fa7) if SaveFPRegs=1 +// struct TransitionBlock +// { +// CalleeSavedRegisters (fp, ra, s1 - s11, tp, gp) +// padding +// ArgumentRegisters (a0 - a7) +// } +// Stack arguments +// +// pushCalleeSavedFloatRegs - Optional parameter. If set to 1, the macro will also save +// the callee-saved floating point registers (fs0-fs11) to the stack. +// These registers are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. +// +.macro PROLOG_WITH_TRANSITION_BLOCK extraParameters = 0, extraLocals = 0, SaveFPRegs = 1, pushCalleeSavedFloatRegs = 0 + __PWTB_SaveFPArgs = \SaveFPRegs + __PWTB_PushCalleeSavedFloatRegs = \pushCalleeSavedFloatRegs + + __PWTB_FloatCalleeSavedRegisters = \extraLocals + + // Note, stack (see __PWTB_StackAlloc variable) must be 16 byte aligned. + .if ((__PWTB_FloatCalleeSavedRegisters % 16) != 0) + __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatCalleeSavedRegisters + 8 + .endif + + // If pushCalleeSavedFloatRegs is specified, reserve space for fs0-fs11 (12 registers * 8 bytes = 96 bytes) + .if (__PWTB_PushCalleeSavedFloatRegs == 1) + __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + 96 + .else + __PWTB_FloatArgumentRegisters = __PWTB_FloatCalleeSavedRegisters + .endif + + __PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters + + .if (__PWTB_SaveFPArgs == 1) + __PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters + .endif + + + __PWTB_CalleeSavedRegisters = __PWTB_TransitionBlock + __PWTB_ArgumentRegisters = __PWTB_TransitionBlock + 15 * 8 + 8 // CalleeSavedRegisters + padding + __PWTB_StackAlloc = __PWTB_ArgumentRegisters + 8 * 8 + + PROLOG_STACK_ALLOC __PWTB_StackAlloc + PROLOG_SAVE_REG_PAIR fp, ra, __PWTB_CalleeSavedRegisters, 1 + + SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters + + SAVE_CALLEESAVED_REGISTERS sp, __PWTB_CalleeSavedRegisters + + .if (__PWTB_SaveFPArgs == 1) + SAVE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters + .endif + + // Save callee-saved floating point registers if requested + .if (__PWTB_PushCalleeSavedFloatRegs == 1) + fsd fs0, (__PWTB_FloatCalleeSavedRegisters)(sp) + fsd fs1, (__PWTB_FloatCalleeSavedRegisters + 8)(sp) + fsd fs2, (__PWTB_FloatCalleeSavedRegisters + 16)(sp) + fsd fs3, (__PWTB_FloatCalleeSavedRegisters + 24)(sp) + fsd fs4, (__PWTB_FloatCalleeSavedRegisters + 32)(sp) + fsd fs5, (__PWTB_FloatCalleeSavedRegisters + 40)(sp) + fsd fs6, (__PWTB_FloatCalleeSavedRegisters + 48)(sp) + fsd fs7, (__PWTB_FloatCalleeSavedRegisters + 56)(sp) + fsd fs8, (__PWTB_FloatCalleeSavedRegisters + 64)(sp) + fsd fs9, (__PWTB_FloatCalleeSavedRegisters + 72)(sp) + fsd fs10, (__PWTB_FloatCalleeSavedRegisters + 80)(sp) + fsd fs11, (__PWTB_FloatCalleeSavedRegisters + 88)(sp) + .endif + +.endm + +.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN + RESTORE_CALLEESAVED_REGISTERS sp, __PWTB_CalleeSavedRegisters + + EPILOG_RESTORE_REG_PAIR fp, ra, __PWTB_CalleeSavedRegisters + + EPILOG_STACK_FREE __PWTB_StackAlloc + + ret +.endm + + +//----------------------------------------------------------------------------- +// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. +// Since this is a tail call argument registers are restored. +// +.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + .if (__PWTB_SaveFPArgs == 1) + RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters + .endif + + RESTORE_CALLEESAVED_REGISTERS sp, __PWTB_CalleeSavedRegisters + + RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters + + EPILOG_RESTORE_REG_PAIR fp, ra, __PWTB_CalleeSavedRegisters + + EPILOG_STACK_FREE __PWTB_StackAlloc +.endm diff --git a/src/coreclr/vm/amd64/AsmMacros.inc b/src/coreclr/vm/amd64/AsmMacros.inc index 97225eff78ea90..8fc1ef4ec66109 100644 --- a/src/coreclr/vm/amd64/AsmMacros.inc +++ b/src/coreclr/vm/amd64/AsmMacros.inc @@ -36,142 +36,6 @@ Section ends endm -; Stack layout: -; -; (stack parameters) -; ... -; r9 -; r8 -; rdx -; rcx <- __PWTB_ArgumentRegisters -; return address -; CalleeSavedRegisters::r15 -; CalleeSavedRegisters::r14 -; CalleeSavedRegisters::r13 -; CalleeSavedRegisters::r12 -; CalleeSavedRegisters::rbp -; CalleeSavedRegisters::rbx -; CalleeSavedRegisters::rsi -; CalleeSavedRegisters::rdi <- __PWTB_StackAlloc -; padding to align xmm save area -; xmm3 -; xmm2 -; xmm1 -; xmm0 <- __PWTB_FloatArgumentRegisters -; Optional: Callee saved floating point registers -; xmm15 -; . -; . -; xmm6 -; extra locals + padding to qword align -; callee's r9 -; callee's r8 -; callee's rdx -; callee's rcx - -PROLOG_WITH_TRANSITION_BLOCK macro extraLocals := <0>, calleeSavedFloatRegs := , stackAllocOnEntry := <0>, stackAllocSpill1, stackAllocSpill2, stackAllocSpill3 - - __PWTB_FloatArgumentRegisters = SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES + extraLocals - - if (__PWTB_FloatArgumentRegisters mod 16) ne 0 - __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8 - endif - - ifidn , - __PWTB_FloatCalleeSavedRegisters = __PWTB_FloatArgumentRegisters - __PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 10 * 16 - endif - - __PWTB_StackAlloc = __PWTB_FloatArgumentRegisters + 4 * 16 + 8 - __PWTB_TransitionBlock = __PWTB_StackAlloc - __PWTB_ArgumentRegisters = __PWTB_StackAlloc + 9 * 8 - - .errnz stackAllocOnEntry ge 4*8, Max supported stackAllocOnEntry is 3*8 - - if stackAllocOnEntry gt 0 - .allocstack stackAllocOnEntry - endif - - ; PUSH_CALLEE_SAVED_REGISTERS expanded here - - if stackAllocOnEntry lt 8 - push_nonvol_reg r15 - endif - - if stackAllocOnEntry lt 2*8 - push_nonvol_reg r14 - endif - - if stackAllocOnEntry lt 3*8 - push_nonvol_reg r13 - endif - - push_nonvol_reg r12 - push_nonvol_reg rbp - push_nonvol_reg rbx - push_nonvol_reg rsi - push_nonvol_reg rdi - - alloc_stack __PWTB_StackAlloc - SAVE_ARGUMENT_REGISTERS __PWTB_ArgumentRegisters - SAVE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters - - ifidn , - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters], xmm6 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 10h], xmm7 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 20h], xmm8 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 30h], xmm9 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 40h], xmm10 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 50h], xmm11 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 60h], xmm12 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 70h], xmm13 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 80h], xmm14 - movdqa [rsp + __PWTB_FloatCalleeSavedRegisters + 90h], xmm15 - endif - - if stackAllocOnEntry ge 3*8 - mov stackAllocSpill3, [rsp + __PWTB_StackAlloc + 28h] - save_reg_postrsp r13, __PWTB_StackAlloc + 28h - endif - - if stackAllocOnEntry ge 2*8 - mov stackAllocSpill2, [rsp + __PWTB_StackAlloc + 30h] - save_reg_postrsp r14, __PWTB_StackAlloc + 30h - endif - - if stackAllocOnEntry ge 8 - mov stackAllocSpill1, [rsp + __PWTB_StackAlloc + 38h] - save_reg_postrsp r15, __PWTB_StackAlloc + 38h - endif - - END_PROLOGUE - - endm - -EPILOG_WITH_TRANSITION_BLOCK macro - - add rsp, __PWTB_StackAlloc - POP_CALLEE_SAVED_REGISTERS - - endm - -EPILOG_WITH_TRANSITION_BLOCK_RETURN macro - - add rsp, __PWTB_StackAlloc - POP_CALLEE_SAVED_REGISTERS - ret - - endm - -EPILOG_WITH_TRANSITION_BLOCK_TAILCALL macro - - RESTORE_FLOAT_ARGUMENT_REGISTERS __PWTB_FloatArgumentRegisters - RESTORE_ARGUMENT_REGISTERS __PWTB_ArgumentRegisters - add rsp, __PWTB_StackAlloc - POP_CALLEE_SAVED_REGISTERS - - endm - t_runtime_thread_locals TEXTEQU ; Inlined version of GetThreadEEAllocContext. Trashes RegTrash, r11 @@ -194,7 +58,7 @@ OFFSETOF__ee_alloc_context EQU OFFSETOF__RuntimeThreadLocals__ee_alloc_context ; the PROLOG_WITH_TRANSITION_BLOCK macro for the stack layout. PUSH_COOP_PINVOKE_FRAME macro target - __PWTB_StackAlloc = SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES + 8 ; alignment to make the stack 16b aligned + __PWTB_StackAlloc = SIZEOF_ARGUMENT_SHADOW_SPACE + 8 ; alignment to make the stack 16b aligned __PWTB_TransitionBlock = __PWTB_StackAlloc PUSH_CALLEE_SAVED_REGISTERS diff --git a/src/coreclr/vm/amd64/ComCallPreStub.asm b/src/coreclr/vm/amd64/ComCallPreStub.asm index b17b5a7ff016e8..ce6f0051d25370 100644 --- a/src/coreclr/vm/amd64/ComCallPreStub.asm +++ b/src/coreclr/vm/amd64/ComCallPreStub.asm @@ -12,7 +12,7 @@ extern UMEntryPrestubUnwindFrameChainHandler:proc NESTED_ENTRY ComCallPreStub, _TEXT, UMEntryPrestubUnwindFrameChainHandler -ComCallPreStub_STACK_FRAME_SIZE = SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES +ComCallPreStub_STACK_FRAME_SIZE = SIZEOF_ARGUMENT_SHADOW_SPACE ; XMM save area ComCallPreStub_XMM_SAVE_OFFSET = ComCallPreStub_STACK_FRAME_SIZE diff --git a/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm b/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm index fcdac50f939199..d8c438fa15323a 100644 --- a/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm +++ b/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm @@ -35,7 +35,7 @@ NESTED_ENTRY DelayLoad_Helper&suffix, _TEXT PROLOG_WITH_TRANSITION_BLOCK 8h, DoNotPushCalleeSavedFloatRegs, 10h, r8, r9 - mov qword ptr [rsp + SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES], frameFlags + mov qword ptr [rsp + SIZEOF_ARGUMENT_SHADOW_SPACE], frameFlags lea rcx, [rsp + __PWTB_TransitionBlock] ; pTransitionBlock mov rdx, rax ; pIndirection diff --git a/src/coreclr/vm/amd64/RedirectedHandledJITCase.asm b/src/coreclr/vm/amd64/RedirectedHandledJITCase.asm index 15a33bdce0bc18..86efa0d2d3579e 100644 --- a/src/coreclr/vm/amd64/RedirectedHandledJITCase.asm +++ b/src/coreclr/vm/amd64/RedirectedHandledJITCase.asm @@ -98,7 +98,7 @@ endif ; scratch area -OFFSET_OF_FRAME = SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES +OFFSET_OF_FRAME = SIZEOF_ARGUMENT_SHADOW_SPACE ; force evaluation to avoid "expression is too complex errors" SIZEOF__FaultingExceptionFrame = SIZEOF__FaultingExceptionFrame @@ -173,7 +173,7 @@ LEAF_END STUB&_FixRsp, _TEXT endm -REDIRECT_FOR_THROW_CONTROL_FRAME_SIZE = SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES + 8 +REDIRECT_FOR_THROW_CONTROL_FRAME_SIZE = SIZEOF_ARGUMENT_SHADOW_SPACE + 8 NESTED_ENTRY RedirectForThrowControl2, _TEXT diff --git a/src/coreclr/vm/amd64/UMThunkStub.asm b/src/coreclr/vm/amd64/UMThunkStub.asm index b58808c291a1b1..e1b2ba0092d878 100644 --- a/src/coreclr/vm/amd64/UMThunkStub.asm +++ b/src/coreclr/vm/amd64/UMThunkStub.asm @@ -12,7 +12,7 @@ extern UMEntryPrestubUnwindFrameChainHandler:proc ; NESTED_ENTRY TheUMEntryPrestub, _TEXT, UMEntryPrestubUnwindFrameChainHandler -TheUMEntryPrestub_STACK_FRAME_SIZE = SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES +TheUMEntryPrestub_STACK_FRAME_SIZE = SIZEOF_ARGUMENT_SHADOW_SPACE ; XMM save area TheUMEntryPrestub_XMM_SAVE_OFFSET = TheUMEntryPrestub_STACK_FRAME_SIZE diff --git a/src/coreclr/vm/amd64/asmconstants.h b/src/coreclr/vm/amd64/asmconstants.h index 2614442b3a8588..0ab88714e8661e 100644 --- a/src/coreclr/vm/amd64/asmconstants.h +++ b/src/coreclr/vm/amd64/asmconstants.h @@ -59,13 +59,9 @@ ASMCONSTANTS_C_ASSERT(ASM_ELEMENT_TYPE_R8 == ELEMENT_TYPE_R8); #endif // FEATURE_VARARGS #ifdef UNIX_AMD64_ABI -// rdi, rsi, rdx, rcx, r8, r9 -#define SIZEOF_MAX_INT_ARG_SPILL 0x30 // xmm0...xmm7 #define SIZEOF_MAX_FP_ARG_SPILL 0x80 #else -// rcx, rdx, r8, r9 -#define SIZEOF_MAX_OUTGOING_ARGUMENT_HOMES 0x20 // xmm0...xmm3 #define SIZEOF_MAX_FP_ARG_SPILL 0x40 #endif diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 5769c4f2f2b6a5..23d35bbb128d18 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -191,7 +191,7 @@ GenerateRedirectedHandledJITCaseStub GCStress // PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -16 - PROLOG_STACK_ALLOC FaultingExceptionFrame_StackAlloc + sub sp, sp, FaultingExceptionFrame_StackAlloc // At this point, the stack maybe misaligned if the thread abort was asynchronously // triggered in the prolog or epilog of the managed method. For such a case, we must @@ -380,7 +380,10 @@ C_FUNC(DelayLoad_Helper\suffix): bl C_FUNC(DynamicHelperWorker) cbnz x0, LOCAL_LABEL(FakeProlog\suffix\()_0) ldr x0, [sp, #__PWTB_ArgumentRegister_FirstArg] + .cfi_remember_state EPILOG_WITH_TRANSITION_BLOCK_RETURN + .cfi_restore_state + .cfi_def_cfa_offset __PWTB_TransitionBlockSize // workaround cfi_restore_state bug LOCAL_LABEL(FakeProlog\suffix\()_0): mov x12, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL diff --git a/src/coreclr/vm/arm64/asmmacros.h b/src/coreclr/vm/arm64/asmmacros.h index 43e94127c09999..d3b1b92f76d36e 100644 --- a/src/coreclr/vm/arm64/asmmacros.h +++ b/src/coreclr/vm/arm64/asmmacros.h @@ -3,139 +3,6 @@ #include "arm64/AsmMacros_Windows.h" -;----------------------------------------------------------------------------- -; The following group of macros assist in implementing prologs and epilogs for methods that set up some -; subclass of TransitionFrame. They ensure that the SP is 16-byte aligned at the conclusion of the prolog - -;----------------------------------------------------------------------------- -; Define the prolog for a TransitionFrame-based method. This macro should be called first in the method and -; comprises the entire prolog (i.e. don't modify SP after calling this).The locals must be 8 byte aligned -; -; $pushCalleeSavedFloatRegs - Optional parameter. If set to PushCalleeSavedFloatRegs, the macro will also save -; the callee-saved floating point registers (d8-d15) to the stack. These registers -; are NOT restored by the EPILOG_WITH_TRANSITION_BLOCK variants. -; - MACRO - PROLOG_WITH_TRANSITION_BLOCK $extraLocals, $SaveFPArgs, $pushCalleeSavedFloatRegs - - GBLA __PWTB_FloatArgumentRegisters - GBLA __PWTB_FloatCalleeSavedRegisters - GBLA __PWTB_ArgumentRegisters - GBLA __PWTB_ArgumentRegister_FirstArg ; We save the x8 register ahead of the first argument, so this - ; is different from the start of the argument register save area. - GBLA __PWTB_StackAlloc - GBLA __PWTB_TransitionBlock - GBLL __PWTB_SaveFPArgs - - IF "$SaveFPArgs" != "" -__PWTB_SaveFPArgs SETL $SaveFPArgs - ELSE -__PWTB_SaveFPArgs SETL {true} - ENDIF - - IF "$extraLocals" != "" -__PWTB_FloatCalleeSavedRegisters SETA $extraLocals - ELSE -__PWTB_FloatCalleeSavedRegisters SETA 0 - ENDIF - - IF __PWTB_FloatCalleeSavedRegisters:MOD:16 != 0 -__PWTB_FloatCalleeSavedRegisters SETA __PWTB_FloatCalleeSavedRegisters + 8 - ENDIF - - ; If PushCalleeSavedFloatRegs is specified, reserve space for d8-d15 (8 registers * 8 bytes = 64 bytes) - IF "$pushCalleeSavedFloatRegs" == "PushCalleeSavedFloatRegs" -__PWTB_FloatArgumentRegisters SETA __PWTB_FloatCalleeSavedRegisters + 64 - ELSE -__PWTB_FloatArgumentRegisters SETA __PWTB_FloatCalleeSavedRegisters - ENDIF - - IF __PWTB_SaveFPArgs -__PWTB_TransitionBlock SETA __PWTB_FloatArgumentRegisters + SIZEOF__FloatArgumentRegisters - ELSE -__PWTB_TransitionBlock SETA __PWTB_FloatArgumentRegisters - ENDIF - -__PWTB_StackAlloc SETA __PWTB_TransitionBlock -__PWTB_ArgumentRegisters SETA __PWTB_StackAlloc + 104 -__PWTB_ArgumentRegister_FirstArg SETA __PWTB_ArgumentRegisters + 8 - - PROLOG_SAVE_REG_PAIR fp, lr, #-176! - ; Spill callee saved registers - PROLOG_SAVE_REG_PAIR x19, x20, #16 - PROLOG_SAVE_REG_PAIR x21, x22, #32 - PROLOG_SAVE_REG_PAIR x23, x24, #48 - PROLOG_SAVE_REG_PAIR x25, x26, #64 - PROLOG_SAVE_REG_PAIR x27, x28, #80 - - ; Allocate space for the rest of the frame - PROLOG_STACK_ALLOC __PWTB_StackAlloc - - ; Spill argument registers. - SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters - - IF __PWTB_SaveFPArgs - SAVE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters - ENDIF - - ; Save callee-saved floating point registers if requested - IF "$pushCalleeSavedFloatRegs" == "PushCalleeSavedFloatRegs" - stp d8, d9, [sp, #__PWTB_FloatCalleeSavedRegisters] - stp d10, d11, [sp, #(__PWTB_FloatCalleeSavedRegisters + 16)] - stp d12, d13, [sp, #(__PWTB_FloatCalleeSavedRegisters + 32)] - stp d14, d15, [sp, #(__PWTB_FloatCalleeSavedRegisters + 48)] - ENDIF - - MEND - -;----------------------------------------------------------------------------- -; Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK. -; - MACRO - EPILOG_WITH_TRANSITION_BLOCK - - EPILOG_STACK_FREE __PWTB_StackAlloc - - EPILOG_RESTORE_REG_PAIR x19, x20, #16 - EPILOG_RESTORE_REG_PAIR x21, x22, #32 - EPILOG_RESTORE_REG_PAIR x23, x24, #48 - EPILOG_RESTORE_REG_PAIR x25, x26, #64 - EPILOG_RESTORE_REG_PAIR x27, x28, #80 - EPILOG_RESTORE_REG_PAIR fp, lr, #176! - MEND - -;----------------------------------------------------------------------------- -; Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and returns to caller. -; - MACRO - EPILOG_WITH_TRANSITION_BLOCK_RETURN - - EPILOG_WITH_TRANSITION_BLOCK - EPILOG_RETURN - MEND - -;----------------------------------------------------------------------------- -; Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling. -; Since this is a tail call argument registers are restored. -; - MACRO - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - - IF __PWTB_SaveFPArgs - RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters - ENDIF - - RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters - EPILOG_STACK_FREE __PWTB_StackAlloc - - EPILOG_RESTORE_REG_PAIR x19, x20, #16 - EPILOG_RESTORE_REG_PAIR x21, x22, #32 - EPILOG_RESTORE_REG_PAIR x23, x24, #48 - EPILOG_RESTORE_REG_PAIR x25, x26, #64 - EPILOG_RESTORE_REG_PAIR x27, x28, #80 - EPILOG_RESTORE_REG_PAIR fp, lr, #176! - MEND - ;----------------------------------------------------------------------------- ; Macros used for shared allocation helpers diff --git a/src/coreclr/vm/eetwain.cpp b/src/coreclr/vm/eetwain.cpp index 007f8f62a77c2a..efc20b3988cbab 100644 --- a/src/coreclr/vm/eetwain.cpp +++ b/src/coreclr/vm/eetwain.cpp @@ -1817,14 +1817,14 @@ unsigned int EECodeManager::GetFrameSize(GCInfoToken gcInfoToken) /*****************************************************************************/ -// This is an assembly helper that enables us to call into EH funclets. +// Calls a catch or finally funclet. EXTERN_C UINT_PTR F_CALL_CONV CallEHFunclet(Object *pThrowable, UINT_PTR pFuncletToInvoke, CONTEXT *pContext, UINT_PTR *pFuncletCallerSP); -// This is an assembly helper that enables us to call into EH filter funclets. +// Calls a filter funclet. EXTERN_C int F_CALL_CONV CallEHFilterFunclet(Object *pThrowable, CONTEXT *pContext, UINT_PTR pFuncletToInvoke, UINT_PTR *pFuncletCallerSP); #ifndef TARGET_WASMARCH -typedef DWORD_PTR (HandlerFn)(UINT_PTR uStackFrame, Object* pExceptionObj); +typedef UINT_PTR (HandlerFn)(UINT_PTR uStackFrame, Object* pExceptionObj); #else typedef TADDR HandlerFn; #endif // TARGET_WASMARCH @@ -1846,9 +1846,9 @@ static inline UINT_PTR CastHandlerFn(HandlerFn *pfnHandler) // * Catch funclet: address to resume at after the catch returns // * Finally funclet: unused // * Filter funclet: result of the filter funclet (EXCEPTION_CONTINUE_SEARCH (0) or EXCEPTION_EXECUTE_HANDLER (1)) -DWORD_PTR EECodeManager::CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilterFunclet) +UINT_PTR EECodeManager::CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilterFunclet) { - DWORD_PTR dwResult = 0; + UINT_PTR dwResult = 0; HandlerFn* pfnHandler = (HandlerFn*)pHandler; // Since the actual caller of the funclet is the assembly helper, pass the reference @@ -2007,7 +2007,7 @@ extern "C" DWORD_PTR STDCALL CallInterpreterFuncletWorker(OBJECTREF throwable, v } } -DWORD_PTR InterpreterCodeManager::CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter) +UINT_PTR InterpreterCodeManager::CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter) { #if !defined(TARGET_WASMARCH) // Call the ASM helper which creates a real TransitionBlock diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index 777e603f626602..882fb964c96f01 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -3058,7 +3058,7 @@ void CallCatchFunclet(BYTE* pHandlerIP, REGDISPLAY* pvRegDisplay, ExInfo* exInfo pThread->DecPreventAbort(); exInfo->m_ScannedStackRange.ExtendUpperBound(exInfo->m_frameIter.m_crawl.GetRegisterSet()->SP); - DWORD_PTR dwResumePC = 0; + UINT_PTR dwResumePC = 0; UINT_PTR callerTargetSp = 0; #if defined(HOST_AMD64) && defined(HOST_WINDOWS) @@ -3346,7 +3346,7 @@ extern "C" CLR_BOOL QCALLTYPE CallFilterFunclet(QCall::ObjectHandleOnStack excep { QCALL_CONTRACT; - DWORD_PTR dwResult = 0; + UINT_PTR dwResult = 0; BEGIN_QCALL;