1 |
|
/* |
2 |
|
* main_unix.cpp - Startup code for Unix |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2004 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
22 |
|
|
23 |
|
#include <stdio.h> |
24 |
|
#include <stdlib.h> |
25 |
– |
#include <pthread.h> |
25 |
|
#include <signal.h> |
26 |
+ |
#include <errno.h> |
27 |
+ |
|
28 |
+ |
#ifdef USE_SDL |
29 |
+ |
# include <SDL.h> |
30 |
+ |
#endif |
31 |
+ |
|
32 |
+ |
#ifndef USE_SDL_VIDEO |
33 |
+ |
# include <X11/Xlib.h> |
34 |
+ |
#endif |
35 |
+ |
|
36 |
+ |
#ifdef HAVE_PTHREADS |
37 |
+ |
# include <pthread.h> |
38 |
+ |
#endif |
39 |
+ |
|
40 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
41 |
+ |
# include <sys/mman.h> |
42 |
+ |
#endif |
43 |
+ |
|
44 |
+ |
#if !EMULATED_68K && defined(__NetBSD__) |
45 |
+ |
# include <m68k/sync_icache.h> |
46 |
+ |
# include <m68k/frame.h> |
47 |
+ |
# include <sys/param.h> |
48 |
+ |
# include <sys/sysctl.h> |
49 |
+ |
struct sigstate { |
50 |
+ |
int ss_flags; |
51 |
+ |
struct frame ss_frame; |
52 |
+ |
struct fpframe ss_fpstate; |
53 |
+ |
}; |
54 |
+ |
# define SS_FPSTATE 0x02 |
55 |
+ |
# define SS_USERREGS 0x04 |
56 |
+ |
#endif |
57 |
+ |
|
58 |
+ |
#ifdef ENABLE_GTK |
59 |
+ |
# include <gtk/gtk.h> |
60 |
+ |
# include <gdk/gdk.h> |
61 |
+ |
# ifdef HAVE_GNOMEUI |
62 |
+ |
# include <gnome.h> |
63 |
+ |
# endif |
64 |
+ |
#endif |
65 |
+ |
|
66 |
+ |
#ifdef ENABLE_XF86_DGA |
67 |
+ |
# include <X11/Xutil.h> |
68 |
+ |
# include <X11/extensions/xf86dga.h> |
69 |
+ |
#endif |
70 |
+ |
|
71 |
+ |
#include <string> |
72 |
+ |
using std::string; |
73 |
|
|
74 |
|
#include "cpu_emulation.h" |
75 |
|
#include "sys.h" |
77 |
|
#include "xpram.h" |
78 |
|
#include "timer.h" |
79 |
|
#include "video.h" |
80 |
+ |
#include "emul_op.h" |
81 |
|
#include "prefs.h" |
82 |
|
#include "prefs_editor.h" |
83 |
|
#include "macos_util.h" |
84 |
|
#include "user_strings.h" |
85 |
|
#include "version.h" |
86 |
|
#include "main.h" |
87 |
+ |
#include "vm_alloc.h" |
88 |
+ |
#include "sigsegv.h" |
89 |
|
|
90 |
< |
#define DEBUG 0 |
91 |
< |
#include "debug.h" |
43 |
< |
|
44 |
< |
|
45 |
< |
#include <X11/Xlib.h> |
46 |
< |
|
47 |
< |
#if ENABLE_GTK |
48 |
< |
#include <gtk/gtk.h> |
90 |
> |
#if USE_JIT |
91 |
> |
extern void flush_icache_range(uint32 start, uint32 size); // from compemu_support.cpp |
92 |
|
#endif |
93 |
|
|
94 |
< |
#if ENABLE_XF86_DGA |
95 |
< |
#include <X11/Xlib.h> |
53 |
< |
#include <X11/Xutil.h> |
54 |
< |
#include <X11/extensions/xf86dga.h> |
94 |
> |
#ifdef ENABLE_MON |
95 |
> |
# include "mon.h" |
96 |
|
#endif |
97 |
|
|
98 |
< |
#if ENABLE_MON |
99 |
< |
#include "mon.h" |
59 |
< |
#endif |
60 |
< |
|
61 |
< |
#ifdef USE_MAPPED_MEMORY |
62 |
< |
#include <sys/mman.h> |
63 |
< |
extern char *address_space, *good_address_map; |
64 |
< |
#endif |
98 |
> |
#define DEBUG 0 |
99 |
> |
#include "debug.h" |
100 |
|
|
101 |
|
|
102 |
|
// Constants |
103 |
|
const char ROM_FILE_NAME[] = "ROM"; |
104 |
+ |
#if !EMULATED_68K |
105 |
+ |
const int SIG_STACK_SIZE = SIGSTKSZ; // Size of signal stack |
106 |
+ |
#endif |
107 |
+ |
const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area |
108 |
+ |
|
109 |
+ |
|
110 |
+ |
#if !EMULATED_68K |
111 |
+ |
// RAM and ROM pointers |
112 |
+ |
uint32 RAMBaseMac; // RAM base (Mac address space) |
113 |
+ |
uint8 *RAMBaseHost; // RAM base (host address space) |
114 |
+ |
uint32 RAMSize; // Size of RAM |
115 |
+ |
uint32 ROMBaseMac; // ROM base (Mac address space) |
116 |
+ |
uint8 *ROMBaseHost; // ROM base (host address space) |
117 |
+ |
uint32 ROMSize; // Size of ROM |
118 |
+ |
#endif |
119 |
|
|
120 |
|
|
121 |
|
// CPU and FPU type, addressing mode |
123 |
|
bool CPUIs68060; |
124 |
|
int FPUType; |
125 |
|
bool TwentyFourBitAddressing; |
126 |
+ |
bool ThirtyThreeBitAddressing = false; |
127 |
|
|
128 |
|
|
129 |
|
// Global variables |
130 |
< |
static char *x_display_name = NULL; // X11 display name |
131 |
< |
Display *x_display = NULL; // X11 display handle |
130 |
> |
#ifndef USE_SDL_VIDEO |
131 |
> |
extern char *x_display_name; // X11 display name |
132 |
> |
extern Display *x_display; // X11 display handle |
133 |
> |
#endif |
134 |
> |
|
135 |
> |
static uint8 last_xpram[XPRAM_SIZE]; // Buffer for monitoring XPRAM changes |
136 |
> |
|
137 |
> |
#ifdef HAVE_PTHREADS |
138 |
> |
#if !EMULATED_68K |
139 |
> |
static pthread_t emul_thread; // Handle of MacOS emulation thread (main thread) |
140 |
> |
#endif |
141 |
|
|
142 |
|
static bool xpram_thread_active = false; // Flag: XPRAM watchdog installed |
143 |
|
static volatile bool xpram_thread_cancel = false; // Flag: Cancel XPRAM thread |
149 |
|
static pthread_attr_t tick_thread_attr; // 60Hz thread attributes |
150 |
|
|
151 |
|
static pthread_mutex_t intflag_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect InterruptFlags |
152 |
+ |
#define LOCK_INTFLAGS pthread_mutex_lock(&intflag_lock) |
153 |
+ |
#define UNLOCK_INTFLAGS pthread_mutex_unlock(&intflag_lock) |
154 |
+ |
|
155 |
+ |
#else |
156 |
+ |
|
157 |
+ |
#define LOCK_INTFLAGS |
158 |
+ |
#define UNLOCK_INTFLAGS |
159 |
+ |
|
160 |
+ |
#endif |
161 |
+ |
|
162 |
+ |
#if !EMULATED_68K |
163 |
+ |
#define SIG_IRQ SIGUSR1 |
164 |
+ |
static struct sigaction sigirq_sa; // Virtual 68k interrupt signal |
165 |
+ |
static struct sigaction sigill_sa; // Illegal instruction |
166 |
+ |
static void *sig_stack = NULL; // Stack for signal handlers |
167 |
+ |
uint16 EmulatedSR; // Emulated bits of SR (supervisor bit and interrupt mask) |
168 |
+ |
#endif |
169 |
+ |
|
170 |
+ |
#if USE_SCRATCHMEM_SUBTERFUGE |
171 |
+ |
uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes |
172 |
+ |
#endif |
173 |
+ |
|
174 |
+ |
#if !defined(HAVE_PTHREADS) |
175 |
+ |
static struct sigaction timer_sa; // sigaction used for timer |
176 |
|
|
177 |
|
#if defined(HAVE_TIMER_CREATE) && defined(_POSIX_REALTIME_SIGNALS) |
178 |
|
#define SIG_TIMER SIGRTMIN |
179 |
< |
static struct sigaction timer_sa; // sigaction used for timer |
96 |
< |
static timer_t timer; // 60Hz timer |
179 |
> |
static timer_t timer; // 60Hz timer |
180 |
|
#endif |
181 |
+ |
#endif // !HAVE_PTHREADS |
182 |
|
|
183 |
< |
#if ENABLE_MON |
184 |
< |
static struct sigaction sigint_sa; // sigaction for SIGINT handler |
183 |
> |
#ifdef ENABLE_MON |
184 |
> |
static struct sigaction sigint_sa; // sigaction for SIGINT handler |
185 |
|
static void sigint_handler(...); |
186 |
|
#endif |
187 |
|
|
188 |
+ |
#if REAL_ADDRESSING |
189 |
+ |
static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped |
190 |
+ |
#endif |
191 |
+ |
|
192 |
|
|
193 |
|
// Prototypes |
194 |
|
static void *xpram_func(void *arg); |
195 |
|
static void *tick_func(void *arg); |
196 |
|
static void one_tick(...); |
197 |
+ |
#if !EMULATED_68K |
198 |
+ |
static void sigirq_handler(int sig, int code, struct sigcontext *scp); |
199 |
+ |
static void sigill_handler(int sig, int code, struct sigcontext *scp); |
200 |
+ |
extern "C" void EmulOpTrampoline(void); |
201 |
+ |
#endif |
202 |
|
|
203 |
|
|
204 |
|
/* |
220 |
|
|
221 |
|
|
222 |
|
/* |
223 |
+ |
* Map memory that can be accessed from the Mac side |
224 |
+ |
*/ |
225 |
+ |
|
226 |
+ |
void *vm_acquire_mac(size_t size) |
227 |
+ |
{ |
228 |
+ |
void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT); |
229 |
+ |
if (m == NULL) { |
230 |
+ |
ThirtyThreeBitAddressing = false; |
231 |
+ |
m = vm_acquire(size); |
232 |
+ |
} |
233 |
+ |
return m; |
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
|
237 |
+ |
/* |
238 |
+ |
* SIGSEGV handler |
239 |
+ |
*/ |
240 |
+ |
|
241 |
+ |
static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
242 |
+ |
{ |
243 |
+ |
#if ENABLE_VOSF |
244 |
+ |
// Handle screen fault |
245 |
+ |
extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t); |
246 |
+ |
if (Screen_fault_handler(fault_address, fault_instruction)) |
247 |
+ |
return SIGSEGV_RETURN_SUCCESS; |
248 |
+ |
#endif |
249 |
+ |
|
250 |
+ |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
251 |
+ |
// Ignore writes to ROM |
252 |
+ |
if (((uintptr)fault_address - (uintptr)ROMBaseHost) < ROMSize) |
253 |
+ |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
254 |
+ |
|
255 |
+ |
// Ignore all other faults, if requested |
256 |
+ |
if (PrefsFindBool("ignoresegv")) |
257 |
+ |
return SIGSEGV_RETURN_SKIP_INSTRUCTION; |
258 |
+ |
#endif |
259 |
+ |
|
260 |
+ |
return SIGSEGV_RETURN_FAILURE; |
261 |
+ |
} |
262 |
+ |
|
263 |
+ |
/* |
264 |
+ |
* Dump state when everything went wrong after a SEGV |
265 |
+ |
*/ |
266 |
+ |
|
267 |
+ |
static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
268 |
+ |
{ |
269 |
+ |
fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); |
270 |
+ |
if (fault_instruction != SIGSEGV_INVALID_PC) |
271 |
+ |
fprintf(stderr, " [IP=%p]", fault_instruction); |
272 |
+ |
fprintf(stderr, "\n"); |
273 |
+ |
#if EMULATED_68K |
274 |
+ |
uaecptr nextpc; |
275 |
+ |
extern void m68k_dumpstate(uaecptr *nextpc); |
276 |
+ |
m68k_dumpstate(&nextpc); |
277 |
+ |
#endif |
278 |
+ |
#if USE_JIT && JIT_DEBUG |
279 |
+ |
extern void compiler_dumpstate(void); |
280 |
+ |
compiler_dumpstate(); |
281 |
+ |
#endif |
282 |
+ |
VideoQuitFullScreen(); |
283 |
+ |
#ifdef ENABLE_MON |
284 |
+ |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
285 |
+ |
mon(3, arg); |
286 |
+ |
QuitEmulator(); |
287 |
+ |
#endif |
288 |
+ |
} |
289 |
+ |
|
290 |
+ |
|
291 |
+ |
/* |
292 |
|
* Main program |
293 |
|
*/ |
294 |
|
|
295 |
+ |
static void usage(const char *prg_name) |
296 |
+ |
{ |
297 |
+ |
printf( |
298 |
+ |
"Usage: %s [OPTION...]\n" |
299 |
+ |
"\nUnix options:\n" |
300 |
+ |
" --config FILE\n read/write configuration from/to FILE\n" |
301 |
+ |
" --display STRING\n X display to use\n" |
302 |
+ |
" --break ADDRESS\n set ROM breakpoint\n" |
303 |
+ |
" --rominfo\n dump ROM information\n", prg_name |
304 |
+ |
); |
305 |
+ |
LoadPrefs(); // read the prefs file so PrefsPrintUsage() will print the correct default values |
306 |
+ |
PrefsPrintUsage(); |
307 |
+ |
exit(0); |
308 |
+ |
} |
309 |
+ |
|
310 |
|
int main(int argc, char **argv) |
311 |
|
{ |
312 |
+ |
char str[256]; |
313 |
+ |
|
314 |
|
// Initialize variables |
315 |
|
RAMBaseHost = NULL; |
316 |
|
ROMBaseHost = NULL; |
321 |
|
printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR); |
322 |
|
printf(" %s\n", GetString(STR_ABOUT_TEXT2)); |
323 |
|
|
324 |
< |
// Parse arguments |
324 |
> |
// Parse command line arguments |
325 |
|
for (int i=1; i<argc; i++) { |
326 |
< |
if (strcmp(argv[i], "-display") == 0 && ++i < argc) |
327 |
< |
x_display_name = argv[i]; |
328 |
< |
else if (strcmp(argv[i], "-break") == 0 && ++i < argc) |
329 |
< |
ROMBreakpoint = strtol(argv[i], NULL, 0); |
330 |
< |
else if (strcmp(argv[i], "-rominfo") == 0) |
326 |
> |
if (strcmp(argv[i], "--help") == 0) { |
327 |
> |
usage(argv[0]); |
328 |
> |
#ifndef USE_SDL_VIDEO |
329 |
> |
} else if (strcmp(argv[i], "--display") == 0) { |
330 |
> |
i++; // don't remove the argument, gtk_init() needs it too |
331 |
> |
if (i < argc) |
332 |
> |
x_display_name = strdup(argv[i]); |
333 |
> |
#endif |
334 |
> |
} else if (strcmp(argv[i], "--break") == 0) { |
335 |
> |
argv[i++] = NULL; |
336 |
> |
if (i < argc) { |
337 |
> |
ROMBreakpoint = strtol(argv[i], NULL, 0); |
338 |
> |
argv[i] = NULL; |
339 |
> |
} |
340 |
> |
} else if (strcmp(argv[i], "--config") == 0) { |
341 |
> |
argv[i++] = NULL; |
342 |
> |
if (i < argc) { |
343 |
> |
extern string UserPrefsPath; // from prefs_unix.cpp |
344 |
> |
UserPrefsPath = argv[i]; |
345 |
> |
argv[i] = NULL; |
346 |
> |
} |
347 |
> |
} else if (strcmp(argv[i], "--rominfo") == 0) { |
348 |
> |
argv[i] = NULL; |
349 |
|
PrintROMInfo = true; |
350 |
+ |
} |
351 |
|
} |
352 |
|
|
353 |
+ |
// Remove processed arguments |
354 |
+ |
for (int i=1; i<argc; i++) { |
355 |
+ |
int k; |
356 |
+ |
for (k=i; k<argc; k++) |
357 |
+ |
if (argv[k] != NULL) |
358 |
+ |
break; |
359 |
+ |
if (k > i) { |
360 |
+ |
k -= i; |
361 |
+ |
for (int j=i+k; j<argc; j++) |
362 |
+ |
argv[j-k] = argv[j]; |
363 |
+ |
argc -= k; |
364 |
+ |
} |
365 |
+ |
} |
366 |
+ |
|
367 |
+ |
#ifdef ENABLE_GTK |
368 |
+ |
#ifdef HAVE_GNOMEUI |
369 |
+ |
// Init GNOME/GTK |
370 |
+ |
char version[16]; |
371 |
+ |
sprintf(version, "%d.%d", VERSION_MAJOR, VERSION_MINOR); |
372 |
+ |
gnome_init("Basilisk II", version, argc, argv); |
373 |
+ |
#else |
374 |
+ |
// Init GTK |
375 |
+ |
gtk_set_locale(); |
376 |
+ |
gtk_init(&argc, &argv); |
377 |
+ |
#endif |
378 |
+ |
#endif |
379 |
+ |
|
380 |
+ |
// Read preferences |
381 |
+ |
PrefsInit(argc, argv); |
382 |
+ |
|
383 |
+ |
// Any command line arguments left? |
384 |
+ |
for (int i=1; i<argc; i++) { |
385 |
+ |
if (argv[i][0] == '-') { |
386 |
+ |
fprintf(stderr, "Unrecognized option '%s'\n", argv[i]); |
387 |
+ |
usage(argv[0]); |
388 |
+ |
} |
389 |
+ |
} |
390 |
+ |
|
391 |
+ |
#ifndef USE_SDL_VIDEO |
392 |
|
// Open display |
393 |
|
x_display = XOpenDisplay(x_display_name); |
394 |
|
if (x_display == NULL) { |
398 |
|
QuitEmulator(); |
399 |
|
} |
400 |
|
|
401 |
< |
#if ENABLE_XF86_DGA && !ENABLE_MON |
401 |
> |
#if defined(ENABLE_XF86_DGA) && !defined(ENABLE_MON) |
402 |
|
// Fork out, so we can return from fullscreen mode when things get ugly |
403 |
|
XF86DGAForkApp(DefaultScreen(x_display)); |
404 |
|
#endif |
168 |
– |
|
169 |
– |
#if ENABLE_GTK |
170 |
– |
// Init GTK |
171 |
– |
gtk_set_locale(); |
172 |
– |
gtk_init(&argc, &argv); |
405 |
|
#endif |
406 |
|
|
407 |
< |
// Read preferences |
408 |
< |
PrefsInit(); |
407 |
> |
#ifdef USE_SDL |
408 |
> |
// Initialize SDL system |
409 |
> |
int sdl_flags = 0; |
410 |
> |
#ifdef USE_SDL_VIDEO |
411 |
> |
sdl_flags |= SDL_INIT_VIDEO; |
412 |
> |
#endif |
413 |
> |
#ifdef USE_SDL_AUDIO |
414 |
> |
sdl_flags |= SDL_INIT_AUDIO; |
415 |
> |
#endif |
416 |
> |
assert(sdl_flags != 0); |
417 |
> |
if (SDL_Init(sdl_flags) == -1) { |
418 |
> |
char str[256]; |
419 |
> |
sprintf(str, "Could not initialize SDL: %s.\n", SDL_GetError()); |
420 |
> |
ErrorAlert(str); |
421 |
> |
QuitEmulator(); |
422 |
> |
} |
423 |
> |
atexit(SDL_Quit); |
424 |
> |
#endif |
425 |
|
|
426 |
|
// Init system routines |
427 |
|
SysInit(); |
431 |
|
if (!PrefsEditor()) |
432 |
|
QuitEmulator(); |
433 |
|
|
434 |
+ |
// Install the handler for SIGSEGV |
435 |
+ |
if (!sigsegv_install_handler(sigsegv_handler)) { |
436 |
+ |
sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGSEGV", strerror(errno)); |
437 |
+ |
ErrorAlert(str); |
438 |
+ |
QuitEmulator(); |
439 |
+ |
} |
440 |
+ |
|
441 |
+ |
// Register dump state function when we got mad after a segfault |
442 |
+ |
sigsegv_set_dump_state(sigsegv_dump_state); |
443 |
+ |
|
444 |
|
// Read RAM size |
445 |
|
RAMSize = PrefsFindInt32("ramsize") & 0xfff00000; // Round down to 1MB boundary |
446 |
|
if (RAMSize < 1024*1024) { |
448 |
|
RAMSize = 1024*1024; |
449 |
|
} |
450 |
|
|
451 |
< |
// Create areas for Mac RAM and ROM |
452 |
< |
#ifdef USE_MAPPED_MEMORY |
453 |
< |
int fd = open("/dev/zero", O_RDWR); |
454 |
< |
good_address_map = (char *)mmap(NULL, 1<<24, PROT_READ, MAP_PRIVATE, fd, 0); |
455 |
< |
address_space = (char *)mmap(NULL, 1<<24, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); |
456 |
< |
if ((int)address_space < 0 || (int)good_address_map < 0) { |
457 |
< |
ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); |
458 |
< |
QuitEmulator(); |
459 |
< |
} |
460 |
< |
RAMBaseHost = (uint8 *)mmap(address_space, RAMSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, 0); |
461 |
< |
ROMBaseHost = (uint8 *)mmap(address_space + 0x00400000, 0x80000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, 0); |
462 |
< |
close(fd); |
463 |
< |
char *nam = tmpnam(NULL); |
464 |
< |
int good_address_fd = open(nam, O_CREAT | O_RDWR, 0600); |
465 |
< |
char buffer[4096]; |
208 |
< |
memset(buffer, 1, sizeof(buffer)); |
209 |
< |
write(good_address_fd, buffer, sizeof(buffer)); |
210 |
< |
unlink(nam); |
211 |
< |
for (int i=0; i<RAMSize; i+=4096) |
212 |
< |
mmap(good_address_map + i, 4096, PROT_READ, MAP_FIXED | MAP_PRIVATE, good_address_fd, 0); |
213 |
< |
for (int i=0; i<0x80000; i+=4096) |
214 |
< |
mmap(good_address_map + i + 0x00400000, 4096, PROT_READ, MAP_FIXED | MAP_PRIVATE, good_address_fd, 0); |
451 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
452 |
> |
RAMSize = RAMSize & -getpagesize(); // Round down to page boundary |
453 |
> |
#endif |
454 |
> |
|
455 |
> |
// Initialize VM system |
456 |
> |
vm_init(); |
457 |
> |
|
458 |
> |
#if REAL_ADDRESSING |
459 |
> |
// Flag: RAM and ROM are contigously allocated from address 0 |
460 |
> |
bool memory_mapped_from_zero = false; |
461 |
> |
|
462 |
> |
// Under Solaris/SPARC and NetBSD/m68k, Basilisk II is known to crash |
463 |
> |
// when trying to map a too big chunk of memory starting at address 0 |
464 |
> |
#if defined(OS_solaris) || defined(OS_netbsd) || defined(PAGEZERO_HACK) |
465 |
> |
const bool can_map_all_memory = false; |
466 |
|
#else |
467 |
< |
RAMBaseHost = new uint8[RAMSize]; |
468 |
< |
ROMBaseHost = new uint8[0x100000]; |
467 |
> |
const bool can_map_all_memory = true; |
468 |
> |
#endif |
469 |
> |
|
470 |
> |
// Try to allocate all memory from 0x0000, if it is not known to crash |
471 |
> |
if (can_map_all_memory && (vm_acquire_fixed(0, RAMSize + 0x100000) == 0)) { |
472 |
> |
D(bug("Could allocate RAM and ROM from 0x0000\n")); |
473 |
> |
memory_mapped_from_zero = true; |
474 |
> |
} |
475 |
> |
|
476 |
> |
#ifndef PAGEZERO_HACK |
477 |
> |
// Otherwise, just create the Low Memory area (0x0000..0x2000) |
478 |
> |
else if (vm_acquire_fixed(0, 0x2000) == 0) { |
479 |
> |
D(bug("Could allocate the Low Memory globals\n")); |
480 |
> |
lm_area_mapped = true; |
481 |
> |
} |
482 |
> |
|
483 |
> |
// Exit on failure |
484 |
> |
else { |
485 |
> |
sprintf(str, GetString(STR_LOW_MEM_MMAP_ERR), strerror(errno)); |
486 |
> |
ErrorAlert(str); |
487 |
> |
QuitEmulator(); |
488 |
> |
} |
489 |
> |
#endif |
490 |
> |
#endif /* REAL_ADDRESSING */ |
491 |
> |
|
492 |
> |
// Create areas for Mac RAM and ROM |
493 |
> |
#if REAL_ADDRESSING |
494 |
> |
if (memory_mapped_from_zero) { |
495 |
> |
RAMBaseHost = (uint8 *)0; |
496 |
> |
ROMBaseHost = RAMBaseHost + RAMSize; |
497 |
> |
} |
498 |
> |
else |
499 |
> |
#endif |
500 |
> |
{ |
501 |
> |
#ifdef USE_33BIT_ADDRESSING |
502 |
> |
// Speculatively enables 33-bit addressing |
503 |
> |
ThirtyThreeBitAddressing = true; |
504 |
> |
#endif |
505 |
> |
RAMBaseHost = (uint8 *)vm_acquire_mac(RAMSize); |
506 |
> |
ROMBaseHost = (uint8 *)vm_acquire_mac(0x100000); |
507 |
> |
if (RAMBaseHost == VM_MAP_FAILED || ROMBaseHost == VM_MAP_FAILED) { |
508 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
509 |
> |
QuitEmulator(); |
510 |
> |
} |
511 |
> |
} |
512 |
> |
|
513 |
> |
#if USE_SCRATCHMEM_SUBTERFUGE |
514 |
> |
// Allocate scratch memory |
515 |
> |
ScratchMem = (uint8 *)vm_acquire(SCRATCH_MEM_SIZE); |
516 |
> |
if (ScratchMem == VM_MAP_FAILED) { |
517 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
518 |
> |
QuitEmulator(); |
519 |
> |
} |
520 |
> |
ScratchMem += SCRATCH_MEM_SIZE/2; // ScratchMem points to middle of block |
521 |
|
#endif |
522 |
|
|
523 |
+ |
#if DIRECT_ADDRESSING |
524 |
+ |
// RAMBaseMac shall always be zero |
525 |
+ |
MEMBaseDiff = (uintptr)RAMBaseHost; |
526 |
+ |
RAMBaseMac = 0; |
527 |
+ |
ROMBaseMac = Host2MacAddr(ROMBaseHost); |
528 |
+ |
#endif |
529 |
+ |
#if REAL_ADDRESSING |
530 |
+ |
RAMBaseMac = (uint32)RAMBaseHost; |
531 |
+ |
ROMBaseMac = (uint32)ROMBaseHost; |
532 |
+ |
#endif |
533 |
+ |
D(bug("Mac RAM starts at %p (%08x)\n", RAMBaseHost, RAMBaseMac)); |
534 |
+ |
D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac)); |
535 |
+ |
|
536 |
|
// Get rom file path from preferences |
537 |
|
const char *rom_path = PrefsFindString("rom"); |
538 |
|
|
539 |
|
// Load Mac ROM |
540 |
|
int rom_fd = open(rom_path ? rom_path : ROM_FILE_NAME, O_RDONLY); |
541 |
|
if (rom_fd < 0) { |
542 |
< |
ErrorAlert(GetString(STR_NO_ROM_FILE_ERR)); |
542 |
> |
ErrorAlert(STR_NO_ROM_FILE_ERR); |
543 |
|
QuitEmulator(); |
544 |
|
} |
545 |
|
printf(GetString(STR_READING_ROM_FILE)); |
546 |
|
ROMSize = lseek(rom_fd, 0, SEEK_END); |
547 |
|
if (ROMSize != 64*1024 && ROMSize != 128*1024 && ROMSize != 256*1024 && ROMSize != 512*1024 && ROMSize != 1024*1024) { |
548 |
< |
ErrorAlert(GetString(STR_ROM_SIZE_ERR)); |
548 |
> |
ErrorAlert(STR_ROM_SIZE_ERR); |
549 |
|
close(rom_fd); |
550 |
|
QuitEmulator(); |
551 |
|
} |
552 |
|
lseek(rom_fd, 0, SEEK_SET); |
553 |
|
if (read(rom_fd, ROMBaseHost, ROMSize) != (ssize_t)ROMSize) { |
554 |
< |
ErrorAlert(GetString(STR_ROM_FILE_READ_ERR)); |
554 |
> |
ErrorAlert(STR_ROM_FILE_READ_ERR); |
555 |
|
close(rom_fd); |
556 |
|
QuitEmulator(); |
557 |
|
} |
558 |
|
|
559 |
+ |
#if !EMULATED_68K |
560 |
+ |
// Get CPU model |
561 |
+ |
int mib[2] = {CTL_HW, HW_MODEL}; |
562 |
+ |
char *model; |
563 |
+ |
size_t model_len; |
564 |
+ |
sysctl(mib, 2, NULL, &model_len, NULL, 0); |
565 |
+ |
model = (char *)malloc(model_len); |
566 |
+ |
sysctl(mib, 2, model, &model_len, NULL, 0); |
567 |
+ |
D(bug("Model: %s\n", model)); |
568 |
+ |
|
569 |
+ |
// Set CPU and FPU type |
570 |
+ |
CPUIs68060 = false; |
571 |
+ |
if (strstr(model, "020")) |
572 |
+ |
CPUType = 2; |
573 |
+ |
else if (strstr(model, "030")) |
574 |
+ |
CPUType = 3; |
575 |
+ |
else if (strstr(model, "040")) |
576 |
+ |
CPUType = 4; |
577 |
+ |
else if (strstr(model, "060")) { |
578 |
+ |
CPUType = 4; |
579 |
+ |
CPUIs68060 = true; |
580 |
+ |
} else { |
581 |
+ |
printf("WARNING: Cannot detect CPU type, assuming 68020\n"); |
582 |
+ |
CPUType = 2; |
583 |
+ |
} |
584 |
+ |
FPUType = 1; // NetBSD has an FPU emulation, so the FPU ought to be available at all times |
585 |
+ |
TwentyFourBitAddressing = false; |
586 |
+ |
#endif |
587 |
+ |
|
588 |
|
// Initialize everything |
589 |
|
if (!InitAll()) |
590 |
|
QuitEmulator(); |
591 |
+ |
D(bug("Initialization complete\n")); |
592 |
|
|
593 |
< |
// Start XPRAM watchdog thread |
594 |
< |
xpram_thread_active = (pthread_create(&xpram_thread, NULL, xpram_func, NULL) == 0); |
593 |
> |
#if !EMULATED_68K |
594 |
> |
// (Virtual) supervisor mode, disable interrupts |
595 |
> |
EmulatedSR = 0x2700; |
596 |
> |
|
597 |
> |
#ifdef HAVE_PTHREADS |
598 |
> |
// Get handle of main thread |
599 |
> |
emul_thread = pthread_self(); |
600 |
> |
#endif |
601 |
> |
|
602 |
> |
// Create and install stack for signal handlers |
603 |
> |
sig_stack = malloc(SIG_STACK_SIZE); |
604 |
> |
D(bug("Signal stack at %p\n", sig_stack)); |
605 |
> |
if (sig_stack == NULL) { |
606 |
> |
ErrorAlert(STR_NOT_ENOUGH_MEMORY_ERR); |
607 |
> |
QuitEmulator(); |
608 |
> |
} |
609 |
> |
stack_t new_stack; |
610 |
> |
new_stack.ss_sp = sig_stack; |
611 |
> |
new_stack.ss_flags = 0; |
612 |
> |
new_stack.ss_size = SIG_STACK_SIZE; |
613 |
> |
if (sigaltstack(&new_stack, NULL) < 0) { |
614 |
> |
sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno)); |
615 |
> |
ErrorAlert(str); |
616 |
> |
QuitEmulator(); |
617 |
> |
} |
618 |
|
|
619 |
< |
#if defined(HAVE_TIMER_CREATE) && defined(_POSIX_REALTIME_SIGNALS) |
620 |
< |
// Start 60Hz timer |
619 |
> |
// Install SIGILL handler for emulating privileged instructions and |
620 |
> |
// executing A-Trap and EMUL_OP opcodes |
621 |
> |
sigemptyset(&sigill_sa.sa_mask); // Block virtual 68k interrupts during SIGILL handling |
622 |
> |
sigaddset(&sigill_sa.sa_mask, SIG_IRQ); |
623 |
> |
sigaddset(&sigill_sa.sa_mask, SIGALRM); |
624 |
> |
sigill_sa.sa_handler = (void (*)(int))sigill_handler; |
625 |
> |
sigill_sa.sa_flags = SA_ONSTACK; |
626 |
> |
if (sigaction(SIGILL, &sigill_sa, NULL) < 0) { |
627 |
> |
sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGILL", strerror(errno)); |
628 |
> |
ErrorAlert(str); |
629 |
> |
QuitEmulator(); |
630 |
> |
} |
631 |
> |
|
632 |
> |
// Install virtual 68k interrupt signal handler |
633 |
> |
sigemptyset(&sigirq_sa.sa_mask); |
634 |
> |
sigaddset(&sigirq_sa.sa_mask, SIGALRM); |
635 |
> |
sigirq_sa.sa_handler = (void (*)(int))sigirq_handler; |
636 |
> |
sigirq_sa.sa_flags = SA_ONSTACK | SA_RESTART; |
637 |
> |
if (sigaction(SIG_IRQ, &sigirq_sa, NULL) < 0) { |
638 |
> |
sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIG_IRQ", strerror(errno)); |
639 |
> |
ErrorAlert(str); |
640 |
> |
QuitEmulator(); |
641 |
> |
} |
642 |
> |
#endif |
643 |
> |
|
644 |
> |
#ifdef ENABLE_MON |
645 |
> |
// Setup SIGINT handler to enter mon |
646 |
> |
sigemptyset(&sigint_sa.sa_mask); |
647 |
> |
sigint_sa.sa_handler = (void (*)(int))sigint_handler; |
648 |
> |
sigint_sa.sa_flags = 0; |
649 |
> |
sigaction(SIGINT, &sigint_sa, NULL); |
650 |
> |
#endif |
651 |
> |
|
652 |
> |
#if defined(HAVE_PTHREADS) |
653 |
> |
|
654 |
> |
// POSIX threads available, start 60Hz thread |
655 |
> |
Set_pthread_attr(&tick_thread_attr, 0); |
656 |
> |
tick_thread_active = (pthread_create(&tick_thread, &tick_thread_attr, tick_func, NULL) == 0); |
657 |
> |
if (!tick_thread_active) { |
658 |
> |
sprintf(str, GetString(STR_TICK_THREAD_ERR), strerror(errno)); |
659 |
> |
ErrorAlert(str); |
660 |
> |
QuitEmulator(); |
661 |
> |
} |
662 |
> |
D(bug("60Hz thread started\n")); |
663 |
> |
|
664 |
> |
#elif defined(HAVE_TIMER_CREATE) && defined(_POSIX_REALTIME_SIGNALS) |
665 |
> |
|
666 |
> |
// POSIX.4 timers and real-time signals available, start 60Hz timer |
667 |
|
sigemptyset(&timer_sa.sa_mask); |
668 |
+ |
timer_sa.sa_sigaction = (void (*)(int, siginfo_t *, void *))one_tick; |
669 |
|
timer_sa.sa_flags = SA_SIGINFO | SA_RESTART; |
254 |
– |
timer_sa.sa_sigaction = one_tick; |
670 |
|
if (sigaction(SIG_TIMER, &timer_sa, NULL) < 0) { |
671 |
< |
printf("FATAL: cannot set up timer signal handler\n"); |
671 |
> |
sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIG_TIMER", strerror(errno)); |
672 |
> |
ErrorAlert(str); |
673 |
|
QuitEmulator(); |
674 |
|
} |
675 |
|
struct sigevent timer_event; |
676 |
|
timer_event.sigev_notify = SIGEV_SIGNAL; |
677 |
|
timer_event.sigev_signo = SIG_TIMER; |
678 |
|
if (timer_create(CLOCK_REALTIME, &timer_event, &timer) < 0) { |
679 |
< |
printf("FATAL: cannot create timer\n"); |
679 |
> |
sprintf(str, GetString(STR_TIMER_CREATE_ERR), strerror(errno)); |
680 |
> |
ErrorAlert(str); |
681 |
|
QuitEmulator(); |
682 |
|
} |
683 |
|
struct itimerspec req; |
686 |
|
req.it_interval.tv_sec = 0; |
687 |
|
req.it_interval.tv_nsec = 16625000; |
688 |
|
if (timer_settime(timer, 0, &req, NULL) < 0) { |
689 |
< |
printf("FATAL: cannot start timer\n"); |
689 |
> |
sprintf(str, GetString(STR_TIMER_SETTIME_ERR), strerror(errno)); |
690 |
> |
ErrorAlert(str); |
691 |
|
QuitEmulator(); |
692 |
|
} |
693 |
+ |
D(bug("60Hz timer started\n")); |
694 |
|
|
695 |
|
#else |
696 |
|
|
697 |
< |
// Start 60Hz thread |
698 |
< |
pthread_attr_init(&tick_thread_attr); |
699 |
< |
#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
700 |
< |
if (geteuid() == 0) { |
701 |
< |
pthread_attr_setinheritsched(&tick_thread_attr, PTHREAD_EXPLICIT_SCHED); |
702 |
< |
pthread_attr_setschedpolicy(&tick_thread_attr, SCHED_FIFO); |
703 |
< |
struct sched_param fifo_param; |
704 |
< |
fifo_param.sched_priority = (sched_get_priority_min(SCHED_FIFO) + sched_get_priority_max(SCHED_FIFO)) / 2; |
705 |
< |
pthread_attr_setschedparam(&tick_thread_attr, &fifo_param); |
706 |
< |
} |
288 |
< |
#endif |
289 |
< |
tick_thread_active = (pthread_create(&tick_thread, &tick_thread_attr, tick_func, NULL) == 0); |
290 |
< |
if (!tick_thread_active) { |
291 |
< |
printf("FATAL: cannot create tick thread\n"); |
697 |
> |
// Start 60Hz timer |
698 |
> |
sigemptyset(&timer_sa.sa_mask); // Block virtual 68k interrupts during SIGARLM handling |
699 |
> |
#if !EMULATED_68K |
700 |
> |
sigaddset(&timer_sa.sa_mask, SIG_IRQ); |
701 |
> |
#endif |
702 |
> |
timer_sa.sa_handler = one_tick; |
703 |
> |
timer_sa.sa_flags = SA_ONSTACK | SA_RESTART; |
704 |
> |
if (sigaction(SIGALRM, &timer_sa, NULL) < 0) { |
705 |
> |
sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGALRM", strerror(errno)); |
706 |
> |
ErrorAlert(str); |
707 |
|
QuitEmulator(); |
708 |
|
} |
709 |
+ |
struct itimerval req; |
710 |
+ |
req.it_interval.tv_sec = req.it_value.tv_sec = 0; |
711 |
+ |
req.it_interval.tv_usec = req.it_value.tv_usec = 16625; |
712 |
+ |
setitimer(ITIMER_REAL, &req, NULL); |
713 |
+ |
|
714 |
|
#endif |
715 |
|
|
716 |
< |
#if ENABLE_MON |
717 |
< |
// Setup SIGINT handler to enter mon |
718 |
< |
sigemptyset(&sigint_sa.sa_mask); |
719 |
< |
sigint_sa.sa_flags = 0; |
720 |
< |
sigint_sa.sa_handler = sigint_handler; |
301 |
< |
sigaction(SIGINT, &sigint_sa, NULL); |
716 |
> |
#ifdef HAVE_PTHREADS |
717 |
> |
// Start XPRAM watchdog thread |
718 |
> |
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
719 |
> |
xpram_thread_active = (pthread_create(&xpram_thread, NULL, xpram_func, NULL) == 0); |
720 |
> |
D(bug("XPRAM thread started\n")); |
721 |
|
#endif |
722 |
|
|
723 |
|
// Start 68k and jump to ROM boot routine |
724 |
+ |
D(bug("Starting emulation...\n")); |
725 |
|
Start680x0(); |
726 |
|
|
727 |
|
QuitEmulator(); |
735 |
|
|
736 |
|
void QuitEmulator(void) |
737 |
|
{ |
738 |
+ |
D(bug("QuitEmulator\n")); |
739 |
+ |
|
740 |
+ |
#if EMULATED_68K |
741 |
|
// Exit 680x0 emulation |
742 |
|
Exit680x0(); |
743 |
+ |
#endif |
744 |
|
|
745 |
< |
#if defined(HAVE_TIMER_CREATE) && defined(_POSIX_REALTIME_SIGNALS) |
322 |
< |
// Stop 60Hz timer |
323 |
< |
timer_delete(timer); |
324 |
< |
#else |
745 |
> |
#if defined(HAVE_PTHREADS) |
746 |
|
// Stop 60Hz thread |
747 |
|
if (tick_thread_active) { |
748 |
|
tick_thread_cancel = true; |
751 |
|
#endif |
752 |
|
pthread_join(tick_thread, NULL); |
753 |
|
} |
754 |
+ |
#elif defined(HAVE_TIMER_CREATE) && defined(_POSIX_REALTIME_SIGNALS) |
755 |
+ |
// Stop 60Hz timer |
756 |
+ |
timer_delete(timer); |
757 |
+ |
#else |
758 |
+ |
struct itimerval req; |
759 |
+ |
req.it_interval.tv_sec = req.it_value.tv_sec = 0; |
760 |
+ |
req.it_interval.tv_usec = req.it_value.tv_usec = 0; |
761 |
+ |
setitimer(ITIMER_REAL, &req, NULL); |
762 |
|
#endif |
763 |
|
|
764 |
+ |
#ifdef HAVE_PTHREADS |
765 |
|
// Stop XPRAM watchdog thread |
766 |
|
if (xpram_thread_active) { |
767 |
|
xpram_thread_cancel = true; |
770 |
|
#endif |
771 |
|
pthread_join(xpram_thread, NULL); |
772 |
|
} |
773 |
+ |
#endif |
774 |
|
|
775 |
|
// Deinitialize everything |
776 |
|
ExitAll(); |
777 |
|
|
778 |
< |
// Delete ROM area |
779 |
< |
delete[] ROMBaseHost; |
778 |
> |
// Free ROM/RAM areas |
779 |
> |
if (RAMBaseHost != VM_MAP_FAILED) { |
780 |
> |
vm_release(RAMBaseHost, RAMSize); |
781 |
> |
RAMBaseHost = NULL; |
782 |
> |
} |
783 |
> |
if (ROMBaseHost != VM_MAP_FAILED) { |
784 |
> |
vm_release(ROMBaseHost, 0x100000); |
785 |
> |
ROMBaseHost = NULL; |
786 |
> |
} |
787 |
|
|
788 |
< |
// Delete RAM area |
789 |
< |
delete[] RAMBaseHost; |
788 |
> |
#if USE_SCRATCHMEM_SUBTERFUGE |
789 |
> |
// Delete scratch memory area |
790 |
> |
if (ScratchMem != (uint8 *)VM_MAP_FAILED) { |
791 |
> |
vm_release((void *)(ScratchMem - SCRATCH_MEM_SIZE/2), SCRATCH_MEM_SIZE); |
792 |
> |
ScratchMem = NULL; |
793 |
> |
} |
794 |
> |
#endif |
795 |
> |
|
796 |
> |
#if REAL_ADDRESSING |
797 |
> |
// Delete Low Memory area |
798 |
> |
if (lm_area_mapped) |
799 |
> |
vm_release(0, 0x2000); |
800 |
> |
#endif |
801 |
> |
|
802 |
> |
// Exit VM wrappers |
803 |
> |
vm_exit(); |
804 |
|
|
805 |
|
// Exit system routines |
806 |
|
SysExit(); |
809 |
|
PrefsExit(); |
810 |
|
|
811 |
|
// Close X11 server connection |
812 |
+ |
#ifndef USE_SDL_VIDEO |
813 |
|
if (x_display) |
814 |
|
XCloseDisplay(x_display); |
815 |
+ |
#endif |
816 |
|
|
817 |
|
exit(0); |
818 |
|
} |
823 |
|
* or a dynamically recompiling emulator) |
824 |
|
*/ |
825 |
|
|
372 |
– |
#if EMULATED_68K |
826 |
|
void FlushCodeCache(void *start, uint32 size) |
827 |
|
{ |
828 |
< |
} |
828 |
> |
#if USE_JIT |
829 |
> |
if (UseJIT) |
830 |
> |
flush_icache_range((uintptr)start, size); |
831 |
> |
#endif |
832 |
> |
#if !EMULATED_68K && defined(__NetBSD__) |
833 |
> |
m68k_sync_icache(start, size); |
834 |
|
#endif |
835 |
+ |
} |
836 |
|
|
837 |
|
|
838 |
|
/* |
839 |
|
* SIGINT handler, enters mon |
840 |
|
*/ |
841 |
|
|
842 |
< |
#if ENABLE_MON |
384 |
< |
extern void m68k_dumpstate(uaecptr *nextpc); |
842 |
> |
#ifdef ENABLE_MON |
843 |
|
static void sigint_handler(...) |
844 |
|
{ |
845 |
+ |
#if EMULATED_68K |
846 |
|
uaecptr nextpc; |
847 |
+ |
extern void m68k_dumpstate(uaecptr *nextpc); |
848 |
|
m68k_dumpstate(&nextpc); |
849 |
< |
char *arg[2] = {"rmon", NULL}; |
850 |
< |
mon(1, arg); |
849 |
> |
#endif |
850 |
> |
VideoQuitFullScreen(); |
851 |
> |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
852 |
> |
mon(3, arg); |
853 |
|
QuitEmulator(); |
854 |
|
} |
855 |
|
#endif |
856 |
|
|
857 |
|
|
858 |
+ |
#ifdef HAVE_PTHREADS |
859 |
+ |
/* |
860 |
+ |
* Pthread configuration |
861 |
+ |
*/ |
862 |
+ |
|
863 |
+ |
void Set_pthread_attr(pthread_attr_t *attr, int priority) |
864 |
+ |
{ |
865 |
+ |
pthread_attr_init(attr); |
866 |
+ |
#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
867 |
+ |
// Some of these only work for superuser |
868 |
+ |
if (geteuid() == 0) { |
869 |
+ |
pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED); |
870 |
+ |
pthread_attr_setschedpolicy(attr, SCHED_FIFO); |
871 |
+ |
struct sched_param fifo_param; |
872 |
+ |
fifo_param.sched_priority = ((sched_get_priority_min(SCHED_FIFO) + |
873 |
+ |
sched_get_priority_max(SCHED_FIFO)) / 2 + |
874 |
+ |
priority); |
875 |
+ |
pthread_attr_setschedparam(attr, &fifo_param); |
876 |
+ |
} |
877 |
+ |
if (pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0) { |
878 |
+ |
#ifdef PTHREAD_SCOPE_BOUND_NP |
879 |
+ |
// If system scope is not available (eg. we're not running |
880 |
+ |
// with CAP_SCHED_MGT capability on an SGI box), try bound |
881 |
+ |
// scope. It exposes pthread scheduling to the kernel, |
882 |
+ |
// without setting realtime priority. |
883 |
+ |
pthread_attr_setscope(attr, PTHREAD_SCOPE_BOUND_NP); |
884 |
+ |
#endif |
885 |
+ |
} |
886 |
+ |
#endif |
887 |
+ |
} |
888 |
+ |
#endif // HAVE_PTHREADS |
889 |
+ |
|
890 |
+ |
|
891 |
+ |
/* |
892 |
+ |
* Mutexes |
893 |
+ |
*/ |
894 |
+ |
|
895 |
+ |
#ifdef HAVE_PTHREADS |
896 |
+ |
|
897 |
+ |
struct B2_mutex { |
898 |
+ |
B2_mutex() { |
899 |
+ |
pthread_mutexattr_t attr; |
900 |
+ |
pthread_mutexattr_init(&attr); |
901 |
+ |
// Initialize the mutex for priority inheritance -- |
902 |
+ |
// required for accurate timing. |
903 |
+ |
#ifdef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL |
904 |
+ |
pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); |
905 |
+ |
#endif |
906 |
+ |
#if defined(HAVE_PTHREAD_MUTEXATTR_SETTYPE) && defined(PTHREAD_MUTEX_NORMAL) |
907 |
+ |
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); |
908 |
+ |
#endif |
909 |
+ |
#ifdef HAVE_PTHREAD_MUTEXATTR_SETPSHARED |
910 |
+ |
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE); |
911 |
+ |
#endif |
912 |
+ |
pthread_mutex_init(&m, &attr); |
913 |
+ |
pthread_mutexattr_destroy(&attr); |
914 |
+ |
} |
915 |
+ |
~B2_mutex() { |
916 |
+ |
pthread_mutex_trylock(&m); // Make sure it's locked before |
917 |
+ |
pthread_mutex_unlock(&m); // unlocking it. |
918 |
+ |
pthread_mutex_destroy(&m); |
919 |
+ |
} |
920 |
+ |
pthread_mutex_t m; |
921 |
+ |
}; |
922 |
+ |
|
923 |
+ |
B2_mutex *B2_create_mutex(void) |
924 |
+ |
{ |
925 |
+ |
return new B2_mutex; |
926 |
+ |
} |
927 |
+ |
|
928 |
+ |
void B2_lock_mutex(B2_mutex *mutex) |
929 |
+ |
{ |
930 |
+ |
pthread_mutex_lock(&mutex->m); |
931 |
+ |
} |
932 |
+ |
|
933 |
+ |
void B2_unlock_mutex(B2_mutex *mutex) |
934 |
+ |
{ |
935 |
+ |
pthread_mutex_unlock(&mutex->m); |
936 |
+ |
} |
937 |
+ |
|
938 |
+ |
void B2_delete_mutex(B2_mutex *mutex) |
939 |
+ |
{ |
940 |
+ |
delete mutex; |
941 |
+ |
} |
942 |
+ |
|
943 |
+ |
#else |
944 |
+ |
|
945 |
+ |
struct B2_mutex { |
946 |
+ |
int dummy; |
947 |
+ |
}; |
948 |
+ |
|
949 |
+ |
B2_mutex *B2_create_mutex(void) |
950 |
+ |
{ |
951 |
+ |
return new B2_mutex; |
952 |
+ |
} |
953 |
+ |
|
954 |
+ |
void B2_lock_mutex(B2_mutex *mutex) |
955 |
+ |
{ |
956 |
+ |
} |
957 |
+ |
|
958 |
+ |
void B2_unlock_mutex(B2_mutex *mutex) |
959 |
+ |
{ |
960 |
+ |
} |
961 |
+ |
|
962 |
+ |
void B2_delete_mutex(B2_mutex *mutex) |
963 |
+ |
{ |
964 |
+ |
delete mutex; |
965 |
+ |
} |
966 |
+ |
|
967 |
+ |
#endif |
968 |
+ |
|
969 |
+ |
|
970 |
|
/* |
971 |
|
* Interrupt flags (must be handled atomically!) |
972 |
|
*/ |
973 |
|
|
974 |
|
uint32 InterruptFlags = 0; |
975 |
|
|
976 |
+ |
#if EMULATED_68K |
977 |
|
void SetInterruptFlag(uint32 flag) |
978 |
|
{ |
979 |
< |
pthread_mutex_lock(&intflag_lock); |
979 |
> |
LOCK_INTFLAGS; |
980 |
|
InterruptFlags |= flag; |
981 |
< |
pthread_mutex_unlock(&intflag_lock); |
981 |
> |
UNLOCK_INTFLAGS; |
982 |
|
} |
983 |
|
|
984 |
|
void ClearInterruptFlag(uint32 flag) |
985 |
|
{ |
986 |
< |
pthread_mutex_lock(&intflag_lock); |
986 |
> |
LOCK_INTFLAGS; |
987 |
|
InterruptFlags &= ~flag; |
988 |
< |
pthread_mutex_unlock(&intflag_lock); |
988 |
> |
UNLOCK_INTFLAGS; |
989 |
> |
} |
990 |
> |
#endif |
991 |
> |
|
992 |
> |
#if !EMULATED_68K |
993 |
> |
void TriggerInterrupt(void) |
994 |
> |
{ |
995 |
> |
#if defined(HAVE_PTHREADS) |
996 |
> |
pthread_kill(emul_thread, SIG_IRQ); |
997 |
> |
#else |
998 |
> |
raise(SIG_IRQ); |
999 |
> |
#endif |
1000 |
> |
} |
1001 |
> |
|
1002 |
> |
void TriggerNMI(void) |
1003 |
> |
{ |
1004 |
> |
// not yet supported |
1005 |
> |
} |
1006 |
> |
#endif |
1007 |
> |
|
1008 |
> |
|
1009 |
> |
/* |
1010 |
> |
* XPRAM watchdog thread (saves XPRAM every minute) |
1011 |
> |
*/ |
1012 |
> |
|
1013 |
> |
static void xpram_watchdog(void) |
1014 |
> |
{ |
1015 |
> |
if (memcmp(last_xpram, XPRAM, XPRAM_SIZE)) { |
1016 |
> |
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
1017 |
> |
SaveXPRAM(); |
1018 |
> |
} |
1019 |
|
} |
1020 |
|
|
1021 |
+ |
#ifdef HAVE_PTHREADS |
1022 |
+ |
static void *xpram_func(void *arg) |
1023 |
+ |
{ |
1024 |
+ |
while (!xpram_thread_cancel) { |
1025 |
+ |
for (int i=0; i<60 && !xpram_thread_cancel; i++) |
1026 |
+ |
Delay_usec(999999); // Only wait 1 second so we quit promptly when xpram_thread_cancel becomes true |
1027 |
+ |
xpram_watchdog(); |
1028 |
+ |
} |
1029 |
+ |
return NULL; |
1030 |
+ |
} |
1031 |
+ |
#endif |
1032 |
+ |
|
1033 |
|
|
1034 |
|
/* |
1035 |
|
* 60Hz thread (really 60.15Hz) |
1036 |
|
*/ |
1037 |
|
|
1038 |
+ |
static void one_second(void) |
1039 |
+ |
{ |
1040 |
+ |
// Pseudo Mac 1Hz interrupt, update local time |
1041 |
+ |
WriteMacInt32(0x20c, TimerDateTime()); |
1042 |
+ |
|
1043 |
+ |
SetInterruptFlag(INTFLAG_1HZ); |
1044 |
+ |
TriggerInterrupt(); |
1045 |
+ |
|
1046 |
+ |
#ifndef HAVE_PTHREADS |
1047 |
+ |
static int second_counter = 0; |
1048 |
+ |
if (++second_counter > 60) { |
1049 |
+ |
second_counter = 0; |
1050 |
+ |
xpram_watchdog(); |
1051 |
+ |
} |
1052 |
+ |
#endif |
1053 |
+ |
} |
1054 |
+ |
|
1055 |
|
static void one_tick(...) |
1056 |
|
{ |
1057 |
|
static int tick_counter = 0; |
424 |
– |
|
425 |
– |
// Pseudo Mac 1Hz interrupt, update local time |
1058 |
|
if (++tick_counter > 60) { |
1059 |
|
tick_counter = 0; |
1060 |
< |
WriteMacInt32(0x20c, TimerDateTime()); |
1060 |
> |
one_second(); |
1061 |
|
} |
1062 |
|
|
1063 |
+ |
#if !defined(HAVE_PTHREADS) && !defined(USE_SDL_VIDEO) |
1064 |
+ |
// No threads available, perform video refresh and networking from here |
1065 |
+ |
VideoRefresh(); |
1066 |
+ |
SetInterruptFlag(INTFLAG_ETHER); |
1067 |
+ |
#endif |
1068 |
+ |
|
1069 |
|
// Trigger 60Hz interrupt |
1070 |
|
if (ROMVersion != ROM_VERSION_CLASSIC || HasMacStarted()) { |
1071 |
|
SetInterruptFlag(INTFLAG_60HZ); |
1073 |
|
} |
1074 |
|
} |
1075 |
|
|
1076 |
+ |
#ifdef HAVE_PTHREADS |
1077 |
|
static void *tick_func(void *arg) |
1078 |
|
{ |
1079 |
+ |
uint64 start = GetTicks_usec(); |
1080 |
+ |
int64 ticks = 0; |
1081 |
+ |
uint64 next = GetTicks_usec(); |
1082 |
|
while (!tick_thread_cancel) { |
441 |
– |
|
442 |
– |
// Wait |
443 |
– |
#ifdef HAVE_NANOSLEEP |
444 |
– |
struct timespec req = {0, 16625000}; |
445 |
– |
nanosleep(&req, NULL); |
446 |
– |
#else |
447 |
– |
usleep(16625); |
448 |
– |
#endif |
449 |
– |
|
450 |
– |
// Action |
1083 |
|
one_tick(); |
1084 |
+ |
next += 16625; |
1085 |
+ |
int64 delay = next - GetTicks_usec(); |
1086 |
+ |
if (delay > 0) |
1087 |
+ |
Delay_usec(delay); |
1088 |
+ |
else if (delay < -16625) |
1089 |
+ |
next = GetTicks_usec(); |
1090 |
+ |
ticks++; |
1091 |
|
} |
1092 |
+ |
uint64 end = GetTicks_usec(); |
1093 |
+ |
D(bug("%Ld ticks in %Ld usec = %f ticks/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1094 |
|
return NULL; |
1095 |
|
} |
1096 |
+ |
#endif |
1097 |
|
|
1098 |
|
|
1099 |
+ |
#if !EMULATED_68K |
1100 |
|
/* |
1101 |
< |
* XPRAM watchdog thread (saves XPRAM every minute) |
1101 |
> |
* Virtual 68k interrupt handler |
1102 |
|
*/ |
1103 |
|
|
1104 |
< |
void *xpram_func(void *arg) |
1104 |
> |
static void sigirq_handler(int sig, int code, struct sigcontext *scp) |
1105 |
|
{ |
1106 |
< |
uint8 last_xpram[256]; |
1107 |
< |
memcpy(last_xpram, XPRAM, 256); |
1106 |
> |
// Interrupts disabled? Then do nothing |
1107 |
> |
if (EmulatedSR & 0x0700) |
1108 |
> |
return; |
1109 |
|
|
1110 |
< |
while (!xpram_thread_cancel) { |
1111 |
< |
for (int i=0; i<60 && !xpram_thread_cancel; i++) { |
1112 |
< |
#ifdef HAVE_NANOSLEEP |
1113 |
< |
struct timespec req = {1, 0}; |
1114 |
< |
nanosleep(&req, NULL); |
1115 |
< |
#else |
1116 |
< |
usleep(1000000); |
1117 |
< |
#endif |
1110 |
> |
struct sigstate *state = (struct sigstate *)scp->sc_ap; |
1111 |
> |
M68kRegisters *regs = (M68kRegisters *)&state->ss_frame; |
1112 |
> |
|
1113 |
> |
// Set up interrupt frame on stack |
1114 |
> |
uint32 a7 = regs->a[7]; |
1115 |
> |
a7 -= 2; |
1116 |
> |
WriteMacInt16(a7, 0x64); |
1117 |
> |
a7 -= 4; |
1118 |
> |
WriteMacInt32(a7, scp->sc_pc); |
1119 |
> |
a7 -= 2; |
1120 |
> |
WriteMacInt16(a7, scp->sc_ps | EmulatedSR); |
1121 |
> |
scp->sc_sp = regs->a[7] = a7; |
1122 |
> |
|
1123 |
> |
// Set interrupt level |
1124 |
> |
EmulatedSR |= 0x2100; |
1125 |
> |
|
1126 |
> |
// Jump to MacOS interrupt handler on return |
1127 |
> |
scp->sc_pc = ReadMacInt32(0x64); |
1128 |
> |
} |
1129 |
> |
|
1130 |
> |
|
1131 |
> |
/* |
1132 |
> |
* SIGILL handler, for emulation of privileged instructions and executing |
1133 |
> |
* A-Trap and EMUL_OP opcodes |
1134 |
> |
*/ |
1135 |
> |
|
1136 |
> |
static void sigill_handler(int sig, int code, struct sigcontext *scp) |
1137 |
> |
{ |
1138 |
> |
struct sigstate *state = (struct sigstate *)scp->sc_ap; |
1139 |
> |
uint16 *pc = (uint16 *)scp->sc_pc; |
1140 |
> |
uint16 opcode = *pc; |
1141 |
> |
M68kRegisters *regs = (M68kRegisters *)&state->ss_frame; |
1142 |
> |
|
1143 |
> |
#define INC_PC(n) scp->sc_pc += (n) |
1144 |
> |
|
1145 |
> |
#define GET_SR (scp->sc_ps | EmulatedSR) |
1146 |
> |
|
1147 |
> |
#define STORE_SR(v) \ |
1148 |
> |
scp->sc_ps = (v) & 0xff; \ |
1149 |
> |
EmulatedSR = (v) & 0xe700; \ |
1150 |
> |
if (((v) & 0x0700) == 0 && InterruptFlags) \ |
1151 |
> |
TriggerInterrupt(); |
1152 |
> |
|
1153 |
> |
//printf("opcode %04x at %p, sr %04x, emul_sr %04x\n", opcode, pc, scp->sc_ps, EmulatedSR); |
1154 |
> |
|
1155 |
> |
if ((opcode & 0xf000) == 0xa000) { |
1156 |
> |
|
1157 |
> |
// A-Line instruction, set up A-Line trap frame on stack |
1158 |
> |
uint32 a7 = regs->a[7]; |
1159 |
> |
a7 -= 2; |
1160 |
> |
WriteMacInt16(a7, 0x28); |
1161 |
> |
a7 -= 4; |
1162 |
> |
WriteMacInt32(a7, (uint32)pc); |
1163 |
> |
a7 -= 2; |
1164 |
> |
WriteMacInt16(a7, GET_SR); |
1165 |
> |
scp->sc_sp = regs->a[7] = a7; |
1166 |
> |
|
1167 |
> |
// Jump to MacOS A-Line handler on return |
1168 |
> |
scp->sc_pc = ReadMacInt32(0x28); |
1169 |
> |
|
1170 |
> |
} else if ((opcode & 0xff00) == 0x7100) { |
1171 |
> |
|
1172 |
> |
// Extended opcode, push registers on user stack |
1173 |
> |
uint32 a7 = regs->a[7]; |
1174 |
> |
a7 -= 4; |
1175 |
> |
WriteMacInt32(a7, (uint32)pc); |
1176 |
> |
a7 -= 2; |
1177 |
> |
WriteMacInt16(a7, scp->sc_ps); |
1178 |
> |
for (int i=7; i>=0; i--) { |
1179 |
> |
a7 -= 4; |
1180 |
> |
WriteMacInt32(a7, regs->a[i]); |
1181 |
> |
} |
1182 |
> |
for (int i=7; i>=0; i--) { |
1183 |
> |
a7 -= 4; |
1184 |
> |
WriteMacInt32(a7, regs->d[i]); |
1185 |
> |
} |
1186 |
> |
scp->sc_sp = regs->a[7] = a7; |
1187 |
> |
|
1188 |
> |
// Jump to EmulOp trampoline code on return |
1189 |
> |
scp->sc_pc = (uint32)EmulOpTrampoline; |
1190 |
> |
|
1191 |
> |
} else switch (opcode) { // Emulate privileged instructions |
1192 |
> |
|
1193 |
> |
case 0x40e7: // move sr,-(sp) |
1194 |
> |
regs->a[7] -= 2; |
1195 |
> |
WriteMacInt16(regs->a[7], GET_SR); |
1196 |
> |
scp->sc_sp = regs->a[7]; |
1197 |
> |
INC_PC(2); |
1198 |
> |
break; |
1199 |
> |
|
1200 |
> |
case 0x46df: { // move (sp)+,sr |
1201 |
> |
uint16 sr = ReadMacInt16(regs->a[7]); |
1202 |
> |
STORE_SR(sr); |
1203 |
> |
regs->a[7] += 2; |
1204 |
> |
scp->sc_sp = regs->a[7]; |
1205 |
> |
INC_PC(2); |
1206 |
> |
break; |
1207 |
> |
} |
1208 |
> |
|
1209 |
> |
case 0x007c: { // ori #xxxx,sr |
1210 |
> |
uint16 sr = GET_SR | pc[1]; |
1211 |
> |
scp->sc_ps = sr & 0xff; // oring bits into the sr can't enable interrupts, so we don't need to call STORE_SR |
1212 |
> |
EmulatedSR = sr & 0xe700; |
1213 |
> |
INC_PC(4); |
1214 |
> |
break; |
1215 |
> |
} |
1216 |
> |
|
1217 |
> |
case 0x027c: { // andi #xxxx,sr |
1218 |
> |
uint16 sr = GET_SR & pc[1]; |
1219 |
> |
STORE_SR(sr); |
1220 |
> |
INC_PC(4); |
1221 |
> |
break; |
1222 |
> |
} |
1223 |
> |
|
1224 |
> |
case 0x46fc: // move #xxxx,sr |
1225 |
> |
STORE_SR(pc[1]); |
1226 |
> |
INC_PC(4); |
1227 |
> |
break; |
1228 |
> |
|
1229 |
> |
case 0x46ef: { // move (xxxx,sp),sr |
1230 |
> |
uint16 sr = ReadMacInt16(regs->a[7] + (int32)(int16)pc[1]); |
1231 |
> |
STORE_SR(sr); |
1232 |
> |
INC_PC(4); |
1233 |
> |
break; |
1234 |
> |
} |
1235 |
> |
|
1236 |
> |
case 0x46d8: // move (a0)+,sr |
1237 |
> |
case 0x46d9: { // move (a1)+,sr |
1238 |
> |
uint16 sr = ReadMacInt16(regs->a[opcode & 7]); |
1239 |
> |
STORE_SR(sr); |
1240 |
> |
regs->a[opcode & 7] += 2; |
1241 |
> |
INC_PC(2); |
1242 |
> |
break; |
1243 |
|
} |
1244 |
< |
if (memcmp(last_xpram, XPRAM, 256)) { |
1245 |
< |
memcpy(last_xpram, XPRAM, 256); |
1246 |
< |
SaveXPRAM(); |
1244 |
> |
|
1245 |
> |
case 0x40f8: // move sr,xxxx.w |
1246 |
> |
WriteMacInt16(pc[1], GET_SR); |
1247 |
> |
INC_PC(4); |
1248 |
> |
break; |
1249 |
> |
|
1250 |
> |
case 0x40d0: // move sr,(a0) |
1251 |
> |
case 0x40d1: // move sr,(a1) |
1252 |
> |
case 0x40d2: // move sr,(a2) |
1253 |
> |
case 0x40d3: // move sr,(a3) |
1254 |
> |
case 0x40d4: // move sr,(a4) |
1255 |
> |
case 0x40d5: // move sr,(a5) |
1256 |
> |
case 0x40d6: // move sr,(a6) |
1257 |
> |
case 0x40d7: // move sr,(sp) |
1258 |
> |
WriteMacInt16(regs->a[opcode & 7], GET_SR); |
1259 |
> |
INC_PC(2); |
1260 |
> |
break; |
1261 |
> |
|
1262 |
> |
case 0x40c0: // move sr,d0 |
1263 |
> |
case 0x40c1: // move sr,d1 |
1264 |
> |
case 0x40c2: // move sr,d2 |
1265 |
> |
case 0x40c3: // move sr,d3 |
1266 |
> |
case 0x40c4: // move sr,d4 |
1267 |
> |
case 0x40c5: // move sr,d5 |
1268 |
> |
case 0x40c6: // move sr,d6 |
1269 |
> |
case 0x40c7: // move sr,d7 |
1270 |
> |
regs->d[opcode & 7] = GET_SR; |
1271 |
> |
INC_PC(2); |
1272 |
> |
break; |
1273 |
> |
|
1274 |
> |
case 0x46c0: // move d0,sr |
1275 |
> |
case 0x46c1: // move d1,sr |
1276 |
> |
case 0x46c2: // move d2,sr |
1277 |
> |
case 0x46c3: // move d3,sr |
1278 |
> |
case 0x46c4: // move d4,sr |
1279 |
> |
case 0x46c5: // move d5,sr |
1280 |
> |
case 0x46c6: // move d6,sr |
1281 |
> |
case 0x46c7: { // move d7,sr |
1282 |
> |
uint16 sr = regs->d[opcode & 7]; |
1283 |
> |
STORE_SR(sr); |
1284 |
> |
INC_PC(2); |
1285 |
> |
break; |
1286 |
> |
} |
1287 |
> |
|
1288 |
> |
case 0xf327: // fsave -(sp) |
1289 |
> |
regs->a[7] -= 4; |
1290 |
> |
WriteMacInt32(regs->a[7], 0x41000000); // Idle frame |
1291 |
> |
scp->sc_sp = regs->a[7]; |
1292 |
> |
INC_PC(2); |
1293 |
> |
break; |
1294 |
> |
|
1295 |
> |
case 0xf35f: // frestore (sp)+ |
1296 |
> |
regs->a[7] += 4; |
1297 |
> |
scp->sc_sp = regs->a[7]; |
1298 |
> |
INC_PC(2); |
1299 |
> |
break; |
1300 |
> |
|
1301 |
> |
case 0x4e73: { // rte |
1302 |
> |
uint32 a7 = regs->a[7]; |
1303 |
> |
uint16 sr = ReadMacInt16(a7); |
1304 |
> |
a7 += 2; |
1305 |
> |
scp->sc_ps = sr & 0xff; |
1306 |
> |
EmulatedSR = sr & 0xe700; |
1307 |
> |
scp->sc_pc = ReadMacInt32(a7); |
1308 |
> |
a7 += 4; |
1309 |
> |
uint16 format = ReadMacInt16(a7) >> 12; |
1310 |
> |
a7 += 2; |
1311 |
> |
static const int frame_adj[16] = { |
1312 |
> |
0, 0, 4, 4, 8, 0, 0, 52, 50, 12, 24, 84, 16, 0, 0, 0 |
1313 |
> |
}; |
1314 |
> |
scp->sc_sp = regs->a[7] = a7 + frame_adj[format]; |
1315 |
> |
break; |
1316 |
|
} |
1317 |
+ |
|
1318 |
+ |
case 0x4e7a: // movec cr,x |
1319 |
+ |
switch (pc[1]) { |
1320 |
+ |
case 0x0002: // movec cacr,d0 |
1321 |
+ |
regs->d[0] = 0x3111; |
1322 |
+ |
break; |
1323 |
+ |
case 0x1002: // movec cacr,d1 |
1324 |
+ |
regs->d[1] = 0x3111; |
1325 |
+ |
break; |
1326 |
+ |
case 0x0003: // movec tc,d0 |
1327 |
+ |
case 0x0004: // movec itt0,d0 |
1328 |
+ |
case 0x0005: // movec itt1,d0 |
1329 |
+ |
case 0x0006: // movec dtt0,d0 |
1330 |
+ |
case 0x0007: // movec dtt1,d0 |
1331 |
+ |
case 0x0806: // movec urp,d0 |
1332 |
+ |
case 0x0807: // movec srp,d0 |
1333 |
+ |
regs->d[0] = 0; |
1334 |
+ |
break; |
1335 |
+ |
case 0x1000: // movec sfc,d1 |
1336 |
+ |
case 0x1001: // movec dfc,d1 |
1337 |
+ |
case 0x1003: // movec tc,d1 |
1338 |
+ |
case 0x1801: // movec vbr,d1 |
1339 |
+ |
regs->d[1] = 0; |
1340 |
+ |
break; |
1341 |
+ |
case 0x8801: // movec vbr,a0 |
1342 |
+ |
regs->a[0] = 0; |
1343 |
+ |
break; |
1344 |
+ |
case 0x9801: // movec vbr,a1 |
1345 |
+ |
regs->a[1] = 0; |
1346 |
+ |
break; |
1347 |
+ |
default: |
1348 |
+ |
goto ill; |
1349 |
+ |
} |
1350 |
+ |
INC_PC(4); |
1351 |
+ |
break; |
1352 |
+ |
|
1353 |
+ |
case 0x4e7b: // movec x,cr |
1354 |
+ |
switch (pc[1]) { |
1355 |
+ |
case 0x1000: // movec d1,sfc |
1356 |
+ |
case 0x1001: // movec d1,dfc |
1357 |
+ |
case 0x0801: // movec d0,vbr |
1358 |
+ |
case 0x1801: // movec d1,vbr |
1359 |
+ |
break; |
1360 |
+ |
case 0x0002: // movec d0,cacr |
1361 |
+ |
case 0x1002: // movec d1,cacr |
1362 |
+ |
FlushCodeCache(NULL, 0); |
1363 |
+ |
break; |
1364 |
+ |
default: |
1365 |
+ |
goto ill; |
1366 |
+ |
} |
1367 |
+ |
INC_PC(4); |
1368 |
+ |
break; |
1369 |
+ |
|
1370 |
+ |
case 0xf478: // cpusha dc |
1371 |
+ |
case 0xf4f8: // cpusha dc/ic |
1372 |
+ |
FlushCodeCache(NULL, 0); |
1373 |
+ |
INC_PC(2); |
1374 |
+ |
break; |
1375 |
+ |
|
1376 |
+ |
default: |
1377 |
+ |
ill: printf("SIGILL num %d, code %d\n", sig, code); |
1378 |
+ |
printf(" context %p:\n", scp); |
1379 |
+ |
printf(" onstack %08x\n", scp->sc_onstack); |
1380 |
+ |
printf(" sp %08x\n", scp->sc_sp); |
1381 |
+ |
printf(" fp %08x\n", scp->sc_fp); |
1382 |
+ |
printf(" pc %08x\n", scp->sc_pc); |
1383 |
+ |
printf(" opcode %04x\n", opcode); |
1384 |
+ |
printf(" sr %08x\n", scp->sc_ps); |
1385 |
+ |
printf(" state %p:\n", state); |
1386 |
+ |
printf(" flags %d\n", state->ss_flags); |
1387 |
+ |
for (int i=0; i<8; i++) |
1388 |
+ |
printf(" d%d %08x\n", i, state->ss_frame.f_regs[i]); |
1389 |
+ |
for (int i=0; i<8; i++) |
1390 |
+ |
printf(" a%d %08x\n", i, state->ss_frame.f_regs[i+8]); |
1391 |
+ |
|
1392 |
+ |
VideoQuitFullScreen(); |
1393 |
+ |
#ifdef ENABLE_MON |
1394 |
+ |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
1395 |
+ |
mon(3, arg); |
1396 |
+ |
#endif |
1397 |
+ |
QuitEmulator(); |
1398 |
+ |
break; |
1399 |
|
} |
480 |
– |
return NULL; |
1400 |
|
} |
1401 |
+ |
#endif |
1402 |
|
|
1403 |
|
|
1404 |
|
/* |
1405 |
|
* Display alert |
1406 |
|
*/ |
1407 |
|
|
1408 |
< |
#if ENABLE_GTK |
1408 |
> |
#ifdef ENABLE_GTK |
1409 |
|
static void dl_destroyed(void) |
1410 |
|
{ |
1411 |
|
gtk_main_quit(); |
1450 |
|
|
1451 |
|
void ErrorAlert(const char *text) |
1452 |
|
{ |
1453 |
< |
#if ENABLE_GTK |
1453 |
> |
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) |
1454 |
|
if (PrefsFindBool("nogui") || x_display == NULL) { |
1455 |
|
printf(GetString(STR_SHELL_ERROR_PREFIX), text); |
1456 |
|
return; |
1469 |
|
|
1470 |
|
void WarningAlert(const char *text) |
1471 |
|
{ |
1472 |
< |
#if ENABLE_GTK |
1472 |
> |
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) |
1473 |
|
if (PrefsFindBool("nogui") || x_display == NULL) { |
1474 |
|
printf(GetString(STR_SHELL_WARNING_PREFIX), text); |
1475 |
|
return; |