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.25 by cebix, 2004-01-12T15:37:24Z vs.
Revision 1.26 by gbeauche, 2004-01-24T11:28:06Z

# Line 76 | Line 76 | static void enter_mon(void)
76   // From main_*.cpp
77   extern uintptr SignalStackBase();
78  
79 + // From rsrc_patches.cpp
80 + extern "C" void check_load_invoc(uint32 type, int16 id, uint32 h);
81 +
82   // PowerPC EmulOp to exit from emulation looop
83   const uint32 POWERPC_EXEC_RETURN = POWERPC_EMUL_OP | 1;
84  
# Line 133 | Line 136 | public:
136          uint32 get_xer() const          { return xer().get(); }
137          void set_xer(uint32 v)          { xer().set(v); }
138  
139 +        // Execute EMUL_OP routine
140 +        void execute_emul_op(uint32 emul_op);
141 +
142          // Execute 68k routine
143          void execute_68k(uint32 entry, M68kRegisters *r);
144  
# Line 142 | Line 148 | public:
148          // Execute MacOS/PPC code
149          uint32 execute_macos_code(uint32 tvect, int nargs, uint32 const *args);
150  
151 +        // Compile one instruction
152 +        virtual bool compile1(codegen_context_t & cg_context);
153 +
154          // Resource manager thunk
155          void get_resource(uint32 old_get_resource);
156  
# Line 211 | Line 220 | typedef bit_field< 20, 20 > FN_field;
220   typedef bit_field< 21, 25 > NATIVE_OP_field;
221   typedef bit_field< 26, 31 > EMUL_OP_field;
222  
223 + // Execute EMUL_OP routine
224 + void sheepshaver_cpu::execute_emul_op(uint32 emul_op)
225 + {
226 +        M68kRegisters r68;
227 +        WriteMacInt32(XLM_68K_R25, gpr(25));
228 +        WriteMacInt32(XLM_RUN_MODE, MODE_EMUL_OP);
229 +        for (int i = 0; i < 8; i++)
230 +                r68.d[i] = gpr(8 + i);
231 +        for (int i = 0; i < 7; i++)
232 +                r68.a[i] = gpr(16 + i);
233 +        r68.a[7] = gpr(1);
234 +        uint32 saved_cr = get_cr() & CR_field<2>::mask();
235 +        uint32 saved_xer = get_xer();
236 +        EmulOp(&r68, gpr(24), emul_op);
237 +        set_cr(saved_cr);
238 +        set_xer(saved_xer);
239 +        for (int i = 0; i < 8; i++)
240 +                gpr(8 + i) = r68.d[i];
241 +        for (int i = 0; i < 7; i++)
242 +                gpr(16 + i) = r68.a[i];
243 +        gpr(1) = r68.a[7];
244 +        WriteMacInt32(XLM_RUN_MODE, MODE_68K);
245 + }
246 +
247   // Execute SheepShaver instruction
248   void sheepshaver_cpu::execute_sheep(uint32 opcode)
249   {
# Line 234 | Line 267 | void sheepshaver_cpu::execute_sheep(uint
267                          pc() += 4;
268                  break;
269  
270 <        default: {      // EMUL_OP
271 <                M68kRegisters r68;
239 <                WriteMacInt32(XLM_68K_R25, gpr(25));
240 <                WriteMacInt32(XLM_RUN_MODE, MODE_EMUL_OP);
241 <                for (int i = 0; i < 8; i++)
242 <                        r68.d[i] = gpr(8 + i);
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++)
254 <                        gpr(16 + i) = r68.a[i];
255 <                gpr(1) = r68.a[7];
256 <                WriteMacInt32(XLM_RUN_MODE, MODE_68K);
270 >        default:        // EMUL_OP
271 >                execute_emul_op(EMUL_OP_field::extract(opcode) - 3);
272                  pc() += 4;
273                  break;
274          }
275 + }
276 +
277 + // Compile one instruction
278 + bool sheepshaver_cpu::compile1(codegen_context_t & cg_context)
279 + {
280 + #if PPC_ENABLE_JIT
281 +        const instr_info_t *ii = cg_context.instr_info;
282 +        if (ii->mnemo != PPC_I(SHEEP))
283 +                return false;
284 +
285 +        bool compiled = false;
286 +        powerpc_dyngen & dg = cg_context.codegen;
287 +        uint32 opcode = cg_context.opcode;
288 +
289 +        switch (opcode & 0x3f) {
290 +        case 0:         // EMUL_RETURN
291 +                dg.gen_invoke(QuitEmulator);
292 +                compiled = true;
293 +                break;
294 +
295 +        case 1:         // EXEC_RETURN
296 +                dg.gen_spcflags_set(SPCFLAG_CPU_EXEC_RETURN);
297 +                compiled = true;
298 +                break;
299 +
300 +        case 2: {       // EXEC_NATIVE
301 +                uint32 selector = NATIVE_OP_field::extract(opcode);
302 +                switch (selector) {
303 +                case NATIVE_PATCH_NAME_REGISTRY:
304 +                        dg.gen_invoke(DoPatchNameRegistry);
305 +                        compiled = true;
306 +                        break;
307 +                case NATIVE_VIDEO_INSTALL_ACCEL:
308 +                        dg.gen_invoke(VideoInstallAccel);
309 +                        compiled = true;
310 +                        break;
311 +                case NATIVE_VIDEO_VBL:
312 +                        dg.gen_invoke(VideoVBL);
313 +                        compiled = true;
314 +                        break;
315 +                case NATIVE_GET_RESOURCE:
316 +                case NATIVE_GET_1_RESOURCE:
317 +                case NATIVE_GET_IND_RESOURCE:
318 +                case NATIVE_GET_1_IND_RESOURCE:
319 +                case NATIVE_R_GET_RESOURCE: {
320 +                        static const uint32 get_resource_ptr[] = {
321 +                                XLM_GET_RESOURCE,
322 +                                XLM_GET_1_RESOURCE,
323 +                                XLM_GET_IND_RESOURCE,
324 +                                XLM_GET_1_IND_RESOURCE,
325 +                                XLM_R_GET_RESOURCE
326 +                        };
327 +                        uint32 old_get_resource = ReadMacInt32(get_resource_ptr[selector - NATIVE_GET_RESOURCE]);
328 +                        typedef void (*func_t)(dyngen_cpu_base, uint32);
329 +                        func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::get_resource).ptr();
330 +                        dg.gen_invoke_CPU_im(func, old_get_resource);
331 +                        compiled = true;
332 +                        break;
333 +                }
334 +                case NATIVE_DISABLE_INTERRUPT:
335 +                        dg.gen_invoke(DisableInterrupt);
336 +                        compiled = true;
337 +                        break;
338 +                case NATIVE_ENABLE_INTERRUPT:
339 +                        dg.gen_invoke(EnableInterrupt);
340 +                        compiled = true;
341 +                        break;
342 +                case NATIVE_CHECK_LOAD_INVOC:
343 +                        dg.gen_load_T0_GPR(3);
344 +                        dg.gen_load_T1_GPR(4);
345 +                        dg.gen_se_16_32_T1();
346 +                        dg.gen_load_T2_GPR(5);
347 +                        dg.gen_invoke_T0_T1_T2((void (*)(uint32, uint32, uint32))check_load_invoc);
348 +                        compiled = true;
349 +                        break;
350 +                }
351 +                if (FN_field::test(opcode)) {
352 +                        if (compiled) {
353 +                                dg.gen_load_A0_LR();
354 +                                dg.gen_set_PC_A0();
355 +                        }
356 +                        cg_context.done_compile = true;
357 +                }
358 +                else
359 +                        cg_context.done_compile = false;
360 +                break;
361          }
362 +
363 +        default: {      // EMUL_OP
364 +                typedef void (*func_t)(dyngen_cpu_base, uint32);
365 +                func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op).ptr();
366 +                dg.gen_invoke_CPU_im(func, EMUL_OP_field::extract(opcode) - 3);
367 +                cg_context.done_compile = false;
368 +                compiled = true;
369 +                break;
370 +        }
371 +        }
372 +        return compiled;
373 + #endif
374 +        return false;
375   }
376  
377   // Handle MacOS interrupt
# Line 493 | Line 607 | inline void sheepshaver_cpu::execute_ppc
607   }
608  
609   // Resource Manager thunk
496 extern "C" void check_load_invoc(uint32 type, int16 id, uint32 h);
497
610   inline void sheepshaver_cpu::get_resource(uint32 old_get_resource)
611   {
612          uint32 type = gpr(3);
# Line 905 | Line 1017 | static void NativeOp(int selector)
1017          case NATIVE_MAKE_EXECUTABLE:
1018                  MakeExecutable(0, (void *)GPR(4), GPR(5));
1019                  break;
1020 +        case NATIVE_CHECK_LOAD_INVOC:
1021 +                check_load_invoc(GPR(3), GPR(4), GPR(5));
1022 +                break;
1023          default:
1024                  printf("FATAL: NATIVE_OP called with bogus selector %d\n", selector);
1025                  QuitEmulator();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines