ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/sysdeps.h
Revision: 1.10
Committed: 2003-10-11T09:57:49Z (21 years, 1 month ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.9: +1 -2 lines
Log Message:
- Add support for FLIGHT_RECORDER with predecode cache
- Always enable predecode cache & flight recorder for now

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * sysdeps.h - System dependent definitions for Linux
3     *
4     * SheepShaver (C) 1997-2002 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
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     #ifdef HAVE_FCNTL_H
48     # include <fcntl.h>
49     #endif
50    
51     #ifdef TIME_WITH_SYS_TIME
52     # include <sys/time.h>
53     # include <time.h>
54     #else
55     # ifdef HAVE_SYS_TIME_H
56     # include <sys/time.h>
57     # else
58     # include <time.h>
59     # endif
60     #endif
61    
62 gbeauche 1.5 // Define for external components
63     #define SHEEPSHAVER 1
64    
65 gbeauche 1.4 // Mac and host address space are the same
66     #define REAL_ADDRESSING 1
67    
68 gbeauche 1.5 #define POWERPC_ROM 1
69    
70     #if EMULATED_PPC
71 gbeauche 1.7 // Handle interrupts asynchronously?
72     #define ASYNC_IRQ 0
73 gbeauche 1.5 // Mac ROM is write protected when banked memory is used
74     #if REAL_ADDRESSING || DIRECT_ADDRESSING
75     # define ROM_IS_WRITE_PROTECTED 0
76     # define USE_SCRATCHMEM_SUBTERFUGE 1
77 cebix 1.1 #else
78 gbeauche 1.5 # define ROM_IS_WRITE_PROTECTED 1
79     #endif
80 gbeauche 1.9 // Configure PowerPC emulator
81     #define PPC_NO_LAZY_PC_UPDATE 1
82 gbeauche 1.10 #define PPC_FLIGHT_RECORDER 1
83 gbeauche 1.5 #else
84     // Mac ROM is write protected
85     #define ROM_IS_WRITE_PROTECTED 1
86     #define USE_SCRATCHMEM_SUBTERFUGE 0
87 cebix 1.1 #endif
88    
89     // Data types
90     typedef unsigned char uint8;
91     typedef signed char int8;
92     #if SIZEOF_SHORT == 2
93     typedef unsigned short uint16;
94     typedef short int16;
95     #elif SIZEOF_INT == 2
96     typedef unsigned int uint16;
97     typedef int int16;
98     #else
99     #error "No 2 byte type, you lose."
100     #endif
101     #if SIZEOF_INT == 4
102     typedef unsigned int uint32;
103     typedef int int32;
104     #elif SIZEOF_LONG == 4
105     typedef unsigned long uint32;
106     typedef long int32;
107     #else
108     #error "No 4 byte type, you lose."
109     #endif
110     #if SIZEOF_LONG == 8
111     typedef unsigned long uint64;
112     typedef long int64;
113 gbeauche 1.3 #define VAL64(a) (a ## l)
114     #define UVAL64(a) (a ## ul)
115 cebix 1.1 #elif SIZEOF_LONG_LONG == 8
116     typedef unsigned long long uint64;
117     typedef long long int64;
118 gbeauche 1.3 #define VAL64(a) (a ## LL)
119     #define UVAL64(a) (a ## uLL)
120 cebix 1.1 #else
121     #error "No 8 byte type, you lose."
122     #endif
123 gbeauche 1.3 #if SIZEOF_VOID_P == 4
124     typedef uint32 uintptr;
125     typedef int32 intptr;
126     #elif SIZEOF_VOID_P == 8
127     typedef uint64 uintptr;
128     typedef int64 intptr;
129     #else
130     #error "Unsupported size of pointer"
131 gbeauche 1.5 #endif
132    
133     // Helper functions to byteswap data
134     #ifdef HAVE_BYTESWAP_H
135     #include <byteswap.h>
136     #endif
137    
138     #ifndef bswap_16
139     #define bswap_16 generic_bswap_16
140     #endif
141    
142     static inline uint16 generic_bswap_16(uint16 x)
143     {
144     return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
145     }
146    
147     #ifndef bswap_32
148     #define bswap_32 generic_bswap_32
149     #endif
150    
151     static inline uint32 generic_bswap_32(uint32 x)
152     {
153     return (((x & 0xff000000) >> 24) |
154     ((x & 0x00ff0000) >> 8) |
155     ((x & 0x0000ff00) << 8) |
156     ((x & 0x000000ff) << 24) );
157     }
158    
159     #ifndef bswap_64
160     #define bswap_64 generic_bswap_64
161     #endif
162    
163     static inline uint64 generic_bswap_64(uint64 x)
164     {
165     return (((x & UVAL64(0xff00000000000000)) >> 56) |
166     ((x & UVAL64(0x00ff000000000000)) >> 40) |
167     ((x & UVAL64(0x0000ff0000000000)) >> 24) |
168     ((x & UVAL64(0x000000ff00000000)) >> 8) |
169     ((x & UVAL64(0x00000000ff000000)) << 8) |
170     ((x & UVAL64(0x0000000000ff0000)) << 24) |
171     ((x & UVAL64(0x000000000000ff00)) << 40) |
172     ((x & UVAL64(0x00000000000000ff)) << 56) );
173     }
174    
175     #ifdef WORDS_BIGENDIAN
176     static inline uint16 tswap16(uint16 x) { return x; }
177     static inline uint32 tswap32(uint32 x) { return x; }
178     static inline uint64 tswap64(uint64 x) { return x; }
179     #else
180     static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
181     static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
182     static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
183 gbeauche 1.3 #endif
184 cebix 1.1
185 gbeauche 1.6 // spin locks
186     #ifdef __GNUC__
187    
188     #ifdef __powerpc__
189     #define HAVE_TEST_AND_SET 1
190     static inline int testandset(int *p)
191     {
192     int ret;
193     __asm__ __volatile__("0: lwarx %0,0,%1 ;"
194     " xor. %0,%3,%0;"
195     " bne 1f;"
196     " stwcx. %2,0,%1;"
197     " bne- 0b;"
198     "1: "
199     : "=&r" (ret)
200     : "r" (p), "r" (1), "r" (0)
201     : "cr0", "memory");
202     return ret;
203     }
204     #endif
205    
206     #ifdef __i386__
207     #define HAVE_TEST_AND_SET 1
208     static inline int testandset(int *p)
209     {
210     char ret;
211     long int readval;
212    
213     __asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0"
214     : "=q" (ret), "=m" (*p), "=a" (readval)
215     : "r" (1), "m" (*p), "a" (0)
216     : "memory");
217     return ret;
218     }
219     #endif
220    
221     #ifdef __s390__
222     #define HAVE_TEST_AND_SET 1
223     static inline int testandset(int *p)
224     {
225     int ret;
226    
227     __asm__ __volatile__("0: cs %0,%1,0(%2)\n"
228     " jl 0b"
229     : "=&d" (ret)
230     : "r" (1), "a" (p), "0" (*p)
231     : "cc", "memory" );
232     return ret;
233     }
234     #endif
235    
236     #ifdef __alpha__
237     #define HAVE_TEST_AND_SET 1
238     static inline int testandset(int *p)
239     {
240     int ret;
241     unsigned long one;
242    
243     __asm__ __volatile__("0: mov 1,%2\n"
244     " ldl_l %0,%1\n"
245     " stl_c %2,%1\n"
246     " beq %2,1f\n"
247     ".subsection 2\n"
248     "1: br 0b\n"
249     ".previous"
250     : "=r" (ret), "=m" (*p), "=r" (one)
251     : "m" (*p));
252     return ret;
253     }
254     #endif
255    
256     #ifdef __sparc__
257     #define HAVE_TEST_AND_SET 1
258     static inline int testandset(int *p)
259     {
260     int ret;
261    
262     __asm__ __volatile__("ldstub [%1], %0"
263     : "=r" (ret)
264     : "r" (p)
265     : "memory");
266    
267     return (ret ? 1 : 0);
268     }
269     #endif
270    
271     #ifdef __arm__
272     #define HAVE_TEST_AND_SET 1
273     static inline int testandset(int *p)
274     {
275     register unsigned int ret;
276     __asm__ __volatile__("swp %0, %1, [%2]"
277     : "=r"(ret)
278     : "0"(1), "r"(p));
279    
280     return ret;
281     }
282     #endif
283    
284     #endif /* __GNUC__ */
285    
286     #if HAVE_TEST_AND_SET
287     #define HAVE_SPINLOCKS 1
288     typedef int spinlock_t;
289    
290 gbeauche 1.8 static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
291 gbeauche 1.6
292     static inline void spin_lock(spinlock_t *lock)
293     {
294     while (testandset(lock));
295     }
296    
297     static inline void spin_unlock(spinlock_t *lock)
298     {
299     *lock = 0;
300     }
301    
302     static inline int spin_trylock(spinlock_t *lock)
303     {
304     return !testandset(lock);
305     }
306     #endif
307    
308 cebix 1.1 // Time data type for Time Manager emulation
309     #ifdef HAVE_CLOCK_GETTIME
310     typedef struct timespec tm_time_t;
311     #else
312     typedef struct timeval tm_time_t;
313     #endif
314    
315 cebix 1.2 // Setup pthread attributes
316     extern void Set_pthread_attr(pthread_attr_t *attr, int priority);
317    
318 cebix 1.1 // Various definitions
319     typedef struct rgb_color {
320     uint8 red;
321     uint8 green;
322     uint8 blue;
323     uint8 alpha;
324     } rgb_color;
325    
326     // Macro for calling MacOS routines
327     #define CallMacOS(type, tvect) call_macos((uint32)tvect)
328     #define CallMacOS1(type, tvect, arg1) call_macos1((uint32)tvect, (uint32)arg1)
329     #define CallMacOS2(type, tvect, arg1, arg2) call_macos2((uint32)tvect, (uint32)arg1, (uint32)arg2)
330     #define CallMacOS3(type, tvect, arg1, arg2, arg3) call_macos3((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3)
331     #define CallMacOS4(type, tvect, arg1, arg2, arg3, arg4) call_macos4((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4)
332     #define CallMacOS5(type, tvect, arg1, arg2, arg3, arg4, arg5) call_macos5((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5)
333     #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)
334     #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)
335    
336 gbeauche 1.3 #ifdef __cplusplus
337     extern "C" {
338     #endif
339     extern uint32 call_macos(uint32 tvect);
340     extern uint32 call_macos1(uint32 tvect, uint32 arg1);
341     extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
342     extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
343     extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
344     extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
345     extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
346     extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
347     #ifdef __cplusplus
348     }
349     #endif
350 cebix 1.1
351     #endif