summaryrefslogtreecommitdiff
path: root/include/iprt/asmdefs.mac
diff options
context:
space:
mode:
Diffstat (limited to 'include/iprt/asmdefs.mac')
-rw-r--r--include/iprt/asmdefs.mac108
1 files changed, 83 insertions, 25 deletions
diff --git a/include/iprt/asmdefs.mac b/include/iprt/asmdefs.mac
index 665c674b..0b363a56 100644
--- a/include/iprt/asmdefs.mac
+++ b/include/iprt/asmdefs.mac
@@ -3,7 +3,7 @@
;
;
-; Copyright (C) 2006-2007 Oracle Corporation
+; Copyright (C) 2006-2012 Oracle Corporation
;
; This file is part of VirtualBox Open Source Edition (OSE), as
; available from http://www.virtualbox.org. This file is free software;
@@ -72,6 +72,11 @@
%define RT_BIT(bit) (1 << bit)
;;
+; Makes a 32-bit unsigned (not type safe, but whatever) out of four byte values.
+%define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) ( (b3 << 24) | (b2 << 16) | (b1 << 8) | b0 )
+
+
+;;
; Align code, pad with INT3.
%define ALIGNCODE(alignment) align alignment, db 0cch
@@ -94,17 +99,19 @@
;;
; Mangles the given name so it can be referenced using DECLASM() in the
; C/C++ world.
-%ifdef RT_ARCH_X86
- %ifdef RT_OS_OS2
- %define NAME(name) _ %+ NAME_OVERLOAD(name)
+%ifndef ASM_FORMAT_BIN
+ %ifdef RT_ARCH_X86
+ %ifdef RT_OS_OS2
+ %define NAME(name) _ %+ NAME_OVERLOAD(name)
+ %endif
+ %ifdef RT_OS_WINDOWS
+ %define NAME(name) _ %+ NAME_OVERLOAD(name)
+ %endif
%endif
- %ifdef RT_OS_WINDOWS
+ %ifdef RT_OS_DARWIN
%define NAME(name) _ %+ NAME_OVERLOAD(name)
%endif
%endif
-%ifdef RT_OS_DARWIN
- %define NAME(name) _ %+ NAME_OVERLOAD(name)
-%endif
%ifndef NAME
%define NAME(name) NAME_OVERLOAD(name)
%endif
@@ -112,9 +119,9 @@
;;
; Mangles the given C name so it will _import_ the right symbol.
%ifdef ASM_FORMAT_PE
-%define IMPNAME(name) __imp_ %+ NAME(name)
+ %define IMPNAME(name) __imp_ %+ NAME(name)
%else
-%define IMPNAME(name) NAME(name)
+ %define IMPNAME(name) NAME(name)
%endif
;;
@@ -130,6 +137,17 @@
%endif
;;
+; Declares an imported object for use with IMP2.
+; @note May change the current section!
+%macro EXTERN_IMP2 1
+ extern IMPNAME(%1)
+ BEGINDATA
+ %ifdef ASM_FORMAT_MACHO
+ g_Imp2_ %+ %1: RTCCPTR_DEF IMPNAME(%1)
+ %endif
+%endmacro
+
+;;
; Gets the pointer to an imported object, version 2.
%ifdef ASM_FORMAT_PE
%ifdef RT_ARCH_AMD64
@@ -137,12 +155,19 @@
%else
%define IMP2(name) dword [IMPNAME(name)]
%endif
-%else
- %ifdef RT_ARCH_AMD64
- %define IMP2(name) IMPNAME(name) wrt rip
- %else
- %define IMP2(name) IMPNAME(name)
+%elifdef ASM_FORMAT_ELF
+ %ifdef PIC
+ %ifdef RT_ARCH_AMD64
+ %define IMP2(name) qword [rel IMPNAME(name) wrt ..got]
+ %else
+ %define IMP2(name) IMPNAME(name) wrt ..plt
+ %endif
%endif
+%elifdef ASM_FORMAT_MACHO
+ %define IMP2(name) RTCCPTR_PRE [g_Imp2_ %+ name xWrtRIP]
+%endif
+%ifndef IMP2
+ %define IMP2(name) IMPNAME(name)
%endif
@@ -276,8 +301,8 @@ size NAME(%1 %+ _EndProc) 0
%ifdef ASM_FORMAT_MACHO
%ifdef __YASM__
- [section .text]
- [section .data]
+ section .text
+ section .data
%endif
%endif
@@ -290,7 +315,7 @@ size NAME(%1 %+ _EndProc) 0
%endmacro
%else
%macro BEGINCODE 0
-[section .text]
+ section .text
%endmacro
%endif
@@ -307,9 +332,9 @@ size NAME(%1 %+ _EndProc) 0
%else
%macro BEGINCONST 0
%ifdef ASM_FORMAT_MACHO ;; @todo check the other guys too.
- [section .rodata]
+ section .rodata
%else
- [section .text]
+ section .text
%endif
%endmacro
%endif
@@ -322,7 +347,7 @@ size NAME(%1 %+ _EndProc) 0
%endmacro
%else
%macro BEGINDATA 0
-[section .data]
+ section .data
%endmacro
%endif
@@ -334,7 +359,7 @@ size NAME(%1 %+ _EndProc) 0
%endmacro
%else
%macro BEGINBSS 0
-[section .bss]
+ section .bss
%endmacro
%endif
@@ -717,7 +742,7 @@ BEGINPROC RT_NOCRT(%1)
-;; @def xS
+;; @def xCB
; The stack unit size / The register unit size.
;; @def xSP
@@ -748,7 +773,7 @@ BEGINPROC RT_NOCRT(%1)
; 'wrt rip' for AMD64 targets, nothing for x86 ones.
%ifdef RT_ARCH_AMD64
- %define xS 8
+ %define xCB 8
%define xSP rsp
%define xBP rbp
%define xAX rax
@@ -759,7 +784,7 @@ BEGINPROC RT_NOCRT(%1)
%define xSI rsi
%define xWrtRIP wrt rip
%else
- %define xS 4
+ %define xCB 4
%define xSP esp
%define xBP ebp
%define xAX eax
@@ -771,4 +796,37 @@ BEGINPROC RT_NOCRT(%1)
%define xWrtRIP
%endif
+
+;
+; Some simple compile time assertions.
+;
+; Note! Requires new kBuild to work.
+;
+
+;;
+; Structure size assertion macro.
+%define AssertCompileSize(a_Type, a_Size) AssertCompileSizeML a_Type, a_Size
+%macro AssertCompileSizeML 2,
+ %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
+ %assign AssertVar_cbActual %1 %+ _size
+ %assign AssertVar_cbExpected %2
+ %if AssertVar_cbActual != AssertVar_cbExpected
+ %error %1 is AssertVar_cbActual bytes instead of AssertVar_cbExpected
+ %endif
+ %endif
+%endmacro
+
+;;
+; Structure memember offset assertion macro.
+%define AssertCompileMemberOffset(a_Type, a_Member, a_off) AssertCompileMemberOffsetML a_Type, a_Member, a_off
+%macro AssertCompileMemberOffsetML 3,
+ %ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
+ %assign AssertVar_offActual %1 %+ . %+ %2
+ %assign AssertVar_offExpected %3
+ %if AssertVar_offActual != AssertVar_offExpected
+ %error %1 %+ . %+ %2 is at AssertVar_offActual instead of AssertVar_offExpected
+ %endif
+ %endif
+%endmacro
+
%endif