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.1 by cebix, 2002-02-04T16:58:13Z vs.
Revision 1.29 by gbeauche, 2004-05-19T21:23:15Z

# 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 59 | Line 63
63   # endif
64   #endif
65  
66 < // Are we using a PPC emulator or the real thing?
67 < #ifdef __powerpc__
68 < #define EMULATED_PPC 0
69 < #else
70 < #define EMULATED_PPC 1
67 < #endif
66 > // Define for external components
67 > #define SHEEPSHAVER 1
68 >
69 > // Mac and host address space are the same
70 > #define REAL_ADDRESSING 1
71  
72   #define POWERPC_ROM 1
73  
74 + #if EMULATED_PPC
75 + // Handle interrupts asynchronously?
76 + #define ASYNC_IRQ 0
77 + // Mac ROM is write protected when banked memory is used
78 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
79 + # define ROM_IS_WRITE_PROTECTED 0
80 + # define USE_SCRATCHMEM_SUBTERFUGE 1
81 + #else
82 + # define ROM_IS_WRITE_PROTECTED 1
83 + #endif
84 + // Configure PowerPC emulator
85 + #define PPC_REENTRANT_JIT 1
86 + #define PPC_CHECK_INTERRUPTS (ASYNC_IRQ ? 0 : 1)
87 + #define PPC_DECODE_CACHE 1
88 + #define PPC_FLIGHT_RECORDER 1
89 + #define PPC_PROFILE_COMPILE_TIME 0
90 + #define PPC_PROFILE_GENERIC_CALLS 0
91 + #define KPX_MAX_CPUS 1
92 + #if defined(__i386__)
93 + #define DYNGEN_ASM_OPTS 1
94 + #endif
95 + #else
96 + // Mac ROM is write protected
97 + #define ROM_IS_WRITE_PROTECTED 1
98 + #define USE_SCRATCHMEM_SUBTERFUGE 0
99 + #endif
100 +
101   // Data types
102   typedef unsigned char uint8;
103   typedef signed char int8;
# Line 92 | Line 122 | typedef long int32;
122   #if SIZEOF_LONG == 8
123   typedef unsigned long uint64;
124   typedef long int64;
125 + #define VAL64(a) (a ## l)
126 + #define UVAL64(a) (a ## ul)
127   #elif SIZEOF_LONG_LONG == 8
128   typedef unsigned long long uint64;
129   typedef long long int64;
130 + #define VAL64(a) (a ## LL)
131 + #define UVAL64(a) (a ## uLL)
132   #else
133   #error "No 8 byte type, you lose."
134   #endif
135 + #if SIZEOF_VOID_P == 4
136 + typedef uint32 uintptr;
137 + typedef int32 intptr;
138 + #elif SIZEOF_VOID_P == 8
139 + typedef uint64 uintptr;
140 + typedef int64 intptr;
141 + #else
142 + #error "Unsupported size of pointer"
143 + #endif
144 +
145 + /**
146 + *              Helper functions to byteswap data
147 + **/
148 +
149 + #if defined(__GNUC__)
150 + #if defined(__x86_64__) || defined(__i386__)
151 + // Linux/AMD64 currently has no asm optimized bswap_32() in <byteswap.h>
152 + #define opt_bswap_32 do_opt_bswap_32
153 + static inline uint32 do_opt_bswap_32(uint32 x)
154 + {
155 +  uint32 v;
156 +  __asm__ __volatile__ ("bswap %0" : "=r" (v) : "0" (x));
157 +  return v;
158 + }
159 + #endif
160 + #endif
161 +
162 + #ifdef HAVE_BYTESWAP_H
163 + #include <byteswap.h>
164 + #endif
165 +
166 + #ifdef  opt_bswap_16
167 + #undef  bswap_16
168 + #define bswap_16 opt_bswap_16
169 + #endif
170 + #ifndef bswap_16
171 + #define bswap_16 generic_bswap_16
172 + #endif
173 +
174 + static inline uint16 generic_bswap_16(uint16 x)
175 + {
176 +  return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
177 + }
178 +
179 + #ifdef  opt_bswap_32
180 + #undef  bswap_32
181 + #define bswap_32 opt_bswap_32
182 + #endif
183 + #ifndef bswap_32
184 + #define bswap_32 generic_bswap_32
185 + #endif
186 +
187 + static inline uint32 generic_bswap_32(uint32 x)
188 + {
189 +  return (((x & 0xff000000) >> 24) |
190 +                  ((x & 0x00ff0000) >>  8) |
191 +                  ((x & 0x0000ff00) <<  8) |
192 +                  ((x & 0x000000ff) << 24) );
193 + }
194 +
195 + #if defined(__i386__)
196 + #define opt_bswap_64 do_opt_bswap_64
197 + static inline uint64 do_opt_bswap_64(uint64 x)
198 + {
199 +  return (bswap_32(x >> 32) | (((uint64)bswap_32((uint32)x)) << 32));
200 + }
201 + #endif
202 +
203 + #ifdef  opt_bswap_64
204 + #undef  bswap_64
205 + #define bswap_64 opt_bswap_64
206 + #endif
207 + #ifndef bswap_64
208 + #define bswap_64 generic_bswap_64
209 + #endif
210 +
211 + static inline uint64 generic_bswap_64(uint64 x)
212 + {
213 +  return (((x & UVAL64(0xff00000000000000)) >> 56) |
214 +                  ((x & UVAL64(0x00ff000000000000)) >> 40) |
215 +                  ((x & UVAL64(0x0000ff0000000000)) >> 24) |
216 +                  ((x & UVAL64(0x000000ff00000000)) >>  8) |
217 +                  ((x & UVAL64(0x00000000ff000000)) <<  8) |
218 +                  ((x & UVAL64(0x0000000000ff0000)) << 24) |
219 +                  ((x & UVAL64(0x000000000000ff00)) << 40) |
220 +                  ((x & UVAL64(0x00000000000000ff)) << 56) );
221 + }
222 +
223 + #ifdef WORDS_BIGENDIAN
224 + static inline uint16 tswap16(uint16 x) { return x; }
225 + static inline uint32 tswap32(uint32 x) { return x; }
226 + static inline uint64 tswap64(uint64 x) { return x; }
227 + #else
228 + static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
229 + static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
230 + static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
231 + #endif
232 +
233 + // spin locks
234 + #ifdef __GNUC__
235 +
236 + #if defined(__powerpc__) || defined(__ppc__)
237 + #define HAVE_TEST_AND_SET 1
238 + static inline int testandset(volatile int *p)
239 + {
240 +        int ret;
241 +        __asm__ __volatile__("0:    lwarx       %0,0,%1\n"
242 +                                                 "      xor.    %0,%3,%0\n"
243 +                                                 "      bne             1f\n"
244 +                                                 "      stwcx.  %2,0,%1\n"
245 +                                                 "      bne-    0b\n"
246 +                                                 "1:    "
247 +                                                 : "=&r" (ret)
248 +                                                 : "r" (p), "r" (1), "r" (0)
249 +                                                 : "cr0", "memory");
250 +        return ret;
251 + }
252 + #endif
253 +
254 + #ifdef __i386__
255 + #define HAVE_TEST_AND_SET 1
256 + static inline int testandset(volatile int *p)
257 + {
258 +        int ret;
259 +        long int readval;
260 +        /* Note: the "xchg" instruction does not need a "lock" prefix */
261 +        __asm__ __volatile__("xchgl %0, %1"
262 +                                                 : "=r" (ret), "=m" (*p), "=a" (readval)
263 +                                                 : "0" (1), "m" (*p)
264 +                                                 : "memory");
265 +        return ret;
266 + }
267 + #endif
268 +
269 + #ifdef __s390__
270 + #define HAVE_TEST_AND_SET 1
271 + static inline int testandset(volatile int *p)
272 + {
273 +        int ret;
274 +
275 +        __asm__ __volatile__("0: cs    %0,%1,0(%2)\n"
276 +                                                 "   jl    0b"
277 +                                                 : "=&d" (ret)
278 +                                                 : "r" (1), "a" (p), "0" (*p)
279 +                                                 : "cc", "memory" );
280 +        return ret;
281 + }
282 + #endif
283 +
284 + #ifdef __alpha__
285 + #define HAVE_TEST_AND_SET 1
286 + static inline int testandset(volatile int *p)
287 + {
288 +        int ret;
289 +        unsigned long one;
290 +
291 +        __asm__ __volatile__("0:        mov 1,%2\n"
292 +                                                 "      ldl_l %0,%1\n"
293 +                                                 "      stl_c %2,%1\n"
294 +                                                 "      beq %2,1f\n"
295 +                                                 ".subsection 2\n"
296 +                                                 "1:    br 0b\n"
297 +                                                 ".previous"
298 +                                                 : "=r" (ret), "=m" (*p), "=r" (one)
299 +                                                 : "m" (*p));
300 +        return ret;
301 + }
302 + #endif
303 +
304 + #ifdef __sparc__
305 + #define HAVE_TEST_AND_SET 1
306 + static inline int testandset(volatile int *p)
307 + {
308 +        int ret;
309 +
310 +        __asm__ __volatile__("ldstub    [%1], %0"
311 +                                                 : "=r" (ret)
312 +                                                 : "r" (p)
313 +                                                 : "memory");
314 +
315 +        return (ret ? 1 : 0);
316 + }
317 + #endif
318 +
319 + #ifdef __arm__
320 + #define HAVE_TEST_AND_SET 1
321 + static inline int testandset(volatile int *p)
322 + {
323 +        register unsigned int ret;
324 +        __asm__ __volatile__("swp %0, %1, [%2]"
325 +                                                 : "=r"(ret)
326 +                                                 : "0"(1), "r"(p));
327 +        
328 +        return ret;
329 + }
330 + #endif
331 +
332 + #endif /* __GNUC__ */
333 +
334 + #if HAVE_TEST_AND_SET
335 + #define HAVE_SPINLOCKS 1
336 + typedef volatile int spinlock_t;
337 +
338 + static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
339 +
340 + static inline void spin_lock(spinlock_t *lock)
341 + {
342 +        while (testandset(lock));
343 + }
344 +
345 + static inline void spin_unlock(spinlock_t *lock)
346 + {
347 +        *lock = 0;
348 + }
349 +
350 + static inline int spin_trylock(spinlock_t *lock)
351 + {
352 +        return !testandset(lock);
353 + }
354 + #endif
355  
356   // Time data type for Time Manager emulation
357   #ifdef HAVE_CLOCK_GETTIME
# Line 106 | Line 360 | typedef struct timespec tm_time_t;
360   typedef struct timeval tm_time_t;
361   #endif
362  
363 + // Timing functions
364 + extern uint64 GetTicks_usec(void);
365 + extern void Delay_usec(uint32 usec);
366 +
367 + #if defined(HAVE_PTHREADS) || (defined(__linux__) && defined(__powerpc__))
368 + // Setup pthread attributes
369 + extern void Set_pthread_attr(pthread_attr_t *attr, int priority);
370 + #endif
371 +
372   // Various definitions
373   typedef struct rgb_color {
374          uint8           red;
# Line 114 | Line 377 | typedef struct rgb_color {
377          uint8           alpha;
378   } rgb_color;
379  
380 + // X11 display fast locks
381 + #ifdef HAVE_SPINLOCKS
382 + #define X11_LOCK_TYPE spinlock_t
383 + #define X11_LOCK_INIT SPIN_LOCK_UNLOCKED
384 + #define XDisplayLock() spin_lock(&x_display_lock)
385 + #define XDisplayUnlock() spin_unlock(&x_display_lock)
386 + #elif defined(HAVE_PTHREADS)
387 + #define X11_LOCK_TYPE pthread_mutex_t
388 + #define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
389 + #define XDisplayLock() pthread_mutex_lock(&x_display_lock);
390 + #define XDisplayUnlock() pthread_mutex_unlock(&x_display_lock);
391 + #else
392 + #define XDisplayLock()
393 + #define XDisplayUnlock()
394 + #endif
395 + #ifdef X11_LOCK_TYPE
396 + extern X11_LOCK_TYPE x_display_lock;
397 + #endif
398 +
399   // Macro for calling MacOS routines
400   #define CallMacOS(type, tvect) call_macos((uint32)tvect)
401   #define CallMacOS1(type, tvect, arg1) call_macos1((uint32)tvect, (uint32)arg1)
# Line 124 | Line 406 | typedef struct rgb_color {
406   #define CallMacOS6(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6) call_macos6((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5, (uint32)arg6)
407   #define CallMacOS7(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6, arg7) call_macos7((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5, (uint32)arg6, (uint32)arg7)
408  
409 < extern "C" uint32 call_macos(uint32 tvect);
410 < extern "C" uint32 call_macos1(uint32 tvect, uint32 arg1);
411 < extern "C" uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
412 < extern "C" uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
413 < extern "C" uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
414 < extern "C" uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
415 < extern "C" uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
416 < extern "C" uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
409 > #ifdef __cplusplus
410 > extern "C" {
411 > #endif
412 > extern uint32 call_macos(uint32 tvect);
413 > extern uint32 call_macos1(uint32 tvect, uint32 arg1);
414 > extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
415 > extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
416 > extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
417 > extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
418 > extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
419 > extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
420 > #ifdef __cplusplus
421 > }
422 > #endif
423  
424   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines