VirtualBox

source: vbox/trunk/include/iprt/asmdefs.mac

最後變更 在這個檔案是 108259,由 vboxsync 提交於 4 週 前

iprt/asmdefs.mac: ELF .data & .text (BEGINCONST) section alignment fixes for yasm. [build fix]

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 37.1 KB
 
1;; @file
2; IPRT - Global YASM/NASM macros
3;
4
5;
6; Copyright (C) 2006-2024 Oracle and/or its affiliates.
7;
8; This file is part of VirtualBox base platform packages, as
9; available from https://www.alldomusa.eu.org.
10;
11; This program is free software; you can redistribute it and/or
12; modify it under the terms of the GNU General Public License
13; as published by the Free Software Foundation, in version 3 of the
14; License.
15;
16; This program is distributed in the hope that it will be useful, but
17; WITHOUT ANY WARRANTY; without even the implied warranty of
18; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19; General Public License for more details.
20;
21; You should have received a copy of the GNU General Public License
22; along with this program; if not, see <https://www.gnu.org/licenses>.
23;
24; The contents of this file may alternatively be used under the terms
25; of the Common Development and Distribution License Version 1.0
26; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27; in the VirtualBox distribution, in which case the provisions of the
28; CDDL are applicable instead of those of the GPL.
29;
30; You may elect to license modified versions of this file under the
31; terms and conditions of either the GPL or the CDDL or both.
32;
33; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34;
35
36; Special hack for bs3kit.
37%ifdef RT_ASMDEFS_INC_FIRST_FILE
38 %include "asmdefs-first.mac" ; edk2-ignore-hack
39%endif
40
41%ifndef ___iprt_asmdefs_mac
42%define ___iprt_asmdefs_mac
43
44
45;; @defgroup grp_rt_cdefs_size Size Constants
46; (Of course, these are binary computer terms, not SI.)
47; @{
48;; 1 K (Kilo) (1 024).
49%define _1K 000000400h
50;; 4 K (Kilo) (4 096).
51%define _4K 000001000h
52;; 8 K (Kilo) (8 192).
53%define _8K 000002000h
54;; 16 K (Kilo) (16 384).
55%define _16K 000004000h
56;; 32 K (Kilo) (32 768).
57%define _32K 000008000h
58;; 64 K (Kilo) (65 536).
59%define _64K 000010000h
60;; 128 K (Kilo) (131 072).
61%define _128K 000020000h
62;; 256 K (Kilo) (262 144).
63%define _256K 000040000h
64;; 512 K (Kilo) (524 288).
65%define _512K 000080000h
66;; 1 M (Mega) (1 048 576).
67%define _1M 000100000h
68;; 2 M (Mega) (2 097 152).
69%define _2M 000200000h
70;; 4 M (Mega) (4 194 304).
71%define _4M 000400000h
72;; 1 G (Giga) (1 073 741 824).
73%define _1G 040000000h
74;; 2 G (Giga) (2 147 483 648).
75%define _2G 00000000080000000h
76;; 4 G (Giga) (4 294 967 296).
77%define _4G 00000000100000000h
78;; 1 T (Tera) (1 099 511 627 776).
79%define _1T 00000010000000000h
80;; 1 P (Peta) (1 125 899 906 842 624).
81%define _1P 00004000000000000h
82;; 1 E (Exa) (1 152 921 504 606 846 976).
83%define _1E 01000000000000000h
84;; 2 E (Exa) (2 305 843 009 213 693 952).
85%define _2E 02000000000000000h
86;; @}
87
88
89;;
90; Define RT_STRICT for debug builds like iprt/cdefs.h does.
91%ifndef RT_STRICT
92 %ifdef DEBUG
93 %define RT_STRICT
94 %endif
95%endif
96%ifdef RT_NO_STRICT
97 %undef RT_STRICT
98%endif
99
100;;
101; Make the mask for the given bit.
102%define RT_BIT(bit) (1 << bit)
103
104;;
105; Make the mask for the given bit.
106%define RT_BIT_32(bit) (1 << bit)
107;;
108; Make the mask for the given bit.
109%define RT_BIT_64(bit) (1 << bit)
110
111;;
112; Makes a 32-bit unsigned (not type safe, but whatever) out of four byte values.
113%define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) ( (b3 << 24) | (b2 << 16) | (b1 << 8) | b0 )
114
115;; Preprocessor concatenation macro.
116%define RT_CONCAT(a_1,a_2) a_1 %+ a_2
117
118;; Preprocessor concatenation macro, three arguments.
119%define RT_CONCAT3(a_1,a_2,a_3) a_1 %+ a_2 %+ a_3
120
121;; Preprocessor concatenation macro, four arguments.
122%define RT_CONCAT4(a_1,a_2,a_3,a_4) a_1 %+ a_2 %+ a_3 %+ a_4
123
124;;
125; Trick for using RT_CONCAT and the like on %define names.
126; @param 1 The name (expression.
127; @param 2 The value.
128%macro RT_DEFINE_EX 2
129 %error 1=%1 2=%2
130 %define %1 %2
131%endmacro
132
133;;
134; Trick for using RT_CONCAT and the like on %xdefine names.
135; @param 1 The name (expression.
136; @param 2 The value.
137%macro RT_XDEFINE_EX 2
138 %xdefine %1 %2
139%endmacro
140
141;;
142; Trick for using RT_CONCAT and the like on %undef names.
143; @param 1 The name (expression.
144%macro RT_UNDEF_EX 1
145 %error 1=%1
146 %undef %1
147%endmacro
148
149;;
150; Empty define
151%define RT_NOTHING
152
153;; Define ASM_FORMAT_PE64 if applicable.
154%ifdef ASM_FORMAT_PE
155 %ifdef RT_ARCH_AMD64
156 %define ASM_FORMAT_PE64 1
157 %endif
158%endif
159
160;;
161; SEH64 macros.
162%ifdef RT_ASM_WITH_SEH64
163 %ifndef ASM_FORMAT_PE64
164 %undef RT_ASM_WITH_SEH64
165 %endif
166%endif
167
168%ifdef RT_ASM_WITH_SEH64_ALT
169 %ifdef ASM_FORMAT_PE64
170 ;; @name Register numbers. Used with RT_CONCAT to convert macro inputs to numbers.
171 ;; @{
172 %define SEH64_PE_GREG_rax 0
173 %define SEH64_PE_GREG_xAX 0
174 %define SEH64_PE_GREG_rcx 1
175 %define SEH64_PE_GREG_xCX 1
176 %define SEH64_PE_GREG_rdx 2
177 %define SEH64_PE_GREG_xDX 2
178 %define SEH64_PE_GREG_rbx 3
179 %define SEH64_PE_GREG_xBX 3
180 %define SEH64_PE_GREG_rsp 4
181 %define SEH64_PE_GREG_xSP 4
182 %define SEH64_PE_GREG_rbp 5
183 %define SEH64_PE_GREG_xBP 5
184 %define SEH64_PE_GREG_rsi 6
185 %define SEH64_PE_GREG_xSI 6
186 %define SEH64_PE_GREG_rdi 7
187 %define SEH64_PE_GREG_xDI 7
188 %define SEH64_PE_GREG_r8 8
189 %define SEH64_PE_GREG_r9 9
190 %define SEH64_PE_GREG_r10 10
191 %define SEH64_PE_GREG_r11 11
192 %define SEH64_PE_GREG_r12 12
193 %define SEH64_PE_GREG_r13 13
194 %define SEH64_PE_GREG_r14 14
195 %define SEH64_PE_GREG_r15 15
196 ;; @}
197
198 ;; @name PE unwind operations.
199 ;; @{
200 %define SEH64_PE_PUSH_NONVOL 0
201 %define SEH64_PE_ALLOC_LARGE 1
202 %define SEH64_PE_ALLOC_SMALL 2
203 %define SEH64_PE_SET_FPREG 3
204 %define SEH64_PE_SAVE_NONVOL 4
205 %define SEH64_PE_SAVE_NONVOL_FAR 5
206 %define SEH64_PE_SAVE_XMM128 8
207 %define SEH64_PE_SAVE_XMM128_FAR 9
208 ;; @}
209
210 ;;
211 ; Starts the unwind info for the manual SEH64 info generation.
212 ; @param 1 Function name.
213 %macro SEH64_ALT_START_UNWIND_INFO 1
214 %assign seh64_idxOps 0
215 %assign seh64_FrameReg SEH64_PE_GREG_rsp
216 %assign seh64_offFrame 0
217 %define asm_seh64_proc %1
218 %undef seh64_slot_bytes
219 %endmacro
220
221 ;; We keep the unwind bytes in the seh64_slot_bytes (x)define, in reverse order as per spec.
222 %macro SEH64_APPEND_SLOT_PAIR 2
223 %ifdef seh64_slot_bytes
224 %xdefine seh64_slot_bytes %1, %2, seh64_slot_bytes
225 %else
226 %xdefine seh64_slot_bytes %1, %2
227 %endif
228 %endmacro
229
230 ;; For multi-slot unwind info.
231 %macro SEH64_APPEND_SLOT_BYTES 2+
232 %rep %0
233 %rotate -1
234 %ifdef seh64_slot_bytes
235 %xdefine seh64_slot_bytes %1, seh64_slot_bytes
236 %else
237 %xdefine seh64_slot_bytes %1
238 %endif
239 %endrep
240 %endmacro
241
242 %else
243 %undef RT_ASM_WITH_SEH64_ALT
244 %endif
245%endif
246
247;;
248; Records a xBP push.
249%macro SEH64_PUSH_xBP 0
250 %ifdef RT_ASM_WITH_SEH64
251 [pushreg rbp]
252
253 %elifdef RT_ASM_WITH_SEH64_ALT
254RT_CONCAT(.seh64_op_label_,seh64_idxOps):
255 %ifdef ASM_FORMAT_PE64
256 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
257 SEH64_PE_PUSH_NONVOL | (SEH64_PE_GREG_rbp << 4)
258 %endif
259 %assign seh64_idxOps seh64_idxOps + 1
260 %endif
261%endmacro
262
263;;
264; Records a general register push.
265; @param 1 Register name.
266%macro SEH64_PUSH_GREG 1
267 %ifdef RT_ASM_WITH_SEH64
268 [pushreg %1]
269
270 %elifdef RT_ASM_WITH_SEH64_ALT
271RT_CONCAT(.seh64_op_label_,seh64_idxOps):
272 %ifdef ASM_FORMAT_PE64
273 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
274 SEH64_PE_PUSH_NONVOL | (RT_CONCAT(SEH64_PE_GREG_,%1) << 4)
275 %endif
276 %assign seh64_idxOps seh64_idxOps + 1
277 %endif
278%endmacro
279
280;;
281; Sets xBP as frame pointer that's pointing to a stack position %1 relative to xBP.
282%macro SEH64_SET_FRAME_xBP 1
283 %ifdef RT_ASM_WITH_SEH64
284 [setframe rbp, %1]
285
286 %elifdef RT_ASM_WITH_SEH64_ALT
287RT_CONCAT(.seh64_op_label_,seh64_idxOps):
288 %ifdef ASM_FORMAT_PE64
289 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
290 SEH64_PE_SET_FPREG | 0 ; vs2019 seems to put the offset in the info field
291 %assign seh64_FrameReg SEH64_PE_GREG_rbp
292 %assign seh64_offFrame %1
293 %endif
294 %assign seh64_idxOps seh64_idxOps + 1
295 %endif
296%endmacro
297
298;;
299; Records an ADD xSP, %1.
300%macro SEH64_ALLOCATE_STACK 1
301 %ifdef RT_ASM_WITH_SEH64
302 [allocstack %1]
303
304 %elifdef RT_ASM_WITH_SEH64_ALT
305RT_CONCAT(.seh64_op_label_,seh64_idxOps):
306 %ifdef ASM_FORMAT_PE64
307 %if (%1) & 7
308 %error "SEH64_ALLOCATE_STACK must be a multiple of 8"
309 %endif
310 %if (%1) < 8
311 %error "SEH64_ALLOCATE_STACK must have an argument that's 8 or higher."
312 %elif (%1) <= 128
313 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
314 SEH64_PE_ALLOC_SMALL | ((((%1) / 8) - 1) << 4)
315 %elif (%1) < 512
316 SEH64_APPEND_SLOT_BYTES RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
317 SEH64_PE_ALLOC_LARGE | 0, \
318 ((%1) / 8) & 0xff, ((%1) / 8) >> 8
319 %else
320 SEH64_APPEND_SLOT_BYTES RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
321 SEH64_PE_ALLOC_LARGE | 1, \
322 (%1) & 0xff, ((%1) >> 8) & 0xff, ((%1) >> 16) & 0xff, ((%1) >> 24) & 0xff
323 %endif
324 %endif
325 %assign seh64_idxOps seh64_idxOps + 1
326 %endif
327%endmacro
328
329%macro SEH64_INFO_HELPER 1
330%if defined(%1)
331 dw %1
332%endif
333%endmacro
334
335;;
336; Ends the prologue.
337%macro SEH64_END_PROLOGUE 0
338.end_of_prologue:
339 %ifdef RT_ASM_WITH_SEH64
340 [endprolog]
341
342 %elifdef RT_ASM_WITH_SEH64_ALT
343 %ifdef ASM_FORMAT_PE
344 ; Emit the unwind info now.
345 %ifndef ASM_DEFINED_XDATA_SECTION
346 %define ASM_DEFINED_XDATA_SECTION
347 section .xdata rdata align=4
348 %else
349 section .xdata
350 align 4, db 0
351 %endif
352.unwind_info:
353 db 1 ; version 1 (3 bit), no flags (5 bits)
354 db .end_of_prologue - .start_of_prologue
355
356 db (.unwind_info_array_end - .unwind_info_array) / 2
357 db seh64_FrameReg | (seh64_offFrame & 0xf0) ; framereg and offset/16.
358.unwind_info_array:
359 %ifdef seh64_slot_bytes
360 db seh64_slot_bytes
361 %undef seh64_slot_bytes
362 %endif
363.unwind_info_array_end:
364
365 ; Reset the segment
366 BEGINCODE
367 %endif
368 %endif
369%endmacro
370
371;;
372; Macro for generating the endbr32/64 instruction when
373; RT_WITH_IBT_BRANCH_PROTECTION is defined.
374%macro IBT_ENDBRxx 0
375 %ifdef RT_WITH_IBT_BRANCH_PROTECTION
376 %ifdef RT_ARCH_AMD64
377 db 0xf3, 0x0f, 0x1e, 0xfa ; yasm doesn't know about endbr64
378 %elifdef RT_ARCH_X86
379 db 0xf3, 0x0f, 0x1e, 0xfb ; yasm doesn't know about endbr32
380 %else
381 %error "Which arch?"
382 %endif
383 %endif
384%endmacro
385
386;;
387; Macro for generating the endbr32/64 instruction when
388; RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK is defined.
389%macro IBT_ENDBRxx_WITHOUT_NOTRACK 0
390 %ifdef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
391 %ifdef RT_ARCH_AMD64
392 db 0xf3, 0x0f, 0x1e, 0xfa ; yasm doesn't know about endbr64
393 %elifdef RT_ARCH_X86
394 db 0xf3, 0x0f, 0x1e, 0xfb ; yasm doesn't know about endbr32
395 %else
396 %error "Which arch?"
397 %endif
398 %endif
399%endmacro
400
401;;
402; Macro for generating a NOTRACK prefix to an indirect jmp or call
403; instruction when RT_WITH_IBT_BRANCH_PROTECTION is defined.
404;
405; @note Carful if mixing with other segment prefixes (should work, but needs
406; testing).
407%macro IBT_NOTRACK 0
408 %ifdef RT_WITH_IBT_BRANCH_PROTECTION
409 %ifndef RT_WITH_IBT_BRANCH_PROTECTION_WITHOUT_NOTRACK
410 db 0x3e ; DS prefix.
411 %endif
412 %endif
413%endmacro
414
415
416;;
417; Align code, pad with INT3.
418%define ALIGNCODE(alignment) align alignment, db 0cch
419
420;;
421; Align data, pad with ZEROs.
422%define ALIGNDATA(alignment) align alignment, db 0
423
424;;
425; Align BSS, pad with ZEROs.
426%define ALIGNBSS(alignment) align alignment, resb 1
427
428;;
429; NAME_OVERLOAD can be defined by a .asm module to modify all the
430; names created using the name macros in this files.
431; This is handy when you've got some kind of template code.
432%ifndef NAME_OVERLOAD
433 %ifdef RT_MANGLER_PREFIX
434 %define NAME_OVERLOAD(name) RT_MANGLER_PREFIX %+ name
435 %else
436 %define NAME_OVERLOAD(name) name
437 %endif
438%endif
439
440;;
441; Mangles the given name so it can be referenced using DECLASM() in the
442; C/C++ world.
443%ifndef ASM_FORMAT_BIN
444 %ifdef RT_ARCH_X86
445 %ifdef RT_OS_OS2
446 %define NAME(name) _ %+ NAME_OVERLOAD(name)
447 %endif
448 %ifdef RT_OS_WINDOWS
449 %define NAME(name) _ %+ NAME_OVERLOAD(name)
450 %endif
451 %endif
452 %ifdef RT_OS_DARWIN
453 %define NAME(name) _ %+ NAME_OVERLOAD(name)
454 %endif
455%endif
456%ifndef NAME
457 %define NAME(name) NAME_OVERLOAD(name)
458%endif
459
460;;
461; Mangles the given C name so it will _import_ the right symbol.
462%ifdef ASM_FORMAT_PE
463 %define IMPNAME(name) __imp_ %+ NAME(name)
464%else
465 %define IMPNAME(name) NAME(name)
466%endif
467
468;;
469; Gets the pointer to an imported object.
470%ifdef ASM_FORMAT_PE
471 %ifdef RT_ARCH_AMD64
472 %define IMP(name) qword [IMPNAME(name) wrt rip]
473 %else
474 %define IMP(name) dword [IMPNAME(name)]
475 %endif
476%else
477 %define IMP(name) IMPNAME(name)
478%endif
479
480;;
481; Gets the pointer to an imported object.
482%ifdef ASM_FORMAT_PE
483 %ifdef RT_ARCH_AMD64
484 %define IMP_SEG(SegOverride, name) qword [SegOverride:IMPNAME(name) wrt rip]
485 %else
486 %define IMP_SEG(SegOverride, name) dword [SegOverride:IMPNAME(name)]
487 %endif
488%else
489 %define IMP_SEG(SegOverride, name) IMPNAME(name)
490%endif
491
492;;
493; Declares an imported object for use with IMP2.
494; @note May change the current section!
495%macro EXTERN_IMP2 1
496 extern IMPNAME(%1)
497 BEGINDATA
498 %ifdef ASM_FORMAT_MACHO
499 g_Imp2_ %+ %1: RTCCPTR_DEF IMPNAME(%1)
500 %endif
501%endmacro
502
503;;
504; Gets the pointer to an imported object, version 2.
505%ifdef ASM_FORMAT_PE
506 %ifdef RT_ARCH_AMD64
507 %define IMP2(name) qword [IMPNAME(name) wrt rip]
508 %else
509 %define IMP2(name) dword [IMPNAME(name)]
510 %endif
511%elifdef ASM_FORMAT_ELF
512 %ifdef PIC
513 %ifdef RT_ARCH_AMD64
514 %define IMP2(name) qword [rel IMPNAME(name) wrt ..got]
515 %else
516 %define IMP2(name) IMPNAME(name) wrt ..plt
517 %endif
518 %endif
519%elifdef ASM_FORMAT_MACHO
520 %define IMP2(name) RTCCPTR_PRE [g_Imp2_ %+ name xWrtRIP]
521%endif
522%ifndef IMP2
523 %define IMP2(name) IMPNAME(name)
524%endif
525
526
527;;
528; Define a label as given, with a '$' prepended to permit using instruction
529; names like fdiv as labels.
530%macro SAFE_LABEL 1
531$%1:
532%endmacro
533
534;;
535; Global marker which is DECLASM() compatible.
536%macro GLOBALNAME 1
537%ifndef ASM_FORMAT_BIN
538global NAME(%1)
539%endif
540SAFE_LABEL NAME(%1)
541%endmacro
542
543;;
544; Global exported marker which is DECLASM() compatible.
545%macro EXPORTEDNAME 1
546 %ifdef ASM_FORMAT_PE
547 export %1=NAME(%1)
548 %endif
549 %ifdef __NASM__
550 %ifdef ASM_FORMAT_OMF
551 export NAME(%1) NAME(%1)
552 %endif
553%endif
554GLOBALNAME %1
555%endmacro
556
557;;
558; Same as GLOBALNAME_EX, but without the name mangling.
559;
560; @param %1 The symbol name - subjected to NAME().
561; @param %2 ELF and PE attributes: 'function', 'object', 'data', 'notype'.
562; PE ignores all but 'function' (yasm only). Other formats ignores
563; this completely.
564; @param %3 Symbol visibility: 'hidden', 'protected', 'internal', and
565; RT_NOTHING (for 'default' visibility).
566; These are ELF attributes, but 'hidden' is translated to
567; 'private_extern' for the Macho-O format.
568; Ignored by other formats.
569;
570%macro GLOBALNAME_RAW 3
571%ifdef ASM_FORMAT_ELF
572global %1:%2 %3
573
574%elifdef ASM_FORMAT_PE
575 %ifidn %2,function
576 %ifdef __YASM__ ; nasm does not support any attributes, it errors out. So, nasm is no good with control flow guard atm.
577global %1:function
578 %else
579global %1
580 %endif
581 %else
582global %1
583 %endif
584
585%elifdef ASM_FORMAT_MACHO
586 %ifidn %3,hidden
587global %1:private_extern
588 %else
589global %1
590 %endif
591
592%elifndef ASM_FORMAT_BIN
593global %1
594
595%endif
596
597%1:
598%endmacro
599
600;;
601; Global marker which is DECLASM() compatible.
602;
603; @param %1 The symbol name - subjected to NAME().
604; @param %2 ELF and PE attributes: 'function', 'object', 'data', 'notype'.
605; PE ignores all but 'function' (yasm only). Other formats ignores
606; this completely.
607; @param %3 Symbol visibility: 'hidden', 'protected', 'internal', and
608; RT_NOTHING (for 'default' visibility).
609; These are ELF attributes, but 'hidden' is translated to
610; 'private_extern' for the Macho-O format.
611; Ignored by other formats.
612;
613%macro GLOBALNAME_EX 3
614GLOBALNAME_RAW NAME(%1), %2, %3
615%endmacro
616
617
618;;
619; Global exported marker, raw version w/o automatic name mangling.
620;
621; @param %1 The internal symbol name.
622; @param %2 The external symbol name.
623; @param %3 ELF and PE attributes: 'function', 'object', 'data', 'notype'.
624; PE ignores all but 'function' (yasm only). Other formats ignores
625; this completely.
626;
627%macro EXPORTEDNAME_RAW 3
628 %ifdef ASM_FORMAT_PE
629 export %2=%1
630 %endif
631 %ifdef __NASM__
632 %ifdef ASM_FORMAT_OMF
633 export %1 %2
634 %endif
635%endif
636GLOBALNAME_RAW %1, %3, RT_NOTHING
637%endmacro
638
639;;
640; Global exported marker which is DECLASM() compatible.
641;
642; @param %1 The symbol name - subjected to NAME().
643; @param %2 ELF and PE attributes: 'function', 'object', 'data', 'notype'.
644; PE ignores all but 'function' (yasm only). Other formats ignores
645; this completely.
646;
647%macro EXPORTEDNAME_EX 2
648EXPORTEDNAME_RAW NAME(%1), %1, %2
649%endmacro
650
651
652;;
653; Begins a procedure, raw version w/o automatic name mangling.
654; @param 1 The (raw) name.
655; @param 2 Whether to manually apply IBT_ENDBRxx (1) or
656; not (0, default). Optional
657%macro BEGINPROC_RAW 1-2 0
658 %ifdef RT_ASM_WITH_SEH64_ALT
659 SEH64_ALT_START_UNWIND_INFO %1
660 %endif
661 %ifdef RT_ASM_WITH_SEH64
662global %1:function
663proc_frame %1
664 %else
665GLOBALNAME_RAW %1, function, hidden
666 %endif
667.start_of_prologue:
668 %if %2 == 0
669 IBT_ENDBRxx
670 %endif
671%endmacro
672
673;;
674; Begins a C callable (DECLASM) procedure.
675%macro BEGINPROC 1-2 0
676BEGINPROC_RAW NAME(%1), %2
677%endmacro
678
679
680;;
681; Begins a exported procedure, raw version w/o automatic name mangling.
682; @param 1 Internal name.
683; @param 2 Exported name.
684; @param 3 Whether to manually apply IBT_ENDBRxx (1) or
685; not (0, default). Optional
686%macro BEGINPROC_EXPORTED_RAW 2-3 0
687 %ifdef RT_ASM_WITH_SEH64_ALT
688 SEH64_ALT_START_UNWIND_INFO %1
689 %endif
690 %ifdef RT_ASM_WITH_SEH64
691 %ifdef ASM_FORMAT_PE
692export %2=%1
693 %endif
694global %1:function
695proc_frame %1
696 %else
697EXPORTEDNAME_RAW %1, %2, function
698 %endif
699.start_of_prologue:
700 %if %3 == 0
701 IBT_ENDBRxx
702 %endif
703%endmacro
704
705;;
706; Begins a C callable (DECLASM) exported procedure.
707%macro BEGINPROC_EXPORTED 1-2 0
708BEGINPROC_EXPORTED_RAW NAME(%1), %1, %2
709%endmacro
710
711
712;;
713; Ends a procedure, raw version w/o automatic name mangling.
714%macro ENDPROC_RAW 1
715 %ifdef RT_ASM_WITH_SEH64
716endproc_frame
717 %endif
718GLOBALNAME_RAW %1 %+ _EndProc, , hidden ; no function here, this isn't a valid code flow target.
719%ifdef ASM_FORMAT_ELF
720 %ifndef __NASM__ ; nasm does this in the global directive.
721size %1 %1 %+ _EndProc - %1
722size %1 %+ _EndProc 4 ; make it non-zero to shut up warnigns from Linux's objtool.
723 %endif
724%endif
725 db 0xCC, 0xCC, 0xCC, 0xCC
726
727 %ifdef RT_ASM_WITH_SEH64_ALT
728 %ifdef ASM_FORMAT_PE
729 ; Emit the RUNTIME_FUNCTION entry. The linker is picky here, no label.
730 %ifndef ASM_DEFINED_PDATA_SECTION
731 %define ASM_DEFINED_PDATA_SECTION
732 section .pdata rdata align=4
733 %else
734 section .pdata
735 %endif
736 dd %1 wrt ..imagebase
737 dd %1 %+ _EndProc wrt ..imagebase
738 dd %1 %+ .unwind_info wrt ..imagebase
739
740 ; Restore code section.
741 BEGINCODE
742 %endif
743 %endif
744%endmacro
745
746;;
747; Ends a C callable procedure.
748%macro ENDPROC 1
749ENDPROC_RAW NAME(%1)
750%endmacro
751
752
753;
754; Do OMF, Mach-O/Yasm and ELF/Yasm segment definitions.
755;
756; For OMF and Mach-O it is to get the segment order right. For Mach-O it's only
757; to make sure the .bss section ends up last (it's not declared here).
758;
759; Neither Mach-O nor ELF have data alignments propagated to the section
760; alignment, so we have to explictly set the .data section and .rodata/.text
761; alignments here to 16 bytes to ensure we can cope with most stuff.
762; TODO: Check what nasm does!
763;
764%ifdef ASM_FORMAT_OMF
765 %ifndef RT_NOINC_SEGMENTS
766
767 ; 16-bit segments first (OMF / OS/2 specific).
768 %ifdef RT_INCL_16BIT_SEGMENTS
769 segment DATA16 public CLASS=FAR_DATA align=16 use16
770 segment DATA16_INIT public CLASS=FAR_DATA align=16 use16
771 group DGROUP16 DATA16 DATA16_INIT
772
773 ;;
774 ; Begins 16-bit data
775 %macro BEGINDATA16 0
776 segment DATA16
777 %endmacro
778
779 ;;
780 ; Begins 16-bit init data
781 %macro BEGINDATA16INIT 0
782 segment DATA16_INIT
783 %endmacro
784
785 segment CODE16 public CLASS=FAR_CODE align=16 use16
786 segment CODE16_INIT public CLASS=FAR_CODE align=16 use16
787 group CGROUP16 CODE16 CODE16_INIT
788
789 ;;
790 ; Begins 16-bit code
791 %macro BEGINCODE16 0
792 segment CODE16
793 %endmacro
794
795 ;;
796 ; Begins 16-bit init code
797 %macro BEGINCODE16INIT 0
798 segment CODE16_INIT
799 %endmacro
800
801 %endif
802
803 ; 32-bit segments.
804 segment TEXT32 public CLASS=CODE align=16 use32 flat
805 segment DATA32 public CLASS=DATA align=16 use32 flat
806 segment BSS32 public CLASS=BSS align=16 use32 flat
807
808 ; Make the TEXT32 segment default.
809 segment TEXT32
810 %endif ; RT_NOINC_SEGMENTS
811%endif
812
813%ifdef ASM_FORMAT_MACHO
814 %ifdef __YASM__
815 %ifndef RT_NOINC_SEGMENTS
816 section .text
817 section .data align=16
818 section .rodata align=16
819 section .text ; Make the .text segment default and w/o attributes
820 %endif
821 %endif
822%endif
823
824%ifdef ASM_FORMAT_ELF
825 %ifdef __YASM__
826 %ifndef RT_NOINC_SEGMENTS
827 section .text align=16
828 section .data align=16
829 section .text ; Make the .text segment default and w/o attributes (or stuc/endstruc will trigger warnings).
830 %endif
831 %endif
832%endif
833
834
835;;
836; Begins code
837%ifdef ASM_FORMAT_OMF
838 %macro BEGINCODE 0
839 segment TEXT32
840 %endmacro
841%else
842%macro BEGINCODE 0
843 section .text
844%endmacro
845%endif
846
847;;
848; Begins constant (read-only) data
849;
850; @remarks This is mapped to the CODE section/segment when there isn't
851; any dedicated const section/segment. (There is code that
852; assumes this, so don't try change it.)
853%ifdef ASM_FORMAT_OMF
854 %macro BEGINCONST 0
855 segment TEXT32
856 %endmacro
857%else
858 %macro BEGINCONST 0
859 %ifdef ASM_FORMAT_MACHO ;; @todo check the other guys too.
860 section .rodata
861 %else
862 section .text
863 %endif
864 %endmacro
865%endif
866
867;;
868; Begins initialized data
869%ifdef ASM_FORMAT_OMF
870 %macro BEGINDATA 0
871 segment DATA32
872 %endmacro
873%else
874%macro BEGINDATA 0
875 section .data
876%endmacro
877%endif
878
879;;
880; Begins uninitialized data
881%ifdef ASM_FORMAT_OMF
882 %macro BEGINBSS 0
883 segment BSS32
884 %endmacro
885%else
886%macro BEGINBSS 0
887 section .bss
888%endmacro
889%endif
890
891
892
893;; @def ARCH_BITS
894; Defines the bit count of the current context.
895%ifndef ARCH_BITS
896 %ifdef RT_ARCH_AMD64
897 %define ARCH_BITS 64
898 %else
899 %define ARCH_BITS 32
900 %endif
901%endif
902
903;; @def HC_ARCH_BITS
904; Defines the host architechture bit count.
905%ifndef HC_ARCH_BITS
906 %ifndef IN_RC
907 %define HC_ARCH_BITS ARCH_BITS
908 %else
909 %define HC_ARCH_BITS 32
910 %endif
911%endif
912
913;; @def R3_ARCH_BITS
914; Defines the host ring-3 architechture bit count.
915%ifndef R3_ARCH_BITS
916 %ifdef IN_RING3
917 %define R3_ARCH_BITS ARCH_BITS
918 %else
919 %define R3_ARCH_BITS HC_ARCH_BITS
920 %endif
921%endif
922
923;; @def R0_ARCH_BITS
924; Defines the host ring-0 architechture bit count.
925%ifndef R0_ARCH_BITS
926 %ifdef IN_RING0
927 %define R0_ARCH_BITS ARCH_BITS
928 %else
929 %define R0_ARCH_BITS HC_ARCH_BITS
930 %endif
931%endif
932
933;; @def GC_ARCH_BITS
934; Defines the guest architechture bit count.
935%ifndef GC_ARCH_BITS
936 %ifdef IN_RC
937 %define GC_ARCH_BITS ARCH_BITS
938 %else
939 %define GC_ARCH_BITS 32
940 %endif
941%endif
942
943
944
945;; @def RTHCPTR_DEF
946; The pesudo-instruction used to declare an initialized pointer variable in the host context.
947%if HC_ARCH_BITS == 64
948 %define RTHCPTR_DEF dq
949%else
950 %define RTHCPTR_DEF dd
951%endif
952
953;; @def RTHCPTR_RES
954; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
955; variable of the host context.
956%if HC_ARCH_BITS == 64
957 %define RTHCPTR_RES resq
958%else
959 %define RTHCPTR_RES resd
960%endif
961
962;; @def RTHCPTR_PRE
963; The memory operand prefix used for a pointer in the host context.
964%if HC_ARCH_BITS == 64
965 %define RTHCPTR_PRE qword
966%else
967 %define RTHCPTR_PRE dword
968%endif
969
970;; @def RTHCPTR_CB
971; The size in bytes of a pointer in the host context.
972%if HC_ARCH_BITS == 64
973 %define RTHCPTR_CB 8
974%else
975 %define RTHCPTR_CB 4
976%endif
977
978
979
980;; @def RTR0PTR_DEF
981; The pesudo-instruction used to declare an initialized pointer variable in the ring-0 host context.
982%if R0_ARCH_BITS == 64
983 %define RTR0PTR_DEF dq
984%else
985 %define RTR0PTR_DEF dd
986%endif
987
988;; @def RTR0PTR_RES
989; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
990; variable of the ring-0 host context.
991%if R0_ARCH_BITS == 64
992 %define RTR0PTR_RES resq
993%else
994 %define RTR0PTR_RES resd
995%endif
996
997;; @def RTR0PTR_PRE
998; The memory operand prefix used for a pointer in the ring-0 host context.
999%if R0_ARCH_BITS == 64
1000 %define RTR0PTR_PRE qword
1001%else
1002 %define RTR0PTR_PRE dword
1003%endif
1004
1005;; @def RTR0PTR_CB
1006; The size in bytes of a pointer in the ring-0 host context.
1007%if R0_ARCH_BITS == 64
1008 %define RTR0PTR_CB 8
1009%else
1010 %define RTR0PTR_CB 4
1011%endif
1012
1013
1014
1015;; @def RTR3PTR_DEF
1016; The pesudo-instruction used to declare an initialized pointer variable in the ring-3 host context.
1017%if R3_ARCH_BITS == 64
1018 %define RTR3PTR_DEF dq
1019%else
1020 %define RTR3PTR_DEF dd
1021%endif
1022
1023;; @def RTR3PTR_RES
1024; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
1025; variable of the ring-3 host context.
1026%if R3_ARCH_BITS == 64
1027 %define RTR3PTR_RES resq
1028%else
1029 %define RTR3PTR_RES resd
1030%endif
1031
1032;; @def RTR3PTR_PRE
1033; The memory operand prefix used for a pointer in the ring-3 host context.
1034%if R3_ARCH_BITS == 64
1035 %define RTR3PTR_PRE qword
1036%else
1037 %define RTR3PTR_PRE dword
1038%endif
1039
1040;; @def RTR3PTR_CB
1041; The size in bytes of a pointer in the ring-3 host context.
1042%if R3_ARCH_BITS == 64
1043 %define RTR3PTR_CB 8
1044%else
1045 %define RTR3PTR_CB 4
1046%endif
1047
1048
1049
1050;; @def RTGCPTR_DEF
1051; The pesudo-instruction used to declare an initialized pointer variable in the guest context.
1052%if GC_ARCH_BITS == 64
1053 %define RTGCPTR_DEF dq
1054%else
1055 %define RTGCPTR_DEF dd
1056%endif
1057
1058;; @def RTGCPTR_RES
1059; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
1060; variable of the guest context.
1061%if GC_ARCH_BITS == 64
1062 %define RTGCPTR_RES resq
1063%else
1064 %define RTGCPTR_RES resd
1065%endif
1066
1067%define RTGCPTR32_RES resd
1068%define RTGCPTR64_RES resq
1069
1070;; @def RTGCPTR_PRE
1071; The memory operand prefix used for a pointer in the guest context.
1072%if GC_ARCH_BITS == 64
1073 %define RTGCPTR_PRE qword
1074%else
1075 %define RTGCPTR_PRE dword
1076%endif
1077
1078;; @def RTGCPTR_CB
1079; The size in bytes of a pointer in the guest context.
1080%if GC_ARCH_BITS == 64
1081 %define RTGCPTR_CB 8
1082%else
1083 %define RTGCPTR_CB 4
1084%endif
1085
1086
1087;; @def RTRCPTR_DEF
1088; The pesudo-instruction used to declare an initialized pointer variable in the raw mode context.
1089%define RTRCPTR_DEF dd
1090
1091;; @def RTRCPTR_RES
1092; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
1093; variable of the raw mode context.
1094%define RTRCPTR_RES resd
1095
1096;; @def RTRCPTR_PRE
1097; The memory operand prefix used for a pointer in the raw mode context.
1098%define RTRCPTR_PRE dword
1099
1100;; @def RTRCPTR_CB
1101; The size in bytes of a pointer in the raw mode context.
1102%define RTRCPTR_CB 4
1103
1104
1105;; @def RT_CCPTR_DEF
1106; The pesudo-instruction used to declare an initialized pointer variable in the current context.
1107
1108;; @def RT_CCPTR_RES
1109; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
1110; variable of the current context.
1111
1112;; @def RT_CCPTR_PRE
1113; The memory operand prefix used for a pointer in the current context.
1114
1115;; @def RT_CCPTR_CB
1116; The size in bytes of a pointer in the current context.
1117
1118%ifdef IN_RC
1119 %define RTCCPTR_DEF RTRCPTR_DEF
1120 %define RTCCPTR_RES RTRCPTR_RES
1121 %define RTCCPTR_PRE RTRCPTR_PRE
1122 %define RTCCPTR_CB RTRCPTR_CB
1123%else
1124 %ifdef IN_RING0
1125 %define RTCCPTR_DEF RTR0PTR_DEF
1126 %define RTCCPTR_RES RTR0PTR_RES
1127 %define RTCCPTR_PRE RTR0PTR_PRE
1128 %define RTCCPTR_CB RTR0PTR_CB
1129 %else
1130 %define RTCCPTR_DEF RTR3PTR_DEF
1131 %define RTCCPTR_RES RTR3PTR_RES
1132 %define RTCCPTR_PRE RTR3PTR_PRE
1133 %define RTCCPTR_CB RTR3PTR_CB
1134 %endif
1135%endif
1136
1137
1138
1139;; @def RTHCPHYS_DEF
1140; The pesudo-instruction used to declare an initialized host physical address.
1141%define RTHCPHYS_DEF dq
1142
1143;; @def RTHCPTR_RES
1144; The pesudo-instruction used to declare (=reserve space for) an uninitialized
1145; host physical address variable
1146%define RTHCPHYS_RES resq
1147
1148;; @def RTHCPTR_PRE
1149; The memory operand prefix used for a host physical address.
1150%define RTHCPHYS_PRE qword
1151
1152;; @def RTHCPHYS_CB
1153; The size in bytes of a host physical address.
1154%define RTHCPHYS_CB 8
1155
1156
1157
1158;; @def RTGCPHYS_DEF
1159; The pesudo-instruction used to declare an initialized guest physical address.
1160%define RTGCPHYS_DEF dq
1161
1162;; @def RTGCPHYS_RES
1163; The pesudo-instruction used to declare (=reserve space for) an uninitialized
1164; guest physical address variable
1165%define RTGCPHYS_RES resq
1166
1167;; @def RTGCPTR_PRE
1168; The memory operand prefix used for a guest physical address.
1169%define RTGCPHYS_PRE qword
1170
1171;; @def RTGCPHYS_CB
1172; The size in bytes of a guest physical address.
1173%define RTGCPHYS_CB 8
1174
1175
1176
1177;;
1178; The size of the long double C/C++ type.
1179; On 32-bit Darwin this is 16 bytes, on L4, Linux, OS/2 and Windows
1180; it's 12 bytes.
1181; @todo figure out what 64-bit Windows does (I don't recall right now).
1182%ifdef RT_ARCH_X86
1183 %ifdef RT_OS_DARWIN
1184 %define RTLRD_CB 16
1185 %else
1186 %define RTLRD_CB 12
1187 %endif
1188%else
1189 %define RTLRD_CB 16
1190%endif
1191
1192;; @name Floating point constants along the lines of the iprt/types.h types.
1193; @note YASM does support special the __Infinity__ and __NaN__ nasm tokens.
1194; @{
1195%define RTFLOAT32U_QNAN_PLUS 0x7fc00000
1196%define RTFLOAT32U_QNAN_MINUS 0xffc00000
1197%define RTFLOAT32U_INF_PLUS 0x7f800000
1198%define RTFLOAT32U_INF_MINUS 0xff800000
1199
1200%define RTFLOAT64U_QNAN_PLUS 0x7ff8000000000000
1201%define RTFLOAT64U_QNAN_MINUS 0xfff8000000000000
1202%define RTFLOAT64U_INF_PLUS 0x7ff0000000000000
1203%define RTFLOAT64U_INF_MINUS 0xfff0000000000000
1204; @}
1205
1206
1207
1208;; @def ASM_CALL64_GCC
1209; Indicates that we're using the GCC 64-bit calling convention.
1210; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
1211
1212;; @def ASM_CALL64_MSC
1213; Indicates that we're using the Microsoft 64-bit calling convention (fastcall on steroids).
1214; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
1215
1216; Note: On X86 we're using cdecl unconditionally. There is not yet any common
1217; calling convention on AMD64, that's why we need to support two different ones.)
1218
1219%ifdef RT_ARCH_AMD64
1220 %ifndef ASM_CALL64_GCC
1221 %ifndef ASM_CALL64_MSC
1222 ; define it based on the object format.
1223 %ifdef ASM_FORMAT_PE
1224 %define ASM_CALL64_MSC
1225 %else
1226 %define ASM_CALL64_GCC
1227 %endif
1228 %endif
1229 %else
1230 ; sanity check.
1231 %ifdef ASM_CALL64_MSC
1232 %error "Only one of the ASM_CALL64_* defines should be defined!"
1233 %endif
1234 %endif
1235%else
1236 ;later; %ifdef ASM_CALL64_GCC
1237 ;later; %error "ASM_CALL64_GCC is defined without RT_ARCH_AMD64!" ASM_CALL64_GCC
1238 ;later; %endif
1239 ;later; %ifdef ASM_CALL64_MSC
1240 ;later; %error "ASM_CALL64_MSC is defined without RT_ARCH_AMD64!" ASM_CALL64_MSC
1241 ;later; %endif
1242%endif
1243
1244
1245;; @def RT_BEGINPROC
1246; Starts an IPRT procedure that should be exported unless IN_RT_STATIC is defined.
1247;
1248; @param 1 The function name. Will apply NAME macro to it.
1249%macro RT_BEGINPROC 1
1250 %ifdef IN_RT_STATIC
1251BEGINPROC %1, 0
1252 %else
1253BEGINPROC_EXPORTED %1, 0
1254 %endif
1255%endmacro ; RT_BEGINPROC
1256
1257
1258;; @def RT_NOCRT
1259; Symbol name wrapper for the No-CRT bits.
1260;
1261; In order to coexist in the same process as other CRTs, we need to
1262; decorate the symbols such that they don't conflict the ones in the
1263; other CRTs. The result of such conflicts / duplicate symbols can
1264; confuse the dynamic loader on unix like systems.
1265;
1266; @remark Always feed the name to this macro first and then pass the result
1267; on to the next *NAME* macro.
1268;
1269%ifndef RT_WITHOUT_NOCRT_WRAPPERS
1270 %define RT_NOCRT(name) nocrt_ %+ name
1271%else
1272 %define RT_NOCRT(name) name
1273%endif
1274
1275;; @def RT_NOCRT_BEGINPROC
1276; Starts a NOCRT procedure, taking care of name wrapping and aliasing.
1277;
1278; Weak aliases for regular crt (%1) names to the nocrt_ prefixed ones will be
1279; added when RT_WITH_NOCRT_ALIASES is defined and the output is ELF. If
1280; RT_WITH_GENALIAS_NOCRT_ALIASES is undefined, strong aliases will be added for
1281; for non-ELF targets, otherwise it's assumed the genalias build tool will do
1282; the weak aliasing for us.
1283;
1284%macro RT_NOCRT_BEGINPROC 1
1285 %ifdef RT_WITH_NOCRT_ALIASES
1286 %ifdef IN_RT_STATIC
1287BEGINPROC RT_NOCRT(%1), 1 ; Do our own IBT_ENDBRxx after aliasing/
1288 %else
1289BEGINPROC_EXPORTED RT_NOCRT(%1), 1 ; Do our own IBT_ENDBRxx after aliasing/
1290 %endif
1291 %ifdef ASM_FORMAT_ELF
1292 ; ELF
1293 %ifdef RT_WITH_NOCRT_UNDERSCORE_ALIASES
1294global NAME(_ %+ %1):function
1295weak NAME(_ %+ %1)
1296SAFE_LABEL NAME(_ %+ %1)
1297 %endif
1298global NAME(%1):function
1299weak NAME(%1)
1300SAFE_LABEL NAME(%1)
1301
1302 %elifndef RT_WITH_GENALIAS_NOCRT_ALIASES
1303 ; non-ELF when not using genalias.
1304 %ifdef RT_WITH_NOCRT_UNDERSCORE_ALIASES
1305GLOBALNAME _%1
1306 %endif
1307GLOBALNAME %1
1308 %endif
1309 IBT_ENDBRxx
1310 %else ; !RT_WITH_NOCRT_ALIASES
1311 %ifdef IN_RT_STATIC
1312BEGINPROC RT_NOCRT(%1), 0
1313 %else
1314BEGINPROC_EXPORTED RT_NOCRT(%1), 0
1315 %endif
1316 %endif ; !RT_WITH_NOCRT_ALIASES
1317%endmacro ; RT_NOCRT_BEGINPROC
1318
1319
1320
1321;; @def xCB
1322; The stack unit size / The register unit size.
1323
1324;; @def xSP
1325; The stack pointer register (RSP or ESP).
1326
1327;; @def xBP
1328; The base pointer register (RBP or ESP).
1329
1330;; @def xAX
1331; RAX or EAX depending on context.
1332
1333;; @def xBX
1334; RBX or EBX depending on context.
1335
1336;; @def xCX
1337; RCX or ECX depending on context.
1338
1339;; @def xDX
1340; RDX or EDX depending on context.
1341
1342;; @def xDI
1343; RDI or EDI depending on context.
1344
1345;; @def xSI
1346; RSI or ESI depending on context.
1347
1348;; @def xWrtRIP
1349; 'wrt rip' for AMD64 targets, nothing for x86 ones.
1350
1351%ifdef RT_ARCH_AMD64
1352 %define xCB 8
1353 %define xSP rsp
1354 %define xBP rbp
1355 %define xAX rax
1356 %define xBX rbx
1357 %define xCX rcx
1358 %define xDX rdx
1359 %define xDI rdi
1360 %define xSI rsi
1361 %define xWrtRIP wrt rip
1362%else
1363 %define xCB 4
1364 %define xSP esp
1365 %define xBP ebp
1366 %define xAX eax
1367 %define xBX ebx
1368 %define xCX ecx
1369 %define xDX edx
1370 %define xDI edi
1371 %define xSI esi
1372 %define xWrtRIP
1373%endif
1374
1375
1376;
1377; NASM sets __PASS__ to 0 in preprocess-only mode, and to 3 when only generating dependencies.
1378; YASM has no such setting which is why we must rely on kBuild to tell us what we're doing.
1379; For simplicity, we'll set the kBuild macro when using NASM.
1380;
1381%ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1382 %ifdef __NASM__
1383 %if __PASS__ == 0 || __PASS__ == 3
1384 %define KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1385 %endif
1386 %endif
1387%endif
1388
1389
1390;
1391; Some simple compile time assertions.
1392;
1393; Note! Requires new kBuild to work with YASM (see above).
1394;
1395
1396;;
1397; Structure size assertion macro.
1398%define AssertCompileSize(a_Type, a_Size) AssertCompileSizeML a_Type, a_Size
1399%macro AssertCompileSizeML 2
1400 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1401 %assign AssertVar_cbActual %1 %+ _size
1402 %assign AssertVar_cbExpected %2
1403 %if AssertVar_cbActual != AssertVar_cbExpected
1404 %error %1 is AssertVar_cbActual bytes instead of AssertVar_cbExpected
1405 %endif
1406 %endif
1407%endmacro
1408
1409;;
1410; Structure size alignment assertion macro.
1411
1412%define AssertCompileSizeAlignment(a_Type, a_Align) AssertCompileSizeAlignmentML a_Type, a_Align
1413%macro AssertCompileSizeAlignmentML 2
1414 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1415 %assign AssertVar_cbActual %1 %+ _size
1416 %assign AssertVar_cbAlignment %2
1417 %if (AssertVar_cbActual & (AssertVar_cbAlignment - 1)) != 0
1418 %error %1 is AssertVar_cbActual bytes, expected size with AssertVar_cbAlignment bytes alignment.
1419 %endif
1420 %endif
1421%endmacro
1422
1423;;
1424; Structure member offset assertion macro.
1425%define AssertCompileMemberOffset(a_Type, a_Member, a_off) AssertCompileMemberOffsetML a_Type, a_Member, a_off
1426%macro AssertCompileMemberOffsetML 3
1427 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1428 %assign AssertVar_offActual %1 %+ . %+ %2
1429 %assign AssertVar_offExpected %3
1430 %if AssertVar_offActual != AssertVar_offExpected
1431 %error %1 %+ . %+ %2 is at AssertVar_offActual instead of AssertVar_offExpected
1432 %endif
1433 %endif
1434%endmacro
1435
1436;;
1437; Structure member alignment assertion macro.
1438%define AssertCompileMemberAlignment(a_Type, a_Member, a_cbAlign) AssertCompileMemberAlignmentML a_Type, a_Member, a_cbAlign
1439%macro AssertCompileMemberAlignmentML 3
1440 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1441 %assign AssertVar_offActual %1 %+ . %+ %2
1442 %assign AssertVar_cbAlign %3
1443 %if AssertVar_offActual & (AssertVar_cbAlign - 1)
1444 %error %1 %+ . %+ %2 is at AssertVar_offActual, expected AssertVar_cbAlign alignment
1445 %endif
1446 %endif
1447%endmacro
1448
1449;;
1450; Generic compile time expression assertion.
1451%define AssertCompile(a_Expr) AssertCompileML { a_Expr }
1452%macro AssertCompileML 1
1453 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1454 %if (%1) != 1
1455 %assign AssertVar_uResult %1
1456 %error %1 => AssertVar_uResult
1457 %endif
1458 %endif
1459%endmacro
1460
1461%endif
1462
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette