Skip to content

Commit 1662aae

Browse files
sdmacleajanvorli
authored andcommitted
[ARM64/Unix] (dotnet/coreclr#9500)
* [Arm64/Unix] Update arm64 *.S files to match *.asm * [Arm64/Unix] Fix CONTEXTToNativeContext() * [Arm64/Unix] ThrowExceptionFromContextInternal * [Arm64/Unix] Preserve x8 argument register * [ARM64/Unix] Add CFI directives Add native unwind info * [Arm64/Unix] Fix RtlRestoreContext * [Arm64/Unix] Restore FP from CurrentContextPointers * [Arm64/Unix] fix pointer math * [Arm64/Unix] Fix CallDescrWorkerInternal personality * [Arm64/Unix] More Fp fixups * [Arm64/Unix] CallEHFunclet machine state Restore non-volatile machine state in CallEHFunclet * [Arm64/Unix] CallDescrWorkerInternal Use empty stack slot to save argument * [Arm64/Unix] RtlVirtualUnwind update pointers * [Arm64] LazyMachState fixes * [Arm64/Unix] disable USE_REDIRECT_FOR_GCSTRESS When FEATURE_PAL is enableds USE_REDIRECT_FOR_GCSTRESS is not supported * [Arm64] ClearRegDisplayArgumentAndScratchRegisters() * [Arm64] Remove unnecesary copy in TransitionFrame * [Arm64/Unix] Fix comment per review * [Arm64/Unix] move constants per review * [Arm64/Unix] Use ldp per review Also fix indentation * [Arm64/Unix] Fix indentation per review * [Arm64/Unix] Remove m_Unwound per review comments * [Arm64/Unix] Use PREPARE_EXTERNAL_VAR to access globals * [Arm64/Unix] Fix more whitespace per earlier review comments Commit migrated from dotnet/coreclr@9baa44a
1 parent f34d2e0 commit 1662aae

File tree

18 files changed

+869
-367
lines changed

18 files changed

+869
-367
lines changed

src/coreclr/src/debug/ee/arm64/dbghelpers.S

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
1-
//Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#include "asmconstants.h"
56
#include "unixasmmacros.inc"
67

7-
NESTED_ENTRY FuncEvalHijack, _TEXT, FuncEvalHijackPersonalityRoutine
8+
//
9+
// hijacking stub used to perform a func-eval, see Debugger::FuncEvalSetup() for use.
10+
//
11+
// on entry:
12+
// x0 : pointer to DebuggerEval object
13+
//
814

9-
// NOTE: FuncEvalHijackPersonalityRoutine is dependent on the stack layout so if
10-
// you change the prolog you will also need to update the personality routine.
15+
// @dbgtodo- once we port Funceval, use the ExceptionHijack stub instead of this func-eval stub.
16+
NESTED_ENTRY FuncEvalHijack, _TEXT, UnhandledExceptionHandlerUnix
1117

12-
// push arg to the stack so our personality routine can find it
13-
// push lr to get good stacktrace in debugger
18+
// NOTE: FuncEvalHijackPersonalityRoutine is dependent on the stack layout so if
19+
// you change the prolog you will also need to update the personality routine.
1420

15-
PROLOG_SAVE_REG_PAIR fp, lr, #-32
21+
// push arg to the stack so our personality routine can find it
22+
// push lr to get good stacktrace in debugger
23+
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -32
24+
str x0, [sp, #16]
25+
// FuncEvalHijackWorker returns the address we should jump to.
26+
bl FuncEvalHijackWorker
27+
28+
EPILOG_STACK_FREE 32
29+
EPILOG_BRANCH_REG x0
30+
NESTED_END FuncEvalHijack
31+
32+
// This is the general purpose hijacking stub. The DacDbi Hijack primitive will
33+
// set up the stack and then set the IP here, and so this just makes the call.
34+
NESTED_ENTRY ExceptionHijack, _TEXT, UnhandledExceptionHandlerUnix
35+
36+
// make the call
37+
bl ExceptionHijackWorker
38+
39+
// effective NOP to terminate unwind
40+
mov x3, x3
41+
42+
// *** should never get here ***
43+
EMIT_BREAKPOINT
44+
45+
// exported label so the debugger knows where the end of this function is
46+
PATCH_LABEL ExceptionHijackEnd
47+
48+
NESTED_END ExceptionHijack, _TEXT
1649

17-
str x0, [sp, #16]
18-
// FuncEvalHijackWorker returns the address we should jump to.
19-
bl FuncEvalHijackWorker
20-
21-
EPILOG_STACK_FREE 32
22-
EPILOG_BRANCH_REG x0
23-
NESTED_END FuncEvalHijack, _TEXT
2450

25-
//NESTED_ENTRY ExceptionHijack,,ExceptionHijackPersonalityRoutine

src/coreclr/src/debug/ee/wks/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ add_compile_options(-fPIC)
5858
if(CLR_CMAKE_PLATFORM_ARCH_AMD64 OR CLR_CMAKE_PLATFORM_ARCH_ARM OR CLR_CMAKE_PLATFORM_ARCH_ARM64 OR CLR_CMAKE_PLATFORM_ARCH_I386)
5959
add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ../${ARCH_SOURCES_DIR}/dbghelpers.S)
6060
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
61-
add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS})
61+
add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ../${ARCH_SOURCES_DIR}/dbghelpers.S)
6262
else()
6363
message(FATAL_ERROR "Only ARM and AMD64 is supported")
6464
endif()

src/coreclr/src/pal/inc/unixasmmacrosarm64.inc

Lines changed: 104 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ C_FUNC(\Name):
3131
.endm
3232

3333
.macro LEAF_END_MARKED Name, Section
34-
.global C_FUNC(\Name\()_End)
3534
C_FUNC(\Name\()_End):
35+
.global C_FUNC(\Name\()_End)
3636
LEAF_END \Name, \Section
3737
.endm
3838

@@ -48,40 +48,54 @@ C_FUNC(\Name\()_End):
4848

4949
.macro EPILOG_STACK_FREE Size
5050
add sp, sp, \Size
51+
.cfi_adjust_cfa_offset -\Size
5152
.endm
5253

5354
.macro EPILOG_STACK_RESTORE
5455
mov sp, fp
56+
.cfi_restore sp
5557
.endm
5658

5759
.macro PROLOG_SAVE_REG reg, ofs
5860
str \reg, [sp, \ofs]
61+
.cfi_rel_offset \reg, \ofs
5962
.endm
6063

6164
.macro PROLOG_SAVE_REG_PAIR reg1, reg2, ofs
6265
stp \reg1, \reg2, [sp, \ofs]
66+
.cfi_rel_offset \reg1, \ofs
67+
.cfi_rel_offset \reg2, \ofs + 8
6368
.ifc \reg1, fp
6469
mov fp, sp
6570
.endif
6671
.endm
6772

6873
.macro PROLOG_SAVE_REG_PAIR_INDEXED reg1, reg2, ofs
6974
stp \reg1, \reg2, [sp, \ofs]!
75+
.cfi_adjust_cfa_offset -\ofs
76+
.cfi_rel_offset \reg1, 0
77+
.cfi_rel_offset \reg2, 8
7078
.ifc \reg1, fp
7179
mov fp, sp
7280
.endif
7381
.endm
7482

7583
.macro EPILOG_RESTORE_REG reg, ofs
7684
ldr \reg, [sp, \ofs]
85+
.cfi_restore \reg1
7786
.endm
7887

7988
.macro EPILOG_RESTORE_REG_PAIR reg1, reg2, ofs
8089
ldp \reg1, \reg2, [sp, \ofs]
90+
.cfi_restore \reg1
91+
.cfi_restore \reg2
8192
.endm
8293

8394
.macro EPILOG_RESTORE_REG_PAIR_INDEXED reg1, reg2, ofs
8495
ldp \reg1, \reg2, [sp], \ofs
96+
.cfi_restore \reg1
97+
.cfi_restore \reg2
98+
.cfi_adjust_cfa_offset -\ofs
8599
.endm
86100

87101
.macro EPILOG_RETURN
@@ -94,14 +108,14 @@ C_FUNC(\Name\()_End):
94108

95109
//-----------------------------------------------------------------------------
96110
// Define the prolog for a TransitionFrame-based method. This macro should be called first in the method and
97-
// comprises the entire prolog (i.e. don't modify SP after calling this).The locals must be 8 byte aligned
111+
// comprises the entire prolog (i.e. don't modify SP after calling this).The locals must be 8 byte aligned
98112
//
99113
// Stack layout:
100114
//
101115
// (stack parameters)
102116
// ...
103117
// fp
104-
// lr
118+
// lr
105119
// CalleeSavedRegisters::x28
106120
// CalleeSavedRegisters::x27
107121
// CalleeSavedRegisters::x26
@@ -133,81 +147,122 @@ C_FUNC(\Name\()_End):
133147
.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, SaveFPArgs = 1
134148

135149
__PWTB_FloatArgumentRegisters = \extraLocals
150+
__PWTB_SaveFPArgs = \SaveFPArgs
136151

137152
.if ((__PWTB_FloatArgumentRegisters % 16) != 0)
138153
__PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8
139154
.endif
140155

141156
__PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters
142157

143-
.if \SaveFPArgs > 0
158+
.if (__PWTB_SaveFPArgs == 1)
144159
__PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters
145160
.endif
146161

147162
__PWTB_StackAlloc = __PWTB_TransitionBlock
148-
__PWTB_ArgumentRegisters = __PWTB_StackAlloc + 96
149-
150-
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-160
151-
// Spill callee saved registers
152-
PROLOG_SAVE_REG_PAIR x19, x20, #16
153-
PROLOG_SAVE_REG_PAIR x21, x22, #32
154-
PROLOG_SAVE_REG_PAIR x23, x24, #48
155-
PROLOG_SAVE_REG_PAIR x25, x26, #64
156-
PROLOG_SAVE_REG_PAIR x27, x28, #80
157-
163+
__PWTB_ArgumentRegisters = __PWTB_StackAlloc + 96
164+
165+
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -176
166+
// Spill callee saved registers
167+
PROLOG_SAVE_REG_PAIR x19, x20, 16
168+
PROLOG_SAVE_REG_PAIR x21, x22, 32
169+
PROLOG_SAVE_REG_PAIR x23, x24, 48
170+
PROLOG_SAVE_REG_PAIR x25, x26, 64
171+
PROLOG_SAVE_REG_PAIR x27, x28, 80
172+
158173
// Allocate space for the rest of the frame
159174
PROLOG_STACK_ALLOC __PWTB_StackAlloc
160-
175+
161176
// Spill argument registers.
162177
SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters
163178

164-
.if \SaveFPArgs > 0
179+
.if (__PWTB_SaveFPArgs == 1)
165180
SAVE_FLOAT_ARGUMENT_REGISTERS sp, \extraLocals
166181
.endif
167182

168183
.endm
169184

170185
//-----------------------------------------------------------------------------
171-
// The Following sets of SAVE_*_REGISTERS expect the memory to be reserved and
186+
// The Following sets of SAVE_*_REGISTERS expect the memory to be reserved and
172187
// base address to be passed in $reg
173188
//
174189

175190
// Reserve 64 bytes of memory before calling SAVE_ARGUMENT_REGISTERS
176-
.macro SAVE_ARGUMENT_REGISTERS reg, ofs
191+
.macro SAVE_ARGUMENT_REGISTERS reg, ofs
177192

178193
stp x0, x1, [\reg, #(\ofs)]
194+
.cfi_rel_offset x0, \ofs
195+
.cfi_rel_offset x1, \ofs + 8
179196
stp x2, x3, [\reg, #(\ofs + 16)]
197+
.cfi_rel_offset x2, \ofs + 16
198+
.cfi_rel_offset x3, \ofs + 24
180199
stp x4, x5, [\reg, #(\ofs + 32)]
200+
.cfi_rel_offset x4, \ofs + 32
201+
.cfi_rel_offset x5, \ofs + 40
181202
stp x6, x7, [\reg, #(\ofs + 48)]
203+
.cfi_rel_offset x6, \ofs + 48
204+
.cfi_rel_offset x7, \ofs + 56
205+
str x8, [\reg, #(\ofs + 64)]
206+
.cfi_rel_offset x8, \ofs + 64
182207

183208
.endm
184209

185210
// Reserve 64 bytes of memory before calling SAVE_FLOAT_ARGUMENT_REGISTERS
186-
.macro SAVE_FLOAT_ARGUMENT_REGISTERS reg, ofs
211+
.macro SAVE_FLOAT_ARGUMENT_REGISTERS reg, ofs
187212

188213
stp d0, d1, [\reg, #(\ofs)]
214+
.cfi_rel_offset d0, \ofs + 0
215+
.cfi_rel_offset d1, \ofs + 8
189216
stp d2, d3, [\reg, #(\ofs + 16)]
217+
.cfi_rel_offset d2, \ofs + 16
218+
.cfi_rel_offset d3, \ofs + 24
190219
stp d4, d5, [\reg, #(\ofs + 32)]
220+
.cfi_rel_offset d4, \ofs + 32
221+
.cfi_rel_offset d5, \ofs + 40
191222
stp d6, d7, [\reg, #(\ofs + 48)]
223+
.cfi_rel_offset d6, \ofs + 48
224+
.cfi_rel_offset d7, \ofs + 56
192225

193226
.endm
194227

195-
.macro RESTORE_ARGUMENT_REGISTERS reg, ofs
228+
.macro RESTORE_ARGUMENT_REGISTERS reg, ofs
196229

197230
ldp x0, x1, [\reg, #(\ofs)]
231+
.cfi_restore x0
232+
.cfi_restore x1
198233
ldp x2, x3, [\reg, #(\ofs + 16)]
234+
.cfi_restore x2
235+
.cfi_restore x3
199236
ldp x4, x5, [\reg, #(\ofs + 32)]
237+
.cfi_restore x4
238+
.cfi_restore x5
200239
ldp x6, x7, [\reg, #(\ofs + 48)]
240+
.cfi_restore x6
241+
.cfi_restore x7
242+
ldr x8, [\reg, #(\ofs + 64)]
243+
.cfi_restore x8
201244

202245
.endm
203246

204-
.macro RESTORE_FLOAT_ARGUMENT_REGISTERS reg, ofs
247+
.macro RESTORE_FLOAT_ARGUMENT_REGISTERS reg, ofs
205248

206249
ldp d0, d1, [\reg, #(\ofs)]
250+
.cfi_restore d0
251+
.cfi_restore d1
207252
ldp d2, d3, [\reg, #(\ofs + 16)]
253+
.cfi_restore d2
254+
.cfi_restore d3
208255
ldp d4, d5, [\reg, #(\ofs + 32)]
256+
.cfi_restore d4
257+
.cfi_restore d5
209258
ldp d6, d7, [\reg, #(\ofs + 48)]
259+
.cfi_restore d6
260+
.cfi_restore d7
261+
262+
.endm
210263

264+
.macro EPILOG_BRANCH Target
265+
b \Target
211266
.endm
212267

213268
.macro EPILOG_BRANCH_REG reg
@@ -216,40 +271,42 @@ C_FUNC(\Name\()_End):
216271

217272
.endm
218273

219-
//-----------------------------------------------------------------------------
220-
// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling.
221-
// Since this is a tail call argument registers are restored.
222-
//
223-
.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL extraLocals = 0, SaveFPArgs =1
224274

225-
__PWTB_FloatArgumentRegisters = \extraLocals
275+
.macro EPILOG_WITH_TRANSITION_BLOCK_RETURN
226276

227-
.if ((__PWTB_FloatArgumentRegisters % 16) != 0)
228-
__PWTB_FloatArgumentRegisters = __PWTB_FloatArgumentRegisters + 8
229-
.endif
277+
EPILOG_STACK_FREE __PWTB_StackAlloc
230278

231-
__PWTB_TransitionBlock = __PWTB_FloatArgumentRegisters
279+
EPILOG_RESTORE_REG_PAIR x19, x20, 16
280+
EPILOG_RESTORE_REG_PAIR x21, x22, 32
281+
EPILOG_RESTORE_REG_PAIR x23, x24, 48
282+
EPILOG_RESTORE_REG_PAIR x25, x26, 64
283+
EPILOG_RESTORE_REG_PAIR x27, x28, 80
284+
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 176
285+
ret
232286

233-
.if \SaveFPArgs > 0
234-
__PWTB_TransitionBlock = __PWTB_TransitionBlock + SIZEOF__FloatArgumentRegisters
235-
.endif
287+
.endm
236288

237-
__PWTB_StackAlloc = __PWTB_TransitionBlock
238-
__PWTB_ArgumentRegisters = __PWTB_StackAlloc + 96
239289

240-
.if \SaveFPArgs > 0
241-
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters
290+
//-----------------------------------------------------------------------------
291+
// Provides a matching epilog to PROLOG_WITH_TRANSITION_BLOCK and ends by preparing for tail-calling.
292+
// Since this is a tail call argument registers are restored.
293+
//
294+
.macro EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
295+
296+
.if (__PWTB_SaveFPArgs == 1)
297+
RESTORE_FLOAT_ARGUMENT_REGISTERS sp, __PWTB_FloatArgumentRegisters
242298
.endif
243299

244300
RESTORE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters
301+
245302
EPILOG_STACK_FREE __PWTB_StackAlloc
246-
247-
EPILOG_RESTORE_REG_PAIR x19, x20, #16
248-
EPILOG_RESTORE_REG_PAIR x21, x22, #32
249-
EPILOG_RESTORE_REG_PAIR x23, x24, #48
250-
EPILOG_RESTORE_REG_PAIR x25, x26, #64
251-
EPILOG_RESTORE_REG_PAIR x27, x28, #80
252-
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #160
303+
304+
EPILOG_RESTORE_REG_PAIR x19, x20, 16
305+
EPILOG_RESTORE_REG_PAIR x21, x22, 32
306+
EPILOG_RESTORE_REG_PAIR x23, x24, 48
307+
EPILOG_RESTORE_REG_PAIR x25, x26, 64
308+
EPILOG_RESTORE_REG_PAIR x27, x28, 80
309+
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 176
253310

254311
.endm
255312

@@ -273,8 +330,8 @@ __RedirectionFuncName SETS "|?RedirectedHandledJITCaseFor":CC:"$reason":CC:"@Thr
273330
IMPORT $__RedirectionFuncName
274331

275332
NESTED_ENTRY $__RedirectionStubFuncName
276-
PROLOG_SAVE_REG_PAIR fp, lr, #-16
277-
sub sp, sp, #16 // stack slot for CONTEXT * and padding
333+
PROLOG_SAVE_REG_PAIR fp, lr, -16
334+
sub sp, sp, #16 // stack slot for CONTEXT * and padding
278335

279336
//REDIRECTSTUB_SP_OFFSET_CONTEXT is defined in asmconstants.h and is used in GetCONTEXTFromRedirectedStubStackFrame
280337
//If CONTEXT is not saved at 0 offset from SP it must be changed as well.

0 commit comments

Comments
 (0)