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.17 by gbeauche, 2003-11-10T16:23:58Z vs.
Revision 1.25 by cebix, 2004-01-12T15:37:24Z

# Line 1 | Line 1
1   /*
2   *  sheepshaver_glue.cpp - Glue Kheperix CPU to SheepShaver CPU engine interface
3   *
4 < *  SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
4 > *  SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 30 | Line 30
30   #include "sigsegv.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"
# Line 71 | Line 73 | static void enter_mon(void)
73   #endif
74   }
75  
76 + // From main_*.cpp
77 + extern uintptr SignalStackBase();
78 +
79 + // PowerPC EmulOp to exit from emulation looop
80 + const uint32 POWERPC_EXEC_RETURN = POWERPC_EMUL_OP | 1;
81 +
82   // Enable multicore (main/interrupts) cpu emulation?
83   #define MULTICORE_CPU (ASYNC_IRQ ? 1 : 0)
84  
# Line 92 | Line 100 | static KernelData * const kernel_data =
100   // SIGSEGV handler
101   static sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t);
102  
103 + // JIT Compiler enabled?
104 + static inline bool enable_jit_p()
105 + {
106 +        return PrefsFindBool("jit");
107 + }
108 +
109  
110   /**
111   *              PowerPC emulator glue with special 'sheep' opcodes
112   **/
113  
114 + enum {
115 +        PPC_I(SHEEP) = PPC_I(MAX),
116 +        PPC_I(SHEEP_MAX)
117 + };
118 +
119   class sheepshaver_cpu
120          : public powerpc_cpu
121   {
# Line 108 | Line 127 | public:
127          // Constructor
128          sheepshaver_cpu();
129  
130 <        // Condition Register accessors
130 >        // CR & XER accessors
131          uint32 get_cr() const           { return cr().get(); }
132          void set_cr(uint32 v)           { cr().set(v); }
133 <
134 <        // Execution loop
116 <        void execute(uint32 entry, bool enable_cache = false);
133 >        uint32 get_xer() const          { return xer().get(); }
134 >        void set_xer(uint32 v)          { xer().set(v); }
135  
136          // Execute 68k routine
137          void execute_68k(uint32 entry, M68kRegisters *r);
# Line 147 | Line 165 | public:
165   lazy_allocator< sheepshaver_cpu > allocator_helper< sheepshaver_cpu, lazy_allocator >::allocator;
166  
167   sheepshaver_cpu::sheepshaver_cpu()
168 <        : powerpc_cpu()
168 >        : powerpc_cpu(enable_jit_p())
169   {
170          init_decoder();
171   }
# Line 165 | Line 183 | void sheepshaver_cpu::init_decoder()
183                  { "sheep",
184                    (execute_pmf)&sheepshaver_cpu::execute_sheep,
185                    NULL,
186 +                  PPC_I(SHEEP),
187                    D_form, 6, 0, CFLOW_JUMP | CFLOW_TRAP
188                  }
189          };
# Line 224 | Line 243 | void sheepshaver_cpu::execute_sheep(uint
243                  for (int i = 0; i < 7; i++)
244                          r68.a[i] = gpr(16 + i);
245                  r68.a[7] = gpr(1);
246 +                uint32 saved_cr = get_cr() & CR_field<2>::mask();
247 +                uint32 saved_xer = get_xer();
248                  EmulOp(&r68, gpr(24), EMUL_OP_field::extract(opcode) - 3);
249 +                set_cr(saved_cr);
250 +                set_xer(saved_xer);
251                  for (int i = 0; i < 8; i++)
252                          gpr(8 + i) = r68.d[i];
253                  for (int i = 0; i < 7; i++)
# Line 237 | Line 260 | void sheepshaver_cpu::execute_sheep(uint
260          }
261   }
262  
240 // Execution loop
241 void sheepshaver_cpu::execute(uint32 entry, bool enable_cache)
242 {
243        powerpc_cpu::execute(entry, enable_cache);
244 }
245
263   // Handle MacOS interrupt
264   void sheepshaver_cpu::interrupt(uint32 entry)
265   {
# Line 260 | Line 277 | void sheepshaver_cpu::interrupt(uint32 e
277   #endif
278  
279          // Initialize stack pointer to SheepShaver alternate stack base
280 <        gpr(1) = SheepStack1Base - 64;
280 >        gpr(1) = SignalStackBase() - 64;
281  
282          // Build trampoline to return from interrupt
283 <        uint32 trampoline[] = { htonl(POWERPC_EMUL_OP | 1) };
283 >        SheepVar32 trampoline = POWERPC_EXEC_RETURN;
284  
285          // Prepare registers for nanokernel interrupt routine
286          kernel_data->v[0x004 >> 2] = htonl(gpr(1));
# Line 282 | Line 299 | void sheepshaver_cpu::interrupt(uint32 e
299          gpr(1)  = KernelDataAddr;
300          gpr(7)  = ntohl(kernel_data->v[0x660 >> 2]);
301          gpr(8)  = 0;
302 <        gpr(10) = (uint32)trampoline;
303 <        gpr(12) = (uint32)trampoline;
302 >        gpr(10) = trampoline.addr();
303 >        gpr(12) = trampoline.addr();
304          gpr(13) = get_cr();
305  
306          // rlwimi. r7,r7,8,0,0
# Line 420 | Line 437 | uint32 sheepshaver_cpu::execute_macos_co
437          uint32 saved_ctr= ctr();
438  
439          // Build trampoline with EXEC_RETURN
440 <        uint32 trampoline[] = { htonl(POWERPC_EMUL_OP | 1) };
441 <        lr() = (uint32)trampoline;
440 >        SheepVar32 trampoline = POWERPC_EXEC_RETURN;
441 >        lr() = trampoline.addr();
442  
443          gpr(1) -= 64;                                                           // Create stack frame
444          uint32 proc = ReadMacInt32(tvect);                      // Get routine address
# Line 465 | Line 482 | inline void sheepshaver_cpu::execute_ppc
482          // Save branch registers
483          uint32 saved_lr = lr();
484  
485 <        const uint32 trampoline[] = { htonl(POWERPC_EMUL_OP | 1) };
486 <        lr() = (uint32)trampoline;
485 >        SheepVar32 trampoline = POWERPC_EXEC_RETURN;
486 >        WriteMacInt32(trampoline.addr(), POWERPC_EXEC_RETURN);
487 >        lr() = trampoline.addr();
488  
489          execute(entry);
490  
# Line 611 | Line 629 | void init_emul_ppc(void)
629          // Initialize main CPU emulator
630          main_cpu = new sheepshaver_cpu();
631          main_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROM_BASE + 0x30d000));
632 +        main_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000));
633          WriteMacInt32(XLM_RUN_MODE, MODE_68K);
634  
635   #if MULTICORE_CPU
# Line 675 | Line 694 | void exit_emul_ppc(void)
694   void emul_ppc(uint32 entry)
695   {
696          current_cpu = main_cpu;
697 < #if DEBUG
697 > #if 0
698          current_cpu->start_log();
699   #endif
700          // start emulation loop and enable code translation or caching
701 <        current_cpu->execute(entry, true);
701 >        current_cpu->execute(entry);
702   }
703  
704   /*
# Line 774 | Line 793 | void sheepshaver_cpu::handle_interrupt(v
793                                  if (InterruptFlags & INTFLAG_VIA) {
794                                          ClearInterruptFlag(INTFLAG_VIA);
795                                          ADBInterrupt();
796 <                                        ExecutePPC(VideoVBL);
796 >                                        ExecuteNative(NATIVE_VIDEO_VBL);
797                                  }
798                          }
799   #endif
# Line 784 | Line 803 | void sheepshaver_cpu::handle_interrupt(v
803          }
804   }
805  
787 /*
788 *  Execute NATIVE_OP opcode (called by PowerPC emulator)
789 */
790
791 #define POWERPC_NATIVE_OP_INIT(LR, OP) \
792                tswap32(POWERPC_EMUL_OP | ((LR) << 11) | (((uint32)OP) << 6) | 2)
793
794 // FIXME: Make sure 32-bit relocations are used
795 const uint32 NativeOpTable[NATIVE_OP_MAX] = {
796        POWERPC_NATIVE_OP_INIT(1, NATIVE_PATCH_NAME_REGISTRY),
797        POWERPC_NATIVE_OP_INIT(1, NATIVE_VIDEO_INSTALL_ACCEL),
798        POWERPC_NATIVE_OP_INIT(1, NATIVE_VIDEO_VBL),
799        POWERPC_NATIVE_OP_INIT(1, NATIVE_VIDEO_DO_DRIVER_IO),
800        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_IRQ),
801        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_INIT),
802        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_TERM),
803        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_OPEN),
804        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_CLOSE),
805        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_WPUT),
806        POWERPC_NATIVE_OP_INIT(1, NATIVE_ETHER_RSRV),
807        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_NOTHING),
808        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_OPEN),
809        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_PRIME_IN),
810        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_PRIME_OUT),
811        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_CONTROL),
812        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_STATUS),
813        POWERPC_NATIVE_OP_INIT(1, NATIVE_SERIAL_CLOSE),
814        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_RESOURCE),
815        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_1_RESOURCE),
816        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_IND_RESOURCE),
817        POWERPC_NATIVE_OP_INIT(1, NATIVE_GET_1_IND_RESOURCE),
818        POWERPC_NATIVE_OP_INIT(1, NATIVE_R_GET_RESOURCE),
819        POWERPC_NATIVE_OP_INIT(0, NATIVE_DISABLE_INTERRUPT),
820        POWERPC_NATIVE_OP_INIT(0, NATIVE_ENABLE_INTERRUPT),
821        POWERPC_NATIVE_OP_INIT(1, NATIVE_MAKE_EXECUTABLE),
822 };
823
806   static void get_resource(void);
807   static void get_1_resource(void);
808   static void get_ind_resource(void);
# Line 935 | Line 917 | static void NativeOp(int selector)
917   }
918  
919   /*
938 *  Execute native subroutine (LR must contain return address)
939 */
940
941 void ExecuteNative(int selector)
942 {
943        uint32 tvect[2];
944        tvect[0] = tswap32(POWERPC_NATIVE_OP_FUNC(selector));
945        tvect[1] = 0; // Fake TVECT
946        RoutineDescriptor desc = BUILD_PPC_ROUTINE_DESCRIPTOR(0, tvect);
947        M68kRegisters r;
948        Execute68k((uint32)&desc, &r);
949 }
950
951 /*
920   *  Execute 68k subroutine (must be ended with EXEC_RETURN)
921   *  This must only be called by the emul_thread when in EMUL_OP mode
922   *  r->a[7] is unused, the routine runs on the caller's stack
# Line 966 | Line 934 | void Execute68k(uint32 pc, M68kRegisters
934  
935   void Execute68kTrap(uint16 trap, M68kRegisters *r)
936   {
937 <        uint16 proc[2];
938 <        proc[0] = htons(trap);
939 <        proc[1] = htons(M68K_RTS);
940 <        Execute68k((uint32)proc, r);
937 >        SheepVar proc_var(4);
938 >        uint32 proc = proc_var.addr();
939 >        WriteMacInt16(proc, trap);
940 >        WriteMacInt16(proc + 2, M68K_RTS);
941 >        Execute68k(proc, r);
942   }
943  
944   /*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines