ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Windows/sysdeps.h
Revision: 1.2
Committed: 2005-03-24T23:39:19Z (19 years, 2 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.1: +8 -0 lines
Log Message:
cross-compilation fixes

File Contents

# Content
1 /*
2 * sysdeps.h - System dependent definitions for Windows
3 *
4 * SheepShaver (C) 1997-2005 Christian Bauer and Marc Hellwig
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef SYSDEPS_H
22 #define SYSDEPS_H
23
24 #ifndef __STDC__
25 #error "Your compiler is not ANSI. Get a real one."
26 #endif
27
28 #include "config.h"
29 #include "user_strings_windows.h"
30
31 #ifndef STDC_HEADERS
32 #error "You don't have ANSI C header files."
33 #endif
34
35 #include <assert.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <time.h>
41 #ifdef __WIN32__
42 #include <windows.h>
43 #endif
44 #include <sys/types.h>
45
46
47 // Define for external components
48 #define SHEEPSHAVER 1
49 #define POWERPC_ROM 1
50 #define EMULATED_PPC 1
51 #define CONFIG_WIN32 1
52
53 // Use Direct Addressing mode
54 #define DIRECT_ADDRESSING 1
55 #define NATMEM_OFFSET 0x02000000
56
57 // Mac ROM is write protected when banked memory is used
58 #if REAL_ADDRESSING || DIRECT_ADDRESSING
59 # define ROM_IS_WRITE_PROTECTED 0
60 # define USE_SCRATCHMEM_SUBTERFUGE 1
61 #else
62 # define ROM_IS_WRITE_PROTECTED 1
63 #endif
64 // Configure PowerPC emulator
65 #define PPC_REENTRANT_JIT 1
66 #define PPC_CHECK_INTERRUPTS 1
67 #define PPC_DECODE_CACHE 1
68 #define PPC_FLIGHT_RECORDER 1
69 #define PPC_PROFILE_COMPILE_TIME 0
70 #define PPC_PROFILE_GENERIC_CALLS 0
71 #define KPX_MAX_CPUS 1
72 #if ENABLE_DYNGEN
73 // Don't bother with predecode cache when using JIT
74 #define PPC_ENABLE_JIT 1
75 #undef PPC_DECODE_CACHE
76 #endif
77 #if defined(__i386__)
78 #define DYNGEN_ASM_OPTS 1
79 #endif
80
81 // Data types
82 typedef unsigned char uint8;
83 typedef signed char int8;
84 #if SIZEOF_SHORT == 2
85 typedef unsigned short uint16;
86 typedef short int16;
87 #elif SIZEOF_INT == 2
88 typedef unsigned int uint16;
89 typedef int int16;
90 #else
91 #error "No 2 byte type, you lose."
92 #endif
93 #if SIZEOF_INT == 4
94 typedef unsigned int uint32;
95 typedef int int32;
96 #elif SIZEOF_LONG == 4
97 typedef unsigned long uint32;
98 typedef long int32;
99 #else
100 #error "No 4 byte type, you lose."
101 #endif
102 #if SIZEOF_LONG == 8
103 typedef unsigned long uint64;
104 typedef long int64;
105 #define VAL64(a) (a ## l)
106 #define UVAL64(a) (a ## ul)
107 #elif SIZEOF_LONG_LONG == 8
108 typedef unsigned long long uint64;
109 typedef long long int64;
110 #define VAL64(a) (a ## LL)
111 #define UVAL64(a) (a ## uLL)
112 #else
113 #error "No 8 byte type, you lose."
114 #endif
115 #if SIZEOF_VOID_P == 4
116 typedef uint32 uintptr;
117 typedef int32 intptr;
118 #elif SIZEOF_VOID_P == 8
119 typedef uint64 uintptr;
120 typedef int64 intptr;
121 #else
122 #error "Unsupported size of pointer"
123 #endif
124
125
126 /**
127 * Helper functions to byteswap data
128 **/
129
130 #if defined(__GNUC__)
131 #if defined(__x86_64__) || defined(__i386__)
132 // Linux/AMD64 currently has no asm optimized bswap_32() in <byteswap.h>
133 #define opt_bswap_32 do_opt_bswap_32
134 static inline uint32 do_opt_bswap_32(uint32 x)
135 {
136 uint32 v;
137 __asm__ __volatile__ ("bswap %0" : "=r" (v) : "0" (x));
138 return v;
139 }
140 #endif
141 #endif
142
143 #ifdef opt_bswap_16
144 #undef bswap_16
145 #define bswap_16 opt_bswap_16
146 #endif
147 #ifndef bswap_16
148 #define bswap_16 generic_bswap_16
149 #endif
150
151 static inline uint16 generic_bswap_16(uint16 x)
152 {
153 return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
154 }
155
156 #ifdef opt_bswap_32
157 #undef bswap_32
158 #define bswap_32 opt_bswap_32
159 #endif
160 #ifndef bswap_32
161 #define bswap_32 generic_bswap_32
162 #endif
163
164 static inline uint32 generic_bswap_32(uint32 x)
165 {
166 return (((x & 0xff000000) >> 24) |
167 ((x & 0x00ff0000) >> 8) |
168 ((x & 0x0000ff00) << 8) |
169 ((x & 0x000000ff) << 24) );
170 }
171
172 #if defined(__i386__)
173 #define opt_bswap_64 do_opt_bswap_64
174 static inline uint64 do_opt_bswap_64(uint64 x)
175 {
176 return (bswap_32(x >> 32) | (((uint64)bswap_32((uint32)x)) << 32));
177 }
178 #endif
179
180 #ifdef opt_bswap_64
181 #undef bswap_64
182 #define bswap_64 opt_bswap_64
183 #endif
184 #ifndef bswap_64
185 #define bswap_64 generic_bswap_64
186 #endif
187
188 static inline uint64 generic_bswap_64(uint64 x)
189 {
190 return (((x & UVAL64(0xff00000000000000)) >> 56) |
191 ((x & UVAL64(0x00ff000000000000)) >> 40) |
192 ((x & UVAL64(0x0000ff0000000000)) >> 24) |
193 ((x & UVAL64(0x000000ff00000000)) >> 8) |
194 ((x & UVAL64(0x00000000ff000000)) << 8) |
195 ((x & UVAL64(0x0000000000ff0000)) << 24) |
196 ((x & UVAL64(0x000000000000ff00)) << 40) |
197 ((x & UVAL64(0x00000000000000ff)) << 56) );
198 }
199
200 #ifdef WORDS_BIGENDIAN
201 static inline uint16 tswap16(uint16 x) { return x; }
202 static inline uint32 tswap32(uint32 x) { return x; }
203 static inline uint64 tswap64(uint64 x) { return x; }
204 #else
205 static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
206 static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
207 static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
208 #endif
209
210 #define do_byteswap_16_g bswap_16
211 #define do_byteswap_16_c(x) \
212 ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
213
214 #define do_byteswap_32_g bswap_32
215 #define do_byteswap_32_c(x) \
216 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
217 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
218
219 #if defined(__GNUC__)
220 #define do_byteswap_16(x) \
221 (__extension__ \
222 ({ register uint16 __v, __x = (x); \
223 if (__builtin_constant_p(__x)) \
224 __v = do_byteswap_16_c(__x); \
225 else \
226 __v = do_byteswap_16_g(__x); \
227 __v; }))
228
229 #define do_byteswap_32(x) \
230 (__extension__ \
231 ({ register uint32 __v, __x = (x); \
232 if (__builtin_constant_p(__x)) \
233 __v = do_byteswap_32_c(__x); \
234 else \
235 __v = do_byteswap_32_g(__x); \
236 __v; }))
237 #else
238 #define do_byteswap_16(x) do_byteswap_16_g(x)
239 #define do_byteswap_32(x) do_byteswap_32_g(x)
240 #endif
241
242 #if defined(__i386__) || defined(__x86_64__)
243 #define ntohl(x) do_byteswap_32(x)
244 #define ntohs(x) do_byteswap_16(x)
245 #define htonl(x) do_byteswap_32(x)
246 #define htons(x) do_byteswap_16(x)
247 #endif
248
249
250 /*
251 * Spin locks
252 */
253
254 #ifdef __GNUC__
255
256 #if defined(__powerpc__) || defined(__ppc__)
257 #define HAVE_TEST_AND_SET 1
258 static inline int testandset(volatile int *p)
259 {
260 int ret;
261 __asm__ __volatile__("0: lwarx %0,0,%1\n"
262 " xor. %0,%3,%0\n"
263 " bne 1f\n"
264 " stwcx. %2,0,%1\n"
265 " bne- 0b\n"
266 "1: "
267 : "=&r" (ret)
268 : "r" (p), "r" (1), "r" (0)
269 : "cr0", "memory");
270 return ret;
271 }
272 #endif
273
274 #if defined(__i386__) || defined(__x86_64__)
275 #define HAVE_TEST_AND_SET 1
276 static inline int testandset(volatile int *p)
277 {
278 long int ret;
279 /* Note: the "xchg" instruction does not need a "lock" prefix */
280 __asm__ __volatile__("xchgl %k0, %1"
281 : "=r" (ret), "=m" (*p)
282 : "0" (1), "m" (*p)
283 : "memory");
284 return ret;
285 }
286 #endif
287
288 #ifdef __alpha__
289 #define HAVE_TEST_AND_SET 1
290 static inline int testandset(volatile int *p)
291 {
292 int ret;
293 unsigned long one;
294
295 __asm__ __volatile__("0: mov 1,%2\n"
296 " ldl_l %0,%1\n"
297 " stl_c %2,%1\n"
298 " beq %2,1f\n"
299 ".subsection 2\n"
300 "1: br 0b\n"
301 ".previous"
302 : "=r" (ret), "=m" (*p), "=r" (one)
303 : "m" (*p));
304 return ret;
305 }
306 #endif
307
308 #endif /* __GNUC__ */
309
310 typedef volatile int spinlock_t;
311
312 static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
313
314 #if HAVE_TEST_AND_SET
315 #define HAVE_SPINLOCKS 1
316 static inline void spin_lock(spinlock_t *lock)
317 {
318 while (testandset(lock));
319 }
320
321 static inline void spin_unlock(spinlock_t *lock)
322 {
323 *lock = 0;
324 }
325
326 static inline int spin_trylock(spinlock_t *lock)
327 {
328 return !testandset(lock);
329 }
330 #else
331 static inline void spin_lock(spinlock_t *lock)
332 {
333 }
334
335 static inline void spin_unlock(spinlock_t *lock)
336 {
337 }
338
339 static inline int spin_trylock(spinlock_t *lock)
340 {
341 return 1;
342 }
343 #endif
344
345 // Time data type for Time Manager emulation
346 typedef int64 tm_time_t;
347
348 // Timing functions
349 extern void timer_init(void);
350 extern uint64 GetTicks_usec(void);
351 extern void Delay_usec(uint32 usec);
352
353 // Various definitions
354 typedef struct rgb_color {
355 uint8 red;
356 uint8 green;
357 uint8 blue;
358 uint8 alpha;
359 } rgb_color;
360
361 // Macro for calling MacOS routines
362 #define CallMacOS(type, tvect) call_macos((uintptr)tvect)
363 #define CallMacOS1(type, tvect, arg1) call_macos1((uintptr)tvect, (uintptr)arg1)
364 #define CallMacOS2(type, tvect, arg1, arg2) call_macos2((uintptr)tvect, (uintptr)arg1, (uintptr)arg2)
365 #define CallMacOS3(type, tvect, arg1, arg2, arg3) call_macos3((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3)
366 #define CallMacOS4(type, tvect, arg1, arg2, arg3, arg4) call_macos4((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4)
367 #define CallMacOS5(type, tvect, arg1, arg2, arg3, arg4, arg5) call_macos5((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4, (uintptr)arg5)
368 #define CallMacOS6(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6) call_macos6((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4, (uintptr)arg5, (uintptr)arg6)
369 #define CallMacOS7(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6, arg7) call_macos7((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4, (uintptr)arg5, (uintptr)arg6, (uintptr)arg7)
370
371 #ifdef __cplusplus
372 extern "C" {
373 #endif
374 extern uint32 call_macos(uint32 tvect);
375 extern uint32 call_macos1(uint32 tvect, uint32 arg1);
376 extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
377 extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
378 extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
379 extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
380 extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
381 extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
382 #ifdef __cplusplus
383 }
384 #endif
385
386 // Misc platform specific definitions
387 #ifdef __WIN32__
388 typedef int64 loff_t;
389 #endif
390 #define ATTRIBUTE_PACKED __attribute__((__packed__))
391
392 #endif