ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Windows/sysdeps.h
Revision: 1.1
Committed: 2005-03-18T00:03:32Z (19 years, 6 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Log Message:
add windows specific sysdeps.h as they are stable enough now. lowered constant
offset to 0x02000000 so that we can cope with the new RAM_BASE value.

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