--- BasiliskII/src/Unix/sysdeps.h 1999/10/27 17:50:07 1.8 +++ BasiliskII/src/Unix/sysdeps.h 2005/01/30 21:42:14 1.32 @@ -1,7 +1,7 @@ /* * sysdeps.h - System dependent definitions for Unix * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2005 Christian Bauer * * 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 @@ -42,7 +42,10 @@ #include #include #include -#include + +#ifdef HAVE_PTHREADS +# include +#endif #ifdef HAVE_FCNTL_H # include @@ -60,18 +63,54 @@ #endif -/* Are the Mac and the host address space the same? */ +#ifdef ENABLE_NATIVE_M68K + +/* Mac and host address space are the same */ +#define REAL_ADDRESSING 1 + +/* Using 68k natively */ +#define EMULATED_68K 0 + +/* Mac ROM is not write protected */ +#define ROM_IS_WRITE_PROTECTED 0 +#define USE_SCRATCHMEM_SUBTERFUGE 1 + +#else + +/* Mac and host address space are distinct */ +#ifndef REAL_ADDRESSING #define REAL_ADDRESSING 0 +#endif -/* Are we using a 68k emulator or the real thing? */ +/* Using 68k emulator */ #define EMULATED_68K 1 -/* Is the Mac ROM write protected? */ -#define ROM_IS_WRITE_PROTECTED 1 +/* The m68k emulator uses a prefetch buffer ? */ +#define USE_PREFETCH_BUFFER 0 + +/* Mac ROM is write protected when banked memory is used */ +#if REAL_ADDRESSING || DIRECT_ADDRESSING +# define ROM_IS_WRITE_PROTECTED 0 +# define USE_SCRATCHMEM_SUBTERFUGE 1 +#else +# define ROM_IS_WRITE_PROTECTED 1 +#endif + +#endif + +/* Direct Addressing requires Video on SEGV signals in plain X11 mode */ +#if DIRECT_ADDRESSING && (!ENABLE_VOSF && !USE_SDL_VIDEO) +# undef ENABLE_VOSF +# define ENABLE_VOSF 1 +#endif /* ExtFS is supported */ #define SUPPORTS_EXTFS 1 +/* BSD socket API supported */ +#define SUPPORTS_UDP_TUNNEL 1 + + /* Data types */ typedef unsigned char uint8; typedef signed char int8; @@ -106,6 +145,22 @@ typedef long long int64; #else #error "No 8 byte type, you lose." #endif +#if SIZEOF_VOID_P == 4 +typedef uint32 uintptr; +typedef int32 intptr; +#elif SIZEOF_VOID_P == 8 +typedef uint64 uintptr; +typedef int64 intptr; +#else +#error "Unsupported size of pointer" +#endif + +#ifndef HAVE_LOFF_T +typedef off_t loff_t; +#endif +#ifndef HAVE_CADDR_T +typedef char * caddr_t; +#endif /* Time data type for Time Manager emulation */ #ifdef HAVE_CLOCK_GETTIME @@ -114,8 +169,13 @@ typedef struct timespec tm_time_t; typedef struct timeval tm_time_t; #endif -/* Offset Mac->Unix time in seconds */ -#define TIME_OFFSET 0x7c25b080 +/* Define codes for all the float formats that we know of. + * Though we only handle IEEE format. */ +#define UNKNOWN_FLOAT_FORMAT 0 +#define IEEE_FLOAT_FORMAT 1 +#define VAX_FLOAT_FORMAT 2 +#define IBM_FLOAT_FORMAT 3 +#define C4X_FLOAT_FORMAT 4 /* UAE CPU data types */ #define uae_s8 int8 @@ -129,10 +189,174 @@ typedef struct timeval tm_time_t; typedef uae_u32 uaecptr; /* Alignment restrictions */ -#if defined(__i386__) || defined(__powerpc__) || defined(__m68k__) +#if defined(__i386__) || defined(__powerpc__) || defined(__m68k__) || defined(__x86_64__) # define CPU_CAN_ACCESS_UNALIGNED #endif +/* Timing functions */ +extern uint64 GetTicks_usec(void); +extern void Delay_usec(uint32 usec); + +/* Spinlocks */ +#ifdef __GNUC__ + +#if defined(__powerpc__) || defined(__ppc__) +#define HAVE_TEST_AND_SET 1 +static inline int testandset(volatile int *p) +{ + int ret; + __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) + : "cr0", "memory"); + return ret; +} +#endif + +/* FIXME: SheepShaver occasionnally hangs with those locks */ +#if 0 && (defined(__i386__) || defined(__x86_64__)) +#define HAVE_TEST_AND_SET 1 +static inline int testandset(volatile int *p) +{ + long int ret; + /* Note: the "xchg" instruction does not need a "lock" prefix */ + __asm__ __volatile__("xchgl %k0, %1" + : "=r" (ret), "=m" (*p) + : "0" (1), "m" (*p) + : "memory"); + return ret; +} +#endif + +#ifdef __s390__ +#define HAVE_TEST_AND_SET 1 +static inline int testandset(volatile int *p) +{ + int ret; + + __asm__ __volatile__("0: cs %0,%1,0(%2)\n" + " jl 0b" + : "=&d" (ret) + : "r" (1), "a" (p), "0" (*p) + : "cc", "memory" ); + return ret; +} +#endif + +#ifdef __alpha__ +#define HAVE_TEST_AND_SET 1 +static inline int testandset(volatile int *p) +{ + int ret; + unsigned long one; + + __asm__ __volatile__("0: mov 1,%2\n" + " ldl_l %0,%1\n" + " stl_c %2,%1\n" + " beq %2,1f\n" + ".subsection 2\n" + "1: br 0b\n" + ".previous" + : "=r" (ret), "=m" (*p), "=r" (one) + : "m" (*p)); + return ret; +} +#endif + +#ifdef __sparc__ +#define HAVE_TEST_AND_SET 1 +static inline int testandset(volatile int *p) +{ + int ret; + + __asm__ __volatile__("ldstub [%1], %0" + : "=r" (ret) + : "r" (p) + : "memory"); + + return (ret ? 1 : 0); +} +#endif + +#ifdef __arm__ +#define HAVE_TEST_AND_SET 1 +static inline int testandset(volatile int *p) +{ + register unsigned int ret; + __asm__ __volatile__("swp %0, %1, [%2]" + : "=r"(ret) + : "0"(1), "r"(p)); + + return ret; +} +#endif + +#endif /* __GNUC__ */ + +typedef volatile int spinlock_t; + +static const spinlock_t SPIN_LOCK_UNLOCKED = 0; + +#if HAVE_TEST_AND_SET +#define HAVE_SPINLOCKS 1 +static inline void spin_lock(spinlock_t *lock) +{ + while (testandset(lock)); +} + +static inline void spin_unlock(spinlock_t *lock) +{ + *lock = 0; +} + +static inline int spin_trylock(spinlock_t *lock) +{ + return !testandset(lock); +} +#else +static inline void spin_lock(spinlock_t *lock) +{ +} + +static inline void spin_unlock(spinlock_t *lock) +{ +} + +static inline int spin_trylock(spinlock_t *lock) +{ + return 1; +} +#endif + +/* 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 + +#ifdef HAVE_PTHREADS +/* Centralized pthread attribute setup */ +void Set_pthread_attr(pthread_attr_t *attr, int priority); +#endif + /* UAE CPU defines */ #ifdef WORDS_BIGENDIAN @@ -173,7 +397,7 @@ static inline void do_put_mem_word(uae_u #else /* WORDS_BIGENDIAN */ -#ifdef __i386__ +#if defined(__i386__) || defined(__x86_64__) /* Intel x86 */ #define X86_PPRO_OPT @@ -191,6 +415,15 @@ static inline void do_put_mem_word(uae_u #else static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;} #endif +#define HAVE_OPTIMIZED_BYTESWAP_32 +/* bswap doesn't affect condition codes */ +static inline uae_u32 do_byteswap_32(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;} +#define HAVE_OPTIMIZED_BYTESWAP_16 +#ifdef X86_PPRO_OPT +static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;} +#else +static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;} +#endif #elif defined(CPU_CAN_ACCESS_UNALIGNED) @@ -212,6 +445,16 @@ static inline void do_put_mem_word(uae_u #endif /* WORDS_BIGENDIAN */ +#ifndef HAVE_OPTIMIZED_BYTESWAP_32 +static inline uae_u32 do_byteswap_32(uae_u32 v) + { return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); } +#endif + +#ifndef HAVE_OPTIMIZED_BYTESWAP_16 +static inline uae_u32 do_byteswap_16(uae_u32 v) + { return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); } +#endif + #define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a))) #define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v)) @@ -219,16 +462,13 @@ static inline void do_put_mem_word(uae_u #define call_mem_put_func(func, addr, v) ((*func)(addr, v)) #define __inline__ inline #define CPU_EMU_SIZE 0 -#undef USE_MAPPED_MEMORY -#undef CAN_MAP_MEMORY #undef NO_INLINE_MEMORY_ACCESS #undef MD_HAVE_MEM_1_FUNCS -#undef USE_COMPILER #define ENUMDECL typedef enum #define ENUMNAME(name) name #define write_log printf -#ifdef X86_ASSEMBLY +#if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) #define ASM_SYM_FOR_FUNC(a) __asm__(a) #else #define ASM_SYM_FOR_FUNC(a)