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 |
240 |
|
// Handle MacOS interrupt |
241 |
|
void sheepshaver_cpu::interrupt(uint32 entry) |
242 |
|
{ |
243 |
+ |
#if EMUL_TIME_STATS |
244 |
+ |
interrupt_count++; |
245 |
+ |
const clock_t interrupt_start = clock(); |
246 |
+ |
#endif |
247 |
+ |
|
248 |
|
#if !MULTICORE_CPU |
249 |
|
// Save program counters and branch registers |
250 |
|
uint32 saved_pc = pc(); |
298 |
|
ctr()= saved_ctr; |
299 |
|
gpr(1) = saved_sp; |
300 |
|
#endif |
301 |
+ |
|
302 |
+ |
#if EMUL_TIME_STATS |
303 |
+ |
interrupt_time += (clock() - interrupt_start); |
304 |
+ |
#endif |
305 |
|
} |
306 |
|
|
307 |
|
// Execute 68k routine |
308 |
|
void sheepshaver_cpu::execute_68k(uint32 entry, M68kRegisters *r) |
309 |
|
{ |
310 |
+ |
#if EMUL_TIME_STATS |
311 |
+ |
exec68k_count++; |
312 |
+ |
const clock_t exec68k_start = clock(); |
313 |
+ |
#endif |
314 |
+ |
|
315 |
|
#if SAFE_EXEC_68K |
316 |
|
if (ReadMacInt32(XLM_RUN_MODE) != MODE_EMUL_OP) |
317 |
|
printf("FATAL: Execute68k() not called from EMUL_OP mode\n"); |
394 |
|
lr() = saved_lr; |
395 |
|
ctr()= saved_ctr; |
396 |
|
set_cr(saved_cr); |
397 |
+ |
|
398 |
+ |
#if EMUL_TIME_STATS |
399 |
+ |
exec68k_time += (clock() - exec68k_start); |
400 |
+ |
#endif |
401 |
|
} |
402 |
|
|
403 |
|
// Call MacOS PPC code |
404 |
|
uint32 sheepshaver_cpu::execute_macos_code(uint32 tvect, int nargs, uint32 const *args) |
405 |
|
{ |
406 |
+ |
#if EMUL_TIME_STATS |
407 |
+ |
macos_exec_count++; |
408 |
+ |
const clock_t macos_exec_start = clock(); |
409 |
+ |
#endif |
410 |
+ |
|
411 |
|
// Save program counters and branch registers |
412 |
|
uint32 saved_pc = pc(); |
413 |
|
uint32 saved_lr = lr(); |
446 |
|
lr() = saved_lr; |
447 |
|
ctr()= saved_ctr; |
448 |
|
|
449 |
+ |
#if EMUL_TIME_STATS |
450 |
+ |
macos_exec_time += (clock() - macos_exec_start); |
451 |
+ |
#endif |
452 |
+ |
|
453 |
|
return retval; |
454 |
|
} |
455 |
|
|
593 |
|
mon_add_command("regs", dump_registers, "regs Dump PowerPC registers\n"); |
594 |
|
mon_add_command("log", dump_log, "log Dump PowerPC emulation log\n"); |
595 |
|
#endif |
596 |
+ |
|
597 |
+ |
#if EMUL_TIME_STATS |
598 |
+ |
emul_start_time = clock(); |
599 |
+ |
#endif |
600 |
|
} |
601 |
|
|
602 |
|
/* |
605 |
|
|
606 |
|
void exit_emul_ppc(void) |
607 |
|
{ |
608 |
+ |
#if EMUL_TIME_STATS |
609 |
+ |
clock_t emul_end_time = clock(); |
610 |
+ |
|
611 |
+ |
printf("### Statistics for SheepShaver emulation parts\n"); |
612 |
+ |
const clock_t emul_time = emul_end_time - emul_start_time; |
613 |
+ |
printf("Total emulation time : %.1f sec\n", double(emul_time) / double(CLOCKS_PER_SEC)); |
614 |
+ |
printf("Total interrupt count: %d (%2.1f Hz)\n", interrupt_count, |
615 |
+ |
(double(interrupt_count) * CLOCKS_PER_SEC) / double(emul_time)); |
616 |
+ |
|
617 |
+ |
#define PRINT_STATS(LABEL, VAR_PREFIX) do { \ |
618 |
+ |
printf("Total " LABEL " count : %d\n", VAR_PREFIX##_count); \ |
619 |
+ |
printf("Total " LABEL " time : %.1f sec (%.1f%%)\n", \ |
620 |
+ |
double(VAR_PREFIX##_time) / double(CLOCKS_PER_SEC), \ |
621 |
+ |
100.0 * double(VAR_PREFIX##_time) / double(emul_time)); \ |
622 |
+ |
} while (0) |
623 |
+ |
|
624 |
+ |
PRINT_STATS("Execute68k[Trap] execution", exec68k); |
625 |
+ |
PRINT_STATS("NativeOp execution", native_exec); |
626 |
+ |
PRINT_STATS("MacOS routine execution", macos_exec); |
627 |
+ |
|
628 |
+ |
#undef PRINT_STATS |
629 |
+ |
printf("\n"); |
630 |
+ |
#endif |
631 |
+ |
|
632 |
|
delete main_cpu; |
633 |
|
#if MULTICORE_CPU |
634 |
|
delete interrupt_cpu; |
674 |
|
void sheepshaver_cpu::handle_interrupt(void) |
675 |
|
{ |
676 |
|
// Do nothing if interrupts are disabled |
677 |
< |
if (int32(ReadMacInt32(XLM_IRQ_NEST)) > 0) |
677 |
> |
if (*(int32 *)XLM_IRQ_NEST > 0) |
678 |
|
return; |
679 |
|
|
680 |
|
// Do nothing if there is no interrupt pending |
798 |
|
|
799 |
|
static void NativeOp(int selector) |
800 |
|
{ |
801 |
+ |
#if EMUL_TIME_STATS |
802 |
+ |
native_exec_count++; |
803 |
+ |
const clock_t native_exec_start = clock(); |
804 |
+ |
#endif |
805 |
+ |
|
806 |
|
switch (selector) { |
807 |
|
case NATIVE_PATCH_NAME_REGISTRY: |
808 |
|
DoPatchNameRegistry(); |
817 |
|
GPR(3) = (int32)(int16)VideoDoDriverIO((void *)GPR(3), (void *)GPR(4), |
818 |
|
(void *)GPR(5), GPR(6), GPR(7)); |
819 |
|
break; |
820 |
< |
case NATIVE_GET_RESOURCE: |
821 |
< |
get_resource(); |
820 |
> |
#ifdef WORDS_BIGENDIAN |
821 |
> |
case NATIVE_ETHER_IRQ: |
822 |
> |
EtherIRQ(); |
823 |
|
break; |
824 |
< |
case NATIVE_GET_1_RESOURCE: |
825 |
< |
get_1_resource(); |
824 |
> |
case NATIVE_ETHER_INIT: |
825 |
> |
GPR(3) = InitStreamModule((void *)GPR(3)); |
826 |
|
break; |
827 |
< |
case NATIVE_GET_IND_RESOURCE: |
828 |
< |
get_ind_resource(); |
827 |
> |
case NATIVE_ETHER_TERM: |
828 |
> |
TerminateStreamModule(); |
829 |
|
break; |
830 |
< |
case NATIVE_GET_1_IND_RESOURCE: |
831 |
< |
get_1_ind_resource(); |
830 |
> |
case NATIVE_ETHER_OPEN: |
831 |
> |
GPR(3) = ether_open((queue_t *)GPR(3), (void *)GPR(4), GPR(5), GPR(6), (void*)GPR(7)); |
832 |
> |
break; |
833 |
> |
case NATIVE_ETHER_CLOSE: |
834 |
> |
GPR(3) = ether_close((queue_t *)GPR(3), GPR(4), (void *)GPR(5)); |
835 |
> |
break; |
836 |
> |
case NATIVE_ETHER_WPUT: |
837 |
> |
GPR(3) = ether_wput((queue_t *)GPR(3), (mblk_t *)GPR(4)); |
838 |
|
break; |
839 |
< |
case NATIVE_R_GET_RESOURCE: |
840 |
< |
r_get_resource(); |
839 |
> |
case NATIVE_ETHER_RSRV: |
840 |
> |
GPR(3) = ether_rsrv((queue_t *)GPR(3)); |
841 |
> |
break; |
842 |
> |
#else |
843 |
> |
case NATIVE_ETHER_INIT: |
844 |
> |
// FIXME: needs more complicated thunks |
845 |
> |
GPR(3) = false; |
846 |
|
break; |
847 |
+ |
#endif |
848 |
|
case NATIVE_SERIAL_NOTHING: |
849 |
|
case NATIVE_SERIAL_OPEN: |
850 |
|
case NATIVE_SERIAL_PRIME_IN: |
865 |
|
GPR(3) = serial_callbacks[selector - NATIVE_SERIAL_NOTHING](GPR(3), GPR(4)); |
866 |
|
break; |
867 |
|
} |
868 |
+ |
case NATIVE_GET_RESOURCE: |
869 |
+ |
case NATIVE_GET_1_RESOURCE: |
870 |
+ |
case NATIVE_GET_IND_RESOURCE: |
871 |
+ |
case NATIVE_GET_1_IND_RESOURCE: |
872 |
+ |
case NATIVE_R_GET_RESOURCE: { |
873 |
+ |
typedef void (*GetResourceCallback)(void); |
874 |
+ |
static const GetResourceCallback get_resource_callbacks[] = { |
875 |
+ |
get_resource, |
876 |
+ |
get_1_resource, |
877 |
+ |
get_ind_resource, |
878 |
+ |
get_1_ind_resource, |
879 |
+ |
r_get_resource |
880 |
+ |
}; |
881 |
+ |
get_resource_callbacks[selector - NATIVE_GET_RESOURCE](); |
882 |
+ |
break; |
883 |
+ |
} |
884 |
|
case NATIVE_DISABLE_INTERRUPT: |
885 |
|
DisableInterrupt(); |
886 |
|
break; |
895 |
|
QuitEmulator(); |
896 |
|
break; |
897 |
|
} |
898 |
+ |
|
899 |
+ |
#if EMUL_TIME_STATS |
900 |
+ |
native_exec_time += (clock() - native_exec_start); |
901 |
+ |
#endif |
902 |
|
} |
903 |
|
|
904 |
|
/* |