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.7 by gbeauche, 2003-10-12T05:44:15Z vs.
Revision 1.21 by gbeauche, 2003-12-04T17:26:38Z

# Line 28 | Line 28
28   #include "macos_util.h"
29   #include "block-alloc.hpp"
30   #include "sigsegv.h"
31 #include "spcflags.h"
31   #include "cpu/ppc/ppc-cpu.hpp"
32   #include "cpu/ppc/ppc-operations.hpp"
33 + #include "cpu/ppc/ppc-instructions.hpp"
34 + #include "thunks.h"
35  
36   // Used for NativeOp trampolines
37   #include "video.h"
38   #include "name_registry.h"
39   #include "serial.h"
40 + #include "ether.h"
41  
42   #include <stdio.h>
43  
# Line 44 | Line 46
46   #include "mon_disass.h"
47   #endif
48  
49 < #define DEBUG 1
49 > #define DEBUG 0
50   #include "debug.h"
51  
52 + // Emulation time statistics
53 + #define EMUL_TIME_STATS 1
54 +
55 + #if EMUL_TIME_STATS
56 + static clock_t emul_start_time;
57 + static uint32 interrupt_count = 0;
58 + static clock_t interrupt_time = 0;
59 + static uint32 exec68k_count = 0;
60 + static clock_t exec68k_time = 0;
61 + static uint32 native_exec_count = 0;
62 + static clock_t native_exec_time = 0;
63 + static uint32 macos_exec_count = 0;
64 + static clock_t macos_exec_time = 0;
65 + #endif
66 +
67   static void enter_mon(void)
68   {
69          // Start up mon in real-mode
# Line 56 | Line 73 | static void enter_mon(void)
73   #endif
74   }
75  
76 + // PowerPC EmulOp to exit from emulation looop
77 + const uint32 POWERPC_EXEC_RETURN = POWERPC_EMUL_OP | 1;
78 +
79   // Enable multicore (main/interrupts) cpu emulation?
80 < #define MULTICORE_CPU 0
80 > #define MULTICORE_CPU (ASYNC_IRQ ? 1 : 0)
81  
82   // Enable Execute68k() safety checks?
83   #define SAFE_EXEC_68K 1
# Line 74 | Line 94 | static void enter_mon(void)
94   // Pointer to Kernel Data
95   static KernelData * const kernel_data = (KernelData *)KERNEL_DATA_BASE;
96  
97 + // SIGSEGV handler
98 + static sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t);
99 +
100 + // JIT Compiler enabled?
101 + static inline bool enable_jit_p()
102 + {
103 +        return PrefsFindBool("jit");
104 + }
105 +
106  
107   /**
108   *              PowerPC emulator glue with special 'sheep' opcodes
109   **/
110  
111 < struct sheepshaver_exec_return { };
111 > enum {
112 >        PPC_I(SHEEP) = PPC_I(MAX),
113 >        PPC_I(SHEEP_MAX)
114 > };
115  
116   class sheepshaver_cpu
117          : public powerpc_cpu
# Line 89 | Line 121 | class sheepshaver_cpu
121  
122   public:
123  
124 <        sheepshaver_cpu()
125 <                : powerpc_cpu()
94 <                { init_decoder(); }
124 >        // Constructor
125 >        sheepshaver_cpu();
126  
127          // Condition Register accessors
128          uint32 get_cr() const           { return cr().get(); }
129          void set_cr(uint32 v)           { cr().set(v); }
130  
100        // Execution loop
101        void execute(uint32 pc);
102
131          // Execute 68k routine
132          void execute_68k(uint32 entry, M68kRegisters *r);
133  
# Line 114 | Line 142 | public:
142  
143          // Handle MacOS interrupt
144          void interrupt(uint32 entry);
145 <
118 <        // spcflags for interrupts handling
119 <        static uint32 spcflags;
145 >        void handle_interrupt();
146  
147          // Lazy memory allocator (one item at a time)
148          void *operator new(size_t size)
# Line 126 | Line 152 | public:
152          // FIXME: really make surre array allocation fail at link time?
153          void *operator new[](size_t);
154          void operator delete[](void *p);
155 +
156 +        // Make sure the SIGSEGV handler can access CPU registers
157 +        friend sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t);
158   };
159  
131 uint32 sheepshaver_cpu::spcflags = 0;
160   lazy_allocator< sheepshaver_cpu > allocator_helper< sheepshaver_cpu, lazy_allocator >::allocator;
161  
162 + sheepshaver_cpu::sheepshaver_cpu()
163 +        : powerpc_cpu(enable_jit_p())
164 + {
165 +        init_decoder();
166 + }
167 +
168   void sheepshaver_cpu::init_decoder()
169   {
170   #ifndef PPC_NO_STATIC_II_INDEX_TABLE
# Line 142 | Line 176 | void sheepshaver_cpu::init_decoder()
176  
177          static const instr_info_t sheep_ii_table[] = {
178                  { "sheep",
179 <                  (execute_fn)&sheepshaver_cpu::execute_sheep,
179 >                  (execute_pmf)&sheepshaver_cpu::execute_sheep,
180                    NULL,
181 +                  PPC_I(SHEEP),
182                    D_form, 6, 0, CFLOW_JUMP | CFLOW_TRAP
183                  }
184          };
# Line 181 | Line 216 | void sheepshaver_cpu::execute_sheep(uint
216          case 0:         // EMUL_RETURN
217                  QuitEmulator();
218                  break;
219 <                
219 >
220          case 1:         // EXEC_RETURN
221 <                throw sheepshaver_exec_return();
221 >                spcflags().set(SPCFLAG_CPU_EXEC_RETURN);
222                  break;
223  
224          case 2:         // EXEC_NATIVE
# Line 216 | Line 251 | void sheepshaver_cpu::execute_sheep(uint
251          }
252   }
253  
219 // Checks for pending interrupts
220 struct execute_nothing {
221        static inline void execute(powerpc_cpu *) { }
222 };
223
224 struct execute_spcflags_check {
225        static inline void execute(powerpc_cpu *cpu) {
226 #if !ASYNC_IRQ
227                if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) {
228                        if (SPCFLAGS_TEST( SPCFLAG_ENTER_MON )) {
229                                SPCFLAGS_CLEAR( SPCFLAG_ENTER_MON );
230                                enter_mon();
231                        }
232                        if (SPCFLAGS_TEST( SPCFLAG_DOINT )) {
233                                SPCFLAGS_CLEAR( SPCFLAG_DOINT );
234                                HandleInterrupt();
235                        }
236                        if (SPCFLAGS_TEST( SPCFLAG_INT )) {
237                                SPCFLAGS_CLEAR( SPCFLAG_INT );
238                                SPCFLAGS_SET( SPCFLAG_DOINT );
239                        }
240                }
241 #endif
242        }
243 };
244
245 // Execution loop
246 void sheepshaver_cpu::execute(uint32 entry)
247 {
248        try {
249                pc() = entry;
250                powerpc_cpu::do_execute<execute_nothing, execute_spcflags_check>();
251        }
252        catch (sheepshaver_exec_return const &) {
253                // Nothing, simply return
254        }
255        catch (...) {
256                printf("ERROR: execute() received an unknown exception!\n");
257                QuitEmulator();
258        }
259 }
260
254   // Handle MacOS interrupt
255   void sheepshaver_cpu::interrupt(uint32 entry)
256   {
257 + #if EMUL_TIME_STATS
258 +        interrupt_count++;
259 +        const clock_t interrupt_start = clock();
260 + #endif
261 +
262   #if !MULTICORE_CPU
263          // Save program counters and branch registers
264          uint32 saved_pc = pc();
# Line 270 | Line 268 | void sheepshaver_cpu::interrupt(uint32 e
268   #endif
269  
270          // Initialize stack pointer to SheepShaver alternate stack base
271 <        gpr(1) = SheepStack1Base - 64;
271 >        SheepArray<64> stack_area;
272 >        gpr(1) = stack_area.addr();
273  
274          // Build trampoline to return from interrupt
275 <        uint32 trampoline[] = { htonl(POWERPC_EMUL_OP | 1) };
275 >        SheepVar32 trampoline = POWERPC_EXEC_RETURN;
276  
277          // Prepare registers for nanokernel interrupt routine
278          kernel_data->v[0x004 >> 2] = htonl(gpr(1));
# Line 292 | Line 291 | void sheepshaver_cpu::interrupt(uint32 e
291          gpr(1)  = KernelDataAddr;
292          gpr(7)  = ntohl(kernel_data->v[0x660 >> 2]);
293          gpr(8)  = 0;
294 <        gpr(10) = (uint32)trampoline;
295 <        gpr(12) = (uint32)trampoline;
296 <        gpr(13) = cr().get();
294 >        gpr(10) = trampoline.addr();
295 >        gpr(12) = trampoline.addr();
296 >        gpr(13) = get_cr();
297  
298          // rlwimi. r7,r7,8,0,0
299          uint32 result = op_ppc_rlwimi::apply(gpr(7), 8, 0x80000000, gpr(7));
# Line 302 | Line 301 | void sheepshaver_cpu::interrupt(uint32 e
301          gpr(7) = result;
302  
303          gpr(11) = 0xf072; // MSR (SRR1)
304 <        cr().set((gpr(11) & 0x0fff0000) | (cr().get() & ~0x0fff0000));
304 >        cr().set((gpr(11) & 0x0fff0000) | (get_cr() & ~0x0fff0000));
305  
306          // Enter nanokernel
307          execute(entry);
# Line 314 | Line 313 | void sheepshaver_cpu::interrupt(uint32 e
313          ctr()= saved_ctr;
314          gpr(1) = saved_sp;
315   #endif
316 +
317 + #if EMUL_TIME_STATS
318 +        interrupt_time += (clock() - interrupt_start);
319 + #endif
320   }
321  
322   // Execute 68k routine
323   void sheepshaver_cpu::execute_68k(uint32 entry, M68kRegisters *r)
324   {
325 + #if EMUL_TIME_STATS
326 +        exec68k_count++;
327 +        const clock_t exec68k_start = clock();
328 + #endif
329 +
330   #if SAFE_EXEC_68K
331          if (ReadMacInt32(XLM_RUN_MODE) != MODE_EMUL_OP)
332                  printf("FATAL: Execute68k() not called from EMUL_OP mode\n");
# Line 328 | Line 336 | void sheepshaver_cpu::execute_68k(uint32
336          uint32 saved_pc = pc();
337          uint32 saved_lr = lr();
338          uint32 saved_ctr= ctr();
339 +        uint32 saved_cr = get_cr();
340  
341          // Create MacOS stack frame
342          // FIXME: make sure MacOS doesn't expect PPC registers to live on top
# Line 399 | Line 408 | void sheepshaver_cpu::execute_68k(uint32
408          pc() = saved_pc;
409          lr() = saved_lr;
410          ctr()= saved_ctr;
411 +        set_cr(saved_cr);
412 +
413 + #if EMUL_TIME_STATS
414 +        exec68k_time += (clock() - exec68k_start);
415 + #endif
416   }
417  
418   // Call MacOS PPC code
419   uint32 sheepshaver_cpu::execute_macos_code(uint32 tvect, int nargs, uint32 const *args)
420   {
421 + #if EMUL_TIME_STATS
422 +        macos_exec_count++;
423 +        const clock_t macos_exec_start = clock();
424 + #endif
425 +
426          // Save program counters and branch registers
427          uint32 saved_pc = pc();
428          uint32 saved_lr = lr();
429          uint32 saved_ctr= ctr();
430  
431          // Build trampoline with EXEC_RETURN
432 <        uint32 trampoline[] = { htonl(POWERPC_EMUL_OP | 1) };
433 <        lr() = (uint32)trampoline;
432 >        SheepVar32 trampoline = POWERPC_EXEC_RETURN;
433 >        lr() = trampoline.addr();
434  
435          gpr(1) -= 64;                                                           // Create stack frame
436          uint32 proc = ReadMacInt32(tvect);                      // Get routine address
# Line 442 | Line 461 | uint32 sheepshaver_cpu::execute_macos_co
461          lr() = saved_lr;
462          ctr()= saved_ctr;
463  
464 + #if EMUL_TIME_STATS
465 +        macos_exec_time += (clock() - macos_exec_start);
466 + #endif
467 +
468          return retval;
469   }
470  
# Line 451 | Line 474 | inline void sheepshaver_cpu::execute_ppc
474          // Save branch registers
475          uint32 saved_lr = lr();
476  
477 <        const uint32 trampoline[] = { htonl(POWERPC_EMUL_OP | 1) };
478 <        lr() = (uint32)trampoline;
477 >        SheepVar32 trampoline = POWERPC_EXEC_RETURN;
478 >        WriteMacInt32(trampoline.addr(), POWERPC_EXEC_RETURN);
479 >        lr() = trampoline.addr();
480  
481          execute(entry);
482  
# Line 546 | Line 570 | static sigsegv_return_t sigsegv_handler(
570          if ((addr - ROM_BASE) < ROM_SIZE)
571                  return SIGSEGV_RETURN_SKIP_INSTRUCTION;
572  
573 <        // Ignore all other faults, if requested
574 <        if (PrefsFindBool("ignoresegv"))
575 <                return SIGSEGV_RETURN_FAILURE;
573 >        // Get program counter of target CPU
574 >        sheepshaver_cpu * const cpu = current_cpu;
575 >        const uint32 pc = cpu->pc();
576 >        
577 >        // Fault in Mac ROM or RAM?
578 >        bool mac_fault = (pc >= ROM_BASE) && (pc < (ROM_BASE + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize));
579 >        if (mac_fault) {
580 >
581 >                // "VM settings" during MacOS 8 installation
582 >                if (pc == ROM_BASE + 0x488160 && cpu->gpr(20) == 0xf8000000)
583 >                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
584 >        
585 >                // MacOS 8.5 installation
586 >                else if (pc == ROM_BASE + 0x488140 && cpu->gpr(16) == 0xf8000000)
587 >                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
588 >        
589 >                // MacOS 8 serial drivers on startup
590 >                else if (pc == ROM_BASE + 0x48e080 && (cpu->gpr(8) == 0xf3012002 || cpu->gpr(8) == 0xf3012000))
591 >                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
592 >        
593 >                // MacOS 8.1 serial drivers on startup
594 >                else if (pc == ROM_BASE + 0x48c5e0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
595 >                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
596 >                else if (pc == ROM_BASE + 0x4a10a0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
597 >                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
598 >
599 >                // Ignore all other faults, if requested
600 >                if (PrefsFindBool("ignoresegv"))
601 >                        return SIGSEGV_RETURN_SKIP_INSTRUCTION;
602 >        }
603   #else
604   #error "FIXME: You don't have the capability to skip instruction within signal handlers"
605   #endif
# Line 585 | Line 636 | void init_emul_ppc(void)
636          mon_add_command("regs", dump_registers, "regs                     Dump PowerPC registers\n");
637          mon_add_command("log", dump_log, "log                      Dump PowerPC emulation log\n");
638   #endif
639 +
640 + #if EMUL_TIME_STATS
641 +        emul_start_time = clock();
642 + #endif
643 + }
644 +
645 + /*
646 + *  Deinitialize emulation
647 + */
648 +
649 + void exit_emul_ppc(void)
650 + {
651 + #if EMUL_TIME_STATS
652 +        clock_t emul_end_time = clock();
653 +
654 +        printf("### Statistics for SheepShaver emulation parts\n");
655 +        const clock_t emul_time = emul_end_time - emul_start_time;
656 +        printf("Total emulation time : %.1f sec\n", double(emul_time) / double(CLOCKS_PER_SEC));
657 +        printf("Total interrupt count: %d (%2.1f Hz)\n", interrupt_count,
658 +                   (double(interrupt_count) * CLOCKS_PER_SEC) / double(emul_time));
659 +
660 + #define PRINT_STATS(LABEL, VAR_PREFIX) do {                                                             \
661 +                printf("Total " LABEL " count : %d\n", VAR_PREFIX##_count);             \
662 +                printf("Total " LABEL " time  : %.1f sec (%.1f%%)\n",                   \
663 +                           double(VAR_PREFIX##_time) / double(CLOCKS_PER_SEC),          \
664 +                           100.0 * double(VAR_PREFIX##_time) / double(emul_time));      \
665 +        } while (0)
666 +
667 +        PRINT_STATS("Execute68k[Trap] execution", exec68k);
668 +        PRINT_STATS("NativeOp execution", native_exec);
669 +        PRINT_STATS("MacOS routine execution", macos_exec);
670 +
671 + #undef PRINT_STATS
672 +        printf("\n");
673 + #endif
674 +
675 +        delete main_cpu;
676 + #if MULTICORE_CPU
677 +        delete interrupt_cpu;
678 + #endif
679   }
680  
681   /*
# Line 594 | Line 685 | void init_emul_ppc(void)
685   void emul_ppc(uint32 entry)
686   {
687          current_cpu = main_cpu;
688 + #if DEBUG
689          current_cpu->start_log();
690 + #endif
691 +        // start emulation loop and enable code translation or caching
692          current_cpu->execute(entry);
693   }
694  
# Line 602 | Line 696 | void emul_ppc(uint32 entry)
696   *  Handle PowerPC interrupt
697   */
698  
699 < // Atomic operations
700 < extern int atomic_add(int *var, int v);
701 < extern int atomic_and(int *var, int v);
702 < extern int atomic_or(int *var, int v);
703 <
704 < #if !ASYNC_IRQ
699 > #if ASYNC_IRQ
700 > void HandleInterrupt(void)
701 > {
702 >        main_cpu->handle_interrupt();
703 > }
704 > #else
705   void TriggerInterrupt(void)
706   {
707   #if 0
708    WriteMacInt32(0x16a, ReadMacInt32(0x16a) + 1);
709   #else
710 <  SPCFLAGS_SET( SPCFLAG_INT );
710 >  // Trigger interrupt to main cpu only
711 >  if (main_cpu)
712 >          main_cpu->trigger_interrupt();
713   #endif
714   }
715   #endif
716  
717 < void HandleInterrupt(void)
717 > void sheepshaver_cpu::handle_interrupt(void)
718   {
719          // Do nothing if interrupts are disabled
720 <        if (int32(ReadMacInt32(XLM_IRQ_NEST)) > 0)
720 >        if (*(int32 *)XLM_IRQ_NEST > 0)
721                  return;
722  
723          // Do nothing if there is no interrupt pending
# Line 637 | Line 733 | void HandleInterrupt(void)
733                  // 68k emulator active, trigger 68k interrupt level 1
734                  assert(current_cpu == main_cpu);
735                  WriteMacInt16(tswap32(kernel_data->v[0x67c >> 2]), 1);
736 <                main_cpu->set_cr(main_cpu->get_cr() | tswap32(kernel_data->v[0x674 >> 2]));
736 >                set_cr(get_cr() | tswap32(kernel_data->v[0x674 >> 2]));
737                  break;
738      
739   #if INTERRUPTS_IN_NATIVE_MODE
740          case MODE_NATIVE:
741                  // 68k emulator inactive, in nanokernel?
742                  assert(current_cpu == main_cpu);
743 <                if (main_cpu->gpr(1) != KernelDataAddr) {
743 >                if (gpr(1) != KernelDataAddr) {
744                          // Prepare for 68k interrupt level 1
745                          WriteMacInt16(tswap32(kernel_data->v[0x67c >> 2]), 1);
746                          WriteMacInt32(tswap32(kernel_data->v[0x658 >> 2]) + 0xdc,
# Line 698 | Line 794 | void HandleInterrupt(void)
794          }
795   }
796  
701 /*
702 *  Execute NATIVE_OP opcode (called by PowerPC emulator)
703 */
704
705 #define POWERPC_NATIVE_OP_INIT(LR, OP) \
706                tswap32(POWERPC_EMUL_OP | ((LR) << 11) | (((uint32)OP) << 6) | 2)
707
708 // FIXME: Make sure 32-bit relocations are used
709 const uint32 NativeOpTable[NATIVE_OP_MAX] = {
710        POWERPC_NATIVE_OP_INIT(1, NATIVE_PATCH_NAME_REGISTRY),
711        POWERPC_NATIVE_OP_INIT(1, NATIVE_VIDEO_INSTALL_ACCEL),
712        POWERPC_NATIVE_OP_INIT(1, NATIVE_VIDEO_VBL),
713        POWERPC_NATIVE_OP_INIT(1, NATIVE_VIDEO_DO_DRIVER_IO),
714        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_IRQ),
715        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_INIT),
716        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_TERM),
717        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_OPEN),
718        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_CLOSE),
719        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_WPUT),
720        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_RSRV),
721        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_NOTHING),
722        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_OPEN),
723        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_PRIME_IN),
724        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_PRIME_OUT),
725        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_CONTROL),
726        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_STATUS),
727        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_CLOSE),
728        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_RESOURCE),
729        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_1_RESOURCE),
730        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_IND_RESOURCE),
731        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_1_IND_RESOURCE),
732        POWERPC_NATIVE_OP_INIT(1, NATIVE_R_GET_RESOURCE),
733        POWERPC_NATIVE_OP_INIT(0, NATIVE_DISABLE_INTERRUPT),
734        POWERPC_NATIVE_OP_INIT(0, NATIVE_ENABLE_INTERRUPT),
735        POWERPC_NATIVE_OP_INIT(1, NATIVE_MAKE_EXECUTABLE),
736 };
737
797   static void get_resource(void);
798   static void get_1_resource(void);
799   static void get_ind_resource(void);
# Line 745 | Line 804 | static void r_get_resource(void);
804  
805   static void NativeOp(int selector)
806   {
807 + #if EMUL_TIME_STATS
808 +        native_exec_count++;
809 +        const clock_t native_exec_start = clock();
810 + #endif
811 +
812          switch (selector) {
813          case NATIVE_PATCH_NAME_REGISTRY:
814                  DoPatchNameRegistry();
# Line 759 | Line 823 | static void NativeOp(int selector)
823                  GPR(3) = (int32)(int16)VideoDoDriverIO((void *)GPR(3), (void *)GPR(4),
824                                                                                             (void *)GPR(5), GPR(6), GPR(7));
825                  break;
826 <        case NATIVE_GET_RESOURCE:
827 <                get_resource();
826 > #ifdef WORDS_BIGENDIAN
827 >        case NATIVE_ETHER_IRQ:
828 >                EtherIRQ();
829                  break;
830 <        case NATIVE_GET_1_RESOURCE:
831 <                get_1_resource();
830 >        case NATIVE_ETHER_INIT:
831 >                GPR(3) = InitStreamModule((void *)GPR(3));
832                  break;
833 <        case NATIVE_GET_IND_RESOURCE:
834 <                get_ind_resource();
833 >        case NATIVE_ETHER_TERM:
834 >                TerminateStreamModule();
835                  break;
836 <        case NATIVE_GET_1_IND_RESOURCE:
837 <                get_1_ind_resource();
836 >        case NATIVE_ETHER_OPEN:
837 >                GPR(3) = ether_open((queue_t *)GPR(3), (void *)GPR(4), GPR(5), GPR(6), (void*)GPR(7));
838 >                break;
839 >        case NATIVE_ETHER_CLOSE:
840 >                GPR(3) = ether_close((queue_t *)GPR(3), GPR(4), (void *)GPR(5));
841                  break;
842 <        case NATIVE_R_GET_RESOURCE:
843 <                r_get_resource();
842 >        case NATIVE_ETHER_WPUT:
843 >                GPR(3) = ether_wput((queue_t *)GPR(3), (mblk_t *)GPR(4));
844                  break;
845 +        case NATIVE_ETHER_RSRV:
846 +                GPR(3) = ether_rsrv((queue_t *)GPR(3));
847 +                break;
848 + #else
849 +        case NATIVE_ETHER_INIT:
850 +                // FIXME: needs more complicated thunks
851 +                GPR(3) = false;
852 +                break;
853 + #endif
854          case NATIVE_SERIAL_NOTHING:
855          case NATIVE_SERIAL_OPEN:
856          case NATIVE_SERIAL_PRIME_IN:
# Line 794 | Line 871 | static void NativeOp(int selector)
871                  GPR(3) = serial_callbacks[selector - NATIVE_SERIAL_NOTHING](GPR(3), GPR(4));
872                  break;
873          }
874 +        case NATIVE_GET_RESOURCE:
875 +        case NATIVE_GET_1_RESOURCE:
876 +        case NATIVE_GET_IND_RESOURCE:
877 +        case NATIVE_GET_1_IND_RESOURCE:
878 +        case NATIVE_R_GET_RESOURCE: {
879 +                typedef void (*GetResourceCallback)(void);
880 +                static const GetResourceCallback get_resource_callbacks[] = {
881 +                        get_resource,
882 +                        get_1_resource,
883 +                        get_ind_resource,
884 +                        get_1_ind_resource,
885 +                        r_get_resource
886 +                };
887 +                get_resource_callbacks[selector - NATIVE_GET_RESOURCE]();
888 +                break;
889 +        }
890          case NATIVE_DISABLE_INTERRUPT:
891                  DisableInterrupt();
892                  break;
# Line 808 | Line 901 | static void NativeOp(int selector)
901                  QuitEmulator();
902                  break;
903          }
904 +
905 + #if EMUL_TIME_STATS
906 +        native_exec_time += (clock() - native_exec_start);
907 + #endif
908   }
909  
910   /*
# Line 816 | Line 913 | static void NativeOp(int selector)
913  
914   void ExecuteNative(int selector)
915   {
916 <        uint32 tvect[2];
820 <        tvect[0] = tswap32(POWERPC_NATIVE_OP_FUNC(selector));
821 <        tvect[1] = 0; // Fake TVECT
822 <        RoutineDescriptor desc = BUILD_PPC_ROUTINE_DESCRIPTOR(0, tvect);
916 >        SheepRoutineDescriptor desc(0, NativeTVECT(selector));
917          M68kRegisters r;
918 <        Execute68k((uint32)&desc, &r);
918 >        Execute68k(desc.addr(), &r);
919   }
920  
921   /*
# Line 842 | Line 936 | void Execute68k(uint32 pc, M68kRegisters
936  
937   void Execute68kTrap(uint16 trap, M68kRegisters *r)
938   {
939 <        uint16 proc[2];
940 <        proc[0] = htons(trap);
941 <        proc[1] = htons(M68K_RTS);
942 <        Execute68k((uint32)proc, r);
939 >        SheepVar proc_var(4);
940 >        uint32 proc = proc_var.addr();
941 >        WriteMacInt16(proc, trap);
942 >        WriteMacInt16(proc + 2, M68K_RTS);
943 >        Execute68k(proc, r);
944   }
945  
946   /*
# Line 900 | Line 995 | uint32 call_macos7(uint32 tvect, uint32
995   }
996  
997   /*
903 *  Atomic operations
904 */
905
906 int atomic_add(int *var, int v)
907 {
908        int ret = *var;
909        *var += v;
910        return ret;
911 }
912
913 int atomic_and(int *var, int v)
914 {
915        int ret = *var;
916        *var &= v;
917        return ret;
918 }
919
920 int atomic_or(int *var, int v)
921 {
922        int ret = *var;
923        *var |= v;
924        return ret;
925 }
926
927 /*
998   *  Resource Manager thunks
999   */
1000  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines