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

Comparing BasiliskII/src/Unix/sysdeps.h (file contents):
Revision 1.14 by cebix, 2000-10-09T17:05:17Z vs.
Revision 1.34 by gbeauche, 2008-01-01T09:40:33Z

# Line 1 | Line 1
1   /*
2   *  sysdeps.h - System dependent definitions for Unix
3   *
4 < *  Basilisk II (C) 1997-2000 Christian Bauer
4 > *  Basilisk II (C) 1997-2008 Christian Bauer
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 43 | Line 43
43   #include <stdlib.h>
44   #include <string.h>
45  
46 + #ifdef HAVE_PTHREADS
47 + # include <pthread.h>
48 + #endif
49 +
50   #ifdef HAVE_FCNTL_H
51   # include <fcntl.h>
52   #endif
# Line 94 | Line 98
98  
99   #endif
100  
101 < /* Direct Addressing requires Video on SEGV signals */
102 < #if DIRECT_ADDRESSING && !ENABLE_VOSF
101 > /* Direct Addressing requires Video on SEGV signals in plain X11 mode */
102 > #if DIRECT_ADDRESSING && (!ENABLE_VOSF && !USE_SDL_VIDEO)
103   # undef  ENABLE_VOSF
104   # define ENABLE_VOSF 1
105   #endif
# Line 103 | Line 107
107   /* ExtFS is supported */
108   #define SUPPORTS_EXTFS 1
109  
110 + /* BSD socket API supported */
111 + #define SUPPORTS_UDP_TUNNEL 1
112 +
113 + /* Use the CPU emulator to check for periodic tasks? */
114 + #ifdef HAVE_PTHREADS
115 + #define USE_PTHREADS_SERVICES
116 + #endif
117 + #if EMULATED_68K
118 + #if defined(__NetBSD__)
119 + #define USE_CPU_EMUL_SERVICES
120 + #endif
121 + #endif
122 + #ifdef USE_CPU_EMUL_SERVICES
123 + #undef USE_PTHREADS_SERVICES
124 + #endif
125 +
126  
127   /* Data types */
128   typedef unsigned char uint8;
# Line 148 | Line 168 | typedef int64 intptr;
168   #error "Unsupported size of pointer"
169   #endif
170  
171 + #ifndef HAVE_LOFF_T
172 + typedef off_t loff_t;
173 + #endif
174 + #ifndef HAVE_CADDR_T
175 + typedef char * caddr_t;
176 + #endif
177 +
178   /* Time data type for Time Manager emulation */
179   #ifdef HAVE_CLOCK_GETTIME
180   typedef struct timespec tm_time_t;
# Line 155 | Line 182 | typedef struct timespec tm_time_t;
182   typedef struct timeval tm_time_t;
183   #endif
184  
185 < /* Offset Mac->Unix time in seconds */
186 < #define TIME_OFFSET 0x7c25b080
185 > /* Define codes for all the float formats that we know of.
186 > * Though we only handle IEEE format.  */
187 > #define UNKNOWN_FLOAT_FORMAT 0
188 > #define IEEE_FLOAT_FORMAT 1
189 > #define VAX_FLOAT_FORMAT 2
190 > #define IBM_FLOAT_FORMAT 3
191 > #define C4X_FLOAT_FORMAT 4
192  
193   /* UAE CPU data types */
194   #define uae_s8 int8
# Line 170 | Line 202 | typedef struct timeval tm_time_t;
202   typedef uae_u32 uaecptr;
203  
204   /* Alignment restrictions */
205 < #if defined(__i386__) || defined(__powerpc__) || defined(__m68k__)
205 > #if defined(__i386__) || defined(__powerpc__) || defined(__m68k__) || defined(__x86_64__)
206   # define CPU_CAN_ACCESS_UNALIGNED
207   #endif
208  
# Line 178 | Line 210 | typedef uae_u32 uaecptr;
210   extern uint64 GetTicks_usec(void);
211   extern void Delay_usec(uint32 usec);
212  
213 + /* Spinlocks */
214 + #ifdef __GNUC__
215 +
216 + #if defined(__powerpc__) || defined(__ppc__)
217 + #define HAVE_TEST_AND_SET 1
218 + static inline int testandset(volatile int *p)
219 + {
220 +        int ret;
221 +        __asm__ __volatile__("0:    lwarx       %0,0,%1\n"
222 +                                                 "      xor.    %0,%3,%0\n"
223 +                                                 "      bne             1f\n"
224 +                                                 "      stwcx.  %2,0,%1\n"
225 +                                                 "      bne-    0b\n"
226 +                                                 "1:    "
227 +                                                 : "=&r" (ret)
228 +                                                 : "r" (p), "r" (1), "r" (0)
229 +                                                 : "cr0", "memory");
230 +        return ret;
231 + }
232 + #endif
233 +
234 + /* FIXME: SheepShaver occasionnally hangs with those locks */
235 + #if 0 && (defined(__i386__) || defined(__x86_64__))
236 + #define HAVE_TEST_AND_SET 1
237 + static inline int testandset(volatile int *p)
238 + {
239 +        long int ret;
240 +        /* Note: the "xchg" instruction does not need a "lock" prefix */
241 +        __asm__ __volatile__("xchgl %k0, %1"
242 +                                                 : "=r" (ret), "=m" (*p)
243 +                                                 : "0" (1), "m" (*p)
244 +                                                 : "memory");
245 +        return ret;
246 + }
247 + #endif
248 +
249 + #ifdef __s390__
250 + #define HAVE_TEST_AND_SET 1
251 + static inline int testandset(volatile int *p)
252 + {
253 +        int ret;
254 +
255 +        __asm__ __volatile__("0: cs    %0,%1,0(%2)\n"
256 +                                                 "   jl    0b"
257 +                                                 : "=&d" (ret)
258 +                                                 : "r" (1), "a" (p), "0" (*p)
259 +                                                 : "cc", "memory" );
260 +        return ret;
261 + }
262 + #endif
263 +
264 + #ifdef __alpha__
265 + #define HAVE_TEST_AND_SET 1
266 + static inline int testandset(volatile int *p)
267 + {
268 +        int ret;
269 +        unsigned long one;
270 +
271 +        __asm__ __volatile__("0:        mov 1,%2\n"
272 +                                                 "      ldl_l %0,%1\n"
273 +                                                 "      stl_c %2,%1\n"
274 +                                                 "      beq %2,1f\n"
275 +                                                 ".subsection 2\n"
276 +                                                 "1:    br 0b\n"
277 +                                                 ".previous"
278 +                                                 : "=r" (ret), "=m" (*p), "=r" (one)
279 +                                                 : "m" (*p));
280 +        return ret;
281 + }
282 + #endif
283 +
284 + #ifdef __sparc__
285 + #define HAVE_TEST_AND_SET 1
286 + static inline int testandset(volatile int *p)
287 + {
288 +        int ret;
289 +
290 +        __asm__ __volatile__("ldstub    [%1], %0"
291 +                                                 : "=r" (ret)
292 +                                                 : "r" (p)
293 +                                                 : "memory");
294 +
295 +        return (ret ? 1 : 0);
296 + }
297 + #endif
298 +
299 + #ifdef __arm__
300 + #define HAVE_TEST_AND_SET 1
301 + static inline int testandset(volatile int *p)
302 + {
303 +        register unsigned int ret;
304 +        __asm__ __volatile__("swp %0, %1, [%2]"
305 +                                                 : "=r"(ret)
306 +                                                 : "0"(1), "r"(p));
307 +        
308 +        return ret;
309 + }
310 + #endif
311 +
312 + #endif /* __GNUC__ */
313 +
314 + typedef volatile int spinlock_t;
315 +
316 + static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
317 +
318 + #if HAVE_TEST_AND_SET
319 + #define HAVE_SPINLOCKS 1
320 + static inline void spin_lock(spinlock_t *lock)
321 + {
322 +        while (testandset(lock));
323 + }
324 +
325 + static inline void spin_unlock(spinlock_t *lock)
326 + {
327 +        *lock = 0;
328 + }
329 +
330 + static inline int spin_trylock(spinlock_t *lock)
331 + {
332 +        return !testandset(lock);
333 + }
334 + #else
335 + static inline void spin_lock(spinlock_t *lock)
336 + {
337 + }
338 +
339 + static inline void spin_unlock(spinlock_t *lock)
340 + {
341 + }
342 +
343 + static inline int spin_trylock(spinlock_t *lock)
344 + {
345 +        return 1;
346 + }
347 + #endif
348 +
349 + /* X11 display fast locks */
350 + #ifdef HAVE_SPINLOCKS
351 + #define X11_LOCK_TYPE spinlock_t
352 + #define X11_LOCK_INIT SPIN_LOCK_UNLOCKED
353 + #define XDisplayLock() spin_lock(&x_display_lock)
354 + #define XDisplayUnlock() spin_unlock(&x_display_lock)
355 + #elif defined(HAVE_PTHREADS)
356 + #define X11_LOCK_TYPE pthread_mutex_t
357 + #define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
358 + #define XDisplayLock() pthread_mutex_lock(&x_display_lock);
359 + #define XDisplayUnlock() pthread_mutex_unlock(&x_display_lock);
360 + #else
361 + #define XDisplayLock()
362 + #define XDisplayUnlock()
363 + #endif
364 + #ifdef X11_LOCK_TYPE
365 + extern X11_LOCK_TYPE x_display_lock;
366 + #endif
367 +
368 + #ifdef HAVE_PTHREADS
369 + /* Centralized pthread attribute setup */
370 + void Set_pthread_attr(pthread_attr_t *attr, int priority);
371 + #endif
372 +
373   /* UAE CPU defines */
374   #ifdef WORDS_BIGENDIAN
375  
# Line 218 | Line 410 | static inline void do_put_mem_word(uae_u
410  
411   #else /* WORDS_BIGENDIAN */
412  
413 < #ifdef __i386__
413 > #if defined(__i386__) || defined(__x86_64__)
414  
415   /* Intel x86 */
416   #define X86_PPRO_OPT
# Line 236 | Line 428 | static inline void do_put_mem_word(uae_u
428   #else
429   static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;}
430   #endif
431 + #define HAVE_OPTIMIZED_BYTESWAP_32
432 + /* bswap doesn't affect condition codes */
433 + static inline uae_u32 do_byteswap_32(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;}
434 + #define HAVE_OPTIMIZED_BYTESWAP_16
435 + #ifdef X86_PPRO_OPT
436 + static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;}
437 + #else
438 + static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;}
439 + #endif
440  
441   #elif defined(CPU_CAN_ACCESS_UNALIGNED)
442  
# Line 257 | Line 458 | static inline void do_put_mem_word(uae_u
458  
459   #endif /* WORDS_BIGENDIAN */
460  
461 + #ifndef HAVE_OPTIMIZED_BYTESWAP_32
462 + static inline uae_u32 do_byteswap_32(uae_u32 v)
463 +        { return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); }
464 + #endif
465 +
466 + #ifndef HAVE_OPTIMIZED_BYTESWAP_16
467 + static inline uae_u32 do_byteswap_16(uae_u32 v)
468 +        { return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); }
469 + #endif
470 +
471   #define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a)))
472   #define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v))
473  
# Line 270 | Line 481 | static inline void do_put_mem_word(uae_u
481   #define ENUMNAME(name) name
482   #define write_log printf
483  
484 < #ifdef USE_COMPILER
274 < #define USE_MAPPED_MEMORY
275 < #define CAN_MAP_MEMORY
276 < #define NO_EXCEPTION_3
277 < #define NO_PREFETCH_BUFFER
278 < #else
279 < #undef USE_MAPPED_MEMORY
280 < #undef CAN_MAP_MEMORY
281 < #endif
282 <
283 < #ifdef X86_ASSEMBLY
484 > #if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY)
485   #define ASM_SYM_FOR_FUNC(a) __asm__(a)
486   #else
487   #define ASM_SYM_FOR_FUNC(a)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines