VirtualBox

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

Last change on this file since 73460 was 69495, checked in by vboxsync, 7 years ago

include: scm updates (year)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.5 KB
Line 
1;; @file
2; IPRT - Global YASM/NASM macros
3;
4
5;
6; Copyright (C) 2006-2017 Oracle Corporation
7;
8; This file is part of VirtualBox Open Source Edition (OSE), as
9; available from http://www.virtualbox.org. This file is free software;
10; you can redistribute it and/or modify it under the terms of the GNU
11; General Public License (GPL) as published by the Free Software
12; Foundation, in version 2 as it comes in the "COPYING" file of the
13; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15;
16; The contents of this file may alternatively be used under the terms
17; of the Common Development and Distribution License Version 1.0
18; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19; VirtualBox OSE distribution, in which case the provisions of the
20; CDDL are applicable instead of those of the GPL.
21;
22; You may elect to license modified versions of this file under the
23; terms and conditions of either the GPL or the CDDL or both.
24;
25
26; Special hack for bs3kit.
27%ifdef RT_ASMDEFS_INC_FIRST_FILE
28 %include "asmdefs-first.mac"
29%endif
30
31%ifndef ___iprt_asmdefs_mac
32%define ___iprt_asmdefs_mac
33
34
35;; @defgroup grp_rt_cdefs_size Size Constants
36; (Of course, these are binary computer terms, not SI.)
37; @{
38;; 1 K (Kilo) (1 024).
39%define _1K 000000400h
40;; 4 K (Kilo) (4 096).
41%define _4K 000001000h
42;; 8 K (Kilo) (8 192).
43%define _8K 000002000h
44;; 16 K (Kilo) (16 384).
45%define _16K 000004000h
46;; 32 K (Kilo) (32 768).
47%define _32K 000008000h
48;; 64 K (Kilo) (65 536).
49%define _64K 000010000h
50;; 128 K (Kilo) (131 072).
51%define _128K 000020000h
52;; 256 K (Kilo) (262 144).
53%define _256K 000040000h
54;; 512 K (Kilo) (524 288).
55%define _512K 000080000h
56;; 1 M (Mega) (1 048 576).
57%define _1M 000100000h
58;; 2 M (Mega) (2 097 152).
59%define _2M 000200000h
60;; 4 M (Mega) (4 194 304).
61%define _4M 000400000h
62;; 1 G (Giga) (1 073 741 824).
63%define _1G 040000000h
64;; 2 G (Giga) (2 147 483 648).
65%define _2G 00000000080000000h
66;; 4 G (Giga) (4 294 967 296).
67%define _4G 00000000100000000h
68;; 1 T (Tera) (1 099 511 627 776).
69%define _1T 00000010000000000h
70;; 1 P (Peta) (1 125 899 906 842 624).
71%define _1P 00004000000000000h
72;; 1 E (Exa) (1 152 921 504 606 846 976).
73%define _1E 01000000000000000h
74;; 2 E (Exa) (2 305 843 009 213 693 952).
75%define _2E 02000000000000000h
76;; @}
77
78
79;;
80; Make the mask for the given bit.
81%define RT_BIT(bit) (1 << bit)
82
83;;
84; Make the mask for the given bit.
85%define RT_BIT_32(bit) (1 << bit)
86;;
87; Make the mask for the given bit.
88%define RT_BIT_64(bit) (1 << bit)
89
90;;
91; Makes a 32-bit unsigned (not type safe, but whatever) out of four byte values.
92%define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) ( (b3 << 24) | (b2 << 16) | (b1 << 8) | b0 )
93
94;; Preprocessor concatenation macro.
95%define RT_CONCAT(a_1,a_2) a_1 %+ a_2
96
97;; Preprocessor concatenation macro, three arguments.
98%define RT_CONCAT3(a_1,a_2,a_3) a_1 %+ a_2 %+ a_3
99
100;; Preprocessor concatenation macro, four arguments.
101%define RT_CONCAT4(a_1,a_2,a_3,a_4) a_1 %+ a_2 %+ a_3 %+ a_4
102
103
104;; Define ASM_FORMAT_PE64 if applicable.
105%ifdef ASM_FORMAT_PE
106 %ifdef RT_ARCH_AMD64
107 %define ASM_FORMAT_PE64 1
108 %endif
109%endif
110
111;;
112; SEH64 macros.
113%ifdef RT_ASM_WITH_SEH64
114 %ifndef ASM_FORMAT_PE64
115 %undef RT_ASM_WITH_SEH64
116 %endif
117%endif
118
119;;
120; Records a xBP push.
121%macro SEH64_PUSH_xBP 0
122 %ifdef RT_ASM_WITH_SEH64
123 [pushreg rbp]
124 %endif
125%endmacro
126
127;;
128; Sets xBP as frame pointer that's pointing to a stack position %1 relative to xBP.
129%macro SEH64_SET_FRAME_xBP 1
130 %ifdef RT_ASM_WITH_SEH64
131 [setframe rbp, %1]
132 %endif
133%endmacro
134
135;;
136; Records an ADD xSP, %1.
137%macro SEH64_ALLOCATE_STACK 1
138 %ifdef RT_ASM_WITH_SEH64
139 [allocstack %1]
140 %endif
141%endmacro
142
143;;
144; Ends the prologue.
145%macro SEH64_END_PROLOGUE 0
146 %ifdef RT_ASM_WITH_SEH64
147 [endprolog]
148 %endif
149%endmacro
150
151
152;;
153; Align code, pad with INT3.
154%define ALIGNCODE(alignment) align alignment, db 0cch
155
156;;
157; Align data, pad with ZEROs.
158%define ALIGNDATA(alignment) align alignment, db 0
159
160;;
161; Align BSS, pad with ZEROs.
162%define ALIGNBSS(alignment) align alignment, resb 1
163
164;;
165; NAME_OVERLOAD can be defined by a .asm module to modify all the
166; names created using the name macros in this files.
167; This is handy when you've got some kind of template code.
168%ifndef NAME_OVERLOAD
169 %define NAME_OVERLOAD(name) name
170%endif
171
172;;
173; Mangles the given name so it can be referenced using DECLASM() in the
174; C/C++ world.
175%ifndef ASM_FORMAT_BIN
176 %ifdef RT_ARCH_X86
177 %ifdef RT_OS_OS2
178 %define NAME(name) _ %+ NAME_OVERLOAD(name)
179 %endif
180 %ifdef RT_OS_WINDOWS
181 %define NAME(name) _ %+ NAME_OVERLOAD(name)
182 %endif
183 %endif
184 %ifdef RT_OS_DARWIN
185 %define NAME(name) _ %+ NAME_OVERLOAD(name)
186 %endif
187%endif
188%ifndef NAME
189 %define NAME(name) NAME_OVERLOAD(name)
190%endif
191
192;;
193; Mangles the given C name so it will _import_ the right symbol.
194%ifdef ASM_FORMAT_PE
195 %define IMPNAME(name) __imp_ %+ NAME(name)
196%else
197 %define IMPNAME(name) NAME(name)
198%endif
199
200;;
201; Gets the pointer to an imported object.
202%ifdef ASM_FORMAT_PE
203 %ifdef RT_ARCH_AMD64
204 %define IMP(name) qword [IMPNAME(name) wrt rip]
205 %else
206 %define IMP(name) dword [IMPNAME(name)]
207 %endif
208%else
209 %define IMP(name) IMPNAME(name)
210%endif
211
212;;
213; Gets the pointer to an imported object.
214%ifdef ASM_FORMAT_PE
215 %ifdef RT_ARCH_AMD64
216 %define IMP_SEG(SegOverride, name) qword [SegOverride:IMPNAME(name) wrt rip]
217 %else
218 %define IMP_SEG(SegOverride, name) dword [SegOverride:IMPNAME(name)]
219 %endif
220%else
221 %define IMP_SEG(SegOverride, name) IMPNAME(name)
222%endif
223
224;;
225; Declares an imported object for use with IMP2.
226; @note May change the current section!
227%macro EXTERN_IMP2 1
228 extern IMPNAME(%1)
229 BEGINDATA
230 %ifdef ASM_FORMAT_MACHO
231 g_Imp2_ %+ %1: RTCCPTR_DEF IMPNAME(%1)
232 %endif
233%endmacro
234
235;;
236; Gets the pointer to an imported object, version 2.
237%ifdef ASM_FORMAT_PE
238 %ifdef RT_ARCH_AMD64
239 %define IMP2(name) qword [IMPNAME(name) wrt rip]
240 %else
241 %define IMP2(name) dword [IMPNAME(name)]
242 %endif
243%elifdef ASM_FORMAT_ELF
244 %ifdef PIC
245 %ifdef RT_ARCH_AMD64
246 %define IMP2(name) qword [rel IMPNAME(name) wrt ..got]
247 %else
248 %define IMP2(name) IMPNAME(name) wrt ..plt
249 %endif
250 %endif
251%elifdef ASM_FORMAT_MACHO
252 %define IMP2(name) RTCCPTR_PRE [g_Imp2_ %+ name xWrtRIP]
253%endif
254%ifndef IMP2
255 %define IMP2(name) IMPNAME(name)
256%endif
257
258
259
260;;
261; Global marker which is DECLASM() compatible.
262%macro GLOBALNAME 1
263%ifndef ASM_FORMAT_BIN
264global NAME(%1)
265%endif
266NAME(%1):
267%endmacro
268
269;;
270; Global exported marker which is DECLASM() compatible.
271%macro EXPORTEDNAME 1
272 %ifdef ASM_FORMAT_PE
273 export %1=NAME(%1)
274 %endif
275 %ifdef __NASM__
276 %ifdef ASM_FORMAT_OMF
277 export NAME(%1) NAME(%1)
278 %endif
279%endif
280GLOBALNAME %1
281%endmacro
282
283;;
284; Global marker which is DECLASM() compatible.
285%macro GLOBALNAME_EX 2
286%ifndef ASM_FORMAT_BIN
287 %ifdef ASM_FORMAT_ELF
288global NAME(%1):%2
289 %else
290global NAME(%1)
291 %endif
292%endif
293NAME(%1):
294%endmacro
295
296;;
297; Global exported marker which is DECLASM() compatible.
298%macro EXPORTEDNAME_EX 2
299 %ifdef ASM_FORMAT_PE
300 export %1=NAME(%1)
301 %endif
302 %ifdef __NASM__
303 %ifdef ASM_FORMAT_OMF
304 export NAME(%1) NAME(%1)
305 %endif
306%endif
307GLOBALNAME_EX %1, %2
308%endmacro
309
310;;
311; Begins a C callable procedure.
312%macro BEGINPROC 1
313 %ifdef RT_ASM_WITH_SEH64
314global NAME(%1):function
315proc_frame NAME(%1)
316 %else
317GLOBALNAME_EX %1, function hidden
318 %endif
319%endmacro
320
321;;
322; Begins a C callable exported procedure.
323%macro BEGINPROC_EXPORTED 1
324 %ifdef RT_ASM_WITH_SEH64
325 %ifdef ASM_FORMAT_PE
326export %1=NAME(%1)
327 %endif
328global NAME(%1):function
329proc_frame NAME(%1)
330 %else
331EXPORTEDNAME_EX %1, function
332 %endif
333%endmacro
334
335;;
336; Ends a C callable procedure.
337%macro ENDPROC 1
338 %ifdef RT_ASM_WITH_SEH64
339endproc_frame
340 %endif
341GLOBALNAME_EX %1 %+ _EndProc, function hidden
342%ifdef ASM_FORMAT_ELF
343 %ifndef __NASM__ ; nasm does this in the global directive.
344size NAME(%1) NAME(%1 %+ _EndProc) - NAME(%1)
345size NAME(%1 %+ _EndProc) 0
346 %endif
347%endif
348 db 0xCC, 0xCC, 0xCC, 0xCC
349%endmacro
350
351
352;
353; Do OMF and Mach-O/Yasm segment definitions
354;
355; Both format requires this to get the segment order right, in the Mach-O/Yasm case
356; it's only to make sure the .bss section ends up last (it's not declared here).
357;
358%ifdef ASM_FORMAT_OMF
359 %ifndef RT_NOINC_SEGMENTS
360
361 ; 16-bit segments first (OMF / OS/2 specific).
362 %ifdef RT_INCL_16BIT_SEGMENTS
363 segment DATA16 public CLASS=FAR_DATA align=16 use16
364 segment DATA16_INIT public CLASS=FAR_DATA align=16 use16
365 group DGROUP16 DATA16 DATA16_INIT
366
367 ;;
368 ; Begins 16-bit data
369 %macro BEGINDATA16 0
370 segment DATA16
371 %endmacro
372
373 ;;
374 ; Begins 16-bit init data
375 %macro BEGINDATA16INIT 0
376 segment DATA16_INIT
377 %endmacro
378
379 segment CODE16 public CLASS=FAR_CODE align=16 use16
380 segment CODE16_INIT public CLASS=FAR_CODE align=16 use16
381 group CGROUP16 CODE16 CODE16_INIT
382
383 ;;
384 ; Begins 16-bit code
385 %macro BEGINCODE16 0
386 segment CODE16
387 %endmacro
388
389 ;;
390 ; Begins 16-bit init code
391 %macro BEGINCODE16INIT 0
392 segment CODE16_INIT
393 %endmacro
394
395 %endif
396
397 ; 32-bit segments.
398 segment TEXT32 public CLASS=CODE align=16 use32 flat
399 segment DATA32 public CLASS=DATA align=16 use32 flat
400 segment BSS32 public CLASS=BSS align=16 use32 flat
401
402 ; Make the TEXT32 segment default.
403 segment TEXT32
404 %endif ; RT_NOINC_SEGMENTS
405%endif
406
407%ifdef ASM_FORMAT_MACHO
408 %ifdef __YASM__
409 section .text
410 section .data
411 %endif
412%endif
413
414
415;;
416; Begins code
417%ifdef ASM_FORMAT_OMF
418 %macro BEGINCODE 0
419 segment TEXT32
420 %endmacro
421%else
422%macro BEGINCODE 0
423 section .text
424%endmacro
425%endif
426
427;;
428; Begins constant (read-only) data
429;
430; @remarks This is mapped to the CODE section/segment when there isn't
431; any dedicated const section/segment. (There is code that
432; assumes this, so don't try change it.)
433%ifdef ASM_FORMAT_OMF
434 %macro BEGINCONST 0
435 segment TEXT32
436 %endmacro
437%else
438 %macro BEGINCONST 0
439 %ifdef ASM_FORMAT_MACHO ;; @todo check the other guys too.
440 section .rodata
441 %else
442 section .text
443 %endif
444 %endmacro
445%endif
446
447;;
448; Begins initialized data
449%ifdef ASM_FORMAT_OMF
450 %macro BEGINDATA 0
451 segment DATA32
452 %endmacro
453%else
454%macro BEGINDATA 0
455 section .data
456%endmacro
457%endif
458
459;;
460; Begins uninitialized data
461%ifdef ASM_FORMAT_OMF
462 %macro BEGINBSS 0
463 segment BSS32
464 %endmacro
465%else
466%macro BEGINBSS 0
467 section .bss
468%endmacro
469%endif
470
471
472
473;; @def ARCH_BITS
474; Defines the bit count of the current context.
475%ifndef ARCH_BITS
476 %ifdef RT_ARCH_AMD64
477 %define ARCH_BITS 64
478 %else
479 %define ARCH_BITS 32
480 %endif
481%endif
482
483;; @def HC_ARCH_BITS
484; Defines the host architechture bit count.
485%ifndef HC_ARCH_BITS
486 %ifndef IN_RC
487 %define HC_ARCH_BITS ARCH_BITS
488 %else
489 %define HC_ARCH_BITS 32
490 %endif
491%endif
492
493;; @def R3_ARCH_BITS
494; Defines the host ring-3 architechture bit count.
495%ifndef R3_ARCH_BITS
496 %ifdef IN_RING3
497 %define R3_ARCH_BITS ARCH_BITS
498 %else
499 %define R3_ARCH_BITS HC_ARCH_BITS
500 %endif
501%endif
502
503;; @def R0_ARCH_BITS
504; Defines the host ring-0 architechture bit count.
505%ifndef R0_ARCH_BITS
506 %ifdef IN_RING0
507 %define R0_ARCH_BITS ARCH_BITS
508 %else
509 %define R0_ARCH_BITS HC_ARCH_BITS
510 %endif
511%endif
512
513;; @def GC_ARCH_BITS
514; Defines the guest architechture bit count.
515%ifndef GC_ARCH_BITS
516 %ifdef IN_RC
517 %define GC_ARCH_BITS ARCH_BITS
518 %else
519 %define GC_ARCH_BITS 32
520 %endif
521%endif
522
523
524
525;; @def RTHCPTR_DEF
526; The pesudo-instruction used to declare an initialized pointer variable in the host context.
527%if HC_ARCH_BITS == 64
528 %define RTHCPTR_DEF dq
529%else
530 %define RTHCPTR_DEF dd
531%endif
532
533;; @def RTHCPTR_RES
534; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
535; variable of the host context.
536%if HC_ARCH_BITS == 64
537 %define RTHCPTR_RES resq
538%else
539 %define RTHCPTR_RES resd
540%endif
541
542;; @def RTHCPTR_PRE
543; The memory operand prefix used for a pointer in the host context.
544%if HC_ARCH_BITS == 64
545 %define RTHCPTR_PRE qword
546%else
547 %define RTHCPTR_PRE dword
548%endif
549
550;; @def RTHCPTR_CB
551; The size in bytes of a pointer in the host context.
552%if HC_ARCH_BITS == 64
553 %define RTHCPTR_CB 8
554%else
555 %define RTHCPTR_CB 4
556%endif
557
558
559
560;; @def RTR0PTR_DEF
561; The pesudo-instruction used to declare an initialized pointer variable in the ring-0 host context.
562%if R0_ARCH_BITS == 64
563 %define RTR0PTR_DEF dq
564%else
565 %define RTR0PTR_DEF dd
566%endif
567
568;; @def RTR0PTR_RES
569; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
570; variable of the ring-0 host context.
571%if R0_ARCH_BITS == 64
572 %define RTR0PTR_RES resq
573%else
574 %define RTR0PTR_RES resd
575%endif
576
577;; @def RTR0PTR_PRE
578; The memory operand prefix used for a pointer in the ring-0 host context.
579%if R0_ARCH_BITS == 64
580 %define RTR0PTR_PRE qword
581%else
582 %define RTR0PTR_PRE dword
583%endif
584
585;; @def RTR0PTR_CB
586; The size in bytes of a pointer in the ring-0 host context.
587%if R0_ARCH_BITS == 64
588 %define RTR0PTR_CB 8
589%else
590 %define RTR0PTR_CB 4
591%endif
592
593
594
595;; @def RTR3PTR_DEF
596; The pesudo-instruction used to declare an initialized pointer variable in the ring-3 host context.
597%if R3_ARCH_BITS == 64
598 %define RTR3PTR_DEF dq
599%else
600 %define RTR3PTR_DEF dd
601%endif
602
603;; @def RTR3PTR_RES
604; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
605; variable of the ring-3 host context.
606%if R3_ARCH_BITS == 64
607 %define RTR3PTR_RES resq
608%else
609 %define RTR3PTR_RES resd
610%endif
611
612;; @def RTR3PTR_PRE
613; The memory operand prefix used for a pointer in the ring-3 host context.
614%if R3_ARCH_BITS == 64
615 %define RTR3PTR_PRE qword
616%else
617 %define RTR3PTR_PRE dword
618%endif
619
620;; @def RTR3PTR_CB
621; The size in bytes of a pointer in the ring-3 host context.
622%if R3_ARCH_BITS == 64
623 %define RTR3PTR_CB 8
624%else
625 %define RTR3PTR_CB 4
626%endif
627
628
629
630;; @def RTGCPTR_DEF
631; The pesudo-instruction used to declare an initialized pointer variable in the guest context.
632%if GC_ARCH_BITS == 64
633 %define RTGCPTR_DEF dq
634%else
635 %define RTGCPTR_DEF dd
636%endif
637
638;; @def RTGCPTR_RES
639; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
640; variable of the guest context.
641%if GC_ARCH_BITS == 64
642 %define RTGCPTR_RES resq
643%else
644 %define RTGCPTR_RES resd
645%endif
646
647%define RTGCPTR32_RES resd
648%define RTGCPTR64_RES resq
649
650;; @def RTGCPTR_PRE
651; The memory operand prefix used for a pointer in the guest context.
652%if GC_ARCH_BITS == 64
653 %define RTGCPTR_PRE qword
654%else
655 %define RTGCPTR_PRE dword
656%endif
657
658;; @def RTGCPTR_CB
659; The size in bytes of a pointer in the guest context.
660%if GC_ARCH_BITS == 64
661 %define RTGCPTR_CB 8
662%else
663 %define RTGCPTR_CB 4
664%endif
665
666
667;; @def RTRCPTR_DEF
668; The pesudo-instruction used to declare an initialized pointer variable in the raw mode context.
669%define RTRCPTR_DEF dd
670
671;; @def RTRCPTR_RES
672; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
673; variable of the raw mode context.
674%define RTRCPTR_RES resd
675
676;; @def RTRCPTR_PRE
677; The memory operand prefix used for a pointer in the raw mode context.
678%define RTRCPTR_PRE dword
679
680;; @def RTRCPTR_CB
681; The size in bytes of a pointer in the raw mode context.
682%define RTRCPTR_CB 4
683
684
685;; @def RT_CCPTR_DEF
686; The pesudo-instruction used to declare an initialized pointer variable in the current context.
687
688;; @def RT_CCPTR_RES
689; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
690; variable of the current context.
691
692;; @def RT_CCPTR_PRE
693; The memory operand prefix used for a pointer in the current context.
694
695;; @def RT_CCPTR_CB
696; The size in bytes of a pointer in the current context.
697
698%ifdef IN_RC
699 %define RTCCPTR_DEF RTRCPTR_DEF
700 %define RTCCPTR_RES RTRCPTR_RES
701 %define RTCCPTR_PRE RTRCPTR_PRE
702 %define RTCCPTR_CB RTRCPTR_CB
703%else
704 %ifdef IN_RING0
705 %define RTCCPTR_DEF RTR0PTR_DEF
706 %define RTCCPTR_RES RTR0PTR_RES
707 %define RTCCPTR_PRE RTR0PTR_PRE
708 %define RTCCPTR_CB RTR0PTR_CB
709 %else
710 %define RTCCPTR_DEF RTR3PTR_DEF
711 %define RTCCPTR_RES RTR3PTR_RES
712 %define RTCCPTR_PRE RTR3PTR_PRE
713 %define RTCCPTR_CB RTR3PTR_CB
714 %endif
715%endif
716
717
718
719;; @def RTHCPHYS_DEF
720; The pesudo-instruction used to declare an initialized host physical address.
721%define RTHCPHYS_DEF dq
722
723;; @def RTHCPTR_RES
724; The pesudo-instruction used to declare (=reserve space for) an uninitialized
725; host physical address variable
726%define RTHCPHYS_RES resq
727
728;; @def RTHCPTR_PRE
729; The memory operand prefix used for a host physical address.
730%define RTHCPHYS_PRE qword
731
732;; @def RTHCPHYS_CB
733; The size in bytes of a host physical address.
734%define RTHCPHYS_CB 8
735
736
737
738;; @def RTGCPHYS_DEF
739; The pesudo-instruction used to declare an initialized guest physical address.
740%define RTGCPHYS_DEF dq
741
742;; @def RTGCPHYS_RES
743; The pesudo-instruction used to declare (=reserve space for) an uninitialized
744; guest physical address variable
745%define RTGCPHYS_RES resq
746
747;; @def RTGCPTR_PRE
748; The memory operand prefix used for a guest physical address.
749%define RTGCPHYS_PRE qword
750
751;; @def RTGCPHYS_CB
752; The size in bytes of a guest physical address.
753%define RTGCPHYS_CB 8
754
755
756
757;;
758; The size of the long double C/C++ type.
759; On 32-bit Darwin this is 16 bytes, on L4, Linux, OS/2 and Windows
760; it's 12 bytes.
761; @todo figure out what 64-bit Windows does (I don't recall right now).
762%ifdef RT_ARCH_X86
763 %ifdef RT_OS_DARWIN
764 %define RTLRD_CB 16
765 %else
766 %define RTLRD_CB 12
767 %endif
768%else
769 %define RTLRD_CB 16
770%endif
771
772
773
774;; @def ASM_CALL64_GCC
775; Indicates that we're using the GCC 64-bit calling convention.
776; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
777
778;; @def ASM_CALL64_MSC
779; Indicates that we're using the Microsoft 64-bit calling convention (fastcall on steroids).
780; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
781
782; Note: On X86 we're using cdecl unconditionally. There is not yet any common
783; calling convention on AMD64, that's why we need to support two different ones.)
784
785%ifdef RT_ARCH_AMD64
786 %ifndef ASM_CALL64_GCC
787 %ifndef ASM_CALL64_MSC
788 ; define it based on the object format.
789 %ifdef ASM_FORMAT_PE
790 %define ASM_CALL64_MSC
791 %else
792 %define ASM_CALL64_GCC
793 %endif
794 %endif
795 %else
796 ; sanity check.
797 %ifdef ASM_CALL64_MSC
798 %error "Only one of the ASM_CALL64_* defines should be defined!"
799 %endif
800 %endif
801%else
802 ;later; %ifdef ASM_CALL64_GCC
803 ;later; %error "ASM_CALL64_GCC is defined without RT_ARCH_AMD64!" ASM_CALL64_GCC
804 ;later; %endif
805 ;later; %ifdef ASM_CALL64_MSC
806 ;later; %error "ASM_CALL64_MSC is defined without RT_ARCH_AMD64!" ASM_CALL64_MSC
807 ;later; %endif
808%endif
809
810
811;; @def RT_NOCRT
812; Symbol name wrapper for the No-CRT bits.
813;
814; In order to coexist in the same process as other CRTs, we need to
815; decorate the symbols such that they don't conflict the ones in the
816; other CRTs. The result of such conflicts / duplicate symbols can
817; confuse the dynamic loader on unix like systems.
818;
819; @remark Always feed the name to this macro first and then pass the result
820; on to the next *NAME* macro.
821;
822%ifndef RT_WITHOUT_NOCRT_WRAPPERS
823 %define RT_NOCRT(name) nocrt_ %+ name
824%else
825 %define RT_NOCRT(name) name
826%endif
827
828;; @def RT_NOCRT_BEGINPROC
829; Starts a NOCRT procedure, taking care of name wrapping and aliasing.
830;
831; Aliasing (weak ones, if supported) will be created when RT_WITH_NOCRT_ALIASES
832; is defined and RT_WITHOUT_NOCRT_WRAPPERS isn't.
833;
834%macro RT_NOCRT_BEGINPROC 1
835%ifdef RT_WITH_NOCRT_ALIASES
836BEGINPROC RT_NOCRT(%1)
837%ifdef ASM_FORMAT_ELF
838global NAME(%1)
839weak NAME(%1)
840NAME(%1):
841%else
842GLOBALNAME %1
843%endif
844%else ; !RT_WITH_NOCRT_ALIASES
845BEGINPROC RT_NOCRT(%1)
846%endif ; !RT_WITH_NOCRT_ALIASES
847%endmacro ; RT_NOCRT_BEGINPROC
848
849%ifdef RT_WITH_NOCRT_ALIASES
850 %ifdef RT_WITHOUT_NOCRT_WRAPPERS
851 %error "RT_WITH_NOCRT_ALIASES and RT_WITHOUT_NOCRT_WRAPPERS doesn't mix."
852 %endif
853%endif
854
855
856
857;; @def xCB
858; The stack unit size / The register unit size.
859
860;; @def xSP
861; The stack pointer register (RSP or ESP).
862
863;; @def xBP
864; The base pointer register (RBP or ESP).
865
866;; @def xAX
867; RAX or EAX depending on context.
868
869;; @def xBX
870; RBX or EBX depending on context.
871
872;; @def xCX
873; RCX or ECX depending on context.
874
875;; @def xDX
876; RDX or EDX depending on context.
877
878;; @def xDI
879; RDI or EDI depending on context.
880
881;; @def xSI
882; RSI or ESI depending on context.
883
884;; @def xWrtRIP
885; 'wrt rip' for AMD64 targets, nothing for x86 ones.
886
887%ifdef RT_ARCH_AMD64
888 %define xCB 8
889 %define xSP rsp
890 %define xBP rbp
891 %define xAX rax
892 %define xBX rbx
893 %define xCX rcx
894 %define xDX rdx
895 %define xDI rdi
896 %define xSI rsi
897 %define xWrtRIP wrt rip
898%else
899 %define xCB 4
900 %define xSP esp
901 %define xBP ebp
902 %define xAX eax
903 %define xBX ebx
904 %define xCX ecx
905 %define xDX edx
906 %define xDI edi
907 %define xSI esi
908 %define xWrtRIP
909%endif
910
911
912;
913; NASM sets __PASS__ to 0 in preprocess-only mode, and to 3 when only generating dependencies.
914; YASM has no such setting which is why we must rely on kBuild to tell us what we're doing.
915; For simplicity, we'll set the kBuild macro when using NASM.
916;
917%ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
918 %ifdef __NASM__
919 %if __PASS__ == 0 || __PASS__ == 3
920 %define KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
921 %endif
922 %endif
923%endif
924
925
926;
927; Some simple compile time assertions.
928;
929; Note! Requires new kBuild to work with YASM (see above).
930;
931
932;;
933; Structure size assertion macro.
934%define AssertCompileSize(a_Type, a_Size) AssertCompileSizeML a_Type, a_Size
935%macro AssertCompileSizeML 2
936 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
937 %assign AssertVar_cbActual %1 %+ _size
938 %assign AssertVar_cbExpected %2
939 %if AssertVar_cbActual != AssertVar_cbExpected
940 %error %1 is AssertVar_cbActual bytes instead of AssertVar_cbExpected
941 %endif
942 %endif
943%endmacro
944
945;;
946; Structure size alignment assertion macro.
947
948%define AssertCompileSizeAlignment(a_Type, a_Align) AssertCompileSizeAlignmentML a_Type, a_Align
949%macro AssertCompileSizeAlignmentML 2
950 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
951 %assign AssertVar_cbActual %1 %+ _size
952 %assign AssertVar_cbAlignment %2
953 %if (AssertVar_cbActual & (AssertVar_cbAlignment - 1)) != 0
954 %error %1 is AssertVar_cbActual bytes, expected size with AssertVar_cbAlignment bytes alignment.
955 %endif
956 %endif
957%endmacro
958
959;;
960; Structure member offset assertion macro.
961%define AssertCompileMemberOffset(a_Type, a_Member, a_off) AssertCompileMemberOffsetML a_Type, a_Member, a_off
962%macro AssertCompileMemberOffsetML 3
963 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
964 %assign AssertVar_offActual %1 %+ . %+ %2
965 %assign AssertVar_offExpected %3
966 %if AssertVar_offActual != AssertVar_offExpected
967 %error %1 %+ . %+ %2 is at AssertVar_offActual instead of AssertVar_offExpected
968 %endif
969 %endif
970%endmacro
971
972;;
973; Structure member alignment assertion macro.
974%define AssertCompileMemberAlignment(a_Type, a_Member, a_cbAlign) AssertCompileMemberAlignmentML a_Type, a_Member, a_cbAlign
975%macro AssertCompileMemberAlignmentML 3
976 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
977 %assign AssertVar_offActual %1 %+ . %+ %2
978 %assign AssertVar_cbAlign %3
979 %if AssertVar_offActual & (AssertVar_cbAlign - 1)
980 %error %1 %+ . %+ %2 is at AssertVar_offActual, expected AssertVar_cbAlign alignment
981 %endif
982 %endif
983%endmacro
984
985;;
986; Generic compile time expression assertion.
987%define AssertCompile(a_Expr) AssertCompileML { a_Expr }
988%macro AssertCompileML 1
989 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
990 %if (%1) != 1
991 %assign AssertVar_uResult %1
992 %error %1 => AssertVar_uResult
993 %endif
994 %endif
995%endmacro
996
997%endif
998
Note: See TracBrowser for help on using the repository browser.

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