VirtualBox

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

Last change on this file since 33516 was 30943, checked in by vboxsync, 14 years ago

iprt/asmdefs.mac: added constants.

  • Property eol-style set to native
File size: 16.8 KB
Line 
1;; @file
2; IPRT - Global YASM/NASM macros
3;
4
5;
6; Copyright (C) 2006-2007 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; Align code, pad with INT3.
76%define ALIGNCODE(alignment) align alignment, db 0cch
77
78;;
79; Align data, pad with ZEROs.
80%define ALIGNDATA(alignment) align alignment, db 0
81
82;;
83; Align BSS, pad with ZEROs.
84%define ALIGNBSS(alignment) align alignment, resb 1
85
86;;
87; NAME_OVERLOAD can be defined by a .asm module to modify all the
88; names created using the name macros in this files.
89; This is handy when you've got some kind of template code.
90%ifndef NAME_OVERLOAD
91 %define NAME_OVERLOAD(name) name
92%endif
93
94;;
95; Mangles the given name so it can be referenced using DECLASM() in the
96; C/C++ world.
97%ifdef RT_ARCH_X86
98 %ifdef RT_OS_OS2
99 %define NAME(name) _ %+ NAME_OVERLOAD(name)
100 %endif
101 %ifdef RT_OS_WINDOWS
102 %define NAME(name) _ %+ NAME_OVERLOAD(name)
103 %endif
104%endif
105%ifdef RT_OS_DARWIN
106 %define NAME(name) _ %+ NAME_OVERLOAD(name)
107%endif
108%ifndef NAME
109 %define NAME(name) NAME_OVERLOAD(name)
110%endif
111
112;;
113; Mangles the given C name so it will _import_ the right symbol.
114%ifdef ASM_FORMAT_PE
115%define IMPNAME(name) __imp_ %+ NAME(name)
116%else
117%define IMPNAME(name) NAME(name)
118%endif
119
120;;
121; Gets the pointer to an imported object.
122%ifdef ASM_FORMAT_PE
123 %ifdef RT_ARCH_AMD64
124 %define IMP(name) qword [IMPNAME(name) wrt rip]
125 %else
126 %define IMP(name) dword [IMPNAME(name)]
127 %endif
128%else
129 %define IMP(name) IMPNAME(name)
130%endif
131
132
133
134;;
135; Global marker which is DECLASM() compatible.
136%macro GLOBALNAME 1,
137%ifndef ASM_FORMAT_BIN
138global NAME(%1)
139%endif
140NAME(%1):
141%endmacro
142
143;;
144; Global exported marker which is DECLASM() compatible.
145%macro EXPORTEDNAME 1,
146 %ifdef ASM_FORMAT_PE
147 export %1=NAME(%1)
148 %endif
149 %ifdef __NASM__
150 %ifdef ASM_FORMAT_OMF
151 export NAME(%1) NAME(%1)
152 %endif
153%endif
154GLOBALNAME %1
155%endmacro
156
157;;
158; Begins a C callable procedure.
159%macro BEGINPROC 1
160GLOBALNAME %1
161%endmacro
162
163;;
164; Begins a C callable exported procedure.
165%macro BEGINPROC_EXPORTED 1
166EXPORTEDNAME %1
167%endmacro
168
169;;
170; Ends a C callable procedure.
171%macro ENDPROC 1
172GLOBALNAME %1_EndProc
173 db 0xCC, 0xCC, 0xCC, 0xCC
174%endmacro
175
176
177;
178; Do OMF and Mach-O/Yasm segment definitions
179;
180; Both format requires this to get the segment order right, in the Mach-O/Yasm case
181; it's only to make sure the .bss section ends up last (it's not declared here).
182;
183%ifdef ASM_FORMAT_OMF
184
185 ; 16-bit segments first (OMF / OS/2 specific).
186 %ifdef RT_INCL_16BIT_SEGMENTS
187 segment DATA16 public CLASS=FAR_DATA align=16 use16
188 segment DATA16_INIT public CLASS=FAR_DATA align=16 use16
189 group DGROUP16 DATA16 DATA16_INIT
190
191 ;;
192 ; Begins 16-bit data
193 %macro BEGINDATA16 0
194 segment DATA16
195 %endmacro
196
197 ;;
198 ; Begins 16-bit init data
199 %macro BEGINDATA16INIT 0
200 segment DATA16_INIT
201 %endmacro
202
203 segment CODE16 public CLASS=FAR_CODE align=16 use16
204 segment CODE16_INIT public CLASS=FAR_CODE align=16 use16
205 group CGROUP16 CODE16 CODE16_INIT
206
207 ;;
208 ; Begins 16-bit code
209 %macro BEGINCODE16 0
210 segment CODE16
211 %endmacro
212
213 ;;
214 ; Begins 16-bit init code
215 %macro BEGINCODE16INIT 0
216 segment CODE16_INIT
217 %endmacro
218
219 %endif
220
221 ; 32-bit segments.
222 segment TEXT32 public CLASS=CODE align=16 use32 flat
223 segment DATA32 public CLASS=DATA align=16 use32 flat
224 segment BSS32 public CLASS=BSS align=16 use32 flat
225
226 ; Make the TEXT32 segment default.
227 segment TEXT32
228%endif
229
230%ifdef ASM_FORMAT_MACHO
231 %ifdef __YASM__
232 [section .text]
233 [section .data]
234 %endif
235%endif
236
237
238;;
239; Begins code
240%ifdef ASM_FORMAT_OMF
241 %macro BEGINCODE 0
242 segment TEXT32
243 %endmacro
244%else
245%macro BEGINCODE 0
246[section .text]
247%endmacro
248%endif
249
250;;
251; Begins constant (read-only) data
252;
253; @remarks This is mapped to the CODE section/segment when there isn't
254; any dedicated const section/segment. (There is code that
255; assumes this, so don't try change it.)
256%ifdef ASM_FORMAT_OMF
257 %macro BEGINCONST 0
258 segment TEXT32
259 %endmacro
260%else
261 %macro BEGINCONST 0
262 %ifdef ASM_FORMAT_MACHO ;; @todo check the other guys too.
263 [section .rodata]
264 %else
265 [section .text]
266 %endif
267 %endmacro
268%endif
269
270;;
271; Begins initialized data
272%ifdef ASM_FORMAT_OMF
273 %macro BEGINDATA 0
274 segment DATA32
275 %endmacro
276%else
277%macro BEGINDATA 0
278[section .data]
279%endmacro
280%endif
281
282;;
283; Begins uninitialized data
284%ifdef ASM_FORMAT_OMF
285 %macro BEGINBSS 0
286 segment BSS32
287 %endmacro
288%else
289%macro BEGINBSS 0
290[section .bss]
291%endmacro
292%endif
293
294
295
296;; @def ARCH_BITS
297; Defines the bit count of the current context.
298%ifndef ARCH_BITS
299 %ifdef RT_ARCH_AMD64
300 %define ARCH_BITS 64
301 %else
302 %define ARCH_BITS 32
303 %endif
304%endif
305
306;; @def HC_ARCH_BITS
307; Defines the host architechture bit count.
308%ifndef HC_ARCH_BITS
309 %ifndef IN_RC
310 %define HC_ARCH_BITS ARCH_BITS
311 %else
312 %define HC_ARCH_BITS 32
313 %endif
314%endif
315
316;; @def R3_ARCH_BITS
317; Defines the host ring-3 architechture bit count.
318%ifndef R3_ARCH_BITS
319 %ifdef IN_RING3
320 %define R3_ARCH_BITS ARCH_BITS
321 %else
322 %define R3_ARCH_BITS HC_ARCH_BITS
323 %endif
324%endif
325
326;; @def R0_ARCH_BITS
327; Defines the host ring-0 architechture bit count.
328%ifndef R0_ARCH_BITS
329 %ifdef IN_RING0
330 %define R0_ARCH_BITS ARCH_BITS
331 %else
332 %define R0_ARCH_BITS HC_ARCH_BITS
333 %endif
334%endif
335
336;; @def GC_ARCH_BITS
337; Defines the guest architechture bit count.
338%ifndef GC_ARCH_BITS
339 %ifdef IN_RC
340 %define GC_ARCH_BITS ARCH_BITS
341 %else
342 %define GC_ARCH_BITS 32
343 %endif
344%endif
345
346
347
348;; @def RTHCPTR_DEF
349; The pesudo-instruction used to declare an initialized pointer variable in the host context.
350%if HC_ARCH_BITS == 64
351 %define RTHCPTR_DEF dq
352%else
353 %define RTHCPTR_DEF dd
354%endif
355
356;; @def RTHCPTR_RES
357; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
358; variable of the host context.
359%if HC_ARCH_BITS == 64
360 %define RTHCPTR_RES resq
361%else
362 %define RTHCPTR_RES resd
363%endif
364
365;; @def RTHCPTR_PRE
366; The memory operand prefix used for a pointer in the host context.
367%if HC_ARCH_BITS == 64
368 %define RTHCPTR_PRE qword
369%else
370 %define RTHCPTR_PRE dword
371%endif
372
373;; @def RTHCPTR_CB
374; The size in bytes of a pointer in the host context.
375%if HC_ARCH_BITS == 64
376 %define RTHCPTR_CB 8
377%else
378 %define RTHCPTR_CB 4
379%endif
380
381
382
383;; @def RTR0PTR_DEF
384; The pesudo-instruction used to declare an initialized pointer variable in the ring-0 host context.
385%if R0_ARCH_BITS == 64
386 %define RTR0PTR_DEF dq
387%else
388 %define RTR0PTR_DEF dd
389%endif
390
391;; @def RTR0PTR_RES
392; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
393; variable of the ring-0 host context.
394%if R0_ARCH_BITS == 64
395 %define RTR0PTR_RES resq
396%else
397 %define RTR0PTR_RES resd
398%endif
399
400;; @def RTR0PTR_PRE
401; The memory operand prefix used for a pointer in the ring-0 host context.
402%if R0_ARCH_BITS == 64
403 %define RTR0PTR_PRE qword
404%else
405 %define RTR0PTR_PRE dword
406%endif
407
408;; @def RTR0PTR_CB
409; The size in bytes of a pointer in the ring-0 host context.
410%if R0_ARCH_BITS == 64
411 %define RTR0PTR_CB 8
412%else
413 %define RTR0PTR_CB 4
414%endif
415
416
417
418;; @def RTR3PTR_DEF
419; The pesudo-instruction used to declare an initialized pointer variable in the ring-3 host context.
420%if R3_ARCH_BITS == 64
421 %define RTR3PTR_DEF dq
422%else
423 %define RTR3PTR_DEF dd
424%endif
425
426;; @def RTR3PTR_RES
427; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
428; variable of the ring-3 host context.
429%if R3_ARCH_BITS == 64
430 %define RTR3PTR_RES resq
431%else
432 %define RTR3PTR_RES resd
433%endif
434
435;; @def RTR3PTR_PRE
436; The memory operand prefix used for a pointer in the ring-3 host context.
437%if R3_ARCH_BITS == 64
438 %define RTR3PTR_PRE qword
439%else
440 %define RTR3PTR_PRE dword
441%endif
442
443;; @def RTR3PTR_CB
444; The size in bytes of a pointer in the ring-3 host context.
445%if R3_ARCH_BITS == 64
446 %define RTR3PTR_CB 8
447%else
448 %define RTR3PTR_CB 4
449%endif
450
451
452
453;; @def RTGCPTR_DEF
454; The pesudo-instruction used to declare an initialized pointer variable in the guest context.
455%if GC_ARCH_BITS == 64
456 %define RTGCPTR_DEF dq
457%else
458 %define RTGCPTR_DEF dd
459%endif
460
461;; @def RTGCPTR_RES
462; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
463; variable of the guest context.
464%if GC_ARCH_BITS == 64
465 %define RTGCPTR_RES resq
466%else
467 %define RTGCPTR_RES resd
468%endif
469
470%define RTGCPTR32_RES resd
471%define RTGCPTR64_RES resq
472
473;; @def RTGCPTR_PRE
474; The memory operand prefix used for a pointer in the guest context.
475%if GC_ARCH_BITS == 64
476 %define RTGCPTR_PRE qword
477%else
478 %define RTGCPTR_PRE dword
479%endif
480
481;; @def RTGCPTR_CB
482; The size in bytes of a pointer in the guest context.
483%if GC_ARCH_BITS == 64
484 %define RTGCPTR_CB 8
485%else
486 %define RTGCPTR_CB 4
487%endif
488
489
490;; @def RTRCPTR_DEF
491; The pesudo-instruction used to declare an initialized pointer variable in the raw mode context.
492%define RTRCPTR_DEF dd
493
494;; @def RTRCPTR_RES
495; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
496; variable of the raw mode context.
497%define RTRCPTR_RES resd
498
499;; @def RTRCPTR_PRE
500; The memory operand prefix used for a pointer in the raw mode context.
501%define RTRCPTR_PRE dword
502
503;; @def RTRCPTR_CB
504; The size in bytes of a pointer in the raw mode context.
505%define RTRCPTR_CB 4
506
507
508;; @def RT_CCPTR_DEF
509; The pesudo-instruction used to declare an initialized pointer variable in the current context.
510
511;; @def RT_CCPTR_RES
512; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
513; variable of the current context.
514
515;; @def RT_CCPTR_PRE
516; The memory operand prefix used for a pointer in the current context.
517
518;; @def RT_CCPTR_CB
519; The size in bytes of a pointer in the current context.
520
521%ifdef IN_RC
522 %define RTCCPTR_DEF RTRCPTR_DEF
523 %define RTCCPTR_RES RTRCPTR_RES
524 %define RTCCPTR_PRE RTRCPTR_PRE
525 %define RTCCPTR_CB RTRCPTR_CB
526%else
527 %ifdef IN_RING0
528 %define RTCCPTR_DEF RTR0PTR_DEF
529 %define RTCCPTR_RES RTR0PTR_RES
530 %define RTCCPTR_PRE RTR0PTR_PRE
531 %define RTCCPTR_CB RTR0PTR_CB
532 %else
533 %define RTCCPTR_DEF RTR3PTR_DEF
534 %define RTCCPTR_RES RTR3PTR_RES
535 %define RTCCPTR_PRE RTR3PTR_PRE
536 %define RTCCPTR_CB RTR3PTR_CB
537 %endif
538%endif
539
540
541
542;; @def RTHCPHYS_DEF
543; The pesudo-instruction used to declare an initialized host physical address.
544%define RTHCPHYS_DEF dq
545
546;; @def RTHCPTR_RES
547; The pesudo-instruction used to declare (=reserve space for) an uninitialized
548; host physical address variable
549%define RTHCPHYS_RES resq
550
551;; @def RTHCPTR_PRE
552; The memory operand prefix used for a host physical address.
553%define RTHCPHYS_PRE qword
554
555;; @def RTHCPHYS_CB
556; The size in bytes of a host physical address.
557%define RTHCPHYS_CB 8
558
559
560
561;; @def RTGCPHYS_DEF
562; The pesudo-instruction used to declare an initialized guest physical address.
563%define RTGCPHYS_DEF dq
564
565;; @def RTGCPHYS_RES
566; The pesudo-instruction used to declare (=reserve space for) an uninitialized
567; guest physical address variable
568%define RTGCPHYS_RES resq
569
570;; @def RTGCPTR_PRE
571; The memory operand prefix used for a guest physical address.
572%define RTGCPHYS_PRE qword
573
574;; @def RTGCPHYS_CB
575; The size in bytes of a guest physical address.
576%define RTGCPHYS_CB 8
577
578
579
580;;
581; The size of the long double C/C++ type.
582; On 32-bit Darwin this is 16 bytes, on L4, Linux, OS/2 and Windows
583; it's 12 bytes.
584; @todo figure out what 64-bit Windows does (I don't recall right now).
585%ifdef RT_ARCH_X86
586 %ifdef RT_OS_DARWIN
587 %define RTLRD_CB 16
588 %else
589 %define RTLRD_CB 12
590 %endif
591%else
592 %define RTLRD_CB 16
593%endif
594
595
596
597;; @def ASM_CALL64_GCC
598; Indicates that we're using the GCC 64-bit calling convention.
599; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
600
601;; @def ASM_CALL64_MSC
602; Indicates that we're using the Microsoft 64-bit calling convention (fastcall on steroids).
603; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
604
605; Note: On X86 we're using cdecl unconditionally. There is not yet any common
606; calling convention on AMD64, that's why we need to support two different ones.)
607
608%ifdef RT_ARCH_AMD64
609 %ifndef ASM_CALL64_GCC
610 %ifndef ASM_CALL64_MSC
611 ; define it based on the object format.
612 %ifdef ASM_FORMAT_PE
613 %define ASM_CALL64_MSC
614 %else
615 %define ASM_CALL64_GCC
616 %endif
617 %endif
618 %else
619 ; sanity check.
620 %ifdef ASM_CALL64_MSC
621 %error "Only one of the ASM_CALL64_* defines should be defined!"
622 %endif
623 %endif
624%endif
625
626
627;; @def RT_NOCRT
628; Symbol name wrapper for the No-CRT bits.
629;
630; In order to coexist in the same process as other CRTs, we need to
631; decorate the symbols such that they don't conflict the ones in the
632; other CRTs. The result of such conflicts / duplicate symbols can
633; confuse the dynamic loader on unix like systems.
634;
635; @remark Always feed the name to this macro first and then pass the result
636; on to the next *NAME* macro.
637;
638%ifndef RT_WITHOUT_NOCRT_WRAPPERS
639 %define RT_NOCRT(name) nocrt_ %+ name
640%else
641 %define RT_NOCRT(name) name
642%endif
643
644;; @def RT_NOCRT_BEGINPROC
645; Starts a NOCRT procedure, taking care of name wrapping and aliasing.
646;
647; Aliasing (weak ones, if supported) will be created when RT_WITH_NOCRT_ALIASES
648; is defined and RT_WITHOUT_NOCRT_WRAPPERS isn't.
649;
650%macro RT_NOCRT_BEGINPROC 1
651%ifdef RT_WITH_NOCRT_ALIASES
652BEGINPROC RT_NOCRT(%1)
653%ifdef ASM_FORMAT_ELF
654global NAME(%1)
655weak NAME(%1)
656NAME(%1):
657%else
658GLOBALNAME %1
659%endif
660%else ; !RT_WITH_NOCRT_ALIASES
661BEGINPROC RT_NOCRT(%1)
662%endif ; !RT_WITH_NOCRT_ALIASES
663%endmacro ; RT_NOCRT_BEGINPROC
664
665%ifdef RT_WITH_NOCRT_ALIASES
666 %ifdef RT_WITHOUT_NOCRT_WRAPPERS
667 %error "RT_WITH_NOCRT_ALIASES and RT_WITHOUT_NOCRT_WRAPPERS doesn't mix."
668 %endif
669%endif
670
671
672
673;; @def xS
674; The stack unit size / The register unit size.
675
676;; @def xSP
677; The stack pointer register (RSP or ESP).
678
679;; @def xBP
680; The base pointer register (RBP or ESP).
681
682;; @def xAX
683; RAX or EAX depending on context.
684
685;; @def xBX
686; RBX or EBX depending on context.
687
688;; @def xCX
689; RCX or ECX depending on context.
690
691;; @def xDX
692; RDX or EDX depending on context.
693
694;; @def xDI
695; RDI or EDI depending on context.
696
697;; @def xSI
698; RSI or ESI depending on context.
699
700;; @def xWrtRIP
701; 'wrt rip' for AMD64 targets, nothing for x86 ones.
702
703%ifdef RT_ARCH_AMD64
704 %define xS 8
705 %define xSP rsp
706 %define xBP rbp
707 %define xAX rax
708 %define xBX rbx
709 %define xCX rcx
710 %define xDX rdx
711 %define xDI rdi
712 %define xSI rsi
713 %define xWrtRIP wrt rip
714%else
715 %define xS 4
716 %define xSP esp
717 %define xBP ebp
718 %define xAX eax
719 %define xBX ebx
720 %define xCX ecx
721 %define xDX edx
722 %define xDI edi
723 %define xSI esi
724 %define xWrtRIP
725%endif
726
727%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