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 |
77 |
|
#else |
78 |
|
# define ROM_IS_WRITE_PROTECTED 1 |
79 |
|
#endif |
80 |
+ |
// Configure PowerPC emulator |
81 |
+ |
#define PPC_CHECK_INTERRUPTS (ASYNC_IRQ ? 0 : 1) |
82 |
+ |
#define PPC_NO_LAZY_PC_UPDATE 1 |
83 |
+ |
//#define PPC_NO_DECODE_CACHE 1 |
84 |
+ |
#define PPC_FLIGHT_RECORDER 1 |
85 |
|
#else |
86 |
|
// Mac ROM is write protected |
87 |
|
#define ROM_IS_WRITE_PROTECTED 1 |
184 |
|
static inline uint64 tswap64(uint64 x) { return bswap_64(x); } |
185 |
|
#endif |
186 |
|
|
187 |
+ |
// spin locks |
188 |
+ |
#ifdef __GNUC__ |
189 |
+ |
|
190 |
+ |
#ifdef __powerpc__ |
191 |
+ |
#define HAVE_TEST_AND_SET 1 |
192 |
+ |
static inline int testandset(int *p) |
193 |
+ |
{ |
194 |
+ |
int ret; |
195 |
+ |
__asm__ __volatile__("0: lwarx %0,0,%1 ;" |
196 |
+ |
" xor. %0,%3,%0;" |
197 |
+ |
" bne 1f;" |
198 |
+ |
" stwcx. %2,0,%1;" |
199 |
+ |
" bne- 0b;" |
200 |
+ |
"1: " |
201 |
+ |
: "=&r" (ret) |
202 |
+ |
: "r" (p), "r" (1), "r" (0) |
203 |
+ |
: "cr0", "memory"); |
204 |
+ |
return ret; |
205 |
+ |
} |
206 |
+ |
#endif |
207 |
+ |
|
208 |
+ |
#ifdef __i386__ |
209 |
+ |
#define HAVE_TEST_AND_SET 1 |
210 |
+ |
static inline int testandset(int *p) |
211 |
+ |
{ |
212 |
+ |
char ret; |
213 |
+ |
long int readval; |
214 |
+ |
|
215 |
+ |
__asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0" |
216 |
+ |
: "=q" (ret), "=m" (*p), "=a" (readval) |
217 |
+ |
: "r" (1), "m" (*p), "a" (0) |
218 |
+ |
: "memory"); |
219 |
+ |
return ret; |
220 |
+ |
} |
221 |
+ |
#endif |
222 |
+ |
|
223 |
+ |
#ifdef __s390__ |
224 |
+ |
#define HAVE_TEST_AND_SET 1 |
225 |
+ |
static inline int testandset(int *p) |
226 |
+ |
{ |
227 |
+ |
int ret; |
228 |
+ |
|
229 |
+ |
__asm__ __volatile__("0: cs %0,%1,0(%2)\n" |
230 |
+ |
" jl 0b" |
231 |
+ |
: "=&d" (ret) |
232 |
+ |
: "r" (1), "a" (p), "0" (*p) |
233 |
+ |
: "cc", "memory" ); |
234 |
+ |
return ret; |
235 |
+ |
} |
236 |
+ |
#endif |
237 |
+ |
|
238 |
+ |
#ifdef __alpha__ |
239 |
+ |
#define HAVE_TEST_AND_SET 1 |
240 |
+ |
static inline int testandset(int *p) |
241 |
+ |
{ |
242 |
+ |
int ret; |
243 |
+ |
unsigned long one; |
244 |
+ |
|
245 |
+ |
__asm__ __volatile__("0: mov 1,%2\n" |
246 |
+ |
" ldl_l %0,%1\n" |
247 |
+ |
" stl_c %2,%1\n" |
248 |
+ |
" beq %2,1f\n" |
249 |
+ |
".subsection 2\n" |
250 |
+ |
"1: br 0b\n" |
251 |
+ |
".previous" |
252 |
+ |
: "=r" (ret), "=m" (*p), "=r" (one) |
253 |
+ |
: "m" (*p)); |
254 |
+ |
return ret; |
255 |
+ |
} |
256 |
+ |
#endif |
257 |
+ |
|
258 |
+ |
#ifdef __sparc__ |
259 |
+ |
#define HAVE_TEST_AND_SET 1 |
260 |
+ |
static inline int testandset(int *p) |
261 |
+ |
{ |
262 |
+ |
int ret; |
263 |
+ |
|
264 |
+ |
__asm__ __volatile__("ldstub [%1], %0" |
265 |
+ |
: "=r" (ret) |
266 |
+ |
: "r" (p) |
267 |
+ |
: "memory"); |
268 |
+ |
|
269 |
+ |
return (ret ? 1 : 0); |
270 |
+ |
} |
271 |
+ |
#endif |
272 |
+ |
|
273 |
+ |
#ifdef __arm__ |
274 |
+ |
#define HAVE_TEST_AND_SET 1 |
275 |
+ |
static inline int testandset(int *p) |
276 |
+ |
{ |
277 |
+ |
register unsigned int ret; |
278 |
+ |
__asm__ __volatile__("swp %0, %1, [%2]" |
279 |
+ |
: "=r"(ret) |
280 |
+ |
: "0"(1), "r"(p)); |
281 |
+ |
|
282 |
+ |
return ret; |
283 |
+ |
} |
284 |
+ |
#endif |
285 |
+ |
|
286 |
+ |
#endif /* __GNUC__ */ |
287 |
+ |
|
288 |
+ |
#if HAVE_TEST_AND_SET |
289 |
+ |
#define HAVE_SPINLOCKS 1 |
290 |
+ |
typedef int spinlock_t; |
291 |
+ |
|
292 |
+ |
static const spinlock_t SPIN_LOCK_UNLOCKED = 0; |
293 |
+ |
|
294 |
+ |
static inline void spin_lock(spinlock_t *lock) |
295 |
+ |
{ |
296 |
+ |
while (testandset(lock)); |
297 |
+ |
} |
298 |
+ |
|
299 |
+ |
static inline void spin_unlock(spinlock_t *lock) |
300 |
+ |
{ |
301 |
+ |
*lock = 0; |
302 |
+ |
} |
303 |
+ |
|
304 |
+ |
static inline int spin_trylock(spinlock_t *lock) |
305 |
+ |
{ |
306 |
+ |
return !testandset(lock); |
307 |
+ |
} |
308 |
+ |
#endif |
309 |
+ |
|
310 |
|
// Time data type for Time Manager emulation |
311 |
|
#ifdef HAVE_CLOCK_GETTIME |
312 |
|
typedef struct timespec tm_time_t; |