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