1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Quake III Arena source code; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 23 #ifndef __Q_PLATFORM_H 24 #define __Q_PLATFORM_H 25 26 // this is for determining if we have an asm version of a C function 27 #define idx64 0 28 29 #ifdef Q3_VM 30 31 #define id386 0 32 #define idppc 0 33 #define idppc_altivec 0 34 #define idsparc 0 35 36 #else 37 38 #define id386 0 39 40 #if (defined(powerc) || defined(powerpc) || defined(ppc) || \ 41 defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY) 42 #define idppc 1 43 #if defined(__VEC__) 44 #define idppc_altivec 1 45 #ifdef __APPLE__ // Apple's GCC does this differently than the FSF. 46 #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ 47 (vector unsigned char) (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) 48 #else 49 #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ 50 (vector unsigned char) {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p} 51 #endif 52 #else 53 #define idppc_altivec 0 54 #endif 55 #else 56 #define idppc 0 57 #define idppc_altivec 0 58 #endif 59 60 #if defined(__sparc__) && !defined(C_ONLY) 61 #define idsparc 1 62 #else 63 #define idsparc 0 64 #endif 65 66 #endif 67 68 #ifndef __ASM_I386__ // don't include the C bits if included from qasm.h 69 70 // for windows fastcall option 71 #define QDECL 72 #define QCALL 73 74 //================================================================= WIN64/32 === 75 76 #if defined(_WIN64) || defined(__WIN64__) 77 78 #undef idx64 79 #define idx64 1 80 81 #undef QDECL 82 #define QDECL __cdecl 83 84 #undef QCALL 85 #define QCALL __stdcall 86 87 #if defined( _MSC_VER ) 88 #define OS_STRING "win_msvc64" 89 #elif defined __MINGW64__ 90 #define OS_STRING "win_mingw64" 91 #endif 92 93 #define ID_INLINE __inline 94 #define PATH_SEP '\\' 95 96 #if defined( __WIN64__ ) 97 #define ARCH_STRING "x64" 98 #elif defined _M_ALPHA 99 #define ARCH_STRING "AXP" 100 #endif 101 102 #define Q3_LITTLE_ENDIAN 103 104 #define DLL_EXT ".dll" 105 106 #elif defined(_WIN32) || defined(__WIN32__) 107 108 #undef QDECL 109 #define QDECL __cdecl 110 111 #undef QCALL 112 #define QCALL __stdcall 113 114 #if defined( _MSC_VER ) 115 #define OS_STRING "win_msvc" 116 #elif defined __MINGW32__ 117 #define OS_STRING "win_mingw" 118 #endif 119 120 #define ID_INLINE __inline 121 #define PATH_SEP '\\' 122 123 #if defined( _M_IX86 ) || defined( __i386__ ) 124 #define ARCH_STRING "x86" 125 #elif defined _M_ALPHA 126 #define ARCH_STRING "AXP" 127 #endif 128 129 #define Q3_LITTLE_ENDIAN 130 131 #define DLL_EXT ".dll" 132 133 #endif 134 135 136 //============================================================== MAC OS X === 137 138 #if defined(__APPLE__) || defined(__APPLE_CC__) 139 140 #define OS_STRING "macosx" 141 #define ID_INLINE inline 142 #define PATH_SEP '/' 143 144 #ifdef __ppc__ 145 #define ARCH_STRING "ppc" 146 #define Q3_BIG_ENDIAN 147 #elif defined __i386__ 148 #define ARCH_STRING "i386" 149 #define Q3_LITTLE_ENDIAN 150 #elif defined __x86_64__ 151 #undef idx64 152 #define idx64 1 153 #define ARCH_STRING "x86_64" 154 #define Q3_LITTLE_ENDIAN 155 #endif 156 157 #define DLL_EXT ".dylib" 158 159 #endif 160 161 //================================================================= LINUX === 162 163 #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__) 164 165 #include <endian.h> 166 167 #if defined(__linux__) 168 #define OS_STRING "linux" 169 #elif defined(__FreeBSD_kernel__) 170 #define OS_STRING "kFreeBSD" 171 #else 172 #define OS_STRING "GNU" 173 #endif 174 175 #define ID_INLINE inline 176 177 #define PATH_SEP '/' 178 179 #if !defined(ARCH_STRING) 180 # error ARCH_STRING should be defined by the Makefile 181 #endif 182 183 #if defined __x86_64__ 184 #undef idx64 185 #define idx64 1 186 #endif 187 188 #if __FLOAT_WORD_ORDER == __BIG_ENDIAN 189 #define Q3_BIG_ENDIAN 190 #else 191 #define Q3_LITTLE_ENDIAN 192 #endif 193 194 #define DLL_EXT ".so" 195 196 #endif 197 198 //=================================================================== BSD === 199 200 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) 201 202 #include <sys/types.h> 203 #include <machine/endian.h> 204 205 #ifndef __BSD__ 206 #define __BSD__ 207 #endif 208 209 #if defined(__FreeBSD__) 210 #define OS_STRING "freebsd" 211 #elif defined(__OpenBSD__) 212 #define OS_STRING "openbsd" 213 #elif defined(__NetBSD__) 214 #define OS_STRING "netbsd" 215 #elif defined(__DragonFly__) 216 #define OS_STRING "dragonfly" 217 #endif 218 219 #define ID_INLINE inline 220 #define PATH_SEP '/' 221 222 #ifdef __i386__ 223 #define ARCH_STRING "i386" 224 #elif defined __amd64__ 225 #define ARCH_STRING "amd64" 226 #elif defined __axp__ 227 #define ARCH_STRING "alpha" 228 #elif defined __powerpc64__ 229 #define ARCH_STRING "powerpc64" 230 #elif defined __powerpc__ 231 #define ARCH_STRING "powerpc" 232 #elif defined __riscv 233 #define ARCH_STRING "riscv64" 234 #endif 235 236 #if BYTE_ORDER == BIG_ENDIAN 237 #define Q3_BIG_ENDIAN 238 #else 239 #define Q3_LITTLE_ENDIAN 240 #endif 241 242 #if defined(__DragonFly__) && defined __x86_64__ 243 #undef idx64 244 #define idx64 1 245 #undef ARCH_STRING 246 #define ARCH_STRING "x86_64" 247 #endif 248 249 #define DLL_EXT ".so" 250 251 #endif 252 253 //================================================================= SUNOS === 254 255 #ifdef __sun 256 257 #include <stdint.h> 258 #include <sys/byteorder.h> 259 260 #define OS_STRING "solaris" 261 #define ID_INLINE inline 262 #define PATH_SEP '/' 263 264 #ifdef __i386__ 265 #define ARCH_STRING "i386" 266 #elif defined __sparc 267 #define ARCH_STRING "sparc" 268 #endif 269 270 #if defined( _BIG_ENDIAN ) 271 #define Q3_BIG_ENDIAN 272 #elif defined( _LITTLE_ENDIAN ) 273 #define Q3_LITTLE_ENDIAN 274 #endif 275 276 #define DLL_EXT ".so" 277 278 #endif 279 280 //================================================================== IRIX === 281 282 #ifdef __sgi 283 284 #define OS_STRING "irix" 285 #define ID_INLINE __inline 286 #define PATH_SEP '/' 287 288 #define ARCH_STRING "mips" 289 290 #define Q3_BIG_ENDIAN // SGI's MIPS are always big endian 291 292 #define DLL_EXT ".so" 293 294 #endif 295 296 //================================================================== Q3VM === 297 298 #ifdef Q3_VM 299 300 #define OS_STRING "q3vm" 301 #define ID_INLINE 302 #define PATH_SEP '/' 303 304 #define ARCH_STRING "bytecode" 305 306 #define DLL_EXT ".qvm" 307 308 #endif 309 310 //=========================================================================== 311 312 //catch missing defines in above blocks 313 #if !defined( OS_STRING ) 314 #error "Operating system not supported" 315 #endif 316 317 #if !defined( ARCH_STRING ) 318 #error "Architecture not supported" 319 #endif 320 321 #ifndef ID_INLINE 322 #error "ID_INLINE not defined" 323 #endif 324 325 #ifndef PATH_SEP 326 #error "PATH_SEP not defined" 327 #endif 328 329 #ifndef DLL_EXT 330 #error "DLL_EXT not defined" 331 #endif 332 333 334 //endianness 335 void CopyShortSwap (void *dest, void *src); 336 void CopyLongSwap (void *dest, void *src); 337 short ShortSwap (short l); 338 int LongSwap (int l); 339 float FloatSwap (const float *f); 340 341 #if defined( Q3_BIG_ENDIAN ) && defined( Q3_LITTLE_ENDIAN ) 342 #error "Endianness defined as both big and little" 343 #elif defined( Q3_BIG_ENDIAN ) 344 345 #define CopyLittleShort(dest, src) CopyShortSwap(dest, src) 346 #define CopyLittleLong(dest, src) CopyLongSwap(dest, src) 347 #define LittleShort(x) ShortSwap(x) 348 #define LittleLong(x) LongSwap(x) 349 #define LittleFloat(x) FloatSwap(&x) 350 #define BigShort 351 #define BigLong 352 #define BigFloat 353 354 #elif defined( Q3_LITTLE_ENDIAN ) 355 356 #define CopyLittleShort(dest, src) Com_Memcpy(dest, src, 2) 357 #define CopyLittleLong(dest, src) Com_Memcpy(dest, src, 4) 358 #define LittleShort 359 #define LittleLong 360 #define LittleFloat 361 #define BigShort(x) ShortSwap(x) 362 #define BigLong(x) LongSwap(x) 363 #define BigFloat(x) FloatSwap(&x) 364 365 #elif defined( Q3_VM ) 366 367 #define LittleShort 368 #define LittleLong 369 #define LittleFloat 370 #define BigShort 371 #define BigLong 372 #define BigFloat 373 374 #else 375 #error "Endianness not defined" 376 #endif 377 378 379 //platform string 380 #ifdef NDEBUG 381 #define PLATFORM_STRING OS_STRING "-" ARCH_STRING 382 #else 383 #define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug" 384 #endif 385 386 #endif 387 388 #endif 389