ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/sysdeps.h
Revision: 1.1
Committed: 1999-10-03T14:16:25Z (25 years, 1 month ago) by cebix
Content type: text/plain
Branch: MAIN
Branch point for: cebix
Log Message:
Initial revision

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * sysdeps.h - System dependent definitions for Unix
3     *
4     * Basilisk II (C) 1997-1999 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    
30     #ifndef STDC_HEADERS
31     #error "You don't have ANSI C header files."
32     #endif
33    
34     #include <sys/types.h>
35     #include <netinet/in.h>
36     #include <assert.h>
37     #include <stdio.h>
38     #include <stdlib.h>
39     #include <string.h>
40     #include <pthread.h>
41    
42     #ifdef HAVE_UNISTD_H
43     # include <unistd.h>
44     #endif
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     /* Are the Mac and the host address space the same? */
63     #define REAL_ADDRESSING 0
64    
65     /* Are we using a 68k emulator or the real thing? */
66     #define EMULATED_68K 1
67    
68     /* Is the Mac ROM write protected? */
69     #define ROM_IS_WRITE_PROTECTED 1
70    
71     /* Data types */
72     typedef unsigned char uint8;
73     typedef signed char int8;
74     #if SIZEOF_SHORT == 2
75     typedef unsigned short uint16;
76     typedef short int16;
77     #elif SIZEOF_INT == 2
78     typedef unsigned int uint16;
79     typedef int int16;
80     #else
81     #error "No 2 byte type, you lose."
82     #endif
83     #if SIZEOF_INT == 4
84     typedef unsigned int uint32;
85     typedef int int32;
86     #elif SIZEOF_LONG == 4
87     typedef unsigned long uint32;
88     typedef long int32;
89     #else
90     #error "No 4 byte type, you lose."
91     #endif
92     #if SIZEOF_LONG == 8
93     typedef unsigned long uint64;
94     typedef long int64;
95     #elif SIZEOF_LONG_LONG == 8
96     typedef unsigned long long uint64;
97     typedef long long int64;
98     #else
99     #error "No 8 byte type, you lose."
100     #endif
101    
102     /* Time data type for Time Manager emulation */
103     #ifdef HAVE_CLOCK_GETTIME
104     typedef struct timespec tm_time_t;
105     #else
106     typedef struct timeval tm_time_t;
107     #endif
108    
109     /* UAE CPU data types */
110     #define uae_s8 int8
111     #define uae_u8 uint8
112     #define uae_s16 int16
113     #define uae_u16 uint16
114     #define uae_s32 int32
115     #define uae_u32 uint32
116     typedef uae_u32 uaecptr;
117    
118     /* Alignment restrictions */
119     #if defined(__i386__) || defined(__powerpc__)
120     # define CPU_CAN_ACCESS_UNALIGNED
121     #endif
122    
123     /* UAE CPU defines */
124     #ifdef WORDS_BIGENDIAN
125    
126     #ifdef CPU_CAN_ACCESS_UNALIGNED
127    
128     /* Big-endian CPUs which can do unaligned accesses */
129     static inline uae_u32 do_get_mem_long(uae_u32 *a) {return *a;}
130     static inline uae_u32 do_get_mem_word(uae_u16 *a) {return *a;}
131     static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = v;}
132     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = v;}
133    
134     #else /* CPU_CAN_ACCESS_UNALIGNED */
135    
136     #ifdef sgi
137     /* The SGI MIPSPro compilers can do unaligned accesses given enough hints.
138     * They will automatically inline these routines. */
139     #ifdef __cplusplus
140     extern "C" { /* only the C compiler does unaligned accesses */
141     #endif
142     extern uae_u32 do_get_mem_long(uae_u32 *a);
143     extern uae_u32 do_get_mem_word(uae_u16 *a);
144     extern void do_put_mem_long(uae_u32 *a, uae_u32 v);
145     extern void do_put_mem_word(uae_u16 *a, uae_u32 v);
146     #ifdef __cplusplus
147     }
148     #endif
149    
150     #else /* sgi */
151    
152     /* Big-endian CPUs which can not do unaligned accesses (this is not the most efficient way to do this...) */
153     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];}
154     static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];}
155     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;}
156     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;}
157     #endif /* sgi */
158    
159     #endif /* CPU_CAN_ACCESS_UNALIGNED */
160    
161     #else /* WORDS_BIGENDIAN */
162    
163     #ifdef __i386__
164    
165     /* Intel x86 */
166     #define X86_PPRO_OPT
167     static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;}
168     #ifdef X86_PPRO_OPT
169     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;}
170     #else
171     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;}
172     #endif
173     #define HAVE_GET_WORD_UNSWAPPED
174     #define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a)))
175     static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;}
176     #ifdef X86_PPRO_OPT
177     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;}
178     #else
179     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;}
180     #endif
181    
182     #elif defined(CPU_CAN_ACCESS_UNALIGNED)
183    
184     /* Other little-endian CPUs which can do unaligned accesses */
185     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);}
186     static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint16 x = *a; return (x >> 8) | (x << 8);}
187     static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = (v >> 24) | (v >> 8) & 0xff00 | (v << 8) & 0xff0000 | (v << 24);}
188     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = (v >> 8) | (v << 8);}
189    
190     #else /* CPU_CAN_ACCESS_UNALIGNED */
191    
192     /* Other little-endian CPUs which can not do unaligned accesses (this needs optimization) */
193     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];}
194     static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint8 *b = (uint8 *)a; return (b[0] << 8) | b[1];}
195     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;}
196     static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {uint8 *b = (uint8 *)a; b[0] = v >> 8; b[1] = v;}
197    
198     #endif /* CPU_CAN_ACCESS_UNALIGNED */
199    
200     #endif /* WORDS_BIGENDIAN */
201    
202     #define do_get_mem_byte(a) ((uae_u32)*((uae_u8 *)(a)))
203     #define do_put_mem_byte(a, v) (*(uae_u8 *)(a) = (v))
204    
205     #define call_mem_get_func(func, addr) ((*func)(addr))
206     #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
207     #define __inline__ inline
208     #define CPU_EMU_SIZE 0
209     #undef USE_MAPPED_MEMORY
210     #undef CAN_MAP_MEMORY
211     #undef NO_INLINE_MEMORY_ACCESS
212     #undef MD_HAVE_MEM_1_FUNCS
213     #undef USE_COMPILER
214     #define ENUMDECL typedef enum
215     #define ENUMNAME(name) name
216     #define write_log printf
217    
218     #ifdef X86_ASSEMBLY
219     #define ASM_SYM_FOR_FUNC(a) __asm__(a)
220     #else
221     #define ASM_SYM_FOR_FUNC(a)
222     #endif
223    
224     #ifndef REGPARAM
225     # define REGPARAM
226     #endif
227     #define REGPARAM2
228    
229     #endif