ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/sysdeps.h
Revision: 1.2
Committed: 2002-10-29T14:28:52Z (22 years ago) by nigel
Content type: text/plain
Branch: MAIN
Changes since 1.1: +11 -3 lines
Log Message:
Fixes for compiling on 10.2

File Contents

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