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 |
+ |
* Dump state when everything went wrong after a SEGV |
112 |
+ |
*/ |
113 |
+ |
|
114 |
+ |
static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
115 |
+ |
{ |
116 |
+ |
fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); |
117 |
+ |
if (fault_instruction != SIGSEGV_INVALID_PC) |
118 |
+ |
fprintf(stderr, " [IP=%p]", fault_instruction); |
119 |
+ |
fprintf(stderr, "\n"); |
120 |
+ |
uaecptr nextpc; |
121 |
+ |
extern void m68k_dumpstate(uaecptr *nextpc); |
122 |
+ |
m68k_dumpstate(&nextpc); |
123 |
+ |
#if USE_JIT && JIT_DEBUG |
124 |
+ |
extern void compiler_dumpstate(void); |
125 |
+ |
compiler_dumpstate(); |
126 |
+ |
#endif |
127 |
+ |
VideoQuitFullScreen(); |
128 |
+ |
#ifdef ENABLE_MON |
129 |
+ |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
130 |
+ |
mon(3, arg); |
131 |
+ |
QuitEmulator(); |
132 |
+ |
#endif |
133 |
+ |
} |
134 |
+ |
|
135 |
|
|
136 |
|
/* |
137 |
|
* Main program |
142 |
|
printf("Usage: %s [OPTION...]\n", prg_name); |
143 |
|
printf("\nUnix options:\n"); |
144 |
|
printf(" --help\n display this usage message\n"); |
145 |
+ |
printf(" --config FILE\n read/write configuration from/to FILE\n"); |
146 |
|
printf(" --break ADDRESS\n set ROM breakpoint\n"); |
147 |
|
printf(" --rominfo\n dump ROM information\n"); |
148 |
+ |
LoadPrefs(); // read the prefs file so PrefsPrintUsage() will print the correct default values |
149 |
|
PrefsPrintUsage(); |
150 |
|
exit(0); |
151 |
|
} |
175 |
|
i++; |
176 |
|
if (i < argc) |
177 |
|
ROMBreakpoint = strtol(argv[i], NULL, 0); |
178 |
+ |
} else if (strcmp(argv[i], "--config") == 0) { |
179 |
+ |
argv[i++] = NULL; |
180 |
+ |
if (i < argc) { |
181 |
+ |
extern string UserPrefsPath; // from prefs_unix.cpp |
182 |
+ |
UserPrefsPath = argv[i]; |
183 |
+ |
argv[i] = NULL; |
184 |
+ |
} |
185 |
|
} else if (strcmp(argv[i], "--rominfo") == 0) { |
186 |
|
PrintROMInfo = true; |
187 |
|
} else if (argv[i][0] == '-') { |
214 |
|
char str[256]; |
215 |
|
|
216 |
|
|
217 |
+ |
// Register request to ignore all segmentation faults |
218 |
+ |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
219 |
+ |
if (PrefsFindBool("ignoresegv")) |
220 |
+ |
sigsegv_set_ignore_state(0, ~(0UL), SIGSEGV_TRANSFER_LOAD | SIGSEGV_TRANSFER_STORE); |
221 |
+ |
#endif |
222 |
+ |
|
223 |
+ |
// Register dump state function when we got mad after a segfault |
224 |
+ |
sigsegv_set_dump_state(sigsegv_dump_state); |
225 |
+ |
|
226 |
|
// Read RAM size |
227 |
|
RAMSize = PrefsFindInt32("ramsize") & 0xfff00000; // Round down to 1MB boundary |
228 |
|
if (RAMSize < 1024*1024) { |
427 |
|
|
428 |
|
void FlushCodeCache(void *start, uint32 size) |
429 |
|
{ |
430 |
+ |
#if USE_JIT |
431 |
+ |
if (UseJIT) |
432 |
+ |
flush_icache(-1); |
433 |
+ |
#endif |
434 |
|
} |
435 |
|
|
436 |
|
|