2005-11-01 22:09:15 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
|
|
|
|
Quake III Arena source code is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
Quake III Arena source code 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Quake III Arena source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
//
|
|
|
|
#ifndef __Q_PLATFORM_H
|
|
|
|
#define __Q_PLATFORM_H
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
// this is for determining if we have an asm version of a C function
|
|
|
|
#ifdef Q3_VM
|
|
|
|
|
|
|
|
#define id386 0
|
|
|
|
#define idppc 0
|
|
|
|
#define idppc_altivec 0
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#else
|
2005-11-04 22:32:00 +00:00
|
|
|
|
|
|
|
#if (defined _M_IX86 || defined __i386__) && \
|
|
|
|
!defined __sun && !defined(C_ONLY)
|
|
|
|
#define id386 1
|
|
|
|
#else
|
|
|
|
#define id386 0
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#if (defined(powerc) || defined(powerpc) || defined(ppc) || \
|
|
|
|
defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY)
|
|
|
|
#define idppc 1
|
2005-11-01 22:09:15 +00:00
|
|
|
#if defined(__VEC__)
|
|
|
|
#define idppc_altivec 1
|
|
|
|
#else
|
|
|
|
#define idppc_altivec 0
|
|
|
|
#endif
|
|
|
|
#else
|
2005-11-04 22:32:00 +00:00
|
|
|
#define idppc 0
|
2005-11-01 22:09:15 +00:00
|
|
|
#define idppc_altivec 0
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __ASM_I386__ // don't include the C bits if included from qasm.h
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
// for windows fastcall option
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define QDECL
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
short ShortSwap (short l);
|
|
|
|
int LongSwap (int l);
|
|
|
|
float FloatSwap (const float *f);
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
//================================================================= WIN32 ===
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#undef QDECL
|
2005-11-04 22:32:00 +00:00
|
|
|
#define QDECL __cdecl
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "win_msvc"
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#ifdef _M_IX86
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "x86"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined _M_ALPHA
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "AXP"
|
2005-11-01 22:09:15 +00:00
|
|
|
#else
|
2005-11-05 00:29:40 +00:00
|
|
|
#error "Unsupported architecture"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
2005-11-05 00:29:40 +00:00
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __MINGW32__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "win_mingw"
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#ifdef __i386__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "x86"
|
2005-11-01 22:09:15 +00:00
|
|
|
#else
|
2005-11-05 00:29:40 +00:00
|
|
|
#error "Unsupported architecture"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
2005-11-05 00:29:40 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Unsupported compiler"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define ID_INLINE __inline
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
static ID_INLINE short BigShort( short l) { return ShortSwap(l); }
|
|
|
|
#define LittleShort
|
|
|
|
static ID_INLINE int BigLong(int l) { return LongSwap(l); }
|
|
|
|
#define LittleLong
|
|
|
|
static ID_INLINE float BigFloat(const float l) { return FloatSwap(&l); }
|
|
|
|
#define LittleFloat
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define PATH_SEP '\\'
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
//============================================================== MAC OS X ===
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#if defined(MACOS_X)
|
|
|
|
|
|
|
|
#define __cdecl
|
|
|
|
#define __declspec(x)
|
|
|
|
#define stricmp strcasecmp
|
2005-11-04 22:32:00 +00:00
|
|
|
#define ID_INLINE inline
|
2005-11-01 22:09:15 +00:00
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "macosx"
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#ifdef __ppc__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "ppc"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __i386__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "i386"
|
2005-11-01 22:09:15 +00:00
|
|
|
#else
|
2005-11-05 00:29:40 +00:00
|
|
|
#error "Unsupported architecture"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define PATH_SEP '/'
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#define __rlwimi(out, in, shift, maskBegin, maskEnd) \
|
|
|
|
asm("rlwimi %0,%1,%2,%3,%4" : "=r" (out) : "r" (in), \
|
|
|
|
"i" (shift), "i" (maskBegin), "i" (maskEnd))
|
|
|
|
#define __dcbt(addr, offset) asm("dcbt %0,%1" : : "b" (addr), "r" (offset))
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE unsigned int __lwbrx(register void *addr,
|
|
|
|
register int offset) {
|
|
|
|
register unsigned int word;
|
|
|
|
|
|
|
|
asm("lwbrx %0,%2,%1" : "=r" (word) : "r" (addr), "b" (offset));
|
|
|
|
return word;
|
2005-11-01 22:09:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE unsigned short __lhbrx(register void *addr,
|
|
|
|
register int offset) {
|
|
|
|
register unsigned short halfword;
|
|
|
|
|
|
|
|
asm("lhbrx %0,%2,%1" : "=r" (halfword) : "r" (addr), "b" (offset));
|
|
|
|
return halfword;
|
2005-11-01 22:09:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE float __fctiw(register float f) {
|
|
|
|
register float fi;
|
2005-11-01 22:09:15 +00:00
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
asm("fctiw %0,%1" : "=f" (fi) : "f" (f));
|
|
|
|
return fi;
|
2005-11-01 22:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BigShort
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE short LittleShort(short l) { return ShortSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigLong
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE int LittleLong(int l) { return LongSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigFloat
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE float LittleFloat(const float l) { return FloatSwap(&l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
//=================================================================== MAC ===
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#ifdef __MACOS__
|
|
|
|
|
|
|
|
#include <MacTypes.h>
|
2005-11-04 22:32:00 +00:00
|
|
|
#define ID_INLINE inline
|
2005-11-01 22:09:15 +00:00
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "macos"
|
|
|
|
#define ARCH_STRING "ppc"
|
2005-11-01 22:09:15 +00:00
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define PATH_SEP ':'
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
void Sys_PumpEvents( void );
|
|
|
|
|
|
|
|
#define BigShort
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE short LittleShort(short l) { return ShortSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigLong
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE int LittleLong(int l) { return LongSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigFloat
|
2005-11-04 22:32:00 +00:00
|
|
|
static ID_INLINE float LittleFloat(const float l) { return FloatSwap(&l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
//================================================================= LINUX ===
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
// the mac compiler can't handle >32k of locals, so we
|
|
|
|
// just waste space and make big arrays static...
|
|
|
|
#ifdef __linux__
|
|
|
|
|
|
|
|
// bk001205 - from Makefile
|
|
|
|
#define stricmp strcasecmp
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define ID_INLINE inline
|
2005-11-01 22:09:15 +00:00
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "linux"
|
|
|
|
|
|
|
|
#if defined __i386__
|
|
|
|
#define ARCH_STRING "i386"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __x86_64__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "x86_64"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __powerpc64__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "ppc64"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __powerpc__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "ppc"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __s390__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "s390"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __s390x__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "s390x"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __ia64__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "ia64"
|
|
|
|
#elif defined __alpha__
|
|
|
|
#define ARCH_STRING "alpha"
|
|
|
|
#elif defined __sparc__
|
|
|
|
#define ARCH_STRING "sparc"
|
|
|
|
#elif defined __arm__
|
|
|
|
#define ARCH_STRING "arm"
|
|
|
|
#elif defined __cris__
|
|
|
|
#define ARCH_STRING "cris"
|
|
|
|
#elif defined __hppa__
|
|
|
|
#define ARCH_STRING "hppa"
|
|
|
|
#elif defined __mips__
|
|
|
|
#define ARCH_STRING "mips"
|
|
|
|
#elif defined __sh__
|
|
|
|
#define ARCH_STRING "sh"
|
2005-11-01 22:09:15 +00:00
|
|
|
#else
|
2005-11-05 00:29:40 +00:00
|
|
|
#error "Unsupported architecture"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define PATH_SEP '/'
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static short BigShort( short l) { return ShortSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define LittleShort
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static int BigLong(int l) { return LongSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define LittleLong
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static float BigFloat(const float l) { return FloatSwap(&l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define LittleFloat
|
|
|
|
#else
|
|
|
|
#define BigShort
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static short LittleShort(short l) { return ShortSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigLong
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static int LittleLong(int l) { return LongSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigFloat
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static float LittleFloat(const float l) { return FloatSwap(&l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
//=============================================================== FreeBSD ===
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#ifdef __FreeBSD__ // rb010123
|
|
|
|
|
|
|
|
#define stricmp strcasecmp
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define ID_INLINE inline
|
2005-11-01 22:09:15 +00:00
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "freebsd"
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#ifdef __i386__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "i386"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __axp__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "alpha"
|
2005-11-01 22:09:15 +00:00
|
|
|
#else
|
2005-11-05 00:29:40 +00:00
|
|
|
#error "Unsupported architecture"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define PATH_SEP '/'
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#if !idppc
|
|
|
|
static short BigShort( short l) { return ShortSwap(l); }
|
|
|
|
#define LittleShort
|
|
|
|
static int BigLong(int l) { return LongSwap(l); }
|
|
|
|
#define LittleLong
|
|
|
|
static float BigFloat(const float l) { return FloatSwap(&l); }
|
|
|
|
#define LittleFloat
|
|
|
|
#else
|
|
|
|
#define BigShort
|
|
|
|
static short LittleShort(short l) { return ShortSwap(l); }
|
|
|
|
#define BigLong
|
2005-11-04 22:32:00 +00:00
|
|
|
static int LittleLong(int l) { return LongSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigFloat
|
2005-11-04 22:32:00 +00:00
|
|
|
static float LittleFloat(const float l) { return FloatSwap(&l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
//================================================================= SUNOS ===
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#ifdef __sun
|
|
|
|
|
|
|
|
#include <sys/isa_defs.h>
|
|
|
|
#include <sys/byteorder.h>
|
|
|
|
|
|
|
|
// bk001205 - from Makefile
|
|
|
|
#define stricmp strcasecmp
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define ID_INLINE inline
|
2005-11-01 22:09:15 +00:00
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "solaris"
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#ifdef __i386__
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "i386"
|
2005-11-01 22:09:15 +00:00
|
|
|
#elif defined __sparc
|
2005-11-05 00:29:40 +00:00
|
|
|
#define ARCH_STRING "sparc"
|
2005-11-05 00:42:28 +00:00
|
|
|
#else
|
|
|
|
#error "Unsupported architecture"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
#define PATH_SEP '/'
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
|
|
|
|
#define BigShort
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static short LittleShort(short l) { return ShortSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigLong
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static int LittleLong(int l) { return LongSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define BigFloat
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static float LittleFloat(const float l) { return FloatSwap(&l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static short BigShort( short l) { return ShortSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define LittleShort
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static int BigLong(int l) { return LongSwap(l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define LittleLong
|
2005-11-04 22:32:00 +00:00
|
|
|
ID_INLINE static float BigFloat(const float l) { return FloatSwap(&l); }
|
2005-11-01 22:09:15 +00:00
|
|
|
#define LittleFloat
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Either _BIG_ENDIAN or _LITTLE_ENDIAN must be #defined, but not both."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 22:32:00 +00:00
|
|
|
//================================================================== Q3VM ===
|
|
|
|
|
|
|
|
#ifdef Q3_VM
|
|
|
|
|
|
|
|
#define ID_INLINE
|
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
#define OS_STRING "q3vm"
|
|
|
|
#define ARCH_STRING "bytecode"
|
2005-11-04 22:32:00 +00:00
|
|
|
|
|
|
|
#define PATH_SEP '/'
|
|
|
|
|
|
|
|
#define LittleShort
|
|
|
|
#define LittleLong
|
|
|
|
#define LittleFloat
|
|
|
|
#define BigShort
|
|
|
|
#define BigLong
|
|
|
|
#define BigFloat
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//===========================================================================
|
2005-11-01 22:09:15 +00:00
|
|
|
|
|
|
|
//catch missing defines in above blocks
|
2005-11-05 00:29:40 +00:00
|
|
|
#if !defined( OS_STRING ) || !defined( ARCH_STRING )
|
|
|
|
#error "OS_STRING or ARCH_STRING not defined"
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ID_INLINE
|
|
|
|
#error "ID_INLINE not defined"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PATH_SEP
|
|
|
|
#error "PATH_SEP not defined"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(BigLong) && !defined(LittleLong)
|
|
|
|
#error "Endianness not defined"
|
|
|
|
#endif
|
|
|
|
|
2005-11-05 00:29:40 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING
|
|
|
|
#else
|
|
|
|
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug"
|
|
|
|
#endif
|
|
|
|
|
2005-11-01 22:09:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|