Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unixasmmacrosarm.inc « unix « Runtime « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7a78f3e23fb03cec005ea876449cff0a7153b94 (plain)
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
// 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.

//
// CONSTANTS -- INTEGER
//

// GC type flags
#define GC_ALLOC_FINALIZE 1
#define GC_ALLOC_ALIGN8_BIAS 4
#define GC_ALLOC_ALIGN8 8

#define TSF_Attached                    0x01
#define TSF_SuppressGcStress            0x08
#define TSF_DoNotTriggerGc              0x10

#define PTFF_SAVE_ALL_PRESERVED 0x00000077  // NOTE: FP is not included in this set!
#define PTFF_SAVE_SP 0x00000100
#define DEFAULT_FRAME_SAVE_FLAGS (PTFF_SAVE_ALL_PRESERVED + PTFF_SAVE_SP)

// These must match the TrapThreadsFlags enum
#define TrapThreadsFlags_None            0
#define TrapThreadsFlags_AbortInProgress 1
#define TrapThreadsFlags_TrapThreads     2

// Rename fields of nested structs
#define OFFSETOF__Thread__m_alloc_context__alloc_ptr (OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr)
#define OFFSETOF__Thread__m_alloc_context__alloc_limit (OFFSETOF__Thread__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_limit)

// GC minimal sized object. We use this to switch between 4 and 8 byte alignment in the GC heap (see AllocFast.asm).
#define SIZEOF__MinObject 12

// Maximum subsection number in .text section
#define MAX_NUMBER_SUBSECTION_TEXT 0x2000

.macro NESTED_ENTRY Name, Section, Handler
        LEAF_ENTRY \Name, \Section
        .ifnc \Handler, NoHandler
        .personality C_FUNC(\Handler)
        .endif
.endm

.macro NESTED_END Name, Section
        LEAF_END \Name, \Section
.endm

.macro PATCH_LABEL Name
        .thumb_func
        .global C_FUNC(\Name)
C_FUNC(\Name):
.endm

.macro ALTERNATE_ENTRY Name
        .global C_FUNC(\Name)
C_FUNC(\Name):
.endm

.macro LEAF_ENTRY Name, Section
        .thumb_func
        .global C_FUNC(\Name)
        .type \Name, %function
C_FUNC(\Name):
        .fnstart
.endm

.macro LEAF_END Name, Section
        .size \Name, .-\Name
        .fnend
.endm

.macro PREPARE_EXTERNAL_VAR Name, HelperReg
        ldr \HelperReg, [pc, #C_FUNC(\Name)@GOTPCREL]
.endm

.macro push_nonvol_reg Register
        push \Register
        .save \Register
.endm

.macro pop_nonvol_reg Register
        pop \Register
.endm

.macro vpush_nonvol_reg Register
        vpush \Register
        .vsave \Register
.endm

.macro vpop_nonvol_reg Register
        vpop \Register
.endm

.macro alloc_stack Size
        sub sp, sp, (\Size)
        .pad #(\Size)
.endm

.macro free_stack Size
        add sp, sp, (\Size)
        .pad #-(\Size)
.endm

.macro POP_CALLEE_SAVED_REGISTERS
        pop_nonvol_reg "{r4-r11, lr}"
.endm

.macro PUSH_CALLEE_SAVED_REGISTERS
        push_nonvol_reg "{r4-r11, lr}"
.endm

.macro push_register Reg
        push \Reg
.endm

.macro push_argument_register Reg
        push_register \Reg
.endm

.macro PUSH_ARGUMENT_REGISTERS
        push {r0-r3}
.endm

.macro pop_register Reg
        pop \Reg
.endm

.macro pop_argument_register Reg
        pop_register \Reg
.endm

.macro POP_ARGUMENT_REGISTERS
        pop {r0-r3}
.endm

.macro EMIT_BREAKPOINT
        .inst.w 0xde01
.endm

.macro PROLOG_PUSH RegList
        push_nonvol_reg "\RegList"
.endm

.macro PROLOG_VPUSH RegList
        vpush_nonvol_reg "\RegList"
.endm

.macro PROLOG_STACK_SAVE Register
        .setfp \Register, sp
        mov \Register, sp
.endm

.macro EPILOG_STACK_RESTORE Register
        mov sp, \Register
.endm

.macro EPILOG_POP RegList
        pop_nonvol_reg "\RegList"
.endm

.macro EPILOG_VPOP RegList
        vpop_nonvol_reg "\RegList"
.endm

.macro PROLOG_STACK_ALLOC Size
        sub sp, sp, #\Size
        .pad #\Size
.endm

.macro EPILOG_STACK_FREE Size
        add sp, sp, #\Size
        .pad #-\Size
.endm

//-----------------------------------------------------------------------------
// Macro used to check (in debug builds only) whether the stack is 64-bit aligned (a requirement before calling
// out into C++/OS code). Invoke this directly after your prolog (if the stack frame size is fixed) or directly
// before a call (if you have a frame pointer and a dynamic stack). A breakpoint will be invoked if the stack
// is misaligned.
//
.macro CHECK_STACK_ALIGNMENT

#ifdef _DEBUG
        push {r0}
        add r0, sp, #4
        tst r0, #7
        pop {r0}
        beq 0f
        EMIT_BREAKPOINT
0:
#endif
.endm

// Loads a 32bit constant into destination register
.macro MOV32 DestReg, Constant
        movw \DestReg, #((\Constant) & 0xFFFF)
        movt \DestReg, #((\Constant) >> 16)
.endm

.macro EXPORT_POINTER_TO_ADDRESS Name

1:

        .data
        .align      4
C_FUNC(\Name):
        .word       1b
        .global     C_FUNC(\Name)
        .text

.endm

//
// Macro used from unmanaged helpers called from managed code where the helper does not transition immediately
// into pre-emptive mode but may cause a GC and thus requires the stack is crawlable. This is typically the
// case for helpers that meddle in GC state (e.g. allocation helpers) where the code must remain in
// cooperative mode since it handles object references and internal GC state directly but a garbage collection
// may be inevitable. In these cases we need to be able to transition to pre-meptive mode deep within the
// unmanaged code but still be able to initialize the stack iterator at the first stack frame which may hold
// interesting GC references. In all our helper cases this corresponds to the most recent managed frame (e.g.
// the helper's caller).
//
// This macro builds a frame describing the current state of managed code.
//
// INVARIANTS
// - The macro assumes it defines the method prolog, it should typically be the first code in a method and
//   certainly appear before any attempt to alter the stack pointer.
// - This macro uses trashReg (after its initial value has been saved in the frame) and upon exit trashReg
//   will contain the address of transition frame.
//
.macro PUSH_COOP_PINVOKE_FRAME trashReg

        PROLOG_STACK_ALLOC 4          // Save space for caller's SP
        PROLOG_PUSH "{r4-r6,r8-r10}"  // Save preserved registers
        PROLOG_STACK_ALLOC 8          // Save space for flags and Thread*
        PROLOG_PUSH "{r7}"            // Save caller's FP
        PROLOG_PUSH "{r11,lr}"        // Save caller's frame-chain pointer and PC

        // Compute SP value at entry to this method and save it in the last slot of the frame (slot #11).
        add         \trashReg, sp, #(12 * 4)
        str         \trashReg, [sp, #(11 * 4)]

        // Record the bitmask of saved registers in the frame (slot #4).
        mov         \trashReg, #DEFAULT_FRAME_SAVE_FLAGS
        str         \trashReg, [sp, #(4 * 4)]

        mov         \trashReg, sp
.endm

// Pop the frame and restore register state preserved by PUSH_COOP_PINVOKE_FRAME
.macro POP_COOP_PINVOKE_FRAME
        EPILOG_POP  "{r11,lr}"        // Restore caller's frame-chain pointer and PC (return address)
        EPILOG_POP  "{r7}"            // Restore caller's FP
        EPILOG_STACK_FREE 8           // Discard flags and Thread*
        EPILOG_POP  "{r4-r6,r8-r10}"  // Restore preserved registers
        EPILOG_STACK_FREE 4           // Discard caller's SP
.endm

#ifdef _DEBUG
.macro GEN_ASSERT message, fileName, funcName
        ldr r0, =\message
        ldr r1, =\fileName
        ldr r2, =\funcName
        bl C_FUNC(NYI_Assert)
.endm
#endif

// thumb with PIC version
.macro INLINE_GET_TLS_VAR Var
        ldr     r0, 2f
1:
        add     r0, pc, r0
        bl      __tls_get_addr(PLT)
        // push data at the end of text section
        .pushsection .text, MAX_NUMBER_SUBSECTION_TEXT, "aM", %progbits, 4
        .balign 4
2:
        .4byte  \Var(TLSGD) + (. - 1b - 4)
        .popsection
.endm

.macro INLINE_GETTHREAD
        // Inlined version of call C_FUNC(RhpGetThread)
        INLINE_GET_TLS_VAR tls_CurrentThread
.endm

.macro INLINE_THREAD_UNHIJACK threadReg, trashReg1, trashReg2
        //
        // Thread::Unhijack()
        //
        ldr         \trashReg1, [\threadReg, #OFFSETOF__Thread__m_pvHijackedReturnAddress]
        cbz         \trashReg1, 1f

        ldr         \trashReg2, [\threadReg, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation]
        str         \trashReg1, [\trashReg2]
        mov         \trashReg1, #0
        str         \trashReg1, [\threadReg, #OFFSETOF__Thread__m_ppvHijackedReturnAddressLocation]
        str         \trashReg1, [\threadReg, #OFFSETOF__Thread__m_pvHijackedReturnAddress]

1:
.endm

.macro EPILOG_BRANCH_REG reg

        bx          \reg

.endm