ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/sysdeps.h
Revision: 1.33
Committed: 2004-06-15T21:37:22Z (20 years, 5 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.32: +5 -0 lines
Log Message:
Don't bother with predecode cache when using JIT.

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * sysdeps.h - System dependent definitions for Linux
3     *
4 cebix 1.21 * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig
5 cebix 1.1 *
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
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #ifndef SYSDEPS_H
22     #define SYSDEPS_H
23    
24     #ifndef __STDC__
25     #error "Your compiler is not ANSI. Get a real one."
26     #endif
27    
28     #include "config.h"
29     #include "user_strings_unix.h"
30    
31     #ifndef STDC_HEADERS
32     #error "You don't have ANSI C header files."
33     #endif
34    
35     #ifdef HAVE_UNISTD_H
36     # include <sys/types.h>
37     # include <unistd.h>
38     #endif
39    
40     #include <netinet/in.h>
41     #include <assert.h>
42     #include <stdio.h>
43     #include <stdlib.h>
44     #include <string.h>
45     #include <signal.h>
46    
47 gbeauche 1.24 #ifdef HAVE_PTHREADS
48     # include <pthread.h>
49     #endif
50    
51 cebix 1.1 #ifdef HAVE_FCNTL_H
52     # include <fcntl.h>
53     #endif
54    
55     #ifdef TIME_WITH_SYS_TIME
56     # include <sys/time.h>
57     # include <time.h>
58     #else
59     # ifdef HAVE_SYS_TIME_H
60     # include <sys/time.h>
61     # else
62     # include <time.h>
63     # endif
64     #endif
65    
66 gbeauche 1.5 // Define for external components
67     #define SHEEPSHAVER 1
68    
69 gbeauche 1.4 // Mac and host address space are the same
70     #define REAL_ADDRESSING 1
71    
72 gbeauche 1.5 #define POWERPC_ROM 1
73    
74     #if EMULATED_PPC
75     // Mac ROM is write protected when banked memory is used
76     #if REAL_ADDRESSING || DIRECT_ADDRESSING
77     # define ROM_IS_WRITE_PROTECTED 0
78     # define USE_SCRATCHMEM_SUBTERFUGE 1
79 cebix 1.1 #else
80 gbeauche 1.5 # define ROM_IS_WRITE_PROTECTED 1
81     #endif
82 gbeauche 1.9 // Configure PowerPC emulator
83 gbeauche 1.29 #define PPC_REENTRANT_JIT 1
84 gbeauche 1.30 #define PPC_CHECK_INTERRUPTS 1
85 gbeauche 1.14 #define PPC_DECODE_CACHE 1
86 gbeauche 1.10 #define PPC_FLIGHT_RECORDER 1
87 gbeauche 1.17 #define PPC_PROFILE_COMPILE_TIME 0
88     #define PPC_PROFILE_GENERIC_CALLS 0
89 gbeauche 1.16 #define KPX_MAX_CPUS 1
90 gbeauche 1.33 #if ENABLE_DYNGEN
91     // Don't bother with predecode cache when using JIT
92     #define PPC_ENABLE_JIT 1
93     #undef PPC_DECODE_CACHE
94     #endif
95 gbeauche 1.28 #if defined(__i386__)
96     #define DYNGEN_ASM_OPTS 1
97     #endif
98 gbeauche 1.5 #else
99     // Mac ROM is write protected
100     #define ROM_IS_WRITE_PROTECTED 1
101     #define USE_SCRATCHMEM_SUBTERFUGE 0
102 cebix 1.1 #endif
103    
104     // Data types
105     typedef unsigned char uint8;
106     typedef signed char int8;
107     #if SIZEOF_SHORT == 2
108     typedef unsigned short uint16;
109     typedef short int16;
110     #elif SIZEOF_INT == 2
111     typedef unsigned int uint16;
112     typedef int int16;
113     #else
114     #error "No 2 byte type, you lose."
115     #endif
116     #if SIZEOF_INT == 4
117     typedef unsigned int uint32;
118     typedef int int32;
119     #elif SIZEOF_LONG == 4
120     typedef unsigned long uint32;
121     typedef long int32;
122     #else
123     #error "No 4 byte type, you lose."
124     #endif
125     #if SIZEOF_LONG == 8
126     typedef unsigned long uint64;
127     typedef long int64;
128 gbeauche 1.3 #define VAL64(a) (a ## l)
129     #define UVAL64(a) (a ## ul)
130 cebix 1.1 #elif SIZEOF_LONG_LONG == 8
131     typedef unsigned long long uint64;
132     typedef long long int64;
133 gbeauche 1.3 #define VAL64(a) (a ## LL)
134     #define UVAL64(a) (a ## uLL)
135 cebix 1.1 #else
136     #error "No 8 byte type, you lose."
137     #endif
138 gbeauche 1.3 #if SIZEOF_VOID_P == 4
139     typedef uint32 uintptr;
140     typedef int32 intptr;
141     #elif SIZEOF_VOID_P == 8
142     typedef uint64 uintptr;
143     typedef int64 intptr;
144     #else
145     #error "Unsupported size of pointer"
146 gbeauche 1.5 #endif
147    
148 gbeauche 1.15 /**
149     * Helper functions to byteswap data
150     **/
151    
152     #if defined(__GNUC__)
153 gbeauche 1.23 #if defined(__x86_64__) || defined(__i386__)
154 gbeauche 1.15 // Linux/AMD64 currently has no asm optimized bswap_32() in <byteswap.h>
155     #define opt_bswap_32 do_opt_bswap_32
156     static inline uint32 do_opt_bswap_32(uint32 x)
157     {
158     uint32 v;
159     __asm__ __volatile__ ("bswap %0" : "=r" (v) : "0" (x));
160     return v;
161     }
162     #endif
163     #endif
164    
165 gbeauche 1.5 #ifdef HAVE_BYTESWAP_H
166     #include <byteswap.h>
167     #endif
168    
169 gbeauche 1.15 #ifdef opt_bswap_16
170     #undef bswap_16
171     #define bswap_16 opt_bswap_16
172     #endif
173 gbeauche 1.5 #ifndef bswap_16
174     #define bswap_16 generic_bswap_16
175     #endif
176    
177     static inline uint16 generic_bswap_16(uint16 x)
178     {
179     return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
180     }
181    
182 gbeauche 1.15 #ifdef opt_bswap_32
183     #undef bswap_32
184     #define bswap_32 opt_bswap_32
185     #endif
186 gbeauche 1.5 #ifndef bswap_32
187     #define bswap_32 generic_bswap_32
188     #endif
189    
190     static inline uint32 generic_bswap_32(uint32 x)
191     {
192     return (((x & 0xff000000) >> 24) |
193     ((x & 0x00ff0000) >> 8) |
194     ((x & 0x0000ff00) << 8) |
195     ((x & 0x000000ff) << 24) );
196     }
197 gbeauche 1.23
198     #if defined(__i386__)
199     #define opt_bswap_64 do_opt_bswap_64
200     static inline uint64 do_opt_bswap_64(uint64 x)
201     {
202     return (bswap_32(x >> 32) | (((uint64)bswap_32((uint32)x)) << 32));
203     }
204     #endif
205 gbeauche 1.5
206 gbeauche 1.15 #ifdef opt_bswap_64
207     #undef bswap_64
208     #define bswap_64 opt_bswap_64
209     #endif
210 gbeauche 1.5 #ifndef bswap_64
211     #define bswap_64 generic_bswap_64
212     #endif
213    
214     static inline uint64 generic_bswap_64(uint64 x)
215     {
216     return (((x & UVAL64(0xff00000000000000)) >> 56) |
217     ((x & UVAL64(0x00ff000000000000)) >> 40) |
218     ((x & UVAL64(0x0000ff0000000000)) >> 24) |
219     ((x & UVAL64(0x000000ff00000000)) >> 8) |
220     ((x & UVAL64(0x00000000ff000000)) << 8) |
221     ((x & UVAL64(0x0000000000ff0000)) << 24) |
222     ((x & UVAL64(0x000000000000ff00)) << 40) |
223     ((x & UVAL64(0x00000000000000ff)) << 56) );
224     }
225    
226     #ifdef WORDS_BIGENDIAN
227     static inline uint16 tswap16(uint16 x) { return x; }
228     static inline uint32 tswap32(uint32 x) { return x; }
229     static inline uint64 tswap64(uint64 x) { return x; }
230     #else
231     static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
232     static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
233     static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
234 gbeauche 1.3 #endif
235 cebix 1.1
236 gbeauche 1.6 // spin locks
237     #ifdef __GNUC__
238    
239 gbeauche 1.22 #if defined(__powerpc__) || defined(__ppc__)
240 gbeauche 1.6 #define HAVE_TEST_AND_SET 1
241 gbeauche 1.20 static inline int testandset(volatile int *p)
242 gbeauche 1.6 {
243     int ret;
244 gbeauche 1.22 __asm__ __volatile__("0: lwarx %0,0,%1\n"
245     " xor. %0,%3,%0\n"
246     " bne 1f\n"
247     " stwcx. %2,0,%1\n"
248     " bne- 0b\n"
249 gbeauche 1.6 "1: "
250     : "=&r" (ret)
251     : "r" (p), "r" (1), "r" (0)
252     : "cr0", "memory");
253     return ret;
254     }
255     #endif
256    
257 gbeauche 1.32 /* FIXME: SheepShaver occasionnally hangs with those locks */
258     #if 0 && (defined(__i386__) || defined(__x86_64__))
259 gbeauche 1.6 #define HAVE_TEST_AND_SET 1
260 gbeauche 1.20 static inline int testandset(volatile int *p)
261 gbeauche 1.6 {
262 gbeauche 1.31 long int ret;
263 gbeauche 1.20 /* Note: the "xchg" instruction does not need a "lock" prefix */
264 gbeauche 1.31 __asm__ __volatile__("xchgl %k0, %1"
265     : "=r" (ret), "=m" (*p)
266 gbeauche 1.20 : "0" (1), "m" (*p)
267 gbeauche 1.6 : "memory");
268     return ret;
269     }
270     #endif
271    
272     #ifdef __s390__
273     #define HAVE_TEST_AND_SET 1
274 gbeauche 1.20 static inline int testandset(volatile int *p)
275 gbeauche 1.6 {
276     int ret;
277    
278     __asm__ __volatile__("0: cs %0,%1,0(%2)\n"
279     " jl 0b"
280     : "=&d" (ret)
281     : "r" (1), "a" (p), "0" (*p)
282     : "cc", "memory" );
283     return ret;
284     }
285     #endif
286    
287     #ifdef __alpha__
288     #define HAVE_TEST_AND_SET 1
289 gbeauche 1.20 static inline int testandset(volatile int *p)
290 gbeauche 1.6 {
291     int ret;
292     unsigned long one;
293    
294     __asm__ __volatile__("0: mov 1,%2\n"
295     " ldl_l %0,%1\n"
296     " stl_c %2,%1\n"
297     " beq %2,1f\n"
298     ".subsection 2\n"
299     "1: br 0b\n"
300     ".previous"
301     : "=r" (ret), "=m" (*p), "=r" (one)
302     : "m" (*p));
303     return ret;
304     }
305     #endif
306    
307     #ifdef __sparc__
308     #define HAVE_TEST_AND_SET 1
309 gbeauche 1.20 static inline int testandset(volatile int *p)
310 gbeauche 1.6 {
311     int ret;
312    
313     __asm__ __volatile__("ldstub [%1], %0"
314     : "=r" (ret)
315     : "r" (p)
316     : "memory");
317    
318     return (ret ? 1 : 0);
319     }
320     #endif
321    
322     #ifdef __arm__
323     #define HAVE_TEST_AND_SET 1
324 gbeauche 1.20 static inline int testandset(volatile int *p)
325 gbeauche 1.6 {
326     register unsigned int ret;
327     __asm__ __volatile__("swp %0, %1, [%2]"
328     : "=r"(ret)
329     : "0"(1), "r"(p));
330    
331     return ret;
332     }
333     #endif
334    
335     #endif /* __GNUC__ */
336    
337 gbeauche 1.20 typedef volatile int spinlock_t;
338 gbeauche 1.6
339 gbeauche 1.8 static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
340 gbeauche 1.6
341 gbeauche 1.32 #if HAVE_TEST_AND_SET
342     #define HAVE_SPINLOCKS 1
343 gbeauche 1.6 static inline void spin_lock(spinlock_t *lock)
344     {
345     while (testandset(lock));
346     }
347    
348     static inline void spin_unlock(spinlock_t *lock)
349     {
350     *lock = 0;
351     }
352    
353     static inline int spin_trylock(spinlock_t *lock)
354     {
355     return !testandset(lock);
356     }
357 gbeauche 1.32 #else
358     static inline void spin_lock(spinlock_t *lock)
359     {
360     }
361    
362     static inline void spin_unlock(spinlock_t *lock)
363     {
364     }
365    
366     static inline int spin_trylock(spinlock_t *lock)
367     {
368     return 1;
369     }
370 gbeauche 1.6 #endif
371    
372 cebix 1.1 // Time data type for Time Manager emulation
373     #ifdef HAVE_CLOCK_GETTIME
374     typedef struct timespec tm_time_t;
375     #else
376     typedef struct timeval tm_time_t;
377     #endif
378    
379 gbeauche 1.18 // Timing functions
380     extern uint64 GetTicks_usec(void);
381     extern void Delay_usec(uint32 usec);
382    
383 gbeauche 1.25 #if defined(HAVE_PTHREADS) || (defined(__linux__) && defined(__powerpc__))
384 cebix 1.2 // Setup pthread attributes
385     extern void Set_pthread_attr(pthread_attr_t *attr, int priority);
386 gbeauche 1.24 #endif
387 cebix 1.2
388 cebix 1.1 // Various definitions
389     typedef struct rgb_color {
390     uint8 red;
391     uint8 green;
392     uint8 blue;
393     uint8 alpha;
394     } rgb_color;
395    
396 gbeauche 1.19 // X11 display fast locks
397     #ifdef HAVE_SPINLOCKS
398     #define X11_LOCK_TYPE spinlock_t
399     #define X11_LOCK_INIT SPIN_LOCK_UNLOCKED
400     #define XDisplayLock() spin_lock(&x_display_lock)
401     #define XDisplayUnlock() spin_unlock(&x_display_lock)
402     #elif defined(HAVE_PTHREADS)
403     #define X11_LOCK_TYPE pthread_mutex_t
404     #define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
405     #define XDisplayLock() pthread_mutex_lock(&x_display_lock);
406     #define XDisplayUnlock() pthread_mutex_unlock(&x_display_lock);
407     #else
408     #define XDisplayLock()
409     #define XDisplayUnlock()
410     #endif
411     #ifdef X11_LOCK_TYPE
412     extern X11_LOCK_TYPE x_display_lock;
413     #endif
414    
415 cebix 1.1 // Macro for calling MacOS routines
416     #define CallMacOS(type, tvect) call_macos((uint32)tvect)
417     #define CallMacOS1(type, tvect, arg1) call_macos1((uint32)tvect, (uint32)arg1)
418     #define CallMacOS2(type, tvect, arg1, arg2) call_macos2((uint32)tvect, (uint32)arg1, (uint32)arg2)
419     #define CallMacOS3(type, tvect, arg1, arg2, arg3) call_macos3((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3)
420     #define CallMacOS4(type, tvect, arg1, arg2, arg3, arg4) call_macos4((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4)
421     #define CallMacOS5(type, tvect, arg1, arg2, arg3, arg4, arg5) call_macos5((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5)
422     #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)
423     #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)
424    
425 gbeauche 1.3 #ifdef __cplusplus
426     extern "C" {
427     #endif
428     extern uint32 call_macos(uint32 tvect);
429     extern uint32 call_macos1(uint32 tvect, uint32 arg1);
430     extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
431     extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
432     extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
433     extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
434     extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
435     extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
436     #ifdef __cplusplus
437     }
438     #endif
439 cebix 1.1
440     #endif