ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/sysdeps.h
(Generate patch)

Comparing SheepShaver/src/Unix/sysdeps.h (file contents):
Revision 1.7 by gbeauche, 2003-09-29T15:46:07Z vs.
Revision 1.32 by gbeauche, 2004-06-02T16:11:49Z

# Line 1 | Line 1
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
# Line 44 | Line 44
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
# Line 68 | Line 72
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
# Line 77 | Line 79
79   #else
80   # define ROM_IS_WRITE_PROTECTED 1
81   #endif
82 + // Configure PowerPC emulator
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
# Line 127 | Line 140 | typedef int64 intptr;
140   #error "Unsupported size of pointer"
141   #endif
142  
143 < // Helper functions to byteswap data
143 > /**
144 > *              Helper functions to byteswap data
145 > **/
146 >
147 > #if defined(__GNUC__)
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)
152 > {
153 >  uint32 v;
154 >  __asm__ __volatile__ ("bswap %0" : "=r" (v) : "0" (x));
155 >  return v;
156 > }
157 > #endif
158 > #endif
159 >
160   #ifdef HAVE_BYTESWAP_H
161   #include <byteswap.h>
162   #endif
163  
164 + #ifdef  opt_bswap_16
165 + #undef  bswap_16
166 + #define bswap_16 opt_bswap_16
167 + #endif
168   #ifndef bswap_16
169   #define bswap_16 generic_bswap_16
170   #endif
# Line 141 | Line 174 | static inline uint16 generic_bswap_16(ui
174    return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
175   }
176  
177 + #ifdef  opt_bswap_32
178 + #undef  bswap_32
179 + #define bswap_32 opt_bswap_32
180 + #endif
181   #ifndef bswap_32
182   #define bswap_32 generic_bswap_32
183   #endif
# Line 153 | Line 190 | static inline uint32 generic_bswap_32(ui
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
204 + #endif
205   #ifndef bswap_64
206   #define bswap_64 generic_bswap_64
207   #endif
# Line 182 | Line 231 | static inline uint64 tswap64(uint64 x) {
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)
# Line 200 | Line 249 | static inline int testandset(int *p)
249   }
250   #endif
251  
252 < #ifdef __i386__
252 > /* FIXME: SheepShaver occasionnally hangs with those locks */
253 > #if 0 && (defined(__i386__) || defined(__x86_64__))
254   #define HAVE_TEST_AND_SET 1
255 < static inline int testandset(int *p)
255 > static inline int testandset(volatile int *p)
256   {
257 <        char ret;
258 <        long int readval;
259 <        
260 <        __asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0"
261 <                                                 : "=q" (ret), "=m" (*p), "=a" (readval)
212 <                                                 : "r" (1), "m" (*p), "a" (0)
257 >        long int ret;
258 >        /* Note: the "xchg" instruction does not need a "lock" prefix */
259 >        __asm__ __volatile__("xchgl %k0, %1"
260 >                                                 : "=r" (ret), "=m" (*p)
261 >                                                 : "0" (1), "m" (*p)
262                                                   : "memory");
263          return ret;
264   }
# Line 217 | Line 266 | static inline int testandset(int *p)
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  
# Line 232 | Line 281 | static inline int testandset(int *p)
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;
# Line 252 | Line 301 | static inline int testandset(int *p)
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  
# Line 267 | Line 316 | static inline int testandset(int *p)
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]"
# Line 280 | Line 329 | static inline int testandset(int *p)
329  
330   #endif /* __GNUC__ */
331  
332 < #if HAVE_TEST_AND_SET
284 < #define HAVE_SPINLOCKS 1
285 < typedef int spinlock_t;
332 > typedef volatile int spinlock_t;
333  
334 < const spinlock_t SPIN_LOCK_UNLOCKED = 0;
334 > static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
335  
336 + #if HAVE_TEST_AND_SET
337 + #define HAVE_SPINLOCKS 1
338   static inline void spin_lock(spinlock_t *lock)
339   {
340          while (testandset(lock));
# Line 300 | Line 349 | static inline int spin_trylock(spinlock_
349   {
350          return !testandset(lock);
351   }
352 + #else
353 + static inline void spin_lock(spinlock_t *lock)
354 + {
355 + }
356 +
357 + static inline void spin_unlock(spinlock_t *lock)
358 + {
359 + }
360 +
361 + static inline int spin_trylock(spinlock_t *lock)
362 + {
363 +        return 1;
364 + }
365   #endif
366  
367   // Time data type for Time Manager emulation
# Line 309 | Line 371 | typedef struct timespec tm_time_t;
371   typedef struct timeval tm_time_t;
372   #endif
373  
374 + // Timing functions
375 + extern uint64 GetTicks_usec(void);
376 + extern void Delay_usec(uint32 usec);
377 +
378 + #if defined(HAVE_PTHREADS) || (defined(__linux__) && defined(__powerpc__))
379   // Setup pthread attributes
380   extern void Set_pthread_attr(pthread_attr_t *attr, int priority);
381 + #endif
382  
383   // Various definitions
384   typedef struct rgb_color {
# Line 320 | Line 388 | typedef struct rgb_color {
388          uint8           alpha;
389   } rgb_color;
390  
391 + // X11 display fast locks
392 + #ifdef HAVE_SPINLOCKS
393 + #define X11_LOCK_TYPE spinlock_t
394 + #define X11_LOCK_INIT SPIN_LOCK_UNLOCKED
395 + #define XDisplayLock() spin_lock(&x_display_lock)
396 + #define XDisplayUnlock() spin_unlock(&x_display_lock)
397 + #elif defined(HAVE_PTHREADS)
398 + #define X11_LOCK_TYPE pthread_mutex_t
399 + #define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
400 + #define XDisplayLock() pthread_mutex_lock(&x_display_lock);
401 + #define XDisplayUnlock() pthread_mutex_unlock(&x_display_lock);
402 + #else
403 + #define XDisplayLock()
404 + #define XDisplayUnlock()
405 + #endif
406 + #ifdef X11_LOCK_TYPE
407 + extern X11_LOCK_TYPE x_display_lock;
408 + #endif
409 +
410   // Macro for calling MacOS routines
411   #define CallMacOS(type, tvect) call_macos((uint32)tvect)
412   #define CallMacOS1(type, tvect, arg1) call_macos1((uint32)tvect, (uint32)arg1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines