1 |
/* |
2 |
* sysdeps.h - System dependent definitions for Mac OS X. |
3 |
* Based on Unix version |
4 |
* |
5 |
* $Id: sysdeps.h,v 1.2 2002/10/29 14:28:52 nigel Exp $ |
6 |
* |
7 |
* Basilisk II (C) 1997-2001 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_FCNTL_H |
50 |
# include <fcntl.h> |
51 |
#endif |
52 |
|
53 |
#ifdef TIME_WITH_SYS_TIME |
54 |
# include <sys/time.h> |
55 |
# include <time.h> |
56 |
#else |
57 |
# ifdef HAVE_SYS_TIME_H |
58 |
# include <sys/time.h> |
59 |
# else |
60 |
# include <time.h> |
61 |
# endif |
62 |
#endif |
63 |
|
64 |
|
65 |
#ifdef AVAILABILITYMACROS |
66 |
# include <AvailabilityMacros.h> |
67 |
#endif |
68 |
|
69 |
/* Emulator and host address space are distinct */ |
70 |
#ifndef REAL_ADDRESSING |
71 |
# define REAL_ADDRESSING 0 |
72 |
#endif |
73 |
|
74 |
/* Linear address translation (i.e. just an offset between Emulator & host) */ |
75 |
#ifndef DIRECT_ADDRESSING |
76 |
# ifdef MAC_OS_X_VERSION_10_2 |
77 |
/* For some reason, compiling on 10.2 with DIRECT_ADDRESSING enabled gives an */ |
78 |
/* app that never writes to its screen! (i.e. it never calls most of video.cpp) */ |
79 |
# define DIRECT_ADDRESSING 1 |
80 |
//# define DIRECT_ADDRESSING 0 |
81 |
# else |
82 |
# define DIRECT_ADDRESSING 1 |
83 |
# endif |
84 |
#endif |
85 |
|
86 |
/* Using 68k emulator */ |
87 |
#define EMULATED_68K 1 |
88 |
|
89 |
/* The m68k emulator uses a prefetch buffer ? */ |
90 |
#define USE_PREFETCH_BUFFER 0 |
91 |
|
92 |
/* Mac ROM is write protected when banked memory is used */ |
93 |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
94 |
# define ROM_IS_WRITE_PROTECTED 0 |
95 |
# define USE_SCRATCHMEM_SUBTERFUGE 1 |
96 |
#else |
97 |
# define ROM_IS_WRITE_PROTECTED 1 |
98 |
#endif |
99 |
|
100 |
|
101 |
/* ExtFS is supported */ |
102 |
#define SUPPORTS_EXTFS 1 |
103 |
|
104 |
|
105 |
/* Data types */ |
106 |
typedef unsigned char uint8; |
107 |
typedef signed char int8; |
108 |
#if SIZEOF_SHORT == 2 |
109 |
typedef unsigned short uint16; |
110 |
typedef short int16; |
111 |
#elif SIZEOF_INT == 2 |
112 |
typedef unsigned int uint16; |
113 |
typedef int int16; |
114 |
#else |
115 |
#error "No 2 byte type, you lose." |
116 |
#endif |
117 |
#if SIZEOF_INT == 4 |
118 |
typedef unsigned int uint32; |
119 |
typedef int int32; |
120 |
#elif SIZEOF_LONG == 4 |
121 |
typedef unsigned long uint32; |
122 |
typedef long int32; |
123 |
#else |
124 |
#error "No 4 byte type, you lose." |
125 |
#endif |
126 |
#if SIZEOF_LONG == 8 |
127 |
typedef unsigned long uint64; |
128 |
typedef long int64; |
129 |
#define VAL64(a) (a ## l) |
130 |
#define UVAL64(a) (a ## ul) |
131 |
#elif SIZEOF_LONG_LONG == 8 |
132 |
typedef unsigned long long uint64; |
133 |
typedef long long int64; |
134 |
#define VAL64(a) (a ## LL) |
135 |
#define UVAL64(a) (a ## uLL) |
136 |
#else |
137 |
#error "No 8 byte type, you lose." |
138 |
#endif |
139 |
#if SIZEOF_VOID_P == 4 |
140 |
typedef uint32 uintptr; |
141 |
typedef int32 intptr; |
142 |
#elif SIZEOF_VOID_P == 8 |
143 |
typedef uint64 uintptr; |
144 |
typedef int64 intptr; |
145 |
#else |
146 |
#error "Unsupported size of pointer" |
147 |
#endif |
148 |
|
149 |
/* Time data type for Time Manager emulation */ |
150 |
#ifdef HAVE_CLOCK_GETTIME |
151 |
typedef struct timespec tm_time_t; |
152 |
#else |
153 |
typedef struct timeval tm_time_t; |
154 |
#endif |
155 |
|
156 |
/* Offset Mac->Unix time in seconds */ |
157 |
#define TIME_OFFSET 0x7c25b080 |
158 |
|
159 |
/* UAE CPU data types */ |
160 |
#define uae_s8 int8 |
161 |
#define uae_u8 uint8 |
162 |
#define uae_s16 int16 |
163 |
#define uae_u16 uint16 |
164 |
#define uae_s32 int32 |
165 |
#define uae_u32 uint32 |
166 |
#define uae_s64 int64 |
167 |
#define uae_u64 uint64 |
168 |
typedef uae_u32 uaecptr; |
169 |
|
170 |
/* Alignment restrictions */ |
171 |
#if defined(__i386__) || defined(__powerpc__) || defined(__m68k__) |
172 |
# define CPU_CAN_ACCESS_UNALIGNED |
173 |
#endif |
174 |
|
175 |
/* Timing functions */ |
176 |
extern uint64 GetTicks_usec(void); |
177 |
extern void Delay_usec(uint32 usec); |
178 |
|
179 |
/* UAE CPU defines */ |
180 |
#ifdef WORDS_BIGENDIAN |
181 |
|
182 |
#ifdef CPU_CAN_ACCESS_UNALIGNED |
183 |
|
184 |
/* Big-endian CPUs which can do unaligned accesses */ |
185 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {return *a;} |
186 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {return *a;} |
187 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = v;} |
188 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = v;} |
189 |
|
190 |
#else /* CPU_CAN_ACCESS_UNALIGNED */ |
191 |
|
192 |
#ifdef sgi |
193 |
/* The SGI MIPSPro compilers can do unaligned accesses given enough hints. |
194 |
* They will automatically inline these routines. */ |
195 |
#ifdef __cplusplus |
196 |
extern "C" { /* only the C compiler does unaligned accesses */ |
197 |
#endif |
198 |
extern uae_u32 do_get_mem_long(uae_u32 *a); |
199 |
extern uae_u32 do_get_mem_word(uae_u16 *a); |
200 |
extern void do_put_mem_long(uae_u32 *a, uae_u32 v); |
201 |
extern void do_put_mem_word(uae_u16 *a, uae_u32 v); |
202 |
#ifdef __cplusplus |
203 |
} |
204 |
#endif |
205 |
|
206 |
#else /* sgi */ |
207 |
|
208 |
/* Big-endian CPUs which can not do unaligned accesses (this is not the most efficient way to do this...) */ |
209 |
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];} |
210 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];} |
211 |
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;} |
212 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;} |
213 |
#endif /* sgi */ |
214 |
|
215 |
#endif /* CPU_CAN_ACCESS_UNALIGNED */ |
216 |
|
217 |
#else /* WORDS_BIGENDIAN */ |
218 |
|
219 |
#ifdef __i386__ |
220 |
|
221 |
/* Intel x86 */ |
222 |
#define X86_PPRO_OPT |
223 |
static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;} |
224 |
#ifdef X86_PPRO_OPT |
225 |
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;} |
226 |
#else |
227 |
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;} |
228 |
#endif |
229 |
#define HAVE_GET_WORD_UNSWAPPED |
230 |
#define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a))) |
231 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
232 |
#ifdef X86_PPRO_OPT |
233 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;} |
234 |
#else |
235 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
236 |
#endif |
237 |
#define HAVE_OPTIMIZED_BYTESWAP_32 |
238 |
/* bswap doesn't affect condition codes */ |
239 |
static inline uae_u32 do_byteswap_32(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;} |
240 |
#define HAVE_OPTIMIZED_BYTESWAP_16 |
241 |
#ifdef X86_PPRO_OPT |
242 |
static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;} |
243 |
#else |
244 |
static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;} |
245 |
#endif |
246 |
|
247 |
#elif defined(CPU_CAN_ACCESS_UNALIGNED) |
248 |
|
249 |
/* Other little-endian CPUs which can do unaligned accesses */ |
250 |
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);} |
251 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint16 x = *a; return (x >> 8) | (x << 8);} |
252 |
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = (v >> 24) | (v >> 8) & 0xff00 | (v << 8) & 0xff0000 | (v << 24);} |
253 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = (v >> 8) | (v << 8);} |
254 |
|
255 |
#else /* CPU_CAN_ACCESS_UNALIGNED */ |
256 |
|
257 |
/* Other little-endian CPUs which can not do unaligned accesses (this needs optimization) */ |
258 |
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];} |
259 |
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];} |
260 |
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;} |
261 |
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;} |
262 |
|
263 |
#endif /* CPU_CAN_ACCESS_UNALIGNED */ |
264 |
|
265 |
#endif /* WORDS_BIGENDIAN */ |
266 |
|
267 |
#ifndef HAVE_OPTIMIZED_BYTESWAP_32 |
268 |
static inline uae_u32 do_byteswap_32(uae_u32 v) |
269 |
{ return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); } |
270 |
#endif |
271 |
|
272 |
#ifndef HAVE_OPTIMIZED_BYTESWAP_16 |
273 |
static inline uae_u32 do_byteswap_16(uae_u32 v) |
274 |
{ return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); } |
275 |
#endif |
276 |
|
277 |
#define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a))) |
278 |
#define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v)) |
279 |
|
280 |
#define call_mem_get_func(func, addr) ((*func)(addr)) |
281 |
#define call_mem_put_func(func, addr, v) ((*func)(addr, v)) |
282 |
#define __inline__ inline |
283 |
#define CPU_EMU_SIZE 0 |
284 |
#undef NO_INLINE_MEMORY_ACCESS |
285 |
#undef MD_HAVE_MEM_1_FUNCS |
286 |
#define ENUMDECL typedef enum |
287 |
#define ENUMNAME(name) name |
288 |
#define write_log printf |
289 |
#undef USE_MAPPED_MEMORY |
290 |
#undef CAN_MAP_MEMORY |
291 |
|
292 |
#ifdef X86_ASSEMBLY |
293 |
#define ASM_SYM_FOR_FUNC(a) __asm__(a) |
294 |
#else |
295 |
#define ASM_SYM_FOR_FUNC(a) |
296 |
#endif |
297 |
|
298 |
#ifndef REGPARAM |
299 |
# define REGPARAM |
300 |
#endif |
301 |
#define REGPARAM2 |
302 |
|
303 |
#endif |