59 |
|
# endif |
60 |
|
#endif |
61 |
|
|
62 |
< |
// Are we using a PPC emulator or the real thing? |
63 |
< |
#ifdef __powerpc__ |
64 |
< |
#define EMULATED_PPC 0 |
65 |
< |
#else |
66 |
< |
#define EMULATED_PPC 1 |
67 |
< |
#endif |
62 |
> |
// Define for external components |
63 |
> |
#define SHEEPSHAVER 1 |
64 |
> |
|
65 |
> |
// Mac and host address space are the same |
66 |
> |
#define REAL_ADDRESSING 1 |
67 |
|
|
68 |
|
#define POWERPC_ROM 1 |
69 |
|
|
70 |
+ |
#if EMULATED_PPC |
71 |
+ |
// Handle interrupts asynchronously? |
72 |
+ |
#define ASYNC_IRQ 0 |
73 |
+ |
// Mac ROM is write protected when banked memory is used |
74 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
75 |
+ |
# define ROM_IS_WRITE_PROTECTED 0 |
76 |
+ |
# define USE_SCRATCHMEM_SUBTERFUGE 1 |
77 |
+ |
#else |
78 |
+ |
# define ROM_IS_WRITE_PROTECTED 1 |
79 |
+ |
#endif |
80 |
+ |
#else |
81 |
+ |
// Mac ROM is write protected |
82 |
+ |
#define ROM_IS_WRITE_PROTECTED 1 |
83 |
+ |
#define USE_SCRATCHMEM_SUBTERFUGE 0 |
84 |
+ |
#endif |
85 |
+ |
|
86 |
|
// Data types |
87 |
|
typedef unsigned char uint8; |
88 |
|
typedef signed char int8; |
107 |
|
#if SIZEOF_LONG == 8 |
108 |
|
typedef unsigned long uint64; |
109 |
|
typedef long int64; |
110 |
+ |
#define VAL64(a) (a ## l) |
111 |
+ |
#define UVAL64(a) (a ## ul) |
112 |
|
#elif SIZEOF_LONG_LONG == 8 |
113 |
|
typedef unsigned long long uint64; |
114 |
|
typedef long long int64; |
115 |
+ |
#define VAL64(a) (a ## LL) |
116 |
+ |
#define UVAL64(a) (a ## uLL) |
117 |
|
#else |
118 |
|
#error "No 8 byte type, you lose." |
119 |
|
#endif |
120 |
+ |
#if SIZEOF_VOID_P == 4 |
121 |
+ |
typedef uint32 uintptr; |
122 |
+ |
typedef int32 intptr; |
123 |
+ |
#elif SIZEOF_VOID_P == 8 |
124 |
+ |
typedef uint64 uintptr; |
125 |
+ |
typedef int64 intptr; |
126 |
+ |
#else |
127 |
+ |
#error "Unsupported size of pointer" |
128 |
+ |
#endif |
129 |
+ |
|
130 |
+ |
// Helper functions to byteswap data |
131 |
+ |
#ifdef HAVE_BYTESWAP_H |
132 |
+ |
#include <byteswap.h> |
133 |
+ |
#endif |
134 |
+ |
|
135 |
+ |
#ifndef bswap_16 |
136 |
+ |
#define bswap_16 generic_bswap_16 |
137 |
+ |
#endif |
138 |
+ |
|
139 |
+ |
static inline uint16 generic_bswap_16(uint16 x) |
140 |
+ |
{ |
141 |
+ |
return ((x & 0xff) << 8) | ((x >> 8) & 0xff); |
142 |
+ |
} |
143 |
+ |
|
144 |
+ |
#ifndef bswap_32 |
145 |
+ |
#define bswap_32 generic_bswap_32 |
146 |
+ |
#endif |
147 |
+ |
|
148 |
+ |
static inline uint32 generic_bswap_32(uint32 x) |
149 |
+ |
{ |
150 |
+ |
return (((x & 0xff000000) >> 24) | |
151 |
+ |
((x & 0x00ff0000) >> 8) | |
152 |
+ |
((x & 0x0000ff00) << 8) | |
153 |
+ |
((x & 0x000000ff) << 24) ); |
154 |
+ |
} |
155 |
+ |
|
156 |
+ |
#ifndef bswap_64 |
157 |
+ |
#define bswap_64 generic_bswap_64 |
158 |
+ |
#endif |
159 |
+ |
|
160 |
+ |
static inline uint64 generic_bswap_64(uint64 x) |
161 |
+ |
{ |
162 |
+ |
return (((x & UVAL64(0xff00000000000000)) >> 56) | |
163 |
+ |
((x & UVAL64(0x00ff000000000000)) >> 40) | |
164 |
+ |
((x & UVAL64(0x0000ff0000000000)) >> 24) | |
165 |
+ |
((x & UVAL64(0x000000ff00000000)) >> 8) | |
166 |
+ |
((x & UVAL64(0x00000000ff000000)) << 8) | |
167 |
+ |
((x & UVAL64(0x0000000000ff0000)) << 24) | |
168 |
+ |
((x & UVAL64(0x000000000000ff00)) << 40) | |
169 |
+ |
((x & UVAL64(0x00000000000000ff)) << 56) ); |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
#ifdef WORDS_BIGENDIAN |
173 |
+ |
static inline uint16 tswap16(uint16 x) { return x; } |
174 |
+ |
static inline uint32 tswap32(uint32 x) { return x; } |
175 |
+ |
static inline uint64 tswap64(uint64 x) { return x; } |
176 |
+ |
#else |
177 |
+ |
static inline uint16 tswap16(uint16 x) { return bswap_16(x); } |
178 |
+ |
static inline uint32 tswap32(uint32 x) { return bswap_32(x); } |
179 |
+ |
static inline uint64 tswap64(uint64 x) { return bswap_64(x); } |
180 |
+ |
#endif |
181 |
+ |
|
182 |
+ |
// spin locks |
183 |
+ |
#ifdef __GNUC__ |
184 |
+ |
|
185 |
+ |
#ifdef __powerpc__ |
186 |
+ |
#define HAVE_TEST_AND_SET 1 |
187 |
+ |
static inline int testandset(int *p) |
188 |
+ |
{ |
189 |
+ |
int ret; |
190 |
+ |
__asm__ __volatile__("0: lwarx %0,0,%1 ;" |
191 |
+ |
" xor. %0,%3,%0;" |
192 |
+ |
" bne 1f;" |
193 |
+ |
" stwcx. %2,0,%1;" |
194 |
+ |
" bne- 0b;" |
195 |
+ |
"1: " |
196 |
+ |
: "=&r" (ret) |
197 |
+ |
: "r" (p), "r" (1), "r" (0) |
198 |
+ |
: "cr0", "memory"); |
199 |
+ |
return ret; |
200 |
+ |
} |
201 |
+ |
#endif |
202 |
+ |
|
203 |
+ |
#ifdef __i386__ |
204 |
+ |
#define HAVE_TEST_AND_SET 1 |
205 |
+ |
static inline int testandset(int *p) |
206 |
+ |
{ |
207 |
+ |
char ret; |
208 |
+ |
long int readval; |
209 |
+ |
|
210 |
+ |
__asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0" |
211 |
+ |
: "=q" (ret), "=m" (*p), "=a" (readval) |
212 |
+ |
: "r" (1), "m" (*p), "a" (0) |
213 |
+ |
: "memory"); |
214 |
+ |
return ret; |
215 |
+ |
} |
216 |
+ |
#endif |
217 |
+ |
|
218 |
+ |
#ifdef __s390__ |
219 |
+ |
#define HAVE_TEST_AND_SET 1 |
220 |
+ |
static inline int testandset(int *p) |
221 |
+ |
{ |
222 |
+ |
int ret; |
223 |
+ |
|
224 |
+ |
__asm__ __volatile__("0: cs %0,%1,0(%2)\n" |
225 |
+ |
" jl 0b" |
226 |
+ |
: "=&d" (ret) |
227 |
+ |
: "r" (1), "a" (p), "0" (*p) |
228 |
+ |
: "cc", "memory" ); |
229 |
+ |
return ret; |
230 |
+ |
} |
231 |
+ |
#endif |
232 |
+ |
|
233 |
+ |
#ifdef __alpha__ |
234 |
+ |
#define HAVE_TEST_AND_SET 1 |
235 |
+ |
static inline int testandset(int *p) |
236 |
+ |
{ |
237 |
+ |
int ret; |
238 |
+ |
unsigned long one; |
239 |
+ |
|
240 |
+ |
__asm__ __volatile__("0: mov 1,%2\n" |
241 |
+ |
" ldl_l %0,%1\n" |
242 |
+ |
" stl_c %2,%1\n" |
243 |
+ |
" beq %2,1f\n" |
244 |
+ |
".subsection 2\n" |
245 |
+ |
"1: br 0b\n" |
246 |
+ |
".previous" |
247 |
+ |
: "=r" (ret), "=m" (*p), "=r" (one) |
248 |
+ |
: "m" (*p)); |
249 |
+ |
return ret; |
250 |
+ |
} |
251 |
+ |
#endif |
252 |
+ |
|
253 |
+ |
#ifdef __sparc__ |
254 |
+ |
#define HAVE_TEST_AND_SET 1 |
255 |
+ |
static inline int testandset(int *p) |
256 |
+ |
{ |
257 |
+ |
int ret; |
258 |
+ |
|
259 |
+ |
__asm__ __volatile__("ldstub [%1], %0" |
260 |
+ |
: "=r" (ret) |
261 |
+ |
: "r" (p) |
262 |
+ |
: "memory"); |
263 |
+ |
|
264 |
+ |
return (ret ? 1 : 0); |
265 |
+ |
} |
266 |
+ |
#endif |
267 |
+ |
|
268 |
+ |
#ifdef __arm__ |
269 |
+ |
#define HAVE_TEST_AND_SET 1 |
270 |
+ |
static inline int testandset(int *p) |
271 |
+ |
{ |
272 |
+ |
register unsigned int ret; |
273 |
+ |
__asm__ __volatile__("swp %0, %1, [%2]" |
274 |
+ |
: "=r"(ret) |
275 |
+ |
: "0"(1), "r"(p)); |
276 |
+ |
|
277 |
+ |
return ret; |
278 |
+ |
} |
279 |
+ |
#endif |
280 |
+ |
|
281 |
+ |
#endif /* __GNUC__ */ |
282 |
+ |
|
283 |
+ |
#if HAVE_TEST_AND_SET |
284 |
+ |
#define HAVE_SPINLOCKS 1 |
285 |
+ |
typedef int spinlock_t; |
286 |
+ |
|
287 |
+ |
const spinlock_t SPIN_LOCK_UNLOCKED = 0; |
288 |
+ |
|
289 |
+ |
static inline void spin_lock(spinlock_t *lock) |
290 |
+ |
{ |
291 |
+ |
while (testandset(lock)); |
292 |
+ |
} |
293 |
+ |
|
294 |
+ |
static inline void spin_unlock(spinlock_t *lock) |
295 |
+ |
{ |
296 |
+ |
*lock = 0; |
297 |
+ |
} |
298 |
+ |
|
299 |
+ |
static inline int spin_trylock(spinlock_t *lock) |
300 |
+ |
{ |
301 |
+ |
return !testandset(lock); |
302 |
+ |
} |
303 |
+ |
#endif |
304 |
|
|
305 |
|
// Time data type for Time Manager emulation |
306 |
|
#ifdef HAVE_CLOCK_GETTIME |
330 |
|
#define CallMacOS6(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6) call_macos6((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5, (uint32)arg6) |
331 |
|
#define CallMacOS7(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6, arg7) call_macos7((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5, (uint32)arg6, (uint32)arg7) |
332 |
|
|
333 |
< |
extern "C" uint32 call_macos(uint32 tvect); |
334 |
< |
extern "C" uint32 call_macos1(uint32 tvect, uint32 arg1); |
335 |
< |
extern "C" uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2); |
336 |
< |
extern "C" uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3); |
337 |
< |
extern "C" uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4); |
338 |
< |
extern "C" uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5); |
339 |
< |
extern "C" uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6); |
340 |
< |
extern "C" uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7); |
333 |
> |
#ifdef __cplusplus |
334 |
> |
extern "C" { |
335 |
> |
#endif |
336 |
> |
extern uint32 call_macos(uint32 tvect); |
337 |
> |
extern uint32 call_macos1(uint32 tvect, uint32 arg1); |
338 |
> |
extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2); |
339 |
> |
extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3); |
340 |
> |
extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4); |
341 |
> |
extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5); |
342 |
> |
extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6); |
343 |
> |
extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7); |
344 |
> |
#ifdef __cplusplus |
345 |
> |
} |
346 |
> |
#endif |
347 |
|
|
348 |
|
#endif |