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" |
105 |
|
// Interrupts in native mode? |
106 |
|
#define INTERRUPTS_IN_NATIVE_MODE 1 |
107 |
|
|
104 |
– |
// Enable native EMUL_OPs to be run without a mode switch |
105 |
– |
#define ENABLE_NATIVE_EMUL_OP 1 |
106 |
– |
|
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 |
|
|
141 |
– |
// Filter out EMUL_OP routines that only call native code |
142 |
– |
bool filter_execute_emul_op(uint32 emul_op); |
143 |
– |
|
144 |
– |
// "Native" EMUL_OP routines |
145 |
– |
void execute_emul_op_microseconds(); |
146 |
– |
void execute_emul_op_idle_time_1(); |
147 |
– |
void execute_emul_op_idle_time_2(); |
148 |
– |
|
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 |
|
|
273 |
– |
// "Native" EMUL_OP routines |
274 |
– |
#define GPR_A(REG) gpr(16 + (REG)) |
275 |
– |
#define GPR_D(REG) gpr( 8 + (REG)) |
276 |
– |
|
277 |
– |
void sheepshaver_cpu::execute_emul_op_microseconds() |
278 |
– |
{ |
279 |
– |
Microseconds(GPR_A(0), GPR_D(0)); |
280 |
– |
} |
281 |
– |
|
282 |
– |
void sheepshaver_cpu::execute_emul_op_idle_time_1() |
283 |
– |
{ |
284 |
– |
// Sleep if no events pending |
285 |
– |
if (ReadMacInt32(0x14c) == 0) |
286 |
– |
Delay_usec(16667); |
287 |
– |
GPR_A(0) = ReadMacInt32(0x2b6); |
288 |
– |
} |
289 |
– |
|
290 |
– |
void sheepshaver_cpu::execute_emul_op_idle_time_2() |
291 |
– |
{ |
292 |
– |
// Sleep if no events pending |
293 |
– |
if (ReadMacInt32(0x14c) == 0) |
294 |
– |
Delay_usec(16667); |
295 |
– |
GPR_D(0) = (uint32)-2; |
296 |
– |
} |
297 |
– |
|
298 |
– |
// Filter out EMUL_OP routines that only call native code |
299 |
– |
bool sheepshaver_cpu::filter_execute_emul_op(uint32 emul_op) |
300 |
– |
{ |
301 |
– |
switch (emul_op) { |
302 |
– |
case OP_MICROSECONDS: |
303 |
– |
execute_emul_op_microseconds(); |
304 |
– |
return true; |
305 |
– |
case OP_IDLE_TIME: |
306 |
– |
execute_emul_op_idle_time_1(); |
307 |
– |
return true; |
308 |
– |
case OP_IDLE_TIME_2: |
309 |
– |
execute_emul_op_idle_time_2(); |
310 |
– |
return true; |
311 |
– |
} |
312 |
– |
return false; |
313 |
– |
} |
314 |
– |
|
266 |
|
// Execute EMUL_OP routine |
267 |
|
void sheepshaver_cpu::execute_emul_op(uint32 emul_op) |
268 |
|
{ |
318 |
– |
#if ENABLE_NATIVE_EMUL_OP |
319 |
– |
// First, filter out EMUL_OPs that can be executed without a mode switch |
320 |
– |
if (filter_execute_emul_op(emul_op)) |
321 |
– |
return; |
322 |
– |
#endif |
323 |
– |
|
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 |
449 |
– |
case NATIVE_DISABLE_INTERRUPT: |
450 |
– |
dg.gen_invoke(DisableInterrupt); |
451 |
– |
status = COMPILE_CODE_OK; |
452 |
– |
break; |
453 |
– |
case NATIVE_ENABLE_INTERRUPT: |
454 |
– |
dg.gen_invoke(EnableInterrupt); |
455 |
– |
status = COMPILE_CODE_OK; |
456 |
– |
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; |
513 |
– |
#if ENABLE_NATIVE_EMUL_OP |
514 |
– |
typedef void (*emul_op_func_t)(dyngen_cpu_base); |
515 |
– |
emul_op_func_t emul_op_func = 0; |
516 |
– |
switch (emul_op) { |
517 |
– |
case OP_MICROSECONDS: |
518 |
– |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_microseconds).ptr(); |
519 |
– |
break; |
520 |
– |
case OP_IDLE_TIME: |
521 |
– |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_1).ptr(); |
522 |
– |
break; |
523 |
– |
case OP_IDLE_TIME_2: |
524 |
– |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_2).ptr(); |
525 |
– |
break; |
526 |
– |
} |
527 |
– |
if (emul_op_func) { |
528 |
– |
dg.gen_invoke_CPU(emul_op_func); |
529 |
– |
cg_context.done_compile = false; |
530 |
– |
status = COMPILE_CODE_OK; |
531 |
– |
break; |
532 |
– |
} |
533 |
– |
#endif |
450 |
|
#if PPC_REENTRANT_JIT |
451 |
|
// Try to execute EmulOp trampoline |
452 |
|
dg.gen_set_PC_im(cg_context.pc + 4); |
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 |
|
|
965 |
– |
// Install the handler for SIGSEGV |
966 |
– |
sigsegv_install_handler(sigsegv_handler); |
967 |
– |
|
881 |
|
#if ENABLE_MON |
882 |
|
// Install "regs" command in cxmon |
883 |
|
mon_add_command("regs", dump_registers, "regs Dump PowerPC registers\n"); |
980 |
|
|
981 |
|
void sheepshaver_cpu::handle_interrupt(void) |
982 |
|
{ |
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 interrupts are disabled |
989 |
< |
if (*(int32 *)XLM_IRQ_NEST > 0) |
989 |
> |
if (int32(ReadMacInt32(XLM_IRQ_NEST)) > 0) |
990 |
|
return; |
991 |
|
|
992 |
|
// Current interrupt nest level |
1102 |
|
gpr(3) = (int32)(int16)VideoDoDriverIO((void *)gpr(3), (void *)gpr(4), |
1103 |
|
(void *)gpr(5), gpr(6), gpr(7)); |
1104 |
|
break; |
1187 |
– |
#ifdef WORDS_BIGENDIAN |
1105 |
|
case NATIVE_ETHER_IRQ: |
1106 |
|
EtherIRQ(); |
1107 |
|
break; |
1123 |
|
case NATIVE_ETHER_RSRV: |
1124 |
|
gpr(3) = ether_rsrv((queue_t *)gpr(3)); |
1125 |
|
break; |
1209 |
– |
#else |
1210 |
– |
case NATIVE_ETHER_INIT: |
1211 |
– |
// FIXME: needs more complicated thunks |
1212 |
– |
gpr(3) = false; |
1213 |
– |
break; |
1214 |
– |
#endif |
1126 |
|
case NATIVE_SYNC_HOOK: |
1127 |
|
gpr(3) = NQD_sync_hook(gpr(3)); |
1128 |
|
break; |
1177 |
|
get_resource_callbacks[selector - NATIVE_GET_RESOURCE](); |
1178 |
|
break; |
1179 |
|
} |
1269 |
– |
case NATIVE_DISABLE_INTERRUPT: |
1270 |
– |
DisableInterrupt(); |
1271 |
– |
break; |
1272 |
– |
case NATIVE_ENABLE_INTERRUPT: |
1273 |
– |
EnableInterrupt(); |
1274 |
– |
break; |
1180 |
|
case NATIVE_MAKE_EXECUTABLE: |
1181 |
|
MakeExecutable(0, (void *)gpr(4), gpr(5)); |
1182 |
|
break; |