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