--- BasiliskII/src/MacOSX/main_macosx.mm 2003/03/26 00:26:38 1.7 +++ BasiliskII/src/MacOSX/main_macosx.mm 2003/08/02 11:03:15 1.9 @@ -1,5 +1,5 @@ /* - * $Id: main_macosx.mm,v 1.7 2003/03/26 00:26:38 nigel Exp $ + * $Id: main_macosx.mm,v 1.9 2003/08/02 11:03:15 nigel Exp $ * * main_macosx.mm - Startup code for MacOS X * Based (in a small way) on the default main.m, @@ -32,20 +32,27 @@ # include #endif +#include +using std::string; + #include "cpu_emulation.h" #include "macos_util_macosx.h" #include "main.h" #include "prefs.h" #include "prefs_editor.h" #include "rom_patches.h" +#include "sigsegv.h" #include "sys.h" -#include "timer.h" #include "user_strings.h" #include "version.h" #include "video.h" #include "vm_alloc.h" #include "xpram.h" +#if USE_JIT +extern void (*flush_icache)(int); // from compemu_support.cpp +#endif + #ifdef ENABLE_MON # include "mon.h" #endif @@ -61,7 +68,6 @@ // Constants const char ROM_FILE_NAME[] = "ROM"; -const int SIG_STACK_SIZE = SIGSTKSZ; // Size of signal stack const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area @@ -91,11 +97,6 @@ static pthread_mutex_t intflag_lock = PT uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes #endif -#if defined(HAVE_TIMER_CREATE) && defined(_POSIX_REALTIME_SIGNALS) -#define SIG_TIMER SIGRTMIN -static timer_t timer; // 60Hz timer -#endif - #ifdef ENABLE_MON static struct sigaction sigint_sa; // sigaction for SIGINT handler static void sigint_handler(...); @@ -106,6 +107,31 @@ static bool lm_area_mapped = false; // F #endif +/* + * Dump state when everything went wrong after a SEGV + */ + +static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) +{ + fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); + if (fault_instruction != SIGSEGV_INVALID_PC) + fprintf(stderr, " [IP=%p]", fault_instruction); + fprintf(stderr, "\n"); + uaecptr nextpc; + extern void m68k_dumpstate(uaecptr *nextpc); + m68k_dumpstate(&nextpc); +#if USE_JIT && JIT_DEBUG + extern void compiler_dumpstate(void); + compiler_dumpstate(); +#endif + VideoQuitFullScreen(); +#ifdef ENABLE_MON + char *arg[4] = {"mon", "-m", "-r", NULL}; + mon(3, arg); + QuitEmulator(); +#endif +} + /* * Main program @@ -116,8 +142,10 @@ static void usage(const char *prg_name) printf("Usage: %s [OPTION...]\n", prg_name); printf("\nUnix options:\n"); printf(" --help\n display this usage message\n"); + printf(" --config FILE\n read/write configuration from/to FILE\n"); printf(" --break ADDRESS\n set ROM breakpoint\n"); printf(" --rominfo\n dump ROM information\n"); + LoadPrefs(); // read the prefs file so PrefsPrintUsage() will print the correct default values PrefsPrintUsage(); exit(0); } @@ -147,6 +175,13 @@ int main(int argc, char **argv) i++; if (i < argc) ROMBreakpoint = strtol(argv[i], NULL, 0); + } else if (strcmp(argv[i], "--config") == 0) { + argv[i++] = NULL; + if (i < argc) { + extern string UserPrefsPath; // from prefs_unix.cpp + UserPrefsPath = argv[i]; + argv[i] = NULL; + } } else if (strcmp(argv[i], "--rominfo") == 0) { PrintROMInfo = true; } else if (argv[i][0] == '-') { @@ -179,6 +214,15 @@ bool InitEmulator (void) char str[256]; + // Register request to ignore all segmentation faults +#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION + if (PrefsFindBool("ignoresegv")) + sigsegv_set_ignore_state(0, ~(0UL), SIGSEGV_TRANSFER_LOAD | SIGSEGV_TRANSFER_STORE); +#endif + + // Register dump state function when we got mad after a segfault + sigsegv_set_dump_state(sigsegv_dump_state); + // Read RAM size RAMSize = PrefsFindInt32("ramsize") & 0xfff00000; // Round down to 1MB boundary if (RAMSize < 1024*1024) { @@ -383,6 +427,10 @@ void QuitEmulator(void) void FlushCodeCache(void *start, uint32 size) { +#if USE_JIT + if (UseJIT) + flush_icache(-1); +#endif }