ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/sysdeps.h
Revision: 1.19
Committed: 2001-07-06T17:36:08Z (23 years, 4 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.18: +0 -3 lines
Log Message:
replaced TIME_OFFSET constant by portable TimeToMacTime() function

File Contents

# Content
1 /*
2 * sysdeps.h - System dependent definitions for Unix
3 *
4 * Basilisk II (C) 1997-2001 Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef SYSDEPS_H
22 #define SYSDEPS_H
23
24 #ifndef __STDC__
25 #error "Your compiler is not ANSI. Get a real one."
26 #endif
27
28 #include "config.h"
29 #include "user_strings_unix.h"
30
31 #ifndef STDC_HEADERS
32 #error "You don't have ANSI C header files."
33 #endif
34
35 #ifdef HAVE_UNISTD_H
36 # include <sys/types.h>
37 # include <unistd.h>
38 #endif
39
40 #include <netinet/in.h>
41 #include <assert.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45
46 #ifdef HAVE_FCNTL_H
47 # include <fcntl.h>
48 #endif
49
50 #ifdef TIME_WITH_SYS_TIME
51 # include <sys/time.h>
52 # include <time.h>
53 #else
54 # ifdef HAVE_SYS_TIME_H
55 # include <sys/time.h>
56 # else
57 # include <time.h>
58 # endif
59 #endif
60
61
62 #ifdef ENABLE_NATIVE_M68K
63
64 /* Mac and host address space are the same */
65 #define REAL_ADDRESSING 1
66
67 /* Using 68k natively */
68 #define EMULATED_68K 0
69
70 /* Mac ROM is not write protected */
71 #define ROM_IS_WRITE_PROTECTED 0
72 #define USE_SCRATCHMEM_SUBTERFUGE 1
73
74 #else
75
76 /* Mac and host address space are distinct */
77 #ifndef REAL_ADDRESSING
78 #define REAL_ADDRESSING 0
79 #endif
80
81 /* Using 68k emulator */
82 #define EMULATED_68K 1
83
84 /* The m68k emulator uses a prefetch buffer ? */
85 #define USE_PREFETCH_BUFFER 0
86
87 /* Mac ROM is write protected when banked memory is used */
88 #if REAL_ADDRESSING || DIRECT_ADDRESSING
89 # define ROM_IS_WRITE_PROTECTED 0
90 # define USE_SCRATCHMEM_SUBTERFUGE 1
91 #else
92 # define ROM_IS_WRITE_PROTECTED 1
93 #endif
94
95 #endif
96
97 /* Direct Addressing requires Video on SEGV signals */
98 #if DIRECT_ADDRESSING && !ENABLE_VOSF
99 # undef ENABLE_VOSF
100 # define ENABLE_VOSF 1
101 #endif
102
103 /* ExtFS is supported */
104 #define SUPPORTS_EXTFS 1
105
106
107 /* Data types */
108 typedef unsigned char uint8;
109 typedef signed char int8;
110 #if SIZEOF_SHORT == 2
111 typedef unsigned short uint16;
112 typedef short int16;
113 #elif SIZEOF_INT == 2
114 typedef unsigned int uint16;
115 typedef int int16;
116 #else
117 #error "No 2 byte type, you lose."
118 #endif
119 #if SIZEOF_INT == 4
120 typedef unsigned int uint32;
121 typedef int int32;
122 #elif SIZEOF_LONG == 4
123 typedef unsigned long uint32;
124 typedef long int32;
125 #else
126 #error "No 4 byte type, you lose."
127 #endif
128 #if SIZEOF_LONG == 8
129 typedef unsigned long uint64;
130 typedef long int64;
131 #define VAL64(a) (a ## l)
132 #define UVAL64(a) (a ## ul)
133 #elif SIZEOF_LONG_LONG == 8
134 typedef unsigned long long uint64;
135 typedef long long int64;
136 #define VAL64(a) (a ## LL)
137 #define UVAL64(a) (a ## uLL)
138 #else
139 #error "No 8 byte type, you lose."
140 #endif
141 #if SIZEOF_VOID_P == 4
142 typedef uint32 uintptr;
143 typedef int32 intptr;
144 #elif SIZEOF_VOID_P == 8
145 typedef uint64 uintptr;
146 typedef int64 intptr;
147 #else
148 #error "Unsupported size of pointer"
149 #endif
150
151 /* Time data type for Time Manager emulation */
152 #ifdef HAVE_CLOCK_GETTIME
153 typedef struct timespec tm_time_t;
154 #else
155 typedef struct timeval tm_time_t;
156 #endif
157
158 /* UAE CPU data types */
159 #define uae_s8 int8
160 #define uae_u8 uint8
161 #define uae_s16 int16
162 #define uae_u16 uint16
163 #define uae_s32 int32
164 #define uae_u32 uint32
165 #define uae_s64 int64
166 #define uae_u64 uint64
167 typedef uae_u32 uaecptr;
168
169 /* Alignment restrictions */
170 #if defined(__i386__) || defined(__powerpc__) || defined(__m68k__)
171 # define CPU_CAN_ACCESS_UNALIGNED
172 #endif
173
174 /* Timing functions */
175 extern uint64 GetTicks_usec(void);
176 extern void Delay_usec(uint32 usec);
177
178 /* UAE CPU defines */
179 #ifdef WORDS_BIGENDIAN
180
181 #ifdef CPU_CAN_ACCESS_UNALIGNED
182
183 /* Big-endian CPUs which can do unaligned accesses */
184 static inline uae_u32 do_get_mem_long(uae_u32 *a) {return *a;}
185 static inline uae_u32 do_get_mem_word(uae_u16 *a) {return *a;}
186 static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = v;}
187 static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = v;}
188
189 #else /* CPU_CAN_ACCESS_UNALIGNED */
190
191 #ifdef sgi
192 /* The SGI MIPSPro compilers can do unaligned accesses given enough hints.
193 * They will automatically inline these routines. */
194 #ifdef __cplusplus
195 extern "C" { /* only the C compiler does unaligned accesses */
196 #endif
197 extern uae_u32 do_get_mem_long(uae_u32 *a);
198 extern uae_u32 do_get_mem_word(uae_u16 *a);
199 extern void do_put_mem_long(uae_u32 *a, uae_u32 v);
200 extern void do_put_mem_word(uae_u16 *a, uae_u32 v);
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #else /* sgi */
206
207 /* Big-endian CPUs which can not do unaligned accesses (this is not the most efficient way to do this...) */
208 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];}
209 static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];}
210 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;}
211 static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;}
212 #endif /* sgi */
213
214 #endif /* CPU_CAN_ACCESS_UNALIGNED */
215
216 #else /* WORDS_BIGENDIAN */
217
218 #ifdef __i386__
219
220 /* Intel x86 */
221 #define X86_PPRO_OPT
222 static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;}
223 #ifdef X86_PPRO_OPT
224 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;}
225 #else
226 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;}
227 #endif
228 #define HAVE_GET_WORD_UNSWAPPED
229 #define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a)))
230 static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;}
231 #ifdef X86_PPRO_OPT
232 static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;}
233 #else
234 static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;}
235 #endif
236 #define HAVE_OPTIMIZED_BYTESWAP_32
237 /* bswap doesn't affect condition codes */
238 static inline uae_u32 do_byteswap_32(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;}
239 #define HAVE_OPTIMIZED_BYTESWAP_16
240 #ifdef X86_PPRO_OPT
241 static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;}
242 #else
243 static inline uae_u32 do_byteswap_16(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;}
244 #endif
245
246 #elif defined(CPU_CAN_ACCESS_UNALIGNED)
247
248 /* Other little-endian CPUs which can do unaligned accesses */
249 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);}
250 static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint16 x = *a; return (x >> 8) | (x << 8);}
251 static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = (v >> 24) | (v >> 8) & 0xff00 | (v << 8) & 0xff0000 | (v << 24);}
252 static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = (v >> 8) | (v << 8);}
253
254 #else /* CPU_CAN_ACCESS_UNALIGNED */
255
256 /* Other little-endian CPUs which can not do unaligned accesses (this needs optimization) */
257 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];}
258 static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];}
259 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;}
260 static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;}
261
262 #endif /* CPU_CAN_ACCESS_UNALIGNED */
263
264 #endif /* WORDS_BIGENDIAN */
265
266 #ifndef HAVE_OPTIMIZED_BYTESWAP_32
267 static inline uae_u32 do_byteswap_32(uae_u32 v)
268 { return (((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v & 0xff) << 24) | ((v & 0xff00) << 8)); }
269 #endif
270
271 #ifndef HAVE_OPTIMIZED_BYTESWAP_16
272 static inline uae_u32 do_byteswap_16(uae_u32 v)
273 { return (((v >> 8) & 0xff) | ((v & 0xff) << 8)); }
274 #endif
275
276 #define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a)))
277 #define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v))
278
279 #define call_mem_get_func(func, addr) ((*func)(addr))
280 #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
281 #define __inline__ inline
282 #define CPU_EMU_SIZE 0
283 #undef NO_INLINE_MEMORY_ACCESS
284 #undef MD_HAVE_MEM_1_FUNCS
285 #define ENUMDECL typedef enum
286 #define ENUMNAME(name) name
287 #define write_log printf
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