VirtualBox

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

Last change on this file since 58803 was 58750, checked in by vboxsync, 9 years ago

iprt/asmdefs.mac,bs3kit: Added RT_ASMDEFS_INC_FIRST_FILE so I can redefine macros used by IPRT assembly code and use it in bs3kit.

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