ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/sysdeps.h
Revision: 1.1
Committed: 2002-03-16T04:00:31Z (22 years, 6 months ago) by nigel
Content type: text/plain
Branch: MAIN
CVS Tags: nigel-build-10
Log Message:
Initial revision of Mac OS X port code. Uses Objective-C++. Needs Mac OS 10.1

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