ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Windows/sysdeps.h
Revision: 1.7
Committed: 2008-01-01T09:47:39Z (16 years, 10 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +1 -1 lines
Error occurred while calculating annotation data.
Log Message:
Happy New Year!

File Contents

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