-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacamd64.inc
580 lines (461 loc) · 10.3 KB
/
macamd64.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
;++
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
;
; Module:
;
; macamd64.w
;
; Astract:
;
; Contains AMD64 public architecture constants and assembly macros.
;
; Author:
;--
;++
;
; push_reg <reg>
;
; Macro Description:
;
; This macro emits a single-byte push <reg> instruction in a
; nested prologue, as well as the associated unwind code.
;
; Arguments:
;
; reg - supplies the integer register to push
;
;--
push_reg macro Reg
push Reg
.pushreg Reg
endm
;++
;
; rex_push_reg <reg>
;
; Macro Description:
;
; This macro emits a single-byte push <reg> instruction in a
; nested prologue, as well as the associated unwind code.
;
; This differs from push_reg only in that a redundant rex prefix
; is added. rex_push_reg must be used in lieu of push_reg when it
; appears as the first instruction in a function, as the calling
; standard dictates that functions must not begin with a single
; byte instruction.
;
; Arguments:
;
; reg - supplies the integer register to push
;
;--
rex_push_reg macro Reg
db 048h
push Reg
.pushreg Reg
endm
;++
;
; push_eflags
;
; Macro Description:
;
; This macro emits a single-byte pushfq instruction in a
; nested prologue, as well as the associated unwind code.
;
; Arguments:
;
; none
;
;--
push_eflags macro
pushfq
.allocstack 8
endm
;++
;
; rex_push_eflags
;
; Macro Description:
;
; This macro emits a single-byte pushfq instruction in a
; nested prologue, as well as the associated unwind code.
;
; This differs from push_eflags only in that a redundant rex prefix
; is added. rex_push_eflags must be used in lieu of push_eflags when it
; appears as the first instruction in a function, as the calling
; standard dictates that functions must not begin with a single
; byte instruction.
;
; Arguments:
;
; none
;
;--
rex_push_eflags macro
db 048h
pushfq
.allocstack 8
endm
;++
;
; alloc_stack <Size>
;
; Macro Description:
;
; This macro emits an opcode to subtract <Size> from rsp, as well
; as the associated unwind code.
;
; Arguments:
;
; Size - The number of bytes to subtract from rsp.
;
;--
alloc_stack macro Size
sub rsp, Size
.allocstack Size
endm
;++
;
; save_reg <Reg>, <Offset>
;
; Macro Description:
;
; This macro emits an opcode to save the non-volatile 64-bit general purpose
; register indicated by <Reg> at offset <Offset> relative to the current
; position of the stack pointer. It also generates the associated unwind
; code.
;
; Arguments:
;
; Reg - Supplies the integer register to save
;
; Offset - Supplies the offset relative to the current position of the stack
; pointer.
;
;--
save_reg macro Reg, Offset
mov Offset[rsp], Reg
.savereg Reg, Offset
endm
;++
;
; save_xmm128 <Reg>, <Offset>
;
; Macro Description:
;
; This macro emits an opcode to save the 128-bit non-volatile xmm register
; indicated by <Reg> at offset <Offset> relative to the current position
; of the stack pointer. It also generates the associated unwind code.
;
; Arguments:
;
; Reg - Supplies the xmm register register to save
;
; Offset - Supplies the offset relative to the current position of the stack
; pointer.
;
;--
save_xmm128 macro Reg, Offset
movdqa Offset[rsp], Reg
.savexmm128 Reg, Offset
endm
;++
;
; push_frame
;
; Macro Description:
;
; This macro emits unwind data indicating that a machine frame has been
; pushed on the stack (usually by the CPU in response to a trap or fault).
;
; Arguments:
;
; None.
;
;--
push_frame macro Code
.pushframe Code
endm
;++
;
; set_frame <Reg>, <Offset>
;
; Macro Description:
;
; This macro emits an opcode and unwind data establishing the use of <Reg>
; as the current stack frame pointer.
;
; Arguments:
;
; Reg - Supplies the integer register to use as the current stack frame
; pointer.
;
; Offset - Supplies the optional offset of the frame pointer relative to
; the stack frame. In stack frames greater than 080h bytes,
; a non-zero offset can help reduce the size of subsequent opcodes
; that access portions of the stack frame by facilitating the use of
; positive and negative single-byte displacements.
;
; If not supplied, no offset is assumed.
;
;--
set_frame macro Reg, Offset
if Offset
lea Reg, Offset[rsp]
else
mov Reg, rsp
endif
.setframe Reg, Offset
endm
;++
;
; END_PROLOGUE
;
; Macro Description:
;
; This macro marks the end of the prologue. This must appear after all
; of the prologue directives in a nested function.
;
; Arguments:
;
; None.
;
;--
END_PROLOGUE macro
.endprolog
endm
;++
;
; LEAF_ENTRY <Name>, <Section>, <NoPad>
;
; Macro Description:
;
; This macro indicates the beginning of a leaf function.
;
; A leaf function is one that DOES NOT:
;
; - manipulate non-volatile registers
; - manipulate the stack pointer
; - call other functions
; - reference an exception handler
; - contain a prologue
; - have any unwind data associated with it
;
; Arguments:
;
; Name - Supplies the name of the function
;
; Section - Supplies the name of the section within which the function
; is to appear
;
; NoPad - If present, indicates that the function should not be prefixed
; with 6 bytes of padding. This is for internal use only - the
; calling standard dictates that functions (nested and leaf) must
; be prefixed with padding.
;
;--
LEAF_ENTRY macro Name, Section, NoPad
Section segment para 'CODE'
ifb <NoPad>
db 6 dup (0cch)
endif
align 16
public Name
Name proc
endm
;++
;
; LEAF_ENTRY_ARG1 <Name>, <Section>, <Arg1>, <NoPad>
;
; Macro Description:
;
; Indicates the beginning of a leaf function, as LEAF_ENTRY above,
; and declares one input parameter so that debug info will be
; generated for it. The other forms, LEAF_ENTRY_ARG2 and LEAF_ENTRY_ARG3,
; are similar.
;
;--
LEAF_ENTRY_ARG1 macro Name, Section, Arg1, NoPad
Section segment para 'CODE'
ifb <NoPad>
db 6 dup (0cch)
endif
align 16
public Name
Name proc Arg1
endm
;++
;
; LEAF_ENTRY_ARG2 <Name>, <Section>, <Arg1>, <Arg2>, <NoPad>
;
; Macro Description:
;
; As LEAF_ENTRY_ARG1 above, marks the entry to a leaf function
; and defines 2 input parameters.
;
;--
LEAF_ENTRY_ARG2 macro Name, Section, Arg1, Arg2, NoPad
Section segment para 'CODE'
ifb <NoPad>
db 6 dup (0cch)
endif
align 16
public Name
Name proc Arg1, Arg2
endm
;++
;
; LEAF_ENTRY_ARG3 <Name>, <Section>, <Arg1>, <Arg2>, <Arg3>, <NoPad>
;
; Macro Description:
;
; As LEAF_ENTRY_ARG1 above, marks the entry to a leaf function
; and defines 3 input parameters.
;
;--
LEAF_ENTRY_ARG3 macro Name, Section, Arg1, Arg2, Arg3, NoPad
Section segment para 'CODE'
ifb <NoPad>
db 6 dup (0cch)
endif
align 16
public Name
Name proc Arg1, Arg2, Arg3
endm
;++
;
; LEAF_END <Name>, <Section>
;
; Macro Description:
;
; This macro indicates the end of a leaf function. It must be paired
; with a LEAF_ENTRY macro that includes matching Name and Section
; parameters.
;
; Arguments:
;
; Name - Supplies the name of the function. Must match that supplied to
; the corresponding LEAF_ENTRY macro.
;
; Section - Supplies the name of the section within which the function
; is to appear. Must match that supplied to the corresponding
; LEAF_ENTRY macro.
;
;--
LEAF_END macro Name, section
Name endp
Section ends
endm
;++
;
; NESTED_ENTRY <Name>, <Section>, <Handler>, <NoPad>
;
; Macro Description:
;
; This macro indicates the beginning of a nested function.
;
; A nested function is one that does any of the following:
;
; - manipulates non-volatile registers
; - manipulates the stack pointer
; - references an exception handler
; - calls other functions
;
; A nested function must include a prologue with unwind data.
;
; Arguments:
;
; Name - Supplies the name of the function.
;
; Section - Supplies the name of the section within which the function
; is to appear.
;
; Handler - Supplies the name of the handler for exceptions raised
; within the scope of this function.
;
; NoPad - If present, indicates that the function should not be prefixed
; with 6 bytes of padding. This is for internal use only - the
; calling standard dictates that functions (nested and leaf) must
; be prefixed with padding.
;
;--
NESTED_ENTRY macro Name, Section, Handler, NoPad
ifdef _CurrentSection_
ifdif <Section>, _CurrentSection_
.err <NESTED_ENTRY invoked for different sections within same module>
endif
endif
_CurrentSection_ EQU <Section>
Section segment para 'CODE'
ifb <NoPad>
db 6 dup (0cch)
endif
align 16
public Name
ifb <Handler>
Name proc frame
else
Name proc frame:Handler
endif
endm
;++
;
; NESTED_END <Name>, <Section>
;
; Macro Description:
;
; This macro indicates the end of a nested function. It must be paired
; with a NESTED_ENTRY macro that includes matching Name and Section
; parameters.
;
; Arguments:
;
; Name - Supplies the name of the function. Must match that supplied to
; the corresponding NESTED_ENTRY macro.
;
; Section - Supplies the name of the section within which the function
; is to appear. Must match that supplied to the corresponding
; NESTED_ENTRY macro.
;
;--
NESTED_END macro Name, section
Name endp
Section ends
endm
;++
;
; ALTERNATE_ENTRY <Name>
;
; Macro Description:
;
; This macro indicates an alternate entry point in a function, or
; a synonymous name for an existing function.
;
; Arguments:
;
; Name - Supplies the name of the alternate entry point.
;
;--
ALTERNATE_ENTRY macro Name
Name:
endm
;++
;
; Yield
;
; Macro Description:
;
; This macro generates a yield instruction, interpreted by SMT processors
; as an indication of a stall or idle condition.
;
; Arguments:
;
; None.
;
;--
Yield macro
pause ; yield execution on SMT processors
endm