ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/sysdeps.h
Revision: 1.11
Committed: 2000-07-13T13:47:11Z (24 years, 3 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: snapshot-13072000
Changes since 1.10: +19 -4 lines
Log Message:
- first version to run natively on NetBSD/m68k

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