2019-05-14 12:30:46 +02:00
|
|
|
/*
|
|
|
|
* Inline assembly support
|
|
|
|
*
|
|
|
|
* Copyright 2019 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __WINE_WINE_ASM_H
|
|
|
|
#define __WINE_WINE_ASM_H
|
|
|
|
|
|
|
|
#if defined(__APPLE__) || (defined(_WIN32) && defined(__i386__))
|
|
|
|
# define __ASM_NAME(name) "_" name
|
|
|
|
#else
|
|
|
|
# define __ASM_NAME(name) name
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(__i386__)
|
2020-11-23 13:58:27 +01:00
|
|
|
# define __ASM_STDCALL(name,args) "_" name "@" #args
|
|
|
|
# define __ASM_FASTCALL(name,args) "@" name "@" #args
|
2019-05-14 12:30:46 +02:00
|
|
|
#else
|
2020-11-23 13:58:27 +01:00
|
|
|
# define __ASM_STDCALL(name,args) __ASM_NAME(name)
|
|
|
|
# define __ASM_FASTCALL(name,args) __ASM_NAME("__fastcall_" name)
|
2019-05-14 12:30:46 +02:00
|
|
|
#endif
|
|
|
|
|
2020-05-29 12:51:04 +02:00
|
|
|
#if defined(__GCC_HAVE_DWARF2_CFI_ASM) || (defined(__clang__) && defined(__GNUC__) && !defined(__SEH__))
|
2019-05-14 12:30:46 +02:00
|
|
|
# define __ASM_CFI(str) str
|
|
|
|
#else
|
2019-05-15 21:42:02 +02:00
|
|
|
# define __ASM_CFI(str)
|
2019-05-14 12:30:46 +02:00
|
|
|
#endif
|
|
|
|
|
2020-12-18 23:37:12 +01:00
|
|
|
#if defined(__SEH__) || (defined(_MSC_VER) && defined(__clang__) && (defined(__x86_64__) || defined(__aarch64__)))
|
2020-09-04 09:36:06 +02:00
|
|
|
# if defined(__aarch64__) && defined(__clang_major__) && (__clang_major__ < 12 || defined(__apple_build_version__))
|
|
|
|
/* Clang got support for aarch64 SEH assembly directives in Clang 12,
|
|
|
|
* before that, only .seh_startproc/.seh_endproc but nothing else was
|
|
|
|
* supported. Support for it doesn't exist in any Apple branded version
|
|
|
|
* of Clang yet. */
|
|
|
|
# define __ASM_SEH(str)
|
|
|
|
# else
|
|
|
|
# define __ASM_SEH(str) str
|
|
|
|
# endif
|
2019-08-21 10:40:24 +02:00
|
|
|
#else
|
|
|
|
# define __ASM_SEH(str)
|
|
|
|
#endif
|
|
|
|
|
2019-05-14 12:30:46 +02:00
|
|
|
#ifdef _WIN32
|
2020-12-18 23:34:34 +01:00
|
|
|
# define __ASM_FUNC_TYPE(name) ".def " name "\n\t.scl 2\n\t.type 32\n\t.endef"
|
2019-05-14 12:30:46 +02:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
# define __ASM_FUNC_TYPE(name) ""
|
2021-01-18 11:43:55 +01:00
|
|
|
#elif defined(__arm__) && defined(__thumb__)
|
|
|
|
# define __ASM_FUNC_TYPE(name) ".type " name ",%function\n\t.thumb_func"
|
|
|
|
#elif defined(__arm__) || defined(__aarch64__)
|
2019-05-14 12:30:46 +02:00
|
|
|
# define __ASM_FUNC_TYPE(name) ".type " name ",%function"
|
|
|
|
#else
|
|
|
|
# define __ASM_FUNC_TYPE(name) ".type " name ",@function"
|
|
|
|
#endif
|
|
|
|
|
2020-11-30 10:30:19 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
# define __ASM_FUNC_SIZE(name) ""
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
# define __ASM_FUNC_SIZE(name) ""
|
|
|
|
#else
|
|
|
|
# define __ASM_FUNC_SIZE(name) "\n\t.size " name ",.-" name
|
|
|
|
#endif
|
|
|
|
|
2020-04-24 20:10:07 +02:00
|
|
|
#if !defined(__GNUC__) && !defined(__clang__)
|
|
|
|
# define __ASM_BLOCK_BEGIN(name) void __asm_dummy_##name(void) {
|
|
|
|
# define __ASM_BLOCK_END }
|
2019-05-14 12:30:46 +02:00
|
|
|
#else
|
2020-04-24 20:10:07 +02:00
|
|
|
# define __ASM_BLOCK_BEGIN(name)
|
|
|
|
# define __ASM_BLOCK_END
|
2019-05-14 12:30:46 +02:00
|
|
|
#endif
|
|
|
|
|
2020-04-24 20:10:07 +02:00
|
|
|
#define __ASM_DEFINE_FUNC(name,code) \
|
|
|
|
__ASM_BLOCK_BEGIN(__LINE__) \
|
|
|
|
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" \
|
2020-11-30 10:30:19 +01:00
|
|
|
__ASM_CFI(".cfi_startproc\n\t") code __ASM_CFI("\n\t.cfi_endproc") __ASM_SEH("\n\t.seh_endproc") __ASM_FUNC_SIZE(name)); \
|
2020-04-24 20:10:07 +02:00
|
|
|
__ASM_BLOCK_END
|
|
|
|
|
2019-05-14 12:30:46 +02:00
|
|
|
#define __ASM_GLOBAL_FUNC(name,code) __ASM_DEFINE_FUNC(__ASM_NAME(#name),code)
|
2019-05-16 18:13:45 +02:00
|
|
|
#define __ASM_STDCALL_FUNC(name,args,code) __ASM_DEFINE_FUNC(__ASM_STDCALL(#name,args),code)
|
2020-11-23 13:58:27 +01:00
|
|
|
#define __ASM_FASTCALL_FUNC(name,args,code) __ASM_DEFINE_FUNC(__ASM_FASTCALL(#name,args),code)
|
2019-05-14 12:30:46 +02:00
|
|
|
|
2020-11-24 11:42:29 +01:00
|
|
|
/* import variables */
|
|
|
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
#define __ASM_DEFINE_IMPORT(name) \
|
|
|
|
__ASM_BLOCK_BEGIN(__LINE__) \
|
|
|
|
asm(".data\n\t.balign 8\n\t.globl __imp_" name "\n__imp_" name ":\n\t.quad " name "\n\t.text"); \
|
|
|
|
__ASM_BLOCK_END
|
|
|
|
#else
|
|
|
|
#define __ASM_DEFINE_IMPORT(name) \
|
|
|
|
__ASM_BLOCK_BEGIN(__LINE__) \
|
|
|
|
asm(".data\n\t.balign 4\n\t.globl __imp_" name "\n__imp_" name ":\n\t.long " name "\n\t.text"); \
|
|
|
|
__ASM_BLOCK_END
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define __ASM_GLOBAL_IMPORT(name) __ASM_DEFINE_IMPORT(__ASM_NAME(#name))
|
|
|
|
#define __ASM_STDCALL_IMPORT(name,args) __ASM_DEFINE_IMPORT(__ASM_STDCALL(#name,args))
|
|
|
|
#else
|
|
|
|
#define __ASM_GLOBAL_IMPORT(name) /* nothing */
|
|
|
|
#define __ASM_STDCALL_IMPORT(name,args) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
2019-05-15 19:59:33 +02:00
|
|
|
/* fastcall support */
|
|
|
|
|
2019-05-16 10:15:26 +02:00
|
|
|
#if defined(__i386__) && !defined(_WIN32)
|
2019-05-15 19:59:33 +02:00
|
|
|
|
|
|
|
# define DEFINE_FASTCALL1_WRAPPER(func) \
|
2020-11-23 13:58:27 +01:00
|
|
|
__ASM_FASTCALL_FUNC( func, 4, \
|
2019-05-15 19:59:33 +02:00
|
|
|
"popl %eax\n\t" \
|
|
|
|
"pushl %ecx\n\t" \
|
|
|
|
"pushl %eax\n\t" \
|
2019-05-16 18:13:45 +02:00
|
|
|
"jmp " __ASM_STDCALL(#func,4) )
|
2019-05-15 19:59:33 +02:00
|
|
|
# define DEFINE_FASTCALL_WRAPPER(func,args) \
|
2020-11-23 13:58:27 +01:00
|
|
|
__ASM_FASTCALL_FUNC( func, args, \
|
2019-05-15 19:59:33 +02:00
|
|
|
"popl %eax\n\t" \
|
|
|
|
"pushl %edx\n\t" \
|
|
|
|
"pushl %ecx\n\t" \
|
|
|
|
"pushl %eax\n\t" \
|
2019-05-16 18:13:45 +02:00
|
|
|
"jmp " __ASM_STDCALL(#func,args) )
|
2019-05-15 19:59:33 +02:00
|
|
|
|
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
# define DEFINE_FASTCALL1_WRAPPER(func) /* nothing */
|
|
|
|
# define DEFINE_FASTCALL_WRAPPER(func,args) /* nothing */
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
2019-05-15 20:06:32 +02:00
|
|
|
/* thiscall support */
|
|
|
|
|
2020-04-23 15:40:54 +02:00
|
|
|
#if defined(__i386__) && !defined(__MINGW32__) && (!defined(_MSC_VER) || !defined(__clang__))
|
2019-05-15 20:06:32 +02:00
|
|
|
|
2020-04-27 02:30:26 +02:00
|
|
|
#define __ASM_USE_THISCALL_WRAPPER
|
2019-05-15 20:06:32 +02:00
|
|
|
# ifdef _MSC_VER
|
|
|
|
# define DEFINE_THISCALL_WRAPPER(func,args) \
|
2019-05-16 13:53:33 +02:00
|
|
|
__declspec(naked) void __thiscall_##func(void) \
|
2019-05-15 20:06:32 +02:00
|
|
|
{ __asm { \
|
|
|
|
pop eax \
|
|
|
|
push ecx \
|
|
|
|
push eax \
|
|
|
|
jmp func \
|
|
|
|
} }
|
|
|
|
# else /* _MSC_VER */
|
|
|
|
# define DEFINE_THISCALL_WRAPPER(func,args) \
|
|
|
|
extern void __thiscall_ ## func(void); \
|
2019-05-16 13:53:33 +02:00
|
|
|
__ASM_STDCALL_FUNC( __thiscall_ ## func, args, \
|
2019-05-15 20:06:32 +02:00
|
|
|
"popl %eax\n\t" \
|
|
|
|
"pushl %ecx\n\t" \
|
|
|
|
"pushl %eax\n\t" \
|
2019-05-16 18:13:45 +02:00
|
|
|
"jmp " __ASM_STDCALL(#func,args) )
|
2019-05-15 20:06:32 +02:00
|
|
|
# endif /* _MSC_VER */
|
|
|
|
|
|
|
|
# define THISCALL(func) (void *)__thiscall_ ## func
|
|
|
|
# define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
|
|
|
|
|
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
# define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
|
|
|
|
# define THISCALL(func) func
|
|
|
|
# define THISCALL_NAME(func) __ASM_NAME(#func)
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
2021-02-04 15:14:24 +01:00
|
|
|
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
|
2020-01-29 10:48:39 +01:00
|
|
|
#define __ASM_OBSOLETE(func) __asm__( ".symver " #func "_obsolete," #func "@WINE_1.0" )
|
|
|
|
#else
|
|
|
|
#undef __ASM_OBSOLETE
|
|
|
|
#endif
|
|
|
|
|
2019-05-14 12:30:46 +02:00
|
|
|
#endif /* __WINE_WINE_ASM_H */
|