VirtualBox

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

Last change on this file since 87835 was 87739, checked in by vboxsync, 4 years ago

SUP/Makefile-wrapper.gmk,iprt/asmdefs.mac: Call objtool on our .r0 object when ORCs are roaming freely accross our Linux kernel. Otherwise we won't get any callstacks. bugref:9937

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.0 KB
Line 
1;; @file
2; IPRT - Global YASM/NASM macros
3;
4
5;
6; Copyright (C) 2006-2020 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; Special hack for bs3kit.
27%ifdef RT_ASMDEFS_INC_FIRST_FILE
28 %include "asmdefs-first.mac"
29%endif
30
31%ifndef ___iprt_asmdefs_mac
32%define ___iprt_asmdefs_mac
33
34
35;; @defgroup grp_rt_cdefs_size Size Constants
36; (Of course, these are binary computer terms, not SI.)
37; @{
38;; 1 K (Kilo) (1 024).
39%define _1K 000000400h
40;; 4 K (Kilo) (4 096).
41%define _4K 000001000h
42;; 8 K (Kilo) (8 192).
43%define _8K 000002000h
44;; 16 K (Kilo) (16 384).
45%define _16K 000004000h
46;; 32 K (Kilo) (32 768).
47%define _32K 000008000h
48;; 64 K (Kilo) (65 536).
49%define _64K 000010000h
50;; 128 K (Kilo) (131 072).
51%define _128K 000020000h
52;; 256 K (Kilo) (262 144).
53%define _256K 000040000h
54;; 512 K (Kilo) (524 288).
55%define _512K 000080000h
56;; 1 M (Mega) (1 048 576).
57%define _1M 000100000h
58;; 2 M (Mega) (2 097 152).
59%define _2M 000200000h
60;; 4 M (Mega) (4 194 304).
61%define _4M 000400000h
62;; 1 G (Giga) (1 073 741 824).
63%define _1G 040000000h
64;; 2 G (Giga) (2 147 483 648).
65%define _2G 00000000080000000h
66;; 4 G (Giga) (4 294 967 296).
67%define _4G 00000000100000000h
68;; 1 T (Tera) (1 099 511 627 776).
69%define _1T 00000010000000000h
70;; 1 P (Peta) (1 125 899 906 842 624).
71%define _1P 00004000000000000h
72;; 1 E (Exa) (1 152 921 504 606 846 976).
73%define _1E 01000000000000000h
74;; 2 E (Exa) (2 305 843 009 213 693 952).
75%define _2E 02000000000000000h
76;; @}
77
78
79;;
80; Make the mask for the given bit.
81%define RT_BIT(bit) (1 << bit)
82
83;;
84; Make the mask for the given bit.
85%define RT_BIT_32(bit) (1 << bit)
86;;
87; Make the mask for the given bit.
88%define RT_BIT_64(bit) (1 << bit)
89
90;;
91; Makes a 32-bit unsigned (not type safe, but whatever) out of four byte values.
92%define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) ( (b3 << 24) | (b2 << 16) | (b1 << 8) | b0 )
93
94;; Preprocessor concatenation macro.
95%define RT_CONCAT(a_1,a_2) a_1 %+ a_2
96
97;; Preprocessor concatenation macro, three arguments.
98%define RT_CONCAT3(a_1,a_2,a_3) a_1 %+ a_2 %+ a_3
99
100;; Preprocessor concatenation macro, four arguments.
101%define RT_CONCAT4(a_1,a_2,a_3,a_4) a_1 %+ a_2 %+ a_3 %+ a_4
102
103;;
104; Trick for using RT_CONCAT and the like on %define names.
105; @param 1 The name (expression.
106; @param 2 The value.
107%macro RT_DEFINE_EX 2
108 %error 1=%1 2=%2
109 %define %1 %2
110%endmacro
111
112;;
113; Trick for using RT_CONCAT and the like on %xdefine names.
114; @param 1 The name (expression.
115; @param 2 The value.
116%macro RT_XDEFINE_EX 2
117 %xdefine %1 %2
118%endmacro
119
120;;
121; Trick for using RT_CONCAT and the like on %undef names.
122; @param 1 The name (expression.
123%macro RT_UNDEF_EX 1
124 %error 1=%1
125 %undef %1
126%endmacro
127
128
129;; Define ASM_FORMAT_PE64 if applicable.
130%ifdef ASM_FORMAT_PE
131 %ifdef RT_ARCH_AMD64
132 %define ASM_FORMAT_PE64 1
133 %endif
134%endif
135
136;;
137; SEH64 macros.
138%ifdef RT_ASM_WITH_SEH64
139 %ifndef ASM_FORMAT_PE64
140 %undef RT_ASM_WITH_SEH64
141 %endif
142%endif
143
144%ifdef RT_ASM_WITH_SEH64_ALT
145 %ifdef ASM_FORMAT_PE64
146 ;; @name Register numbers. Used with RT_CONCAT to convert macro inputs to numbers.
147 ;; @{
148 %define SEH64_PE_GREG_rax 0
149 %define SEH64_PE_GREG_xAX 0
150 %define SEH64_PE_GREG_rcx 1
151 %define SEH64_PE_GREG_xCX 1
152 %define SEH64_PE_GREG_rdx 2
153 %define SEH64_PE_GREG_xDX 2
154 %define SEH64_PE_GREG_rbx 3
155 %define SEH64_PE_GREG_xBX 3
156 %define SEH64_PE_GREG_rsp 4
157 %define SEH64_PE_GREG_xSP 4
158 %define SEH64_PE_GREG_rbp 5
159 %define SEH64_PE_GREG_xBP 5
160 %define SEH64_PE_GREG_rsi 6
161 %define SEH64_PE_GREG_xSI 6
162 %define SEH64_PE_GREG_rdi 7
163 %define SEH64_PE_GREG_xDI 7
164 %define SEH64_PE_GREG_r8 8
165 %define SEH64_PE_GREG_r9 9
166 %define SEH64_PE_GREG_r10 10
167 %define SEH64_PE_GREG_r11 11
168 %define SEH64_PE_GREG_r12 12
169 %define SEH64_PE_GREG_r13 13
170 %define SEH64_PE_GREG_r14 14
171 %define SEH64_PE_GREG_r15 15
172 ;; @}
173
174 ;; @name PE unwind operations.
175 ;; @{
176 %define SEH64_PE_PUSH_NONVOL 0
177 %define SEH64_PE_ALLOC_LARGE 1
178 %define SEH64_PE_ALLOC_SMALL 2
179 %define SEH64_PE_SET_FPREG 3
180 %define SEH64_PE_SAVE_NONVOL 4
181 %define SEH64_PE_SAVE_NONVOL_FAR 5
182 %define SEH64_PE_SAVE_XMM128 8
183 %define SEH64_PE_SAVE_XMM128_FAR 9
184 ;; @}
185
186 ;;
187 ; Starts the unwind info for the manual SEH64 info generation.
188 ; @param 1 Function name.
189 %macro SEH64_ALT_START_UNWIND_INFO 1
190 %assign seh64_idxOps 0
191 %assign seh64_FrameReg SEH64_PE_GREG_rsp
192 %assign seh64_offFrame 0
193 %define asm_seh64_proc %1
194 %undef seh64_slot_bytes
195 %endmacro
196
197 ;; We keep the unwind bytes in the seh64_slot_bytes (x)define, in reverse order as per spec.
198 %macro SEH64_APPEND_SLOT_PAIR 2
199 %ifdef seh64_slot_bytes
200 %xdefine seh64_slot_bytes %1, %2, seh64_slot_bytes
201 %else
202 %xdefine seh64_slot_bytes %1, %2
203 %endif
204 %endmacro
205
206 ;; For multi-slot unwind info.
207 %macro SEH64_APPEND_SLOT_BYTES 2+
208 %rep %0
209 %rotate -1
210 %ifdef seh64_slot_bytes
211 %xdefine seh64_slot_bytes %1, seh64_slot_bytes
212 %else
213 %xdefine seh64_slot_bytes %1
214 %endif
215 %endrep
216 %endmacro
217
218 %else
219 %undef RT_ASM_WITH_SEH64_ALT
220 %endif
221%endif
222
223;;
224; Records a xBP push.
225%macro SEH64_PUSH_xBP 0
226 %ifdef RT_ASM_WITH_SEH64
227 [pushreg rbp]
228
229 %elifdef RT_ASM_WITH_SEH64_ALT
230RT_CONCAT(.seh64_op_label_,seh64_idxOps):
231 %ifdef ASM_FORMAT_PE64
232 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
233 SEH64_PE_PUSH_NONVOL | (SEH64_PE_GREG_rbp << 4)
234 %endif
235 %assign seh64_idxOps seh64_idxOps + 1
236 %endif
237%endmacro
238
239;;
240; Records a general register push.
241; @param 1 Register name.
242%macro SEH64_PUSH_GREG 1
243 %ifdef RT_ASM_WITH_SEH64
244 [pushreg %1]
245
246 %elifdef RT_ASM_WITH_SEH64_ALT
247RT_CONCAT(.seh64_op_label_,seh64_idxOps):
248 %ifdef ASM_FORMAT_PE64
249 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
250 SEH64_PE_PUSH_NONVOL | (RT_CONCAT(SEH64_PE_GREG_,%1) << 4)
251 %endif
252 %assign seh64_idxOps seh64_idxOps + 1
253 %endif
254%endmacro
255
256;;
257; Sets xBP as frame pointer that's pointing to a stack position %1 relative to xBP.
258%macro SEH64_SET_FRAME_xBP 1
259 %ifdef RT_ASM_WITH_SEH64
260 [setframe rbp, %1]
261
262 %elifdef RT_ASM_WITH_SEH64_ALT
263RT_CONCAT(.seh64_op_label_,seh64_idxOps):
264 %ifdef ASM_FORMAT_PE64
265 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
266 SEH64_PE_SET_FPREG | 0 ; vs2019 seems to put the offset in the info field
267 %assign seh64_FrameReg SEH64_PE_GREG_rbp
268 %assign seh64_offFrame %1
269 %endif
270 %assign seh64_idxOps seh64_idxOps + 1
271 %endif
272%endmacro
273
274;;
275; Records an ADD xSP, %1.
276%macro SEH64_ALLOCATE_STACK 1
277 %ifdef RT_ASM_WITH_SEH64
278 [allocstack %1]
279
280 %elifdef RT_ASM_WITH_SEH64_ALT
281RT_CONCAT(.seh64_op_label_,seh64_idxOps):
282 %ifdef ASM_FORMAT_PE64
283 %if (%1) & 7
284 %error "SEH64_ALLOCATE_STACK must be a multiple of 8"
285 %endif
286 %if (%1) < 8
287 %error "SEH64_ALLOCATE_STACK must have an argument that's 8 or higher."
288 %elif (%1) <= 128
289 SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
290 SEH64_PE_ALLOC_SMALL | ((((%1) / 8) - 1) << 4)
291 %elif (%1) < 512
292 SEH64_APPEND_SLOT_BYTES RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
293 SEH64_PE_ALLOC_LARGE | 0, \
294 ((%1) / 8) & 0xff, ((%1) / 8) >> 8
295 %else
296 SEH64_APPEND_SLOT_BYTES RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
297 SEH64_PE_ALLOC_LARGE | 1, \
298 (%1) & 0xff, ((%1) >> 8) & 0xff, ((%1) >> 16) & 0xff, ((%1) >> 24) & 0xff
299 %endif
300 %endif
301 %assign seh64_idxOps seh64_idxOps + 1
302 %endif
303%endmacro
304
305%macro SEH64_INFO_HELPER 1
306%if defined(%1)
307 dw %1
308%endif
309%endmacro
310
311;;
312; Ends the prologue.
313%macro SEH64_END_PROLOGUE 0
314.end_of_prologue:
315 %ifdef RT_ASM_WITH_SEH64
316 [endprolog]
317
318 %elifdef RT_ASM_WITH_SEH64_ALT
319 %ifdef ASM_FORMAT_PE
320 ; Emit the unwind info now.
321 %ifndef ASM_DEFINED_XDATA_SECTION
322 %define ASM_DEFINED_XDATA_SECTION
323 section .xdata rdata align=4
324 %else
325 section .xdata
326 align 4, db 0
327 %endif
328.unwind_info:
329 db 1 ; version 1 (3 bit), no flags (5 bits)
330 db .end_of_prologue - .start_of_prologue
331
332 db (.unwind_info_array_end - .unwind_info_array) / 2
333 db seh64_FrameReg | (seh64_offFrame & 0xf0) ; framereg and offset/16.
334.unwind_info_array:
335 %ifdef seh64_slot_bytes
336 db seh64_slot_bytes
337 %undef seh64_slot_bytes
338 %endif
339.unwind_info_array_end:
340
341 ; Reset the segment
342 BEGINCODE
343 %endif
344 %endif
345%endmacro
346
347
348;;
349; Align code, pad with INT3.
350%define ALIGNCODE(alignment) align alignment, db 0cch
351
352;;
353; Align data, pad with ZEROs.
354%define ALIGNDATA(alignment) align alignment, db 0
355
356;;
357; Align BSS, pad with ZEROs.
358%define ALIGNBSS(alignment) align alignment, resb 1
359
360;;
361; NAME_OVERLOAD can be defined by a .asm module to modify all the
362; names created using the name macros in this files.
363; This is handy when you've got some kind of template code.
364%ifndef NAME_OVERLOAD
365 %define NAME_OVERLOAD(name) name
366%endif
367
368;;
369; Mangles the given name so it can be referenced using DECLASM() in the
370; C/C++ world.
371%ifndef ASM_FORMAT_BIN
372 %ifdef RT_ARCH_X86
373 %ifdef RT_OS_OS2
374 %define NAME(name) _ %+ NAME_OVERLOAD(name)
375 %endif
376 %ifdef RT_OS_WINDOWS
377 %define NAME(name) _ %+ NAME_OVERLOAD(name)
378 %endif
379 %endif
380 %ifdef RT_OS_DARWIN
381 %define NAME(name) _ %+ NAME_OVERLOAD(name)
382 %endif
383%endif
384%ifndef NAME
385 %define NAME(name) NAME_OVERLOAD(name)
386%endif
387
388;;
389; Mangles the given C name so it will _import_ the right symbol.
390%ifdef ASM_FORMAT_PE
391 %define IMPNAME(name) __imp_ %+ NAME(name)
392%else
393 %define IMPNAME(name) NAME(name)
394%endif
395
396;;
397; Gets the pointer to an imported object.
398%ifdef ASM_FORMAT_PE
399 %ifdef RT_ARCH_AMD64
400 %define IMP(name) qword [IMPNAME(name) wrt rip]
401 %else
402 %define IMP(name) dword [IMPNAME(name)]
403 %endif
404%else
405 %define IMP(name) IMPNAME(name)
406%endif
407
408;;
409; Gets the pointer to an imported object.
410%ifdef ASM_FORMAT_PE
411 %ifdef RT_ARCH_AMD64
412 %define IMP_SEG(SegOverride, name) qword [SegOverride:IMPNAME(name) wrt rip]
413 %else
414 %define IMP_SEG(SegOverride, name) dword [SegOverride:IMPNAME(name)]
415 %endif
416%else
417 %define IMP_SEG(SegOverride, name) IMPNAME(name)
418%endif
419
420;;
421; Declares an imported object for use with IMP2.
422; @note May change the current section!
423%macro EXTERN_IMP2 1
424 extern IMPNAME(%1)
425 BEGINDATA
426 %ifdef ASM_FORMAT_MACHO
427 g_Imp2_ %+ %1: RTCCPTR_DEF IMPNAME(%1)
428 %endif
429%endmacro
430
431;;
432; Gets the pointer to an imported object, version 2.
433%ifdef ASM_FORMAT_PE
434 %ifdef RT_ARCH_AMD64
435 %define IMP2(name) qword [IMPNAME(name) wrt rip]
436 %else
437 %define IMP2(name) dword [IMPNAME(name)]
438 %endif
439%elifdef ASM_FORMAT_ELF
440 %ifdef PIC
441 %ifdef RT_ARCH_AMD64
442 %define IMP2(name) qword [rel IMPNAME(name) wrt ..got]
443 %else
444 %define IMP2(name) IMPNAME(name) wrt ..plt
445 %endif
446 %endif
447%elifdef ASM_FORMAT_MACHO
448 %define IMP2(name) RTCCPTR_PRE [g_Imp2_ %+ name xWrtRIP]
449%endif
450%ifndef IMP2
451 %define IMP2(name) IMPNAME(name)
452%endif
453
454
455
456;;
457; Global marker which is DECLASM() compatible.
458%macro GLOBALNAME 1
459%ifndef ASM_FORMAT_BIN
460global NAME(%1)
461%endif
462NAME(%1):
463%endmacro
464
465;;
466; Global exported marker which is DECLASM() compatible.
467%macro EXPORTEDNAME 1
468 %ifdef ASM_FORMAT_PE
469 export %1=NAME(%1)
470 %endif
471 %ifdef __NASM__
472 %ifdef ASM_FORMAT_OMF
473 export NAME(%1) NAME(%1)
474 %endif
475%endif
476GLOBALNAME %1
477%endmacro
478
479;;
480; Global marker which is DECLASM() compatible.
481%macro GLOBALNAME_EX 2
482%ifndef ASM_FORMAT_BIN
483 %ifdef ASM_FORMAT_ELF
484global NAME(%1):%2
485 %else
486global NAME(%1)
487 %endif
488%endif
489NAME(%1):
490%endmacro
491
492;;
493; Global exported marker which is DECLASM() compatible.
494%macro EXPORTEDNAME_EX 2
495 %ifdef ASM_FORMAT_PE
496 export %1=NAME(%1)
497 %endif
498 %ifdef __NASM__
499 %ifdef ASM_FORMAT_OMF
500 export NAME(%1) NAME(%1)
501 %endif
502%endif
503GLOBALNAME_EX %1, %2
504%endmacro
505
506;;
507; Begins a C callable procedure.
508%macro BEGINPROC 1
509 %ifdef RT_ASM_WITH_SEH64_ALT
510 SEH64_ALT_START_UNWIND_INFO %1
511 %endif
512 %ifdef RT_ASM_WITH_SEH64
513global NAME(%1):function
514proc_frame NAME(%1)
515 %else
516GLOBALNAME_EX %1, function hidden
517 %endif
518.start_of_prologue:
519%endmacro
520
521;;
522; Begins a C callable exported procedure.
523%macro BEGINPROC_EXPORTED 1
524 %ifdef RT_ASM_WITH_SEH64_ALT
525 SEH64_ALT_START_UNWIND_INFO %1
526 %endif
527 %ifdef RT_ASM_WITH_SEH64
528 %ifdef ASM_FORMAT_PE
529export %1=NAME(%1)
530 %endif
531global NAME(%1):function
532proc_frame NAME(%1)
533 %else
534EXPORTEDNAME_EX %1, function
535 %endif
536.start_of_prologue:
537%endmacro
538
539;;
540; Ends a C callable procedure.
541%macro ENDPROC 1
542 %ifdef RT_ASM_WITH_SEH64
543endproc_frame
544 %endif
545GLOBALNAME_EX %1 %+ _EndProc, function hidden
546%ifdef ASM_FORMAT_ELF
547 %ifndef __NASM__ ; nasm does this in the global directive.
548size NAME(%1) NAME(%1 %+ _EndProc) - NAME(%1)
549size NAME(%1 %+ _EndProc) 4 ; make it non-zero to shut up warnigns from Linux's objtool.
550 %endif
551%endif
552 db 0xCC, 0xCC, 0xCC, 0xCC
553
554 %ifdef RT_ASM_WITH_SEH64_ALT
555 %ifdef ASM_FORMAT_PE
556 ; Emit the RUNTIME_FUNCTION entry. The linker is picky here, no label.
557 %ifndef ASM_DEFINED_PDATA_SECTION
558 %define ASM_DEFINED_PDATA_SECTION
559 section .pdata rdata align=4
560 %else
561 section .pdata
562 %endif
563 dd NAME(%1) wrt ..imagebase
564 dd NAME(%1 %+ _EndProc) wrt ..imagebase
565 dd NAME(%1 %+ .unwind_info) wrt ..imagebase
566
567 ; Restore code section.
568 BEGINCODE
569 %endif
570 %endif
571%endmacro
572
573
574;
575; Do OMF and Mach-O/Yasm segment definitions
576;
577; Both format requires this to get the segment order right, in the Mach-O/Yasm case
578; it's only to make sure the .bss section ends up last (it's not declared here).
579;
580%ifdef ASM_FORMAT_OMF
581 %ifndef RT_NOINC_SEGMENTS
582
583 ; 16-bit segments first (OMF / OS/2 specific).
584 %ifdef RT_INCL_16BIT_SEGMENTS
585 segment DATA16 public CLASS=FAR_DATA align=16 use16
586 segment DATA16_INIT public CLASS=FAR_DATA align=16 use16
587 group DGROUP16 DATA16 DATA16_INIT
588
589 ;;
590 ; Begins 16-bit data
591 %macro BEGINDATA16 0
592 segment DATA16
593 %endmacro
594
595 ;;
596 ; Begins 16-bit init data
597 %macro BEGINDATA16INIT 0
598 segment DATA16_INIT
599 %endmacro
600
601 segment CODE16 public CLASS=FAR_CODE align=16 use16
602 segment CODE16_INIT public CLASS=FAR_CODE align=16 use16
603 group CGROUP16 CODE16 CODE16_INIT
604
605 ;;
606 ; Begins 16-bit code
607 %macro BEGINCODE16 0
608 segment CODE16
609 %endmacro
610
611 ;;
612 ; Begins 16-bit init code
613 %macro BEGINCODE16INIT 0
614 segment CODE16_INIT
615 %endmacro
616
617 %endif
618
619 ; 32-bit segments.
620 segment TEXT32 public CLASS=CODE align=16 use32 flat
621 segment DATA32 public CLASS=DATA align=16 use32 flat
622 segment BSS32 public CLASS=BSS align=16 use32 flat
623
624 ; Make the TEXT32 segment default.
625 segment TEXT32
626 %endif ; RT_NOINC_SEGMENTS
627%endif
628
629%ifdef ASM_FORMAT_MACHO
630 %ifdef __YASM__
631 section .text
632 section .data
633 %endif
634%endif
635
636
637;;
638; Begins code
639%ifdef ASM_FORMAT_OMF
640 %macro BEGINCODE 0
641 segment TEXT32
642 %endmacro
643%else
644%macro BEGINCODE 0
645 section .text
646%endmacro
647%endif
648
649;;
650; Begins constant (read-only) data
651;
652; @remarks This is mapped to the CODE section/segment when there isn't
653; any dedicated const section/segment. (There is code that
654; assumes this, so don't try change it.)
655%ifdef ASM_FORMAT_OMF
656 %macro BEGINCONST 0
657 segment TEXT32
658 %endmacro
659%else
660 %macro BEGINCONST 0
661 %ifdef ASM_FORMAT_MACHO ;; @todo check the other guys too.
662 section .rodata
663 %else
664 section .text
665 %endif
666 %endmacro
667%endif
668
669;;
670; Begins initialized data
671%ifdef ASM_FORMAT_OMF
672 %macro BEGINDATA 0
673 segment DATA32
674 %endmacro
675%else
676%macro BEGINDATA 0
677 section .data
678%endmacro
679%endif
680
681;;
682; Begins uninitialized data
683%ifdef ASM_FORMAT_OMF
684 %macro BEGINBSS 0
685 segment BSS32
686 %endmacro
687%else
688%macro BEGINBSS 0
689 section .bss
690%endmacro
691%endif
692
693
694
695;; @def ARCH_BITS
696; Defines the bit count of the current context.
697%ifndef ARCH_BITS
698 %ifdef RT_ARCH_AMD64
699 %define ARCH_BITS 64
700 %else
701 %define ARCH_BITS 32
702 %endif
703%endif
704
705;; @def HC_ARCH_BITS
706; Defines the host architechture bit count.
707%ifndef HC_ARCH_BITS
708 %ifndef IN_RC
709 %define HC_ARCH_BITS ARCH_BITS
710 %else
711 %define HC_ARCH_BITS 32
712 %endif
713%endif
714
715;; @def R3_ARCH_BITS
716; Defines the host ring-3 architechture bit count.
717%ifndef R3_ARCH_BITS
718 %ifdef IN_RING3
719 %define R3_ARCH_BITS ARCH_BITS
720 %else
721 %define R3_ARCH_BITS HC_ARCH_BITS
722 %endif
723%endif
724
725;; @def R0_ARCH_BITS
726; Defines the host ring-0 architechture bit count.
727%ifndef R0_ARCH_BITS
728 %ifdef IN_RING0
729 %define R0_ARCH_BITS ARCH_BITS
730 %else
731 %define R0_ARCH_BITS HC_ARCH_BITS
732 %endif
733%endif
734
735;; @def GC_ARCH_BITS
736; Defines the guest architechture bit count.
737%ifndef GC_ARCH_BITS
738 %ifdef IN_RC
739 %define GC_ARCH_BITS ARCH_BITS
740 %else
741 %define GC_ARCH_BITS 32
742 %endif
743%endif
744
745
746
747;; @def RTHCPTR_DEF
748; The pesudo-instruction used to declare an initialized pointer variable in the host context.
749%if HC_ARCH_BITS == 64
750 %define RTHCPTR_DEF dq
751%else
752 %define RTHCPTR_DEF dd
753%endif
754
755;; @def RTHCPTR_RES
756; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
757; variable of the host context.
758%if HC_ARCH_BITS == 64
759 %define RTHCPTR_RES resq
760%else
761 %define RTHCPTR_RES resd
762%endif
763
764;; @def RTHCPTR_PRE
765; The memory operand prefix used for a pointer in the host context.
766%if HC_ARCH_BITS == 64
767 %define RTHCPTR_PRE qword
768%else
769 %define RTHCPTR_PRE dword
770%endif
771
772;; @def RTHCPTR_CB
773; The size in bytes of a pointer in the host context.
774%if HC_ARCH_BITS == 64
775 %define RTHCPTR_CB 8
776%else
777 %define RTHCPTR_CB 4
778%endif
779
780
781
782;; @def RTR0PTR_DEF
783; The pesudo-instruction used to declare an initialized pointer variable in the ring-0 host context.
784%if R0_ARCH_BITS == 64
785 %define RTR0PTR_DEF dq
786%else
787 %define RTR0PTR_DEF dd
788%endif
789
790;; @def RTR0PTR_RES
791; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
792; variable of the ring-0 host context.
793%if R0_ARCH_BITS == 64
794 %define RTR0PTR_RES resq
795%else
796 %define RTR0PTR_RES resd
797%endif
798
799;; @def RTR0PTR_PRE
800; The memory operand prefix used for a pointer in the ring-0 host context.
801%if R0_ARCH_BITS == 64
802 %define RTR0PTR_PRE qword
803%else
804 %define RTR0PTR_PRE dword
805%endif
806
807;; @def RTR0PTR_CB
808; The size in bytes of a pointer in the ring-0 host context.
809%if R0_ARCH_BITS == 64
810 %define RTR0PTR_CB 8
811%else
812 %define RTR0PTR_CB 4
813%endif
814
815
816
817;; @def RTR3PTR_DEF
818; The pesudo-instruction used to declare an initialized pointer variable in the ring-3 host context.
819%if R3_ARCH_BITS == 64
820 %define RTR3PTR_DEF dq
821%else
822 %define RTR3PTR_DEF dd
823%endif
824
825;; @def RTR3PTR_RES
826; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
827; variable of the ring-3 host context.
828%if R3_ARCH_BITS == 64
829 %define RTR3PTR_RES resq
830%else
831 %define RTR3PTR_RES resd
832%endif
833
834;; @def RTR3PTR_PRE
835; The memory operand prefix used for a pointer in the ring-3 host context.
836%if R3_ARCH_BITS == 64
837 %define RTR3PTR_PRE qword
838%else
839 %define RTR3PTR_PRE dword
840%endif
841
842;; @def RTR3PTR_CB
843; The size in bytes of a pointer in the ring-3 host context.
844%if R3_ARCH_BITS == 64
845 %define RTR3PTR_CB 8
846%else
847 %define RTR3PTR_CB 4
848%endif
849
850
851
852;; @def RTGCPTR_DEF
853; The pesudo-instruction used to declare an initialized pointer variable in the guest context.
854%if GC_ARCH_BITS == 64
855 %define RTGCPTR_DEF dq
856%else
857 %define RTGCPTR_DEF dd
858%endif
859
860;; @def RTGCPTR_RES
861; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
862; variable of the guest context.
863%if GC_ARCH_BITS == 64
864 %define RTGCPTR_RES resq
865%else
866 %define RTGCPTR_RES resd
867%endif
868
869%define RTGCPTR32_RES resd
870%define RTGCPTR64_RES resq
871
872;; @def RTGCPTR_PRE
873; The memory operand prefix used for a pointer in the guest context.
874%if GC_ARCH_BITS == 64
875 %define RTGCPTR_PRE qword
876%else
877 %define RTGCPTR_PRE dword
878%endif
879
880;; @def RTGCPTR_CB
881; The size in bytes of a pointer in the guest context.
882%if GC_ARCH_BITS == 64
883 %define RTGCPTR_CB 8
884%else
885 %define RTGCPTR_CB 4
886%endif
887
888
889;; @def RTRCPTR_DEF
890; The pesudo-instruction used to declare an initialized pointer variable in the raw mode context.
891%define RTRCPTR_DEF dd
892
893;; @def RTRCPTR_RES
894; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
895; variable of the raw mode context.
896%define RTRCPTR_RES resd
897
898;; @def RTRCPTR_PRE
899; The memory operand prefix used for a pointer in the raw mode context.
900%define RTRCPTR_PRE dword
901
902;; @def RTRCPTR_CB
903; The size in bytes of a pointer in the raw mode context.
904%define RTRCPTR_CB 4
905
906
907;; @def RT_CCPTR_DEF
908; The pesudo-instruction used to declare an initialized pointer variable in the current context.
909
910;; @def RT_CCPTR_RES
911; The pesudo-instruction used to declare (=reserve space for) an uninitialized pointer
912; variable of the current context.
913
914;; @def RT_CCPTR_PRE
915; The memory operand prefix used for a pointer in the current context.
916
917;; @def RT_CCPTR_CB
918; The size in bytes of a pointer in the current context.
919
920%ifdef IN_RC
921 %define RTCCPTR_DEF RTRCPTR_DEF
922 %define RTCCPTR_RES RTRCPTR_RES
923 %define RTCCPTR_PRE RTRCPTR_PRE
924 %define RTCCPTR_CB RTRCPTR_CB
925%else
926 %ifdef IN_RING0
927 %define RTCCPTR_DEF RTR0PTR_DEF
928 %define RTCCPTR_RES RTR0PTR_RES
929 %define RTCCPTR_PRE RTR0PTR_PRE
930 %define RTCCPTR_CB RTR0PTR_CB
931 %else
932 %define RTCCPTR_DEF RTR3PTR_DEF
933 %define RTCCPTR_RES RTR3PTR_RES
934 %define RTCCPTR_PRE RTR3PTR_PRE
935 %define RTCCPTR_CB RTR3PTR_CB
936 %endif
937%endif
938
939
940
941;; @def RTHCPHYS_DEF
942; The pesudo-instruction used to declare an initialized host physical address.
943%define RTHCPHYS_DEF dq
944
945;; @def RTHCPTR_RES
946; The pesudo-instruction used to declare (=reserve space for) an uninitialized
947; host physical address variable
948%define RTHCPHYS_RES resq
949
950;; @def RTHCPTR_PRE
951; The memory operand prefix used for a host physical address.
952%define RTHCPHYS_PRE qword
953
954;; @def RTHCPHYS_CB
955; The size in bytes of a host physical address.
956%define RTHCPHYS_CB 8
957
958
959
960;; @def RTGCPHYS_DEF
961; The pesudo-instruction used to declare an initialized guest physical address.
962%define RTGCPHYS_DEF dq
963
964;; @def RTGCPHYS_RES
965; The pesudo-instruction used to declare (=reserve space for) an uninitialized
966; guest physical address variable
967%define RTGCPHYS_RES resq
968
969;; @def RTGCPTR_PRE
970; The memory operand prefix used for a guest physical address.
971%define RTGCPHYS_PRE qword
972
973;; @def RTGCPHYS_CB
974; The size in bytes of a guest physical address.
975%define RTGCPHYS_CB 8
976
977
978
979;;
980; The size of the long double C/C++ type.
981; On 32-bit Darwin this is 16 bytes, on L4, Linux, OS/2 and Windows
982; it's 12 bytes.
983; @todo figure out what 64-bit Windows does (I don't recall right now).
984%ifdef RT_ARCH_X86
985 %ifdef RT_OS_DARWIN
986 %define RTLRD_CB 16
987 %else
988 %define RTLRD_CB 12
989 %endif
990%else
991 %define RTLRD_CB 16
992%endif
993
994
995
996;; @def ASM_CALL64_GCC
997; Indicates that we're using the GCC 64-bit calling convention.
998; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
999
1000;; @def ASM_CALL64_MSC
1001; Indicates that we're using the Microsoft 64-bit calling convention (fastcall on steroids).
1002; @see @ref sec_vboxrem_amd64_compare (in VBoxREMWrapper.cpp) for an ABI description.
1003
1004; Note: On X86 we're using cdecl unconditionally. There is not yet any common
1005; calling convention on AMD64, that's why we need to support two different ones.)
1006
1007%ifdef RT_ARCH_AMD64
1008 %ifndef ASM_CALL64_GCC
1009 %ifndef ASM_CALL64_MSC
1010 ; define it based on the object format.
1011 %ifdef ASM_FORMAT_PE
1012 %define ASM_CALL64_MSC
1013 %else
1014 %define ASM_CALL64_GCC
1015 %endif
1016 %endif
1017 %else
1018 ; sanity check.
1019 %ifdef ASM_CALL64_MSC
1020 %error "Only one of the ASM_CALL64_* defines should be defined!"
1021 %endif
1022 %endif
1023%else
1024 ;later; %ifdef ASM_CALL64_GCC
1025 ;later; %error "ASM_CALL64_GCC is defined without RT_ARCH_AMD64!" ASM_CALL64_GCC
1026 ;later; %endif
1027 ;later; %ifdef ASM_CALL64_MSC
1028 ;later; %error "ASM_CALL64_MSC is defined without RT_ARCH_AMD64!" ASM_CALL64_MSC
1029 ;later; %endif
1030%endif
1031
1032
1033;; @def RT_NOCRT
1034; Symbol name wrapper for the No-CRT bits.
1035;
1036; In order to coexist in the same process as other CRTs, we need to
1037; decorate the symbols such that they don't conflict the ones in the
1038; other CRTs. The result of such conflicts / duplicate symbols can
1039; confuse the dynamic loader on unix like systems.
1040;
1041; @remark Always feed the name to this macro first and then pass the result
1042; on to the next *NAME* macro.
1043;
1044%ifndef RT_WITHOUT_NOCRT_WRAPPERS
1045 %define RT_NOCRT(name) nocrt_ %+ name
1046%else
1047 %define RT_NOCRT(name) name
1048%endif
1049
1050;; @def RT_NOCRT_BEGINPROC
1051; Starts a NOCRT procedure, taking care of name wrapping and aliasing.
1052;
1053; Aliasing (weak ones, if supported) will be created when RT_WITH_NOCRT_ALIASES
1054; is defined and RT_WITHOUT_NOCRT_WRAPPERS isn't.
1055;
1056%macro RT_NOCRT_BEGINPROC 1
1057 %ifdef RT_WITH_NOCRT_ALIASES
1058BEGINPROC_EXPORTED RT_NOCRT(%1)
1059 %ifdef ASM_FORMAT_ELF
1060global NAME(%1)
1061weak NAME(%1)
1062NAME(%1):
1063 %else
1064GLOBALNAME %1
1065 %endif
1066 %else ; !RT_WITH_NOCRT_ALIASES
1067BEGINPROC_EXPORTED RT_NOCRT(%1)
1068 %endif ; !RT_WITH_NOCRT_ALIASES
1069%endmacro ; RT_NOCRT_BEGINPROC
1070
1071%ifdef RT_WITH_NOCRT_ALIASES
1072 %ifdef RT_WITHOUT_NOCRT_WRAPPERS
1073 %error "RT_WITH_NOCRT_ALIASES and RT_WITHOUT_NOCRT_WRAPPERS doesn't mix."
1074 %endif
1075%endif
1076
1077
1078
1079;; @def xCB
1080; The stack unit size / The register unit size.
1081
1082;; @def xSP
1083; The stack pointer register (RSP or ESP).
1084
1085;; @def xBP
1086; The base pointer register (RBP or ESP).
1087
1088;; @def xAX
1089; RAX or EAX depending on context.
1090
1091;; @def xBX
1092; RBX or EBX depending on context.
1093
1094;; @def xCX
1095; RCX or ECX depending on context.
1096
1097;; @def xDX
1098; RDX or EDX depending on context.
1099
1100;; @def xDI
1101; RDI or EDI depending on context.
1102
1103;; @def xSI
1104; RSI or ESI depending on context.
1105
1106;; @def xWrtRIP
1107; 'wrt rip' for AMD64 targets, nothing for x86 ones.
1108
1109%ifdef RT_ARCH_AMD64
1110 %define xCB 8
1111 %define xSP rsp
1112 %define xBP rbp
1113 %define xAX rax
1114 %define xBX rbx
1115 %define xCX rcx
1116 %define xDX rdx
1117 %define xDI rdi
1118 %define xSI rsi
1119 %define xWrtRIP wrt rip
1120%else
1121 %define xCB 4
1122 %define xSP esp
1123 %define xBP ebp
1124 %define xAX eax
1125 %define xBX ebx
1126 %define xCX ecx
1127 %define xDX edx
1128 %define xDI edi
1129 %define xSI esi
1130 %define xWrtRIP
1131%endif
1132
1133
1134;
1135; NASM sets __PASS__ to 0 in preprocess-only mode, and to 3 when only generating dependencies.
1136; YASM has no such setting which is why we must rely on kBuild to tell us what we're doing.
1137; For simplicity, we'll set the kBuild macro when using NASM.
1138;
1139%ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1140 %ifdef __NASM__
1141 %if __PASS__ == 0 || __PASS__ == 3
1142 %define KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1143 %endif
1144 %endif
1145%endif
1146
1147
1148;
1149; Some simple compile time assertions.
1150;
1151; Note! Requires new kBuild to work with YASM (see above).
1152;
1153
1154;;
1155; Structure size assertion macro.
1156%define AssertCompileSize(a_Type, a_Size) AssertCompileSizeML a_Type, a_Size
1157%macro AssertCompileSizeML 2
1158 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1159 %assign AssertVar_cbActual %1 %+ _size
1160 %assign AssertVar_cbExpected %2
1161 %if AssertVar_cbActual != AssertVar_cbExpected
1162 %error %1 is AssertVar_cbActual bytes instead of AssertVar_cbExpected
1163 %endif
1164 %endif
1165%endmacro
1166
1167;;
1168; Structure size alignment assertion macro.
1169
1170%define AssertCompileSizeAlignment(a_Type, a_Align) AssertCompileSizeAlignmentML a_Type, a_Align
1171%macro AssertCompileSizeAlignmentML 2
1172 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1173 %assign AssertVar_cbActual %1 %+ _size
1174 %assign AssertVar_cbAlignment %2
1175 %if (AssertVar_cbActual & (AssertVar_cbAlignment - 1)) != 0
1176 %error %1 is AssertVar_cbActual bytes, expected size with AssertVar_cbAlignment bytes alignment.
1177 %endif
1178 %endif
1179%endmacro
1180
1181;;
1182; Structure member offset assertion macro.
1183%define AssertCompileMemberOffset(a_Type, a_Member, a_off) AssertCompileMemberOffsetML a_Type, a_Member, a_off
1184%macro AssertCompileMemberOffsetML 3
1185 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1186 %assign AssertVar_offActual %1 %+ . %+ %2
1187 %assign AssertVar_offExpected %3
1188 %if AssertVar_offActual != AssertVar_offExpected
1189 %error %1 %+ . %+ %2 is at AssertVar_offActual instead of AssertVar_offExpected
1190 %endif
1191 %endif
1192%endmacro
1193
1194;;
1195; Structure member alignment assertion macro.
1196%define AssertCompileMemberAlignment(a_Type, a_Member, a_cbAlign) AssertCompileMemberAlignmentML a_Type, a_Member, a_cbAlign
1197%macro AssertCompileMemberAlignmentML 3
1198 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1199 %assign AssertVar_offActual %1 %+ . %+ %2
1200 %assign AssertVar_cbAlign %3
1201 %if AssertVar_offActual & (AssertVar_cbAlign - 1)
1202 %error %1 %+ . %+ %2 is at AssertVar_offActual, expected AssertVar_cbAlign alignment
1203 %endif
1204 %endif
1205%endmacro
1206
1207;;
1208; Generic compile time expression assertion.
1209%define AssertCompile(a_Expr) AssertCompileML { a_Expr }
1210%macro AssertCompileML 1
1211 %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
1212 %if (%1) != 1
1213 %assign AssertVar_uResult %1
1214 %error %1 => AssertVar_uResult
1215 %endif
1216 %endif
1217%endmacro
1218
1219%endif
1220
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