ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/sysdeps.h
Revision: 1.13
Committed: 2003-10-26T14:16:37Z (20 years, 8 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.12: +1 -1 lines
Log Message:
Fix ASYNC_IRQ build but locks may still happen. Note that with a predecode
cache, checking for pending interrupts may not be the bottle neck nowadays.

File Contents

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