ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/sysdeps.h
Revision: 1.6
Committed: 2004-01-12T15:29:24Z (20 years, 6 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.5: +2 -2 lines
Log Message:
Happy New Year! :)

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 cebix 1.6 * $Id: sysdeps.h,v 1.5 2003/03/25 01:42:41 nigel 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     #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 nigel 1.3 #ifdef AVAILABILITYMACROS
66     # include <AvailabilityMacros.h>
67     #endif
68 nigel 1.2
69 nigel 1.1 /* Emulator and host address space are distinct */
70     #ifndef REAL_ADDRESSING
71 nigel 1.2 # define REAL_ADDRESSING 0
72 nigel 1.1 #endif
73    
74     /* Linear address translation (i.e. just an offset between Emulator & host) */
75     #ifndef DIRECT_ADDRESSING
76 nigel 1.2 # ifdef MAC_OS_X_VERSION_10_2
77 nigel 1.3 /* 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 nigel 1.4 # define DIRECT_ADDRESSING 0
80 nigel 1.2 # else
81     # define DIRECT_ADDRESSING 1
82     # endif
83 nigel 1.1 #endif
84    
85     /* Using 68k emulator */
86     #define EMULATED_68K 1
87    
88     /* The m68k emulator uses a prefetch buffer ? */
89     #define USE_PREFETCH_BUFFER 0
90    
91     /* Mac ROM is write protected when banked memory is used */
92     #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    
99    
100     /* ExtFS is supported */
101     #define SUPPORTS_EXTFS 1
102    
103    
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     typedef off_t loff_t;
150 nigel 1.1 #endif
151    
152     /* Time data type for Time Manager emulation */
153     #ifdef HAVE_CLOCK_GETTIME
154     typedef struct timespec tm_time_t;
155     #else
156     typedef struct timeval tm_time_t;
157     #endif
158    
159     /* Offset Mac->Unix time in seconds */
160     #define TIME_OFFSET 0x7c25b080
161    
162     /* UAE CPU data types */
163     #define uae_s8 int8
164     #define uae_u8 uint8
165     #define uae_s16 int16
166     #define uae_u16 uint16
167     #define uae_s32 int32
168     #define uae_u32 uint32
169     #define uae_s64 int64
170     #define uae_u64 uint64
171     typedef uae_u32 uaecptr;
172    
173     /* Alignment restrictions */
174 nigel 1.5 #if defined(__i386__) || defined(__powerpc__) || defined(__m68k__) || defined(__x86_64__)
175 nigel 1.1 # define CPU_CAN_ACCESS_UNALIGNED
176     #endif
177    
178     /* Timing functions */
179     extern uint64 GetTicks_usec(void);
180     extern void Delay_usec(uint32 usec);
181    
182     /* UAE CPU defines */
183     #ifdef WORDS_BIGENDIAN
184    
185     #ifdef CPU_CAN_ACCESS_UNALIGNED
186    
187     /* Big-endian CPUs which can do unaligned accesses */
188     static inline uae_u32 do_get_mem_long(uae_u32 *a) {return *a;}
189     static inline uae_u32 do_get_mem_word(uae_u16 *a) {return *a;}
190     static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = v;}
191     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = v;}
192    
193     #else /* CPU_CAN_ACCESS_UNALIGNED */
194    
195     #ifdef sgi
196     /* The SGI MIPSPro compilers can do unaligned accesses given enough hints.
197     * They will automatically inline these routines. */
198     #ifdef __cplusplus
199     extern "C" { /* only the C compiler does unaligned accesses */
200     #endif
201     extern uae_u32 do_get_mem_long(uae_u32 *a);
202     extern uae_u32 do_get_mem_word(uae_u16 *a);
203     extern void do_put_mem_long(uae_u32 *a, uae_u32 v);
204     extern void do_put_mem_word(uae_u16 *a, uae_u32 v);
205     #ifdef __cplusplus
206     }
207     #endif
208    
209     #else /* sgi */
210    
211     /* Big-endian CPUs which can not do unaligned accesses (this is not the most efficient way to do this...) */
212     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];}
213     static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];}
214     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;}
215     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;}
216     #endif /* sgi */
217    
218     #endif /* CPU_CAN_ACCESS_UNALIGNED */
219    
220     #else /* WORDS_BIGENDIAN */
221    
222 nigel 1.5 #if defined(__i386__) || defined(__x86_64__)
223 nigel 1.1
224     /* Intel x86 */
225     #define X86_PPRO_OPT
226     static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;}
227     #ifdef X86_PPRO_OPT
228     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;}
229     #else
230     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;}
231     #endif
232     #define HAVE_GET_WORD_UNSWAPPED
233     #define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a)))
234     static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;}
235     #ifdef X86_PPRO_OPT
236     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;}
237     #else
238     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;}
239     #endif
240     #define HAVE_OPTIMIZED_BYTESWAP_32
241     /* bswap doesn't affect condition codes */
242     static inline uae_u32 do_byteswap_32(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;}
243     #define HAVE_OPTIMIZED_BYTESWAP_16
244     #ifdef X86_PPRO_OPT
245     static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;}
246     #else
247     static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;}
248     #endif
249    
250     #elif defined(CPU_CAN_ACCESS_UNALIGNED)
251    
252     /* Other little-endian CPUs which can do unaligned accesses */
253     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);}
254     static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint16 x = *a; return (x >> 8) | (x << 8);}
255     static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = (v >> 24) | (v >> 8) & 0xff00 | (v << 8) & 0xff0000 | (v << 24);}
256     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = (v >> 8) | (v << 8);}
257    
258     #else /* CPU_CAN_ACCESS_UNALIGNED */
259    
260     /* Other little-endian CPUs which can not do unaligned accesses (this needs optimization) */
261     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];}
262     static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];}
263     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;}
264     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;}
265    
266     #endif /* CPU_CAN_ACCESS_UNALIGNED */
267    
268     #endif /* WORDS_BIGENDIAN */
269    
270     #ifndef HAVE_OPTIMIZED_BYTESWAP_32
271     static inline uae_u32 do_byteswap_32(uae_u32 v)
272     { return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); }
273     #endif
274    
275     #ifndef HAVE_OPTIMIZED_BYTESWAP_16
276     static inline uae_u32 do_byteswap_16(uae_u32 v)
277     { return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); }
278     #endif
279    
280     #define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a)))
281     #define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v))
282    
283     #define call_mem_get_func(func, addr) ((*func)(addr))
284     #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
285     #define __inline__ inline
286     #define CPU_EMU_SIZE 0
287     #undef NO_INLINE_MEMORY_ACCESS
288     #undef MD_HAVE_MEM_1_FUNCS
289     #define ENUMDECL typedef enum
290     #define ENUMNAME(name) name
291     #define write_log printf
292     #undef USE_MAPPED_MEMORY
293     #undef CAN_MAP_MEMORY
294    
295 nigel 1.5 #if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY)
296 nigel 1.1 #define ASM_SYM_FOR_FUNC(a) __asm__(a)
297     #else
298     #define ASM_SYM_FOR_FUNC(a)
299     #endif
300    
301     #ifndef REGPARAM
302     # define REGPARAM
303     #endif
304     #define REGPARAM2
305    
306     #endif