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" |
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 (ASYNC_IRQ ? 1 : 0) |
81 |
|
|
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 |
+ |
enum { |
112 |
+ |
PPC_I(SHEEP) = PPC_I(MAX), |
113 |
+ |
PPC_I(SHEEP_MAX) |
114 |
+ |
}; |
115 |
+ |
|
116 |
|
class sheepshaver_cpu |
117 |
|
: public powerpc_cpu |
118 |
|
{ |
128 |
|
uint32 get_cr() const { return cr().get(); } |
129 |
|
void set_cr(uint32 v) { cr().set(v); } |
130 |
|
|
115 |
– |
// Execution loop |
116 |
– |
void execute(uint32 entry, bool enable_cache = false); |
117 |
– |
|
131 |
|
// Execute 68k routine |
132 |
|
void execute_68k(uint32 entry, M68kRegisters *r); |
133 |
|
|
160 |
|
lazy_allocator< sheepshaver_cpu > allocator_helper< sheepshaver_cpu, lazy_allocator >::allocator; |
161 |
|
|
162 |
|
sheepshaver_cpu::sheepshaver_cpu() |
163 |
< |
: powerpc_cpu() |
163 |
> |
: powerpc_cpu(enable_jit_p()) |
164 |
|
{ |
165 |
|
init_decoder(); |
166 |
|
} |
178 |
|
{ "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 |
|
}; |
251 |
|
} |
252 |
|
} |
253 |
|
|
240 |
– |
// Execution loop |
241 |
– |
void sheepshaver_cpu::execute(uint32 entry, bool enable_cache) |
242 |
– |
{ |
243 |
– |
powerpc_cpu::execute(entry, enable_cache); |
244 |
– |
} |
245 |
– |
|
254 |
|
// Handle MacOS interrupt |
255 |
|
void sheepshaver_cpu::interrupt(uint32 entry) |
256 |
|
{ |
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)); |
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; |
294 |
> |
gpr(10) = trampoline.addr(); |
295 |
> |
gpr(12) = trampoline.addr(); |
296 |
|
gpr(13) = get_cr(); |
297 |
|
|
298 |
|
// rlwimi. r7,r7,8,0,0 |
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 |
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 |
|
|
689 |
|
current_cpu->start_log(); |
690 |
|
#endif |
691 |
|
// start emulation loop and enable code translation or caching |
692 |
< |
current_cpu->execute(entry, true); |
692 |
> |
current_cpu->execute(entry); |
693 |
|
} |
694 |
|
|
695 |
|
/* |
794 |
|
} |
795 |
|
} |
796 |
|
|
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 |
– |
|
797 |
|
static void get_resource(void); |
798 |
|
static void get_1_resource(void); |
799 |
|
static void get_ind_resource(void); |
913 |
|
|
914 |
|
void ExecuteNative(int selector) |
915 |
|
{ |
916 |
< |
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); |
916 |
> |
SheepRoutineDescriptor desc(0, NativeTVECT(selector)); |
917 |
|
M68kRegisters r; |
918 |
< |
Execute68k((uint32)&desc, &r); |
918 |
> |
Execute68k(desc.addr(), &r); |
919 |
|
} |
920 |
|
|
921 |
|
/* |
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 |
|
/* |