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.25 by gbeauche, 2004-02-25T22:02:59Z

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines