--- SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp 2004/05/20 12:33:58 1.41 +++ SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp 2007/12/30 09:18:40 1.74 @@ -1,7 +1,7 @@ /* * sheepshaver_glue.cpp - Glue Kheperix CPU to SheepShaver CPU engine interface * - * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig + * SheepShaver (C) 1997-2005 Christian Bauer and Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +42,13 @@ #include #include +#ifdef HAVE_MALLOC_H +#include +#endif + +#ifdef USE_SDL_VIDEO +#include +#endif #if ENABLE_MON #include "mon.h" @@ -52,11 +59,13 @@ #include "debug.h" // Emulation time statistics -#define EMUL_TIME_STATS 1 +#ifndef EMUL_TIME_STATS +#define EMUL_TIME_STATS 0 +#endif #if EMUL_TIME_STATS static clock_t emul_start_time; -static uint32 interrupt_count = 0; +static uint32 interrupt_count = 0, ppc_interrupt_count = 0; static clock_t interrupt_time = 0; static uint32 exec68k_count = 0; static clock_t exec68k_time = 0; @@ -80,13 +89,11 @@ extern uintptr SignalStackBase(); // From rsrc_patches.cpp extern "C" void check_load_invoc(uint32 type, int16 id, uint32 h); +extern "C" void named_check_load_invoc(uint32 type, uint32 name, uint32 h); // PowerPC EmulOp to exit from emulation looop const uint32 POWERPC_EXEC_RETURN = POWERPC_EMUL_OP | 1; -// Enable interrupt routine safety checks? -#define SAFE_INTERRUPT_PPC 1 - // Enable Execute68k() safety checks? #define SAFE_EXEC_68K 1 @@ -99,14 +106,11 @@ const uint32 POWERPC_EXEC_RETURN = POWER // Interrupts in native mode? #define INTERRUPTS_IN_NATIVE_MODE 1 -// Enable native EMUL_OPs to be run without a mode switch -#define ENABLE_NATIVE_EMUL_OP 1 - // Pointer to Kernel Data -static KernelData * const kernel_data = (KernelData *)KERNEL_DATA_BASE; +static KernelData * kernel_data; // SIGSEGV handler -static sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); +sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); #if PPC_ENABLE_JIT && PPC_REENTRANT_JIT // Special trampolines for EmulOp and NativeOp @@ -114,12 +118,6 @@ static uint8 *emul_op_trampoline; static uint8 *native_op_trampoline; #endif -// JIT Compiler enabled? -static inline bool enable_jit_p() -{ - return PrefsFindBool("jit"); -} - /** * PowerPC emulator glue with special 'sheep' opcodes @@ -136,29 +134,6 @@ class sheepshaver_cpu void init_decoder(); void execute_sheep(uint32 opcode); - // Filter out EMUL_OP routines that only call native code - bool filter_execute_emul_op(uint32 emul_op); - - // "Native" EMUL_OP routines - void execute_emul_op_microseconds(); - void execute_emul_op_idle_time_1(); - void execute_emul_op_idle_time_2(); - - // CPU context to preserve on interrupt - class interrupt_context { - uint32 gpr[32]; - uint32 pc; - uint32 lr; - uint32 ctr; - uint32 cr; - uint32 xer; - sheepshaver_cpu *cpu; - const char *where; - public: - interrupt_context(sheepshaver_cpu *_cpu, const char *_where); - ~interrupt_context(); - }; - public: // Constructor @@ -185,56 +160,28 @@ public: // Execute MacOS/PPC code uint32 execute_macos_code(uint32 tvect, int nargs, uint32 const *args); +#if PPC_ENABLE_JIT // Compile one instruction virtual int compile1(codegen_context_t & cg_context); - +#endif // Resource manager thunk void get_resource(uint32 old_get_resource); // Handle MacOS interrupt void interrupt(uint32 entry); - void handle_interrupt(); // Make sure the SIGSEGV handler can access CPU registers - friend sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); + friend sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip); }; -// Memory allocator returning areas aligned on 16-byte boundaries -void *operator new(size_t size) -{ - void *p; - -#if defined(HAVE_POSIX_MEMALIGN) - if (posix_memalign(&p, 16, size) != 0) - throw std::bad_alloc(); -#elif defined(HAVE_MEMALIGN) - p = memalign(16, size); -#elif defined(HAVE_VALLOC) - p = valloc(size); // page-aligned! -#else - /* XXX: handle padding ourselves */ - p = malloc(size); -#endif - - return p; -} - -void operator delete(void *p) -{ -#if defined(HAVE_MEMALIGN) || defined(HAVE_VALLOC) -#if defined(__GLIBC__) - // this is known to work only with GNU libc - free(p); -#endif -#else - free(p); -#endif -} - sheepshaver_cpu::sheepshaver_cpu() - : powerpc_cpu(enable_jit_p()) { init_decoder(); + +#if PPC_ENABLE_JIT + if (PrefsFindBool("jit")) + enable_jit(); +#endif } void sheepshaver_cpu::init_decoder() @@ -242,7 +189,6 @@ void sheepshaver_cpu::init_decoder() static const instr_info_t sheep_ii_table[] = { { "sheep", (execute_pmf)&sheepshaver_cpu::execute_sheep, - NULL, PPC_I(SHEEP), D_form, 6, 0, CFLOW_JUMP | CFLOW_TRAP } @@ -268,57 +214,9 @@ typedef bit_field< 19, 19 > FN_field; typedef bit_field< 20, 25 > NATIVE_OP_field; typedef bit_field< 26, 31 > EMUL_OP_field; -// "Native" EMUL_OP routines -#define GPR_A(REG) gpr(16 + (REG)) -#define GPR_D(REG) gpr( 8 + (REG)) - -void sheepshaver_cpu::execute_emul_op_microseconds() -{ - Microseconds(GPR_A(0), GPR_D(0)); -} - -void sheepshaver_cpu::execute_emul_op_idle_time_1() -{ - // Sleep if no events pending - if (ReadMacInt32(0x14c) == 0) - Delay_usec(16667); - GPR_A(0) = ReadMacInt32(0x2b6); -} - -void sheepshaver_cpu::execute_emul_op_idle_time_2() -{ - // Sleep if no events pending - if (ReadMacInt32(0x14c) == 0) - Delay_usec(16667); - GPR_D(0) = (uint32)-2; -} - -// Filter out EMUL_OP routines that only call native code -bool sheepshaver_cpu::filter_execute_emul_op(uint32 emul_op) -{ - switch (emul_op) { - case OP_MICROSECONDS: - execute_emul_op_microseconds(); - return true; - case OP_IDLE_TIME: - execute_emul_op_idle_time_1(); - return true; - case OP_IDLE_TIME_2: - execute_emul_op_idle_time_2(); - return true; - } - return false; -} - // Execute EMUL_OP routine void sheepshaver_cpu::execute_emul_op(uint32 emul_op) { -#if ENABLE_NATIVE_EMUL_OP - // First, filter out EMUL_OPs that can be executed without a mode switch - if (filter_execute_emul_op(emul_op)) - return; -#endif - M68kRegisters r68; WriteMacInt32(XLM_68K_R25, gpr(25)); WriteMacInt32(XLM_RUN_MODE, MODE_EMUL_OP); @@ -327,7 +225,7 @@ void sheepshaver_cpu::execute_emul_op(ui for (int i = 0; i < 7; i++) r68.a[i] = gpr(16 + i); r68.a[7] = gpr(1); - uint32 saved_cr = get_cr() & CR_field<2>::mask(); + uint32 saved_cr = get_cr() & 0xff9fffff; // mask_operand::compute(11, 8) uint32 saved_xer = get_xer(); EmulOp(&r68, gpr(24), emul_op); set_cr(saved_cr); @@ -371,9 +269,9 @@ void sheepshaver_cpu::execute_sheep(uint } // Compile one instruction +#if PPC_ENABLE_JIT int sheepshaver_cpu::compile1(codegen_context_t & cg_context) { -#if PPC_ENABLE_JIT const instr_info_t *ii = cg_context.instr_info; if (ii->mnemo != PPC_I(SHEEP)) return COMPILE_FAILURE; @@ -435,6 +333,7 @@ int sheepshaver_cpu::compile1(codegen_co status = COMPILE_CODE_OK; break; } +#endif case NATIVE_CHECK_LOAD_INVOC: dg.gen_load_T0_GPR(3); dg.gen_load_T1_GPR(4); @@ -443,47 +342,72 @@ int sheepshaver_cpu::compile1(codegen_co dg.gen_invoke_T0_T1_T2((void (*)(uint32, uint32, uint32))check_load_invoc); status = COMPILE_CODE_OK; break; -#endif - case NATIVE_DISABLE_INTERRUPT: - dg.gen_invoke(DisableInterrupt); + case NATIVE_NAMED_CHECK_LOAD_INVOC: + dg.gen_load_T0_GPR(3); + dg.gen_load_T1_GPR(4); + dg.gen_load_T2_GPR(5); + dg.gen_invoke_T0_T1_T2((void (*)(uint32, uint32, uint32))named_check_load_invoc); + status = COMPILE_CODE_OK; + break; + case NATIVE_NQD_SYNC_HOOK: + dg.gen_load_T0_GPR(3); + dg.gen_invoke_T0_ret_T0((uint32 (*)(uint32))NQD_sync_hook); + dg.gen_store_T0_GPR(3); status = COMPILE_CODE_OK; break; - case NATIVE_ENABLE_INTERRUPT: - dg.gen_invoke(EnableInterrupt); + case NATIVE_NQD_BITBLT_HOOK: + dg.gen_load_T0_GPR(3); + dg.gen_invoke_T0_ret_T0((uint32 (*)(uint32))NQD_bitblt_hook); + dg.gen_store_T0_GPR(3); + status = COMPILE_CODE_OK; + break; + case NATIVE_NQD_FILLRECT_HOOK: + dg.gen_load_T0_GPR(3); + dg.gen_invoke_T0_ret_T0((uint32 (*)(uint32))NQD_fillrect_hook); + dg.gen_store_T0_GPR(3); + status = COMPILE_CODE_OK; + break; + case NATIVE_NQD_UNKNOWN_HOOK: + dg.gen_load_T0_GPR(3); + dg.gen_invoke_T0_ret_T0((uint32 (*)(uint32))NQD_unknown_hook); + dg.gen_store_T0_GPR(3); status = COMPILE_CODE_OK; break; - case NATIVE_BITBLT: + case NATIVE_NQD_BITBLT: dg.gen_load_T0_GPR(3); dg.gen_invoke_T0((void (*)(uint32))NQD_bitblt); status = COMPILE_CODE_OK; break; - case NATIVE_INVRECT: + case NATIVE_NQD_INVRECT: dg.gen_load_T0_GPR(3); dg.gen_invoke_T0((void (*)(uint32))NQD_invrect); status = COMPILE_CODE_OK; break; - case NATIVE_FILLRECT: + case NATIVE_NQD_FILLRECT: dg.gen_load_T0_GPR(3); dg.gen_invoke_T0((void (*)(uint32))NQD_fillrect); status = COMPILE_CODE_OK; break; } // Could we fully translate this NativeOp? - if (FN_field::test(opcode)) { - if (status != COMPILE_FAILURE) { - dg.gen_load_A0_LR(); - dg.gen_set_PC_A0(); + if (status == COMPILE_CODE_OK) { + if (!FN_field::test(opcode)) + cg_context.done_compile = false; + else { + dg.gen_load_T0_LR_aligned(); + dg.gen_set_PC_T0(); + cg_context.done_compile = true; } - cg_context.done_compile = true; - break; - } - else if (status != COMPILE_FAILURE) { - cg_context.done_compile = false; break; } #if PPC_REENTRANT_JIT // Try to execute NativeOp trampoline - dg.gen_set_PC_im(cg_context.pc + 4); + if (!FN_field::test(opcode)) + dg.gen_set_PC_im(cg_context.pc + 4); + else { + dg.gen_load_T0_LR_aligned(); + dg.gen_set_PC_T0(); + } dg.gen_mov_32_T0_im(selector); dg.gen_jmp(native_op_trampoline); cg_context.done_compile = true; @@ -491,37 +415,20 @@ int sheepshaver_cpu::compile1(codegen_co break; #endif // Invoke NativeOp handler - typedef void (*func_t)(dyngen_cpu_base, uint32); - func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_native_op).ptr(); - dg.gen_invoke_CPU_im(func, selector); - cg_context.done_compile = false; - status = COMPILE_CODE_OK; + if (!FN_field::test(opcode)) { + typedef void (*func_t)(dyngen_cpu_base, uint32); + func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_native_op).ptr(); + dg.gen_invoke_CPU_im(func, selector); + cg_context.done_compile = false; + status = COMPILE_CODE_OK; + } + // Otherwise, let it generate a call to execute_sheep() which + // will cause necessary updates to the program counter break; } default: { // EMUL_OP uint32 emul_op = EMUL_OP_field::extract(opcode) - 3; -#if ENABLE_NATIVE_EMUL_OP - typedef void (*emul_op_func_t)(dyngen_cpu_base); - emul_op_func_t emul_op_func = 0; - switch (emul_op) { - case OP_MICROSECONDS: - emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_microseconds).ptr(); - break; - case OP_IDLE_TIME: - emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_1).ptr(); - break; - case OP_IDLE_TIME_2: - emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_2).ptr(); - break; - } - if (emul_op_func) { - dg.gen_invoke_CPU(emul_op_func); - cg_context.done_compile = false; - status = COMPILE_CODE_OK; - break; - } -#endif #if PPC_REENTRANT_JIT // Try to execute EmulOp trampoline dg.gen_set_PC_im(cg_context.pc + 4); @@ -541,65 +448,17 @@ int sheepshaver_cpu::compile1(codegen_co } } return status; -#endif - return COMPILE_FAILURE; } - -// CPU context to preserve on interrupt -sheepshaver_cpu::interrupt_context::interrupt_context(sheepshaver_cpu *_cpu, const char *_where) -{ -#if SAFE_INTERRUPT_PPC >= 2 - cpu = _cpu; - where = _where; - - // Save interrupt context - memcpy(&gpr[0], &cpu->gpr(0), sizeof(gpr)); - pc = cpu->pc(); - lr = cpu->lr(); - ctr = cpu->ctr(); - cr = cpu->get_cr(); - xer = cpu->get_xer(); -#endif -} - -sheepshaver_cpu::interrupt_context::~interrupt_context() -{ -#if SAFE_INTERRUPT_PPC >= 2 - // Check whether CPU context was preserved by interrupt - if (memcmp(&gpr[0], &cpu->gpr(0), sizeof(gpr)) != 0) { - printf("FATAL: %s: interrupt clobbers registers\n", where); - for (int i = 0; i < 32; i++) - if (gpr[i] != cpu->gpr(i)) - printf(" r%d: %08x -> %08x\n", i, gpr[i], cpu->gpr(i)); - } - if (pc != cpu->pc()) - printf("FATAL: %s: interrupt clobbers PC\n", where); - if (lr != cpu->lr()) - printf("FATAL: %s: interrupt clobbers LR\n", where); - if (ctr != cpu->ctr()) - printf("FATAL: %s: interrupt clobbers CTR\n", where); - if (cr != cpu->get_cr()) - printf("FATAL: %s: interrupt clobbers CR\n", where); - if (xer != cpu->get_xer()) - printf("FATAL: %s: interrupt clobbers XER\n", where); #endif -} // Handle MacOS interrupt void sheepshaver_cpu::interrupt(uint32 entry) { #if EMUL_TIME_STATS - interrupt_count++; + ppc_interrupt_count++; const clock_t interrupt_start = clock(); #endif -#if SAFE_INTERRUPT_PPC - static int depth = 0; - if (depth != 0) - printf("FATAL: sheepshaver_cpu::interrupt() called more than once: %d\n", depth); - depth++; -#endif - // Save program counters and branch registers uint32 saved_pc = pc(); uint32 saved_lr = lr(); @@ -653,10 +512,6 @@ void sheepshaver_cpu::interrupt(uint32 e #if EMUL_TIME_STATS interrupt_time += (clock() - interrupt_start); #endif - -#if SAFE_INTERRUPT_PPC - depth--; -#endif } // Execute 68k routine @@ -875,19 +730,19 @@ static void dump_log(void) * Initialize CPU emulation */ -static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) +sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip) { #if ENABLE_VOSF // Handle screen fault - extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t); - if (Screen_fault_handler(fault_address, fault_instruction)) + extern bool Screen_fault_handler(sigsegv_info_t *sip); + if (Screen_fault_handler(sip)) return SIGSEGV_RETURN_SUCCESS; #endif - const uintptr addr = (uintptr)fault_address; + const uintptr addr = (uintptr)sigsegv_get_fault_address(sip); #if HAVE_SIGSEGV_SKIP_INSTRUCTION // Ignore writes to ROM - if ((addr - ROM_BASE) < ROM_SIZE) + if ((addr - (uintptr)ROMBaseHost) < ROM_SIZE) return SIGSEGV_RETURN_SKIP_INSTRUCTION; // Get program counter of target CPU @@ -895,7 +750,7 @@ static sigsegv_return_t sigsegv_handler( const uint32 pc = cpu->pc(); // Fault in Mac ROM or RAM? - bool mac_fault = (pc >= ROM_BASE) && (pc < (ROM_BASE + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize)); + bool mac_fault = (pc >= ROM_BASE) && (pc < (ROM_BASE + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize)) || (pc >= DR_CACHE_BASE && pc < (DR_CACHE_BASE + DR_CACHE_SIZE)); if (mac_fault) { // "VM settings" during MacOS 8 installation @@ -915,6 +770,12 @@ static sigsegv_return_t sigsegv_handler( return SIGSEGV_RETURN_SKIP_INSTRUCTION; else if (pc == ROM_BASE + 0x4a10a0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000)) return SIGSEGV_RETURN_SKIP_INSTRUCTION; + + // MacOS 8.6 serial drivers on startup (with DR Cache and OldWorld ROM) + else if ((pc - DR_CACHE_BASE) < DR_CACHE_SIZE && (cpu->gpr(16) == 0xf3012002 || cpu->gpr(16) == 0xf3012000)) + return SIGSEGV_RETURN_SKIP_INSTRUCTION; + else if ((pc - DR_CACHE_BASE) < DR_CACHE_SIZE && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000)) + return SIGSEGV_RETURN_SKIP_INSTRUCTION; // Ignore writes to the zero page else if ((uint32)(addr - SheepMem::ZeroPage()) < (uint32)SheepMem::PageSize()) @@ -928,9 +789,9 @@ static sigsegv_return_t sigsegv_handler( #error "FIXME: You don't have the capability to skip instruction within signal handlers" #endif - printf("SIGSEGV\n"); - printf(" pc %p\n", fault_instruction); - printf(" ea %p\n", fault_address); + fprintf(stderr, "SIGSEGV\n"); + fprintf(stderr, " pc %p\n", sigsegv_get_fault_instruction_address(sip)); + fprintf(stderr, " ea %p\n", sigsegv_get_fault_address(sip)); dump_registers(); ppc_cpu->dump_log(); enter_mon(); @@ -941,15 +802,15 @@ static sigsegv_return_t sigsegv_handler( void init_emul_ppc(void) { + // Get pointer to KernelData in host address space + kernel_data = (KernelData *)Mac2HostAddr(KERNEL_DATA_BASE); + // Initialize main CPU emulator ppc_cpu = new sheepshaver_cpu(); ppc_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROM_BASE + 0x30d000)); ppc_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000)); WriteMacInt32(XLM_RUN_MODE, MODE_68K); - // Install the handler for SIGSEGV - sigsegv_install_handler(sigsegv_handler); - #if ENABLE_MON // Install "regs" command in cxmon mon_add_command("regs", dump_registers, "regs Dump PowerPC registers\n"); @@ -975,6 +836,8 @@ void exit_emul_ppc(void) printf("Total emulation time : %.1f sec\n", double(emul_time) / double(CLOCKS_PER_SEC)); printf("Total interrupt count: %d (%2.1f Hz)\n", interrupt_count, (double(interrupt_count) * CLOCKS_PER_SEC) / double(emul_time)); + printf("Total ppc interrupt count: %d (%2.1f %%)\n", ppc_interrupt_count, + (double(ppc_interrupt_count) * 100.0) / double(interrupt_count)); #define PRINT_STATS(LABEL, VAR_PREFIX) do { \ printf("Total " LABEL " count : %d\n", VAR_PREFIX##_count); \ @@ -992,6 +855,7 @@ void exit_emul_ppc(void) #endif delete ppc_cpu; + ppc_cpu = NULL; } #if PPC_ENABLE_JIT && PPC_REENTRANT_JIT @@ -1039,6 +903,7 @@ void emul_ppc(uint32 entry) void TriggerInterrupt(void) { + idle_resume(); #if 0 WriteMacInt32(0x16a, ReadMacInt32(0x16a) + 1); #else @@ -1048,36 +913,34 @@ void TriggerInterrupt(void) #endif } -void sheepshaver_cpu::handle_interrupt(void) +void HandleInterrupt(powerpc_registers *r) { - // Do nothing if interrupts are disabled - if (*(int32 *)XLM_IRQ_NEST > 0) - return; +#ifdef USE_SDL_VIDEO + // We must fill in the events queue in the same thread that did call SDL_SetVideoMode() + SDL_PumpEvents(); +#endif - // Do nothing if there is no interrupt pending - if (InterruptFlags == 0) + // Do nothing if interrupts are disabled + if (int32(ReadMacInt32(XLM_IRQ_NEST)) > 0) return; - // Current interrupt nest level - static int interrupt_depth = 0; - ++interrupt_depth; - - // Disable MacOS stack sniffer - WriteMacInt32(0x110, 0); + // Update interrupt count +#if EMUL_TIME_STATS + interrupt_count++; +#endif // Interrupt action depends on current run mode switch (ReadMacInt32(XLM_RUN_MODE)) { case MODE_68K: // 68k emulator active, trigger 68k interrupt level 1 WriteMacInt16(tswap32(kernel_data->v[0x67c >> 2]), 1); - set_cr(get_cr() | tswap32(kernel_data->v[0x674 >> 2])); + r->cr.set(r->cr.get() | tswap32(kernel_data->v[0x674 >> 2])); break; #if INTERRUPTS_IN_NATIVE_MODE case MODE_NATIVE: // 68k emulator inactive, in nanokernel? - if (gpr(1) != KernelDataAddr && interrupt_depth == 1) { - interrupt_context ctx(this, "PowerPC mode"); + if (r->gpr[1] != KernelDataAddr) { // Prepare for 68k interrupt level 1 WriteMacInt16(tswap32(kernel_data->v[0x67c >> 2]), 1); @@ -1099,13 +962,15 @@ void sheepshaver_cpu::handle_interrupt(v case MODE_EMUL_OP: // 68k emulator active, within EMUL_OP routine, execute 68k interrupt routine directly when interrupt level is 0 if ((ReadMacInt32(XLM_68K_R25) & 7) == 0) { - interrupt_context ctx(this, "68k mode"); +#if EMUL_TIME_STATS + const clock_t interrupt_start = clock(); +#endif #if 1 // Execute full 68k interrupt routine M68kRegisters r; uint32 old_r25 = ReadMacInt32(XLM_68K_R25); // Save interrupt level WriteMacInt32(XLM_68K_R25, 0x21); // Execute with interrupt level 1 - static const uint8 proc[] = { + static const uint8 proc_template[] = { 0x3f, 0x3c, 0x00, 0x00, // move.w #$0000,-(sp) (fake format word) 0x48, 0x7a, 0x00, 0x0a, // pea @1(pc) (return address) 0x40, 0xe7, // move sr,-(sp) (saved SR) @@ -1113,7 +978,8 @@ void sheepshaver_cpu::handle_interrupt(v 0x4e, 0xd0, // jmp (a0) M68K_RTS >> 8, M68K_RTS & 0xff // @1 }; - Execute68k((uint32)proc, &r); + BUILD_SHEEPSHAVER_PROCEDURE(proc); + Execute68k(proc, &r); WriteMacInt32(XLM_68K_R25, old_r25); // Restore interrupt level #else // Only update cursor @@ -1125,21 +991,15 @@ void sheepshaver_cpu::handle_interrupt(v } } #endif +#if EMUL_TIME_STATS + interrupt_time += (clock() - interrupt_start); +#endif } break; #endif } - - // We are done with this interrupt - --interrupt_depth; } -static void get_resource(void); -static void get_1_resource(void); -static void get_ind_resource(void); -static void get_1_ind_resource(void); -static void r_get_resource(void); - // Execute NATIVE_OP routine void sheepshaver_cpu::execute_native_op(uint32 selector) { @@ -1159,10 +1019,20 @@ void sheepshaver_cpu::execute_native_op( VideoVBL(); break; case NATIVE_VIDEO_DO_DRIVER_IO: - gpr(3) = (int32)(int16)VideoDoDriverIO((void *)gpr(3), (void *)gpr(4), - (void *)gpr(5), gpr(6), gpr(7)); + gpr(3) = (int32)(int16)VideoDoDriverIO(gpr(3), gpr(4), gpr(5), gpr(6), gpr(7)); + break; + case NATIVE_ETHER_AO_GET_HWADDR: + AO_get_ethernet_address(gpr(3)); + break; + case NATIVE_ETHER_AO_ADD_MULTI: + AO_enable_multicast(gpr(3)); + break; + case NATIVE_ETHER_AO_DEL_MULTI: + AO_disable_multicast(gpr(3)); + break; + case NATIVE_ETHER_AO_SEND_PACKET: + AO_transmit_packet(gpr(3)); break; -#ifdef WORDS_BIGENDIAN case NATIVE_ETHER_IRQ: EtherIRQ(); break; @@ -1184,28 +1054,25 @@ void sheepshaver_cpu::execute_native_op( case NATIVE_ETHER_RSRV: gpr(3) = ether_rsrv((queue_t *)gpr(3)); break; -#else - case NATIVE_ETHER_INIT: - // FIXME: needs more complicated thunks - gpr(3) = false; - break; -#endif - case NATIVE_SYNC_HOOK: + case NATIVE_NQD_SYNC_HOOK: gpr(3) = NQD_sync_hook(gpr(3)); break; - case NATIVE_BITBLT_HOOK: + case NATIVE_NQD_UNKNOWN_HOOK: + gpr(3) = NQD_unknown_hook(gpr(3)); + break; + case NATIVE_NQD_BITBLT_HOOK: gpr(3) = NQD_bitblt_hook(gpr(3)); break; - case NATIVE_BITBLT: + case NATIVE_NQD_BITBLT: NQD_bitblt(gpr(3)); break; - case NATIVE_FILLRECT_HOOK: + case NATIVE_NQD_FILLRECT_HOOK: gpr(3) = NQD_fillrect_hook(gpr(3)); break; - case NATIVE_INVRECT: + case NATIVE_NQD_INVRECT: NQD_invrect(gpr(3)); break; - case NATIVE_FILLRECT: + case NATIVE_NQD_FILLRECT: NQD_fillrect(gpr(3)); break; case NATIVE_SERIAL_NOTHING: @@ -1229,33 +1096,29 @@ void sheepshaver_cpu::execute_native_op( break; } case NATIVE_GET_RESOURCE: + get_resource(ReadMacInt32(XLM_GET_RESOURCE)); + break; case NATIVE_GET_1_RESOURCE: + get_resource(ReadMacInt32(XLM_GET_1_RESOURCE)); + break; case NATIVE_GET_IND_RESOURCE: - case NATIVE_GET_1_IND_RESOURCE: - case NATIVE_R_GET_RESOURCE: { - typedef void (*GetResourceCallback)(void); - static const GetResourceCallback get_resource_callbacks[] = { - ::get_resource, - ::get_1_resource, - ::get_ind_resource, - ::get_1_ind_resource, - ::r_get_resource - }; - get_resource_callbacks[selector - NATIVE_GET_RESOURCE](); + get_resource(ReadMacInt32(XLM_GET_IND_RESOURCE)); break; - } - case NATIVE_DISABLE_INTERRUPT: - DisableInterrupt(); + case NATIVE_GET_1_IND_RESOURCE: + get_resource(ReadMacInt32(XLM_GET_1_IND_RESOURCE)); break; - case NATIVE_ENABLE_INTERRUPT: - EnableInterrupt(); + case NATIVE_R_GET_RESOURCE: + get_resource(ReadMacInt32(XLM_R_GET_RESOURCE)); break; case NATIVE_MAKE_EXECUTABLE: - MakeExecutable(0, (void *)gpr(4), gpr(5)); + MakeExecutable(0, gpr(4), gpr(5)); break; case NATIVE_CHECK_LOAD_INVOC: check_load_invoc(gpr(3), gpr(4), gpr(5)); break; + case NATIVE_NAMED_CHECK_LOAD_INVOC: + named_check_load_invoc(gpr(3), gpr(4), gpr(5)); + break; default: printf("FATAL: NATIVE_OP called with bogus selector %d\n", selector); QuitEmulator(); @@ -1342,32 +1205,3 @@ uint32 call_macos7(uint32 tvect, uint32 const uint32 args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }; return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); } - -/* - * Resource Manager thunks - */ - -void get_resource(void) -{ - ppc_cpu->get_resource(ReadMacInt32(XLM_GET_RESOURCE)); -} - -void get_1_resource(void) -{ - ppc_cpu->get_resource(ReadMacInt32(XLM_GET_1_RESOURCE)); -} - -void get_ind_resource(void) -{ - ppc_cpu->get_resource(ReadMacInt32(XLM_GET_IND_RESOURCE)); -} - -void get_1_ind_resource(void) -{ - ppc_cpu->get_resource(ReadMacInt32(XLM_GET_1_IND_RESOURCE)); -} - -void r_get_resource(void) -{ - ppc_cpu->get_resource(ReadMacInt32(XLM_R_GET_RESOURCE)); -}