msdasql: Implement IColumnsRowset GetAvailableColumns.
[wine.git] / include / wine / asm.h
blob2c996ccd86b27557f86f293a62379543824f5215
1 /*
2 * Inline assembly support
4 * Copyright 2019 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_WINE_ASM_H
22 #define __WINE_WINE_ASM_H
24 #if defined(__APPLE__) || (defined(__WINE_PE_BUILD) && defined(__i386__))
25 # define __ASM_NAME(name) "_" name
26 #else
27 # define __ASM_NAME(name) name
28 #endif
30 #if defined(__WINE_PE_BUILD) && defined(__i386__)
31 # define __ASM_STDCALL(name,args) "_" name "@" #args
32 # define __ASM_FASTCALL(name,args) "@" name "@" #args
33 #else
34 # define __ASM_STDCALL(name,args) __ASM_NAME(name)
35 # define __ASM_FASTCALL(name,args) __ASM_NAME("__fastcall_" name)
36 #endif
38 #if defined(__GCC_HAVE_DWARF2_CFI_ASM) || ((defined(__APPLE__) || defined(__clang__)) && defined(__GNUC__) && !defined(__SEH__))
39 # define __ASM_CFI(str) str
40 #else
41 # define __ASM_CFI(str)
42 #endif
44 #if defined(__SEH__) || (defined(_MSC_VER) && defined(__clang__) && (defined(__x86_64__) || defined(__aarch64__)))
45 # if defined(__aarch64__) && defined(__clang_major__) && (__clang_major__ < 12 || defined(__apple_build_version__))
46 /* Clang got support for aarch64 SEH assembly directives in Clang 12,
47 * before that, only .seh_startproc/.seh_endproc but nothing else was
48 * supported. Support for it doesn't exist in any Apple branded version
49 * of Clang yet. */
50 # define __ASM_SEH(str)
51 # else
52 # define __ASM_SEH(str) str
53 # endif
54 #else
55 # define __ASM_SEH(str)
56 #endif
58 #ifdef __WINE_PE_BUILD
59 # define __ASM_FUNC_TYPE(name) ".def " name "\n\t.scl 2\n\t.type 32\n\t.endef"
60 #elif defined(__APPLE__)
61 # define __ASM_FUNC_TYPE(name) ""
62 #elif defined(__arm__) && defined(__thumb__)
63 # define __ASM_FUNC_TYPE(name) ".type " name ",%function\n\t.thumb_func"
64 #elif defined(__arm__) || defined(__aarch64__)
65 # define __ASM_FUNC_TYPE(name) ".type " name ",%function"
66 #else
67 # define __ASM_FUNC_TYPE(name) ".type " name ",@function"
68 #endif
70 #ifdef __WINE_PE_BUILD
71 # define __ASM_FUNC_SIZE(name) ""
72 #elif defined(__APPLE__)
73 # define __ASM_FUNC_SIZE(name) ""
74 #else
75 # define __ASM_FUNC_SIZE(name) "\n\t.size " name ",.-" name
76 #endif
78 #if !defined(__GNUC__) && !defined(__clang__)
79 # define __ASM_BLOCK_BEGIN(name) void __asm_dummy_##name(void) {
80 # define __ASM_BLOCK_END }
81 #else
82 # define __ASM_BLOCK_BEGIN(name)
83 # define __ASM_BLOCK_END
84 #endif
86 #define __ASM_DEFINE_FUNC(name,code) \
87 __ASM_BLOCK_BEGIN(__LINE__) \
88 asm(".text\n\t.align 4\n\t.globl " name "\n\t" __ASM_FUNC_TYPE(name) __ASM_SEH("\n\t.seh_proc " name) "\n" name ":\n\t" \
89 __ASM_CFI(".cfi_startproc\n\t") code __ASM_CFI("\n\t.cfi_endproc") __ASM_SEH("\n\t.seh_endproc") __ASM_FUNC_SIZE(name)); \
90 __ASM_BLOCK_END
92 #define __ASM_GLOBAL_FUNC(name,code) __ASM_DEFINE_FUNC(__ASM_NAME(#name),code)
93 #define __ASM_STDCALL_FUNC(name,args,code) __ASM_DEFINE_FUNC(__ASM_STDCALL(#name,args),code)
94 #define __ASM_FASTCALL_FUNC(name,args,code) __ASM_DEFINE_FUNC(__ASM_FASTCALL(#name,args),code)
96 /* import variables */
98 #ifdef _WIN64
99 #define __ASM_DEFINE_IMPORT(name) \
100 __ASM_BLOCK_BEGIN(__LINE__) \
101 asm(".data\n\t.balign 8\n\t.globl __imp_" name "\n__imp_" name ":\n\t.quad " name "\n\t.text"); \
102 __ASM_BLOCK_END
103 #else
104 #define __ASM_DEFINE_IMPORT(name) \
105 __ASM_BLOCK_BEGIN(__LINE__) \
106 asm(".data\n\t.balign 4\n\t.globl __imp_" name "\n__imp_" name ":\n\t.long " name "\n\t.text"); \
107 __ASM_BLOCK_END
108 #endif
110 #ifdef __WINE_PE_BUILD
111 #define __ASM_GLOBAL_IMPORT(name) __ASM_DEFINE_IMPORT(__ASM_NAME(#name))
112 #define __ASM_STDCALL_IMPORT(name,args) __ASM_DEFINE_IMPORT(__ASM_STDCALL(#name,args))
113 #else
114 #define __ASM_GLOBAL_IMPORT(name) /* nothing */
115 #define __ASM_STDCALL_IMPORT(name,args) /* nothing */
116 #endif
118 /* fastcall support */
120 #if defined(__i386__) && !defined(__WINE_PE_BUILD)
122 # define __ASM_USE_FASTCALL_WRAPPER
123 # define DEFINE_FASTCALL1_WRAPPER(func) \
124 __ASM_FASTCALL_FUNC( func, 4, \
125 "popl %eax\n\t" \
126 "pushl %ecx\n\t" \
127 "pushl %eax\n\t" \
128 "jmp " __ASM_STDCALL(#func,4) )
129 # define DEFINE_FASTCALL_WRAPPER(func,args) \
130 __ASM_FASTCALL_FUNC( func, args, \
131 "popl %eax\n\t" \
132 "pushl %edx\n\t" \
133 "pushl %ecx\n\t" \
134 "pushl %eax\n\t" \
135 "jmp " __ASM_STDCALL(#func,args) )
137 #else /* __i386__ */
139 # define DEFINE_FASTCALL1_WRAPPER(func) /* nothing */
140 # define DEFINE_FASTCALL_WRAPPER(func,args) /* nothing */
142 #endif /* __i386__ */
144 /* thiscall support */
146 #if defined(__i386__) && !defined(__MINGW32__) && (!defined(_MSC_VER) || !defined(__clang__))
148 # define __ASM_USE_THISCALL_WRAPPER
149 # ifdef _MSC_VER
150 # define DEFINE_THISCALL_WRAPPER(func,args) \
151 __declspec(naked) void __thiscall_##func(void) \
152 { __asm { \
153 pop eax \
154 push ecx \
155 push eax \
156 jmp func \
158 # else /* _MSC_VER */
159 # define DEFINE_THISCALL_WRAPPER(func,args) \
160 extern void __thiscall_ ## func(void); \
161 __ASM_STDCALL_FUNC( __thiscall_ ## func, args, \
162 "popl %eax\n\t" \
163 "pushl %ecx\n\t" \
164 "pushl %eax\n\t" \
165 "jmp " __ASM_STDCALL(#func,args) )
166 # endif /* _MSC_VER */
168 # define THISCALL(func) (void *)__thiscall_ ## func
169 # define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
171 #else /* __i386__ */
173 # define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
174 # define THISCALL(func) func
175 # define THISCALL_NAME(func) __ASM_NAME(#func)
177 #endif /* __i386__ */
179 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(__WINE_PE_BUILD) && !defined(__APPLE__) && !defined(__ANDROID__)
180 #define __ASM_OBSOLETE(func) __asm__( ".symver " #func "_obsolete," #func "@WINE_1.0" )
181 #else
182 #undef __ASM_OBSOLETE
183 #endif
185 #endif /* __WINE_WINE_ASM_H */