diff --git a/SheepShaver/src/BeOS/main_beos.cpp b/SheepShaver/src/BeOS/main_beos.cpp index c356620f..ce44304b 100644 --- a/SheepShaver/src/BeOS/main_beos.cpp +++ b/SheepShaver/src/BeOS/main_beos.cpp @@ -1264,18 +1264,6 @@ void Execute68kTrap(uint16 trap, M68kRegisters *r) } -/* - * Execute PPC code from EMUL_OP routine (real mode switch) - */ - -void ExecutePPC(void (*func)()) -{ - SheepRoutineDescriptor desc(0, (uint32)func); - M68kRegisters r; - Execute68k(desc.addr(), &r); -} - - /* * Quit emulator (must only be called from main thread) */ @@ -1331,7 +1319,7 @@ void MakeExecutable(int dummy, void *start, uint32 length) void PatchAfterStartup(void) { - ExecutePPC(VideoInstallAccel); + ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL); InstallExtFS(); } @@ -1579,7 +1567,7 @@ void SheepShaver::sigusr1_handler(vregs *r) if (InterruptFlags & INTFLAG_VIA) { ClearInterruptFlag(INTFLAG_VIA); ADBInterrupt(); - ExecutePPC(VideoVBL); + ExecuteNative(NATIVE_VIDEO_VBL); } } #endif diff --git a/SheepShaver/src/Unix/main_unix.cpp b/SheepShaver/src/Unix/main_unix.cpp index bacb625c..c1824498 100644 --- a/SheepShaver/src/Unix/main_unix.cpp +++ b/SheepShaver/src/Unix/main_unix.cpp @@ -672,24 +672,16 @@ int main(int argc, char **argv) WriteMacInt32(XLM_PVR, PVR); // Theoretical PVR WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode) -#if EMULATED_PPC - WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT)); +#if !EMULATED_PPC + WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator +#endif + WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT)); // DLPI ethernet driver functions WriteMacInt32(XLM_ETHER_TERM, NativeFunction(NATIVE_ETHER_TERM)); WriteMacInt32(XLM_ETHER_OPEN, NativeFunction(NATIVE_ETHER_OPEN)); WriteMacInt32(XLM_ETHER_CLOSE, NativeFunction(NATIVE_ETHER_CLOSE)); WriteMacInt32(XLM_ETHER_WPUT, NativeFunction(NATIVE_ETHER_WPUT)); WriteMacInt32(XLM_ETHER_RSRV, NativeFunction(NATIVE_ETHER_RSRV)); WriteMacInt32(XLM_VIDEO_DOIO, NativeFunction(NATIVE_VIDEO_DO_DRIVER_IO)); -#else - WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator - WriteMacInt32(XLM_ETHER_INIT, (uint32)InitStreamModule); // DLPI ethernet driver functions - WriteMacInt32(XLM_ETHER_TERM, (uint32)TerminateStreamModule); - WriteMacInt32(XLM_ETHER_OPEN, (uint32)ether_open); - WriteMacInt32(XLM_ETHER_CLOSE, (uint32)ether_close); - WriteMacInt32(XLM_ETHER_WPUT, (uint32)ether_wput); - WriteMacInt32(XLM_ETHER_RSRV, (uint32)ether_rsrv); - WriteMacInt32(XLM_VIDEO_DOIO, (uint32)VideoDoDriverIO); -#endif D(bug("Low Memory initialized\n")); // Start 60Hz thread @@ -958,19 +950,6 @@ void Execute68kTrap(uint16 trap, M68kRegisters *r) uint16 proc[2] = {trap, M68K_RTS}; Execute68k((uint32)proc, r); } - - -/* - * Execute PPC code from EMUL_OP routine (real mode switch) - */ - -void ExecutePPC(void (*func)()) -{ - uint32 tvect[2] = {(uint32)func, 0}; // Fake TVECT - SheepRoutineDescriptor desc(0, (uint32)tvect); - M68kRegisters r; - Execute68k(desc.addr(), &r); -} #endif @@ -1049,11 +1028,7 @@ void MakeExecutable(int dummy, void *start, uint32 length) void PatchAfterStartup(void) { -#if EMULATED_PPC ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL); -#else - ExecutePPC(VideoInstallAccel); -#endif InstallExtFS(); } @@ -1394,7 +1369,7 @@ static void sigusr2_handler(int sig, sigcontext_struct *sc) if (InterruptFlags & INTFLAG_VIA) { ClearInterruptFlag(INTFLAG_VIA); ADBInterrupt(); - ExecutePPC(VideoVBL); + ExecuteNative(NATIVE_VIDEO_VBL); } } #endif diff --git a/SheepShaver/src/emul_op.cpp b/SheepShaver/src/emul_op.cpp index 1045ef4f..80bc24ca 100644 --- a/SheepShaver/src/emul_op.cpp +++ b/SheepShaver/src/emul_op.cpp @@ -307,11 +307,7 @@ void EmulOp(M68kRegisters *r, uint32 pc, int selector) #if !PRECISE_TIMING TimerInterrupt(); #endif -#if EMULATED_PPC ExecuteNative(NATIVE_VIDEO_VBL); -#else - ExecutePPC(VideoVBL); -#endif static int tick_counter = 0; if (++tick_counter >= 60) { @@ -329,11 +325,7 @@ void EmulOp(M68kRegisters *r, uint32 pc, int selector) } if (InterruptFlags & INTFLAG_ETHER) { ClearInterruptFlag(INTFLAG_ETHER); -#if EMULATED_PPC ExecuteNative(NATIVE_ETHER_IRQ); -#else - ExecutePPC(EtherIRQ); -#endif } if (InterruptFlags & INTFLAG_TIMER) { ClearInterruptFlag(INTFLAG_TIMER); diff --git a/SheepShaver/src/include/cpu_emulation.h b/SheepShaver/src/include/cpu_emulation.h index 4368a4ec..9ea13011 100644 --- a/SheepShaver/src/include/cpu_emulation.h +++ b/SheepShaver/src/include/cpu_emulation.h @@ -95,9 +95,7 @@ extern void Execute68k(uint32, M68kRegisters *r); // Execute 68k subroutine fr extern void Execute68kTrap(uint16 trap, M68kRegisters *r); // Execute 68k A-Trap from EMUL_OP routine #if EMULATED_PPC extern void FlushCodeCache(uintptr start, uintptr end); // Invalidate emulator caches -extern void ExecuteNative(int selector); // Execute native code from EMUL_OP routine (real mode switch) -#else -extern void ExecutePPC(void (*func)(void)); // Execute PPC code from EMUL_OP routine (real mode switch) #endif +extern void ExecuteNative(int selector); // Execute native code from EMUL_OP routine (real mode switch) #endif diff --git a/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp b/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp index 59afca73..f160d68c 100644 --- a/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp +++ b/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp @@ -784,7 +784,7 @@ void sheepshaver_cpu::handle_interrupt(void) if (InterruptFlags & INTFLAG_VIA) { ClearInterruptFlag(INTFLAG_VIA); ADBInterrupt(); - ExecutePPC(VideoVBL); + ExecuteNative(NATIVE_VIDEO_VBL); } } #endif @@ -907,17 +907,6 @@ static void NativeOp(int selector) #endif } -/* - * Execute native subroutine (LR must contain return address) - */ - -void ExecuteNative(int selector) -{ - SheepRoutineDescriptor desc(0, NativeTVECT(selector)); - M68kRegisters r; - Execute68k(desc.addr(), &r); -} - /* * Execute 68k subroutine (must be ended with EXEC_RETURN) * This must only be called by the emul_thread when in EMUL_OP mode diff --git a/SheepShaver/src/name_registry.cpp b/SheepShaver/src/name_registry.cpp index 5588fc1c..ae50ea2f 100644 --- a/SheepShaver/src/name_registry.cpp +++ b/SheepShaver/src/name_registry.cpp @@ -302,9 +302,5 @@ void PatchNameRegistry(void) } // Main routine must be executed in PPC mode -#if EMULATED_PPC ExecuteNative(NATIVE_PATCH_NAME_REGISTRY); -#else - ExecutePPC(DoPatchNameRegistry); -#endif } diff --git a/SheepShaver/src/thunks.cpp b/SheepShaver/src/thunks.cpp index ec5adffe..b4818ce3 100644 --- a/SheepShaver/src/thunks.cpp +++ b/SheepShaver/src/thunks.cpp @@ -29,6 +29,7 @@ #include "name_registry.h" #include "serial.h" #include "ether.h" +#include "macos_util.h" /* NativeOp instruction format: @@ -41,7 +42,10 @@ #define POWERPC_NATIVE_OP(LR, OP) \ (POWERPC_EMUL_OP | ((LR) << 11) | (((uint32)OP) << 6) | 2) -// Return the fake PowerPC opcode to handle specified native code +/* + * Return the fake PowerPC opcode to handle specified native code + */ + #if EMULATED_PPC uint32 NativeOpcode(int selector) { @@ -84,14 +88,17 @@ uint32 NativeOpcode(int selector) } #endif -// NativeOp -> { TVECT, function base } mappings + +/* + * Initialize the thunks system + */ + struct native_op_t { uint32 tvect; uint32 func; }; static native_op_t native_op[NATIVE_OP_MAX]; -// Initialize the thunks system bool ThunksInit(void) { #if EMULATED_PPC @@ -120,6 +127,17 @@ bool ThunksInit(void) #else #error "FIXME: define NativeOp for your platform" #endif + DEFINE_NATIVE_OP(NATIVE_PATCH_NAME_REGISTRY, DoPatchNameRegistry); + DEFINE_NATIVE_OP(NATIVE_VIDEO_INSTALL_ACCEL, VideoInstallAccel); + DEFINE_NATIVE_OP(NATIVE_VIDEO_VBL, VideoVBL); + DEFINE_NATIVE_OP(NATIVE_VIDEO_DO_DRIVER_IO, VideoDoDriverIO); + DEFINE_NATIVE_OP(NATIVE_ETHER_IRQ, EtherIRQ); + DEFINE_NATIVE_OP(NATIVE_ETHER_INIT, InitStreamModule); + DEFINE_NATIVE_OP(NATIVE_ETHER_TERM, TerminateStreamModule); + DEFINE_NATIVE_OP(NATIVE_ETHER_OPEN, ether_open); + DEFINE_NATIVE_OP(NATIVE_ETHER_CLOSE, ether_close); + DEFINE_NATIVE_OP(NATIVE_ETHER_WPUT, ether_wput); + DEFINE_NATIVE_OP(NATIVE_ETHER_RSRV, ether_rsrv); DEFINE_NATIVE_OP(NATIVE_SERIAL_NOTHING, SerialNothing); DEFINE_NATIVE_OP(NATIVE_SERIAL_OPEN, SerialOpen); DEFINE_NATIVE_OP(NATIVE_SERIAL_PRIME_IN, SerialPrimeIn); @@ -133,20 +151,40 @@ bool ThunksInit(void) return true; } -// Return the native function descriptor (TVECT) + +/* + * Return the native function descriptor (TVECT) + */ + uint32 NativeTVECT(int selector) { assert(selector < NATIVE_OP_MAX); const uint32 tvect = native_op[selector].tvect; assert(tvect != 0); - return native_op[selector].tvect; + return tvect; } -// Return the native function address + +/* + * Return the native function address + */ + uint32 NativeFunction(int selector) { assert(selector < NATIVE_OP_MAX); const uint32 func = native_op[selector].func; assert(func != 0); - return native_op[selector].func; + return func; +} + + +/* + * Execute native code from EMUL_OP routine (real mode switch) + */ + +void ExecuteNative(int selector) +{ + SheepRoutineDescriptor desc(0, NativeTVECT(selector)); + M68kRegisters r; + Execute68k(desc.addr(), &r); }