1 |
|
/* |
2 |
|
* sysdeps.h - System dependent definitions for Linux |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
4 |
> |
* SheepShaver (C) 1997-2004 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 |
44 |
|
#include <string.h> |
45 |
|
#include <signal.h> |
46 |
|
|
47 |
+ |
#ifdef HAVE_PTHREADS |
48 |
+ |
# include <pthread.h> |
49 |
+ |
#endif |
50 |
+ |
|
51 |
|
#ifdef HAVE_FCNTL_H |
52 |
|
# include <fcntl.h> |
53 |
|
#endif |
72 |
|
#define POWERPC_ROM 1 |
73 |
|
|
74 |
|
#if EMULATED_PPC |
71 |
– |
// Handle interrupts asynchronously? |
72 |
– |
#define ASYNC_IRQ 0 |
75 |
|
// Mac ROM is write protected when banked memory is used |
76 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
77 |
|
# define ROM_IS_WRITE_PROTECTED 0 |
80 |
|
# define ROM_IS_WRITE_PROTECTED 1 |
81 |
|
#endif |
82 |
|
// Configure PowerPC emulator |
83 |
< |
#define PPC_CHECK_INTERRUPTS (ASYNC_IRQ ? 0 : 1) |
83 |
> |
#define PPC_REENTRANT_JIT 1 |
84 |
> |
#define PPC_CHECK_INTERRUPTS 1 |
85 |
|
#define PPC_DECODE_CACHE 1 |
86 |
|
#define PPC_FLIGHT_RECORDER 1 |
87 |
|
#define PPC_PROFILE_COMPILE_TIME 0 |
88 |
|
#define PPC_PROFILE_GENERIC_CALLS 0 |
89 |
|
#define KPX_MAX_CPUS 1 |
90 |
+ |
#if defined(__i386__) |
91 |
+ |
#define DYNGEN_ASM_OPTS 1 |
92 |
+ |
#endif |
93 |
|
#else |
94 |
|
// Mac ROM is write protected |
95 |
|
#define ROM_IS_WRITE_PROTECTED 1 |
145 |
|
**/ |
146 |
|
|
147 |
|
#if defined(__GNUC__) |
148 |
< |
#if defined(__x86_64__) |
148 |
> |
#if defined(__x86_64__) || defined(__i386__) |
149 |
|
// Linux/AMD64 currently has no asm optimized bswap_32() in <byteswap.h> |
150 |
|
#define opt_bswap_32 do_opt_bswap_32 |
151 |
|
static inline uint32 do_opt_bswap_32(uint32 x) |
190 |
|
((x & 0x000000ff) << 24) ); |
191 |
|
} |
192 |
|
|
193 |
+ |
#if defined(__i386__) |
194 |
+ |
#define opt_bswap_64 do_opt_bswap_64 |
195 |
+ |
static inline uint64 do_opt_bswap_64(uint64 x) |
196 |
+ |
{ |
197 |
+ |
return (bswap_32(x >> 32) | (((uint64)bswap_32((uint32)x)) << 32)); |
198 |
+ |
} |
199 |
+ |
#endif |
200 |
+ |
|
201 |
|
#ifdef opt_bswap_64 |
202 |
|
#undef bswap_64 |
203 |
|
#define bswap_64 opt_bswap_64 |
231 |
|
// spin locks |
232 |
|
#ifdef __GNUC__ |
233 |
|
|
234 |
< |
#ifdef __powerpc__ |
234 |
> |
#if defined(__powerpc__) || defined(__ppc__) |
235 |
|
#define HAVE_TEST_AND_SET 1 |
236 |
< |
static inline int testandset(int *p) |
236 |
> |
static inline int testandset(volatile int *p) |
237 |
|
{ |
238 |
|
int ret; |
239 |
< |
__asm__ __volatile__("0: lwarx %0,0,%1 ;" |
240 |
< |
" xor. %0,%3,%0;" |
241 |
< |
" bne 1f;" |
242 |
< |
" stwcx. %2,0,%1;" |
243 |
< |
" bne- 0b;" |
239 |
> |
__asm__ __volatile__("0: lwarx %0,0,%1\n" |
240 |
> |
" xor. %0,%3,%0\n" |
241 |
> |
" bne 1f\n" |
242 |
> |
" stwcx. %2,0,%1\n" |
243 |
> |
" bne- 0b\n" |
244 |
|
"1: " |
245 |
|
: "=&r" (ret) |
246 |
|
: "r" (p), "r" (1), "r" (0) |
251 |
|
|
252 |
|
#ifdef __i386__ |
253 |
|
#define HAVE_TEST_AND_SET 1 |
254 |
< |
static inline int testandset(int *p) |
254 |
> |
static inline int testandset(volatile int *p) |
255 |
|
{ |
256 |
< |
char ret; |
256 |
> |
int ret; |
257 |
|
long int readval; |
258 |
< |
|
259 |
< |
__asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0" |
260 |
< |
: "=q" (ret), "=m" (*p), "=a" (readval) |
261 |
< |
: "r" (1), "m" (*p), "a" (0) |
258 |
> |
/* Note: the "xchg" instruction does not need a "lock" prefix */ |
259 |
> |
__asm__ __volatile__("xchgl %0, %1" |
260 |
> |
: "=r" (ret), "=m" (*p), "=a" (readval) |
261 |
> |
: "0" (1), "m" (*p) |
262 |
|
: "memory"); |
263 |
|
return ret; |
264 |
|
} |
266 |
|
|
267 |
|
#ifdef __s390__ |
268 |
|
#define HAVE_TEST_AND_SET 1 |
269 |
< |
static inline int testandset(int *p) |
269 |
> |
static inline int testandset(volatile int *p) |
270 |
|
{ |
271 |
|
int ret; |
272 |
|
|
281 |
|
|
282 |
|
#ifdef __alpha__ |
283 |
|
#define HAVE_TEST_AND_SET 1 |
284 |
< |
static inline int testandset(int *p) |
284 |
> |
static inline int testandset(volatile int *p) |
285 |
|
{ |
286 |
|
int ret; |
287 |
|
unsigned long one; |
301 |
|
|
302 |
|
#ifdef __sparc__ |
303 |
|
#define HAVE_TEST_AND_SET 1 |
304 |
< |
static inline int testandset(int *p) |
304 |
> |
static inline int testandset(volatile int *p) |
305 |
|
{ |
306 |
|
int ret; |
307 |
|
|
316 |
|
|
317 |
|
#ifdef __arm__ |
318 |
|
#define HAVE_TEST_AND_SET 1 |
319 |
< |
static inline int testandset(int *p) |
319 |
> |
static inline int testandset(volatile int *p) |
320 |
|
{ |
321 |
|
register unsigned int ret; |
322 |
|
__asm__ __volatile__("swp %0, %1, [%2]" |
331 |
|
|
332 |
|
#if HAVE_TEST_AND_SET |
333 |
|
#define HAVE_SPINLOCKS 1 |
334 |
< |
typedef int spinlock_t; |
334 |
> |
typedef volatile int spinlock_t; |
335 |
|
|
336 |
|
static const spinlock_t SPIN_LOCK_UNLOCKED = 0; |
337 |
|
|
362 |
|
extern uint64 GetTicks_usec(void); |
363 |
|
extern void Delay_usec(uint32 usec); |
364 |
|
|
365 |
+ |
#if defined(HAVE_PTHREADS) || (defined(__linux__) && defined(__powerpc__)) |
366 |
|
// Setup pthread attributes |
367 |
|
extern void Set_pthread_attr(pthread_attr_t *attr, int priority); |
368 |
+ |
#endif |
369 |
|
|
370 |
|
// Various definitions |
371 |
|
typedef struct rgb_color { |
375 |
|
uint8 alpha; |
376 |
|
} rgb_color; |
377 |
|
|
378 |
+ |
// X11 display fast locks |
379 |
+ |
#ifdef HAVE_SPINLOCKS |
380 |
+ |
#define X11_LOCK_TYPE spinlock_t |
381 |
+ |
#define X11_LOCK_INIT SPIN_LOCK_UNLOCKED |
382 |
+ |
#define XDisplayLock() spin_lock(&x_display_lock) |
383 |
+ |
#define XDisplayUnlock() spin_unlock(&x_display_lock) |
384 |
+ |
#elif defined(HAVE_PTHREADS) |
385 |
+ |
#define X11_LOCK_TYPE pthread_mutex_t |
386 |
+ |
#define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER |
387 |
+ |
#define XDisplayLock() pthread_mutex_lock(&x_display_lock); |
388 |
+ |
#define XDisplayUnlock() pthread_mutex_unlock(&x_display_lock); |
389 |
+ |
#else |
390 |
+ |
#define XDisplayLock() |
391 |
+ |
#define XDisplayUnlock() |
392 |
+ |
#endif |
393 |
+ |
#ifdef X11_LOCK_TYPE |
394 |
+ |
extern X11_LOCK_TYPE x_display_lock; |
395 |
+ |
#endif |
396 |
+ |
|
397 |
|
// Macro for calling MacOS routines |
398 |
|
#define CallMacOS(type, tvect) call_macos((uint32)tvect) |
399 |
|
#define CallMacOS1(type, tvect, arg1) call_macos1((uint32)tvect, (uint32)arg1) |