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 #ifdef Q3_VM
28 
29 #define id386 0
30 #define idppc 0
31 #define idppc_altivec 0
32 #define idsparc 0
33 
34 #else
35 
36 #if (defined _M_IX86 || defined __i386__) && !defined(C_ONLY)
37 #define id386 1
38 #else
39 #define id386 0
40 #endif
41 
42 #if (defined(powerc) || defined(powerpc) || defined(ppc) || \
43 	defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY)
44 #define idppc 1
45 #if defined(__VEC__)
46 #define idppc_altivec 1
47 #ifdef MACOS_X  // Apple's GCC does this differently than the FSF.
48 #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
49 	(vector unsigned char) (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
50 #else
51 #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
52 	(vector unsigned char) {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}
53 #endif
54 #else
55 #define idppc_altivec 0
56 #endif
57 #else
58 #define idppc 0
59 #define idppc_altivec 0
60 #endif
61 
62 #if defined(__sparc__) && !defined(C_ONLY)
63 #define idsparc 1
64 #else
65 #define idsparc 0
66 #endif
67 
68 #endif
69 
70 #ifndef __ASM_I386__ // don't include the C bits if included from qasm.h
71 
72 // for windows fastcall option
73 #define QDECL
74 
75 //================================================================= WIN32 ===
76 
77 #ifdef _WIN32
78 
79 #undef QDECL
80 #define QDECL __cdecl
81 
82 #if defined( _MSC_VER )
83 #define OS_STRING "win_msvc"
84 #elif defined __MINGW32__
85 #define OS_STRING "win_mingw"
86 #endif
87 
88 #define ID_INLINE __inline
89 #define PATH_SEP '\\'
90 
91 #if defined( _M_IX86 ) || defined( __i386__ )
92 #define ARCH_STRING "x86"
93 #elif defined _M_ALPHA
94 #define ARCH_STRING "AXP"
95 #endif
96 
97 #define Q3_LITTLE_ENDIAN
98 
99 #define DLL_EXT ".dll"
100 
101 #endif
102 
103 //============================================================== MAC OS X ===
104 
105 #if defined(MACOS_X) || defined(__APPLE_CC__)
106 
107 // make sure this is defined, just for sanity's sake...
108 #ifndef MACOS_X
109 #define MACOS_X
110 #endif
111 
112 #define OS_STRING "macosx"
113 #define ID_INLINE inline
114 #define PATH_SEP '/'
115 
116 #ifdef __ppc__
117 #define ARCH_STRING "ppc"
118 #define Q3_BIG_ENDIAN
119 #elif defined __i386__
120 #define ARCH_STRING "i386"
121 #define Q3_LITTLE_ENDIAN
122 #endif
123 
124 #define DLL_EXT ".dylib"
125 
126 #endif
127 
128 //================================================================= LINUX ===
129 
130 #ifdef __linux__
131 
132 #include <endian.h>
133 
134 #define OS_STRING "linux"
135 #define ID_INLINE inline
136 #define PATH_SEP '/'
137 
138 #if defined __i386__
139 #define ARCH_STRING "i386"
140 #elif defined __x86_64__
141 #define ARCH_STRING "x86_64"
142 #elif defined __powerpc64__
143 #define ARCH_STRING "ppc64"
144 #elif defined __powerpc__
145 #define ARCH_STRING "ppc"
146 #elif defined __s390__
147 #define ARCH_STRING "s390"
148 #elif defined __s390x__
149 #define ARCH_STRING "s390x"
150 #elif defined __ia64__
151 #define ARCH_STRING "ia64"
152 #elif defined __alpha__
153 #define ARCH_STRING "alpha"
154 #elif defined __sparc__
155 #define ARCH_STRING "sparc"
156 #elif defined __arm__
157 #define ARCH_STRING "arm"
158 #elif defined __cris__
159 #define ARCH_STRING "cris"
160 #elif defined __hppa__
161 #define ARCH_STRING "hppa"
162 #elif defined __mips__
163 #define ARCH_STRING "mips"
164 #elif defined __sh__
165 #define ARCH_STRING "sh"
166 #endif
167 
168 #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
169 #define Q3_BIG_ENDIAN
170 #else
171 #define Q3_LITTLE_ENDIAN
172 #endif
173 
174 #define DLL_EXT ".so"
175 
176 #endif
177 
178 //=================================================================== BSD ===
179 
180 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
181  || defined(__DragonFly__)
182 
183 #include <sys/types.h>
184 #include <machine/endian.h>
185 
186 #ifndef __BSD__
187   #define __BSD__
188 #endif
189 
190 #if defined(__FreeBSD__) || defined(__DragonFly__)
191 #define OS_STRING "freebsd"
192 #elif defined(__OpenBSD__)
193 #define OS_STRING "openbsd"
194 #elif defined(__NetBSD__)
195 #define OS_STRING "netbsd"
196 #endif
197 
198 #define ID_INLINE inline
199 #define PATH_SEP '/'
200 
201 #ifdef __i386__
202 #define ARCH_STRING "i386"
203 #elif defined __amd64__
204 #define ARCH_STRING "amd64"
205 #elif defined __axp__
206 #define ARCH_STRING "alpha"
207 #elif defined __powerpc64__
208 #define ARCH_STRING "ppc64"
209 #elif defined __powerpc__
210 #define ARCH_STRING "ppc"
211 #endif
212 
213 #if BYTE_ORDER == BIG_ENDIAN
214 #define Q3_BIG_ENDIAN
215 #else
216 #define Q3_LITTLE_ENDIAN
217 #endif
218 
219 #define DLL_EXT ".so"
220 
221 #endif
222 
223 //================================================================= SUNOS ===
224 
225 #ifdef __sun
226 
227 #include <stdint.h>
228 #include <sys/byteorder.h>
229 
230 #define OS_STRING "solaris"
231 #define ID_INLINE inline
232 #define PATH_SEP '/'
233 
234 #ifdef __i386__
235 #define ARCH_STRING "i386"
236 #elif defined __sparc
237 #define ARCH_STRING "sparc"
238 #endif
239 
240 #if defined( _BIG_ENDIAN )
241 #define Q3_BIG_ENDIAN
242 #elif defined( _LITTLE_ENDIAN )
243 #define Q3_LITTLE_ENDIAN
244 #endif
245 
246 #define DLL_EXT ".so"
247 
248 #endif
249 
250 //================================================================== IRIX ===
251 
252 #ifdef __sgi
253 
254 #define OS_STRING "irix"
255 #define ID_INLINE __inline
256 #define PATH_SEP '/'
257 
258 #define ARCH_STRING "mips"
259 
260 #define Q3_BIG_ENDIAN // SGI's MIPS are always big endian
261 
262 #define DLL_EXT ".so"
263 
264 #endif
265 
266 //================================================================== Q3VM ===
267 
268 #ifdef Q3_VM
269 
270 #define OS_STRING "q3vm"
271 #define ID_INLINE
272 #define PATH_SEP '/'
273 
274 #define ARCH_STRING "bytecode"
275 
276 #define DLL_EXT ".qvm"
277 
278 #endif
279 
280 //===========================================================================
281 
282 //catch missing defines in above blocks
283 #if !defined( OS_STRING )
284 #error "Operating system not supported"
285 #endif
286 
287 #if !defined( ARCH_STRING )
288 #error "Architecture not supported"
289 #endif
290 
291 #ifndef ID_INLINE
292 #error "ID_INLINE not defined"
293 #endif
294 
295 #ifndef PATH_SEP
296 #error "PATH_SEP not defined"
297 #endif
298 
299 #ifndef DLL_EXT
300 #error "DLL_EXT not defined"
301 #endif
302 
303 
304 //endianness
305 short ShortSwap (short l);
306 int LongSwap (int l);
307 float FloatSwap (const float *f);
308 
309 #if defined( Q3_BIG_ENDIAN ) && defined( Q3_LITTLE_ENDIAN )
310 #error "Endianness defined as both big and little"
311 #elif defined( Q3_BIG_ENDIAN )
312 
313 #define LittleShort(x) ShortSwap(x)
314 #define LittleLong(x) LongSwap(x)
315 #define LittleFloat(x) FloatSwap(&x)
316 #define BigShort
317 #define BigLong
318 #define BigFloat
319 
320 #elif defined( Q3_LITTLE_ENDIAN )
321 
322 #define LittleShort
323 #define LittleLong
324 #define LittleFloat
325 #define BigShort(x) ShortSwap(x)
326 #define BigLong(x) LongSwap(x)
327 #define BigFloat(x) FloatSwap(&x)
328 
329 #elif defined( Q3_VM )
330 
331 #define LittleShort
332 #define LittleLong
333 #define LittleFloat
334 #define BigShort
335 #define BigLong
336 #define BigFloat
337 
338 #else
339 #error "Endianness not defined"
340 #endif
341 
342 
343 //platform string
344 #ifdef NDEBUG
345 #define PLATFORM_STRING OS_STRING "-" ARCH_STRING
346 #else
347 #define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug"
348 #endif
349 
350 #endif
351 
352 #endif
353