VirtualBox

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

Last change on this file since 54712 was 54690, checked in by vboxsync, 10 years ago

asmdefs.mac: RT_CONCAT* macros.

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