VirtualBox

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

Last change on this file since 76553 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

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