VirtualBox

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

Last change on this file since 8464 was 8260, checked in by vboxsync, 17 years ago

rebranding

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