ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/sysdeps.h
Revision: 1.7
Committed: 2004-01-20T23:35:47Z (20 years, 9 months ago) by nigel
Content type: text/plain
Branch: MAIN
Changes since 1.6: +28 -17 lines
Log Message:
Incorporate recent changes from Unix/sysdeps.h

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