35 |
|
#include "video.h" |
36 |
|
#include "name_registry.h" |
37 |
|
#include "serial.h" |
38 |
+ |
#include "ether.h" |
39 |
|
|
40 |
|
#include <stdio.h> |
41 |
|
|
47 |
|
#define DEBUG 0 |
48 |
|
#include "debug.h" |
49 |
|
|
50 |
+ |
// Emulation time statistics |
51 |
+ |
#define EMUL_TIME_STATS 1 |
52 |
+ |
|
53 |
+ |
#if EMUL_TIME_STATS |
54 |
+ |
static clock_t emul_start_time; |
55 |
+ |
static uint32 interrupt_count = 0; |
56 |
+ |
static clock_t interrupt_time = 0; |
57 |
+ |
static uint32 exec68k_count = 0; |
58 |
+ |
static clock_t exec68k_time = 0; |
59 |
+ |
static uint32 native_exec_count = 0; |
60 |
+ |
static clock_t native_exec_time = 0; |
61 |
+ |
static uint32 macos_exec_count = 0; |
62 |
+ |
static clock_t macos_exec_time = 0; |
63 |
+ |
#endif |
64 |
+ |
|
65 |
|
static void enter_mon(void) |
66 |
|
{ |
67 |
|
// Start up mon in real-mode |
89 |
|
// Pointer to Kernel Data |
90 |
|
static KernelData * const kernel_data = (KernelData *)KERNEL_DATA_BASE; |
91 |
|
|
92 |
+ |
// SIGSEGV handler |
93 |
+ |
static sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); |
94 |
+ |
|
95 |
|
|
96 |
|
/** |
97 |
|
* PowerPC emulator glue with special 'sheep' opcodes |
139 |
|
// FIXME: really make surre array allocation fail at link time? |
140 |
|
void *operator new[](size_t); |
141 |
|
void operator delete[](void *p); |
142 |
+ |
|
143 |
+ |
// Make sure the SIGSEGV handler can access CPU registers |
144 |
+ |
friend sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); |
145 |
|
}; |
146 |
|
|
147 |
|
lazy_allocator< sheepshaver_cpu > allocator_helper< sheepshaver_cpu, lazy_allocator >::allocator; |
246 |
|
// Handle MacOS interrupt |
247 |
|
void sheepshaver_cpu::interrupt(uint32 entry) |
248 |
|
{ |
249 |
+ |
#if EMUL_TIME_STATS |
250 |
+ |
interrupt_count++; |
251 |
+ |
const clock_t interrupt_start = clock(); |
252 |
+ |
#endif |
253 |
+ |
|
254 |
|
#if !MULTICORE_CPU |
255 |
|
// Save program counters and branch registers |
256 |
|
uint32 saved_pc = pc(); |
304 |
|
ctr()= saved_ctr; |
305 |
|
gpr(1) = saved_sp; |
306 |
|
#endif |
307 |
+ |
|
308 |
+ |
#if EMUL_TIME_STATS |
309 |
+ |
interrupt_time += (clock() - interrupt_start); |
310 |
+ |
#endif |
311 |
|
} |
312 |
|
|
313 |
|
// Execute 68k routine |
314 |
|
void sheepshaver_cpu::execute_68k(uint32 entry, M68kRegisters *r) |
315 |
|
{ |
316 |
+ |
#if EMUL_TIME_STATS |
317 |
+ |
exec68k_count++; |
318 |
+ |
const clock_t exec68k_start = clock(); |
319 |
+ |
#endif |
320 |
+ |
|
321 |
|
#if SAFE_EXEC_68K |
322 |
|
if (ReadMacInt32(XLM_RUN_MODE) != MODE_EMUL_OP) |
323 |
|
printf("FATAL: Execute68k() not called from EMUL_OP mode\n"); |
400 |
|
lr() = saved_lr; |
401 |
|
ctr()= saved_ctr; |
402 |
|
set_cr(saved_cr); |
403 |
+ |
|
404 |
+ |
#if EMUL_TIME_STATS |
405 |
+ |
exec68k_time += (clock() - exec68k_start); |
406 |
+ |
#endif |
407 |
|
} |
408 |
|
|
409 |
|
// Call MacOS PPC code |
410 |
|
uint32 sheepshaver_cpu::execute_macos_code(uint32 tvect, int nargs, uint32 const *args) |
411 |
|
{ |
412 |
+ |
#if EMUL_TIME_STATS |
413 |
+ |
macos_exec_count++; |
414 |
+ |
const clock_t macos_exec_start = clock(); |
415 |
+ |
#endif |
416 |
+ |
|
417 |
|
// Save program counters and branch registers |
418 |
|
uint32 saved_pc = pc(); |
419 |
|
uint32 saved_lr = lr(); |
452 |
|
lr() = saved_lr; |
453 |
|
ctr()= saved_ctr; |
454 |
|
|
455 |
+ |
#if EMUL_TIME_STATS |
456 |
+ |
macos_exec_time += (clock() - macos_exec_start); |
457 |
+ |
#endif |
458 |
+ |
|
459 |
|
return retval; |
460 |
|
} |
461 |
|
|
560 |
|
if ((addr - ROM_BASE) < ROM_SIZE) |
561 |
|
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
562 |
|
|
563 |
< |
// Ignore all other faults, if requested |
564 |
< |
if (PrefsFindBool("ignoresegv")) |
565 |
< |
return SIGSEGV_RETURN_FAILURE; |
563 |
> |
// Get program counter of target CPU |
564 |
> |
sheepshaver_cpu * const cpu = current_cpu; |
565 |
> |
const uint32 pc = cpu->pc(); |
566 |
> |
|
567 |
> |
// Fault in Mac ROM or RAM? |
568 |
> |
bool mac_fault = (pc >= ROM_BASE) && (pc < (ROM_BASE + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize)); |
569 |
> |
if (mac_fault) { |
570 |
> |
|
571 |
> |
// "VM settings" during MacOS 8 installation |
572 |
> |
if (pc == ROM_BASE + 0x488160 && cpu->gpr(20) == 0xf8000000) |
573 |
> |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
574 |
> |
|
575 |
> |
// MacOS 8.5 installation |
576 |
> |
else if (pc == ROM_BASE + 0x488140 && cpu->gpr(16) == 0xf8000000) |
577 |
> |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
578 |
> |
|
579 |
> |
// MacOS 8 serial drivers on startup |
580 |
> |
else if (pc == ROM_BASE + 0x48e080 && (cpu->gpr(8) == 0xf3012002 || cpu->gpr(8) == 0xf3012000)) |
581 |
> |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
582 |
> |
|
583 |
> |
// MacOS 8.1 serial drivers on startup |
584 |
> |
else if (pc == ROM_BASE + 0x48c5e0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000)) |
585 |
> |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
586 |
> |
else if (pc == ROM_BASE + 0x4a10a0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000)) |
587 |
> |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
588 |
> |
|
589 |
> |
// Ignore all other faults, if requested |
590 |
> |
if (PrefsFindBool("ignoresegv")) |
591 |
> |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
592 |
> |
} |
593 |
|
#else |
594 |
|
#error "FIXME: You don't have the capability to skip instruction within signal handlers" |
595 |
|
#endif |
626 |
|
mon_add_command("regs", dump_registers, "regs Dump PowerPC registers\n"); |
627 |
|
mon_add_command("log", dump_log, "log Dump PowerPC emulation log\n"); |
628 |
|
#endif |
629 |
+ |
|
630 |
+ |
#if EMUL_TIME_STATS |
631 |
+ |
emul_start_time = clock(); |
632 |
+ |
#endif |
633 |
|
} |
634 |
|
|
635 |
|
/* |
638 |
|
|
639 |
|
void exit_emul_ppc(void) |
640 |
|
{ |
641 |
+ |
#if EMUL_TIME_STATS |
642 |
+ |
clock_t emul_end_time = clock(); |
643 |
+ |
|
644 |
+ |
printf("### Statistics for SheepShaver emulation parts\n"); |
645 |
+ |
const clock_t emul_time = emul_end_time - emul_start_time; |
646 |
+ |
printf("Total emulation time : %.1f sec\n", double(emul_time) / double(CLOCKS_PER_SEC)); |
647 |
+ |
printf("Total interrupt count: %d (%2.1f Hz)\n", interrupt_count, |
648 |
+ |
(double(interrupt_count) * CLOCKS_PER_SEC) / double(emul_time)); |
649 |
+ |
|
650 |
+ |
#define PRINT_STATS(LABEL, VAR_PREFIX) do { \ |
651 |
+ |
printf("Total " LABEL " count : %d\n", VAR_PREFIX##_count); \ |
652 |
+ |
printf("Total " LABEL " time : %.1f sec (%.1f%%)\n", \ |
653 |
+ |
double(VAR_PREFIX##_time) / double(CLOCKS_PER_SEC), \ |
654 |
+ |
100.0 * double(VAR_PREFIX##_time) / double(emul_time)); \ |
655 |
+ |
} while (0) |
656 |
+ |
|
657 |
+ |
PRINT_STATS("Execute68k[Trap] execution", exec68k); |
658 |
+ |
PRINT_STATS("NativeOp execution", native_exec); |
659 |
+ |
PRINT_STATS("MacOS routine execution", macos_exec); |
660 |
+ |
|
661 |
+ |
#undef PRINT_STATS |
662 |
+ |
printf("\n"); |
663 |
+ |
#endif |
664 |
+ |
|
665 |
|
delete main_cpu; |
666 |
|
#if MULTICORE_CPU |
667 |
|
delete interrupt_cpu; |
707 |
|
void sheepshaver_cpu::handle_interrupt(void) |
708 |
|
{ |
709 |
|
// Do nothing if interrupts are disabled |
710 |
< |
if (int32(ReadMacInt32(XLM_IRQ_NEST)) > 0) |
710 |
> |
if (*(int32 *)XLM_IRQ_NEST > 0) |
711 |
|
return; |
712 |
|
|
713 |
|
// Do nothing if there is no interrupt pending |
831 |
|
|
832 |
|
static void NativeOp(int selector) |
833 |
|
{ |
834 |
+ |
#if EMUL_TIME_STATS |
835 |
+ |
native_exec_count++; |
836 |
+ |
const clock_t native_exec_start = clock(); |
837 |
+ |
#endif |
838 |
+ |
|
839 |
|
switch (selector) { |
840 |
|
case NATIVE_PATCH_NAME_REGISTRY: |
841 |
|
DoPatchNameRegistry(); |
850 |
|
GPR(3) = (int32)(int16)VideoDoDriverIO((void *)GPR(3), (void *)GPR(4), |
851 |
|
(void *)GPR(5), GPR(6), GPR(7)); |
852 |
|
break; |
853 |
< |
case NATIVE_GET_RESOURCE: |
854 |
< |
get_resource(); |
853 |
> |
#ifdef WORDS_BIGENDIAN |
854 |
> |
case NATIVE_ETHER_IRQ: |
855 |
> |
EtherIRQ(); |
856 |
|
break; |
857 |
< |
case NATIVE_GET_1_RESOURCE: |
858 |
< |
get_1_resource(); |
857 |
> |
case NATIVE_ETHER_INIT: |
858 |
> |
GPR(3) = InitStreamModule((void *)GPR(3)); |
859 |
|
break; |
860 |
< |
case NATIVE_GET_IND_RESOURCE: |
861 |
< |
get_ind_resource(); |
860 |
> |
case NATIVE_ETHER_TERM: |
861 |
> |
TerminateStreamModule(); |
862 |
|
break; |
863 |
< |
case NATIVE_GET_1_IND_RESOURCE: |
864 |
< |
get_1_ind_resource(); |
863 |
> |
case NATIVE_ETHER_OPEN: |
864 |
> |
GPR(3) = ether_open((queue_t *)GPR(3), (void *)GPR(4), GPR(5), GPR(6), (void*)GPR(7)); |
865 |
> |
break; |
866 |
> |
case NATIVE_ETHER_CLOSE: |
867 |
> |
GPR(3) = ether_close((queue_t *)GPR(3), GPR(4), (void *)GPR(5)); |
868 |
> |
break; |
869 |
> |
case NATIVE_ETHER_WPUT: |
870 |
> |
GPR(3) = ether_wput((queue_t *)GPR(3), (mblk_t *)GPR(4)); |
871 |
|
break; |
872 |
< |
case NATIVE_R_GET_RESOURCE: |
873 |
< |
r_get_resource(); |
872 |
> |
case NATIVE_ETHER_RSRV: |
873 |
> |
GPR(3) = ether_rsrv((queue_t *)GPR(3)); |
874 |
|
break; |
875 |
+ |
#else |
876 |
+ |
case NATIVE_ETHER_INIT: |
877 |
+ |
// FIXME: needs more complicated thunks |
878 |
+ |
GPR(3) = false; |
879 |
+ |
break; |
880 |
+ |
#endif |
881 |
|
case NATIVE_SERIAL_NOTHING: |
882 |
|
case NATIVE_SERIAL_OPEN: |
883 |
|
case NATIVE_SERIAL_PRIME_IN: |
898 |
|
GPR(3) = serial_callbacks[selector - NATIVE_SERIAL_NOTHING](GPR(3), GPR(4)); |
899 |
|
break; |
900 |
|
} |
901 |
+ |
case NATIVE_GET_RESOURCE: |
902 |
+ |
case NATIVE_GET_1_RESOURCE: |
903 |
+ |
case NATIVE_GET_IND_RESOURCE: |
904 |
+ |
case NATIVE_GET_1_IND_RESOURCE: |
905 |
+ |
case NATIVE_R_GET_RESOURCE: { |
906 |
+ |
typedef void (*GetResourceCallback)(void); |
907 |
+ |
static const GetResourceCallback get_resource_callbacks[] = { |
908 |
+ |
get_resource, |
909 |
+ |
get_1_resource, |
910 |
+ |
get_ind_resource, |
911 |
+ |
get_1_ind_resource, |
912 |
+ |
r_get_resource |
913 |
+ |
}; |
914 |
+ |
get_resource_callbacks[selector - NATIVE_GET_RESOURCE](); |
915 |
+ |
break; |
916 |
+ |
} |
917 |
|
case NATIVE_DISABLE_INTERRUPT: |
918 |
|
DisableInterrupt(); |
919 |
|
break; |
928 |
|
QuitEmulator(); |
929 |
|
break; |
930 |
|
} |
931 |
+ |
|
932 |
+ |
#if EMUL_TIME_STATS |
933 |
+ |
native_exec_time += (clock() - native_exec_start); |
934 |
+ |
#endif |
935 |
|
} |
936 |
|
|
937 |
|
/* |