1 |
|
/* |
2 |
|
* emul_op.cpp - 68k opcodes for ROM patches |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
4 |
> |
* SheepShaver (C) 1997-2005 Christian Bauer and Marc Hellwig |
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 |
51 |
|
#include "debug.h" |
52 |
|
|
53 |
|
|
54 |
– |
#if __BEOS__ |
55 |
– |
#define PRECISE_TIMING 1 |
56 |
– |
#else |
57 |
– |
#define PRECISE_TIMING 0 |
58 |
– |
#endif |
59 |
– |
|
60 |
– |
|
54 |
|
// TVector of MakeExecutable |
55 |
< |
static uint32 *MakeExecutableTvec; |
55 |
> |
static uint32 MakeExecutableTvec; |
56 |
|
|
57 |
|
|
58 |
|
/* |
252 |
|
InstallDrivers(); |
253 |
|
|
254 |
|
// Patch MakeExecutable() |
255 |
< |
MakeExecutableTvec = (uint32 *)FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable"); |
256 |
< |
D(bug("MakeExecutable TVECT at %p\n", MakeExecutableTvec)); |
257 |
< |
MakeExecutableTvec[0] = htonl(NativeFunction(NATIVE_MAKE_EXECUTABLE)); |
255 |
> |
MakeExecutableTvec = FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable"); |
256 |
> |
D(bug("MakeExecutable TVECT at %08x\n", MakeExecutableTvec)); |
257 |
> |
WriteMacInt32(MakeExecutableTvec, NativeFunction(NATIVE_MAKE_EXECUTABLE)); |
258 |
|
#if !EMULATED_PPC |
259 |
< |
MakeExecutableTvec[1] = (uint32)TOC; |
259 |
> |
WriteMacInt32(MakeExecutableTvec + 4, (uint32)TOC); |
260 |
|
#endif |
261 |
|
|
262 |
|
// Patch DebugStr() |
263 |
< |
static const uint16 proc[] = { |
264 |
< |
PW(M68K_EMUL_OP_DEBUG_STR), |
265 |
< |
PW(0x4e74), // rtd #4 |
266 |
< |
PW(0x0004) |
263 |
> |
static const uint8 proc_template[] = { |
264 |
> |
M68K_EMUL_OP_DEBUG_STR >> 8, M68K_EMUL_OP_DEBUG_STR, |
265 |
> |
0x4e, 0x74, // rtd #4 |
266 |
> |
0x00, 0x04 |
267 |
|
}; |
268 |
< |
WriteMacInt32(0x1dfc, (uint32)proc); |
268 |
> |
BUILD_SHEEPSHAVER_PROCEDURE(proc); |
269 |
> |
WriteMacInt32(0x1dfc, proc); |
270 |
|
break; |
271 |
|
} |
272 |
|
|
281 |
|
TimerReset(); |
282 |
|
MacOSUtilReset(); |
283 |
|
AudioReset(); |
284 |
< |
#if 0 |
285 |
< |
printf("DR activated\n"); |
286 |
< |
WriteMacInt32(KernelDataAddr + 0x17a0, 3); // Prepare for DR emulator activation |
287 |
< |
WriteMacInt32(KernelDataAddr + 0x17c0, DR_CACHE_BASE); |
288 |
< |
WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE); |
289 |
< |
WriteMacInt32(KernelDataAddr + 0x1b00, DR_CACHE_BASE + 0x10000); |
290 |
< |
memcpy((void *)(DR_CACHE_BASE + 0x10000), (void *)(ROM_BASE + 0x370000), 0x10000); |
291 |
< |
clear_caches((void *)(DR_CACHE_BASE + 0x10000), 0x10000, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE); |
292 |
< |
#endif |
284 |
> |
|
285 |
> |
// Enable DR emulator |
286 |
> |
if (PrefsFindBool("jit68k")) { |
287 |
> |
D(bug("DR activated\n")); |
288 |
> |
WriteMacInt32(KernelDataAddr + 0x17a0, 3); // Prepare for DR emulator activation |
289 |
> |
WriteMacInt32(KernelDataAddr + 0x17c0, DR_CACHE_BASE); |
290 |
> |
WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE); |
291 |
> |
WriteMacInt32(KernelDataAddr + 0x1b04, DR_CACHE_BASE); |
292 |
> |
WriteMacInt32(KernelDataAddr + 0x1b00, DR_EMULATOR_BASE); |
293 |
> |
memcpy((void *)DR_EMULATOR_BASE, (void *)(ROM_BASE + 0x370000), DR_EMULATOR_SIZE); |
294 |
> |
MakeExecutable(0, DR_EMULATOR_BASE, DR_EMULATOR_SIZE); |
295 |
> |
} |
296 |
|
break; |
297 |
|
|
298 |
|
case OP_IRQ: // Level 1 interrupt |
429 |
|
PatchNativeResourceManager(); |
430 |
|
break; |
431 |
|
|
432 |
+ |
case OP_NTRB_17_PATCH4: |
433 |
+ |
r->d[0] = ReadMacInt16(r->a[7]); |
434 |
+ |
r->a[7] += 2; |
435 |
+ |
D(bug("%d %d\n", ReadMacInt16(r->a[2]), ReadMacInt16(r->a[2] + 6))); |
436 |
+ |
if (ReadMacInt16(r->a[2]) == 11 && ReadMacInt16(r->a[2] + 6) == 17) |
437 |
+ |
PatchNativeResourceManager(); |
438 |
+ |
break; |
439 |
+ |
|
440 |
|
case OP_CHECKLOAD: { // vCheckLoad() patch |
441 |
|
uint32 type = ReadMacInt32(r->a[7]); |
442 |
|
r->a[7] += 4; |
461 |
|
break; |
462 |
|
|
463 |
|
case OP_IDLE_TIME: |
459 |
– |
#if __BEOS__ |
464 |
|
// Sleep if no events pending |
465 |
< |
if (ReadMacInt32(0x14c) == 0) { |
466 |
< |
sleep(16667); |
463 |
< |
} |
464 |
< |
#endif |
465 |
> |
if (ReadMacInt32(0x14c) == 0) |
466 |
> |
Delay_usec(16667); |
467 |
|
r->a[0] = ReadMacInt32(0x2b6); |
468 |
|
break; |
469 |
|
|
470 |
+ |
case OP_IDLE_TIME_2: |
471 |
+ |
// Sleep if no events pending |
472 |
+ |
if (ReadMacInt32(0x14c) == 0) |
473 |
+ |
Delay_usec(16667); |
474 |
+ |
r->d[0] = (uint32)-2; |
475 |
+ |
break; |
476 |
+ |
|
477 |
|
default: |
478 |
|
printf("FATAL: EMUL_OP called with bogus selector %08x\n", selector); |
479 |
|
QuitEmulator(); |