ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/sysdeps.h
Revision: 1.22
Committed: 2002-02-07T16:10:55Z (22 years, 4 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.21: +5 -0 lines
Log Message:
cleaned up pthread attributes [Brian Johnson]

File Contents

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