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