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 |
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 |
|
|
130 |
|
// Constructor |
131 |
|
sheepshaver_cpu(); |
132 |
|
|
133 |
< |
// Condition Register accessors |
133 |
> |
// CR & XER accessors |
134 |
|
uint32 get_cr() const { return cr().get(); } |
135 |
|
void set_cr(uint32 v) { cr().set(v); } |
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); |
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 |
|
|
181 |
|
|
182 |
|
void sheepshaver_cpu::init_decoder() |
183 |
|
{ |
173 |
– |
#ifndef PPC_NO_STATIC_II_INDEX_TABLE |
174 |
– |
static bool initialized = false; |
175 |
– |
if (initialized) |
176 |
– |
return; |
177 |
– |
initialized = true; |
178 |
– |
#endif |
179 |
– |
|
184 |
|
static const instr_info_t sheep_ii_table[] = { |
185 |
|
{ "sheep", |
186 |
|
(execute_pmf)&sheepshaver_cpu::execute_sheep, |
213 |
|
typedef bit_field< 21, 25 > NATIVE_OP_field; |
214 |
|
typedef bit_field< 26, 31 > EMUL_OP_field; |
215 |
|
|
216 |
+ |
// Execute EMUL_OP routine |
217 |
+ |
void sheepshaver_cpu::execute_emul_op(uint32 emul_op) |
218 |
+ |
{ |
219 |
+ |
M68kRegisters r68; |
220 |
+ |
WriteMacInt32(XLM_68K_R25, gpr(25)); |
221 |
+ |
WriteMacInt32(XLM_RUN_MODE, MODE_EMUL_OP); |
222 |
+ |
for (int i = 0; i < 8; i++) |
223 |
+ |
r68.d[i] = gpr(8 + i); |
224 |
+ |
for (int i = 0; i < 7; i++) |
225 |
+ |
r68.a[i] = gpr(16 + i); |
226 |
+ |
r68.a[7] = gpr(1); |
227 |
+ |
uint32 saved_cr = get_cr() & CR_field<2>::mask(); |
228 |
+ |
uint32 saved_xer = get_xer(); |
229 |
+ |
EmulOp(&r68, gpr(24), emul_op); |
230 |
+ |
set_cr(saved_cr); |
231 |
+ |
set_xer(saved_xer); |
232 |
+ |
for (int i = 0; i < 8; i++) |
233 |
+ |
gpr(8 + i) = r68.d[i]; |
234 |
+ |
for (int i = 0; i < 7; i++) |
235 |
+ |
gpr(16 + i) = r68.a[i]; |
236 |
+ |
gpr(1) = r68.a[7]; |
237 |
+ |
WriteMacInt32(XLM_RUN_MODE, MODE_68K); |
238 |
+ |
} |
239 |
+ |
|
240 |
|
// Execute SheepShaver instruction |
241 |
|
void sheepshaver_cpu::execute_sheep(uint32 opcode) |
242 |
|
{ |
260 |
|
pc() += 4; |
261 |
|
break; |
262 |
|
|
263 |
< |
default: { // EMUL_OP |
264 |
< |
M68kRegisters r68; |
237 |
< |
WriteMacInt32(XLM_68K_R25, gpr(25)); |
238 |
< |
WriteMacInt32(XLM_RUN_MODE, MODE_EMUL_OP); |
239 |
< |
for (int i = 0; i < 8; i++) |
240 |
< |
r68.d[i] = gpr(8 + i); |
241 |
< |
for (int i = 0; i < 7; i++) |
242 |
< |
r68.a[i] = gpr(16 + i); |
243 |
< |
r68.a[7] = gpr(1); |
244 |
< |
EmulOp(&r68, gpr(24), EMUL_OP_field::extract(opcode) - 3); |
245 |
< |
for (int i = 0; i < 8; i++) |
246 |
< |
gpr(8 + i) = r68.d[i]; |
247 |
< |
for (int i = 0; i < 7; i++) |
248 |
< |
gpr(16 + i) = r68.a[i]; |
249 |
< |
gpr(1) = r68.a[7]; |
250 |
< |
WriteMacInt32(XLM_RUN_MODE, MODE_68K); |
263 |
> |
default: // EMUL_OP |
264 |
> |
execute_emul_op(EMUL_OP_field::extract(opcode) - 3); |
265 |
|
pc() += 4; |
266 |
|
break; |
267 |
|
} |
268 |
+ |
} |
269 |
+ |
|
270 |
+ |
// Compile one instruction |
271 |
+ |
bool sheepshaver_cpu::compile1(codegen_context_t & cg_context) |
272 |
+ |
{ |
273 |
+ |
#if PPC_ENABLE_JIT |
274 |
+ |
const instr_info_t *ii = cg_context.instr_info; |
275 |
+ |
if (ii->mnemo != PPC_I(SHEEP)) |
276 |
+ |
return false; |
277 |
+ |
|
278 |
+ |
bool compiled = false; |
279 |
+ |
powerpc_dyngen & dg = cg_context.codegen; |
280 |
+ |
uint32 opcode = cg_context.opcode; |
281 |
+ |
|
282 |
+ |
switch (opcode & 0x3f) { |
283 |
+ |
case 0: // EMUL_RETURN |
284 |
+ |
dg.gen_invoke(QuitEmulator); |
285 |
+ |
compiled = true; |
286 |
+ |
break; |
287 |
+ |
|
288 |
+ |
case 1: // EXEC_RETURN |
289 |
+ |
dg.gen_spcflags_set(SPCFLAG_CPU_EXEC_RETURN); |
290 |
+ |
compiled = true; |
291 |
+ |
break; |
292 |
+ |
|
293 |
+ |
case 2: { // EXEC_NATIVE |
294 |
+ |
uint32 selector = NATIVE_OP_field::extract(opcode); |
295 |
+ |
switch (selector) { |
296 |
+ |
case NATIVE_PATCH_NAME_REGISTRY: |
297 |
+ |
dg.gen_invoke(DoPatchNameRegistry); |
298 |
+ |
compiled = true; |
299 |
+ |
break; |
300 |
+ |
case NATIVE_VIDEO_INSTALL_ACCEL: |
301 |
+ |
dg.gen_invoke(VideoInstallAccel); |
302 |
+ |
compiled = true; |
303 |
+ |
break; |
304 |
+ |
case NATIVE_VIDEO_VBL: |
305 |
+ |
dg.gen_invoke(VideoVBL); |
306 |
+ |
compiled = true; |
307 |
+ |
break; |
308 |
+ |
case NATIVE_GET_RESOURCE: |
309 |
+ |
case NATIVE_GET_1_RESOURCE: |
310 |
+ |
case NATIVE_GET_IND_RESOURCE: |
311 |
+ |
case NATIVE_GET_1_IND_RESOURCE: |
312 |
+ |
case NATIVE_R_GET_RESOURCE: { |
313 |
+ |
static const uint32 get_resource_ptr[] = { |
314 |
+ |
XLM_GET_RESOURCE, |
315 |
+ |
XLM_GET_1_RESOURCE, |
316 |
+ |
XLM_GET_IND_RESOURCE, |
317 |
+ |
XLM_GET_1_IND_RESOURCE, |
318 |
+ |
XLM_R_GET_RESOURCE |
319 |
+ |
}; |
320 |
+ |
uint32 old_get_resource = ReadMacInt32(get_resource_ptr[selector - NATIVE_GET_RESOURCE]); |
321 |
+ |
typedef void (*func_t)(dyngen_cpu_base, uint32); |
322 |
+ |
func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::get_resource).ptr(); |
323 |
+ |
dg.gen_invoke_CPU_im(func, old_get_resource); |
324 |
+ |
compiled = true; |
325 |
+ |
break; |
326 |
+ |
} |
327 |
+ |
case NATIVE_DISABLE_INTERRUPT: |
328 |
+ |
dg.gen_invoke(DisableInterrupt); |
329 |
+ |
compiled = true; |
330 |
+ |
break; |
331 |
+ |
case NATIVE_ENABLE_INTERRUPT: |
332 |
+ |
dg.gen_invoke(EnableInterrupt); |
333 |
+ |
compiled = true; |
334 |
+ |
break; |
335 |
+ |
case NATIVE_CHECK_LOAD_INVOC: |
336 |
+ |
dg.gen_load_T0_GPR(3); |
337 |
+ |
dg.gen_load_T1_GPR(4); |
338 |
+ |
dg.gen_se_16_32_T1(); |
339 |
+ |
dg.gen_load_T2_GPR(5); |
340 |
+ |
dg.gen_invoke_T0_T1_T2((void (*)(uint32, uint32, uint32))check_load_invoc); |
341 |
+ |
compiled = true; |
342 |
+ |
break; |
343 |
+ |
} |
344 |
+ |
if (FN_field::test(opcode)) { |
345 |
+ |
if (compiled) { |
346 |
+ |
dg.gen_load_A0_LR(); |
347 |
+ |
dg.gen_set_PC_A0(); |
348 |
+ |
} |
349 |
+ |
cg_context.done_compile = true; |
350 |
+ |
} |
351 |
+ |
else |
352 |
+ |
cg_context.done_compile = false; |
353 |
+ |
break; |
354 |
|
} |
355 |
+ |
|
356 |
+ |
default: { // EMUL_OP |
357 |
+ |
typedef void (*func_t)(dyngen_cpu_base, uint32); |
358 |
+ |
func_t func = (func_t)nv_mem_fun(&sheepshaver_cpu::execute_emul_op).ptr(); |
359 |
+ |
dg.gen_invoke_CPU_im(func, EMUL_OP_field::extract(opcode) - 3); |
360 |
+ |
cg_context.done_compile = false; |
361 |
+ |
compiled = true; |
362 |
+ |
break; |
363 |
+ |
} |
364 |
+ |
} |
365 |
+ |
return compiled; |
366 |
+ |
#endif |
367 |
+ |
return false; |
368 |
|
} |
369 |
|
|
370 |
|
// Handle MacOS interrupt |
600 |
|
} |
601 |
|
|
602 |
|
// Resource Manager thunk |
490 |
– |
extern "C" void check_load_invoc(uint32 type, int16 id, uint32 h); |
491 |
– |
|
603 |
|
inline void sheepshaver_cpu::get_resource(uint32 old_get_resource) |
604 |
|
{ |
605 |
|
uint32 type = gpr(3); |
734 |
|
// Initialize main CPU emulator |
735 |
|
main_cpu = new sheepshaver_cpu(); |
736 |
|
main_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROM_BASE + 0x30d000)); |
737 |
+ |
main_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000)); |
738 |
|
WriteMacInt32(XLM_RUN_MODE, MODE_68K); |
739 |
|
|
740 |
|
#if MULTICORE_CPU |
799 |
|
void emul_ppc(uint32 entry) |
800 |
|
{ |
801 |
|
current_cpu = main_cpu; |
802 |
< |
#if DEBUG |
802 |
> |
#if 0 |
803 |
|
current_cpu->start_log(); |
804 |
|
#endif |
805 |
|
// start emulation loop and enable code translation or caching |
1010 |
|
case NATIVE_MAKE_EXECUTABLE: |
1011 |
|
MakeExecutable(0, (void *)GPR(4), GPR(5)); |
1012 |
|
break; |
1013 |
+ |
case NATIVE_CHECK_LOAD_INVOC: |
1014 |
+ |
check_load_invoc(GPR(3), GPR(4), GPR(5)); |
1015 |
+ |
break; |
1016 |
|
default: |
1017 |
|
printf("FATAL: NATIVE_OP called with bogus selector %d\n", selector); |
1018 |
|
QuitEmulator(); |