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-2002 Christian Bauer |
8 |
> |
* Basilisk II (C) 1997-2004 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 |
21 |
|
* along with this program; if not, write to the Free Software |
22 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
|
*/ |
24 |
< |
#define PTHREADS |
24 |
> |
#define PTHREADS // Why is this here? |
25 |
|
#include "sysdeps.h" |
26 |
|
|
27 |
|
#ifdef HAVE_PTHREADS |
32 |
|
# include <sys/mman.h> |
33 |
|
#endif |
34 |
|
|
35 |
+ |
#include <string> |
36 |
+ |
using std::string; |
37 |
+ |
|
38 |
|
#include "cpu_emulation.h" |
39 |
|
#include "macos_util_macosx.h" |
40 |
|
#include "main.h" |
41 |
|
#include "prefs.h" |
42 |
|
#include "prefs_editor.h" |
43 |
|
#include "rom_patches.h" |
44 |
+ |
#include "sigsegv.h" |
45 |
|
#include "sys.h" |
42 |
– |
#include "timer.h" |
46 |
|
#include "user_strings.h" |
47 |
|
#include "version.h" |
48 |
|
#include "video.h" |
49 |
|
#include "vm_alloc.h" |
50 |
|
#include "xpram.h" |
51 |
|
|
52 |
+ |
#if USE_JIT |
53 |
+ |
extern void (*flush_icache)(int); // from compemu_support.cpp |
54 |
+ |
#endif |
55 |
+ |
|
56 |
|
#ifdef ENABLE_MON |
57 |
|
# include "mon.h" |
58 |
|
#endif |
68 |
|
|
69 |
|
// Constants |
70 |
|
const char ROM_FILE_NAME[] = "ROM"; |
64 |
– |
const int SIG_STACK_SIZE = SIGSTKSZ; // Size of signal stack |
71 |
|
const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area |
72 |
|
|
73 |
|
|
97 |
|
uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes |
98 |
|
#endif |
99 |
|
|
94 |
– |
#if defined(HAVE_TIMER_CREATE) && defined(_POSIX_REALTIME_SIGNALS) |
95 |
– |
#define SIG_TIMER SIGRTMIN |
96 |
– |
static timer_t timer; // 60Hz timer |
97 |
– |
#endif |
98 |
– |
|
100 |
|
#ifdef ENABLE_MON |
101 |
|
static struct sigaction sigint_sa; // sigaction for SIGINT handler |
102 |
|
static void sigint_handler(...); |
107 |
|
#endif |
108 |
|
|
109 |
|
|
110 |
+ |
/* |
111 |
+ |
* SIGSEGV handler |
112 |
+ |
*/ |
113 |
+ |
|
114 |
+ |
static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, |
115 |
+ |
sigsegv_address_t fault_instruction) |
116 |
+ |
{ |
117 |
+ |
#if ENABLE_VOSF |
118 |
+ |
// Handle screen fault |
119 |
+ |
extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t); |
120 |
+ |
if (Screen_fault_handler(fault_address, fault_instruction)) |
121 |
+ |
return SIGSEGV_RETURN_SUCCESS; |
122 |
+ |
#endif |
123 |
+ |
|
124 |
+ |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
125 |
+ |
// Ignore writes to ROM |
126 |
+ |
if (((uintptr)fault_address - (uintptr)ROMBaseHost) < ROMSize) |
127 |
+ |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
128 |
+ |
|
129 |
+ |
// Ignore all other faults, if requested |
130 |
+ |
if (PrefsFindBool("ignoresegv")) |
131 |
+ |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
132 |
+ |
#endif |
133 |
+ |
|
134 |
+ |
return SIGSEGV_RETURN_FAILURE; |
135 |
+ |
} |
136 |
+ |
|
137 |
+ |
|
138 |
+ |
/* |
139 |
+ |
* Dump state when everything went wrong after a SEGV |
140 |
+ |
*/ |
141 |
+ |
|
142 |
+ |
static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
143 |
+ |
{ |
144 |
+ |
fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); |
145 |
+ |
if (fault_instruction != SIGSEGV_INVALID_PC) |
146 |
+ |
fprintf(stderr, " [IP=%p]", fault_instruction); |
147 |
+ |
fprintf(stderr, "\n"); |
148 |
+ |
uaecptr nextpc; |
149 |
+ |
extern void m68k_dumpstate(uaecptr *nextpc); |
150 |
+ |
m68k_dumpstate(&nextpc); |
151 |
+ |
#if USE_JIT && JIT_DEBUG |
152 |
+ |
extern void compiler_dumpstate(void); |
153 |
+ |
compiler_dumpstate(); |
154 |
+ |
#endif |
155 |
+ |
VideoQuitFullScreen(); |
156 |
+ |
#ifdef ENABLE_MON |
157 |
+ |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
158 |
+ |
mon(3, arg); |
159 |
+ |
QuitEmulator(); |
160 |
+ |
#endif |
161 |
+ |
} |
162 |
+ |
|
163 |
|
|
164 |
|
/* |
165 |
|
* Main program |
170 |
|
printf("Usage: %s [OPTION...]\n", prg_name); |
171 |
|
printf("\nUnix options:\n"); |
172 |
|
printf(" --help\n display this usage message\n"); |
173 |
+ |
printf(" --config FILE\n read/write configuration from/to FILE\n"); |
174 |
|
printf(" --break ADDRESS\n set ROM breakpoint\n"); |
175 |
|
printf(" --rominfo\n dump ROM information\n"); |
176 |
+ |
LoadPrefs(); // read the prefs file so PrefsPrintUsage() will print the correct default values |
177 |
|
PrefsPrintUsage(); |
178 |
|
exit(0); |
179 |
|
} |
190 |
|
printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR); |
191 |
|
printf(" %s\n", GetString(STR_ABOUT_TEXT2)); |
192 |
|
|
137 |
– |
// Read preferences |
138 |
– |
PrefsInit(argc, argv); |
139 |
– |
|
193 |
|
// Parse command line arguments |
194 |
|
for (int i=1; i<argc; i++) { |
195 |
|
if (strcmp(argv[i], "--help") == 0) { |
200 |
|
i++; |
201 |
|
if (i < argc) |
202 |
|
ROMBreakpoint = strtol(argv[i], NULL, 0); |
203 |
+ |
} else if (strcmp(argv[i], "--config") == 0) { |
204 |
+ |
argv[i++] = NULL; |
205 |
+ |
if (i < argc) { |
206 |
+ |
extern string UserPrefsPath; // from prefs_unix.cpp |
207 |
+ |
UserPrefsPath = argv[i]; |
208 |
+ |
argv[i] = NULL; |
209 |
+ |
} |
210 |
|
} else if (strcmp(argv[i], "--rominfo") == 0) { |
211 |
|
PrintROMInfo = true; |
212 |
|
} else if (argv[i][0] == '-') { |
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
+ |
// Read preferences |
219 |
+ |
PrefsInit(argc, argv); |
220 |
+ |
|
221 |
|
// Init system routines |
222 |
|
SysInit(); |
223 |
|
|
242 |
|
char str[256]; |
243 |
|
|
244 |
|
|
245 |
+ |
// Install the handler for SIGSEGV |
246 |
+ |
if (!sigsegv_install_handler(sigsegv_handler)) { |
247 |
+ |
sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGSEGV", strerror(errno)); |
248 |
+ |
ErrorAlert(str); |
249 |
+ |
QuitEmulator(); |
250 |
+ |
} |
251 |
+ |
|
252 |
+ |
// Register dump state function when we got mad after a segfault |
253 |
+ |
sigsegv_set_dump_state(sigsegv_dump_state); |
254 |
+ |
|
255 |
|
// Read RAM size |
256 |
|
RAMSize = PrefsFindInt32("ramsize") & 0xfff00000; // Round down to 1MB boundary |
257 |
|
if (RAMSize < 1024*1024) { |
272 |
|
|
273 |
|
// Under Solaris/SPARC and NetBSD/m68k, Basilisk II is known to crash |
274 |
|
// when trying to map a too big chunk of memory starting at address 0 |
275 |
< |
#if defined(OS_solaris) || defined(OS_netbsd) |
275 |
> |
#if defined(OS_solaris) || defined(OS_netbsd) || defined(PAGEZERO_HACK) |
276 |
|
const bool can_map_all_memory = false; |
277 |
|
#else |
278 |
|
const bool can_map_all_memory = true; |
283 |
|
D(bug("Could allocate RAM and ROM from 0x0000\n")); |
284 |
|
memory_mapped_from_zero = true; |
285 |
|
} |
286 |
< |
|
286 |
> |
|
287 |
> |
#ifndef PAGEZERO_HACK |
288 |
|
// Otherwise, just create the Low Memory area (0x0000..0x2000) |
289 |
|
else if (vm_acquire_fixed(0, 0x2000) == 0) { |
290 |
|
D(bug("Could allocate the Low Memory globals\n")); |
297 |
|
ErrorAlert(str); |
298 |
|
QuitEmulator(); |
299 |
|
} |
300 |
+ |
#endif |
301 |
|
#else |
302 |
|
*str = 0; // Eliminate unused variable warning |
303 |
< |
#endif |
303 |
> |
#endif /* REAL_ADDRESSING */ |
304 |
|
|
305 |
|
// Create areas for Mac RAM and ROM |
306 |
|
#if REAL_ADDRESSING |
458 |
|
|
459 |
|
void FlushCodeCache(void *start, uint32 size) |
460 |
|
{ |
461 |
+ |
#if USE_JIT |
462 |
+ |
if (UseJIT) |
463 |
+ |
flush_icache(-1); |
464 |
+ |
#endif |
465 |
|
} |
466 |
|
|
467 |
|
|
490 |
|
#ifdef HAVE_PTHREADS |
491 |
|
|
492 |
|
struct B2_mutex { |
493 |
< |
B2_mutex() { pthread_mutex_init(&m, NULL); } |
494 |
< |
~B2_mutex() { pthread_mutex_unlock(&m); pthread_mutex_destroy(&m); } |
493 |
> |
B2_mutex() { |
494 |
> |
pthread_mutexattr_t attr; |
495 |
> |
pthread_mutexattr_init(&attr); |
496 |
> |
// Initialize the mutex for priority inheritance -- |
497 |
> |
// required for accurate timing. |
498 |
> |
#ifdef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL |
499 |
> |
pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); |
500 |
> |
#endif |
501 |
> |
#if defined(HAVE_PTHREAD_MUTEXATTR_SETTYPE) && defined(PTHREAD_MUTEX_NORMAL) |
502 |
> |
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); |
503 |
> |
#endif |
504 |
> |
#ifdef HAVE_PTHREAD_MUTEXATTR_SETPSHARED |
505 |
> |
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE); |
506 |
> |
#endif |
507 |
> |
pthread_mutex_init(&m, &attr); |
508 |
> |
pthread_mutexattr_destroy(&attr); |
509 |
> |
} |
510 |
> |
~B2_mutex() { |
511 |
> |
pthread_mutex_trylock(&m); // Make sure it's locked before |
512 |
> |
pthread_mutex_unlock(&m); // unlocking it. |
513 |
> |
pthread_mutex_destroy(&m); |
514 |
> |
} |
515 |
|
pthread_mutex_t m; |
516 |
|
}; |
517 |
|
|
594 |
|
NSString *error = [NSString stringWithCString: text]; |
595 |
|
NSString *button = [NSString stringWithCString: GetString(STR_QUIT_BUTTON) ]; |
596 |
|
|
498 |
– |
// If we have a full screen mode, quit it here? |
499 |
– |
|
597 |
|
NSLog(error); |
598 |
+ |
if ( PrefsFindBool("nogui") ) |
599 |
+ |
return; |
600 |
+ |
VideoQuitFullScreen(); |
601 |
|
NSRunCriticalAlertPanel(title, error, button, nil, nil); |
602 |
|
} |
603 |
|
|
614 |
|
NSString *button = [NSString stringWithCString: GetString(STR_OK_BUTTON) ]; |
615 |
|
|
616 |
|
NSLog(warning); |
617 |
+ |
if ( PrefsFindBool("nogui") ) |
618 |
+ |
return; |
619 |
+ |
VideoQuitFullScreen(); |
620 |
|
NSRunAlertPanel(title, warning, button, nil, nil); |
621 |
|
} |
622 |
|
|
633 |
|
NSString *yes = [NSString stringWithCString: pos]; |
634 |
|
NSString *no = [NSString stringWithCString: neg]; |
635 |
|
|
533 |
– |
NSLog(warning); |
636 |
|
return NSRunInformationalAlertPanel(title, warning, yes, no, nil); |
637 |
|
} |