VirtualBox

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

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

iprt/asmdefs.mac: Introduced RT_NOINC_SEGMENTS to avoid unncessary segments in the BS3Kit stuff.

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