VirtualBox

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

Last change on this file since 5974 was 5690, checked in by vboxsync, 17 years ago

BEGINCONST - defaults to text (BEGINCODE) on most platforms, be warned.

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