84 |
|
// PowerPC EmulOp to exit from emulation looop |
85 |
|
const uint32 POWERPC_EXEC_RETURN = POWERPC_EMUL_OP | 1; |
86 |
|
|
87 |
– |
// Enable multicore (main/interrupts) cpu emulation? |
88 |
– |
#define MULTICORE_CPU (ASYNC_IRQ ? 1 : 0) |
89 |
– |
|
87 |
|
// Enable interrupt routine safety checks? |
88 |
|
#define SAFE_INTERRUPT_PPC 1 |
89 |
|
|
600 |
|
depth++; |
601 |
|
#endif |
602 |
|
|
606 |
– |
#if !MULTICORE_CPU |
603 |
|
// Save program counters and branch registers |
604 |
|
uint32 saved_pc = pc(); |
605 |
|
uint32 saved_lr = lr(); |
606 |
|
uint32 saved_ctr= ctr(); |
607 |
|
uint32 saved_sp = gpr(1); |
612 |
– |
#endif |
608 |
|
|
609 |
|
// Initialize stack pointer to SheepShaver alternate stack base |
610 |
|
gpr(1) = SignalStackBase() - 64; |
644 |
|
// Enter nanokernel |
645 |
|
execute(entry); |
646 |
|
|
652 |
– |
#if !MULTICORE_CPU |
647 |
|
// Restore program counters and branch registers |
648 |
|
pc() = saved_pc; |
649 |
|
lr() = saved_lr; |
650 |
|
ctr()= saved_ctr; |
651 |
|
gpr(1) = saved_sp; |
658 |
– |
#endif |
652 |
|
|
653 |
|
#if EMUL_TIME_STATS |
654 |
|
interrupt_time += (clock() - interrupt_start); |
850 |
|
* SheepShaver CPU engine interface |
851 |
|
**/ |
852 |
|
|
853 |
< |
static sheepshaver_cpu *main_cpu = NULL; // CPU emulator to handle usual control flow |
854 |
< |
static sheepshaver_cpu *interrupt_cpu = NULL; // CPU emulator to handle interrupts |
862 |
< |
static sheepshaver_cpu *current_cpu = NULL; // Current CPU emulator context |
853 |
> |
// PowerPC CPU emulator |
854 |
> |
static sheepshaver_cpu *ppc_cpu = NULL; |
855 |
|
|
856 |
|
void FlushCodeCache(uintptr start, uintptr end) |
857 |
|
{ |
858 |
|
D(bug("FlushCodeCache(%08x, %08x)\n", start, end)); |
859 |
< |
main_cpu->invalidate_cache_range(start, end); |
868 |
< |
#if MULTICORE_CPU |
869 |
< |
interrupt_cpu->invalidate_cache_range(start, end); |
870 |
< |
#endif |
871 |
< |
} |
872 |
< |
|
873 |
< |
static inline void cpu_push(sheepshaver_cpu *new_cpu) |
874 |
< |
{ |
875 |
< |
#if MULTICORE_CPU |
876 |
< |
current_cpu = new_cpu; |
877 |
< |
#endif |
878 |
< |
} |
879 |
< |
|
880 |
< |
static inline void cpu_pop() |
881 |
< |
{ |
882 |
< |
#if MULTICORE_CPU |
883 |
< |
current_cpu = main_cpu; |
884 |
< |
#endif |
859 |
> |
ppc_cpu->invalidate_cache_range(start, end); |
860 |
|
} |
861 |
|
|
862 |
|
// Dump PPC registers |
863 |
|
static void dump_registers(void) |
864 |
|
{ |
865 |
< |
current_cpu->dump_registers(); |
865 |
> |
ppc_cpu->dump_registers(); |
866 |
|
} |
867 |
|
|
868 |
|
// Dump log |
869 |
|
static void dump_log(void) |
870 |
|
{ |
871 |
< |
current_cpu->dump_log(); |
871 |
> |
ppc_cpu->dump_log(); |
872 |
|
} |
873 |
|
|
874 |
|
/* |
891 |
|
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
892 |
|
|
893 |
|
// Get program counter of target CPU |
894 |
< |
sheepshaver_cpu * const cpu = current_cpu; |
894 |
> |
sheepshaver_cpu * const cpu = ppc_cpu; |
895 |
|
const uint32 pc = cpu->pc(); |
896 |
|
|
897 |
|
// Fault in Mac ROM or RAM? |
931 |
|
printf("SIGSEGV\n"); |
932 |
|
printf(" pc %p\n", fault_instruction); |
933 |
|
printf(" ea %p\n", fault_address); |
959 |
– |
printf(" cpu %s\n", current_cpu == main_cpu ? "main" : "interrupts"); |
934 |
|
dump_registers(); |
935 |
< |
current_cpu->dump_log(); |
935 |
> |
ppc_cpu->dump_log(); |
936 |
|
enter_mon(); |
937 |
|
QuitEmulator(); |
938 |
|
|
942 |
|
void init_emul_ppc(void) |
943 |
|
{ |
944 |
|
// Initialize main CPU emulator |
945 |
< |
main_cpu = new sheepshaver_cpu(); |
946 |
< |
main_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROM_BASE + 0x30d000)); |
947 |
< |
main_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000)); |
945 |
> |
ppc_cpu = new sheepshaver_cpu(); |
946 |
> |
ppc_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROM_BASE + 0x30d000)); |
947 |
> |
ppc_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000)); |
948 |
|
WriteMacInt32(XLM_RUN_MODE, MODE_68K); |
949 |
|
|
976 |
– |
#if MULTICORE_CPU |
977 |
– |
// Initialize alternate CPU emulator to handle interrupts |
978 |
– |
interrupt_cpu = new sheepshaver_cpu(); |
979 |
– |
#endif |
980 |
– |
|
950 |
|
// Install the handler for SIGSEGV |
951 |
|
sigsegv_install_handler(sigsegv_handler); |
952 |
|
|
991 |
|
printf("\n"); |
992 |
|
#endif |
993 |
|
|
994 |
< |
delete main_cpu; |
1026 |
< |
#if MULTICORE_CPU |
1027 |
< |
delete interrupt_cpu; |
1028 |
< |
#endif |
994 |
> |
delete ppc_cpu; |
995 |
|
} |
996 |
|
|
997 |
|
#if PPC_ENABLE_JIT && PPC_REENTRANT_JIT |
1026 |
|
|
1027 |
|
void emul_ppc(uint32 entry) |
1028 |
|
{ |
1063 |
– |
current_cpu = main_cpu; |
1029 |
|
#if 0 |
1030 |
< |
current_cpu->start_log(); |
1030 |
> |
ppc_cpu->start_log(); |
1031 |
|
#endif |
1032 |
|
// start emulation loop and enable code translation or caching |
1033 |
< |
current_cpu->execute(entry); |
1033 |
> |
ppc_cpu->execute(entry); |
1034 |
|
} |
1035 |
|
|
1036 |
|
/* |
1037 |
|
* Handle PowerPC interrupt |
1038 |
|
*/ |
1039 |
|
|
1075 |
– |
#if ASYNC_IRQ |
1076 |
– |
void HandleInterrupt(void) |
1077 |
– |
{ |
1078 |
– |
main_cpu->handle_interrupt(); |
1079 |
– |
} |
1080 |
– |
#else |
1040 |
|
void TriggerInterrupt(void) |
1041 |
|
{ |
1042 |
|
#if 0 |
1043 |
|
WriteMacInt32(0x16a, ReadMacInt32(0x16a) + 1); |
1044 |
|
#else |
1045 |
|
// Trigger interrupt to main cpu only |
1046 |
< |
if (main_cpu) |
1047 |
< |
main_cpu->trigger_interrupt(); |
1046 |
> |
if (ppc_cpu) |
1047 |
> |
ppc_cpu->trigger_interrupt(); |
1048 |
|
#endif |
1049 |
|
} |
1091 |
– |
#endif |
1050 |
|
|
1051 |
|
void sheepshaver_cpu::handle_interrupt(void) |
1052 |
|
{ |
1069 |
|
switch (ReadMacInt32(XLM_RUN_MODE)) { |
1070 |
|
case MODE_68K: |
1071 |
|
// 68k emulator active, trigger 68k interrupt level 1 |
1114 |
– |
assert(current_cpu == main_cpu); |
1072 |
|
WriteMacInt16(tswap32(kernel_data->v[0x67c >> 2]), 1); |
1073 |
|
set_cr(get_cr() | tswap32(kernel_data->v[0x674 >> 2])); |
1074 |
|
break; |
1076 |
|
#if INTERRUPTS_IN_NATIVE_MODE |
1077 |
|
case MODE_NATIVE: |
1078 |
|
// 68k emulator inactive, in nanokernel? |
1122 |
– |
assert(current_cpu == main_cpu); |
1079 |
|
if (gpr(1) != KernelDataAddr && interrupt_depth == 1) { |
1080 |
|
interrupt_context ctx(this, "PowerPC mode"); |
1081 |
|
|
1087 |
|
|
1088 |
|
// Execute nanokernel interrupt routine (this will activate the 68k emulator) |
1089 |
|
DisableInterrupt(); |
1134 |
– |
cpu_push(interrupt_cpu); |
1090 |
|
if (ROMType == ROMTYPE_NEWWORLD) |
1091 |
< |
current_cpu->interrupt(ROM_BASE + 0x312b1c); |
1091 |
> |
ppc_cpu->interrupt(ROM_BASE + 0x312b1c); |
1092 |
|
else |
1093 |
< |
current_cpu->interrupt(ROM_BASE + 0x312a3c); |
1139 |
< |
cpu_pop(); |
1093 |
> |
ppc_cpu->interrupt(ROM_BASE + 0x312a3c); |
1094 |
|
} |
1095 |
|
break; |
1096 |
|
#endif |
1275 |
|
|
1276 |
|
void Execute68k(uint32 pc, M68kRegisters *r) |
1277 |
|
{ |
1278 |
< |
current_cpu->execute_68k(pc, r); |
1278 |
> |
ppc_cpu->execute_68k(pc, r); |
1279 |
|
} |
1280 |
|
|
1281 |
|
/* |
1298 |
|
|
1299 |
|
uint32 call_macos(uint32 tvect) |
1300 |
|
{ |
1301 |
< |
return current_cpu->execute_macos_code(tvect, 0, NULL); |
1301 |
> |
return ppc_cpu->execute_macos_code(tvect, 0, NULL); |
1302 |
|
} |
1303 |
|
|
1304 |
|
uint32 call_macos1(uint32 tvect, uint32 arg1) |
1305 |
|
{ |
1306 |
|
const uint32 args[] = { arg1 }; |
1307 |
< |
return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1307 |
> |
return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1308 |
|
} |
1309 |
|
|
1310 |
|
uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2) |
1311 |
|
{ |
1312 |
|
const uint32 args[] = { arg1, arg2 }; |
1313 |
< |
return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1313 |
> |
return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1314 |
|
} |
1315 |
|
|
1316 |
|
uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3) |
1317 |
|
{ |
1318 |
|
const uint32 args[] = { arg1, arg2, arg3 }; |
1319 |
< |
return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1319 |
> |
return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1320 |
|
} |
1321 |
|
|
1322 |
|
uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4) |
1323 |
|
{ |
1324 |
|
const uint32 args[] = { arg1, arg2, arg3, arg4 }; |
1325 |
< |
return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1325 |
> |
return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1326 |
|
} |
1327 |
|
|
1328 |
|
uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5) |
1329 |
|
{ |
1330 |
|
const uint32 args[] = { arg1, arg2, arg3, arg4, arg5 }; |
1331 |
< |
return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1331 |
> |
return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1332 |
|
} |
1333 |
|
|
1334 |
|
uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6) |
1335 |
|
{ |
1336 |
|
const uint32 args[] = { arg1, arg2, arg3, arg4, arg5, arg6 }; |
1337 |
< |
return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1337 |
> |
return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1338 |
|
} |
1339 |
|
|
1340 |
|
uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7) |
1341 |
|
{ |
1342 |
|
const uint32 args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }; |
1343 |
< |
return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1343 |
> |
return ppc_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); |
1344 |
|
} |
1345 |
|
|
1346 |
|
/* |
1349 |
|
|
1350 |
|
void get_resource(void) |
1351 |
|
{ |
1352 |
< |
current_cpu->get_resource(ReadMacInt32(XLM_GET_RESOURCE)); |
1352 |
> |
ppc_cpu->get_resource(ReadMacInt32(XLM_GET_RESOURCE)); |
1353 |
|
} |
1354 |
|
|
1355 |
|
void get_1_resource(void) |
1356 |
|
{ |
1357 |
< |
current_cpu->get_resource(ReadMacInt32(XLM_GET_1_RESOURCE)); |
1357 |
> |
ppc_cpu->get_resource(ReadMacInt32(XLM_GET_1_RESOURCE)); |
1358 |
|
} |
1359 |
|
|
1360 |
|
void get_ind_resource(void) |
1361 |
|
{ |
1362 |
< |
current_cpu->get_resource(ReadMacInt32(XLM_GET_IND_RESOURCE)); |
1362 |
> |
ppc_cpu->get_resource(ReadMacInt32(XLM_GET_IND_RESOURCE)); |
1363 |
|
} |
1364 |
|
|
1365 |
|
void get_1_ind_resource(void) |
1366 |
|
{ |
1367 |
< |
current_cpu->get_resource(ReadMacInt32(XLM_GET_1_IND_RESOURCE)); |
1367 |
> |
ppc_cpu->get_resource(ReadMacInt32(XLM_GET_1_IND_RESOURCE)); |
1368 |
|
} |
1369 |
|
|
1370 |
|
void r_get_resource(void) |
1371 |
|
{ |
1372 |
< |
current_cpu->get_resource(ReadMacInt32(XLM_R_GET_RESOURCE)); |
1372 |
> |
ppc_cpu->get_resource(ReadMacInt32(XLM_R_GET_RESOURCE)); |
1373 |
|
} |