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