From 907bff3fa5365d9e42421b1e6fe019f6f1b48e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Sowi=C5=84ski?= Date: Tue, 5 Sep 2023 16:25:35 +0200 Subject: [PATCH] Factor out hardcoded offsets to PROFILE_PLATFORM_SPECIFIC_DATA struct These offsets are now in asmconstants.h validated against the C struct with static asserts. --- src/coreclr/vm/amd64/asmconstants.h | 75 +++++++ src/coreclr/vm/amd64/asmhelpers.S | 241 +++++++++------------- src/coreclr/vm/amd64/cgencpu.h | 40 ++++ src/coreclr/vm/amd64/profiler.cpp | 42 +--- src/coreclr/vm/arm/asmconstants.h | 25 +++ src/coreclr/vm/arm/asmhelpers.S | 17 +- src/coreclr/vm/arm/cgencpu.h | 27 +++ src/coreclr/vm/arm/profiler.cpp | 26 +-- src/coreclr/vm/arm64/asmconstants.h | 39 ++++ src/coreclr/vm/arm64/asmhelpers.S | 24 +-- src/coreclr/vm/arm64/cgencpu.h | 27 +++ src/coreclr/vm/arm64/profiler.cpp | 23 +-- src/coreclr/vm/loongarch64/asmconstants.h | 39 ++++ src/coreclr/vm/loongarch64/asmhelpers.S | 28 ++- src/coreclr/vm/loongarch64/cgencpu.h | 28 +++ src/coreclr/vm/loongarch64/profiler.cpp | 24 +-- 16 files changed, 434 insertions(+), 291 deletions(-) diff --git a/src/coreclr/vm/amd64/asmconstants.h b/src/coreclr/vm/amd64/asmconstants.h index ebe9cb81042e5..cac0ba0f2d382 100644 --- a/src/coreclr/vm/amd64/asmconstants.h +++ b/src/coreclr/vm/amd64/asmconstants.h @@ -576,6 +576,81 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun #define CallCountingStubData__TargetForThresholdReached 0x10 ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached)) +#ifdef PROFILING_SUPPORTED +#define PROFILE_ENTER 0x1 +#define PROFILE_LEAVE 0x2 +#define PROFILE_TAILCALL 0x4 + +#define ASMCONSTANTS_C_ASSERT_OFFSET(type, field) \ + ASMCONSTANTS_C_ASSERT(type##__##field == offsetof(type, field)) + +#if defined(UNIX_AMD64_ABI) + #define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer 0x8*16 + ASMCONSTANTS_C_ASSERT(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer == + sizeof((*(PROFILE_PLATFORM_SPECIFIC_DATA*)0).buffer)) + #define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 0x8*22 + SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer +#else + #define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA__buffer 0 + #define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 0x8*12 +#endif // UNIX_AMD64_ABI +ASMCONSTANT_SIZEOF_ASSERT(PROFILE_PLATFORM_SPECIFIC_DATA) + +#define PROFILE_PLATFORM_SPECIFIC_DATA__functionId 0x0 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, functionId) +#define PROFILE_PLATFORM_SPECIFIC_DATA__rbp 0x8 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rbp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__probeRsp 0x10 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, probeRsp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__ip 0x18 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, ip) +#define PROFILE_PLATFORM_SPECIFIC_DATA__profiledRsp 0x20 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, profiledRsp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__rax 0x28 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rax) +#define PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg 0x30 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, hiddenArg) +#define PROFILE_PLATFORM_SPECIFIC_DATA__flt0 0x38 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt0) +#define PROFILE_PLATFORM_SPECIFIC_DATA__flt1 0x40 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt1) +#define PROFILE_PLATFORM_SPECIFIC_DATA__flt2 0x48 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt2) +#define PROFILE_PLATFORM_SPECIFIC_DATA__flt3 0x50 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt3) +#if defined(UNIX_AMD64_ABI) + #define PROFILE_PLATFORM_SPECIFIC_DATA__flt4 0x58 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt4) + #define PROFILE_PLATFORM_SPECIFIC_DATA__flt5 0x60 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt5) + #define PROFILE_PLATFORM_SPECIFIC_DATA__flt6 0x68 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt6) + #define PROFILE_PLATFORM_SPECIFIC_DATA__flt7 0x70 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flt7) + #define PROFILE_PLATFORM_SPECIFIC_DATA__rdi 0x78 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rdi) + #define PROFILE_PLATFORM_SPECIFIC_DATA__rsi 0x80 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rsi) + #define PROFILE_PLATFORM_SPECIFIC_DATA__rdx 0x88 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rdx) + #define PROFILE_PLATFORM_SPECIFIC_DATA__rcx 0x90 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, rcx) + #define PROFILE_PLATFORM_SPECIFIC_DATA__r8 0x98 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, r8) + #define PROFILE_PLATFORM_SPECIFIC_DATA__r9 0xa0 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, r9) + #define PROFILE_PLATFORM_SPECIFIC_DATA__flags 0xa8 +#else // !UNIX_AMD64_ABI + #define PROFILE_PLATFORM_SPECIFIC_DATA__flags 0x58 +#endif // UNIX_AMD64_ABI +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flags) +#if defined(UNIX_AMD64_ABI) + #define PROFILE_PLATFORM_SPECIFIC_DATA__buffer 0xb0 + ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, buffer) +#endif + +#undef ASMCONSTANTS_C_ASSERT_OFFSET +#endif // PROFILING_SUPPORTED + #undef ASMCONSTANTS_RUNTIME_ASSERT #undef ASMCONSTANTS_C_ASSERT #ifndef UNIX_AMD64_ABI diff --git a/src/coreclr/vm/amd64/asmhelpers.S b/src/coreclr/vm/amd64/asmhelpers.S index 9f45f9f39d599..8d83938246a2c 100644 --- a/src/coreclr/vm/amd64/asmhelpers.S +++ b/src/coreclr/vm/amd64/asmhelpers.S @@ -8,45 +8,12 @@ #define real4 dword #define real8 qword -# -# file: profile.cpp -# typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA -# { -# FunctionID *functionId; # function ID comes in the r11 register -# void *rbp; -# void *probersp; -# void *ip; -# void *profiledRsp; -# UINT64 rax; -# LPVOID hiddenArg; -# UINT64 flt0; -# UINT64 flt1; -# UINT64 flt2; -# UINT64 flt3; -# UINT64 flt4; -# UINT64 flt5; -# UINT64 flt6; -# UINT64 flt7; -# UINT64 rdi; -# UINT64 rsi; -# UINT64 rdx; -# UINT64 rcx; -# UINT64 r8; -# UINT64 r9; -# UINT32 flags; -# UINT64 buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE]; -# } PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; - # On linux arguments can be passed in non-sequential registers. Integer arguments are # passed in sequential integer registers and floating point registers are passed in # sequential floating point registers. This presents a problem when we go to pass the # struct argument as a COR_PRF_FUNCTION_ARGUMENT_RANGE which expects the arguments are # in one contiguous range. This space is a scratch space that the ArgIterator can use # to copy the structs to so they are sequential. -.equ SIZEOF_PROFILE_STRUCT_BUFFER, 0x8*16 - -# Space for register spilling -.equ SIZEOF_PROFILE_PLATFORM_SPECIFIC_DATA, 0x8*22 + SIZEOF_PROFILE_STRUCT_BUFFER # Pad the frame size by 0x8 so when the xmm0 and xmm1 register store/restore happens # we can align to 16 and be guaranteed to not exceed the frame size @@ -57,11 +24,7 @@ # data struct that we spill the general purpose registers to, then space to # spill xmm0 and xmm1, then finally 8 bytes of padding to ensure that the xmm # register reads/writes are aligned on 16 bytes. -.equ SIZEOF_STACK_FRAME, SIZEOF_PROFILE_PLATFORM_SPECIFIC_DATA + STACK_FUDGE_FACTOR - -.equ PROFILE_ENTER, 0x1 -.equ PROFILE_LEAVE, 0x2 -.equ PROFILE_TAILCALL, 0x4 +.equ SIZEOF_STACK_FRAME, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA + STACK_FUDGE_FACTOR # *********************************************************** # NOTE: @@ -102,29 +65,29 @@ NESTED_ENTRY ProfileEnterNaked, _TEXT, NoHandler # setup ProfilePlatformSpecificData structure xor r11, r11 # nullify r11 - mov [rsp + 0x0], r11 # r11 is null -- struct functionId field - save_reg_postrsp rbp, 0x8 # -- struct rbp field - mov [rsp + 0x10], rax # caller rsp -- struct probeRsp field - mov [rsp + 0x18], r10 # return address -- struct ip field - mov [rsp + 0x20], r15 # -- struct profiledRsp field - mov [rsp + 0x28], r11 # return value -- struct rax field - mov [rsp + 0x30], r11 # r11 is null -- struct hiddenArg field - movsd real8 ptr [rsp + 0x38], xmm0 # -- struct flt0 field - movsd real8 ptr [rsp + 0x40], xmm1 # -- struct flt1 field - movsd real8 ptr [rsp + 0x48], xmm2 # -- struct flt2 field - movsd real8 ptr [rsp + 0x50], xmm3 # -- struct flt3 field - movsd real8 ptr [rsp + 0x58], xmm4 # -- struct flt4 field - movsd real8 ptr [rsp + 0x60], xmm5 # -- struct flt5 field - movsd real8 ptr [rsp + 0x68], xmm6 # -- struct flt6 field - movsd real8 ptr [rsp + 0x70], xmm7 # -- struct flt7 field - mov [rsp + 0x78], rdi # -- struct rdi field - mov [rsp + 0x80], rsi # -- struct rsi field - mov [rsp + 0x88], rdx # -- struct rdx field - mov [rsp + 0x90], rcx # -- struct rcx field - mov [rsp + 0x98], r8 # -- struct r8 field - mov [rsp + 0xa0], r9 # -- struct r9 field - mov r10, 0x1 # PROFILE_ENTER - mov [rsp + 0xa8], r10d # -- struct flags field + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__functionId], r11 + save_reg_postrsp rbp, PROFILE_PLATFORM_SPECIFIC_DATA__rbp + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__probeRsp], rax # caller rsp + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__ip], r10 # return address + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__profiledRsp], r15 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rax], r11 # return value + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg], r11 # r11 is null + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt0], xmm0 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt1], xmm1 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt2], xmm2 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt3], xmm3 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt4], xmm4 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt5], xmm5 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt6], xmm6 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt7], xmm7 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdi], rdi + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rsi], rsi + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdx], rdx + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rcx], rcx + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r8], r8 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r9], r9 + mov r10, PROFILE_ENTER + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flags], r10d END_PROLOGUE @@ -134,22 +97,22 @@ NESTED_ENTRY ProfileEnterNaked, _TEXT, NoHandler call C_FUNC(ProfileEnter) # restore fp return registers - movsd xmm0, real8 ptr [rsp + 0x38] # -- struct flt0 field - movsd xmm1, real8 ptr [rsp + 0x40] # -- struct flt1 field - movsd xmm2, real8 ptr [rsp + 0x48] # -- struct flt2 field - movsd xmm3, real8 ptr [rsp + 0x50] # -- struct flt3 field - movsd xmm4, real8 ptr [rsp + 0x58] # -- struct flt4 field - movsd xmm5, real8 ptr [rsp + 0x60] # -- struct flt5 field - movsd xmm6, real8 ptr [rsp + 0x68] # -- struct flt6 field - movsd xmm7, real8 ptr [rsp + 0x70] # -- struct flt7 field + movsd xmm0, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt0] + movsd xmm1, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt1] + movsd xmm2, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt2] + movsd xmm3, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt3] + movsd xmm4, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt4] + movsd xmm5, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt5] + movsd xmm6, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt6] + movsd xmm7, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt7] # restore arg registers - mov rdi, [rsp + 0x78] - mov rsi, [rsp + 0x80] - mov rdx, [rsp + 0x88] - mov rcx, [rsp + 0x90] - mov r8, [rsp + 0x98] - mov r9, [rsp + 0xa0] + mov rdi, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdi] + mov rsi, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rsi] + mov rdx, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdx] + mov rcx, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rcx] + mov r8, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r8] + mov r9, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r9] # begin epilogue free_stack SIZEOF_STACK_FRAME @@ -182,29 +145,29 @@ NESTED_ENTRY ProfileLeaveNaked, _TEXT, NoHandler # setup ProfilePlatformSpecificData structure xor r11, r11 # nullify r11 - mov [rsp + 0x0], r11 # r11 is null -- struct functionId field - save_reg_postrsp rbp, 0x8 # -- struct rbp field - mov [rsp + 0x10], rbx # caller rsp -- struct probeRsp field - mov [rsp + 0x18], r10 # return address -- struct ip field - mov [rsp + 0x20], rsi # -- struct profiledRsp field - mov [rsp + 0x28], rax # return value -- struct rax field - mov [rsp + 0x30], r11 # r11 is null -- struct hiddenArg field - movsd real8 ptr [rsp + 0x38], xmm0 # -- struct flt0 field - movsd real8 ptr [rsp + 0x40], xmm1 # -- struct flt1 field - movsd real8 ptr [rsp + 0x48], xmm2 # -- struct flt2 field - movsd real8 ptr [rsp + 0x50], xmm3 # -- struct flt3 field - movsd real8 ptr [rsp + 0x58], xmm4 # -- struct flt4 field - movsd real8 ptr [rsp + 0x60], xmm5 # -- struct flt5 field - movsd real8 ptr [rsp + 0x68], xmm6 # -- struct flt6 field - movsd real8 ptr [rsp + 0x70], xmm7 # -- struct flt7 field - mov [rsp + 0x78], r11 # -- struct rdi field - mov [rsp + 0x80], r11 # -- struct rsi field - mov [rsp + 0x88], rdx # -- struct rdx field - mov [rsp + 0x90], r11 # -- struct rcx field - mov [rsp + 0x98], r11 # -- struct r8 field - mov [rsp + 0xa0], r11 # -- struct r9 field - mov r10, 0x2 # PROFILE_LEAVE - mov [rsp + 0xa8], r10d # flags -- struct flags field + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__functionId], r11 # r11 is null + save_reg_postrsp rbp, PROFILE_PLATFORM_SPECIFIC_DATA__rbp + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__probeRsp], rbx # caller rsp + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__ip], r10 # return address + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__profiledRsp], rsi + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rax], rax # return value + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg], r11 # r11 is null + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt0], xmm0 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt1], xmm1 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt2], xmm2 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt3], xmm3 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt4], xmm4 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt5], xmm5 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt6], xmm6 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt7], xmm7 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdi], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rsi], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdx], rdx + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rcx], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r8], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r9], r11 + mov r10, PROFILE_LEAVE + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flags], r10d END_PROLOGUE @@ -213,17 +176,17 @@ NESTED_ENTRY ProfileLeaveNaked, _TEXT, NoHandler call C_FUNC(ProfileLeave) # restore fp return registers - movsd xmm0, real8 ptr [rsp + 0x38] # -- struct flt0 field - movsd xmm1, real8 ptr [rsp + 0x40] # -- struct flt1 field - movsd xmm2, real8 ptr [rsp + 0x48] # -- struct flt2 field - movsd xmm3, real8 ptr [rsp + 0x50] # -- struct flt3 field - movsd xmm4, real8 ptr [rsp + 0x58] # -- struct flt4 field - movsd xmm5, real8 ptr [rsp + 0x60] # -- struct flt5 field - movsd xmm6, real8 ptr [rsp + 0x68] # -- struct flt6 field - movsd xmm7, real8 ptr [rsp + 0x70] # -- struct flt7 field + movsd xmm0, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt0] + movsd xmm1, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt1] + movsd xmm2, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt2] + movsd xmm3, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt3] + movsd xmm4, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt4] + movsd xmm5, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt5] + movsd xmm6, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt6] + movsd xmm7, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt7] # restore int return register - mov rax, [rsp + 0x28] + mov rax, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rax] # begin epilogue free_stack SIZEOF_STACK_FRAME @@ -256,29 +219,29 @@ NESTED_ENTRY ProfileTailcallNaked, _TEXT, NoHandler # setup ProfilePlatformSpecificData structure xor r11, r11 # nullify r11 - mov [rsp + 0x0], r11 # r11 is null -- struct functionId field - save_reg_postrsp rbp, 0x8 # -- struct rbp field - mov [rsp + 0x10], rbx # caller rsp -- struct probeRsp field - mov [rsp + 0x18], r10 # return address -- struct ip field - mov [rsp + 0x20], rsi # -- struct profiledRsp field - mov [rsp + 0x28], rax # return value -- struct rax field - mov [rsp + 0x30], r11 # r11 is null -- struct hiddenArg field - movsd real8 ptr [rsp + 0x38], xmm0 # -- struct flt0 field - movsd real8 ptr [rsp + 0x40], xmm1 # -- struct flt1 field - movsd real8 ptr [rsp + 0x48], xmm2 # -- struct flt2 field - movsd real8 ptr [rsp + 0x50], xmm3 # -- struct flt3 field - movsd real8 ptr [rsp + 0x58], xmm4 # -- struct flt4 field - movsd real8 ptr [rsp + 0x60], xmm5 # -- struct flt5 field - movsd real8 ptr [rsp + 0x68], xmm6 # -- struct flt6 field - movsd real8 ptr [rsp + 0x70], xmm7 # -- struct flt7 field - mov [rsp + 0x78], r11 # -- struct rdi field - mov [rsp + 0x80], r11 # -- struct rsi field - mov [rsp + 0x88], rdx # -- struct rdx field - mov [rsp + 0x90], r11 # -- struct rcx field - mov [rsp + 0x98], r11 # -- struct r8 field - mov [rsp + 0xa0], r11 # -- struct r9 field - mov r10, 0x2 # PROFILE_LEAVE - mov [rsp + 0xa8], r10d # flags -- struct flags field + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__functionId], r11 # r11 is null + save_reg_postrsp rbp, PROFILE_PLATFORM_SPECIFIC_DATA__rbp + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__probeRsp], rbx # caller rsp + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__ip], r10 # return address + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__profiledRsp], rsi + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rax], rax # return value + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg], r11 # r11 is null + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt0], xmm0 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt1], xmm1 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt2], xmm2 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt3], xmm3 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt4], xmm4 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt5], xmm5 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt6], xmm6 + movsd real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt7], xmm7 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdi], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rsi], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rdx], rdx + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rcx], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r8], r11 + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__r9], r11 + mov r10, PROFILE_LEAVE + mov [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flags], r10d END_PROLOGUE @@ -287,17 +250,17 @@ NESTED_ENTRY ProfileTailcallNaked, _TEXT, NoHandler call C_FUNC(ProfileTailcall) # restore fp return registers - movsd xmm0, real8 ptr [rsp + 0x38] # -- struct flt0 field - movsd xmm1, real8 ptr [rsp + 0x40] # -- struct flt1 field - movsd xmm2, real8 ptr [rsp + 0x48] # -- struct flt2 field - movsd xmm3, real8 ptr [rsp + 0x50] # -- struct flt3 field - movsd xmm4, real8 ptr [rsp + 0x58] # -- struct flt4 field - movsd xmm5, real8 ptr [rsp + 0x60] # -- struct flt5 field - movsd xmm6, real8 ptr [rsp + 0x68] # -- struct flt6 field - movsd xmm7, real8 ptr [rsp + 0x70] # -- struct flt7 field + movsd xmm0, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt0] + movsd xmm1, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt1] + movsd xmm2, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt2] + movsd xmm3, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt3] + movsd xmm4, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt4] + movsd xmm5, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt5] + movsd xmm6, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt6] + movsd xmm7, real8 ptr [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__flt7] # restore int return register - mov rax, [rsp + 0x28] + mov rax, [rsp + PROFILE_PLATFORM_SPECIFIC_DATA__rax] # begin epilogue free_stack SIZEOF_STACK_FRAME diff --git a/src/coreclr/vm/amd64/cgencpu.h b/src/coreclr/vm/amd64/cgencpu.h index 9603883ed8694..5dcaf12dfb812 100644 --- a/src/coreclr/vm/amd64/cgencpu.h +++ b/src/coreclr/vm/amd64/cgencpu.h @@ -277,7 +277,47 @@ struct EHContext { #include "stublinkeramd64.h" +//********************************************************************** +// Profiling +//********************************************************************** + +#ifdef PROFILING_SUPPORTED + +#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE 16 + +typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA +{ + FunctionID functionId; + void *rbp; + void *probeRsp; + void *ip; + void *profiledRsp; + UINT64 rax; + LPVOID hiddenArg; + UINT64 flt0; // floats stored as doubles + UINT64 flt1; + UINT64 flt2; + UINT64 flt3; +#if defined(UNIX_AMD64_ABI) + UINT64 flt4; + UINT64 flt5; + UINT64 flt6; + UINT64 flt7; + UINT64 rdi; + UINT64 rsi; + UINT64 rdx; + UINT64 rcx; + UINT64 r8; + UINT64 r9; +#endif + UINT32 flags; +#if defined(UNIX_AMD64_ABI) + // A buffer to copy structs in to so they are sequential for GetFunctionEnter3Info. + UINT64 buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE]; +#endif +} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; +#endif // PROFILING_SUPPORTED //********************************************************************** // Exception handling diff --git a/src/coreclr/vm/amd64/profiler.cpp b/src/coreclr/vm/amd64/profiler.cpp index a290016b131ff..26d9b970a7da2 100644 --- a/src/coreclr/vm/amd64/profiler.cpp +++ b/src/coreclr/vm/amd64/profiler.cpp @@ -12,52 +12,12 @@ #include "common.h" #ifdef PROFILING_SUPPORTED +#include "asmconstants.h" #include "proftoeeinterfaceimpl.h" #include "argdestination.h" MethodDesc *FunctionIdToMethodDesc(FunctionID functionID); -// TODO: move these to some common.h file -// FLAGS -#define PROFILE_ENTER 0x1 -#define PROFILE_LEAVE 0x2 -#define PROFILE_TAILCALL 0x4 - -#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE 16 - -typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA -{ - FunctionID functionId; - void *rbp; - void *probeRsp; - void *ip; - void *profiledRsp; - UINT64 rax; - LPVOID hiddenArg; - UINT64 flt0; // floats stored as doubles - UINT64 flt1; - UINT64 flt2; - UINT64 flt3; -#if defined(UNIX_AMD64_ABI) - UINT64 flt4; - UINT64 flt5; - UINT64 flt6; - UINT64 flt7; - UINT64 rdi; - UINT64 rsi; - UINT64 rdx; - UINT64 rcx; - UINT64 r8; - UINT64 r9; -#endif - UINT32 flags; -#if defined(UNIX_AMD64_ABI) - // A buffer to copy structs in to so they are sequential for GetFunctionEnter3Info. - UINT64 buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE]; -#endif -} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; - - /* * ProfileGetIPFromPlatformSpecificHandle * diff --git a/src/coreclr/vm/arm/asmconstants.h b/src/coreclr/vm/arm/asmconstants.h index b3b16f1ed62c9..a03ca4e7211a3 100644 --- a/src/coreclr/vm/arm/asmconstants.h +++ b/src/coreclr/vm/arm/asmconstants.h @@ -235,5 +235,30 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun #define CallCountingStubData__TargetForThresholdReached 0x08 ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached)) +#ifdef PROFILING_SUPPORTED +#define PROFILE_ENTER 0x1 +#define PROFILE_LEAVE 0x2 +#define PROFILE_TAILCALL 0x4 + +#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 104 +ASMCONSTANTS_C_ASSERT(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA == sizeof(PROFILE_PLATFORM_SPECIFIC_DATA)) + +#define ASMCONSTANTS_C_ASSERT_OFFSET(type, field) \ + ASMCONSTANTS_C_ASSERT(type##__##field == offsetof(type, field)) + +#define PROFILE_PLATFORM_SPECIFIC_DATA__functionId 80 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, functionId) +#define PROFILE_PLATFORM_SPECIFIC_DATA__probeSp 84 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, probeSp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp 88 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, profiledSp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg 92 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, hiddenArg) +#define PROFILE_PLATFORM_SPECIFIC_DATA__flags 96 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flags) + +#undef ASMCONSTANTS_C_ASSERT_OFFSET +#endif // PROFILING_SUPPORTED + #undef ASMCONSTANTS_RUNTIME_ASSERT #undef ASMCONSTANTS_C_ASSERT diff --git a/src/coreclr/vm/arm/asmhelpers.S b/src/coreclr/vm/arm/asmhelpers.S index cff06940290fb..997bd9ff74e7d 100644 --- a/src/coreclr/vm/arm/asmhelpers.S +++ b/src/coreclr/vm/arm/asmhelpers.S @@ -342,11 +342,8 @@ LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub, _TEXT bx lr LEAF_END JIT_ProfilerEnterLeaveTailcallStub, _TEXT -#define PROFILE_ENTER 1 -#define PROFILE_LEAVE 2 -#define PROFILE_TAILCALL 4 // size of profiler data structure plus alignment padding -#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 104+4 +#define PADDED_SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA+4 // typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA // { @@ -385,23 +382,23 @@ NESTED_ENTRY \helper\()Naked, _TEXT, NoHandler CHECK_STACK_ALIGNMENT // set the other args, starting with functionID - str r0, [sp, #80] + str r0, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__functionId] // probeSp is the original sp when this stub was called - add r2, sp, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA+20 - str r2, [sp, #84] + add r2, sp, PADDED_SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA+20 + str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__probeSp] // get the address of the arguments from the frame pointer, store in profiledSp add r2, r11, #8 - str r2, [sp, #88] + str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp] // clear hiddenArg movw r2, #0 - str r2, [sp, #92] + str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg] // set the flag to indicate what hook this is movw r2, \flags - str r2, [sp, #96] + str r2, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__flags] // sp is the address of PROFILE_PLATFORM_SPECIFIC_DATA, then call to C++ mov r1, sp diff --git a/src/coreclr/vm/arm/cgencpu.h b/src/coreclr/vm/arm/cgencpu.h index d31700e3477a4..e7888aecc83b0 100644 --- a/src/coreclr/vm/arm/cgencpu.h +++ b/src/coreclr/vm/arm/cgencpu.h @@ -174,6 +174,33 @@ struct EHContext { #define ARGUMENTREGISTERS_SIZE sizeof(ArgumentRegisters) + +//********************************************************************** +// Profiling +//********************************************************************** + +#ifdef PROFILING_SUPPORTED + +typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA +{ + UINT32 r0; // Keep r0 & r1 contiguous to make returning 64-bit results easier + UINT32 r1; + void *R11; + void *Pc; + union // Float arg registers as 32-bit (s0-s15) and 64-bit (d0-d7) + { + UINT32 s[16]; + UINT64 d[8]; + }; + FunctionID functionId; + void *probeSp; // stack pointer of managed function + void *profiledSp; // location of arguments on stack + LPVOID hiddenArg; + UINT32 flags; +} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; + +#endif // PROFILING_SUPPORTED + //********************************************************************** // Exception handling //********************************************************************** diff --git a/src/coreclr/vm/arm/profiler.cpp b/src/coreclr/vm/arm/profiler.cpp index eba128093324f..410417a667a01 100644 --- a/src/coreclr/vm/arm/profiler.cpp +++ b/src/coreclr/vm/arm/profiler.cpp @@ -13,34 +13,10 @@ #ifdef PROFILING_SUPPORTED #include "proftoeeinterfaceimpl.h" +#include "asmconstants.h" MethodDesc *FunctionIdToMethodDesc(FunctionID functionID); -// TODO: move these to some common.h file -// FLAGS -#define PROFILE_ENTER 0x1 -#define PROFILE_LEAVE 0x2 -#define PROFILE_TAILCALL 0x4 - -typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA -{ - UINT32 r0; // Keep r0 & r1 contiguous to make returning 64-bit results easier - UINT32 r1; - void *R11; - void *Pc; - union // Float arg registers as 32-bit (s0-s15) and 64-bit (d0-d7) - { - UINT32 s[16]; - UINT64 d[8]; - }; - FunctionID functionId; - void *probeSp; // stack pointer of managed function - void *profiledSp; // location of arguments on stack - LPVOID hiddenArg; - UINT32 flags; -} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; - - /* * ProfileGetIPFromPlatformSpecificHandle * diff --git a/src/coreclr/vm/arm64/asmconstants.h b/src/coreclr/vm/arm64/asmconstants.h index 5210438aad3de..46a446c0c8416 100644 --- a/src/coreclr/vm/arm64/asmconstants.h +++ b/src/coreclr/vm/arm64/asmconstants.h @@ -233,5 +233,44 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun #define CallCountingStubData__TargetForThresholdReached 0x10 ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached)) +#ifdef PROFILING_SUPPORTED +#define PROFILE_ENTER 0x1 +#define PROFILE_LEAVE 0x2 +#define PROFILE_TAILCALL 0x4 + +#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 320 +ASMCONSTANTS_C_ASSERT(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA == sizeof(PROFILE_PLATFORM_SPECIFIC_DATA)) + +#define ASMCONSTANTS_C_ASSERT_OFFSET(type, field) \ + ASMCONSTANTS_C_ASSERT(type##__##field == offsetof(type, field)) + +#define PROFILE_PLATFORM_SPECIFIC_DATA__Fp 0 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, Fp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__Pc 8 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, Pc) +#define PROFILE_PLATFORM_SPECIFIC_DATA__x8 16 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, x8) +#define PROFILE_PLATFORM_SPECIFIC_DATA__argumentRegisters 24 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, argumentRegisters) +#define PROFILE_PLATFORM_SPECIFIC_DATA__functionId 88 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, functionId) +#define PROFILE_PLATFORM_SPECIFIC_DATA__floatArgumentRegisters 96 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, floatArgumentRegisters) +#define PROFILE_PLATFORM_SPECIFIC_DATA__probeSp 224 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, probeSp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp 232 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, profiledSp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg 240 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, hiddenArg) +#define PROFILE_PLATFORM_SPECIFIC_DATA__flags 248 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flags) +#define PROFILE_PLATFORM_SPECIFIC_DATA__unused 252 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, unused) +#define PROFILE_PLATFORM_SPECIFIC_DATA__buffer 256 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, buffer) + +#undef ASMCONSTANTS_C_ASSERT_OFFSET +#endif // PROFILING_SUPPORTED + #undef ASMCONSTANTS_RUNTIME_ASSERT #undef ASMCONSTANTS_C_ASSERT diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index e12db2efcddba..49d4c4ea34ad7 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -938,12 +938,6 @@ LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub, _TEXT ret lr LEAF_END JIT_ProfilerEnterLeaveTailcallStub, _TEXT -// ------------------------------------------------------------------ -#define PROFILE_ENTER 1 -#define PROFILE_LEAVE 2 -#define PROFILE_TAILCALL 4 -#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 320 - // ------------------------------------------------------------------ .macro GenerateProfileHelper helper, flags NESTED_ENTRY \helper\()Naked, _TEXT, NoHandler @@ -957,21 +951,21 @@ NESTED_ENTRY \helper\()Naked, _TEXT, NoHandler // Values of other volatile registers are not preserved. PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA // Allocate space and save Fp, Pc. - SAVE_ARGUMENT_REGISTERS sp, 16 // Save x8 and argument registers (x0-x7). - str xzr, [sp, 88] // Clear functionId. - SAVE_FLOAT_ARGUMENT_REGISTERS sp, 96 // Save floating-point/SIMD registers (q0-q7). - add x12, fp, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA // Compute probeSp - initial value of Sp on entry to the helper. - stp x12, x11, [sp, 224] // Save probeSp, profiledSp. - str xzr, [sp, 240] // Clear hiddenArg. + SAVE_ARGUMENT_REGISTERS sp, PROFILE_PLATFORM_SPECIFIC_DATA__x8 // Save x8 and argument registers (x0-x7). + str xzr, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__functionId] // Clear functionId. + SAVE_FLOAT_ARGUMENT_REGISTERS sp, PROFILE_PLATFORM_SPECIFIC_DATA__floatArgumentRegisters + add x12, fp, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA // Compute probeSp - initial value of Sp on entry to the helper. + stp x12, x11, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__probeSp] // Save probeSp, profiledSp. + str xzr, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg] // Clear hiddenArg. mov w12, \flags - stp w12, wzr, [sp, 248] // Save flags and clear unused field. + stp w12, wzr, [sp, PROFILE_PLATFORM_SPECIFIC_DATA__flags] // Save flags and clear unused field. mov x0, x10 mov x1, sp bl C_FUNC(\helper) - RESTORE_ARGUMENT_REGISTERS sp, 16 // Restore x8 and argument registers. - RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 96 // Restore floating-point/SIMD registers. + RESTORE_ARGUMENT_REGISTERS sp, PROFILE_PLATFORM_SPECIFIC_DATA__x8 // Restore x8 and argument registers. + RESTORE_FLOAT_ARGUMENT_REGISTERS sp, PROFILE_PLATFORM_SPECIFIC_DATA__floatArgumentRegisters // Restore floating-point/SIMD registers. EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA EPILOG_RETURN diff --git a/src/coreclr/vm/arm64/cgencpu.h b/src/coreclr/vm/arm64/cgencpu.h index 4350390843e57..3ec3d6ea3b1a1 100644 --- a/src/coreclr/vm/arm64/cgencpu.h +++ b/src/coreclr/vm/arm64/cgencpu.h @@ -165,6 +165,33 @@ struct FloatArgumentRegisters { #define NUM_FLOAT_ARGUMENT_REGISTERS 8 +//********************************************************************** +// Profiling +//********************************************************************** + +#ifdef PROFILING_SUPPORTED + +#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE (NUM_FLOAT_ARGUMENT_REGISTERS * sizeof(double)) + +typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA +{ + void* Fp; + void* Pc; + void* x8; + ArgumentRegisters argumentRegisters; + FunctionID functionId; + FloatArgumentRegisters floatArgumentRegisters; + void* probeSp; + void* profiledSp; + void* hiddenArg; + UINT32 flags; + UINT32 unused; + BYTE buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE]; +} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; + +#endif // PROFILING_SUPPORTED + + //********************************************************************** // Exception handling //********************************************************************** diff --git a/src/coreclr/vm/arm64/profiler.cpp b/src/coreclr/vm/arm64/profiler.cpp index f46f9e6a7f562..471677347ea57 100644 --- a/src/coreclr/vm/arm64/profiler.cpp +++ b/src/coreclr/vm/arm64/profiler.cpp @@ -4,30 +4,9 @@ #include "common.h" #ifdef PROFILING_SUPPORTED +#include "asmconstants.h" #include "proftoeeinterfaceimpl.h" -#define PROFILE_ENTER 1 -#define PROFILE_LEAVE 2 -#define PROFILE_TAILCALL 4 - -#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE (NUM_FLOAT_ARGUMENT_REGISTERS * sizeof(double)) - -typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA -{ - void* Fp; - void* Pc; - void* x8; - ArgumentRegisters argumentRegisters; - FunctionID functionId; - FloatArgumentRegisters floatArgumentRegisters; - void* probeSp; - void* profiledSp; - void* hiddenArg; - UINT32 flags; - UINT32 unused; - BYTE buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE]; -} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; - UINT_PTR ProfileGetIPFromPlatformSpecificHandle(void* pPlatformSpecificHandle) { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/loongarch64/asmconstants.h b/src/coreclr/vm/loongarch64/asmconstants.h index 38c383543bcb1..929eb732451dd 100644 --- a/src/coreclr/vm/loongarch64/asmconstants.h +++ b/src/coreclr/vm/loongarch64/asmconstants.h @@ -254,5 +254,44 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun #define CallCountingStubData__TargetForThresholdReached 0x10 ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached)) +#ifdef PROFILING_SUPPORTED +#define PROFILE_ENTER 1 +#define PROFILE_LEAVE 2 +#define PROFILE_TAILCALL 4 + +#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 272 +ASMCONSTANTS_C_ASSERT(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA == sizeof(PROFILE_PLATFORM_SPECIFIC_DATA)) + +#define ASMCONSTANTS_C_ASSERT_OFFSET(type, field) \ + ASMCONSTANTS_C_ASSERT(type##__##field == offsetof(type, field)) + +#define PROFILE_PLATFORM_SPECIFIC_DATA__Fp 0 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, Fp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__Pc 8 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, Pc) +#define PROFILE_PLATFORM_SPECIFIC_DATA__x8 16 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, x8) +#define PROFILE_PLATFORM_SPECIFIC_DATA__argumentRegisters 24 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, argumentRegisters) +#define PROFILE_PLATFORM_SPECIFIC_DATA__functionId 88 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, functionId) +#define PROFILE_PLATFORM_SPECIFIC_DATA__floatArgumentRegisters 96 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, floatArgumentRegisters) +#define PROFILE_PLATFORM_SPECIFIC_DATA__probeSp 224 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, probeSp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp 232 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, profiledSp) +#define PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg 240 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, hiddenArg) +#define PROFILE_PLATFORM_SPECIFIC_DATA__flags 248 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, flags) +#define PROFILE_PLATFORM_SPECIFIC_DATA__unused 252 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, unused) +#define PROFILE_PLATFORM_SPECIFIC_DATA__buffer 256 +ASMCONSTANTS_C_ASSERT_OFFSET(PROFILE_PLATFORM_SPECIFIC_DATA, buffer) + +#undef ASMCONSTANTS_C_ASSERT_OFFSET +#endif + #undef ASMCONSTANTS_RUNTIME_ASSERT #undef ASMCONSTANTS_C_ASSERT diff --git a/src/coreclr/vm/loongarch64/asmhelpers.S b/src/coreclr/vm/loongarch64/asmhelpers.S index bd7edee56e2fe..dbf1452c9574d 100644 --- a/src/coreclr/vm/loongarch64/asmhelpers.S +++ b/src/coreclr/vm/loongarch64/asmhelpers.S @@ -1026,12 +1026,6 @@ LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub, _TEXT jirl $r0, $ra, 0 LEAF_END JIT_ProfilerEnterLeaveTailcallStub, _TEXT -// ------------------------------------------------------------------ -#define PROFILE_ENTER 1 -#define PROFILE_LEAVE 2 -#define PROFILE_TAILCALL 4 -#define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 272 - // ------------------------------------------------------------------ .macro GenerateProfileHelper helper, flags NESTED_ENTRY \helper\()Naked, _TEXT, NoHandler @@ -1046,24 +1040,26 @@ NESTED_ENTRY \helper\()Naked, _TEXT, NoHandler // $fp,$ra PROLOG_SAVE_REG_PAIR_INDEXED 22, 1, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA // Allocate space and save Fp, Pc. - SAVE_ARGUMENT_REGISTERS $sp, 16 // Save $t0 and argument registers ($a0-$a7). - st.d $zero, $sp, 88 // Clear functionId. - SAVE_FLOAT_ARGUMENT_REGISTERS $sp, 96 // Save floating-point/SIMD registers ($fa0-$fa7). + // Please validate, SAVE_ARGUMENT_REGISTERS doesn't save $t0 + SAVE_ARGUMENT_REGISTERS $sp, PROFILE_PLATFORM_SPECIFIC_DATA__argumentRegisters // Save $t0 and argument registers ($a0-$a7). + st.d $zero, $sp, PROFILE_PLATFORM_SPECIFIC_DATA__functionId // Clear functionId. + SAVE_FLOAT_ARGUMENT_REGISTERS $sp, PROFILE_PLATFORM_SPECIFIC_DATA__floatArgumentRegisters addi.d $t3, $fp, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA // Compute probeSp - initial value of Sp on entry to the helper. - st.d $t3, $sp, 224 // Save probeSp. - st.d $t2, $sp, 232 // Save profiledSp. + st.d $t3, $sp, PROFILE_PLATFORM_SPECIFIC_DATA__probeSp + st.d $t2, $sp, PROFILE_PLATFORM_SPECIFIC_DATA__profiledSp - st.d $zero, $sp, 240 // Clear hiddenArg. + st.d $zero, $sp, PROFILE_PLATFORM_SPECIFIC_DATA__hiddenArg // Clear hiddenArg. addi.d $t3, $zero, \flags - st.w $t3, $sp, 248 // Save flags. - st.d $zero, $sp, 256 // clear unused field. + st.w $t3, $sp, PROFILE_PLATFORM_SPECIFIC_DATA__flags + st.d $zero, $sp, PROFILE_PLATFORM_SPECIFIC_DATA__unused ori $a1, $t1, 0 ori $a2, $sp, 0 bl C_FUNC(\helper) - RESTORE_ARGUMENT_REGISTERS $sp, 16 // Restore $t0 and argument registers. - RESTORE_FLOAT_ARGUMENT_REGISTERS $sp, 96 // Restore floating-point/SIMD registers. + // Please validate, RESTORE_ARGUMENT_REGISTERS doesn't restore $t0 + RESTORE_ARGUMENT_REGISTERS $sp, PROFILE_PLATFORM_SPECIFIC_DATA__argumentRegisters // Restore $t0 and argument registers. + RESTORE_FLOAT_ARGUMENT_REGISTERS $sp, PROFILE_PLATFORM_SPECIFIC_DATA__floatArgumentRegisters // $fp, $ra EPILOG_RESTORE_REG_PAIR_INDEXED 22, 1, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA EPILOG_RETURN diff --git a/src/coreclr/vm/loongarch64/cgencpu.h b/src/coreclr/vm/loongarch64/cgencpu.h index 6a11a3a57b756..a9275fda8f24a 100644 --- a/src/coreclr/vm/loongarch64/cgencpu.h +++ b/src/coreclr/vm/loongarch64/cgencpu.h @@ -138,6 +138,34 @@ struct FloatArgumentRegisters { #define NUM_FLOAT_ARGUMENT_REGISTERS 8 +//********************************************************************** +// Profiling +//********************************************************************** + +#ifdef PROFILING_SUPPORTED + +// Scratch space to store HFA return values (max 16 bytes) +#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE 16 + +typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA +{ + void* Fp; + void* Pc; + void* x8; + ArgumentRegisters argumentRegisters; + FunctionID functionId; + FloatArgumentRegisters floatArgumentRegisters; + void* probeSp; + void* profiledSp; + void* hiddenArg; + UINT32 flags; + UINT32 unused; + BYTE buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE]; +} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; + +#endif // PROFILING_SUPPORTED + + //********************************************************************** // Exception handling //********************************************************************** diff --git a/src/coreclr/vm/loongarch64/profiler.cpp b/src/coreclr/vm/loongarch64/profiler.cpp index 4668e7b9d9d73..4e9075e50f15d 100644 --- a/src/coreclr/vm/loongarch64/profiler.cpp +++ b/src/coreclr/vm/loongarch64/profiler.cpp @@ -5,29 +5,7 @@ #ifdef PROFILING_SUPPORTED #include "proftoeeinterfaceimpl.h" - -#define PROFILE_ENTER 1 -#define PROFILE_LEAVE 2 -#define PROFILE_TAILCALL 4 - -// Scratch space to store HFA return values (max 16 bytes) -#define PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE 16 - -typedef struct _PROFILE_PLATFORM_SPECIFIC_DATA -{ - void* Fp; - void* Pc; - void* x8; - ArgumentRegisters argumentRegisters; - FunctionID functionId; - FloatArgumentRegisters floatArgumentRegisters; - void* probeSp; - void* profiledSp; - void* hiddenArg; - UINT32 flags; - UINT32 unused; - BYTE buffer[PROFILE_PLATFORM_SPECIFIC_DATA_BUFFER_SIZE]; -} PROFILE_PLATFORM_SPECIFIC_DATA, *PPROFILE_PLATFORM_SPECIFIC_DATA; +#include "asmconstants.h" UINT_PTR ProfileGetIPFromPlatformSpecificHandle(void* pPlatformSpecificHandle) {