VirtualBox

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

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

iprt/asmdefs.mac: Added RT_BIT_32 macro.

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