ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Windows/sysdeps.h
Revision: 1.4
Committed: 2005-11-27T20:36:30Z (18 years, 11 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.3: +5 -0 lines
Log Message:
Windows fixes for "new" Ethernet API. The full driver is needed because of
DIRECT_ADDRESSING mode.

File Contents

# User Rev Content
1 gbeauche 1.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 gbeauche 1.2 #include <time.h>
41     #ifdef __WIN32__
42 gbeauche 1.1 #include <windows.h>
43 gbeauche 1.2 #endif
44     #include <sys/types.h>
45    
46 gbeauche 1.1
47     // Define for external components
48     #define SHEEPSHAVER 1
49     #define POWERPC_ROM 1
50     #define EMULATED_PPC 1
51 gbeauche 1.2 #define CONFIG_WIN32 1
52 gbeauche 1.1
53     // Use Direct Addressing mode
54     #define DIRECT_ADDRESSING 1
55     #define NATMEM_OFFSET 0x02000000
56    
57 gbeauche 1.4 // Always use the complete (non-stubs based) Ethernet driver
58     #if DIRECT_ADDRESSING
59     #define USE_ETHER_FULL_DRIVER 1
60     #endif
61    
62 gbeauche 1.1 // 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    
129     /**
130     * Helper functions to byteswap data
131     **/
132    
133     #if defined(__GNUC__)
134     #if defined(__x86_64__) || defined(__i386__)
135     // Linux/AMD64 currently has no asm optimized bswap_32() in <byteswap.h>
136     #define opt_bswap_32 do_opt_bswap_32
137     static inline uint32 do_opt_bswap_32(uint32 x)
138     {
139     uint32 v;
140     __asm__ __volatile__ ("bswap %0" : "=r" (v) : "0" (x));
141     return v;
142     }
143     #endif
144     #endif
145    
146     #ifdef opt_bswap_16
147     #undef bswap_16
148     #define bswap_16 opt_bswap_16
149     #endif
150     #ifndef bswap_16
151     #define bswap_16 generic_bswap_16
152     #endif
153    
154     static inline uint16 generic_bswap_16(uint16 x)
155     {
156     return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
157     }
158    
159     #ifdef opt_bswap_32
160     #undef bswap_32
161     #define bswap_32 opt_bswap_32
162     #endif
163     #ifndef bswap_32
164     #define bswap_32 generic_bswap_32
165     #endif
166    
167     static inline uint32 generic_bswap_32(uint32 x)
168     {
169     return (((x & 0xff000000) >> 24) |
170     ((x & 0x00ff0000) >> 8) |
171     ((x & 0x0000ff00) << 8) |
172     ((x & 0x000000ff) << 24) );
173     }
174    
175     #if defined(__i386__)
176     #define opt_bswap_64 do_opt_bswap_64
177     static inline uint64 do_opt_bswap_64(uint64 x)
178     {
179     return (bswap_32(x >> 32) | (((uint64)bswap_32((uint32)x)) << 32));
180     }
181     #endif
182    
183     #ifdef opt_bswap_64
184     #undef bswap_64
185     #define bswap_64 opt_bswap_64
186     #endif
187     #ifndef bswap_64
188     #define bswap_64 generic_bswap_64
189     #endif
190    
191     static inline uint64 generic_bswap_64(uint64 x)
192     {
193     return (((x & UVAL64(0xff00000000000000)) >> 56) |
194     ((x & UVAL64(0x00ff000000000000)) >> 40) |
195     ((x & UVAL64(0x0000ff0000000000)) >> 24) |
196     ((x & UVAL64(0x000000ff00000000)) >> 8) |
197     ((x & UVAL64(0x00000000ff000000)) << 8) |
198     ((x & UVAL64(0x0000000000ff0000)) << 24) |
199     ((x & UVAL64(0x000000000000ff00)) << 40) |
200     ((x & UVAL64(0x00000000000000ff)) << 56) );
201     }
202    
203     #ifdef WORDS_BIGENDIAN
204     static inline uint16 tswap16(uint16 x) { return x; }
205     static inline uint32 tswap32(uint32 x) { return x; }
206     static inline uint64 tswap64(uint64 x) { return x; }
207     #else
208     static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
209     static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
210     static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
211     #endif
212    
213     #define do_byteswap_16_g bswap_16
214     #define do_byteswap_16_c(x) \
215     ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
216    
217     #define do_byteswap_32_g bswap_32
218     #define do_byteswap_32_c(x) \
219     ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
220     (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
221    
222     #if defined(__GNUC__)
223     #define do_byteswap_16(x) \
224     (__extension__ \
225     ({ register uint16 __v, __x = (x); \
226     if (__builtin_constant_p(__x)) \
227     __v = do_byteswap_16_c(__x); \
228     else \
229     __v = do_byteswap_16_g(__x); \
230     __v; }))
231    
232     #define do_byteswap_32(x) \
233     (__extension__ \
234     ({ register uint32 __v, __x = (x); \
235     if (__builtin_constant_p(__x)) \
236     __v = do_byteswap_32_c(__x); \
237     else \
238     __v = do_byteswap_32_g(__x); \
239     __v; }))
240     #else
241     #define do_byteswap_16(x) do_byteswap_16_g(x)
242     #define do_byteswap_32(x) do_byteswap_32_g(x)
243     #endif
244    
245     #if defined(__i386__) || defined(__x86_64__)
246     #define ntohl(x) do_byteswap_32(x)
247     #define ntohs(x) do_byteswap_16(x)
248     #define htonl(x) do_byteswap_32(x)
249     #define htons(x) do_byteswap_16(x)
250     #endif
251    
252    
253     /*
254     * Spin locks
255     */
256    
257     #ifdef __GNUC__
258    
259     #if defined(__powerpc__) || defined(__ppc__)
260     #define HAVE_TEST_AND_SET 1
261     static inline int testandset(volatile int *p)
262     {
263     int ret;
264     __asm__ __volatile__("0: lwarx %0,0,%1\n"
265     " xor. %0,%3,%0\n"
266     " bne 1f\n"
267     " stwcx. %2,0,%1\n"
268     " bne- 0b\n"
269     "1: "
270     : "=&r" (ret)
271     : "r" (p), "r" (1), "r" (0)
272     : "cr0", "memory");
273     return ret;
274     }
275     #endif
276    
277     #if defined(__i386__) || defined(__x86_64__)
278     #define HAVE_TEST_AND_SET 1
279     static inline int testandset(volatile int *p)
280     {
281     long int ret;
282     /* Note: the "xchg" instruction does not need a "lock" prefix */
283     __asm__ __volatile__("xchgl %k0, %1"
284     : "=r" (ret), "=m" (*p)
285     : "0" (1), "m" (*p)
286     : "memory");
287     return ret;
288     }
289     #endif
290    
291     #ifdef __alpha__
292     #define HAVE_TEST_AND_SET 1
293     static inline int testandset(volatile int *p)
294     {
295     int ret;
296     unsigned long one;
297    
298     __asm__ __volatile__("0: mov 1,%2\n"
299     " ldl_l %0,%1\n"
300     " stl_c %2,%1\n"
301     " beq %2,1f\n"
302     ".subsection 2\n"
303     "1: br 0b\n"
304     ".previous"
305     : "=r" (ret), "=m" (*p), "=r" (one)
306     : "m" (*p));
307     return ret;
308     }
309     #endif
310    
311     #endif /* __GNUC__ */
312    
313     typedef volatile int spinlock_t;
314    
315     static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
316    
317     #if HAVE_TEST_AND_SET
318     #define HAVE_SPINLOCKS 1
319     static inline void spin_lock(spinlock_t *lock)
320     {
321     while (testandset(lock));
322     }
323    
324     static inline void spin_unlock(spinlock_t *lock)
325     {
326     *lock = 0;
327     }
328    
329     static inline int spin_trylock(spinlock_t *lock)
330     {
331     return !testandset(lock);
332     }
333     #else
334     static inline void spin_lock(spinlock_t *lock)
335     {
336     }
337    
338     static inline void spin_unlock(spinlock_t *lock)
339     {
340     }
341    
342     static inline int spin_trylock(spinlock_t *lock)
343     {
344     return 1;
345     }
346     #endif
347    
348     // Time data type for Time Manager emulation
349     typedef int64 tm_time_t;
350    
351     // Timing functions
352     extern void timer_init(void);
353     extern uint64 GetTicks_usec(void);
354     extern void Delay_usec(uint32 usec);
355    
356     // Various definitions
357     typedef struct rgb_color {
358     uint8 red;
359     uint8 green;
360     uint8 blue;
361     uint8 alpha;
362     } rgb_color;
363    
364     // Macro for calling MacOS routines
365     #define CallMacOS(type, tvect) call_macos((uintptr)tvect)
366     #define CallMacOS1(type, tvect, arg1) call_macos1((uintptr)tvect, (uintptr)arg1)
367     #define CallMacOS2(type, tvect, arg1, arg2) call_macos2((uintptr)tvect, (uintptr)arg1, (uintptr)arg2)
368     #define CallMacOS3(type, tvect, arg1, arg2, arg3) call_macos3((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3)
369     #define CallMacOS4(type, tvect, arg1, arg2, arg3, arg4) call_macos4((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4)
370     #define CallMacOS5(type, tvect, arg1, arg2, arg3, arg4, arg5) call_macos5((uintptr)tvect, (uintptr)arg1, (uintptr)arg2, (uintptr)arg3, (uintptr)arg4, (uintptr)arg5)
371     #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)
372     #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)
373    
374     #ifdef __cplusplus
375     extern "C" {
376     #endif
377     extern uint32 call_macos(uint32 tvect);
378     extern uint32 call_macos1(uint32 tvect, uint32 arg1);
379     extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
380     extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
381     extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
382     extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
383     extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
384     extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
385     #ifdef __cplusplus
386     }
387     #endif
388    
389     // Misc platform specific definitions
390 gbeauche 1.2 #ifdef __WIN32__
391 gbeauche 1.1 typedef int64 loff_t;
392 gbeauche 1.2 #endif
393 gbeauche 1.1 #define ATTRIBUTE_PACKED __attribute__((__packed__))
394    
395     #endif