1 /* 2 3 Package: dyncall 4 Library: dyncall 5 File: dyncall/dyncall_macros.h 6 Description: Platform detection macros 7 License: 8 9 Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, 10 Tassilo Philipp <tphilipp@potion-studios.com> 11 12 Permission to use, copy, modify, and distribute this software for any 13 purpose with or without fee is hereby granted, provided that the above 14 copyright notice and this permission notice appear in all copies. 15 16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 23 24 */ 25 26 27 28 /* 29 30 dyncall macros 31 32 Platform detection, specific defines and configuration. 33 The purpose of this file is to provide coherent platform and compiler 34 specific defines. So instead of defines like WIN32, _OpenBSD_ or 35 __GNUC__, one should use DC__OS_Win32, DC__OS_OpenBSD or DC__C_GNU, 36 respectively. 37 38 REVISION 39 2007/12/11 initial 40 41 */ 42 43 44 #ifndef DYNCALL_MACROS_H 45 #define DYNCALL_MACROS_H 46 47 48 /* Platform specific defines. */ 49 50 /* MS Windows XP x64/Vista64 or later. */ 51 #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) 52 #define DC__OS_Win64 53 54 /* MS Windows NT/95/98/ME/2000/XP/Vista32. */ 55 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__WINDOWS__) || defined(_WINDOWS) 56 #define DC__OS_Win32 57 58 /* All the OS' based on Darwin OS (MacOS X, OpenDarwin). Note that '__APPLE__' may be defined for classic MacOS, too. */ 59 /* __MACOSX__ is not defined in gcc assembler mode (switch: -S) */ 60 /* @@@ TODO: Check for Classic OS */ 61 62 #elif defined(__APPLE__) || defined(__Darwin__) 63 # define DC__OS_Darwin 64 # if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) 65 # define DC__OS_IPhone 66 # else /* defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) */ 67 # define DC__OS_MacOSX 68 # endif 69 70 /* The most popular open source Unix-like OS - Linux. */ 71 #elif defined(__linux__) || defined(__linux) || defined(__gnu_linux__) 72 #define DC__OS_Linux 73 74 /* The most powerful open source Unix-like OS - FreeBSD. */ 75 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* latter is (also) used by systems using FreeBSD kernel, e.g. Debian/kFreeBSD, which could be detected specifically by also checking for __GLIBC__ */ 76 #define DC__OS_FreeBSD 77 78 /* The most secure open source Unix-like OS - OpenBSD. */ 79 #elif defined(__OpenBSD__) 80 #define DC__OS_OpenBSD 81 82 /* The most portable open source Unix-like OS - NetBSD. */ 83 #elif defined(__NetBSD__) 84 #define DC__OS_NetBSD 85 86 /* The FreeBSD fork having heavy clusterization in mind - DragonFlyBSD. */ 87 #elif defined(__DragonFly__) 88 #define DC__OS_DragonFlyBSD 89 90 /* Sun's Unix-like OS - SunOS / Solaris. */ 91 #elif defined(__sun__) || defined(__sun) || defined(sun) 92 #define DC__OS_SunOS 93 94 /* The "Linux-like environment for Windows" - Cygwin. */ 95 #elif defined(__CYGWIN__) 96 #define DC__OS_Cygwin 97 98 /* The "Minimalist GNU for Windows" - MinGW. */ 99 #elif defined(__MINGW__)/*@@@*/ 100 #define DC__OS_MinGW 101 102 /* The Nintendo DS (homebrew) using devkitpro. */ 103 #elif defined(__nds__) 104 #define DC__OS_NDS 105 106 /* The PlayStation Portable (homebrew) SDK. */ 107 #elif defined(__psp__) || defined(PSP) 108 #define DC__OS_PSP 109 110 /* Haiku (BeOS alike). */ 111 #elif defined(__HAIKU__) 112 #define DC__OS_BeOS 113 114 /* The Unix successor - Plan9 from Bell Labs */ 115 #elif defined(Plan9) || defined(__Plan9__) 116 #define DC__OS_Plan9 117 118 /* Digital's Unix-like OS - VMS */ 119 #elif defined(__vms) 120 #define DC__OS_VMS 121 122 #elif defined(__minix) 123 #define DC__OS_Minix 124 125 #else 126 127 /* Unable to determine OS, which is probably ok (e.g. baremetal stuff, etc.). */ 128 #define DC__OS_UNKNOWN 129 #endif 130 131 132 133 /* Compiler specific defines. Do not change the order, because */ 134 /* some of the compilers define flags for compatible ones, too. */ 135 136 /* Intel's C/C++ compiler. */ 137 #if defined(__INTEL_COMPILER) 138 #define DC__C_Intel 139 140 /* MS C/C++ compiler. */ 141 #elif defined(_MSC_VER) 142 #define DC__C_MSVC 143 144 /* LLVM clang. */ 145 #elif defined(__clang__) || defined(__llvm__) 146 #define DC__C_CLANG 147 148 /* The GNU Compiler Collection - GCC. */ 149 #elif defined(__GNUC__) 150 #define DC__C_GNU 151 152 /* Watcom compiler. */ 153 #elif defined(__WATCOMC__) 154 #define DC__C_WATCOM 155 156 /* Portable C Compiler. */ 157 #elif defined(__PCC__) 158 #define DC__C_PCC 159 160 /* Sun Pro C. */ 161 #elif defined(__SUNPRO_C) 162 #define DC__C_SUNPRO 163 164 /* Undetected C Compiler. */ 165 #else 166 #define DC__C_UNKNOWN 167 #endif 168 169 170 171 /* Architecture. */ 172 173 /* Check architecture. */ 174 #if defined(_M_X64_) || defined(_M_AMD64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) 175 # define DC__Arch_AMD64 176 #elif defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__386__) || defined(__i386) 177 # define DC__Arch_Intel_x86 178 #elif defined(_M_IA64) || defined(__ia64__) 179 # define DC__Arch_Itanium 180 #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__) 181 # if defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__) || defined(__powerpc64__) 182 # define DC__Arch_PPC64 183 # else 184 # define DC__Arch_PPC32 185 # endif 186 #elif defined(__mips64__) || defined(__mips64) 187 # define DC__Arch_MIPS64 188 #elif defined(_M_MRX000) || defined(__mips__) || defined(__mips) || defined(_mips) 189 # define DC__Arch_MIPS 190 #elif defined(__arm__) 191 # define DC__Arch_ARM 192 #elif defined(_M_ARM64) || defined(__aarch64__) || defined(__arm64) || defined(__arm64__) 193 # define DC__Arch_ARM64 194 #elif defined(__sh__) 195 # define DC__Arch_SuperH 196 #elif defined(__sparc) || defined(__sparc__) 197 # if defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || defined(__arch64__) 198 # define DC__Arch_Sparc64 199 # else 200 # define DC__Arch_Sparc 201 # endif 202 #endif 203 204 205 206 /* Rough OS classification. */ 207 208 #if defined(DC__OS_Win32) || defined(DC__OS_Win64) 209 # define DC_WINDOWS 210 #elif defined(DC__OS_Plan9) 211 # define DC_PLAN9 212 #elif defined(DC__OS_NDS) || defined(DC__OS_PSP) 213 # define DC_OTHER 214 #else 215 # define DC_UNIX 216 #endif 217 218 219 220 /* Misc machine-dependent modes, ABIs, etc.. */ 221 222 #if defined(__arm__) && !defined(__thumb__) 223 # define DC__Arch_ARM_ARM 224 #elif defined(__arm__) && defined(__thumb__) 225 # define DC__Arch_ARM_THUMB 226 #endif 227 228 #if defined(DC__Arch_ARM_ARM) || defined(DC__Arch_ARM_THUMB) 229 # if defined(__ARM_EABI__) || defined(DC__OS_NDS) 230 # if defined (__ARM_PCS_VFP) && (__ARM_PCS_VFP == 1) 231 # define DC__ABI_ARM_HF 232 # else 233 # define DC__ABI_ARM_EABI 234 # endif 235 # elif defined(__APCS_32__) 236 # define DC__ABI_ARM_OABI 237 # endif 238 #endif /* ARM */ 239 240 #if defined(DC__Arch_MIPS) || defined(DC__Arch_MIPS64) 241 # if defined(_ABIO32) || defined(__mips_o32) || defined(_MIPS_ARCH_MIPS1) || defined(_MIPS_ARCH_MIPS2) 242 # define DC__ABI_MIPS_O32 243 # elif defined(_ABI64) || defined(__mips_n64) 244 # define DC__ABI_MIPS_N64 245 # elif defined(_ABIN32) 246 # define DC__ABI_MIPS_N32 247 # else 248 # define DC__ABI_MIPS_EABI 249 # endif 250 /* Set extra flag to know if FP hardware ABI, default to yes, if unsure */ 251 # if (defined(__mips_hard_float) && (__mips_hard_float == 1)) || !defined(__mips_soft_float) || (__mips_soft_float != 1) 252 # define DC__ABI_HARDFLOAT /* @@@ make this general for all archs? */ 253 # else 254 # define DC__ABI_SOFTFLOAT 255 # endif 256 #endif /* MIPS */ 257 258 #if defined(DC__Arch_PPC64) 259 # if defined(_CALL_ELF) 260 # define DC__ABI_PPC64_ELF_V _CALL_ELF 261 # else 262 # define DC__ABI_PPC64_ELF_V 0 /* 0 means not explicitly set, otherwise this is 1 (big endian) and 2 (little endian) */ 263 # endif 264 #endif /* PPC64 */ 265 266 267 /* Endian detection. */ 268 #if defined(DC__Arch_Intel_x86) || defined(DC__Arch_AMD64) /* always little */ 269 # define DC__Endian_LITTLE 270 #elif defined(DC__Arch_Sparc) /* always purely big until v9 */ 271 # define DC__Endian_BIG 272 #else /* all others are bi-endian */ 273 /* @@@check flags used on following bi-endianness archs: 274 DC__Arch_Itanium 275 DC__Arch_PPC32 276 DC__Arch_PPC64 277 DC__Arch_SuperH 278 */ 279 # if (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 1)) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(MIPSEB) || defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || defined(__ARMEB__) || defined(__AARCH64EB__) 280 # define DC__Endian_BIG 281 # elif (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 2)) || defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || defined(MIPSEL) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(__ARMEL__) || defined(__AARCH64EL__) 282 # define DC__Endian_LITTLE 283 # elif defined(DC__Arch_Sparc64) && !defined(__BYTE_ORDER__) /* Sparc64 default is big-endian, except if explicitly defined */ 284 # define DC__Endian_BIG 285 # elif defined(__BYTE_ORDER__) /* explicitly set */ 286 # if defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 287 # define DC__Endian_BIG 288 # elif defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 289 # define DC__Endian_LITTLE 290 # endif 291 # endif /* no else, leave unset if not sure */ 292 #endif 293 294 295 /* Internal macro/tag. */ 296 #if !defined(DC_API) 297 # define DC_API 298 #endif 299 300 #endif /* DYNCALL_MACROS_H */ 301 302