1 |
cebix |
1.1 |
/* |
2 |
|
|
* sysdeps.h - System dependent definitions for Unix |
3 |
|
|
* |
4 |
cebix |
1.21 |
* Basilisk II (C) 1997-2002 Christian Bauer |
5 |
cebix |
1.1 |
* |
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 |
cebix |
1.3 |
#include "user_strings_unix.h" |
30 |
cebix |
1.1 |
|
31 |
|
|
#ifndef STDC_HEADERS |
32 |
|
|
#error "You don't have ANSI C header files." |
33 |
|
|
#endif |
34 |
|
|
|
35 |
cebix |
1.2 |
#ifdef HAVE_UNISTD_H |
36 |
|
|
# include <sys/types.h> |
37 |
|
|
# include <unistd.h> |
38 |
|
|
#endif |
39 |
|
|
|
40 |
cebix |
1.1 |
#include <netinet/in.h> |
41 |
|
|
#include <assert.h> |
42 |
|
|
#include <stdio.h> |
43 |
|
|
#include <stdlib.h> |
44 |
|
|
#include <string.h> |
45 |
|
|
|
46 |
gbeauche |
1.24 |
#ifdef HAVE_PTHREADS |
47 |
|
|
# include <pthread.h> |
48 |
|
|
#endif |
49 |
|
|
|
50 |
cebix |
1.1 |
#ifdef HAVE_FCNTL_H |
51 |
|
|
# include <fcntl.h> |
52 |
|
|
#endif |
53 |
|
|
|
54 |
|
|
#ifdef TIME_WITH_SYS_TIME |
55 |
|
|
# include <sys/time.h> |
56 |
|
|
# include <time.h> |
57 |
|
|
#else |
58 |
|
|
# ifdef HAVE_SYS_TIME_H |
59 |
|
|
# include <sys/time.h> |
60 |
|
|
# else |
61 |
|
|
# include <time.h> |
62 |
|
|
# endif |
63 |
|
|
#endif |
64 |
|
|
|
65 |
|
|
|
66 |
cebix |
1.11 |
#ifdef ENABLE_NATIVE_M68K |
67 |
|
|
|
68 |
|
|
/* Mac and host address space are the same */ |
69 |
|
|
#define REAL_ADDRESSING 1 |
70 |
|
|
|
71 |
|
|
/* Using 68k natively */ |
72 |
|
|
#define EMULATED_68K 0 |
73 |
|
|
|
74 |
|
|
/* Mac ROM is not write protected */ |
75 |
|
|
#define ROM_IS_WRITE_PROTECTED 0 |
76 |
cebix |
1.14 |
#define USE_SCRATCHMEM_SUBTERFUGE 1 |
77 |
cebix |
1.11 |
|
78 |
|
|
#else |
79 |
|
|
|
80 |
|
|
/* Mac and host address space are distinct */ |
81 |
gbeauche |
1.13 |
#ifndef REAL_ADDRESSING |
82 |
cebix |
1.1 |
#define REAL_ADDRESSING 0 |
83 |
gbeauche |
1.13 |
#endif |
84 |
cebix |
1.1 |
|
85 |
cebix |
1.11 |
/* Using 68k emulator */ |
86 |
cebix |
1.1 |
#define EMULATED_68K 1 |
87 |
|
|
|
88 |
gbeauche |
1.13 |
/* The m68k emulator uses a prefetch buffer ? */ |
89 |
|
|
#define USE_PREFETCH_BUFFER 0 |
90 |
|
|
|
91 |
cebix |
1.14 |
/* Mac ROM is write protected when banked memory is used */ |
92 |
gbeauche |
1.13 |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
93 |
|
|
# define ROM_IS_WRITE_PROTECTED 0 |
94 |
|
|
# define USE_SCRATCHMEM_SUBTERFUGE 1 |
95 |
|
|
#else |
96 |
|
|
# define ROM_IS_WRITE_PROTECTED 1 |
97 |
|
|
#endif |
98 |
cebix |
1.1 |
|
99 |
cebix |
1.11 |
#endif |
100 |
|
|
|
101 |
gbeauche |
1.13 |
/* Direct Addressing requires Video on SEGV signals */ |
102 |
|
|
#if DIRECT_ADDRESSING && !ENABLE_VOSF |
103 |
|
|
# undef ENABLE_VOSF |
104 |
|
|
# define ENABLE_VOSF 1 |
105 |
|
|
#endif |
106 |
|
|
|
107 |
cebix |
1.6 |
/* ExtFS is supported */ |
108 |
|
|
#define SUPPORTS_EXTFS 1 |
109 |
cebix |
1.11 |
|
110 |
cebix |
1.20 |
/* BSD socket API supported */ |
111 |
|
|
#define SUPPORTS_UDP_TUNNEL 1 |
112 |
|
|
|
113 |
cebix |
1.6 |
|
114 |
cebix |
1.1 |
/* Data types */ |
115 |
|
|
typedef unsigned char uint8; |
116 |
|
|
typedef signed char int8; |
117 |
|
|
#if SIZEOF_SHORT == 2 |
118 |
|
|
typedef unsigned short uint16; |
119 |
|
|
typedef short int16; |
120 |
|
|
#elif SIZEOF_INT == 2 |
121 |
|
|
typedef unsigned int uint16; |
122 |
|
|
typedef int int16; |
123 |
|
|
#else |
124 |
|
|
#error "No 2 byte type, you lose." |
125 |
|
|
#endif |
126 |
|
|
#if SIZEOF_INT == 4 |
127 |
|
|
typedef unsigned int uint32; |
128 |
|
|
typedef int int32; |
129 |
|
|
#elif SIZEOF_LONG == 4 |
130 |
|
|
typedef unsigned long uint32; |
131 |
|
|
typedef long int32; |
132 |
|
|
#else |
133 |
|
|
#error "No 4 byte type, you lose." |
134 |
|
|
#endif |
135 |
|
|
#if SIZEOF_LONG == 8 |
136 |
|
|
typedef unsigned long uint64; |
137 |
|
|
typedef long int64; |
138 |
cebix |
1.8 |
#define VAL64(a) (a ## l) |
139 |
|
|
#define UVAL64(a) (a ## ul) |
140 |
cebix |
1.1 |
#elif SIZEOF_LONG_LONG == 8 |
141 |
|
|
typedef unsigned long long uint64; |
142 |
|
|
typedef long long int64; |
143 |
cebix |
1.8 |
#define VAL64(a) (a ## LL) |
144 |
|
|
#define UVAL64(a) (a ## uLL) |
145 |
cebix |
1.1 |
#else |
146 |
|
|
#error "No 8 byte type, you lose." |
147 |
gbeauche |
1.13 |
#endif |
148 |
|
|
#if SIZEOF_VOID_P == 4 |
149 |
|
|
typedef uint32 uintptr; |
150 |
|
|
typedef int32 intptr; |
151 |
|
|
#elif SIZEOF_VOID_P == 8 |
152 |
|
|
typedef uint64 uintptr; |
153 |
|
|
typedef int64 intptr; |
154 |
|
|
#else |
155 |
|
|
#error "Unsupported size of pointer" |
156 |
cebix |
1.1 |
#endif |
157 |
|
|
|
158 |
|
|
/* Time data type for Time Manager emulation */ |
159 |
|
|
#ifdef HAVE_CLOCK_GETTIME |
160 |
|
|
typedef struct timespec tm_time_t; |
161 |
|
|
#else |
162 |
|
|
typedef struct timeval tm_time_t; |
163 |
|
|
#endif |
164 |
|
|
|
165 |
gbeauche |
1.23 |
/* Define codes for all the float formats that we know of. |
166 |
|
|
* Though we only handle IEEE format. */ |
167 |
|
|
#define UNKNOWN_FLOAT_FORMAT 0 |
168 |
|
|
#define IEEE_FLOAT_FORMAT 1 |
169 |
|
|
#define VAX_FLOAT_FORMAT 2 |
170 |
|
|
#define IBM_FLOAT_FORMAT 3 |
171 |
|
|
#define C4X_FLOAT_FORMAT 4 |
172 |
|
|
|
173 |
cebix |
1.1 |
/* UAE CPU data types */ |
174 |
|
|
#define uae_s8 int8 |
175 |
|
|
#define uae_u8 uint8 |
176 |
|
|
#define uae_s16 int16 |
177 |
|
|
#define uae_u16 uint16 |
178 |
|
|
#define uae_s32 int32 |
179 |
|
|
#define uae_u32 uint32 |
180 |
cebix |
1.7 |
#define uae_s64 int64 |
181 |
|
|
#define uae_u64 uint64 |
182 |
cebix |
1.1 |
typedef uae_u32 uaecptr; |
183 |
|
|
|
184 |
|
|
/* Alignment restrictions */ |
185 |
gbeauche |
1.25 |
#if defined(__i386__) || defined(__powerpc__) || defined(__m68k__) || defined(__x86_64__) |
186 |
cebix |
1.1 |
# define CPU_CAN_ACCESS_UNALIGNED |
187 |
|
|
#endif |
188 |
|
|
|
189 |
cebix |
1.12 |
/* Timing functions */ |
190 |
|
|
extern uint64 GetTicks_usec(void); |
191 |
|
|
extern void Delay_usec(uint32 usec); |
192 |
|
|
|
193 |
cebix |
1.22 |
#ifdef HAVE_PTHREADS |
194 |
|
|
/* Centralized pthread attribute setup */ |
195 |
|
|
void Set_pthread_attr(pthread_attr_t *attr, int priority); |
196 |
|
|
#endif |
197 |
|
|
|
198 |
cebix |
1.1 |
/* UAE CPU defines */ |
199 |
|
|
#ifdef WORDS_BIGENDIAN |
200 |
|
|
|
201 |
|
|
#ifdef CPU_CAN_ACCESS_UNALIGNED |
202 |
|
|
|
203 |
|
|
/* Big-endian CPUs which can do unaligned accesses */ |
204 |
|
|
static inline uae_u32 do_get_mem_long(uae_u32 *a) {return *a;} |
205 |
|
|
static inline uae_u32 do_get_mem_word(uae_u16 *a) {return *a;} |
206 |
|
|
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = v;} |
207 |
|
|
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = v;} |
208 |
|
|
|
209 |
|
|
#else /* CPU_CAN_ACCESS_UNALIGNED */ |
210 |
|
|
|
211 |
|
|
#ifdef sgi |
212 |
|
|
/* The SGI MIPSPro compilers can do unaligned accesses given enough hints. |
213 |
|
|
* They will automatically inline these routines. */ |
214 |
|
|
#ifdef __cplusplus |
215 |
|
|
extern "C" { /* only the C compiler does unaligned accesses */ |
216 |
|
|
#endif |
217 |
|
|
extern uae_u32 do_get_mem_long(uae_u32 *a); |
218 |
|
|
extern uae_u32 do_get_mem_word(uae_u16 *a); |
219 |
|
|
extern void do_put_mem_long(uae_u32 *a, uae_u32 v); |
220 |
|
|
extern void do_put_mem_word(uae_u16 *a, uae_u32 v); |
221 |
|
|
#ifdef __cplusplus |
222 |
|
|
} |
223 |
|
|
#endif |
224 |
|
|
|
225 |
|
|
#else /* sgi */ |
226 |
|
|
|
227 |
|
|
/* Big-endian CPUs which can not do unaligned accesses (this is not the most efficient way to do this...) */ |
228 |
|
|
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];} |
229 |
|
|
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];} |
230 |
|
|
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;} |
231 |
|
|
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;} |
232 |
|
|
#endif /* sgi */ |
233 |
|
|
|
234 |
|
|
#endif /* CPU_CAN_ACCESS_UNALIGNED */ |
235 |
|
|
|
236 |
|
|
#else /* WORDS_BIGENDIAN */ |
237 |
|
|
|
238 |
gbeauche |
1.25 |
#if defined(__i386__) || defined(__x86_64__) |
239 |
cebix |
1.1 |
|
240 |
|
|
/* Intel x86 */ |
241 |
|
|
#define X86_PPRO_OPT |
242 |
|
|
static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;} |
243 |
|
|
#ifdef X86_PPRO_OPT |
244 |
|
|
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;} |
245 |
|
|
#else |
246 |
|
|
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;} |
247 |
|
|
#endif |
248 |
|
|
#define HAVE_GET_WORD_UNSWAPPED |
249 |
|
|
#define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a))) |
250 |
|
|
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
251 |
|
|
#ifdef X86_PPRO_OPT |
252 |
|
|
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;} |
253 |
|
|
#else |
254 |
|
|
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;} |
255 |
|
|
#endif |
256 |
gbeauche |
1.16 |
#define HAVE_OPTIMIZED_BYTESWAP_32 |
257 |
|
|
/* bswap doesn't affect condition codes */ |
258 |
|
|
static inline uae_u32 do_byteswap_32(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;} |
259 |
|
|
#define HAVE_OPTIMIZED_BYTESWAP_16 |
260 |
|
|
#ifdef X86_PPRO_OPT |
261 |
|
|
static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;} |
262 |
|
|
#else |
263 |
|
|
static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;} |
264 |
|
|
#endif |
265 |
cebix |
1.1 |
|
266 |
|
|
#elif defined(CPU_CAN_ACCESS_UNALIGNED) |
267 |
|
|
|
268 |
|
|
/* Other little-endian CPUs which can do unaligned accesses */ |
269 |
|
|
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);} |
270 |
|
|
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint16 x = *a; return (x >> 8) | (x << 8);} |
271 |
|
|
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = (v >> 24) | (v >> 8) & 0xff00 | (v << 8) & 0xff0000 | (v << 24);} |
272 |
|
|
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = (v >> 8) | (v << 8);} |
273 |
|
|
|
274 |
|
|
#else /* CPU_CAN_ACCESS_UNALIGNED */ |
275 |
|
|
|
276 |
|
|
/* Other little-endian CPUs which can not do unaligned accesses (this needs optimization) */ |
277 |
|
|
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];} |
278 |
|
|
static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];} |
279 |
|
|
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;} |
280 |
|
|
static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;} |
281 |
|
|
|
282 |
|
|
#endif /* CPU_CAN_ACCESS_UNALIGNED */ |
283 |
|
|
|
284 |
|
|
#endif /* WORDS_BIGENDIAN */ |
285 |
gbeauche |
1.16 |
|
286 |
|
|
#ifndef HAVE_OPTIMIZED_BYTESWAP_32 |
287 |
|
|
static inline uae_u32 do_byteswap_32(uae_u32 v) |
288 |
|
|
{ return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); } |
289 |
|
|
#endif |
290 |
|
|
|
291 |
|
|
#ifndef HAVE_OPTIMIZED_BYTESWAP_16 |
292 |
|
|
static inline uae_u32 do_byteswap_16(uae_u32 v) |
293 |
|
|
{ return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); } |
294 |
|
|
#endif |
295 |
cebix |
1.1 |
|
296 |
|
|
#define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a))) |
297 |
|
|
#define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v)) |
298 |
|
|
|
299 |
|
|
#define call_mem_get_func(func, addr) ((*func)(addr)) |
300 |
|
|
#define call_mem_put_func(func, addr, v) ((*func)(addr, v)) |
301 |
|
|
#define __inline__ inline |
302 |
|
|
#define CPU_EMU_SIZE 0 |
303 |
|
|
#undef NO_INLINE_MEMORY_ACCESS |
304 |
|
|
#undef MD_HAVE_MEM_1_FUNCS |
305 |
|
|
#define ENUMDECL typedef enum |
306 |
|
|
#define ENUMNAME(name) name |
307 |
|
|
#define write_log printf |
308 |
|
|
|
309 |
gbeauche |
1.26 |
#if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) |
310 |
cebix |
1.1 |
#define ASM_SYM_FOR_FUNC(a) __asm__(a) |
311 |
|
|
#else |
312 |
|
|
#define ASM_SYM_FOR_FUNC(a) |
313 |
|
|
#endif |
314 |
|
|
|
315 |
|
|
#ifndef REGPARAM |
316 |
|
|
# define REGPARAM |
317 |
|
|
#endif |
318 |
|
|
#define REGPARAM2 |
319 |
|
|
|
320 |
|
|
#endif |