1 |
/* |
2 |
* sysdeps.h - System dependent definitions for Mac OS X. |
3 |
* Based on Unix version |
4 |
* |
5 |
* $Id: sysdeps.h,v 1.8 2004/01/26 12:06:02 nigel Exp $ |
6 |
* |
7 |
* Basilisk II (C) 1997-2005 Christian Bauer |
8 |
* |
9 |
* This program is free software; you can redistribute it and/or modify |
10 |
* it under the terms of the GNU General Public License as published by |
11 |
* the Free Software Foundation; either version 2 of the License, or |
12 |
* (at your option) any later version. |
13 |
* |
14 |
* This program is distributed in the hope that it will be useful, |
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
* GNU General Public License for more details. |
18 |
* |
19 |
* You should have received a copy of the GNU General Public License |
20 |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
*/ |
23 |
|
24 |
#ifndef SYSDEPS_H |
25 |
#define SYSDEPS_H |
26 |
|
27 |
#ifndef __STDC__ |
28 |
#error "Your compiler is not ANSI. Get a real one." |
29 |
#endif |
30 |
|
31 |
#include "config.h" |
32 |
#include "user_strings_unix.h" |
33 |
|
34 |
#ifndef STDC_HEADERS |
35 |
#error "You don't have ANSI C header files." |
36 |
#endif |
37 |
|
38 |
#ifdef HAVE_UNISTD_H |
39 |
# include <sys/types.h> |
40 |
# include <unistd.h> |
41 |
#endif |
42 |
|
43 |
#include <netinet/in.h> |
44 |
#include <assert.h> |
45 |
#include <stdio.h> |
46 |
#include <stdlib.h> |
47 |
#include <string.h> |
48 |
|
49 |
#ifdef HAVE_PTHREADS |
50 |
# include <pthread.h> |
51 |
#endif |
52 |
|
53 |
#ifdef HAVE_FCNTL_H |
54 |
# include <fcntl.h> |
55 |
#endif |
56 |
|
57 |
#ifdef TIME_WITH_SYS_TIME |
58 |
# include <sys/time.h> |
59 |
# include <time.h> |
60 |
#else |
61 |
# ifdef HAVE_SYS_TIME_H |
62 |
# include <sys/time.h> |
63 |
# else |
64 |
# include <time.h> |
65 |
# endif |
66 |
#endif |
67 |
|
68 |
|
69 |
/* Symbol to distinguish Nigel's Aqua port from a normal Darwin X11 build */ |
70 |
/* (this sysdeps.h file is currently specific to the Mac OS X Aqua port) */ |
71 |
#define AQUA 1 |
72 |
|
73 |
/* Header which defines OS X version for selecting APIs */ |
74 |
#ifdef AVAILABILITYMACROS |
75 |
# include <AvailabilityMacros.h> |
76 |
#endif |
77 |
|
78 |
|
79 |
#ifdef ENABLE_NATIVE_M68K |
80 |
|
81 |
/* Mac and host address space are the same */ |
82 |
#define REAL_ADDRESSING 1 |
83 |
|
84 |
/* Using 68k natively */ |
85 |
#define EMULATED_68K 0 |
86 |
|
87 |
/* Mac ROM is not write protected */ |
88 |
#define ROM_IS_WRITE_PROTECTED 0 |
89 |
#define USE_SCRATCHMEM_SUBTERFUGE 1 |
90 |
|
91 |
#else |
92 |
|
93 |
/* Mac and host address space are distinct */ |
94 |
#ifndef REAL_ADDRESSING |
95 |
#define REAL_ADDRESSING 0 |
96 |
#endif |
97 |
|
98 |
/* Using 68k emulator */ |
99 |
#define EMULATED_68K 1 |
100 |
|
101 |
/* The m68k emulator uses a prefetch buffer ? */ |
102 |
#define USE_PREFETCH_BUFFER 0 |
103 |
|
104 |
/* Mac ROM is write protected when banked memory is used */ |
105 |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
106 |
# define ROM_IS_WRITE_PROTECTED 0 |
107 |
# define USE_SCRATCHMEM_SUBTERFUGE 1 |
108 |
#else |
109 |
# define ROM_IS_WRITE_PROTECTED 1 |
110 |
#endif |
111 |
|
112 |
#endif |
113 |
|
114 |
/* Direct Addressing requires Video on SEGV signals */ |
115 |
#if DIRECT_ADDRESSING && !ENABLE_VOSF |
116 |
# undef ENABLE_VOSF |
117 |
# define ENABLE_VOSF 1 |
118 |
#endif |
119 |
|
120 |
/* ExtFS is supported */ |
121 |
#define SUPPORTS_EXTFS 1 |
122 |
|
123 |
/* BSD socket API supported */ |
124 |
#define SUPPORTS_UDP_TUNNEL 1 |
125 |
|
126 |
|
127 |
/* Data types */ |
128 |
typedef unsigned char uint8; |
129 |
typedef signed char int8; |
130 |
#if SIZEOF_SHORT == 2 |
131 |
typedef unsigned short uint16; |
132 |
typedef short int16; |
133 |
#elif SIZEOF_INT == 2 |
134 |
typedef unsigned int uint16; |
135 |
typedef int int16; |
136 |
#else |
137 |
#error "No 2 byte type, you lose." |
138 |
#endif |
139 |
#if SIZEOF_INT == 4 |
140 |
typedef unsigned int uint32; |
141 |
typedef int int32; |
142 |
#elif SIZEOF_LONG == 4 |
143 |
typedef unsigned long uint32; |
144 |
typedef long int32; |
145 |
#else |
146 |
#error "No 4 byte type, you lose." |
147 |
#endif |
148 |
#if SIZEOF_LONG == 8 |
149 |
typedef unsigned long uint64; |
150 |
typedef long int64; |
151 |
#define VAL64(a) (a ## l) |
152 |
#define UVAL64(a) (a ## ul) |
153 |
#elif SIZEOF_LONG_LONG == 8 |
154 |
typedef unsigned long long uint64; |
155 |
typedef long long int64; |
156 |
#define VAL64(a) (a ## LL) |
157 |
#define UVAL64(a) (a ## uLL) |
158 |
#else |
159 |
#error "No 8 byte type, you lose." |
160 |
#endif |
161 |
#if SIZEOF_VOID_P == 4 |
162 |
typedef uint32 uintptr; |
163 |
typedef int32 intptr; |
164 |
#elif SIZEOF_VOID_P == 8 |
165 |
typedef uint64 uintptr; |
166 |
typedef int64 intptr; |
167 |
#else |
168 |
#error "Unsupported size of pointer" |
169 |
#endif |
170 |
|
171 |
#ifndef HAVE_LOFF_T |
172 |
typedef off_t loff_t; |
173 |
#endif |
174 |
#ifndef HAVE_CADDR_T |
175 |
typedef char * caddr_t; |
176 |
#endif |
177 |
|
178 |
/* Time data type for Time Manager emulation */ |
179 |
#ifdef HAVE_CLOCK_GETTIME |
180 |
typedef struct timespec tm_time_t; |
181 |
#else |
182 |
typedef struct timeval tm_time_t; |
183 |
#endif |
184 |
|
185 |
/* Define codes for all the float formats that we know of. |
186 |
* Though we only handle IEEE format. */ |
187 |
#define UNKNOWN_FLOAT_FORMAT 0 |
188 |
#define IEEE_FLOAT_FORMAT 1 |
189 |
#define VAX_FLOAT_FORMAT 2 |
190 |
#define IBM_FLOAT_FORMAT 3 |
191 |
#define C4X_FLOAT_FORMAT 4 |
192 |
|
193 |
/* UAE CPU data types */ |
194 |
#define uae_s8 int8 |
195 |
#define uae_u8 uint8 |
196 |
#define uae_s16 int16 |
197 |
#define uae_u16 uint16 |
198 |
#define uae_s32 int32 |
199 |
#define uae_u32 uint32 |
200 |
#define uae_s64 int64 |
201 |
#define uae_u64 uint64 |
202 |
typedef uae_u32 uaecptr; |
203 |
|
204 |
/* Alignment restrictions */ |
205 |
#if defined(__i386__) || defined(__powerpc__) || defined(__m68k__) || defined(__x86_64__) |
206 |
# define CPU_CAN_ACCESS_UNALIGNED |
207 |
#endif |
208 |
|
209 |
/* Timing functions */ |
210 |
extern uint64 GetTicks_usec(void); |
211 |
extern void Delay_usec(uint32 usec); |
212 |
|
213 |
#ifdef HAVE_PTHREADS |
214 |
/* Centralized pthread attribute setup */ |
215 |
void Set_pthread_attr(pthread_attr_t *attr, int priority); |
216 |
#endif |
217 |
|
218 |
/* UAE CPU defines */ |
219 |
#ifdef WORDS_BIGENDIAN |
220 |
|
221 |
#ifdef CPU_CAN_ACCESS_UNALIGNED |
222 |
|
223 |
/* Big-endian CPUs which can do unaligned accesses */ |
224 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {return *a;} |
225 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {return *a;} |
226 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = v;} |
227 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = v;} |
228 |
|
229 |
#else /* CPU_CAN_ACCESS_UNALIGNED */ |
230 |
|
231 |
#ifdef sgi |
232 |
/* The SGI MIPSPro compilers can do unaligned accesses given enough hints. |
233 |
* They will automatically inline these routines. */ |
234 |
#ifdef __cplusplus |
235 |
extern "C" { /* only the C compiler does unaligned accesses */ |
236 |
#endif |
237 |
extern uae_u32 do_get_mem_long(uae_u32 *a); |
238 |
extern uae_u32 do_get_mem_word(uae_u16 *a); |
239 |
extern void do_put_mem_long(uae_u32 *a, uae_u32 v); |
240 |
extern void do_put_mem_word(uae_u16 *a, uae_u32 v); |
241 |
#ifdef __cplusplus |
242 |
} |
243 |
#endif |
244 |
|
245 |
#else /* sgi */ |
246 |
|
247 |
/* Big-endian CPUs which can not do unaligned accesses (this is not the most efficient way to do this...) */ |
248 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint8 *b = (uint8 *)a; return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];} |
249 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];} |
250 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 24; b[1] = v >> 16; b[2] = v >> 8; b[3] = v;} |
251 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;} |
252 |
#endif /* sgi */ |
253 |
|
254 |
#endif /* CPU_CAN_ACCESS_UNALIGNED */ |
255 |
|
256 |
#else /* WORDS_BIGENDIAN */ |
257 |
|
258 |
#if defined(__i386__) || defined(__x86_64__) |
259 |
|
260 |
/* Intel x86 */ |
261 |
#define X86_PPRO_OPT |
262 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;} |
263 |
#ifdef X86_PPRO_OPT |
264 |
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;} |
265 |
#else |
266 |
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;} |
267 |
#endif |
268 |
#define HAVE_GET_WORD_UNSWAPPED |
269 |
#define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a))) |
270 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
271 |
#ifdef X86_PPRO_OPT |
272 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;} |
273 |
#else |
274 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
275 |
#endif |
276 |
#define HAVE_OPTIMIZED_BYTESWAP_32 |
277 |
/* bswap doesn't affect condition codes */ |
278 |
static inline uae_u32 do_byteswap_32(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;} |
279 |
#define HAVE_OPTIMIZED_BYTESWAP_16 |
280 |
#ifdef X86_PPRO_OPT |
281 |
static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;} |
282 |
#else |
283 |
static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;} |
284 |
#endif |
285 |
|
286 |
#elif defined(CPU_CAN_ACCESS_UNALIGNED) |
287 |
|
288 |
/* Other little-endian CPUs which can do unaligned accesses */ |
289 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 x = *a; return (x >> 24) | (x >> 8) & 0xff00 | (x << 8) & 0xff0000 | (x << 24);} |
290 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint16 x = *a; return (x >> 8) | (x << 8);} |
291 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = (v >> 24) | (v >> 8) & 0xff00 | (v << 8) & 0xff0000 | (v << 24);} |
292 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = (v >> 8) | (v << 8);} |
293 |
|
294 |
#else /* CPU_CAN_ACCESS_UNALIGNED */ |
295 |
|
296 |
/* Other little-endian CPUs which can not do unaligned accesses (this needs optimization) */ |
297 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint8 *b = (uint8 *)a; return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];} |
298 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];} |
299 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 24; b[1] = v >> 16; b[2] = v >> 8; b[3] = v;} |
300 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;} |
301 |
|
302 |
#endif /* CPU_CAN_ACCESS_UNALIGNED */ |
303 |
|
304 |
#endif /* WORDS_BIGENDIAN */ |
305 |
|
306 |
#ifndef HAVE_OPTIMIZED_BYTESWAP_32 |
307 |
static inline uae_u32 do_byteswap_32(uae_u32 v) |
308 |
{ return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); } |
309 |
#endif |
310 |
|
311 |
#ifndef HAVE_OPTIMIZED_BYTESWAP_16 |
312 |
static inline uae_u32 do_byteswap_16(uae_u32 v) |
313 |
{ return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); } |
314 |
#endif |
315 |
|
316 |
#define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a))) |
317 |
#define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v)) |
318 |
|
319 |
#define call_mem_get_func(func, addr) ((*func)(addr)) |
320 |
#define call_mem_put_func(func, addr, v) ((*func)(addr, v)) |
321 |
#define __inline__ inline |
322 |
#define CPU_EMU_SIZE 0 |
323 |
#undef NO_INLINE_MEMORY_ACCESS |
324 |
#undef MD_HAVE_MEM_1_FUNCS |
325 |
#define ENUMDECL typedef enum |
326 |
#define ENUMNAME(name) name |
327 |
#define write_log printf |
328 |
|
329 |
#if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) |
330 |
#define ASM_SYM_FOR_FUNC(a) __asm__(a) |
331 |
#else |
332 |
#define ASM_SYM_FOR_FUNC(a) |
333 |
#endif |
334 |
|
335 |
#ifndef REGPARAM |
336 |
# define REGPARAM |
337 |
#endif |
338 |
#define REGPARAM2 |
339 |
|
340 |
#endif |