109 |
|
#include "user_strings.h" |
110 |
|
#include "vm_alloc.h" |
111 |
|
#include "sigsegv.h" |
112 |
+ |
#include "thunks.h" |
113 |
|
|
114 |
|
#define DEBUG 0 |
115 |
|
#include "debug.h" |
146 |
|
const char ROM_FILE_NAME[] = "ROM"; |
147 |
|
const char ROM_FILE_NAME2[] = "Mac OS ROM"; |
148 |
|
|
149 |
< |
const uint32 RAM_BASE = 0x20000000; // Base address of RAM |
149 |
> |
const uintptr RAM_BASE = 0x20000000; // Base address of RAM |
150 |
|
const uint32 SIG_STACK_SIZE = 0x10000; // Size of signal stack |
151 |
|
|
152 |
|
|
173 |
|
#endif |
174 |
|
uint32 RAMBase; // Base address of Mac RAM |
175 |
|
uint32 RAMSize; // Size of Mac RAM |
175 |
– |
uint32 SheepStack1Base; // SheepShaver first alternate stack base |
176 |
– |
uint32 SheepStack2Base; // SheepShaver second alternate stack base |
177 |
– |
uint32 SheepThunksBase; // SheepShaver thunks base |
176 |
|
uint32 KernelDataAddr; // Address of Kernel Data |
177 |
|
uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM |
178 |
|
uint32 PVR; // Theoretical PVR |
185 |
|
Display *x_display = NULL; // X11 display handle |
186 |
|
|
187 |
|
static int zero_fd = 0; // FD of /dev/zero |
190 |
– |
static bool sheep_area_mapped = false; // Flag: SheepShaver data area mmap()ed |
188 |
|
static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped |
189 |
|
static int kernel_area = -1; // SHM ID of Kernel Data area |
190 |
|
static bool rom_area_mapped = false; // Flag: Mac ROM mmap()ped |
213 |
|
static sigregs sigsegv_regs; // Register dump when crashed |
214 |
|
#endif |
215 |
|
|
216 |
+ |
uintptr SheepMem::base = 0x60000000; // Address of SheepShaver data |
217 |
+ |
uintptr SheepMem::top = 0; // Top of SheepShaver data (stack like storage) |
218 |
+ |
|
219 |
|
|
220 |
|
// Prototypes |
221 |
|
static void Quit(void); |
470 |
|
ErrorAlert(str); |
471 |
|
goto quit; |
472 |
|
} |
473 |
< |
kernel_data = (KernelData *)0x68ffe000; |
473 |
> |
kernel_data = (KernelData *)KERNEL_DATA_BASE; |
474 |
|
emulator_data = &kernel_data->ed; |
475 |
< |
KernelDataAddr = (uint32)kernel_data; |
475 |
> |
KernelDataAddr = KERNEL_DATA_BASE; |
476 |
|
D(bug("Kernel Data at %p, Emulator Data at %p\n", kernel_data, emulator_data)); |
477 |
|
|
478 |
|
// Create area for SheepShaver data |
479 |
< |
if (vm_acquire_fixed((char *)SHEEP_BASE, SHEEP_SIZE) < 0) { |
479 |
> |
if (!SheepMem::Init()) { |
480 |
|
sprintf(str, GetString(STR_SHEEP_MEM_MMAP_ERR), strerror(errno)); |
481 |
|
ErrorAlert(str); |
482 |
|
goto quit; |
483 |
|
} |
484 |
– |
SheepStack1Base = SHEEP_BASE + 0x10000; |
485 |
– |
SheepStack2Base = SheepStack1Base + 0x10000; |
486 |
– |
SheepThunksBase = SheepStack2Base + 0x1000; |
487 |
– |
sheep_area_mapped = true; |
484 |
|
|
485 |
|
// Create area for Mac ROM |
486 |
|
if (vm_acquire_fixed((char *)ROM_BASE, ROM_AREA_SIZE) < 0) { |
575 |
|
boot_globs[1] = htonl(RAMSize); |
576 |
|
boot_globs[2] = htonl((uint32)-1); // End of bank table |
577 |
|
|
578 |
+ |
// Init thunks |
579 |
+ |
if (!ThunksInit()) |
580 |
+ |
goto quit; |
581 |
+ |
|
582 |
|
// Init drivers |
583 |
|
SonyInit(); |
584 |
|
DiskInit(); |
622 |
|
// Initialize Kernel Data |
623 |
|
memset(kernel_data, 0, sizeof(KernelData)); |
624 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
625 |
< |
static uint32 of_dev_tree[4] = {0, 0, 0, 0}; |
626 |
< |
static uint8 vector_lookup_tbl[128]; |
627 |
< |
static uint8 vector_mask_tbl[64]; |
625 |
> |
uintptr of_dev_tree = SheepMem::Reserve(4 * sizeof(uint32)); |
626 |
> |
memset((void *)of_dev_tree, 0, 4 * sizeof(uint32)); |
627 |
> |
uintptr vector_lookup_tbl = SheepMem::Reserve(128); |
628 |
> |
uintptr vector_mask_tbl = SheepMem::Reserve(64); |
629 |
|
memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80); |
630 |
< |
memset(vector_lookup_tbl, 0, 128); |
631 |
< |
memset(vector_mask_tbl, 0, 64); |
630 |
> |
memset((void *)vector_lookup_tbl, 0, 128); |
631 |
> |
memset((void *)vector_mask_tbl, 0, 64); |
632 |
|
kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE); |
633 |
< |
kernel_data->v[0xb84 >> 2] = htonl((uint32)of_dev_tree); // OF device tree base |
634 |
< |
kernel_data->v[0xb90 >> 2] = htonl((uint32)vector_lookup_tbl); |
635 |
< |
kernel_data->v[0xb94 >> 2] = htonl((uint32)vector_mask_tbl); |
633 |
> |
kernel_data->v[0xb84 >> 2] = htonl(of_dev_tree); // OF device tree base |
634 |
> |
kernel_data->v[0xb90 >> 2] = htonl(vector_lookup_tbl); |
635 |
> |
kernel_data->v[0xb94 >> 2] = htonl(vector_mask_tbl); |
636 |
|
kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE); // OpenPIC base |
637 |
|
kernel_data->v[0xbb0 >> 2] = htonl(0); // ADB base |
638 |
|
kernel_data->v[0xc20 >> 2] = htonl(RAMSize); |
668 |
|
D(bug("Initializing Low Memory...\n")); |
669 |
|
memset(NULL, 0, 0x3000); |
670 |
|
WriteMacInt32(XLM_SIGNATURE, FOURCC('B','a','a','h')); // Signature to detect SheepShaver |
671 |
< |
WriteMacInt32(XLM_KERNEL_DATA, (uint32)kernel_data); // For trap replacement routines |
671 |
> |
WriteMacInt32(XLM_KERNEL_DATA, KernelDataAddr); // For trap replacement routines |
672 |
|
WriteMacInt32(XLM_PVR, PVR); // Theoretical PVR |
673 |
|
WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch |
674 |
|
WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode) |
675 |
|
#if EMULATED_PPC |
676 |
< |
WriteMacInt32(XLM_ETHER_INIT, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_INIT)); |
677 |
< |
WriteMacInt32(XLM_ETHER_TERM, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_TERM)); |
678 |
< |
WriteMacInt32(XLM_ETHER_OPEN, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_OPEN)); |
679 |
< |
WriteMacInt32(XLM_ETHER_CLOSE, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_CLOSE)); |
680 |
< |
WriteMacInt32(XLM_ETHER_WPUT, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_WPUT)); |
681 |
< |
WriteMacInt32(XLM_ETHER_RSRV, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_RSRV)); |
682 |
< |
WriteMacInt32(XLM_VIDEO_DOIO, POWERPC_NATIVE_OP_FUNC(NATIVE_VIDEO_DO_DRIVER_IO)); |
676 |
> |
WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT)); |
677 |
> |
WriteMacInt32(XLM_ETHER_TERM, NativeFunction(NATIVE_ETHER_TERM)); |
678 |
> |
WriteMacInt32(XLM_ETHER_OPEN, NativeFunction(NATIVE_ETHER_OPEN)); |
679 |
> |
WriteMacInt32(XLM_ETHER_CLOSE, NativeFunction(NATIVE_ETHER_CLOSE)); |
680 |
> |
WriteMacInt32(XLM_ETHER_WPUT, NativeFunction(NATIVE_ETHER_WPUT)); |
681 |
> |
WriteMacInt32(XLM_ETHER_RSRV, NativeFunction(NATIVE_ETHER_RSRV)); |
682 |
> |
WriteMacInt32(XLM_VIDEO_DOIO, NativeFunction(NATIVE_VIDEO_DO_DRIVER_IO)); |
683 |
|
#else |
684 |
|
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator |
685 |
|
WriteMacInt32(XLM_ETHER_INIT, (uint32)InitStreamModule); // DLPI ethernet driver functions |
844 |
|
DiskExit(); |
845 |
|
SonyExit(); |
846 |
|
|
847 |
+ |
// Delete SheepShaver globals |
848 |
+ |
SheepMem::Exit(); |
849 |
+ |
|
850 |
|
// Delete RAM area |
851 |
|
if (ram_area_mapped) |
852 |
|
vm_release((char *)RAM_BASE, RAMSize); |
967 |
|
void ExecutePPC(void (*func)()) |
968 |
|
{ |
969 |
|
uint32 tvect[2] = {(uint32)func, 0}; // Fake TVECT |
970 |
< |
RoutineDescriptor desc = BUILD_PPC_ROUTINE_DESCRIPTOR(0, tvect); |
970 |
> |
SheepRoutineDescriptor desc(0, tvect); |
971 |
|
M68kRegisters r; |
972 |
|
Execute68k((uint32)&desc, &r); |
973 |
|
} |
1791 |
|
|
1792 |
|
|
1793 |
|
/* |
1794 |
+ |
* Helpers to share 32-bit addressable data with MacOS |
1795 |
+ |
*/ |
1796 |
+ |
|
1797 |
+ |
bool SheepMem::Init(void) |
1798 |
+ |
{ |
1799 |
+ |
if (vm_acquire_fixed((char *)base, size) < 0) |
1800 |
+ |
return false; |
1801 |
+ |
top = base + size; |
1802 |
+ |
return true; |
1803 |
+ |
} |
1804 |
+ |
|
1805 |
+ |
void SheepMem::Exit(void) |
1806 |
+ |
{ |
1807 |
+ |
if (top) |
1808 |
+ |
vm_release((void *)base, size); |
1809 |
+ |
} |
1810 |
+ |
|
1811 |
+ |
|
1812 |
+ |
/* |
1813 |
|
* Display alert |
1814 |
|
*/ |
1815 |
|
|