-
Notifications
You must be signed in to change notification settings - Fork 4
/
yasm_macwin.inc.nofat
381 lines (326 loc) · 8.57 KB
/
yasm_macwin.inc.nofat
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
; Copyright (C) 2009, 2008 Brian Gladman
;
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are
; met:
; 1. Redistributions of source code must retain the above copyright notice,
; this list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
; HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
; Standardised register numbering scheme
%define r0 rax
%define r1 rdx
%define r2 rcx
%define r3 rbx
%define r4 rsi
%define r5 rdi
%define r6 rbp
%define r7 rsp
%define r0d eax
%define r1d edx
%define r2d ecx
%define r3d ebx
%define r4d esi
%define r5d edi
%define r6d ebp
%define r7d esp
%define r0w ax
%define r1w dx
%define r2w cx
%define r3w bx
%define r4w si
%define r5w di
%define r6w bp
%define r7w sp
%define r0b al
%define r1b dl
%define r2b cl
%define r3b bl
%define r4b sil
%define r5b dil
%define r6b bpl
%define r7b spl
%define asm_sym(x) __g %+ x
; Standard macro for alignment (used to allow easy subsititution of
; alternative padding schemes)
%macro xalign 1
align %1
%endmacro
; YASM macros for handling Windows Prologues and Epilogues
;
; Copyright 2008, 2009 Brian Gladman
;
; Windows x64 prologue macro:
;
; FRAME_PROC name, var_slots, register_save_list
;
; Windows x64 epilogue macro:
;
; EXIT_PROC register_save_list
;
; Windows x64 epilogue and end procedure macro
;
; END_PROC register_save_list
;
; where:
; name: routine name
; var_slots: stack space needed in 8 byte units
; register_save_list: comma separated list of registers to
; save and restore: a list of general
; purpose registers followed, if XMM
; registers are present, by XMM, and
; then a list of the numbers of the
; XMM registers to save and restore
; e.g. rsi, rdi, rbp, XMM, 6, 7, 8
; On return the macro variable 'stack_use' gives the total number
; of bytes used on the stack. This allows the function parameters
; to be accessed at [rsp + stack_use + 8 * n] where n starts at 1
; (for n = 1..4 this is shadow space for a register parameter)
%macro FRAME_PROC 2-*
global asm_sym(%1)
%ifdef DLL
export asm_sym(%1)
%endif
PROC_FRAME asm_sym(%1)
%rotate 1
%if %1 < 0
%error Negative stack allocation not allowed
%else
%assign var_slots %1
%endif
%rotate 1
%assign reg_slots 0
%assign xmm_seen 0
%if %0 > 2
%rep %0 - 2
%ifnum %1
%if xmm_seen == 0
%error Not an XMM register
%else
alloc_stack 16
save_xmm128 XMM%1, 0
%assign reg_slots reg_slots + 2
%endif
%elifid %1
%ifidni XMM, %1
%if reg_slots & 1 == 0
alloc_stack 8
%assign reg_slots reg_slots + 1
%assign xmm_seen 1
%else
%assign xmm_seen 2
%endif
%elif xmm_seen == 0
push_reg %1
%assign reg_slots reg_slots + 1
%else
%error XMM registers must be last in the save list
%endif
%else
%error Bad parameter list
%endif
%rotate 1
%endrep
%endif
%if (reg_slots & 1) == (var_slots & 1)
%assign var_slots var_slots + 1
%endif
%if var_slots > 0
alloc_stack 8 * var_slots
%endif
%assign stack_use 8 * (reg_slots + var_slots)
END_PROLOGUE
%endmacro
%macro EXIT_PROC 0-*
add rsp, 8 * var_slots
%if %0 > 0
%rep %0
%rotate -1
%ifnum %1
movdqa XMM%1, [rsp]
add rsp, 16
%elifidni %1, XMM
%if xmm_seen == 1
add rsp, 8
%endif
%else
pop %1
%endif
%endrep
%endif
ret
%endmacro
%macro END_PROC 0-*
%if var_slots
add rsp, 8 * var_slots
%endif
%if %0 > 0
%rep %0
%rotate -1
%ifnum %1
movdqa XMM%1, [rsp]
add rsp, 16
%elifidni %1, XMM
%if xmm_seen == 1
add rsp, 8
%endif
%else
pop %1
%endif
%endrep
%endif
ret
ENDPROC_FRAME
%endmacro
%macro LEAF_PROC 1
global asm_sym(%1)
%ifdef DLL
export asm_sym(%1)
%endif
asm_sym(%1):
%endmacro
; Macros for using assembler code using the GCC Calling
; Conventions in Windows. These macros move the first
; six integer parameters from Microsoft ABI calling
; calling conventions to those used by GCC:
;
; function( MSVC --> GCC
; p1, rcx rdi
; p2, rdx rsi
; p3, r8 rdx
; p4, r9 rcx
; p5, [rsp+40] r8
; p6, [rsp+48] r9
;
; WIN64_GCC_PROC name, n_parms, (frame | leaf)
;
; WIN64_GCC_EXIT frame | leaf
;
; WIN64_GCC_END frame | leaf
;
; name subroutine name
; n_parms number of parameters (default 6)
; type frame or leaf function (default frame)
;
; These defines are also used and must be set before the
; macros are used:
;
; reg_save_list list of registers to be saved
; and restored
; var_slots number of 8 byte slots needed
; on the stack (excluding the
; register save/restore space)
%macro WIN64_GCC_PROC 1-3 6, frame
%ifidn %3, frame
%ifndef reg_save_list
%define reg_save_list rsi, rdi
%endif
%ifndef var_slots
%define var_slots 0
%endif
FRAME_PROC %1, var_slots, reg_save_list
%elifidn %3, leaf
LEAF_PROC %1
%else
%error no (or wrong) function type defined
%endif
%if %2 > 0
mov rdi, rcx
%endif
%if %2 > 1
mov rsi, rdx
%endif
%if %2 > 2
mov rdx, r8
%endif
%if %2 > 3
mov rcx, r9
%endif
%if %2 > 4
mov r8, [rsp + stack_use + 40]
%endif
%if %2 > 5
mov r9, [rsp + stack_use + 48]
%endif
%endmacro
%macro WIN64_GCC_EXIT 0-1 frame
%ifidn %1, frame
EXIT_PROC reg_save_list
%elifidn %1, leaf
ret
%else
%error no (or wrong) function type defined
%endif
%endmacro
%macro WIN64_GCC_END 0-1 frame
%ifidn %1, frame
END_PROC reg_save_list
%elifidn %1, leaf
ret
%else
%error no (or wrong) function type defined
%endif
%endmacro
; Copyright 2008, William Hart, Jason Worth-Martin
;
; This file is part of the MPIR Library.
;
; The MPIR Library is free software; you can redistribute it and/or modify
; it under the terms of the GNU Lesser General Public License as published by
; the Free Software Foundation; either version 2.1 of the License, or (at your
; option) any later version.
;
; The MPIR Library is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
; License for more details.
;
; You should have received a copy of the GNU Lesser General Public License
; along with the MPIR Library; see the file COPYING.LIB. If not, write to
; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
; 02110-1301, USA.
%macro G_LABEL 1
%ifdef GSYM_PREFIX
_%1:
%else
%1:
%endif
%endmacro
%macro G_EXPORT 1
%ifdef GSYM_PREFIX
global _%1:function
%else
global %1:function
%endif
%endmacro
%macro G_EXTERN 1
%ifdef GSYM_PREFIX
extern _%1
%else
extern %1
%endif
%endmacro
%macro GLOBAL_FUNC 1
G_EXPORT __g%1
G_EXPORT %1
G_LABEL __g%1
G_LABEL %1
%endmacro
%define EXCLUDE_PREINV 1