ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/sysdeps.h
Revision: 1.11
Committed: 2011-03-11T16:47:48Z (13 years, 4 months ago) by asvitkine
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +6 -1 lines
Log Message:
[Joseph Oswald]
Fix MACH timer header

File Contents

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