ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/sysdeps.h
Revision: 1.9
Committed: 2003-10-11T09:34:35Z (20 years, 8 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.8: +4 -0 lines
Log Message:
Move PPC emulator config to here

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