ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/sysdeps.h
Revision: 1.13
Committed: 2000-09-22T17:14:46Z (24 years, 1 month ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.12: +26 -1 lines
Log Message:
- added [u]intptr types
- set rom protection flag according to the addressing mode used
- set use_prefetch_buffer to 0

File Contents

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