43 |
|
#include <stdio.h> |
44 |
|
#include <stdlib.h> |
45 |
|
|
46 |
+ |
#ifdef USE_SDL_VIDEO |
47 |
+ |
#include <SDL_events.h> |
48 |
+ |
#endif |
49 |
+ |
|
50 |
|
#if ENABLE_MON |
51 |
|
#include "mon.h" |
52 |
|
#include "mon_disass.h" |
56 |
|
#include "debug.h" |
57 |
|
|
58 |
|
// Emulation time statistics |
59 |
< |
#define EMUL_TIME_STATS 1 |
59 |
> |
#ifndef EMUL_TIME_STATS |
60 |
> |
#define EMUL_TIME_STATS 0 |
61 |
> |
#endif |
62 |
|
|
63 |
|
#if EMUL_TIME_STATS |
64 |
|
static clock_t emul_start_time; |
65 |
< |
static uint32 interrupt_count = 0; |
65 |
> |
static uint32 interrupt_count = 0, ppc_interrupt_count = 0; |
66 |
|
static clock_t interrupt_time = 0; |
67 |
|
static uint32 exec68k_count = 0; |
68 |
|
static clock_t exec68k_time = 0; |
105 |
|
// Interrupts in native mode? |
106 |
|
#define INTERRUPTS_IN_NATIVE_MODE 1 |
107 |
|
|
102 |
– |
// Enable native EMUL_OPs to be run without a mode switch |
103 |
– |
#define ENABLE_NATIVE_EMUL_OP 1 |
104 |
– |
|
108 |
|
// Pointer to Kernel Data |
109 |
|
static KernelData * const kernel_data = (KernelData *)KERNEL_DATA_BASE; |
110 |
|
|
111 |
|
// SIGSEGV handler |
112 |
< |
static sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); |
112 |
> |
sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); |
113 |
|
|
114 |
|
#if PPC_ENABLE_JIT && PPC_REENTRANT_JIT |
115 |
|
// Special trampolines for EmulOp and NativeOp |
139 |
|
void init_decoder(); |
140 |
|
void execute_sheep(uint32 opcode); |
141 |
|
|
139 |
– |
// Filter out EMUL_OP routines that only call native code |
140 |
– |
bool filter_execute_emul_op(uint32 emul_op); |
141 |
– |
|
142 |
– |
// "Native" EMUL_OP routines |
143 |
– |
void execute_emul_op_microseconds(); |
144 |
– |
void execute_emul_op_idle_time_1(); |
145 |
– |
void execute_emul_op_idle_time_2(); |
146 |
– |
|
142 |
|
// CPU context to preserve on interrupt |
143 |
|
class interrupt_context { |
144 |
|
uint32 gpr[32]; |
263 |
|
typedef bit_field< 20, 25 > NATIVE_OP_field; |
264 |
|
typedef bit_field< 26, 31 > EMUL_OP_field; |
265 |
|
|
271 |
– |
// "Native" EMUL_OP routines |
272 |
– |
#define GPR_A(REG) gpr(16 + (REG)) |
273 |
– |
#define GPR_D(REG) gpr( 8 + (REG)) |
274 |
– |
|
275 |
– |
void sheepshaver_cpu::execute_emul_op_microseconds() |
276 |
– |
{ |
277 |
– |
Microseconds(GPR_A(0), GPR_D(0)); |
278 |
– |
} |
279 |
– |
|
280 |
– |
void sheepshaver_cpu::execute_emul_op_idle_time_1() |
281 |
– |
{ |
282 |
– |
// Sleep if no events pending |
283 |
– |
if (ReadMacInt32(0x14c) == 0) |
284 |
– |
Delay_usec(16667); |
285 |
– |
GPR_A(0) = ReadMacInt32(0x2b6); |
286 |
– |
} |
287 |
– |
|
288 |
– |
void sheepshaver_cpu::execute_emul_op_idle_time_2() |
289 |
– |
{ |
290 |
– |
// Sleep if no events pending |
291 |
– |
if (ReadMacInt32(0x14c) == 0) |
292 |
– |
Delay_usec(16667); |
293 |
– |
GPR_D(0) = (uint32)-2; |
294 |
– |
} |
295 |
– |
|
296 |
– |
// Filter out EMUL_OP routines that only call native code |
297 |
– |
bool sheepshaver_cpu::filter_execute_emul_op(uint32 emul_op) |
298 |
– |
{ |
299 |
– |
switch (emul_op) { |
300 |
– |
case OP_MICROSECONDS: |
301 |
– |
execute_emul_op_microseconds(); |
302 |
– |
return true; |
303 |
– |
case OP_IDLE_TIME: |
304 |
– |
execute_emul_op_idle_time_1(); |
305 |
– |
return true; |
306 |
– |
case OP_IDLE_TIME_2: |
307 |
– |
execute_emul_op_idle_time_2(); |
308 |
– |
return true; |
309 |
– |
} |
310 |
– |
return false; |
311 |
– |
} |
312 |
– |
|
266 |
|
// Execute EMUL_OP routine |
267 |
|
void sheepshaver_cpu::execute_emul_op(uint32 emul_op) |
268 |
|
{ |
316 |
– |
#if ENABLE_NATIVE_EMUL_OP |
317 |
– |
// First, filter out EMUL_OPs that can be executed without a mode switch |
318 |
– |
if (filter_execute_emul_op(emul_op)) |
319 |
– |
return; |
320 |
– |
#endif |
321 |
– |
|
269 |
|
M68kRegisters r68; |
270 |
|
WriteMacInt32(XLM_68K_R25, gpr(25)); |
271 |
|
WriteMacInt32(XLM_RUN_MODE, MODE_EMUL_OP); |
391 |
|
status = COMPILE_CODE_OK; |
392 |
|
break; |
393 |
|
#endif |
447 |
– |
case NATIVE_DISABLE_INTERRUPT: |
448 |
– |
dg.gen_invoke(DisableInterrupt); |
449 |
– |
status = COMPILE_CODE_OK; |
450 |
– |
break; |
451 |
– |
case NATIVE_ENABLE_INTERRUPT: |
452 |
– |
dg.gen_invoke(EnableInterrupt); |
453 |
– |
status = COMPILE_CODE_OK; |
454 |
– |
break; |
394 |
|
case NATIVE_BITBLT: |
395 |
|
dg.gen_load_T0_GPR(3); |
396 |
|
dg.gen_invoke_T0((void (*)(uint32))NQD_bitblt); |
447 |
|
|
448 |
|
default: { // EMUL_OP |
449 |
|
uint32 emul_op = EMUL_OP_field::extract(opcode) - 3; |
511 |
– |
#if ENABLE_NATIVE_EMUL_OP |
512 |
– |
typedef void (*emul_op_func_t)(dyngen_cpu_base); |
513 |
– |
emul_op_func_t emul_op_func = 0; |
514 |
– |
switch (emul_op) { |
515 |
– |
case OP_MICROSECONDS: |
516 |
– |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_microseconds).ptr(); |
517 |
– |
break; |
518 |
– |
case OP_IDLE_TIME: |
519 |
– |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_1).ptr(); |
520 |
– |
break; |
521 |
– |
case OP_IDLE_TIME_2: |
522 |
– |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_2).ptr(); |
523 |
– |
break; |
524 |
– |
} |
525 |
– |
if (emul_op_func) { |
526 |
– |
dg.gen_invoke_CPU(emul_op_func); |
527 |
– |
cg_context.done_compile = false; |
528 |
– |
status = COMPILE_CODE_OK; |
529 |
– |
break; |
530 |
– |
} |
531 |
– |
#endif |
450 |
|
#if PPC_REENTRANT_JIT |
451 |
|
// Try to execute EmulOp trampoline |
452 |
|
dg.gen_set_PC_im(cg_context.pc + 4); |
514 |
|
void sheepshaver_cpu::interrupt(uint32 entry) |
515 |
|
{ |
516 |
|
#if EMUL_TIME_STATS |
517 |
< |
interrupt_count++; |
517 |
> |
ppc_interrupt_count++; |
518 |
|
const clock_t interrupt_start = clock(); |
519 |
|
#endif |
520 |
|
|
800 |
|
* Initialize CPU emulation |
801 |
|
*/ |
802 |
|
|
803 |
< |
static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
803 |
> |
sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
804 |
|
{ |
805 |
|
#if ENABLE_VOSF |
806 |
|
// Handle screen fault |
878 |
|
ppc_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000)); |
879 |
|
WriteMacInt32(XLM_RUN_MODE, MODE_68K); |
880 |
|
|
963 |
– |
// Install the handler for SIGSEGV |
964 |
– |
sigsegv_install_handler(sigsegv_handler); |
965 |
– |
|
881 |
|
#if ENABLE_MON |
882 |
|
// Install "regs" command in cxmon |
883 |
|
mon_add_command("regs", dump_registers, "regs Dump PowerPC registers\n"); |
903 |
|
printf("Total emulation time : %.1f sec\n", double(emul_time) / double(CLOCKS_PER_SEC)); |
904 |
|
printf("Total interrupt count: %d (%2.1f Hz)\n", interrupt_count, |
905 |
|
(double(interrupt_count) * CLOCKS_PER_SEC) / double(emul_time)); |
906 |
+ |
printf("Total ppc interrupt count: %d (%2.1f %%)\n", ppc_interrupt_count, |
907 |
+ |
(double(ppc_interrupt_count) * 100.0) / double(interrupt_count)); |
908 |
|
|
909 |
|
#define PRINT_STATS(LABEL, VAR_PREFIX) do { \ |
910 |
|
printf("Total " LABEL " count : %d\n", VAR_PREFIX##_count); \ |
980 |
|
|
981 |
|
void sheepshaver_cpu::handle_interrupt(void) |
982 |
|
{ |
983 |
< |
// Do nothing if interrupts are disabled |
984 |
< |
if (*(int32 *)XLM_IRQ_NEST > 0) |
985 |
< |
return; |
983 |
> |
#ifdef USE_SDL_VIDEO |
984 |
> |
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
985 |
> |
SDL_PumpEvents(); |
986 |
> |
#endif |
987 |
|
|
988 |
< |
// Do nothing if there is no interrupt pending |
989 |
< |
if (InterruptFlags == 0) |
988 |
> |
// Do nothing if interrupts are disabled |
989 |
> |
if (int32(ReadMacInt32(XLM_IRQ_NEST)) > 0) |
990 |
|
return; |
991 |
|
|
992 |
|
// Current interrupt nest level |
993 |
|
static int interrupt_depth = 0; |
994 |
|
++interrupt_depth; |
995 |
+ |
#if EMUL_TIME_STATS |
996 |
+ |
interrupt_count++; |
997 |
+ |
#endif |
998 |
|
|
999 |
|
// Disable MacOS stack sniffer |
1000 |
|
WriteMacInt32(0x110, 0); |
1034 |
|
// 68k emulator active, within EMUL_OP routine, execute 68k interrupt routine directly when interrupt level is 0 |
1035 |
|
if ((ReadMacInt32(XLM_68K_R25) & 7) == 0) { |
1036 |
|
interrupt_context ctx(this, "68k mode"); |
1037 |
+ |
#if EMUL_TIME_STATS |
1038 |
+ |
const clock_t interrupt_start = clock(); |
1039 |
+ |
#endif |
1040 |
|
#if 1 |
1041 |
|
// Execute full 68k interrupt routine |
1042 |
|
M68kRegisters r; |
1062 |
|
} |
1063 |
|
} |
1064 |
|
#endif |
1065 |
+ |
#if EMUL_TIME_STATS |
1066 |
+ |
interrupt_time += (clock() - interrupt_start); |
1067 |
+ |
#endif |
1068 |
|
} |
1069 |
|
break; |
1070 |
|
#endif |
1184 |
|
get_resource_callbacks[selector - NATIVE_GET_RESOURCE](); |
1185 |
|
break; |
1186 |
|
} |
1260 |
– |
case NATIVE_DISABLE_INTERRUPT: |
1261 |
– |
DisableInterrupt(); |
1262 |
– |
break; |
1263 |
– |
case NATIVE_ENABLE_INTERRUPT: |
1264 |
– |
EnableInterrupt(); |
1265 |
– |
break; |
1187 |
|
case NATIVE_MAKE_EXECUTABLE: |
1188 |
|
MakeExecutable(0, (void *)gpr(4), gpr(5)); |
1189 |
|
break; |