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