ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Windows/sysdeps.h
Revision: 1.3
Committed: 2005-11-27T16:20:17Z (18 years, 6 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.2: +0 -2 lines
Log Message:
Do use predecode cache in case the JIT is disabled by the user ("jit" option)

File Contents

# Content
1 /*
2 * sysdeps.h - System dependent definitions for Windows
3 *
4 * SheepShaver (C) 1997-2005 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_windows.h"
30
31 #ifndef STDC_HEADERS
32 #error "You don't have ANSI C header files."
33 #endif
34
35 #include <assert.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <time.h>
41 #ifdef __WIN32__
42 #include <windows.h>
43 #endif
44 #include <sys/types.h>
45
46
47 // Define for external components
48 #define SHEEPSHAVER 1
49 #define POWERPC_ROM 1
50 #define EMULATED_PPC 1
51 #define CONFIG_WIN32 1
52
53 // Use Direct Addressing mode
54 #define DIRECT_ADDRESSING 1
55 #define NATMEM_OFFSET 0x02000000
56
57 // Mac ROM is write protected when banked memory is used
58 #if REAL_ADDRESSING || DIRECT_ADDRESSING
59 # define ROM_IS_WRITE_PROTECTED 0
60 # define USE_SCRATCHMEM_SUBTERFUGE 1
61 #else
62 # define ROM_IS_WRITE_PROTECTED 1
63 #endif
64 // Configure PowerPC emulator
65 #define PPC_REENTRANT_JIT 1
66 #define PPC_CHECK_INTERRUPTS 1
67 #define PPC_DECODE_CACHE 1
68 #define PPC_FLIGHT_RECORDER 1
69 #define PPC_PROFILE_COMPILE_TIME 0
70 #define PPC_PROFILE_GENERIC_CALLS 0
71 #define KPX_MAX_CPUS 1
72 #if ENABLE_DYNGEN
73 #define PPC_ENABLE_JIT 1
74 #endif
75 #if defined(__i386__)
76 #define DYNGEN_ASM_OPTS 1
77 #endif
78
79 // Data types
80 typedef unsigned char uint8;
81 typedef signed char int8;
82 #if SIZEOF_SHORT == 2
83 typedef unsigned short uint16;
84 typedef short int16;
85 #elif SIZEOF_INT == 2
86 typedef unsigned int uint16;
87 typedef int int16;
88 #else
89 #error "No 2 byte type, you lose."
90 #endif
91 #if SIZEOF_INT == 4
92 typedef unsigned int uint32;
93 typedef int int32;
94 #elif SIZEOF_LONG == 4
95 typedef unsigned long uint32;
96 typedef long int32;
97 #else
98 #error "No 4 byte type, you lose."
99 #endif
100 #if SIZEOF_LONG == 8
101 typedef unsigned long uint64;
102 typedef long int64;
103 #define VAL64(a) (a ## l)
104 #define UVAL64(a) (a ## ul)
105 #elif SIZEOF_LONG_LONG == 8
106 typedef unsigned long long uint64;
107 typedef long long int64;
108 #define VAL64(a) (a ## LL)
109 #define UVAL64(a) (a ## uLL)
110 #else
111 #error "No 8 byte type, you lose."
112 #endif
113 #if SIZEOF_VOID_P == 4
114 typedef uint32 uintptr;
115 typedef int32 intptr;
116 #elif SIZEOF_VOID_P == 8
117 typedef uint64 uintptr;
118 typedef int64 intptr;
119 #else
120 #error "Unsupported size of pointer"
121 #endif
122
123
124 /**
125 * Helper functions to byteswap data
126 **/
127
128 #if defined(__GNUC__)
129 #if defined(__x86_64__) || defined(__i386__)
130 // Linux/AMD64 currently has no asm optimized bswap_32() in <byteswap.h>
131 #define opt_bswap_32 do_opt_bswap_32
132 static inline uint32 do_opt_bswap_32(uint32 x)
133 {
134 uint32 v;
135 __asm__ __volatile__ ("bswap %0" : "=r" (v) : "0" (x));
136 return v;
137 }
138 #endif
139 #endif
140
141 #ifdef opt_bswap_16
142 #undef bswap_16
143 #define bswap_16 opt_bswap_16
144 #endif
145 #ifndef bswap_16
146 #define bswap_16 generic_bswap_16
147 #endif
148
149 static inline uint16 generic_bswap_16(uint16 x)
150 {
151 return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
152 }
153
154 #ifdef opt_bswap_32
155 #undef bswap_32
156 #define bswap_32 opt_bswap_32
157 #endif
158 #ifndef bswap_32
159 #define bswap_32 generic_bswap_32
160 #endif
161
162 static inline uint32 generic_bswap_32(uint32 x)
163 {
164 return (((x & 0xff000000) >> 24) |
165 ((x & 0x00ff0000) >> 8) |
166 ((x & 0x0000ff00) << 8) |
167 ((x & 0x000000ff) << 24) );
168 }
169
170 #if defined(__i386__)
171 #define opt_bswap_64 do_opt_bswap_64
172 static inline uint64 do_opt_bswap_64(uint64 x)
173 {
174 return (bswap_32(x >> 32) | (((uint64)bswap_32((uint32)x)) << 32));
175 }
176 #endif
177
178 #ifdef opt_bswap_64
179 #undef bswap_64
180 #define bswap_64 opt_bswap_64
181 #endif
182 #ifndef bswap_64
183 #define bswap_64 generic_bswap_64
184 #endif
185
186 static inline uint64 generic_bswap_64(uint64 x)
187 {
188 return (((x & UVAL64(0xff00000000000000)) >> 56) |
189 ((x & UVAL64(0x00ff000000000000)) >> 40) |
190 ((x & UVAL64(0x0000ff0000000000)) >> 24) |
191 ((x & UVAL64(0x000000ff00000000)) >> 8) |
192 ((x & UVAL64(0x00000000ff000000)) << 8) |
193 ((x & UVAL64(0x0000000000ff0000)) << 24) |
194 ((x & UVAL64(0x000000000000ff00)) << 40) |
195 ((x & UVAL64(0x00000000000000ff)) << 56) );
196 }
197
198 #ifdef WORDS_BIGENDIAN
199 static inline uint16 tswap16(uint16 x) { return x; }
200 static inline uint32 tswap32(uint32 x) { return x; }
201 static inline uint64 tswap64(uint64 x) { return x; }
202 #else
203 static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
204 static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
205 static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
206 #endif
207
208 #define do_byteswap_16_g bswap_16
209 #define do_byteswap_16_c(x) \
210 ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
211
212 #define do_byteswap_32_g bswap_32
213 #define do_byteswap_32_c(x) \
214 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
215 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
216
217 #if defined(__GNUC__)
218 #define do_byteswap_16(x) \
219 (__extension__ \
220 ({ register uint16 __v, __x = (x); \
221 if (__builtin_constant_p(__x)) \
222 __v = do_byteswap_16_c(__x); \
223 else \
224 __v = do_byteswap_16_g(__x); \
225 __v; }))
226
227 #define do_byteswap_32(x) \
228 (__extension__ \
229 ({ register uint32 __v, __x = (x); \
230 if (__builtin_constant_p(__x)) \
231 __v = do_byteswap_32_c(__x); \
232 else \
233 __v = do_byteswap_32_g(__x); \
234 __v; }))
235 #else
236 #define do_byteswap_16(x) do_byteswap_16_g(x)
237 #define do_byteswap_32(x) do_byteswap_32_g(x)
238 #endif
239
240 #if defined(__i386__) || defined(__x86_64__)
241 #define ntohl(x) do_byteswap_32(x)
242 #define ntohs(x) do_byteswap_16(x)
243 #define htonl(x) do_byteswap_32(x)
244 #define htons(x) do_byteswap_16(x)
245 #endif
246
247
248 /*
249 * Spin locks
250 */
251
252 #ifdef __GNUC__
253
254 #if defined(__powerpc__) || defined(__ppc__)
255 #define HAVE_TEST_AND_SET 1
256 static inline int testandset(volatile int *p)
257 {
258 int ret;
259 __asm__ __volatile__("0: lwarx %0,0,%1\n"
260 " xor. %0,%3,%0\n"
261 " bne 1f\n"
262 " stwcx. %2,0,%1\n"
263 " bne- 0b\n"
264 "1: "
265 : "=&r" (ret)
266 : "r" (p), "r" (1), "r" (0)
267 : "cr0", "memory");
268 return ret;
269 }
270 #endif
271
272 #if defined(__i386__) || defined(__x86_64__)
273 #define HAVE_TEST_AND_SET 1
274 static inline int testandset(volatile int *p)
275 {
276 long int ret;
277 /* Note: the "xchg" instruction does not need a "lock" prefix */
278 __asm__ __volatile__("xchgl %k0, %1"
279 : "=r" (ret), "=m" (*p)
280 : "0" (1), "m" (*p)
281 : "memory");
282 return ret;
283 }
284 #endif
285
286 #ifdef __alpha__
287 #define HAVE_TEST_AND_SET 1
288 static inline int testandset(volatile int *p)
289 {
290 int ret;
291 unsigned long one;
292
293 __asm__ __volatile__("0: mov 1,%2\n"
294 " ldl_l %0,%1\n"
295 " stl_c %2,%1\n"
296 " beq %2,1f\n"
297 ".subsection 2\n"
298 "1: br 0b\n"
299 ".previous"
300 : "=r" (ret), "=m" (*p), "=r" (one)
301 : "m" (*p));
302 return ret;
303 }
304 #endif
305
306 #endif /* __GNUC__ */
307
308 typedef volatile int spinlock_t;
309
310 static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
311
312 #if HAVE_TEST_AND_SET
313 #define HAVE_SPINLOCKS 1
314 static inline void spin_lock(spinlock_t *lock)
315 {
316 while (testandset(lock));
317 }
318
319 static inline void spin_unlock(spinlock_t *lock)
320 {
321 *lock = 0;
322 }
323
324 static inline int spin_trylock(spinlock_t *lock)
325 {
326 return !testandset(lock);
327 }
328 #else
329 static inline void spin_lock(spinlock_t *lock)
330 {
331 }
332
333 static inline void spin_unlock(spinlock_t *lock)
334 {
335 }
336
337 static inline int spin_trylock(spinlock_t *lock)
338 {
339 return 1;
340 }
341 #endif
342
343 // Time data type for Time Manager emulation
344 typedef int64 tm_time_t;
345
346 // Timing functions
347 extern void timer_init(void);
348 extern uint64 GetTicks_usec(void);
349 extern void Delay_usec(uint32 usec);
350
351 // Various definitions
352 typedef struct rgb_color {
353 uint8 red;
354 uint8 green;
355 uint8 blue;
356 uint8 alpha;
357 } rgb_color;
358
359 // Macro for calling MacOS routines
360 #define CallMacOS(type, tvect) call_macos((uintptr)tvect)
361 #define CallMacOS1(type, tvect, arg1) call_macos1((uintptr)tvect, (uintptr)arg1)
362 #define CallMacOS2(type, tvect, arg1, arg2) call_macos2((uintptr)tvect, (uintptr)arg1, (uintptr)arg2)
363 #define CallMacOS3(type, tvect, arg1, arg2, arg3) call_macos3((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3)
364 #define CallMacOS4(type, tvect, arg1, arg2, arg3, arg4) call_macos4((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4)
365 #define CallMacOS5(type, tvect, arg1, arg2, arg3, arg4, arg5) call_macos5((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4, (uintptr)arg5)
366 #define CallMacOS6(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6) call_macos6((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4, (uintptr)arg5, (uintptr)arg6)
367 #define CallMacOS7(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6, arg7) call_macos7((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4, (uintptr)arg5, (uintptr)arg6, (uintptr)arg7)
368
369 #ifdef __cplusplus
370 extern "C" {
371 #endif
372 extern uint32 call_macos(uint32 tvect);
373 extern uint32 call_macos1(uint32 tvect, uint32 arg1);
374 extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
375 extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
376 extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
377 extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
378 extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
379 extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
380 #ifdef __cplusplus
381 }
382 #endif
383
384 // Misc platform specific definitions
385 #ifdef __WIN32__
386 typedef int64 loff_t;
387 #endif
388 #define ATTRIBUTE_PACKED __attribute__((__packed__))
389
390 #endif