VirtualBox

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

Last change on this file since 4919 was 4256, checked in by vboxsync, 17 years ago

CR/LF

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