ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp
(Generate patch)

Comparing SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp (file contents):
Revision 1.42 by gbeauche, 2004-05-23T05:28:12Z vs.
Revision 1.49 by gbeauche, 2004-07-11T06:42:28Z

# Line 43 | Line 43
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"
# Line 52 | Line 56
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;
# Line 99 | Line 105 | const uint32 POWERPC_EXEC_RETURN = POWER
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
# Line 136 | Line 139 | class sheepshaver_cpu
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];
# Line 268 | Line 263 | typedef bit_field< 19, 19 > FN_field;
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);
# Line 444 | Line 391 | int sheepshaver_cpu::compile1(codegen_co
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);
# Line 508 | Line 447 | int sheepshaver_cpu::compile1(codegen_co
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);
# Line 596 | Line 514 | sheepshaver_cpu::interrupt_context::~int
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  
# Line 882 | Line 800 | static void dump_log(void)
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
# Line 902 | Line 820 | static sigsegv_return_t sigsegv_handler(
820          const uint32 pc = cpu->pc();
821          
822          // Fault in Mac ROM or RAM?
823 <        bool mac_fault = (pc >= ROM_BASE) && (pc < (ROM_BASE + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize));
823 >        bool mac_fault = (pc >= ROM_BASE) && (pc < (ROM_BASE + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize)) || (pc >= DR_CACHE_BASE && pc < (DR_CACHE_BASE + DR_CACHE_SIZE));
824          if (mac_fault) {
825  
826                  // "VM settings" during MacOS 8 installation
# Line 922 | Line 840 | static sigsegv_return_t sigsegv_handler(
840                          return SIGSEGV_RETURN_SKIP_INSTRUCTION;
841                  else if (pc == ROM_BASE + 0x4a10a0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
842                          return SIGSEGV_RETURN_SKIP_INSTRUCTION;
843 +        
844 +                // MacOS 8.6 serial drivers on startup (with DR Cache and OldWorld ROM)
845 +                else if ((pc - DR_CACHE_BASE) < DR_CACHE_SIZE && (cpu->gpr(16) == 0xf3012002 || cpu->gpr(16) == 0xf3012000))
846 +                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
847 +                else if ((pc - DR_CACHE_BASE) < DR_CACHE_SIZE && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
848 +                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
849  
850                  // Ignore writes to the zero page
851                  else if ((uint32)(addr - SheepMem::ZeroPage()) < (uint32)SheepMem::PageSize())
# Line 954 | Line 878 | void init_emul_ppc(void)
878          ppc_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000));
879          WriteMacInt32(XLM_RUN_MODE, MODE_68K);
880  
957        // Install the handler for SIGSEGV
958        sigsegv_install_handler(sigsegv_handler);
959
881   #if ENABLE_MON
882          // Install "regs" command in cxmon
883          mon_add_command("regs", dump_registers, "regs                     Dump PowerPC registers\n");
# Line 982 | Line 903 | void exit_emul_ppc(void)
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);             \
# Line 1057 | Line 980 | void TriggerInterrupt(void)
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);
# Line 1107 | Line 1034 | void sheepshaver_cpu::handle_interrupt(v
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;
# Line 1132 | Line 1062 | void sheepshaver_cpu::handle_interrupt(v
1062                                  }
1063                          }
1064   #endif
1065 + #if EMUL_TIME_STATS
1066 +                        interrupt_time += (clock() - interrupt_start);
1067 + #endif
1068                  }
1069                  break;
1070   #endif
# Line 1251 | Line 1184 | void sheepshaver_cpu::execute_native_op(
1184                  get_resource_callbacks[selector - NATIVE_GET_RESOURCE]();
1185                  break;
1186          }
1254        case NATIVE_DISABLE_INTERRUPT:
1255                DisableInterrupt();
1256                break;
1257        case NATIVE_ENABLE_INTERRUPT:
1258                EnableInterrupt();
1259                break;
1187          case NATIVE_MAKE_EXECUTABLE:
1188                  MakeExecutable(0, (void *)gpr(4), gpr(5));
1189                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines