1 |
/* |
2 |
* sysdeps.h - System dependent definitions for Windows |
3 |
* |
4 |
* Basilisk II (C) 1997-2008 Christian Bauer |
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 |
#ifndef WIN32 |
36 |
#define WIN32 |
37 |
#endif |
38 |
|
39 |
#include <assert.h> |
40 |
#include <stdio.h> |
41 |
#include <stdlib.h> |
42 |
#include <string.h> |
43 |
#include <time.h> |
44 |
#ifdef __WIN32__ |
45 |
#include <windows.h> |
46 |
#endif |
47 |
#include <sys/types.h> |
48 |
|
49 |
|
50 |
/* Mac and host address space are distinct */ |
51 |
#ifndef REAL_ADDRESSING |
52 |
#define REAL_ADDRESSING 0 |
53 |
#endif |
54 |
#if REAL_ADDRESSING |
55 |
#error "Real Addressing mode can't work without proper kernel support" |
56 |
#endif |
57 |
|
58 |
/* Using 68k emulator */ |
59 |
#define EMULATED_68K 1 |
60 |
|
61 |
/* The m68k emulator uses a prefetch buffer ? */ |
62 |
#define USE_PREFETCH_BUFFER 0 |
63 |
|
64 |
/* Mac ROM is write protected when banked memory is used */ |
65 |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
66 |
# define ROM_IS_WRITE_PROTECTED 0 |
67 |
# define USE_SCRATCHMEM_SUBTERFUGE 1 |
68 |
#else |
69 |
# define ROM_IS_WRITE_PROTECTED 1 |
70 |
#endif |
71 |
|
72 |
/* Direct Addressing requires Video on SEGV signals in plain X11 mode */ |
73 |
#if DIRECT_ADDRESSING && (!ENABLE_VOSF && !USE_SDL_VIDEO) |
74 |
# undef ENABLE_VOSF |
75 |
# define ENABLE_VOSF 1 |
76 |
#endif |
77 |
|
78 |
/* ExtFS is supported */ |
79 |
#define SUPPORTS_EXTFS 1 |
80 |
|
81 |
|
82 |
/* Data types */ |
83 |
typedef unsigned char uint8; |
84 |
typedef signed char int8; |
85 |
#if SIZEOF_SHORT == 2 |
86 |
typedef unsigned short uint16; |
87 |
typedef short int16; |
88 |
#elif SIZEOF_INT == 2 |
89 |
typedef unsigned int uint16; |
90 |
typedef int int16; |
91 |
#else |
92 |
#error "No 2 byte type, you lose." |
93 |
#endif |
94 |
#if SIZEOF_INT == 4 |
95 |
typedef unsigned int uint32; |
96 |
typedef int int32; |
97 |
#elif SIZEOF_LONG == 4 |
98 |
typedef unsigned long uint32; |
99 |
typedef long int32; |
100 |
#else |
101 |
#error "No 4 byte type, you lose." |
102 |
#endif |
103 |
#if SIZEOF_LONG == 8 |
104 |
typedef unsigned long uint64; |
105 |
typedef long int64; |
106 |
#define VAL64(a) (a ## l) |
107 |
#define UVAL64(a) (a ## ul) |
108 |
#elif SIZEOF_LONG_LONG == 8 |
109 |
typedef unsigned long long uint64; |
110 |
typedef long long int64; |
111 |
#define VAL64(a) (a ## LL) |
112 |
#define UVAL64(a) (a ## uLL) |
113 |
#else |
114 |
#error "No 8 byte type, you lose." |
115 |
#endif |
116 |
#if SIZEOF_VOID_P == 4 |
117 |
typedef uint32 uintptr; |
118 |
typedef int32 intptr; |
119 |
#elif SIZEOF_VOID_P == 8 |
120 |
typedef uint64 uintptr; |
121 |
typedef int64 intptr; |
122 |
#else |
123 |
#error "Unsupported size of pointer" |
124 |
#endif |
125 |
|
126 |
#ifdef __WIN32__ |
127 |
typedef int64 loff_t; |
128 |
#endif |
129 |
#ifndef HAVE_CADDR_T |
130 |
typedef char * caddr_t; |
131 |
#endif |
132 |
|
133 |
/* Time data type for Time Manager emulation */ |
134 |
typedef int64 tm_time_t; |
135 |
|
136 |
/* Define codes for all the float formats that we know of. |
137 |
* Though we only handle IEEE format. */ |
138 |
#define UNKNOWN_FLOAT_FORMAT 0 |
139 |
#define IEEE_FLOAT_FORMAT 1 |
140 |
#define VAX_FLOAT_FORMAT 2 |
141 |
#define IBM_FLOAT_FORMAT 3 |
142 |
#define C4X_FLOAT_FORMAT 4 |
143 |
|
144 |
/* UAE CPU data types */ |
145 |
#define uae_s8 int8 |
146 |
#define uae_u8 uint8 |
147 |
#define uae_s16 int16 |
148 |
#define uae_u16 uint16 |
149 |
#define uae_s32 int32 |
150 |
#define uae_u32 uint32 |
151 |
#define uae_s64 int64 |
152 |
#define uae_u64 uint64 |
153 |
typedef uae_u32 uaecptr; |
154 |
|
155 |
/* Timing functions */ |
156 |
extern void timer_init(void); |
157 |
extern uint64 GetTicks_usec(void); |
158 |
extern void Delay_usec(uint32 usec); |
159 |
|
160 |
/* Spinlocks */ |
161 |
#ifdef __GNUC__ |
162 |
#define HAVE_TEST_AND_SET 1 |
163 |
static inline int testandset(volatile int *p) |
164 |
{ |
165 |
long int ret; |
166 |
/* Note: the "xchg" instruction does not need a "lock" prefix */ |
167 |
__asm__ __volatile__("xchgl %k0, %1" |
168 |
: "=r" (ret), "=m" (*p) |
169 |
: "0" (1), "m" (*p) |
170 |
: "memory"); |
171 |
return ret; |
172 |
} |
173 |
#endif /* __GNUC__ */ |
174 |
|
175 |
typedef volatile int spinlock_t; |
176 |
|
177 |
static const spinlock_t SPIN_LOCK_UNLOCKED = 0; |
178 |
|
179 |
#if HAVE_TEST_AND_SET |
180 |
#define HAVE_SPINLOCKS 1 |
181 |
static inline void spin_lock(spinlock_t *lock) |
182 |
{ |
183 |
while (testandset(lock)); |
184 |
} |
185 |
|
186 |
static inline void spin_unlock(spinlock_t *lock) |
187 |
{ |
188 |
*lock = 0; |
189 |
} |
190 |
|
191 |
static inline int spin_trylock(spinlock_t *lock) |
192 |
{ |
193 |
return !testandset(lock); |
194 |
} |
195 |
#else |
196 |
static inline void spin_lock(spinlock_t *lock) |
197 |
{ |
198 |
} |
199 |
|
200 |
static inline void spin_unlock(spinlock_t *lock) |
201 |
{ |
202 |
} |
203 |
|
204 |
static inline int spin_trylock(spinlock_t *lock) |
205 |
{ |
206 |
return 1; |
207 |
} |
208 |
#endif |
209 |
|
210 |
/* Intel x86 */ |
211 |
#define X86_PPRO_OPT |
212 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;} |
213 |
#ifdef X86_PPRO_OPT |
214 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint32 retval; __asm__ ("movzwl %w1,%k0\n\tshll $16,%k0\n\tbswapl %k0\n" : "=&r" (retval) : "m" (*a) : "cc"); return retval;} |
215 |
#else |
216 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint32 retval; __asm__ ("xorl %k0,%k0\n\tmovw %w1,%w0\n\trolw $8,%w0" : "=&r" (retval) : "m" (*a) : "cc"); return retval;} |
217 |
#endif |
218 |
#define HAVE_GET_WORD_UNSWAPPED |
219 |
#define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a))) |
220 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
221 |
#ifdef X86_PPRO_OPT |
222 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;} |
223 |
#else |
224 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
225 |
#endif |
226 |
#define HAVE_OPTIMIZED_BYTESWAP_32 |
227 |
/* bswap doesn't affect condition codes */ |
228 |
static inline uae_u32 do_byteswap_32_g(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;} |
229 |
#define HAVE_OPTIMIZED_BYTESWAP_16 |
230 |
#ifdef X86_PPRO_OPT |
231 |
static inline uae_u32 do_byteswap_16_g(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;} |
232 |
#else |
233 |
static inline uae_u32 do_byteswap_16_g(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;} |
234 |
#endif |
235 |
|
236 |
#ifndef HAVE_OPTIMIZED_BYTESWAP_32 |
237 |
static inline uae_u32 do_byteswap_32_g(uae_u32 v) |
238 |
{ return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); } |
239 |
#endif |
240 |
|
241 |
#ifndef HAVE_OPTIMIZED_BYTESWAP_16 |
242 |
static inline uae_u32 do_byteswap_16_g(uae_u32 v) |
243 |
{ return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); } |
244 |
#endif |
245 |
|
246 |
#define do_byteswap_16_c(x) \ |
247 |
((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) |
248 |
|
249 |
#define do_byteswap_32_c(x) \ |
250 |
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ |
251 |
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) |
252 |
|
253 |
#if defined(__GNUC__) |
254 |
#define do_byteswap_16(x) \ |
255 |
(__extension__ \ |
256 |
({ register uint16 __v, __x = (x); \ |
257 |
if (__builtin_constant_p(__x)) \ |
258 |
__v = do_byteswap_16_c(__x); \ |
259 |
else \ |
260 |
__v = do_byteswap_16_g(__x); \ |
261 |
__v; })) |
262 |
|
263 |
#define do_byteswap_32(x) \ |
264 |
(__extension__ \ |
265 |
({ register uint32 __v, __x = (x); \ |
266 |
if (__builtin_constant_p(__x)) \ |
267 |
__v = do_byteswap_32_c(__x); \ |
268 |
else \ |
269 |
__v = do_byteswap_32_g(__x); \ |
270 |
__v; })) |
271 |
#else |
272 |
#define do_byteswap_16(x) do_byteswap_16_g(x) |
273 |
#define do_byteswap_32(x) do_byteswap_32_g(x) |
274 |
#endif |
275 |
|
276 |
/* Byte-swapping routines */ |
277 |
#if defined(__i386__) || defined(__x86_64__) |
278 |
#define ntohl(x) do_byteswap_32(x) |
279 |
#define ntohs(x) do_byteswap_16(x) |
280 |
#define htonl(x) do_byteswap_32(x) |
281 |
#define htons(x) do_byteswap_16(x) |
282 |
#endif |
283 |
|
284 |
#define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a))) |
285 |
#define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v)) |
286 |
|
287 |
#define call_mem_get_func(func, addr) ((*func)(addr)) |
288 |
#define call_mem_put_func(func, addr, v) ((*func)(addr, v)) |
289 |
#define __inline__ inline |
290 |
#define CPU_EMU_SIZE 0 |
291 |
#undef NO_INLINE_MEMORY_ACCESS |
292 |
#undef MD_HAVE_MEM_1_FUNCS |
293 |
#define ENUMDECL typedef enum |
294 |
#define ENUMNAME(name) name |
295 |
#define write_log printf |
296 |
|
297 |
#define ATTRIBUTE_PACKED __attribute__((packed)) |
298 |
|
299 |
#if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) |
300 |
#define ASM_SYM_FOR_FUNC(a) __asm__(a) |
301 |
#else |
302 |
#define ASM_SYM_FOR_FUNC(a) |
303 |
#endif |
304 |
|
305 |
#ifndef REGPARAM |
306 |
# define REGPARAM |
307 |
#endif |
308 |
#define REGPARAM2 |
309 |
|
310 |
#endif |