42 |
|
|
43 |
|
#include <stdio.h> |
44 |
|
#include <stdlib.h> |
45 |
+ |
#ifdef HAVE_MALLOC_H |
46 |
+ |
#include <malloc.h> |
47 |
+ |
#endif |
48 |
|
|
49 |
|
#ifdef USE_SDL_VIDEO |
50 |
|
#include <SDL_events.h> |
109 |
|
#define INTERRUPTS_IN_NATIVE_MODE 1 |
110 |
|
|
111 |
|
// Pointer to Kernel Data |
112 |
< |
static KernelData * const kernel_data = (KernelData *)KERNEL_DATA_BASE; |
112 |
> |
static KernelData * kernel_data; |
113 |
|
|
114 |
|
// SIGSEGV handler |
115 |
|
sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); |
183 |
|
// Execute MacOS/PPC code |
184 |
|
uint32 execute_macos_code(uint32 tvect, int nargs, uint32 const *args); |
185 |
|
|
186 |
+ |
#if PPC_ENABLE_JIT |
187 |
|
// Compile one instruction |
188 |
|
virtual int compile1(codegen_context_t & cg_context); |
189 |
< |
|
189 |
> |
#endif |
190 |
|
// Resource manager thunk |
191 |
|
void get_resource(uint32 old_get_resource); |
192 |
|
|
196 |
|
|
197 |
|
// Make sure the SIGSEGV handler can access CPU registers |
198 |
|
friend sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); |
199 |
+ |
|
200 |
+ |
// Memory allocator returning areas aligned on 16-byte boundaries |
201 |
+ |
void *operator new(size_t size); |
202 |
+ |
void operator delete(void *p); |
203 |
|
}; |
204 |
|
|
205 |
|
// Memory allocator returning areas aligned on 16-byte boundaries |
206 |
< |
void *operator new(size_t size) |
206 |
> |
void *sheepshaver_cpu::operator new(size_t size) |
207 |
|
{ |
208 |
|
void *p; |
209 |
|
|
222 |
|
return p; |
223 |
|
} |
224 |
|
|
225 |
< |
void operator delete(void *p) |
225 |
> |
void sheepshaver_cpu::operator delete(void *p) |
226 |
|
{ |
227 |
|
#if defined(HAVE_MEMALIGN) || defined(HAVE_VALLOC) |
228 |
|
#if defined(__GLIBC__) |
326 |
|
} |
327 |
|
|
328 |
|
// Compile one instruction |
329 |
+ |
#if PPC_ENABLE_JIT |
330 |
|
int sheepshaver_cpu::compile1(codegen_context_t & cg_context) |
331 |
|
{ |
323 |
– |
#if PPC_ENABLE_JIT |
332 |
|
const instr_info_t *ii = cg_context.instr_info; |
333 |
|
if (ii->mnemo != PPC_I(SHEEP)) |
334 |
|
return COMPILE_FAILURE; |
474 |
|
} |
475 |
|
} |
476 |
|
return status; |
469 |
– |
#endif |
470 |
– |
return COMPILE_FAILURE; |
477 |
|
} |
478 |
+ |
#endif |
479 |
|
|
480 |
|
// CPU context to preserve on interrupt |
481 |
|
sheepshaver_cpu::interrupt_context::interrupt_context(sheepshaver_cpu *_cpu, const char *_where) |
819 |
|
const uintptr addr = (uintptr)fault_address; |
820 |
|
#if HAVE_SIGSEGV_SKIP_INSTRUCTION |
821 |
|
// Ignore writes to ROM |
822 |
< |
if ((addr - ROM_BASE) < ROM_SIZE) |
822 |
> |
if ((addr - (uintptr)ROMBaseHost) < ROM_SIZE) |
823 |
|
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
824 |
|
|
825 |
|
// Get program counter of target CPU |
879 |
|
|
880 |
|
void init_emul_ppc(void) |
881 |
|
{ |
882 |
+ |
// Get pointer to KernelData in host address space |
883 |
+ |
kernel_data = (KernelData *)Mac2HostAddr(KERNEL_DATA_BASE); |
884 |
+ |
|
885 |
|
// Initialize main CPU emulator |
886 |
|
ppc_cpu = new sheepshaver_cpu(); |
887 |
|
ppc_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROM_BASE + 0x30d000)); |
1052 |
|
M68kRegisters r; |
1053 |
|
uint32 old_r25 = ReadMacInt32(XLM_68K_R25); // Save interrupt level |
1054 |
|
WriteMacInt32(XLM_68K_R25, 0x21); // Execute with interrupt level 1 |
1055 |
< |
static const uint8 proc[] = { |
1055 |
> |
static const uint8 proc_template[] = { |
1056 |
|
0x3f, 0x3c, 0x00, 0x00, // move.w #$0000,-(sp) (fake format word) |
1057 |
|
0x48, 0x7a, 0x00, 0x0a, // pea @1(pc) (return address) |
1058 |
|
0x40, 0xe7, // move sr,-(sp) (saved SR) |
1060 |
|
0x4e, 0xd0, // jmp (a0) |
1061 |
|
M68K_RTS >> 8, M68K_RTS & 0xff // @1 |
1062 |
|
}; |
1063 |
< |
Execute68k((uint32)proc, &r); |
1063 |
> |
BUILD_SHEEPSHAVER_PROCEDURE(proc); |
1064 |
> |
Execute68k(proc, &r); |
1065 |
|
WriteMacInt32(XLM_68K_R25, old_r25); // Restore interrupt level |
1066 |
|
#else |
1067 |
|
// Only update cursor |
1110 |
|
VideoVBL(); |
1111 |
|
break; |
1112 |
|
case NATIVE_VIDEO_DO_DRIVER_IO: |
1113 |
< |
gpr(3) = (int32)(int16)VideoDoDriverIO((void *)gpr(3), (void *)gpr(4), |
1103 |
< |
(void *)gpr(5), gpr(6), gpr(7)); |
1113 |
> |
gpr(3) = (int32)(int16)VideoDoDriverIO(gpr(3), gpr(4), gpr(5), gpr(6), gpr(7)); |
1114 |
|
break; |
1105 |
– |
#ifdef WORDS_BIGENDIAN |
1115 |
|
case NATIVE_ETHER_IRQ: |
1116 |
|
EtherIRQ(); |
1117 |
|
break; |
1133 |
|
case NATIVE_ETHER_RSRV: |
1134 |
|
gpr(3) = ether_rsrv((queue_t *)gpr(3)); |
1135 |
|
break; |
1127 |
– |
#else |
1128 |
– |
case NATIVE_ETHER_INIT: |
1129 |
– |
// FIXME: needs more complicated thunks |
1130 |
– |
gpr(3) = false; |
1131 |
– |
break; |
1132 |
– |
#endif |
1136 |
|
case NATIVE_SYNC_HOOK: |
1137 |
|
gpr(3) = NQD_sync_hook(gpr(3)); |
1138 |
|
break; |
1188 |
|
break; |
1189 |
|
} |
1190 |
|
case NATIVE_MAKE_EXECUTABLE: |
1191 |
< |
MakeExecutable(0, (void *)gpr(4), gpr(5)); |
1191 |
> |
MakeExecutable(0, gpr(4), gpr(5)); |
1192 |
|
break; |
1193 |
|
case NATIVE_CHECK_LOAD_INVOC: |
1194 |
|
check_load_invoc(gpr(3), gpr(4), gpr(5)); |