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