VirtualBox

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

Last change on this file since 54924 was 54763, checked in by vboxsync, 10 years ago

PATM,CPUM: Redid the CPUID stuff by calling a patch helper function implemented by CPUM. This eliminates needing to expose CPUM guts to in patches that gets saved. Also reimplemented the lookup as a binary search (for the leaf, not sub-leaf).

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