This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
unixasmmacrosarm64.inc
344 lines (272 loc) · 10 KB
/
unixasmmacrosarm64.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
.macro NESTED_ENTRY Name, Section, Handler
LEAF_ENTRY \Name, \Section
.ifnc \Handler, NoHandler
.cfi_personality 0x1b, C_FUNC(\Handler) // 0x1b == DW_EH_PE_pcrel | DW_EH_PE_sdata4
.endif
.endm
.macro NESTED_END Name, Section
LEAF_END \Name, \Section
.endm
.macro PATCH_LABEL Name
.global C_FUNC(\Name)
C_FUNC(\Name):
.endm
.macro LEAF_ENTRY Name, Section
.global C_FUNC(\Name)
.type \Name, %function
C_FUNC(\Name):
.cfi_startproc
.endm
.macro LEAF_END Name, Section
.size \Name, .-\Name
.cfi_endproc
.endm
.macro LEAF_END_MARKED Name, Section
C_FUNC(\Name\()_End):
.global C_FUNC(\Name\()_End)
LEAF_END \Name, \Section
.endm
.macro PREPARE_EXTERNAL_VAR Name, HelperReg
adrp \HelperReg, \Name
add \HelperReg, \HelperReg, :lo12:\Name
.endm
.macro PROLOG_STACK_ALLOC Size
sub sp, sp, \Size
.endm
.macro EPILOG_STACK_FREE Size
add sp, sp, \Size
.cfi_adjust_cfa_offset -\Size
.endm
.macro EPILOG_STACK_RESTORE
mov sp, fp
.cfi_restore sp
.endm
.macro PROLOG_SAVE_REG reg, ofs
str \reg, [sp, \ofs]
.cfi_rel_offset \reg, \ofs
.endm
.macro PROLOG_SAVE_REG_PAIR reg1, reg2, ofs
stp \reg1, \reg2, [sp, \ofs]
.cfi_rel_offset \reg1, \ofs
.cfi_rel_offset \reg2, \ofs + 8
.ifc \reg1, fp
mov fp, sp
.cfi_def_cfa_register fp
.endif
.endm
.macro PROLOG_SAVE_REG_PAIR_INDEXED reg1, reg2, ofs
stp \reg1, \reg2, [sp, \ofs]!
.cfi_adjust_cfa_offset -\ofs
.cfi_rel_offset \reg1, 0
.cfi_rel_offset \reg2, 8
.ifc \reg1, fp
mov fp, sp
.cfi_def_cfa_register fp
.endif
.endm
.macro EPILOG_RESTORE_REG reg, ofs
ldr \reg, [sp, \ofs]
.cfi_restore \reg1
.endm
.macro EPILOG_RESTORE_REG_PAIR reg1, reg2, ofs
ldp \reg1, \reg2, [sp, \ofs]
.cfi_restore \reg1
.cfi_restore \reg2
.endm
.macro EPILOG_RESTORE_REG_PAIR_INDEXED reg1, reg2, ofs
ldp \reg1, \reg2, [sp], \ofs
.cfi_restore \reg1
.cfi_restore \reg2
.cfi_adjust_cfa_offset -\ofs
.endm
.macro EPILOG_RETURN
ret
.endm
.macro EMIT_BREAKPOINT
brk #0
.endm
//-----------------------------------------------------------------------------
// 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
// FloatRegisters::q7
// FloatRegisters::q6
// FloatRegisters::q5
// FloatRegisters::q4
// FloatRegisters::q3
// FloatRegisters::q2
// FloatRegisters::q1
// FloatRegisters::q0
.macro PROLOG_WITH_TRANSITION_BLOCK extraLocals = 0, SaveFPArgs = 1
__PWTB_FloatArgumentRegisters = \extraLocals
__PWTB_SaveFPArgs = \SaveFPArgs
.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_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
// Spill argument registers.
SAVE_ARGUMENT_REGISTERS sp, __PWTB_ArgumentRegisters
.if (__PWTB_SaveFPArgs == 1)
SAVE_FLOAT_ARGUMENT_REGISTERS sp, \extraLocals
.endif
.endm
//-----------------------------------------------------------------------------
// The Following sets of SAVE_*_REGISTERS expect the memory to be reserved and
// base address to be passed in $reg
//
// Reserve 64 bytes of memory before calling SAVE_ARGUMENT_REGISTERS
.macro SAVE_ARGUMENT_REGISTERS reg, ofs
str x8, [\reg, #(\ofs)]
stp x0, x1, [\reg, #(\ofs + 8)]
stp x2, x3, [\reg, #(\ofs + 24)]
stp x4, x5, [\reg, #(\ofs + 40)]
stp x6, x7, [\reg, #(\ofs + 56)]
.endm
// Reserve 128 bytes of memory before calling SAVE_FLOAT_ARGUMENT_REGISTERS
.macro SAVE_FLOAT_ARGUMENT_REGISTERS reg, ofs
stp q0, q1, [\reg, #(\ofs)]
stp q2, q3, [\reg, #(\ofs + 32)]
stp q4, q5, [\reg, #(\ofs + 64)]
stp q6, q7, [\reg, #(\ofs + 96)]
.endm
.macro RESTORE_ARGUMENT_REGISTERS reg, ofs
ldr x8, [\reg, #(\ofs)]
ldp x0, x1, [\reg, #(\ofs + 8)]
ldp x2, x3, [\reg, #(\ofs + 24)]
ldp x4, x5, [\reg, #(\ofs + 40)]
ldp x6, x7, [\reg, #(\ofs + 56)]
.endm
.macro RESTORE_FLOAT_ARGUMENT_REGISTERS reg, ofs
ldp q0, q1, [\reg, #(\ofs)]
ldp q2, q3, [\reg, #(\ofs + 32)]
ldp q4, q5, [\reg, #(\ofs + 64)]
ldp q6, q7, [\reg, #(\ofs + 96)]
.endm
.macro EPILOG_BRANCH Target
b \Target
.endm
.macro EPILOG_BRANCH_REG reg
br \reg
.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
//-----------------------------------------------------------------------------
// 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
// ------------------------------------------------------------------
// Macro to generate Redirection Stubs
//
// $reason : reason for redirection
// Eg. GCThreadControl
// NOTE: If you edit this macro, make sure you update GetCONTEXTFromRedirectedStubStackFrame.
// This function is used by both the personality routine and the debugger to retrieve the original CONTEXT.
.macro GenerateRedirectedHandledJITCaseStub reason
#if NOTYET
GBLS __RedirectionStubFuncName
GBLS __RedirectionStubEndFuncName
GBLS __RedirectionFuncName
__RedirectionStubFuncName SETS "RedirectedHandledJITCaseFor":CC:"$reason":CC:"_Stub"
__RedirectionStubEndFuncName SETS "RedirectedHandledJITCaseFor":CC:"$reason":CC:"_StubEnd"
__RedirectionFuncName SETS "|?RedirectedHandledJITCaseFor":CC:"$reason":CC:"@Thread@@CAXXZ|"
IMPORT $__RedirectionFuncName
NESTED_ENTRY $__RedirectionStubFuncName
PROLOG_SAVE_REG_PAIR fp, lr, -16
sub sp, sp, #16 // stack slot for CONTEXT * and padding
//REDIRECTSTUB_SP_OFFSET_CONTEXT is defined in asmconstants.h and is used in GetCONTEXTFromRedirectedStubStackFrame
//If CONTEXT is not saved at 0 offset from SP it must be changed as well.
ASSERT REDIRECTSTUB_SP_OFFSET_CONTEXT == 0
// Stack alignment. This check is necessary as this function can be
// entered before complete execution of the prolog of another function.
and x8, fp, #15
sub sp, sp, x8
//
// Save a copy of the redirect CONTEXT*.
// This is needed for the debugger to unwind the stack.
//
bl GetCurrentSavedRedirectContext
str x0, [sp]
//
// Fetch the interrupted pc and save it as our return address.
//
ldr x1, [x0, #CONTEXT_Pc]
str x1, [fp, #8]
//
// Call target, which will do whatever we needed to do in the context
// of the target thread, and will RtlRestoreContext when it is done.
//
bl $__RedirectionFuncName
EMIT_BREAKPOINT // Unreachable
// Put a label here to tell the debugger where the end of this function is.
$__RedirectionStubEndFuncName
EXPORT $__RedirectionStubEndFuncName
NESTED_END
#else
EMIT_BREAKPOINT
#endif
.endm