5 |
|
* Based (in a small way) on the default main.m, |
6 |
|
and on Basilisk's main_unix.cpp |
7 |
|
* |
8 |
< |
* Basilisk II (C) 1997-2005 Christian Bauer |
8 |
> |
* Basilisk II (C) 1997-2008 Christian Bauer |
9 |
|
* |
10 |
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
* it under the terms of the GNU General Public License as published by |
54 |
|
#include "xpram.h" |
55 |
|
|
56 |
|
#if USE_JIT |
57 |
< |
extern void flush_icache_range(uint32 start, uint32 size); // from compemu_support.cpp |
57 |
> |
extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp |
58 |
|
#endif |
59 |
|
|
60 |
|
#ifdef ENABLE_MON |
73 |
|
const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area |
74 |
|
|
75 |
|
|
76 |
+ |
static char *bundle = NULL; // If in an OS X application bundle, its path |
77 |
+ |
|
78 |
+ |
|
79 |
|
// CPU and FPU type, addressing mode |
80 |
|
int CPUType; |
81 |
|
bool CPUIs68060; |
82 |
|
int FPUType; |
83 |
|
bool TwentyFourBitAddressing; |
81 |
– |
bool ThirtyThreeBitAddressing = false; |
84 |
|
|
85 |
|
|
86 |
|
// Global variables |
116 |
|
* Helpers to map memory that can be accessed from the Mac side |
117 |
|
*/ |
118 |
|
|
119 |
< |
// NOTE: VM_MAP_33BIT is only used when compiling a 64-bit JIT on specific platforms |
119 |
> |
// NOTE: VM_MAP_32BIT is only used when compiling a 64-bit JIT on specific platforms |
120 |
|
void *vm_acquire_mac(size_t size) |
121 |
|
{ |
122 |
< |
void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT); |
121 |
< |
#ifdef USE_33BIT_ADDRESSING |
122 |
< |
if (m == VM_MAP_FAILED) { |
123 |
< |
printf("WARNING: Cannot acquire memory in 33-bit address space (%s)\n", strerror(errno)); |
124 |
< |
ThirtyThreeBitAddressing = false; |
125 |
< |
m = vm_acquire(size); |
126 |
< |
} |
127 |
< |
#endif |
128 |
< |
return m; |
122 |
> |
return vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); |
123 |
|
} |
124 |
|
|
125 |
|
static int vm_acquire_mac_fixed(void *addr, size_t size) |
126 |
|
{ |
127 |
< |
int ret = vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_33BIT); |
134 |
< |
#ifdef USE_33BIT_ADDRESSING |
135 |
< |
if (ret < 0) { |
136 |
< |
printf("WARNING: Cannot acquire fixed memory in 33-bit address space (%s)\n", strerror(errno)); |
137 |
< |
ThirtyThreeBitAddressing = false; |
138 |
< |
ret = vm_acquire_fixed(addr, size); |
139 |
< |
} |
140 |
< |
#endif |
141 |
< |
return ret; |
127 |
> |
return vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_32BIT); |
128 |
|
} |
129 |
|
|
130 |
|
|
132 |
|
* SIGSEGV handler |
133 |
|
*/ |
134 |
|
|
135 |
< |
static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, |
150 |
< |
sigsegv_address_t fault_instruction) |
135 |
> |
static sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip) |
136 |
|
{ |
137 |
+ |
const uintptr fault_address = (uintptr)sigsegv_get_fault_address(sip); |
138 |
|
#if ENABLE_VOSF |
139 |
|
// Handle screen fault |
140 |
< |
extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t); |
141 |
< |
if (Screen_fault_handler(fault_address, fault_instruction)) |
140 |
> |
extern bool Screen_fault_handler(sigsegv_info_t *sip); |
141 |
> |
if (Screen_fault_handler(sip)) |
142 |
|
return SIGSEGV_RETURN_SUCCESS; |
143 |
|
#endif |
144 |
|
|
160 |
|
* Dump state when everything went wrong after a SEGV |
161 |
|
*/ |
162 |
|
|
163 |
< |
static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
163 |
> |
static void sigsegv_dump_state(sigsegv_info_t *sip) |
164 |
|
{ |
165 |
+ |
const sigsegv_address_t fault_address = sigsegv_get_fault_address(sip); |
166 |
+ |
const sigsegv_address_t fault_instruction = sigsegv_get_fault_instruction_address(sip); |
167 |
|
fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); |
168 |
< |
if (fault_instruction != SIGSEGV_INVALID_PC) |
168 |
> |
if (fault_instruction != SIGSEGV_INVALID_ADDRESS) |
169 |
|
fprintf(stderr, " [IP=%p]", fault_instruction); |
170 |
|
fprintf(stderr, "\n"); |
171 |
|
uaecptr nextpc; |
185 |
|
|
186 |
|
|
187 |
|
/* |
188 |
+ |
* Screen fault handler |
189 |
+ |
*/ |
190 |
+ |
|
191 |
+ |
bool Screen_fault_handler(sigsegv_info_t *sip) |
192 |
+ |
{ |
193 |
+ |
return true; |
194 |
+ |
} |
195 |
+ |
|
196 |
+ |
|
197 |
+ |
/* |
198 |
|
* Main program |
199 |
|
*/ |
200 |
|
|
254 |
|
// Init system routines |
255 |
|
SysInit(); |
256 |
|
|
257 |
+ |
// Set the current directory somewhere useful. |
258 |
+ |
// Handy for storing the ROM file |
259 |
+ |
bundle = strstr(argv[0], "BasiliskII.app/Contents/MacOS/BasiliskII"); |
260 |
+ |
if (bundle) |
261 |
+ |
{ |
262 |
+ |
while (*bundle != '/') |
263 |
+ |
++bundle; |
264 |
+ |
|
265 |
+ |
*bundle = 0; // Throw away Contents/... on end of argv[0] |
266 |
+ |
bundle = argv[0]; |
267 |
+ |
|
268 |
+ |
chdir(bundle); |
269 |
+ |
} |
270 |
+ |
|
271 |
|
// Open display, attach to window server, |
272 |
|
// load pre-instantiated classes from MainMenu.nib, start run loop |
273 |
|
int i = NSApplicationMain(argc, (const char **)argv); |
315 |
|
// Initialize VM system |
316 |
|
vm_init(); |
317 |
|
|
306 |
– |
#ifdef USE_33BIT_ADDRESSING |
307 |
– |
// Speculatively enables 33-bit addressing |
308 |
– |
ThirtyThreeBitAddressing = true; |
309 |
– |
#endif |
310 |
– |
|
318 |
|
#if REAL_ADDRESSING |
319 |
|
// Flag: RAM and ROM are contigously allocated from address 0 |
320 |
|
bool memory_mapped_from_zero = false; |
396 |
|
// Get rom file path from preferences |
397 |
|
const char *rom_path = PrefsFindString("rom"); |
398 |
|
if ( ! rom_path ) |
399 |
+ |
if ( bundle ) |
400 |
+ |
WarningAlert("No rom pathname set. Trying BasiliskII.app/ROM"); |
401 |
+ |
else |
402 |
|
WarningAlert("No rom pathname set. Trying ./ROM"); |
403 |
|
|
404 |
|
// Load Mac ROM |
507 |
|
void FlushCodeCache(void *start, uint32 size) |
508 |
|
{ |
509 |
|
#if USE_JIT |
510 |
< |
if (UseJIT) |
511 |
< |
flush_icache_range((uintptr)start, size); |
510 |
> |
if (UseJIT) |
511 |
> |
flush_icache_range((uint8 *)start, size); |
512 |
|
#endif |
513 |
|
} |
514 |
|
|