38 |
|
#include "name_registry.h" |
39 |
|
#include "serial.h" |
40 |
|
#include "ether.h" |
41 |
+ |
#include "timer.h" |
42 |
|
|
43 |
|
#include <stdio.h> |
44 |
|
#include <stdlib.h> |
87 |
|
// Enable multicore (main/interrupts) cpu emulation? |
88 |
|
#define MULTICORE_CPU (ASYNC_IRQ ? 1 : 0) |
89 |
|
|
90 |
+ |
// Enable interrupt routine safety checks? |
91 |
+ |
#define SAFE_INTERRUPT_PPC 1 |
92 |
+ |
|
93 |
|
// Enable Execute68k() safety checks? |
94 |
|
#define SAFE_EXEC_68K 1 |
95 |
|
|
102 |
|
// Interrupts in native mode? |
103 |
|
#define INTERRUPTS_IN_NATIVE_MODE 1 |
104 |
|
|
105 |
+ |
// Enable native EMUL_OPs to be run without a mode switch |
106 |
+ |
#define ENABLE_NATIVE_EMUL_OP 1 |
107 |
+ |
|
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); |
113 |
|
|
114 |
+ |
#if PPC_ENABLE_JIT && PPC_REENTRANT_JIT |
115 |
+ |
// Special trampolines for EmulOp and NativeOp |
116 |
+ |
static uint8 *emul_op_trampoline; |
117 |
+ |
static uint8 *native_op_trampoline; |
118 |
+ |
#endif |
119 |
+ |
|
120 |
|
// JIT Compiler enabled? |
121 |
|
static inline bool enable_jit_p() |
122 |
|
{ |
139 |
|
void init_decoder(); |
140 |
|
void execute_sheep(uint32 opcode); |
141 |
|
|
142 |
+ |
// Filter out EMUL_OP routines that only call native code |
143 |
+ |
bool filter_execute_emul_op(uint32 emul_op); |
144 |
+ |
|
145 |
+ |
// "Native" EMUL_OP routines |
146 |
+ |
void execute_emul_op_microseconds(); |
147 |
+ |
void execute_emul_op_idle_time_1(); |
148 |
+ |
void execute_emul_op_idle_time_2(); |
149 |
+ |
|
150 |
+ |
// CPU context to preserve on interrupt |
151 |
+ |
class interrupt_context { |
152 |
+ |
uint32 gpr[32]; |
153 |
+ |
uint32 pc; |
154 |
+ |
uint32 lr; |
155 |
+ |
uint32 ctr; |
156 |
+ |
uint32 cr; |
157 |
+ |
uint32 xer; |
158 |
+ |
sheepshaver_cpu *cpu; |
159 |
+ |
const char *where; |
160 |
+ |
public: |
161 |
+ |
interrupt_context(sheepshaver_cpu *_cpu, const char *_where); |
162 |
+ |
~interrupt_context(); |
163 |
+ |
}; |
164 |
+ |
|
165 |
|
public: |
166 |
|
|
167 |
|
// Constructor |
173 |
|
uint32 get_xer() const { return xer().get(); } |
174 |
|
void set_xer(uint32 v) { xer().set(v); } |
175 |
|
|
176 |
+ |
// Execute NATIVE_OP routine |
177 |
+ |
void execute_native_op(uint32 native_op); |
178 |
+ |
|
179 |
|
// Execute EMUL_OP routine |
180 |
|
void execute_emul_op(uint32 emul_op); |
181 |
|
|
189 |
|
uint32 execute_macos_code(uint32 tvect, int nargs, uint32 const *args); |
190 |
|
|
191 |
|
// Compile one instruction |
192 |
< |
virtual bool compile1(codegen_context_t & cg_context); |
192 |
> |
virtual int compile1(codegen_context_t & cg_context); |
193 |
|
|
194 |
|
// Resource manager thunk |
195 |
|
void get_resource(uint32 old_get_resource); |
260 |
|
} |
261 |
|
} |
262 |
|
|
224 |
– |
// Forward declaration for native opcode handler |
225 |
– |
static void NativeOp(int selector); |
226 |
– |
|
263 |
|
/* NativeOp instruction format: |
264 |
< |
+------------+--------------------------+--+----------+------------+ |
265 |
< |
| 6 | |FN| OP | 2 | |
266 |
< |
+------------+--------------------------+--+----------+------------+ |
267 |
< |
0 5 |6 19 20 21 25 26 31 |
264 |
> |
+------------+-------------------------+--+-----------+------------+ |
265 |
> |
| 6 | |FN| OP | 2 | |
266 |
> |
+------------+-------------------------+--+-----------+------------+ |
267 |
> |
0 5 |6 18 19 20 25 26 31 |
268 |
|
*/ |
269 |
|
|
270 |
< |
typedef bit_field< 20, 20 > FN_field; |
271 |
< |
typedef bit_field< 21, 25 > NATIVE_OP_field; |
270 |
> |
typedef bit_field< 19, 19 > FN_field; |
271 |
> |
typedef bit_field< 20, 25 > NATIVE_OP_field; |
272 |
|
typedef bit_field< 26, 31 > EMUL_OP_field; |
273 |
|
|
274 |
+ |
// "Native" EMUL_OP routines |
275 |
+ |
#define GPR_A(REG) gpr(16 + (REG)) |
276 |
+ |
#define GPR_D(REG) gpr( 8 + (REG)) |
277 |
+ |
|
278 |
+ |
void sheepshaver_cpu::execute_emul_op_microseconds() |
279 |
+ |
{ |
280 |
+ |
Microseconds(GPR_A(0), GPR_D(0)); |
281 |
+ |
} |
282 |
+ |
|
283 |
+ |
void sheepshaver_cpu::execute_emul_op_idle_time_1() |
284 |
+ |
{ |
285 |
+ |
// Sleep if no events pending |
286 |
+ |
if (ReadMacInt32(0x14c) == 0) |
287 |
+ |
Delay_usec(16667); |
288 |
+ |
GPR_A(0) = ReadMacInt32(0x2b6); |
289 |
+ |
} |
290 |
+ |
|
291 |
+ |
void sheepshaver_cpu::execute_emul_op_idle_time_2() |
292 |
+ |
{ |
293 |
+ |
// Sleep if no events pending |
294 |
+ |
if (ReadMacInt32(0x14c) == 0) |
295 |
+ |
Delay_usec(16667); |
296 |
+ |
GPR_D(0) = (uint32)-2; |
297 |
+ |
} |
298 |
+ |
|
299 |
+ |
// Filter out EMUL_OP routines that only call native code |
300 |
+ |
bool sheepshaver_cpu::filter_execute_emul_op(uint32 emul_op) |
301 |
+ |
{ |
302 |
+ |
switch (emul_op) { |
303 |
+ |
case OP_MICROSECONDS: |
304 |
+ |
execute_emul_op_microseconds(); |
305 |
+ |
return true; |
306 |
+ |
case OP_IDLE_TIME: |
307 |
+ |
execute_emul_op_idle_time_1(); |
308 |
+ |
return true; |
309 |
+ |
case OP_IDLE_TIME_2: |
310 |
+ |
execute_emul_op_idle_time_2(); |
311 |
+ |
return true; |
312 |
+ |
} |
313 |
+ |
return false; |
314 |
+ |
} |
315 |
+ |
|
316 |
|
// Execute EMUL_OP routine |
317 |
|
void sheepshaver_cpu::execute_emul_op(uint32 emul_op) |
318 |
|
{ |
319 |
+ |
#if ENABLE_NATIVE_EMUL_OP |
320 |
+ |
// First, filter out EMUL_OPs that can be executed without a mode switch |
321 |
+ |
if (filter_execute_emul_op(emul_op)) |
322 |
+ |
return; |
323 |
+ |
#endif |
324 |
+ |
|
325 |
|
M68kRegisters r68; |
326 |
|
WriteMacInt32(XLM_68K_R25, gpr(25)); |
327 |
|
WriteMacInt32(XLM_RUN_MODE, MODE_EMUL_OP); |
359 |
|
break; |
360 |
|
|
361 |
|
case 2: // EXEC_NATIVE |
362 |
< |
NativeOp(NATIVE_OP_field::extract(opcode)); |
362 |
> |
execute_native_op(NATIVE_OP_field::extract(opcode)); |
363 |
|
if (FN_field::test(opcode)) |
364 |
|
pc() = lr(); |
365 |
|
else |
374 |
|
} |
375 |
|
|
376 |
|
// Compile one instruction |
377 |
< |
bool sheepshaver_cpu::compile1(codegen_context_t & cg_context) |
377 |
> |
int sheepshaver_cpu::compile1(codegen_context_t & cg_context) |
378 |
|
{ |
379 |
|
#if PPC_ENABLE_JIT |
380 |
|
const instr_info_t *ii = cg_context.instr_info; |
381 |
|
if (ii->mnemo != PPC_I(SHEEP)) |
382 |
< |
return false; |
382 |
> |
return COMPILE_FAILURE; |
383 |
|
|
384 |
< |
bool compiled = false; |
384 |
> |
int status = COMPILE_FAILURE; |
385 |
|
powerpc_dyngen & dg = cg_context.codegen; |
386 |
|
uint32 opcode = cg_context.opcode; |
387 |
|
|
388 |
|
switch (opcode & 0x3f) { |
389 |
|
case 0: // EMUL_RETURN |
390 |
|
dg.gen_invoke(QuitEmulator); |
391 |
< |
compiled = true; |
391 |
> |
status = COMPILE_CODE_OK; |
392 |
|
break; |
393 |
|
|
394 |
|
case 1: // EXEC_RETURN |
395 |
|
dg.gen_spcflags_set(SPCFLAG_CPU_EXEC_RETURN); |
396 |
< |
compiled = true; |
396 |
> |
// Don't check for pending interrupts, we do know we have to |
397 |
> |
// get out of this block ASAP |
398 |
> |
dg.gen_exec_return(); |
399 |
> |
status = COMPILE_EPILOGUE_OK; |
400 |
|
break; |
401 |
|
|
402 |
|
case 2: { // EXEC_NATIVE |
403 |
|
uint32 selector = NATIVE_OP_field::extract(opcode); |
404 |
|
switch (selector) { |
405 |
+ |
#if !PPC_REENTRANT_JIT |
406 |
+ |
// Filter out functions that may invoke Execute68k() or |
407 |
+ |
// CallMacOS(), this would break reentrancy as they could |
408 |
+ |
// invalidate the translation cache and even overwrite |
409 |
+ |
// continuation code when we are done with them. |
410 |
|
case NATIVE_PATCH_NAME_REGISTRY: |
411 |
|
dg.gen_invoke(DoPatchNameRegistry); |
412 |
< |
compiled = true; |
412 |
> |
status = COMPILE_CODE_OK; |
413 |
|
break; |
414 |
|
case NATIVE_VIDEO_INSTALL_ACCEL: |
415 |
|
dg.gen_invoke(VideoInstallAccel); |
416 |
< |
compiled = true; |
416 |
> |
status = COMPILE_CODE_OK; |
417 |
|
break; |
418 |
|
case NATIVE_VIDEO_VBL: |
419 |
|
dg.gen_invoke(VideoVBL); |
420 |
< |
compiled = true; |
420 |
> |
status = COMPILE_CODE_OK; |
421 |
|
break; |
422 |
|
case NATIVE_GET_RESOURCE: |
423 |
|
case NATIVE_GET_1_RESOURCE: |
435 |
|
typedef void (*func_t)(dyngen_cpu_base, uint32); |
436 |
|
func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::get_resource).ptr(); |
437 |
|
dg.gen_invoke_CPU_im(func, old_get_resource); |
438 |
< |
compiled = true; |
438 |
> |
status = COMPILE_CODE_OK; |
439 |
|
break; |
440 |
|
} |
441 |
+ |
case NATIVE_CHECK_LOAD_INVOC: |
442 |
+ |
dg.gen_load_T0_GPR(3); |
443 |
+ |
dg.gen_load_T1_GPR(4); |
444 |
+ |
dg.gen_se_16_32_T1(); |
445 |
+ |
dg.gen_load_T2_GPR(5); |
446 |
+ |
dg.gen_invoke_T0_T1_T2((void (*)(uint32, uint32, uint32))check_load_invoc); |
447 |
+ |
status = COMPILE_CODE_OK; |
448 |
+ |
break; |
449 |
+ |
#endif |
450 |
|
case NATIVE_DISABLE_INTERRUPT: |
451 |
|
dg.gen_invoke(DisableInterrupt); |
452 |
< |
compiled = true; |
452 |
> |
status = COMPILE_CODE_OK; |
453 |
|
break; |
454 |
|
case NATIVE_ENABLE_INTERRUPT: |
455 |
|
dg.gen_invoke(EnableInterrupt); |
456 |
< |
compiled = true; |
456 |
> |
status = COMPILE_CODE_OK; |
457 |
|
break; |
458 |
< |
case NATIVE_CHECK_LOAD_INVOC: |
458 |
> |
case NATIVE_BITBLT: |
459 |
|
dg.gen_load_T0_GPR(3); |
460 |
< |
dg.gen_load_T1_GPR(4); |
461 |
< |
dg.gen_se_16_32_T1(); |
462 |
< |
dg.gen_load_T2_GPR(5); |
463 |
< |
dg.gen_invoke_T0_T1_T2((void (*)(uint32, uint32, uint32))check_load_invoc); |
464 |
< |
compiled = true; |
460 |
> |
dg.gen_invoke_T0((void (*)(uint32))NQD_bitblt); |
461 |
> |
status = COMPILE_CODE_OK; |
462 |
> |
break; |
463 |
> |
case NATIVE_INVRECT: |
464 |
> |
dg.gen_load_T0_GPR(3); |
465 |
> |
dg.gen_invoke_T0((void (*)(uint32))NQD_invrect); |
466 |
> |
status = COMPILE_CODE_OK; |
467 |
> |
break; |
468 |
> |
case NATIVE_FILLRECT: |
469 |
> |
dg.gen_load_T0_GPR(3); |
470 |
> |
dg.gen_invoke_T0((void (*)(uint32))NQD_fillrect); |
471 |
> |
status = COMPILE_CODE_OK; |
472 |
|
break; |
473 |
|
} |
474 |
+ |
// Could we fully translate this NativeOp? |
475 |
|
if (FN_field::test(opcode)) { |
476 |
< |
if (compiled) { |
476 |
> |
if (status != COMPILE_FAILURE) { |
477 |
|
dg.gen_load_A0_LR(); |
478 |
|
dg.gen_set_PC_A0(); |
479 |
|
} |
480 |
|
cg_context.done_compile = true; |
481 |
+ |
break; |
482 |
|
} |
483 |
< |
else |
483 |
> |
else if (status != COMPILE_FAILURE) { |
484 |
|
cg_context.done_compile = false; |
485 |
+ |
break; |
486 |
+ |
} |
487 |
+ |
#if PPC_REENTRANT_JIT |
488 |
+ |
// Try to execute NativeOp trampoline |
489 |
+ |
dg.gen_set_PC_im(cg_context.pc + 4); |
490 |
+ |
dg.gen_mov_32_T0_im(selector); |
491 |
+ |
dg.gen_jmp(native_op_trampoline); |
492 |
+ |
cg_context.done_compile = true; |
493 |
+ |
status = COMPILE_EPILOGUE_OK; |
494 |
+ |
break; |
495 |
+ |
#endif |
496 |
+ |
// Invoke NativeOp handler |
497 |
+ |
typedef void (*func_t)(dyngen_cpu_base, uint32); |
498 |
+ |
func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_native_op).ptr(); |
499 |
+ |
dg.gen_invoke_CPU_im(func, selector); |
500 |
+ |
cg_context.done_compile = false; |
501 |
+ |
status = COMPILE_CODE_OK; |
502 |
|
break; |
503 |
|
} |
504 |
|
|
505 |
|
default: { // EMUL_OP |
506 |
+ |
uint32 emul_op = EMUL_OP_field::extract(opcode) - 3; |
507 |
+ |
#if ENABLE_NATIVE_EMUL_OP |
508 |
+ |
typedef void (*emul_op_func_t)(dyngen_cpu_base); |
509 |
+ |
emul_op_func_t emul_op_func = 0; |
510 |
+ |
switch (emul_op) { |
511 |
+ |
case OP_MICROSECONDS: |
512 |
+ |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_microseconds).ptr(); |
513 |
+ |
break; |
514 |
+ |
case OP_IDLE_TIME: |
515 |
+ |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_1).ptr(); |
516 |
+ |
break; |
517 |
+ |
case OP_IDLE_TIME_2: |
518 |
+ |
emul_op_func = (emul_op_func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op_idle_time_2).ptr(); |
519 |
+ |
break; |
520 |
+ |
} |
521 |
+ |
if (emul_op_func) { |
522 |
+ |
dg.gen_invoke_CPU(emul_op_func); |
523 |
+ |
cg_context.done_compile = false; |
524 |
+ |
status = COMPILE_CODE_OK; |
525 |
+ |
break; |
526 |
+ |
} |
527 |
+ |
#endif |
528 |
+ |
#if PPC_REENTRANT_JIT |
529 |
+ |
// Try to execute EmulOp trampoline |
530 |
+ |
dg.gen_set_PC_im(cg_context.pc + 4); |
531 |
+ |
dg.gen_mov_32_T0_im(emul_op); |
532 |
+ |
dg.gen_jmp(emul_op_trampoline); |
533 |
+ |
cg_context.done_compile = true; |
534 |
+ |
status = COMPILE_EPILOGUE_OK; |
535 |
+ |
break; |
536 |
+ |
#endif |
537 |
+ |
// Invoke EmulOp handler |
538 |
|
typedef void (*func_t)(dyngen_cpu_base, uint32); |
539 |
|
func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op).ptr(); |
540 |
< |
dg.gen_invoke_CPU_im(func, EMUL_OP_field::extract(opcode) - 3); |
540 |
> |
dg.gen_invoke_CPU_im(func, emul_op); |
541 |
|
cg_context.done_compile = false; |
542 |
< |
compiled = true; |
542 |
> |
status = COMPILE_CODE_OK; |
543 |
|
break; |
544 |
|
} |
545 |
|
} |
546 |
< |
return compiled; |
546 |
> |
return status; |
547 |
> |
#endif |
548 |
> |
return COMPILE_FAILURE; |
549 |
> |
} |
550 |
> |
|
551 |
> |
// CPU context to preserve on interrupt |
552 |
> |
sheepshaver_cpu::interrupt_context::interrupt_context(sheepshaver_cpu *_cpu, const char *_where) |
553 |
> |
{ |
554 |
> |
#if SAFE_INTERRUPT_PPC >= 2 |
555 |
> |
cpu = _cpu; |
556 |
> |
where = _where; |
557 |
> |
|
558 |
> |
// Save interrupt context |
559 |
> |
memcpy(&gpr[0], &cpu->gpr(0), sizeof(gpr)); |
560 |
> |
pc = cpu->pc(); |
561 |
> |
lr = cpu->lr(); |
562 |
> |
ctr = cpu->ctr(); |
563 |
> |
cr = cpu->get_cr(); |
564 |
> |
xer = cpu->get_xer(); |
565 |
> |
#endif |
566 |
> |
} |
567 |
> |
|
568 |
> |
sheepshaver_cpu::interrupt_context::~interrupt_context() |
569 |
> |
{ |
570 |
> |
#if SAFE_INTERRUPT_PPC >= 2 |
571 |
> |
// Check whether CPU context was preserved by interrupt |
572 |
> |
if (memcmp(&gpr[0], &cpu->gpr(0), sizeof(gpr)) != 0) { |
573 |
> |
printf("FATAL: %s: interrupt clobbers registers\n", where); |
574 |
> |
for (int i = 0; i < 32; i++) |
575 |
> |
if (gpr[i] != cpu->gpr(i)) |
576 |
> |
printf(" r%d: %08x -> %08x\n", i, gpr[i], cpu->gpr(i)); |
577 |
> |
} |
578 |
> |
if (pc != cpu->pc()) |
579 |
> |
printf("FATAL: %s: interrupt clobbers PC\n", where); |
580 |
> |
if (lr != cpu->lr()) |
581 |
> |
printf("FATAL: %s: interrupt clobbers LR\n", where); |
582 |
> |
if (ctr != cpu->ctr()) |
583 |
> |
printf("FATAL: %s: interrupt clobbers CTR\n", where); |
584 |
> |
if (cr != cpu->get_cr()) |
585 |
> |
printf("FATAL: %s: interrupt clobbers CR\n", where); |
586 |
> |
if (xer != cpu->get_xer()) |
587 |
> |
printf("FATAL: %s: interrupt clobbers XER\n", where); |
588 |
|
#endif |
389 |
– |
return false; |
589 |
|
} |
590 |
|
|
591 |
|
// Handle MacOS interrupt |
596 |
|
const clock_t interrupt_start = clock(); |
597 |
|
#endif |
598 |
|
|
599 |
+ |
#if SAFE_INTERRUPT_PPC |
600 |
+ |
static int depth = 0; |
601 |
+ |
if (depth != 0) |
602 |
+ |
printf("FATAL: sheepshaver_cpu::interrupt() called more than once: %d\n", depth); |
603 |
+ |
depth++; |
604 |
+ |
#endif |
605 |
+ |
|
606 |
|
#if !MULTICORE_CPU |
607 |
|
// Save program counters and branch registers |
608 |
|
uint32 saved_pc = pc(); |
660 |
|
#if EMUL_TIME_STATS |
661 |
|
interrupt_time += (clock() - interrupt_start); |
662 |
|
#endif |
663 |
+ |
|
664 |
+ |
#if SAFE_INTERRUPT_PPC |
665 |
+ |
depth--; |
666 |
+ |
#endif |
667 |
|
} |
668 |
|
|
669 |
|
// Execute 68k routine |
1028 |
|
#endif |
1029 |
|
} |
1030 |
|
|
1031 |
+ |
#if PPC_ENABLE_JIT && PPC_REENTRANT_JIT |
1032 |
+ |
// Initialize EmulOp trampolines |
1033 |
+ |
void init_emul_op_trampolines(basic_dyngen & dg) |
1034 |
+ |
{ |
1035 |
+ |
typedef void (*func_t)(dyngen_cpu_base, uint32); |
1036 |
+ |
func_t func; |
1037 |
+ |
|
1038 |
+ |
// EmulOp |
1039 |
+ |
emul_op_trampoline = dg.gen_start(); |
1040 |
+ |
func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op).ptr(); |
1041 |
+ |
dg.gen_invoke_CPU_T0(func); |
1042 |
+ |
dg.gen_exec_return(); |
1043 |
+ |
dg.gen_end(); |
1044 |
+ |
|
1045 |
+ |
// NativeOp |
1046 |
+ |
native_op_trampoline = dg.gen_start(); |
1047 |
+ |
func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_native_op).ptr(); |
1048 |
+ |
dg.gen_invoke_CPU_T0(func); |
1049 |
+ |
dg.gen_exec_return(); |
1050 |
+ |
dg.gen_end(); |
1051 |
+ |
|
1052 |
+ |
D(bug("EmulOp trampoline: %p\n", emul_op_trampoline)); |
1053 |
+ |
D(bug("NativeOp trampoline: %p\n", native_op_trampoline)); |
1054 |
+ |
} |
1055 |
+ |
#endif |
1056 |
+ |
|
1057 |
|
/* |
1058 |
|
* Emulation loop |
1059 |
|
*/ |
1117 |
|
// 68k emulator inactive, in nanokernel? |
1118 |
|
assert(current_cpu == main_cpu); |
1119 |
|
if (gpr(1) != KernelDataAddr) { |
1120 |
+ |
interrupt_context ctx(this, "PowerPC mode"); |
1121 |
+ |
|
1122 |
|
// Prepare for 68k interrupt level 1 |
1123 |
|
WriteMacInt16(tswap32(kernel_data->v[0x67c >> 2]), 1); |
1124 |
|
WriteMacInt32(tswap32(kernel_data->v[0x658 >> 2]) + 0xdc, |
1141 |
|
case MODE_EMUL_OP: |
1142 |
|
// 68k emulator active, within EMUL_OP routine, execute 68k interrupt routine directly when interrupt level is 0 |
1143 |
|
if ((ReadMacInt32(XLM_68K_R25) & 7) == 0) { |
1144 |
+ |
interrupt_context ctx(this, "68k mode"); |
1145 |
|
#if 1 |
1146 |
|
// Execute full 68k interrupt routine |
1147 |
|
M68kRegisters r; |
1179 |
|
static void get_1_ind_resource(void); |
1180 |
|
static void r_get_resource(void); |
1181 |
|
|
1182 |
< |
#define GPR(REG) current_cpu->gpr(REG) |
1183 |
< |
|
945 |
< |
static void NativeOp(int selector) |
1182 |
> |
// Execute NATIVE_OP routine |
1183 |
> |
void sheepshaver_cpu::execute_native_op(uint32 selector) |
1184 |
|
{ |
1185 |
|
#if EMUL_TIME_STATS |
1186 |
|
native_exec_count++; |
1198 |
|
VideoVBL(); |
1199 |
|
break; |
1200 |
|
case NATIVE_VIDEO_DO_DRIVER_IO: |
1201 |
< |
GPR(3) = (int32)(int16)VideoDoDriverIO((void *)GPR(3), (void *)GPR(4), |
1202 |
< |
(void *)GPR(5), GPR(6), GPR(7)); |
1201 |
> |
gpr(3) = (int32)(int16)VideoDoDriverIO((void *)gpr(3), (void *)gpr(4), |
1202 |
> |
(void *)gpr(5), gpr(6), gpr(7)); |
1203 |
|
break; |
1204 |
|
#ifdef WORDS_BIGENDIAN |
1205 |
|
case NATIVE_ETHER_IRQ: |
1206 |
|
EtherIRQ(); |
1207 |
|
break; |
1208 |
|
case NATIVE_ETHER_INIT: |
1209 |
< |
GPR(3) = InitStreamModule((void *)GPR(3)); |
1209 |
> |
gpr(3) = InitStreamModule((void *)gpr(3)); |
1210 |
|
break; |
1211 |
|
case NATIVE_ETHER_TERM: |
1212 |
|
TerminateStreamModule(); |
1213 |
|
break; |
1214 |
|
case NATIVE_ETHER_OPEN: |
1215 |
< |
GPR(3) = ether_open((queue_t *)GPR(3), (void *)GPR(4), GPR(5), GPR(6), (void*)GPR(7)); |
1215 |
> |
gpr(3) = ether_open((queue_t *)gpr(3), (void *)gpr(4), gpr(5), gpr(6), (void*)gpr(7)); |
1216 |
|
break; |
1217 |
|
case NATIVE_ETHER_CLOSE: |
1218 |
< |
GPR(3) = ether_close((queue_t *)GPR(3), GPR(4), (void *)GPR(5)); |
1218 |
> |
gpr(3) = ether_close((queue_t *)gpr(3), gpr(4), (void *)gpr(5)); |
1219 |
|
break; |
1220 |
|
case NATIVE_ETHER_WPUT: |
1221 |
< |
GPR(3) = ether_wput((queue_t *)GPR(3), (mblk_t *)GPR(4)); |
1221 |
> |
gpr(3) = ether_wput((queue_t *)gpr(3), (mblk_t *)gpr(4)); |
1222 |
|
break; |
1223 |
|
case NATIVE_ETHER_RSRV: |
1224 |
< |
GPR(3) = ether_rsrv((queue_t *)GPR(3)); |
1224 |
> |
gpr(3) = ether_rsrv((queue_t *)gpr(3)); |
1225 |
|
break; |
1226 |
|
#else |
1227 |
|
case NATIVE_ETHER_INIT: |
1228 |
|
// FIXME: needs more complicated thunks |
1229 |
< |
GPR(3) = false; |
1229 |
> |
gpr(3) = false; |
1230 |
|
break; |
1231 |
|
#endif |
1232 |
|
case NATIVE_SYNC_HOOK: |
1233 |
< |
GPR(3) = NQD_sync_hook(GPR(3)); |
1233 |
> |
gpr(3) = NQD_sync_hook(gpr(3)); |
1234 |
|
break; |
1235 |
|
case NATIVE_BITBLT_HOOK: |
1236 |
< |
GPR(3) = NQD_bitblt_hook(GPR(3)); |
1236 |
> |
gpr(3) = NQD_bitblt_hook(gpr(3)); |
1237 |
|
break; |
1238 |
|
case NATIVE_BITBLT: |
1239 |
< |
NQD_bitblt(GPR(3)); |
1239 |
> |
NQD_bitblt(gpr(3)); |
1240 |
|
break; |
1241 |
|
case NATIVE_FILLRECT_HOOK: |
1242 |
< |
GPR(3) = NQD_fillrect_hook(GPR(3)); |
1242 |
> |
gpr(3) = NQD_fillrect_hook(gpr(3)); |
1243 |
|
break; |
1244 |
|
case NATIVE_INVRECT: |
1245 |
< |
NQD_invrect(GPR(3)); |
1245 |
> |
NQD_invrect(gpr(3)); |
1246 |
|
break; |
1247 |
|
case NATIVE_FILLRECT: |
1248 |
< |
NQD_fillrect(GPR(3)); |
1248 |
> |
NQD_fillrect(gpr(3)); |
1249 |
|
break; |
1250 |
|
case NATIVE_SERIAL_NOTHING: |
1251 |
|
case NATIVE_SERIAL_OPEN: |
1264 |
|
SerialStatus, |
1265 |
|
SerialClose |
1266 |
|
}; |
1267 |
< |
GPR(3) = serial_callbacks[selector - NATIVE_SERIAL_NOTHING](GPR(3), GPR(4)); |
1267 |
> |
gpr(3) = serial_callbacks[selector - NATIVE_SERIAL_NOTHING](gpr(3), gpr(4)); |
1268 |
|
break; |
1269 |
|
} |
1270 |
|
case NATIVE_GET_RESOURCE: |
1274 |
|
case NATIVE_R_GET_RESOURCE: { |
1275 |
|
typedef void (*GetResourceCallback)(void); |
1276 |
|
static const GetResourceCallback get_resource_callbacks[] = { |
1277 |
< |
get_resource, |
1278 |
< |
get_1_resource, |
1279 |
< |
get_ind_resource, |
1280 |
< |
get_1_ind_resource, |
1281 |
< |
r_get_resource |
1277 |
> |
::get_resource, |
1278 |
> |
::get_1_resource, |
1279 |
> |
::get_ind_resource, |
1280 |
> |
::get_1_ind_resource, |
1281 |
> |
::r_get_resource |
1282 |
|
}; |
1283 |
|
get_resource_callbacks[selector - NATIVE_GET_RESOURCE](); |
1284 |
|
break; |
1290 |
|
EnableInterrupt(); |
1291 |
|
break; |
1292 |
|
case NATIVE_MAKE_EXECUTABLE: |
1293 |
< |
MakeExecutable(0, (void *)GPR(4), GPR(5)); |
1293 |
> |
MakeExecutable(0, (void *)gpr(4), gpr(5)); |
1294 |
|
break; |
1295 |
|
case NATIVE_CHECK_LOAD_INVOC: |
1296 |
< |
check_load_invoc(GPR(3), GPR(4), GPR(5)); |
1296 |
> |
check_load_invoc(gpr(3), gpr(4), gpr(5)); |
1297 |
|
break; |
1298 |
|
default: |
1299 |
|
printf("FATAL: NATIVE_OP called with bogus selector %d\n", selector); |