--- SheepShaver/src/Unix/sysdeps.h 2003/11/24 21:20:47 1.15 +++ SheepShaver/src/Unix/sysdeps.h 2004/01/26 13:52:31 1.23 @@ -1,7 +1,7 @@ /* * sysdeps.h - System dependent definitions for Linux * - * SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig + * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,6 +81,9 @@ #define PPC_CHECK_INTERRUPTS (ASYNC_IRQ ? 0 : 1) #define PPC_DECODE_CACHE 1 #define PPC_FLIGHT_RECORDER 1 +#define PPC_PROFILE_COMPILE_TIME 0 +#define PPC_PROFILE_GENERIC_CALLS 0 +#define KPX_MAX_CPUS 1 #else // Mac ROM is write protected #define ROM_IS_WRITE_PROTECTED 1 @@ -136,7 +139,7 @@ typedef int64 intptr; **/ #if defined(__GNUC__) -#if defined(__x86_64__) +#if defined(__x86_64__) || defined(__i386__) // Linux/AMD64 currently has no asm optimized bswap_32() in #define opt_bswap_32 do_opt_bswap_32 static inline uint32 do_opt_bswap_32(uint32 x) @@ -181,6 +184,14 @@ static inline uint32 generic_bswap_32(ui ((x & 0x000000ff) << 24) ); } +#if defined(__i386__) +#define opt_bswap_64 do_opt_bswap_64 +static inline uint64 do_opt_bswap_64(uint64 x) +{ + return (bswap_32(x >> 32) | (((uint64)bswap_32((uint32)x)) << 32)); +} +#endif + #ifdef opt_bswap_64 #undef bswap_64 #define bswap_64 opt_bswap_64 @@ -214,16 +225,16 @@ static inline uint64 tswap64(uint64 x) { // spin locks #ifdef __GNUC__ -#ifdef __powerpc__ +#if defined(__powerpc__) || defined(__ppc__) #define HAVE_TEST_AND_SET 1 -static inline int testandset(int *p) +static inline int testandset(volatile int *p) { int ret; - __asm__ __volatile__("0: lwarx %0,0,%1 ;" - " xor. %0,%3,%0;" - " bne 1f;" - " stwcx. %2,0,%1;" - " bne- 0b;" + __asm__ __volatile__("0: lwarx %0,0,%1\n" + " xor. %0,%3,%0\n" + " bne 1f\n" + " stwcx. %2,0,%1\n" + " bne- 0b\n" "1: " : "=&r" (ret) : "r" (p), "r" (1), "r" (0) @@ -234,14 +245,14 @@ static inline int testandset(int *p) #ifdef __i386__ #define HAVE_TEST_AND_SET 1 -static inline int testandset(int *p) +static inline int testandset(volatile int *p) { - char ret; + int ret; long int readval; - - __asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0" - : "=q" (ret), "=m" (*p), "=a" (readval) - : "r" (1), "m" (*p), "a" (0) + /* Note: the "xchg" instruction does not need a "lock" prefix */ + __asm__ __volatile__("xchgl %0, %1" + : "=r" (ret), "=m" (*p), "=a" (readval) + : "0" (1), "m" (*p) : "memory"); return ret; } @@ -249,7 +260,7 @@ static inline int testandset(int *p) #ifdef __s390__ #define HAVE_TEST_AND_SET 1 -static inline int testandset(int *p) +static inline int testandset(volatile int *p) { int ret; @@ -264,7 +275,7 @@ static inline int testandset(int *p) #ifdef __alpha__ #define HAVE_TEST_AND_SET 1 -static inline int testandset(int *p) +static inline int testandset(volatile int *p) { int ret; unsigned long one; @@ -284,7 +295,7 @@ static inline int testandset(int *p) #ifdef __sparc__ #define HAVE_TEST_AND_SET 1 -static inline int testandset(int *p) +static inline int testandset(volatile int *p) { int ret; @@ -299,7 +310,7 @@ static inline int testandset(int *p) #ifdef __arm__ #define HAVE_TEST_AND_SET 1 -static inline int testandset(int *p) +static inline int testandset(volatile int *p) { register unsigned int ret; __asm__ __volatile__("swp %0, %1, [%2]" @@ -314,7 +325,7 @@ static inline int testandset(int *p) #if HAVE_TEST_AND_SET #define HAVE_SPINLOCKS 1 -typedef int spinlock_t; +typedef volatile int spinlock_t; static const spinlock_t SPIN_LOCK_UNLOCKED = 0; @@ -341,6 +352,10 @@ typedef struct timespec tm_time_t; typedef struct timeval tm_time_t; #endif +// Timing functions +extern uint64 GetTicks_usec(void); +extern void Delay_usec(uint32 usec); + // Setup pthread attributes extern void Set_pthread_attr(pthread_attr_t *attr, int priority); @@ -352,6 +367,25 @@ typedef struct rgb_color { uint8 alpha; } rgb_color; +// X11 display fast locks +#ifdef HAVE_SPINLOCKS +#define X11_LOCK_TYPE spinlock_t +#define X11_LOCK_INIT SPIN_LOCK_UNLOCKED +#define XDisplayLock() spin_lock(&x_display_lock) +#define XDisplayUnlock() spin_unlock(&x_display_lock) +#elif defined(HAVE_PTHREADS) +#define X11_LOCK_TYPE pthread_mutex_t +#define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER +#define XDisplayLock() pthread_mutex_lock(&x_display_lock); +#define XDisplayUnlock() pthread_mutex_unlock(&x_display_lock); +#else +#define XDisplayLock() +#define XDisplayUnlock() +#endif +#ifdef X11_LOCK_TYPE +extern X11_LOCK_TYPE x_display_lock; +#endif + // Macro for calling MacOS routines #define CallMacOS(type, tvect) call_macos((uint32)tvect) #define CallMacOS1(type, tvect, arg1) call_macos1((uint32)tvect, (uint32)arg1)