1 |
|
/* |
2 |
|
* main_unix.cpp - Emulation core, Unix implementation |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
4 |
> |
* SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig |
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 |
65 |
|
* ExecutePPC (or any function that might cause a mode switch). The signal |
66 |
|
* stack is restored before exiting the SIGUSR2 handler. |
67 |
|
* |
68 |
+ |
* There is apparently another problem when processing signals. In |
69 |
+ |
* fullscreen mode, we get quick updates of the mouse position. This |
70 |
+ |
* causes an increased number of calls to TriggerInterrupt(). And, |
71 |
+ |
* since IRQ_NEST is not fully handled atomically, nested calls to |
72 |
+ |
* ppc_interrupt() may cause stack corruption to eventually crash the |
73 |
+ |
* emulator. |
74 |
+ |
* |
75 |
+ |
* FIXME: |
76 |
+ |
* The current solution is to allocate another signal stack when |
77 |
+ |
* processing ppc_interrupt(). However, it may be better to detect |
78 |
+ |
* the INTFLAG_ADB case and handle it specifically with some extra mutex? |
79 |
+ |
* |
80 |
|
* TODO: |
81 |
|
* check if SIGSEGV handler works for all registers (including FP!) |
82 |
|
*/ |
121 |
|
#include "user_strings.h" |
122 |
|
#include "vm_alloc.h" |
123 |
|
#include "sigsegv.h" |
124 |
+ |
#include "thunks.h" |
125 |
|
|
126 |
|
#define DEBUG 0 |
127 |
|
#include "debug.h" |
128 |
|
|
129 |
|
|
130 |
+ |
#ifdef HAVE_DIRENT_H |
131 |
+ |
#include <dirent.h> |
132 |
+ |
#endif |
133 |
+ |
|
134 |
+ |
#ifdef USE_SDL |
135 |
+ |
#include <SDL.h> |
136 |
+ |
#endif |
137 |
+ |
|
138 |
+ |
#ifndef USE_SDL_VIDEO |
139 |
|
#include <X11/Xlib.h> |
140 |
+ |
#endif |
141 |
|
|
142 |
|
#ifdef ENABLE_GTK |
143 |
|
#include <gtk/gtk.h> |
154 |
|
#endif |
155 |
|
|
156 |
|
|
157 |
+ |
// Enable emulation of unaligned lmw/stmw? |
158 |
+ |
#define EMULATE_UNALIGNED_LOADSTORE_MULTIPLE 1 |
159 |
+ |
|
160 |
|
// Enable Execute68k() safety checks? |
161 |
|
#define SAFE_EXEC_68K 0 |
162 |
|
|
166 |
|
// Interrupts in native mode? |
167 |
|
#define INTERRUPTS_IN_NATIVE_MODE 1 |
168 |
|
|
169 |
+ |
// Number of alternate stacks for signal handlers? |
170 |
+ |
#define SIG_STACK_COUNT 4 |
171 |
+ |
|
172 |
|
|
173 |
|
// Constants |
174 |
|
const char ROM_FILE_NAME[] = "ROM"; |
175 |
|
const char ROM_FILE_NAME2[] = "Mac OS ROM"; |
176 |
|
|
177 |
< |
const uint32 RAM_BASE = 0x20000000; // Base address of RAM |
177 |
> |
const uintptr RAM_BASE = 0x20000000; // Base address of RAM |
178 |
|
const uint32 SIG_STACK_SIZE = 0x10000; // Size of signal stack |
179 |
|
|
180 |
|
|
181 |
|
#if !EMULATED_PPC |
153 |
– |
// Structure in which registers are saved in a signal handler; |
154 |
– |
// sigcontext->regs points to it |
155 |
– |
// (see arch/ppc/kernel/signal.c) |
156 |
– |
typedef struct { |
157 |
– |
uint32 u[4]; |
158 |
– |
} __attribute((aligned(16))) vector128; |
159 |
– |
#include <linux/elf.h> |
160 |
– |
|
182 |
|
struct sigregs { |
183 |
< |
elf_gregset_t gp_regs; // Identical to pt_regs |
184 |
< |
double fp_regs[ELF_NFPREG]; // f0..f31 and fpsrc |
185 |
< |
//more (uninteresting) stuff following here |
183 |
> |
uint32 nip; |
184 |
> |
uint32 link; |
185 |
> |
uint32 ctr; |
186 |
> |
uint32 msr; |
187 |
> |
uint32 xer; |
188 |
> |
uint32 ccr; |
189 |
> |
uint32 gpr[32]; |
190 |
> |
}; |
191 |
> |
|
192 |
> |
#if defined(__linux__) |
193 |
> |
#include <sys/ucontext.h> |
194 |
> |
#define MACHINE_REGISTERS(scp) ((machine_regs *)(((ucontext_t *)scp)->uc_mcontext.regs)) |
195 |
> |
|
196 |
> |
struct machine_regs : public pt_regs |
197 |
> |
{ |
198 |
> |
u_long & cr() { return pt_regs::ccr; } |
199 |
> |
uint32 cr() const { return pt_regs::ccr; } |
200 |
> |
uint32 lr() const { return pt_regs::link; } |
201 |
> |
uint32 ctr() const { return pt_regs::ctr; } |
202 |
> |
uint32 xer() const { return pt_regs::xer; } |
203 |
> |
uint32 msr() const { return pt_regs::msr; } |
204 |
> |
uint32 dar() const { return pt_regs::dar; } |
205 |
> |
u_long & pc() { return pt_regs::nip; } |
206 |
> |
uint32 pc() const { return pt_regs::nip; } |
207 |
> |
u_long & gpr(int i) { return pt_regs::gpr[i]; } |
208 |
> |
uint32 gpr(int i) const { return pt_regs::gpr[i]; } |
209 |
> |
}; |
210 |
> |
#endif |
211 |
> |
|
212 |
> |
#if defined(__APPLE__) && defined(__MACH__) |
213 |
> |
#include <sys/signal.h> |
214 |
> |
extern "C" int sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss); |
215 |
> |
|
216 |
> |
#include <sys/ucontext.h> |
217 |
> |
#define MACHINE_REGISTERS(scp) ((machine_regs *)(((ucontext_t *)scp)->uc_mcontext)) |
218 |
> |
|
219 |
> |
struct machine_regs : public mcontext |
220 |
> |
{ |
221 |
> |
uint32 & cr() { return ss.cr; } |
222 |
> |
uint32 cr() const { return ss.cr; } |
223 |
> |
uint32 lr() const { return ss.lr; } |
224 |
> |
uint32 ctr() const { return ss.ctr; } |
225 |
> |
uint32 xer() const { return ss.xer; } |
226 |
> |
uint32 msr() const { return ss.srr1; } |
227 |
> |
uint32 dar() const { return es.dar; } |
228 |
> |
uint32 & pc() { return ss.srr0; } |
229 |
> |
uint32 pc() const { return ss.srr0; } |
230 |
> |
uint32 & gpr(int i) { return (&ss.r0)[i]; } |
231 |
> |
uint32 gpr(int i) const { return (&ss.r0)[i]; } |
232 |
|
}; |
233 |
|
#endif |
234 |
|
|
235 |
+ |
static void build_sigregs(sigregs *srp, machine_regs *mrp) |
236 |
+ |
{ |
237 |
+ |
srp->nip = mrp->pc(); |
238 |
+ |
srp->link = mrp->lr(); |
239 |
+ |
srp->ctr = mrp->ctr(); |
240 |
+ |
srp->msr = mrp->msr(); |
241 |
+ |
srp->xer = mrp->xer(); |
242 |
+ |
srp->ccr = mrp->cr(); |
243 |
+ |
for (int i = 0; i < 32; i++) |
244 |
+ |
srp->gpr[i] = mrp->gpr(i); |
245 |
+ |
} |
246 |
+ |
|
247 |
+ |
static struct sigaltstack sig_stacks[SIG_STACK_COUNT]; // Stacks for signal handlers |
248 |
+ |
static int sig_stack_id = 0; // Stack slot currently used |
249 |
+ |
|
250 |
+ |
static inline void sig_stack_acquire(void) |
251 |
+ |
{ |
252 |
+ |
if (++sig_stack_id == SIG_STACK_COUNT) { |
253 |
+ |
printf("FATAL: signal stack overflow\n"); |
254 |
+ |
return; |
255 |
+ |
} |
256 |
+ |
sigaltstack(&sig_stacks[sig_stack_id], NULL); |
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
static inline void sig_stack_release(void) |
260 |
+ |
{ |
261 |
+ |
if (--sig_stack_id < 0) { |
262 |
+ |
printf("FATAL: signal stack underflow\n"); |
263 |
+ |
return; |
264 |
+ |
} |
265 |
+ |
sigaltstack(&sig_stacks[sig_stack_id], NULL); |
266 |
+ |
} |
267 |
+ |
#endif |
268 |
+ |
|
269 |
|
|
270 |
|
// Global variables (exported) |
271 |
|
#if !EMULATED_PPC |
273 |
|
#endif |
274 |
|
uint32 RAMBase; // Base address of Mac RAM |
275 |
|
uint32 RAMSize; // Size of Mac RAM |
175 |
– |
uint32 SheepStack1Base; // SheepShaver first alternate stack base |
176 |
– |
uint32 SheepStack2Base; // SheepShaver second alternate stack base |
177 |
– |
uint32 SheepThunksBase; // SheepShaver thunks base |
276 |
|
uint32 KernelDataAddr; // Address of Kernel Data |
277 |
|
uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM |
278 |
+ |
uint32 DRCacheAddr; // Address of DR Cache |
279 |
|
uint32 PVR; // Theoretical PVR |
280 |
|
int64 CPUClockSpeed; // Processor clock speed (Hz) |
281 |
|
int64 BusClockSpeed; // Bus clock speed (Hz) |
282 |
+ |
int64 TimebaseSpeed; // Timebase clock speed (Hz) |
283 |
|
|
284 |
|
|
285 |
|
// Global variables |
286 |
< |
static char *x_display_name = NULL; // X11 display name |
286 |
> |
#ifndef USE_SDL_VIDEO |
287 |
> |
char *x_display_name = NULL; // X11 display name |
288 |
|
Display *x_display = NULL; // X11 display handle |
289 |
+ |
#ifdef X11_LOCK_TYPE |
290 |
+ |
X11_LOCK_TYPE x_display_lock = X11_LOCK_INIT; // X11 display lock |
291 |
+ |
#endif |
292 |
+ |
#endif |
293 |
|
|
294 |
|
static int zero_fd = 0; // FD of /dev/zero |
190 |
– |
static bool sheep_area_mapped = false; // Flag: SheepShaver data area mmap()ed |
295 |
|
static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped |
296 |
|
static int kernel_area = -1; // SHM ID of Kernel Data area |
297 |
|
static bool rom_area_mapped = false; // Flag: Mac ROM mmap()ped |
298 |
|
static bool ram_area_mapped = false; // Flag: Mac RAM mmap()ped |
299 |
+ |
static bool dr_cache_area_mapped = false; // Flag: Mac DR Cache mmap()ped |
300 |
+ |
static bool dr_emulator_area_mapped = false;// Flag: Mac DR Emulator mmap()ped |
301 |
|
static KernelData *kernel_data; // Pointer to Kernel Data |
302 |
|
static EmulatorData *emulator_data; |
303 |
|
|
304 |
|
static uint8 last_xpram[XPRAM_SIZE]; // Buffer for monitoring XPRAM changes |
305 |
|
|
306 |
|
static bool nvram_thread_active = false; // Flag: NVRAM watchdog installed |
307 |
+ |
static volatile bool nvram_thread_cancel; // Flag: Cancel NVRAM thread |
308 |
|
static pthread_t nvram_thread; // NVRAM watchdog |
309 |
|
static bool tick_thread_active = false; // Flag: MacOS thread installed |
310 |
+ |
static volatile bool tick_thread_cancel; // Flag: Cancel 60Hz thread |
311 |
|
static pthread_t tick_thread; // 60Hz thread |
312 |
|
static pthread_t emul_thread; // MacOS thread |
313 |
|
|
315 |
|
static int64 num_segv = 0; // Number of handled SEGV signals |
316 |
|
|
317 |
|
static struct sigaction sigusr2_action; // Interrupt signal (of emulator thread) |
318 |
< |
#if !EMULATED_PPC |
318 |
> |
#if EMULATED_PPC |
319 |
> |
static uintptr sig_stack = 0; // Stack for PowerPC interrupt routine |
320 |
> |
#else |
321 |
|
static struct sigaction sigsegv_action; // Data access exception signal (of emulator thread) |
322 |
|
static struct sigaction sigill_action; // Illegal instruction signal (of emulator thread) |
213 |
– |
static void *sig_stack = NULL; // Stack for signal handlers |
214 |
– |
static void *extra_stack = NULL; // Stack for SIGSEGV inside interrupt handler |
323 |
|
static bool emul_thread_fatal = false; // Flag: MacOS thread crashed, tick thread shall dump debug output |
324 |
|
static sigregs sigsegv_regs; // Register dump when crashed |
325 |
+ |
static const char *crash_reason = NULL; // Reason of the crash (SIGSEGV, SIGBUS, SIGILL) |
326 |
|
#endif |
327 |
|
|
328 |
+ |
uint32 SheepMem::page_size; // Size of a native page |
329 |
+ |
uintptr SheepMem::zero_page = 0; // Address of ro page filled in with zeros |
330 |
+ |
uintptr SheepMem::base = 0x60000000; // Address of SheepShaver data |
331 |
+ |
uintptr SheepMem::top = 0; // Top of SheepShaver data (stack like storage) |
332 |
+ |
|
333 |
|
|
334 |
|
// Prototypes |
335 |
|
static void Quit(void); |
337 |
|
static void *nvram_func(void *arg); |
338 |
|
static void *tick_func(void *arg); |
339 |
|
#if EMULATED_PPC |
340 |
< |
static void sigusr2_handler(int sig); |
340 |
> |
extern void emul_ppc(uint32 start); |
341 |
> |
extern void init_emul_ppc(void); |
342 |
> |
extern void exit_emul_ppc(void); |
343 |
> |
sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); |
344 |
|
#else |
345 |
< |
static void sigusr2_handler(int sig, sigcontext_struct *sc); |
346 |
< |
static void sigsegv_handler(int sig, sigcontext_struct *sc); |
347 |
< |
static void sigill_handler(int sig, sigcontext_struct *sc); |
345 |
> |
static void sigusr2_handler(int sig, siginfo_t *sip, void *scp); |
346 |
> |
static void sigsegv_handler(int sig, siginfo_t *sip, void *scp); |
347 |
> |
static void sigill_handler(int sig, siginfo_t *sip, void *scp); |
348 |
|
#endif |
349 |
|
|
350 |
|
|
351 |
|
// From asm_linux.S |
352 |
< |
#if EMULATED_PPC |
236 |
< |
extern int atomic_add(int *var, int v); |
237 |
< |
extern int atomic_and(int *var, int v); |
238 |
< |
extern int atomic_or(int *var, int v); |
239 |
< |
#else |
352 |
> |
#if !EMULATED_PPC |
353 |
|
extern "C" void *get_toc(void); |
354 |
|
extern "C" void *get_sp(void); |
355 |
|
extern "C" void flush_icache_range(void *start, void *end); |
364 |
|
#endif |
365 |
|
|
366 |
|
|
367 |
+ |
#if EMULATED_PPC |
368 |
+ |
/* |
369 |
+ |
* Return signal stack base |
370 |
+ |
*/ |
371 |
+ |
|
372 |
+ |
uintptr SignalStackBase(void) |
373 |
+ |
{ |
374 |
+ |
return sig_stack + SIG_STACK_SIZE; |
375 |
+ |
} |
376 |
+ |
|
377 |
+ |
|
378 |
+ |
/* |
379 |
+ |
* Atomic operations |
380 |
+ |
*/ |
381 |
+ |
|
382 |
+ |
#if HAVE_SPINLOCKS |
383 |
+ |
static spinlock_t atomic_ops_lock = SPIN_LOCK_UNLOCKED; |
384 |
+ |
#else |
385 |
+ |
#define spin_lock(LOCK) |
386 |
+ |
#define spin_unlock(LOCK) |
387 |
+ |
#endif |
388 |
+ |
|
389 |
+ |
int atomic_add(int *var, int v) |
390 |
+ |
{ |
391 |
+ |
spin_lock(&atomic_ops_lock); |
392 |
+ |
int ret = *var; |
393 |
+ |
*var += v; |
394 |
+ |
spin_unlock(&atomic_ops_lock); |
395 |
+ |
return ret; |
396 |
+ |
} |
397 |
+ |
|
398 |
+ |
int atomic_and(int *var, int v) |
399 |
+ |
{ |
400 |
+ |
spin_lock(&atomic_ops_lock); |
401 |
+ |
int ret = *var; |
402 |
+ |
*var &= v; |
403 |
+ |
spin_unlock(&atomic_ops_lock); |
404 |
+ |
return ret; |
405 |
+ |
} |
406 |
+ |
|
407 |
+ |
int atomic_or(int *var, int v) |
408 |
+ |
{ |
409 |
+ |
spin_lock(&atomic_ops_lock); |
410 |
+ |
int ret = *var; |
411 |
+ |
*var |= v; |
412 |
+ |
spin_unlock(&atomic_ops_lock); |
413 |
+ |
return ret; |
414 |
+ |
} |
415 |
+ |
#endif |
416 |
+ |
|
417 |
+ |
|
418 |
|
/* |
419 |
|
* Main program |
420 |
|
*/ |
433 |
|
char str[256]; |
434 |
|
uint32 *boot_globs; |
435 |
|
int16 i16; |
272 |
– |
int drive, driver; |
436 |
|
int rom_fd; |
437 |
|
FILE *proc_file; |
438 |
|
const char *rom_path; |
466 |
|
for (int i=1; i<argc; i++) { |
467 |
|
if (strcmp(argv[i], "--help") == 0) { |
468 |
|
usage(argv[0]); |
469 |
+ |
#ifndef USE_SDL_VIDEO |
470 |
|
} else if (strcmp(argv[i], "--display") == 0) { |
471 |
|
i++; |
472 |
|
if (i < argc) |
473 |
|
x_display_name = strdup(argv[i]); |
474 |
+ |
#endif |
475 |
|
} else if (argv[i][0] == '-') { |
476 |
|
fprintf(stderr, "Unrecognized option '%s'\n", argv[i]); |
477 |
|
usage(argv[0]); |
478 |
|
} |
479 |
|
} |
480 |
|
|
481 |
+ |
#ifdef USE_SDL |
482 |
+ |
// Initialize SDL system |
483 |
+ |
int sdl_flags = 0; |
484 |
+ |
#ifdef USE_SDL_VIDEO |
485 |
+ |
sdl_flags |= SDL_INIT_VIDEO; |
486 |
+ |
#endif |
487 |
+ |
assert(sdl_flags != 0); |
488 |
+ |
if (SDL_Init(sdl_flags) == -1) { |
489 |
+ |
char str[256]; |
490 |
+ |
sprintf(str, "Could not initialize SDL: %s.\n", SDL_GetError()); |
491 |
+ |
ErrorAlert(str); |
492 |
+ |
goto quit; |
493 |
+ |
} |
494 |
+ |
atexit(SDL_Quit); |
495 |
+ |
#endif |
496 |
+ |
|
497 |
+ |
#ifndef USE_SDL_VIDEO |
498 |
|
// Open display |
499 |
|
x_display = XOpenDisplay(x_display_name); |
500 |
|
if (x_display == NULL) { |
508 |
|
// Fork out, so we can return from fullscreen mode when things get ugly |
509 |
|
XF86DGAForkApp(DefaultScreen(x_display)); |
510 |
|
#endif |
511 |
+ |
#endif |
512 |
|
|
513 |
|
#ifdef ENABLE_MON |
514 |
|
// Initialize mon |
515 |
|
mon_init(); |
516 |
|
#endif |
517 |
|
|
518 |
+ |
#if !EMULATED_PPC |
519 |
+ |
// Create and install stacks for signal handlers |
520 |
+ |
for (int i = 0; i < SIG_STACK_COUNT; i++) { |
521 |
+ |
void *sig_stack = malloc(SIG_STACK_SIZE); |
522 |
+ |
D(bug("Signal stack %d at %p\n", i, sig_stack)); |
523 |
+ |
if (sig_stack == NULL) { |
524 |
+ |
ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); |
525 |
+ |
goto quit; |
526 |
+ |
} |
527 |
+ |
sig_stacks[i].ss_sp = sig_stack; |
528 |
+ |
sig_stacks[i].ss_flags = 0; |
529 |
+ |
sig_stacks[i].ss_size = SIG_STACK_SIZE; |
530 |
+ |
} |
531 |
+ |
sig_stack_id = 0; |
532 |
+ |
if (sigaltstack(&sig_stacks[0], NULL) < 0) { |
533 |
+ |
sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno)); |
534 |
+ |
ErrorAlert(str); |
535 |
+ |
goto quit; |
536 |
+ |
} |
537 |
+ |
#endif |
538 |
+ |
|
539 |
+ |
#if !EMULATED_PPC |
540 |
+ |
// Install SIGSEGV and SIGBUS handlers |
541 |
+ |
sigemptyset(&sigsegv_action.sa_mask); // Block interrupts during SEGV handling |
542 |
+ |
sigaddset(&sigsegv_action.sa_mask, SIGUSR2); |
543 |
+ |
sigsegv_action.sa_sigaction = sigsegv_handler; |
544 |
+ |
sigsegv_action.sa_flags = SA_ONSTACK | SA_SIGINFO; |
545 |
+ |
#ifdef HAVE_SIGNAL_SA_RESTORER |
546 |
+ |
sigsegv_action.sa_restorer = NULL; |
547 |
+ |
#endif |
548 |
+ |
if (sigaction(SIGSEGV, &sigsegv_action, NULL) < 0) { |
549 |
+ |
sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); |
550 |
+ |
ErrorAlert(str); |
551 |
+ |
goto quit; |
552 |
+ |
} |
553 |
+ |
if (sigaction(SIGBUS, &sigsegv_action, NULL) < 0) { |
554 |
+ |
sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); |
555 |
+ |
ErrorAlert(str); |
556 |
+ |
goto quit; |
557 |
+ |
} |
558 |
+ |
#else |
559 |
+ |
// Install SIGSEGV handler for CPU emulator |
560 |
+ |
if (!sigsegv_install_handler(sigsegv_handler)) { |
561 |
+ |
sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); |
562 |
+ |
ErrorAlert(str); |
563 |
+ |
goto quit; |
564 |
+ |
} |
565 |
+ |
#endif |
566 |
+ |
|
567 |
+ |
// Initialize VM system |
568 |
+ |
vm_init(); |
569 |
+ |
|
570 |
|
// Get system info |
571 |
|
PVR = 0x00040000; // Default: 604 |
572 |
|
CPUClockSpeed = 100000000; // Default: 100MHz |
573 |
|
BusClockSpeed = 100000000; // Default: 100MHz |
574 |
< |
#if !EMULATED_PPC |
574 |
> |
TimebaseSpeed = 25000000; // Default: 25MHz |
575 |
> |
#if EMULATED_PPC |
576 |
> |
PVR = 0x000c0000; // Default: 7400 (with AltiVec) |
577 |
> |
#elif defined(__APPLE__) && defined(__MACH__) |
578 |
> |
proc_file = popen("ioreg -c IOPlatformDevice", "r"); |
579 |
> |
if (proc_file) { |
580 |
> |
char line[256]; |
581 |
> |
bool powerpc_node = false; |
582 |
> |
while (fgets(line, sizeof(line) - 1, proc_file)) { |
583 |
> |
// Read line |
584 |
> |
int len = strlen(line); |
585 |
> |
if (len == 0) |
586 |
> |
continue; |
587 |
> |
line[len - 1] = 0; |
588 |
> |
|
589 |
> |
// Parse line |
590 |
> |
if (strstr(line, "o PowerPC,")) |
591 |
> |
powerpc_node = true; |
592 |
> |
else if (powerpc_node) { |
593 |
> |
uint32 value; |
594 |
> |
char head[256]; |
595 |
> |
if (sscanf(line, "%[ |]\"cpu-version\" = <%x>", head, &value) == 2) |
596 |
> |
PVR = value; |
597 |
> |
else if (sscanf(line, "%[ |]\"clock-frequency\" = <%x>", head, &value) == 2) |
598 |
> |
CPUClockSpeed = value; |
599 |
> |
else if (sscanf(line, "%[ |]\"bus-frequency\" = <%x>", head, &value) == 2) |
600 |
> |
BusClockSpeed = value; |
601 |
> |
else if (sscanf(line, "%[ |]\"timebase-frequency\" = <%x>", head, &value) == 2) |
602 |
> |
TimebaseSpeed = value; |
603 |
> |
else if (strchr(line, '}')) |
604 |
> |
powerpc_node = false; |
605 |
> |
} |
606 |
> |
} |
607 |
> |
fclose(proc_file); |
608 |
> |
} else { |
609 |
> |
sprintf(str, GetString(STR_PROC_CPUINFO_WARN), strerror(errno)); |
610 |
> |
WarningAlert(str); |
611 |
> |
} |
612 |
> |
#else |
613 |
|
proc_file = fopen("/proc/cpuinfo", "r"); |
614 |
|
if (proc_file) { |
615 |
|
char line[256]; |
623 |
|
// Parse line |
624 |
|
int i; |
625 |
|
char value[256]; |
626 |
< |
if (sscanf(line, "cpu : %s", value) == 1) { |
626 |
> |
if (sscanf(line, "cpu : %[0-9A-Za-a]", value) == 1) { |
627 |
|
if (strcmp(value, "601") == 0) |
628 |
|
PVR = 0x00010000; |
629 |
|
else if (strcmp(value, "603") == 0) |
640 |
|
PVR = 0x000a0000; |
641 |
|
else if (strcmp(value, "750") == 0) |
642 |
|
PVR = 0x00080000; |
643 |
+ |
else if (strcmp(value, "750FX") == 0) |
644 |
+ |
PVR = 0x70000000; |
645 |
|
else if (strcmp(value, "821") == 0) |
646 |
|
PVR = 0x00320000; |
647 |
|
else if (strcmp(value, "860") == 0) |
648 |
|
PVR = 0x00500000; |
649 |
+ |
else if (strcmp(value, "7400") == 0) |
650 |
+ |
PVR = 0x000c0000; |
651 |
+ |
else if (strcmp(value, "7410") == 0) |
652 |
+ |
PVR = 0x800c0000; |
653 |
+ |
else if (strcmp(value, "7450") == 0) |
654 |
+ |
PVR = 0x80000000; |
655 |
+ |
else if (strcmp(value, "7455") == 0) |
656 |
+ |
PVR = 0x80010000; |
657 |
+ |
else if (strcmp(value, "7457") == 0) |
658 |
+ |
PVR = 0x80020000; |
659 |
+ |
else if (strcmp(value, "PPC970") == 0) |
660 |
+ |
PVR = 0x00390000; |
661 |
|
else |
662 |
|
printf("WARNING: Unknown CPU type '%s', assuming 604\n", value); |
663 |
|
} |
669 |
|
sprintf(str, GetString(STR_PROC_CPUINFO_WARN), strerror(errno)); |
670 |
|
WarningAlert(str); |
671 |
|
} |
672 |
+ |
|
673 |
+ |
// Get actual bus frequency |
674 |
+ |
proc_file = fopen("/proc/device-tree/clock-frequency", "r"); |
675 |
+ |
if (proc_file) { |
676 |
+ |
union { uint8 b[4]; uint32 l; } value; |
677 |
+ |
if (fread(value.b, sizeof(value), 1, proc_file) == 1) |
678 |
+ |
BusClockSpeed = value.l; |
679 |
+ |
fclose(proc_file); |
680 |
+ |
} |
681 |
+ |
|
682 |
+ |
// Get actual timebase frequency |
683 |
+ |
TimebaseSpeed = BusClockSpeed / 4; |
684 |
+ |
DIR *cpus_dir; |
685 |
+ |
if ((cpus_dir = opendir("/proc/device-tree/cpus")) != NULL) { |
686 |
+ |
struct dirent *cpu_entry; |
687 |
+ |
while ((cpu_entry = readdir(cpus_dir)) != NULL) { |
688 |
+ |
if (strstr(cpu_entry->d_name, "PowerPC,") == cpu_entry->d_name) { |
689 |
+ |
char timebase_freq_node[256]; |
690 |
+ |
sprintf(timebase_freq_node, "/proc/device-tree/cpus/%s/timebase-frequency", cpu_entry->d_name); |
691 |
+ |
proc_file = fopen(timebase_freq_node, "r"); |
692 |
+ |
if (proc_file) { |
693 |
+ |
union { uint8 b[4]; uint32 l; } value; |
694 |
+ |
if (fread(value.b, sizeof(value), 1, proc_file) == 1) |
695 |
+ |
TimebaseSpeed = value.l; |
696 |
+ |
fclose(proc_file); |
697 |
+ |
} |
698 |
+ |
} |
699 |
+ |
} |
700 |
+ |
closedir(cpus_dir); |
701 |
+ |
} |
702 |
|
#endif |
703 |
+ |
// Remap any newer G4/G5 processor to plain G4 for compatibility |
704 |
+ |
switch (PVR >> 16) { |
705 |
+ |
case 0x8000: // 7450 |
706 |
+ |
case 0x8001: // 7455 |
707 |
+ |
case 0x8002: // 7457 |
708 |
+ |
case 0x0039: // 970 |
709 |
+ |
PVR = 0x000c0000; // 7400 |
710 |
+ |
break; |
711 |
+ |
} |
712 |
|
D(bug("PVR: %08x (assumed)\n", PVR)); |
713 |
|
|
714 |
|
// Init system routines |
732 |
|
goto quit; |
733 |
|
} |
734 |
|
|
735 |
+ |
#ifndef PAGEZERO_HACK |
736 |
|
// Create Low Memory area (0x0000..0x3000) |
737 |
|
if (vm_acquire_fixed((char *)0, 0x3000) < 0) { |
738 |
|
sprintf(str, GetString(STR_LOW_MEM_MMAP_ERR), strerror(errno)); |
740 |
|
goto quit; |
741 |
|
} |
742 |
|
lm_area_mapped = true; |
743 |
+ |
#endif |
744 |
|
|
745 |
|
// Create areas for Kernel Data |
746 |
|
kernel_area = shmget(IPC_PRIVATE, KERNEL_AREA_SIZE, 0600); |
759 |
|
ErrorAlert(str); |
760 |
|
goto quit; |
761 |
|
} |
762 |
< |
kernel_data = (KernelData *)0x68ffe000; |
762 |
> |
kernel_data = (KernelData *)KERNEL_DATA_BASE; |
763 |
|
emulator_data = &kernel_data->ed; |
764 |
< |
KernelDataAddr = (uint32)kernel_data; |
764 |
> |
KernelDataAddr = KERNEL_DATA_BASE; |
765 |
|
D(bug("Kernel Data at %p, Emulator Data at %p\n", kernel_data, emulator_data)); |
766 |
|
|
767 |
+ |
// Create area for DR Cache |
768 |
+ |
if (vm_acquire_fixed((void *)DR_EMULATOR_BASE, DR_EMULATOR_SIZE) < 0) { |
769 |
+ |
sprintf(str, GetString(STR_DR_EMULATOR_MMAP_ERR), strerror(errno)); |
770 |
+ |
ErrorAlert(str); |
771 |
+ |
goto quit; |
772 |
+ |
} |
773 |
+ |
dr_emulator_area_mapped = true; |
774 |
+ |
if (vm_acquire_fixed((void *)DR_CACHE_BASE, DR_CACHE_SIZE) < 0) { |
775 |
+ |
sprintf(str, GetString(STR_DR_CACHE_MMAP_ERR), strerror(errno)); |
776 |
+ |
ErrorAlert(str); |
777 |
+ |
goto quit; |
778 |
+ |
} |
779 |
+ |
dr_cache_area_mapped = true; |
780 |
+ |
#if !EMULATED_PPC |
781 |
+ |
if (vm_protect((char *)DR_CACHE_BASE, DR_CACHE_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) { |
782 |
+ |
sprintf(str, GetString(STR_DR_CACHE_MMAP_ERR), strerror(errno)); |
783 |
+ |
ErrorAlert(str); |
784 |
+ |
goto quit; |
785 |
+ |
} |
786 |
+ |
#endif |
787 |
+ |
DRCacheAddr = DR_CACHE_BASE; |
788 |
+ |
D(bug("DR Cache at %p\n", DRCacheAddr)); |
789 |
+ |
|
790 |
|
// Create area for SheepShaver data |
791 |
< |
if (vm_acquire_fixed((char *)SHEEP_BASE, SHEEP_SIZE) < 0) { |
791 |
> |
if (!SheepMem::Init()) { |
792 |
|
sprintf(str, GetString(STR_SHEEP_MEM_MMAP_ERR), strerror(errno)); |
793 |
|
ErrorAlert(str); |
794 |
|
goto quit; |
795 |
|
} |
445 |
– |
SheepStack1Base = SHEEP_BASE + 0x10000; |
446 |
– |
SheepStack2Base = SheepStack1Base + 0x10000; |
447 |
– |
SheepThunksBase = SheepStack2Base + 0x1000; |
448 |
– |
sheep_area_mapped = true; |
796 |
|
|
797 |
|
// Create area for Mac ROM |
798 |
|
if (vm_acquire_fixed((char *)ROM_BASE, ROM_AREA_SIZE) < 0) { |
800 |
|
ErrorAlert(str); |
801 |
|
goto quit; |
802 |
|
} |
803 |
< |
#if !EMULATED_PPC || defined(__powerpc__) |
803 |
> |
#if !EMULATED_PPC |
804 |
|
if (vm_protect((char *)ROM_BASE, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) { |
805 |
|
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); |
806 |
|
ErrorAlert(str); |
870 |
|
// Load NVRAM |
871 |
|
XPRAMInit(); |
872 |
|
|
873 |
+ |
// Load XPRAM default values if signature not found |
874 |
+ |
if (XPRAM[0x130c] != 0x4e || XPRAM[0x130d] != 0x75 |
875 |
+ |
|| XPRAM[0x130e] != 0x4d || XPRAM[0x130f] != 0x63) { |
876 |
+ |
D(bug("Loading XPRAM default values\n")); |
877 |
+ |
memset(XPRAM + 0x1300, 0, 0x100); |
878 |
+ |
XPRAM[0x130c] = 0x4e; // "NuMc" signature |
879 |
+ |
XPRAM[0x130d] = 0x75; |
880 |
+ |
XPRAM[0x130e] = 0x4d; |
881 |
+ |
XPRAM[0x130f] = 0x63; |
882 |
+ |
XPRAM[0x1301] = 0x80; // InternalWaitFlags = DynWait (don't wait for SCSI devices upon bootup) |
883 |
+ |
XPRAM[0x1310] = 0xa8; // Standard PRAM values |
884 |
+ |
XPRAM[0x1311] = 0x00; |
885 |
+ |
XPRAM[0x1312] = 0x00; |
886 |
+ |
XPRAM[0x1313] = 0x22; |
887 |
+ |
XPRAM[0x1314] = 0xcc; |
888 |
+ |
XPRAM[0x1315] = 0x0a; |
889 |
+ |
XPRAM[0x1316] = 0xcc; |
890 |
+ |
XPRAM[0x1317] = 0x0a; |
891 |
+ |
XPRAM[0x131c] = 0x00; |
892 |
+ |
XPRAM[0x131d] = 0x02; |
893 |
+ |
XPRAM[0x131e] = 0x63; |
894 |
+ |
XPRAM[0x131f] = 0x00; |
895 |
+ |
XPRAM[0x1308] = 0x13; |
896 |
+ |
XPRAM[0x1309] = 0x88; |
897 |
+ |
XPRAM[0x130a] = 0x00; |
898 |
+ |
XPRAM[0x130b] = 0xcc; |
899 |
+ |
XPRAM[0x1376] = 0x00; // OSDefault = MacOS |
900 |
+ |
XPRAM[0x1377] = 0x01; |
901 |
+ |
} |
902 |
+ |
|
903 |
|
// Set boot volume |
904 |
< |
drive = PrefsFindInt32("bootdrive"); |
904 |
> |
i16 = PrefsFindInt32("bootdrive"); |
905 |
|
XPRAM[0x1378] = i16 >> 8; |
906 |
|
XPRAM[0x1379] = i16 & 0xff; |
907 |
< |
driver = PrefsFindInt32("bootdriver"); |
907 |
> |
i16 = PrefsFindInt32("bootdriver"); |
908 |
|
XPRAM[0x137a] = i16 >> 8; |
909 |
|
XPRAM[0x137b] = i16 & 0xff; |
910 |
|
|
917 |
|
boot_globs[1] = htonl(RAMSize); |
918 |
|
boot_globs[2] = htonl((uint32)-1); // End of bank table |
919 |
|
|
920 |
+ |
// Init thunks |
921 |
+ |
if (!ThunksInit()) |
922 |
+ |
goto quit; |
923 |
+ |
|
924 |
|
// Init drivers |
925 |
|
SonyInit(); |
926 |
|
DiskInit(); |
930 |
|
// Init external file system |
931 |
|
ExtFSInit(); |
932 |
|
|
933 |
+ |
// Init ADB |
934 |
+ |
ADBInit(); |
935 |
+ |
|
936 |
|
// Init audio |
937 |
|
AudioInit(); |
938 |
|
|
967 |
|
// Initialize Kernel Data |
968 |
|
memset(kernel_data, 0, sizeof(KernelData)); |
969 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
970 |
< |
static uint32 of_dev_tree[4] = {0, 0, 0, 0}; |
971 |
< |
static uint8 vector_lookup_tbl[128]; |
972 |
< |
static uint8 vector_mask_tbl[64]; |
970 |
> |
uintptr of_dev_tree = SheepMem::Reserve(4 * sizeof(uint32)); |
971 |
> |
memset((void *)of_dev_tree, 0, 4 * sizeof(uint32)); |
972 |
> |
uintptr vector_lookup_tbl = SheepMem::Reserve(128); |
973 |
> |
uintptr vector_mask_tbl = SheepMem::Reserve(64); |
974 |
|
memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80); |
975 |
< |
memset(vector_lookup_tbl, 0, 128); |
976 |
< |
memset(vector_mask_tbl, 0, 64); |
975 |
> |
memset((void *)vector_lookup_tbl, 0, 128); |
976 |
> |
memset((void *)vector_mask_tbl, 0, 64); |
977 |
|
kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE); |
978 |
< |
kernel_data->v[0xb84 >> 2] = htonl((uint32)of_dev_tree); // OF device tree base |
979 |
< |
kernel_data->v[0xb90 >> 2] = htonl((uint32)vector_lookup_tbl); |
980 |
< |
kernel_data->v[0xb94 >> 2] = htonl((uint32)vector_mask_tbl); |
978 |
> |
kernel_data->v[0xb84 >> 2] = htonl(of_dev_tree); // OF device tree base |
979 |
> |
kernel_data->v[0xb90 >> 2] = htonl(vector_lookup_tbl); |
980 |
> |
kernel_data->v[0xb94 >> 2] = htonl(vector_mask_tbl); |
981 |
|
kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE); // OpenPIC base |
982 |
|
kernel_data->v[0xbb0 >> 2] = htonl(0); // ADB base |
983 |
|
kernel_data->v[0xc20 >> 2] = htonl(RAMSize); |
990 |
|
kernel_data->v[0xc50 >> 2] = htonl(RAMBase); |
991 |
|
kernel_data->v[0xc54 >> 2] = htonl(RAMSize); |
992 |
|
kernel_data->v[0xf60 >> 2] = htonl(PVR); |
993 |
< |
kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed); |
994 |
< |
kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed); |
995 |
< |
kernel_data->v[0xf6c >> 2] = htonl(CPUClockSpeed); |
993 |
> |
kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed); // clock-frequency |
994 |
> |
kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed); // bus-frequency |
995 |
> |
kernel_data->v[0xf6c >> 2] = htonl(TimebaseSpeed); // timebase-frequency |
996 |
|
} else { |
997 |
|
kernel_data->v[0xc80 >> 2] = htonl(RAMSize); |
998 |
|
kernel_data->v[0xc84 >> 2] = htonl(RAMSize); |
1004 |
|
kernel_data->v[0xcb0 >> 2] = htonl(RAMBase); |
1005 |
|
kernel_data->v[0xcb4 >> 2] = htonl(RAMSize); |
1006 |
|
kernel_data->v[0xf80 >> 2] = htonl(PVR); |
1007 |
< |
kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed); |
1008 |
< |
kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed); |
1009 |
< |
kernel_data->v[0xf8c >> 2] = htonl(CPUClockSpeed); |
1007 |
> |
kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed); // clock-frequency |
1008 |
> |
kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed); // bus-frequency |
1009 |
> |
kernel_data->v[0xf8c >> 2] = htonl(TimebaseSpeed); // timebase-frequency |
1010 |
|
} |
1011 |
|
|
1012 |
|
// Initialize extra low memory |
1013 |
|
D(bug("Initializing Low Memory...\n")); |
1014 |
|
memset(NULL, 0, 0x3000); |
1015 |
|
WriteMacInt32(XLM_SIGNATURE, FOURCC('B','a','a','h')); // Signature to detect SheepShaver |
1016 |
< |
WriteMacInt32(XLM_KERNEL_DATA, (uint32)kernel_data); // For trap replacement routines |
1016 |
> |
WriteMacInt32(XLM_KERNEL_DATA, KernelDataAddr); // For trap replacement routines |
1017 |
|
WriteMacInt32(XLM_PVR, PVR); // Theoretical PVR |
1018 |
|
WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch |
1019 |
|
WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode) |
1020 |
< |
#if EMULATED_PPC |
1021 |
< |
WriteMacInt32(XLM_ETHER_INIT, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_INIT)); |
1022 |
< |
WriteMacInt32(XLM_ETHER_TERM, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_TERM)); |
638 |
< |
WriteMacInt32(XLM_ETHER_OPEN, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_OPEN)); |
639 |
< |
WriteMacInt32(XLM_ETHER_CLOSE, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_CLOSE)); |
640 |
< |
WriteMacInt32(XLM_ETHER_WPUT, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_WPUT)); |
641 |
< |
WriteMacInt32(XLM_ETHER_RSRV, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_RSRV)); |
642 |
< |
WriteMacInt32(XLM_VIDEO_DOIO, POWERPC_NATIVE_OP_FUNC(NATIVE_VIDEO_DO_DRIVER_IO)); |
643 |
< |
#else |
644 |
< |
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator |
645 |
< |
WriteMacInt32(XLM_ETHER_INIT, (uint32)InitStreamModule); // DLPI ethernet driver functions |
646 |
< |
WriteMacInt32(XLM_ETHER_TERM, (uint32)TerminateStreamModule); |
647 |
< |
WriteMacInt32(XLM_ETHER_OPEN, (uint32)ether_open); |
648 |
< |
WriteMacInt32(XLM_ETHER_CLOSE, (uint32)ether_close); |
649 |
< |
WriteMacInt32(XLM_ETHER_WPUT, (uint32)ether_wput); |
650 |
< |
WriteMacInt32(XLM_ETHER_RSRV, (uint32)ether_rsrv); |
651 |
< |
WriteMacInt32(XLM_VIDEO_DOIO, (uint32)VideoDoDriverIO); |
1020 |
> |
WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage()); // Pointer to read-only page with all bits set to 0 |
1021 |
> |
#if !EMULATED_PPC |
1022 |
> |
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator |
1023 |
|
#endif |
1024 |
+ |
WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT)); // DLPI ethernet driver functions |
1025 |
+ |
WriteMacInt32(XLM_ETHER_TERM, NativeFunction(NATIVE_ETHER_TERM)); |
1026 |
+ |
WriteMacInt32(XLM_ETHER_OPEN, NativeFunction(NATIVE_ETHER_OPEN)); |
1027 |
+ |
WriteMacInt32(XLM_ETHER_CLOSE, NativeFunction(NATIVE_ETHER_CLOSE)); |
1028 |
+ |
WriteMacInt32(XLM_ETHER_WPUT, NativeFunction(NATIVE_ETHER_WPUT)); |
1029 |
+ |
WriteMacInt32(XLM_ETHER_RSRV, NativeFunction(NATIVE_ETHER_RSRV)); |
1030 |
+ |
WriteMacInt32(XLM_VIDEO_DOIO, NativeFunction(NATIVE_VIDEO_DO_DRIVER_IO)); |
1031 |
|
D(bug("Low Memory initialized\n")); |
1032 |
|
|
1033 |
|
// Start 60Hz thread |
1034 |
+ |
tick_thread_cancel = false; |
1035 |
|
tick_thread_active = (pthread_create(&tick_thread, NULL, tick_func, NULL) == 0); |
1036 |
|
D(bug("Tick thread installed (%ld)\n", tick_thread)); |
1037 |
|
|
1038 |
|
// Start NVRAM watchdog thread |
1039 |
|
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
1040 |
+ |
nvram_thread_cancel = false; |
1041 |
|
nvram_thread_active = (pthread_create(&nvram_thread, NULL, nvram_func, NULL) == 0); |
1042 |
|
D(bug("NVRAM thread installed (%ld)\n", nvram_thread)); |
1043 |
|
|
1044 |
|
#if !EMULATED_PPC |
665 |
– |
// Create and install stacks for signal handlers |
666 |
– |
sig_stack = malloc(SIG_STACK_SIZE); |
667 |
– |
D(bug("Signal stack at %p\n", sig_stack)); |
668 |
– |
if (sig_stack == NULL) { |
669 |
– |
ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); |
670 |
– |
goto quit; |
671 |
– |
} |
672 |
– |
extra_stack = malloc(SIG_STACK_SIZE); |
673 |
– |
D(bug("Extra stack at %p\n", extra_stack)); |
674 |
– |
if (extra_stack == NULL) { |
675 |
– |
ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); |
676 |
– |
goto quit; |
677 |
– |
} |
678 |
– |
struct sigaltstack new_stack; |
679 |
– |
new_stack.ss_sp = sig_stack; |
680 |
– |
new_stack.ss_flags = 0; |
681 |
– |
new_stack.ss_size = SIG_STACK_SIZE; |
682 |
– |
if (sigaltstack(&new_stack, NULL) < 0) { |
683 |
– |
sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno)); |
684 |
– |
ErrorAlert(str); |
685 |
– |
goto quit; |
686 |
– |
} |
687 |
– |
#endif |
688 |
– |
|
689 |
– |
#if !EMULATED_PPC |
690 |
– |
// Install SIGSEGV handler |
691 |
– |
sigemptyset(&sigsegv_action.sa_mask); // Block interrupts during SEGV handling |
692 |
– |
sigaddset(&sigsegv_action.sa_mask, SIGUSR2); |
693 |
– |
sigsegv_action.sa_handler = (__sighandler_t)sigsegv_handler; |
694 |
– |
sigsegv_action.sa_flags = SA_ONSTACK; |
695 |
– |
sigsegv_action.sa_restorer = NULL; |
696 |
– |
if (sigaction(SIGSEGV, &sigsegv_action, NULL) < 0) { |
697 |
– |
sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); |
698 |
– |
ErrorAlert(str); |
699 |
– |
goto quit; |
700 |
– |
} |
701 |
– |
|
1045 |
|
// Install SIGILL handler |
1046 |
|
sigemptyset(&sigill_action.sa_mask); // Block interrupts during ILL handling |
1047 |
|
sigaddset(&sigill_action.sa_mask, SIGUSR2); |
1048 |
< |
sigill_action.sa_handler = (__sighandler_t)sigill_handler; |
1049 |
< |
sigill_action.sa_flags = SA_ONSTACK; |
1048 |
> |
sigill_action.sa_sigaction = sigill_handler; |
1049 |
> |
sigill_action.sa_flags = SA_ONSTACK | SA_SIGINFO; |
1050 |
> |
#ifdef HAVE_SIGNAL_SA_RESTORER |
1051 |
|
sigill_action.sa_restorer = NULL; |
1052 |
+ |
#endif |
1053 |
|
if (sigaction(SIGILL, &sigill_action, NULL) < 0) { |
1054 |
|
sprintf(str, GetString(STR_SIGILL_INSTALL_ERR), strerror(errno)); |
1055 |
|
ErrorAlert(str); |
1057 |
|
} |
1058 |
|
#endif |
1059 |
|
|
1060 |
+ |
#if !EMULATED_PPC |
1061 |
|
// Install interrupt signal handler |
1062 |
|
sigemptyset(&sigusr2_action.sa_mask); |
1063 |
< |
sigusr2_action.sa_handler = (__sighandler_t)sigusr2_handler; |
1064 |
< |
sigusr2_action.sa_flags = 0; |
1065 |
< |
#if !EMULATED_PPC |
720 |
< |
sigusr2_action.sa_flags = SA_ONSTACK | SA_RESTART; |
721 |
< |
#endif |
1063 |
> |
sigusr2_action.sa_sigaction = sigusr2_handler; |
1064 |
> |
sigusr2_action.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; |
1065 |
> |
#ifdef HAVE_SIGNAL_SA_RESTORER |
1066 |
|
sigusr2_action.sa_restorer = NULL; |
1067 |
+ |
#endif |
1068 |
|
if (sigaction(SIGUSR2, &sigusr2_action, NULL) < 0) { |
1069 |
|
sprintf(str, GetString(STR_SIGUSR2_INSTALL_ERR), strerror(errno)); |
1070 |
|
ErrorAlert(str); |
1071 |
|
goto quit; |
1072 |
|
} |
1073 |
+ |
#endif |
1074 |
|
|
1075 |
|
// Get my thread ID and execute MacOS thread function |
1076 |
|
emul_thread = pthread_self(); |
1089 |
|
|
1090 |
|
static void Quit(void) |
1091 |
|
{ |
1092 |
+ |
#if EMULATED_PPC |
1093 |
+ |
// Exit PowerPC emulation |
1094 |
+ |
exit_emul_ppc(); |
1095 |
+ |
#endif |
1096 |
+ |
|
1097 |
|
// Stop 60Hz thread |
1098 |
|
if (tick_thread_active) { |
1099 |
+ |
tick_thread_cancel = true; |
1100 |
|
pthread_cancel(tick_thread); |
1101 |
|
pthread_join(tick_thread, NULL); |
1102 |
|
} |
1103 |
|
|
1104 |
|
// Stop NVRAM watchdog thread |
1105 |
|
if (nvram_thread_active) { |
1106 |
+ |
nvram_thread_cancel = true; |
1107 |
|
pthread_cancel(nvram_thread); |
1108 |
|
pthread_join(nvram_thread, NULL); |
1109 |
|
} |
1110 |
|
|
1111 |
|
#if !EMULATED_PPC |
1112 |
< |
// Uninstall SIGSEGV handler |
1112 |
> |
// Uninstall SIGSEGV and SIGBUS handlers |
1113 |
|
sigemptyset(&sigsegv_action.sa_mask); |
1114 |
|
sigsegv_action.sa_handler = SIG_DFL; |
1115 |
|
sigsegv_action.sa_flags = 0; |
1116 |
|
sigaction(SIGSEGV, &sigsegv_action, NULL); |
1117 |
+ |
sigaction(SIGBUS, &sigsegv_action, NULL); |
1118 |
|
|
1119 |
|
// Uninstall SIGILL handler |
1120 |
|
sigemptyset(&sigill_action.sa_mask); |
1121 |
|
sigill_action.sa_handler = SIG_DFL; |
1122 |
|
sigill_action.sa_flags = 0; |
1123 |
|
sigaction(SIGILL, &sigill_action, NULL); |
1124 |
+ |
|
1125 |
+ |
// Delete stacks for signal handlers |
1126 |
+ |
for (int i = 0; i < SIG_STACK_COUNT; i++) { |
1127 |
+ |
void *sig_stack = sig_stacks[i].ss_sp; |
1128 |
+ |
if (sig_stack) |
1129 |
+ |
free(sig_stack); |
1130 |
+ |
} |
1131 |
|
#endif |
1132 |
|
|
1133 |
|
// Save NVRAM |
1148 |
|
// Exit audio |
1149 |
|
AudioExit(); |
1150 |
|
|
1151 |
+ |
// Exit ADB |
1152 |
+ |
ADBExit(); |
1153 |
+ |
|
1154 |
|
// Exit video |
1155 |
|
VideoExit(); |
1156 |
|
|
1163 |
|
DiskExit(); |
1164 |
|
SonyExit(); |
1165 |
|
|
1166 |
+ |
// Delete thunks |
1167 |
+ |
ThunksExit(); |
1168 |
+ |
|
1169 |
+ |
// Delete SheepShaver globals |
1170 |
+ |
SheepMem::Exit(); |
1171 |
+ |
|
1172 |
|
// Delete RAM area |
1173 |
|
if (ram_area_mapped) |
1174 |
|
vm_release((char *)RAM_BASE, RAMSize); |
1177 |
|
if (rom_area_mapped) |
1178 |
|
vm_release((char *)ROM_BASE, ROM_AREA_SIZE); |
1179 |
|
|
1180 |
+ |
// Delete DR cache areas |
1181 |
+ |
if (dr_emulator_area_mapped) |
1182 |
+ |
vm_release((void *)DR_EMULATOR_BASE, DR_EMULATOR_SIZE); |
1183 |
+ |
if (dr_cache_area_mapped) |
1184 |
+ |
vm_release((void *)DR_CACHE_BASE, DR_CACHE_SIZE); |
1185 |
+ |
|
1186 |
|
// Delete Kernel Data area |
1187 |
|
if (kernel_area >= 0) { |
1188 |
|
shmdt((void *)KERNEL_DATA_BASE); |
1210 |
|
#endif |
1211 |
|
|
1212 |
|
// Close X11 server connection |
1213 |
+ |
#ifndef USE_SDL_VIDEO |
1214 |
|
if (x_display) |
1215 |
|
XCloseDisplay(x_display); |
1216 |
+ |
#endif |
1217 |
|
|
1218 |
|
exit(0); |
1219 |
|
} |
1224 |
|
*/ |
1225 |
|
|
1226 |
|
#if EMULATED_PPC |
849 |
– |
extern void emul_ppc(uint32 start); |
850 |
– |
extern void init_emul_ppc(void); |
1227 |
|
void jump_to_rom(uint32 entry) |
1228 |
|
{ |
1229 |
|
init_emul_ppc(); |
1288 |
|
uint16 proc[2] = {trap, M68K_RTS}; |
1289 |
|
Execute68k((uint32)proc, r); |
1290 |
|
} |
915 |
– |
|
916 |
– |
|
917 |
– |
/* |
918 |
– |
* Execute PPC code from EMUL_OP routine (real mode switch) |
919 |
– |
*/ |
920 |
– |
|
921 |
– |
void ExecutePPC(void (*func)()) |
922 |
– |
{ |
923 |
– |
uint32 tvect[2] = {(uint32)func, 0}; // Fake TVECT |
924 |
– |
RoutineDescriptor desc = BUILD_PPC_ROUTINE_DESCRIPTOR(0, tvect); |
925 |
– |
M68kRegisters r; |
926 |
– |
Execute68k((uint32)&desc, &r); |
927 |
– |
} |
1291 |
|
#endif |
1292 |
|
|
1293 |
|
|
1350 |
|
|
1351 |
|
void MakeExecutable(int dummy, void *start, uint32 length) |
1352 |
|
{ |
1353 |
< |
#if !EMULATED_PPC |
991 |
< |
if (((uint32)start >= ROM_BASE) && ((uint32)start < (ROM_BASE + ROM_SIZE))) |
1353 |
> |
if (((uintptr)start >= ROM_BASE) && ((uintptr)start < (ROM_BASE + ROM_SIZE))) |
1354 |
|
return; |
1355 |
< |
flush_icache_range(start, (void *)((uint32)start + length)); |
1355 |
> |
#if EMULATED_PPC |
1356 |
> |
FlushCodeCache((uintptr)start, (uintptr)start + length); |
1357 |
> |
#else |
1358 |
> |
flush_icache_range(start, (void *)((uintptr)start + length)); |
1359 |
|
#endif |
1360 |
|
} |
1361 |
|
|
1366 |
|
|
1367 |
|
void PatchAfterStartup(void) |
1368 |
|
{ |
1004 |
– |
#if EMULATED_PPC |
1369 |
|
ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL); |
1006 |
– |
#else |
1007 |
– |
ExecutePPC(VideoInstallAccel); |
1008 |
– |
#endif |
1370 |
|
InstallExtFS(); |
1371 |
|
} |
1372 |
|
|
1375 |
|
* NVRAM watchdog thread (saves NVRAM every minute) |
1376 |
|
*/ |
1377 |
|
|
1378 |
< |
static void *nvram_func(void *arg) |
1378 |
> |
static void nvram_watchdog(void) |
1379 |
|
{ |
1380 |
< |
struct timespec req = {60, 0}; // 1 minute |
1380 |
> |
if (memcmp(last_xpram, XPRAM, XPRAM_SIZE)) { |
1381 |
> |
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
1382 |
> |
SaveXPRAM(); |
1383 |
> |
} |
1384 |
> |
} |
1385 |
|
|
1386 |
< |
for (;;) { |
1387 |
< |
pthread_testcancel(); |
1388 |
< |
nanosleep(&req, NULL); |
1389 |
< |
pthread_testcancel(); |
1390 |
< |
if (memcmp(last_xpram, XPRAM, XPRAM_SIZE)) { |
1391 |
< |
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
1027 |
< |
SaveXPRAM(); |
1028 |
< |
} |
1386 |
> |
static void *nvram_func(void *arg) |
1387 |
> |
{ |
1388 |
> |
while (!nvram_thread_cancel) { |
1389 |
> |
for (int i=0; i<60 && !nvram_thread_cancel; i++) |
1390 |
> |
Delay_usec(999999); // Only wait 1 second so we quit promptly when nvram_thread_cancel becomes true |
1391 |
> |
nvram_watchdog(); |
1392 |
|
} |
1393 |
|
return NULL; |
1394 |
|
} |
1401 |
|
static void *tick_func(void *arg) |
1402 |
|
{ |
1403 |
|
int tick_counter = 0; |
1404 |
< |
struct timespec req = {0, 16625000}; |
1404 |
> |
uint64 start = GetTicks_usec(); |
1405 |
> |
int64 ticks = 0; |
1406 |
> |
uint64 next = GetTicks_usec(); |
1407 |
|
|
1408 |
< |
for (;;) { |
1408 |
> |
while (!tick_thread_cancel) { |
1409 |
|
|
1410 |
|
// Wait |
1411 |
< |
nanosleep(&req, NULL); |
1411 |
> |
next += 16625; |
1412 |
> |
int64 delay = next - GetTicks_usec(); |
1413 |
> |
if (delay > 0) |
1414 |
> |
Delay_usec(delay); |
1415 |
> |
else if (delay < -16625) |
1416 |
> |
next = GetTicks_usec(); |
1417 |
> |
ticks++; |
1418 |
|
|
1419 |
|
#if !EMULATED_PPC |
1420 |
|
// Did we crash? |
1421 |
|
if (emul_thread_fatal) { |
1422 |
|
|
1423 |
|
// Yes, dump registers |
1424 |
< |
pt_regs *r = (pt_regs *)&sigsegv_regs; |
1424 |
> |
sigregs *r = &sigsegv_regs; |
1425 |
|
char str[256]; |
1426 |
< |
sprintf(str, "SIGSEGV\n" |
1426 |
> |
if (crash_reason == NULL) |
1427 |
> |
crash_reason = "SIGSEGV"; |
1428 |
> |
sprintf(str, "%s\n" |
1429 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
1430 |
|
" xer %08lx cr %08lx \n" |
1431 |
|
" r0 %08lx r1 %08lx r2 %08lx r3 %08lx\n" |
1436 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
1437 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
1438 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
1439 |
+ |
crash_reason, |
1440 |
|
r->nip, r->link, r->ctr, r->msr, |
1441 |
|
r->xer, r->ccr, |
1442 |
|
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
1472 |
|
TriggerInterrupt(); |
1473 |
|
} |
1474 |
|
} |
1475 |
+ |
|
1476 |
+ |
uint64 end = GetTicks_usec(); |
1477 |
+ |
D(bug("%Ld ticks in %Ld usec = %f ticks/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1478 |
|
return NULL; |
1479 |
|
} |
1480 |
|
|
1485 |
|
|
1486 |
|
void Set_pthread_attr(pthread_attr_t *attr, int priority) |
1487 |
|
{ |
1488 |
< |
// nothing to do |
1488 |
> |
#ifdef HAVE_PTHREADS |
1489 |
> |
pthread_attr_init(attr); |
1490 |
> |
#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
1491 |
> |
// Some of these only work for superuser |
1492 |
> |
if (geteuid() == 0) { |
1493 |
> |
pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED); |
1494 |
> |
pthread_attr_setschedpolicy(attr, SCHED_FIFO); |
1495 |
> |
struct sched_param fifo_param; |
1496 |
> |
fifo_param.sched_priority = ((sched_get_priority_min(SCHED_FIFO) + |
1497 |
> |
sched_get_priority_max(SCHED_FIFO)) / 2 + |
1498 |
> |
priority); |
1499 |
> |
pthread_attr_setschedparam(attr, &fifo_param); |
1500 |
> |
} |
1501 |
> |
if (pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0) { |
1502 |
> |
#ifdef PTHREAD_SCOPE_BOUND_NP |
1503 |
> |
// If system scope is not available (eg. we're not running |
1504 |
> |
// with CAP_SCHED_MGT capability on an SGI box), try bound |
1505 |
> |
// scope. It exposes pthread scheduling to the kernel, |
1506 |
> |
// without setting realtime priority. |
1507 |
> |
pthread_attr_setscope(attr, PTHREAD_SCOPE_BOUND_NP); |
1508 |
> |
#endif |
1509 |
> |
} |
1510 |
> |
#endif |
1511 |
> |
#endif |
1512 |
|
} |
1513 |
|
|
1514 |
|
|
1595 |
|
* Trigger signal USR2 from another thread |
1596 |
|
*/ |
1597 |
|
|
1598 |
< |
#if !EMULATED_PPC || ASYNC_IRQ |
1598 |
> |
#if !EMULATED_PPC |
1599 |
|
void TriggerInterrupt(void) |
1600 |
|
{ |
1601 |
|
if (ready_for_signals) |
1627 |
|
|
1628 |
|
void DisableInterrupt(void) |
1629 |
|
{ |
1630 |
+ |
#if EMULATED_PPC |
1631 |
+ |
WriteMacInt32(XLM_IRQ_NEST, int32(ReadMacInt32(XLM_IRQ_NEST)) + 1); |
1632 |
+ |
#else |
1633 |
|
atomic_add((int *)XLM_IRQ_NEST, 1); |
1634 |
+ |
#endif |
1635 |
|
} |
1636 |
|
|
1637 |
|
|
1641 |
|
|
1642 |
|
void EnableInterrupt(void) |
1643 |
|
{ |
1644 |
+ |
#if EMULATED_PPC |
1645 |
+ |
WriteMacInt32(XLM_IRQ_NEST, int32(ReadMacInt32(XLM_IRQ_NEST)) - 1); |
1646 |
+ |
#else |
1647 |
|
atomic_add((int *)XLM_IRQ_NEST, -1); |
1648 |
+ |
#endif |
1649 |
|
} |
1650 |
|
|
1651 |
|
|
1653 |
|
* USR2 handler |
1654 |
|
*/ |
1655 |
|
|
1656 |
< |
#if EMULATED_PPC |
1657 |
< |
static void sigusr2_handler(int sig) |
1656 |
> |
#if !EMULATED_PPC |
1657 |
> |
static void sigusr2_handler(int sig, siginfo_t *sip, void *scp) |
1658 |
|
{ |
1659 |
< |
#if ASYNC_IRQ |
1660 |
< |
extern void HandleInterrupt(void); |
1661 |
< |
HandleInterrupt(); |
1659 |
> |
machine_regs *r = MACHINE_REGISTERS(scp); |
1660 |
> |
|
1661 |
> |
#ifdef USE_SDL_VIDEO |
1662 |
> |
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
1663 |
> |
SDL_PumpEvents(); |
1664 |
|
#endif |
1255 |
– |
} |
1256 |
– |
#else |
1257 |
– |
static void sigusr2_handler(int sig, sigcontext_struct *sc) |
1258 |
– |
{ |
1259 |
– |
pt_regs *r = sc->regs; |
1665 |
|
|
1666 |
|
// Do nothing if interrupts are disabled |
1667 |
|
if (*(int32 *)XLM_IRQ_NEST > 0) |
1675 |
|
case MODE_68K: |
1676 |
|
// 68k emulator active, trigger 68k interrupt level 1 |
1677 |
|
WriteMacInt16(ntohl(kernel_data->v[0x67c >> 2]), 1); |
1678 |
< |
r->ccr |= ntohl(kernel_data->v[0x674 >> 2]); |
1678 |
> |
r->cr() |= ntohl(kernel_data->v[0x674 >> 2]); |
1679 |
|
break; |
1680 |
|
|
1681 |
|
#if INTERRUPTS_IN_NATIVE_MODE |
1682 |
|
case MODE_NATIVE: |
1683 |
|
// 68k emulator inactive, in nanokernel? |
1684 |
< |
if (r->gpr[1] != KernelDataAddr) { |
1684 |
> |
if (r->gpr(1) != KernelDataAddr) { |
1685 |
> |
|
1686 |
> |
// Set extra stack for nested interrupts |
1687 |
> |
sig_stack_acquire(); |
1688 |
> |
|
1689 |
|
// Prepare for 68k interrupt level 1 |
1690 |
|
WriteMacInt16(ntohl(kernel_data->v[0x67c >> 2]), 1); |
1691 |
|
WriteMacInt32(ntohl(kernel_data->v[0x658 >> 2]) + 0xdc, ReadMacInt32(ntohl(kernel_data->v[0x658 >> 2]) + 0xdc) | ntohl(kernel_data->v[0x674 >> 2])); |
1692 |
|
|
1693 |
|
// Execute nanokernel interrupt routine (this will activate the 68k emulator) |
1694 |
< |
atomic_add((int32 *)XLM_IRQ_NEST, 1); |
1694 |
> |
DisableInterrupt(); |
1695 |
|
if (ROMType == ROMTYPE_NEWWORLD) |
1696 |
|
ppc_interrupt(ROM_BASE + 0x312b1c, KernelDataAddr); |
1697 |
|
else |
1698 |
|
ppc_interrupt(ROM_BASE + 0x312a3c, KernelDataAddr); |
1699 |
+ |
|
1700 |
+ |
// Reset normal signal stack |
1701 |
+ |
sig_stack_release(); |
1702 |
|
} |
1703 |
|
break; |
1704 |
|
#endif |
1709 |
|
if ((ReadMacInt32(XLM_68K_R25) & 7) == 0) { |
1710 |
|
|
1711 |
|
// Set extra stack for SIGSEGV handler |
1712 |
< |
struct sigaltstack new_stack; |
1301 |
< |
new_stack.ss_sp = extra_stack; |
1302 |
< |
new_stack.ss_flags = 0; |
1303 |
< |
new_stack.ss_size = SIG_STACK_SIZE; |
1304 |
< |
sigaltstack(&new_stack, NULL); |
1712 |
> |
sig_stack_acquire(); |
1713 |
|
#if 1 |
1714 |
|
// Execute full 68k interrupt routine |
1715 |
|
M68kRegisters r; |
1731 |
|
if (InterruptFlags & INTFLAG_VIA) { |
1732 |
|
ClearInterruptFlag(INTFLAG_VIA); |
1733 |
|
ADBInterrupt(); |
1734 |
< |
ExecutePPC(VideoVBL); |
1734 |
> |
ExecuteNative(NATIVE_VIDEO_VBL); |
1735 |
|
} |
1736 |
|
} |
1737 |
|
#endif |
1738 |
|
// Reset normal signal stack |
1739 |
< |
new_stack.ss_sp = sig_stack; |
1332 |
< |
new_stack.ss_flags = 0; |
1333 |
< |
new_stack.ss_size = SIG_STACK_SIZE; |
1334 |
< |
sigaltstack(&new_stack, NULL); |
1739 |
> |
sig_stack_release(); |
1740 |
|
} |
1741 |
|
break; |
1742 |
|
#endif |
1750 |
|
*/ |
1751 |
|
|
1752 |
|
#if !EMULATED_PPC |
1753 |
< |
static void sigsegv_handler(int sig, sigcontext_struct *sc) |
1753 |
> |
static void sigsegv_handler(int sig, siginfo_t *sip, void *scp) |
1754 |
|
{ |
1755 |
< |
pt_regs *r = sc->regs; |
1755 |
> |
machine_regs *r = MACHINE_REGISTERS(scp); |
1756 |
|
|
1757 |
|
// Get effective address |
1758 |
< |
uint32 addr = r->dar; |
1758 |
> |
uint32 addr = r->dar(); |
1759 |
|
|
1760 |
|
#if ENABLE_VOSF |
1761 |
|
// Handle screen fault. |
1762 |
|
extern bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction); |
1763 |
< |
if (Screen_fault_handler((sigsegv_address_t)addr, (sigsegv_address_t)r->nip)) |
1763 |
> |
if (Screen_fault_handler((sigsegv_address_t)addr, (sigsegv_address_t)r->pc())) |
1764 |
|
return; |
1765 |
|
#endif |
1766 |
|
|
1767 |
|
num_segv++; |
1768 |
|
|
1769 |
< |
// Fault in Mac ROM or RAM? |
1770 |
< |
bool mac_fault = (r->nip >= ROM_BASE) && (r->nip < (ROM_BASE + ROM_AREA_SIZE)) || (r->nip >= RAMBase) && (r->nip < (RAMBase + RAMSize)); |
1769 |
> |
// Fault in Mac ROM or RAM or DR Cache? |
1770 |
> |
bool mac_fault = (r->pc() >= ROM_BASE) && (r->pc() < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)) || (r->pc() >= DR_CACHE_BASE && r->pc() < (DR_CACHE_BASE + DR_CACHE_SIZE)); |
1771 |
|
if (mac_fault) { |
1772 |
|
|
1773 |
|
// "VM settings" during MacOS 8 installation |
1774 |
< |
if (r->nip == ROM_BASE + 0x488160 && r->gpr[20] == 0xf8000000) { |
1775 |
< |
r->nip += 4; |
1776 |
< |
r->gpr[8] = 0; |
1774 |
> |
if (r->pc() == ROM_BASE + 0x488160 && r->gpr(20) == 0xf8000000) { |
1775 |
> |
r->pc() += 4; |
1776 |
> |
r->gpr(8) = 0; |
1777 |
|
return; |
1778 |
|
|
1779 |
|
// MacOS 8.5 installation |
1780 |
< |
} else if (r->nip == ROM_BASE + 0x488140 && r->gpr[16] == 0xf8000000) { |
1781 |
< |
r->nip += 4; |
1782 |
< |
r->gpr[8] = 0; |
1780 |
> |
} else if (r->pc() == ROM_BASE + 0x488140 && r->gpr(16) == 0xf8000000) { |
1781 |
> |
r->pc() += 4; |
1782 |
> |
r->gpr(8) = 0; |
1783 |
|
return; |
1784 |
|
|
1785 |
|
// MacOS 8 serial drivers on startup |
1786 |
< |
} else if (r->nip == ROM_BASE + 0x48e080 && (r->gpr[8] == 0xf3012002 || r->gpr[8] == 0xf3012000)) { |
1787 |
< |
r->nip += 4; |
1788 |
< |
r->gpr[8] = 0; |
1786 |
> |
} else if (r->pc() == ROM_BASE + 0x48e080 && (r->gpr(8) == 0xf3012002 || r->gpr(8) == 0xf3012000)) { |
1787 |
> |
r->pc() += 4; |
1788 |
> |
r->gpr(8) = 0; |
1789 |
|
return; |
1790 |
|
|
1791 |
|
// MacOS 8.1 serial drivers on startup |
1792 |
< |
} else if (r->nip == ROM_BASE + 0x48c5e0 && (r->gpr[20] == 0xf3012002 || r->gpr[20] == 0xf3012000)) { |
1793 |
< |
r->nip += 4; |
1792 |
> |
} else if (r->pc() == ROM_BASE + 0x48c5e0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { |
1793 |
> |
r->pc() += 4; |
1794 |
|
return; |
1795 |
< |
} else if (r->nip == ROM_BASE + 0x4a10a0 && (r->gpr[20] == 0xf3012002 || r->gpr[20] == 0xf3012000)) { |
1796 |
< |
r->nip += 4; |
1795 |
> |
} else if (r->pc() == ROM_BASE + 0x4a10a0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { |
1796 |
> |
r->pc() += 4; |
1797 |
> |
return; |
1798 |
> |
|
1799 |
> |
// MacOS 8.6 serial drivers on startup (with DR Cache and OldWorld ROM) |
1800 |
> |
} else if ((r->pc() - DR_CACHE_BASE) < DR_CACHE_SIZE && (r->gpr(16) == 0xf3012002 || r->gpr(16) == 0xf3012000)) { |
1801 |
> |
r->pc() += 4; |
1802 |
> |
return; |
1803 |
> |
} else if ((r->pc() - DR_CACHE_BASE) < DR_CACHE_SIZE && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { |
1804 |
> |
r->pc() += 4; |
1805 |
|
return; |
1806 |
|
} |
1807 |
|
|
1808 |
|
// Get opcode and divide into fields |
1809 |
< |
uint32 opcode = *((uint32 *)r->nip); |
1809 |
> |
uint32 opcode = *((uint32 *)r->pc()); |
1810 |
|
uint32 primop = opcode >> 26; |
1811 |
|
uint32 exop = (opcode >> 1) & 0x3ff; |
1812 |
|
uint32 ra = (opcode >> 16) & 0x1f; |
1895 |
|
transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_NORM; break; |
1896 |
|
case 45: // sthu |
1897 |
|
transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_U; break; |
1898 |
+ |
#if EMULATE_UNALIGNED_LOADSTORE_MULTIPLE |
1899 |
+ |
case 46: // lmw |
1900 |
+ |
if ((addr % 4) != 0) { |
1901 |
+ |
uint32 ea = addr; |
1902 |
+ |
D(bug("WARNING: unaligned lmw to EA=%08x from IP=%08x\n", ea, r->pc())); |
1903 |
+ |
for (int i = rd; i <= 31; i++) { |
1904 |
+ |
r->gpr(i) = ReadMacInt32(ea); |
1905 |
+ |
ea += 4; |
1906 |
+ |
} |
1907 |
+ |
r->pc() += 4; |
1908 |
+ |
goto rti; |
1909 |
+ |
} |
1910 |
+ |
break; |
1911 |
+ |
case 47: // stmw |
1912 |
+ |
if ((addr % 4) != 0) { |
1913 |
+ |
uint32 ea = addr; |
1914 |
+ |
D(bug("WARNING: unaligned stmw to EA=%08x from IP=%08x\n", ea, r->pc())); |
1915 |
+ |
for (int i = rd; i <= 31; i++) { |
1916 |
+ |
WriteMacInt32(ea, r->gpr(i)); |
1917 |
+ |
ea += 4; |
1918 |
+ |
} |
1919 |
+ |
r->pc() += 4; |
1920 |
+ |
goto rti; |
1921 |
+ |
} |
1922 |
+ |
break; |
1923 |
+ |
#endif |
1924 |
|
} |
1925 |
|
|
1926 |
< |
// Ignore ROM writes |
1927 |
< |
if (transfer_type == TYPE_STORE && addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) { |
1928 |
< |
// D(bug("WARNING: %s write access to ROM at %08lx, pc %08lx\n", transfer_size == SIZE_BYTE ? "Byte" : transfer_size == SIZE_HALFWORD ? "Halfword" : "Word", addr, r->nip)); |
1926 |
> |
// Ignore ROM writes (including to the zero page, which is read-only) |
1927 |
> |
if (transfer_type == TYPE_STORE && |
1928 |
> |
((addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) || |
1929 |
> |
(addr >= SheepMem::ZeroPage() && addr < SheepMem::ZeroPage() + SheepMem::PageSize()))) { |
1930 |
> |
// D(bug("WARNING: %s write access to ROM at %08lx, pc %08lx\n", transfer_size == SIZE_BYTE ? "Byte" : transfer_size == SIZE_HALFWORD ? "Halfword" : "Word", addr, r->pc())); |
1931 |
|
if (addr_mode == MODE_U || addr_mode == MODE_UX) |
1932 |
< |
r->gpr[ra] = addr; |
1933 |
< |
r->nip += 4; |
1932 |
> |
r->gpr(ra) = addr; |
1933 |
> |
r->pc() += 4; |
1934 |
|
goto rti; |
1935 |
|
} |
1936 |
|
|
1937 |
|
// Ignore illegal memory accesses? |
1938 |
|
if (PrefsFindBool("ignoresegv")) { |
1939 |
|
if (addr_mode == MODE_U || addr_mode == MODE_UX) |
1940 |
< |
r->gpr[ra] = addr; |
1940 |
> |
r->gpr(ra) = addr; |
1941 |
|
if (transfer_type == TYPE_LOAD) |
1942 |
< |
r->gpr[rd] = 0; |
1943 |
< |
r->nip += 4; |
1942 |
> |
r->gpr(rd) = 0; |
1943 |
> |
r->pc() += 4; |
1944 |
|
goto rti; |
1945 |
|
} |
1946 |
|
|
1948 |
|
if (!PrefsFindBool("nogui")) { |
1949 |
|
char str[256]; |
1950 |
|
if (transfer_type == TYPE_LOAD || transfer_type == TYPE_STORE) |
1951 |
< |
sprintf(str, GetString(STR_MEM_ACCESS_ERR), transfer_size == SIZE_BYTE ? "byte" : transfer_size == SIZE_HALFWORD ? "halfword" : "word", transfer_type == TYPE_LOAD ? GetString(STR_MEM_ACCESS_READ) : GetString(STR_MEM_ACCESS_WRITE), addr, r->nip, r->gpr[24], r->gpr[1]); |
1951 |
> |
sprintf(str, GetString(STR_MEM_ACCESS_ERR), transfer_size == SIZE_BYTE ? "byte" : transfer_size == SIZE_HALFWORD ? "halfword" : "word", transfer_type == TYPE_LOAD ? GetString(STR_MEM_ACCESS_READ) : GetString(STR_MEM_ACCESS_WRITE), addr, r->pc(), r->gpr(24), r->gpr(1)); |
1952 |
|
else |
1953 |
< |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->nip, r->gpr[24], r->gpr[1], opcode); |
1953 |
> |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->pc(), r->gpr(24), r->gpr(1), opcode); |
1954 |
|
ErrorAlert(str); |
1955 |
|
QuitEmulator(); |
1956 |
|
return; |
1958 |
|
} |
1959 |
|
|
1960 |
|
// For all other errors, jump into debugger (sort of...) |
1961 |
+ |
crash_reason = (sig == SIGBUS) ? "SIGBUS" : "SIGSEGV"; |
1962 |
|
if (!ready_for_signals) { |
1963 |
< |
printf("SIGSEGV\n"); |
1964 |
< |
printf(" sigcontext %p, pt_regs %p\n", sc, r); |
1963 |
> |
printf("%s\n"); |
1964 |
> |
printf(" sigcontext %p, machine_regs %p\n", scp, r); |
1965 |
|
printf( |
1966 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
1967 |
|
" xer %08lx cr %08lx \n" |
1973 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
1974 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
1975 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
1976 |
< |
r->nip, r->link, r->ctr, r->msr, |
1977 |
< |
r->xer, r->ccr, |
1978 |
< |
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
1979 |
< |
r->gpr[4], r->gpr[5], r->gpr[6], r->gpr[7], |
1980 |
< |
r->gpr[8], r->gpr[9], r->gpr[10], r->gpr[11], |
1981 |
< |
r->gpr[12], r->gpr[13], r->gpr[14], r->gpr[15], |
1982 |
< |
r->gpr[16], r->gpr[17], r->gpr[18], r->gpr[19], |
1983 |
< |
r->gpr[20], r->gpr[21], r->gpr[22], r->gpr[23], |
1984 |
< |
r->gpr[24], r->gpr[25], r->gpr[26], r->gpr[27], |
1985 |
< |
r->gpr[28], r->gpr[29], r->gpr[30], r->gpr[31]); |
1976 |
> |
crash_reason, |
1977 |
> |
r->pc(), r->lr(), r->ctr(), r->msr(), |
1978 |
> |
r->xer(), r->cr(), |
1979 |
> |
r->gpr(0), r->gpr(1), r->gpr(2), r->gpr(3), |
1980 |
> |
r->gpr(4), r->gpr(5), r->gpr(6), r->gpr(7), |
1981 |
> |
r->gpr(8), r->gpr(9), r->gpr(10), r->gpr(11), |
1982 |
> |
r->gpr(12), r->gpr(13), r->gpr(14), r->gpr(15), |
1983 |
> |
r->gpr(16), r->gpr(17), r->gpr(18), r->gpr(19), |
1984 |
> |
r->gpr(20), r->gpr(21), r->gpr(22), r->gpr(23), |
1985 |
> |
r->gpr(24), r->gpr(25), r->gpr(26), r->gpr(27), |
1986 |
> |
r->gpr(28), r->gpr(29), r->gpr(30), r->gpr(31)); |
1987 |
|
exit(1); |
1988 |
|
QuitEmulator(); |
1989 |
|
return; |
1990 |
|
} else { |
1991 |
|
// We crashed. Save registers, tell tick thread and loop forever |
1992 |
< |
sigsegv_regs = *(sigregs *)r; |
1992 |
> |
build_sigregs(&sigsegv_regs, r); |
1993 |
|
emul_thread_fatal = true; |
1994 |
|
for (;;) ; |
1995 |
|
} |
2001 |
|
* SIGILL handler |
2002 |
|
*/ |
2003 |
|
|
2004 |
< |
static void sigill_handler(int sig, sigcontext_struct *sc) |
2004 |
> |
static void sigill_handler(int sig, siginfo_t *sip, void *scp) |
2005 |
|
{ |
2006 |
< |
pt_regs *r = sc->regs; |
2006 |
> |
machine_regs *r = MACHINE_REGISTERS(scp); |
2007 |
|
char str[256]; |
2008 |
|
|
2009 |
|
// Fault in Mac ROM or RAM? |
2010 |
< |
bool mac_fault = (r->nip >= ROM_BASE) && (r->nip < (ROM_BASE + ROM_AREA_SIZE)) || (r->nip >= RAMBase) && (r->nip < (RAMBase + RAMSize)); |
2010 |
> |
bool mac_fault = (r->pc() >= ROM_BASE) && (r->pc() < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)); |
2011 |
|
if (mac_fault) { |
2012 |
|
|
2013 |
|
// Get opcode and divide into fields |
2014 |
< |
uint32 opcode = *((uint32 *)r->nip); |
2014 |
> |
uint32 opcode = *((uint32 *)r->pc()); |
2015 |
|
uint32 primop = opcode >> 26; |
2016 |
|
uint32 exop = (opcode >> 1) & 0x3ff; |
2017 |
|
uint32 ra = (opcode >> 16) & 0x1f; |
2022 |
|
switch (primop) { |
2023 |
|
case 9: // POWER instructions |
2024 |
|
case 22: |
2025 |
< |
power_inst: sprintf(str, GetString(STR_POWER_INSTRUCTION_ERR), r->nip, r->gpr[1], opcode); |
2025 |
> |
power_inst: sprintf(str, GetString(STR_POWER_INSTRUCTION_ERR), r->pc(), r->gpr(1), opcode); |
2026 |
|
ErrorAlert(str); |
2027 |
|
QuitEmulator(); |
2028 |
|
return; |
2030 |
|
case 31: |
2031 |
|
switch (exop) { |
2032 |
|
case 83: // mfmsr |
2033 |
< |
r->gpr[rd] = 0xf072; |
2034 |
< |
r->nip += 4; |
2033 |
> |
r->gpr(rd) = 0xf072; |
2034 |
> |
r->pc() += 4; |
2035 |
|
goto rti; |
2036 |
|
|
2037 |
|
case 210: // mtsr |
2038 |
|
case 242: // mtsrin |
2039 |
|
case 306: // tlbie |
2040 |
< |
r->nip += 4; |
2040 |
> |
r->pc() += 4; |
2041 |
|
goto rti; |
2042 |
|
|
2043 |
|
case 339: { // mfspr |
2053 |
|
case 957: // PMC3 |
2054 |
|
case 958: // PMC4 |
2055 |
|
case 959: // SDA |
2056 |
< |
r->nip += 4; |
2056 |
> |
r->pc() += 4; |
2057 |
|
goto rti; |
2058 |
|
case 25: // SDR1 |
2059 |
< |
r->gpr[rd] = 0xdead001f; |
2060 |
< |
r->nip += 4; |
2059 |
> |
r->gpr(rd) = 0xdead001f; |
2060 |
> |
r->pc() += 4; |
2061 |
|
goto rti; |
2062 |
|
case 287: // PVR |
2063 |
< |
r->gpr[rd] = PVR; |
2064 |
< |
r->nip += 4; |
2063 |
> |
r->gpr(rd) = PVR; |
2064 |
> |
r->pc() += 4; |
2065 |
|
goto rti; |
2066 |
|
} |
2067 |
|
break; |
2097 |
|
case 957: // PMC3 |
2098 |
|
case 958: // PMC4 |
2099 |
|
case 959: // SDA |
2100 |
< |
r->nip += 4; |
2100 |
> |
r->pc() += 4; |
2101 |
|
goto rti; |
2102 |
|
} |
2103 |
|
break; |
2116 |
|
|
2117 |
|
// In GUI mode, show error alert |
2118 |
|
if (!PrefsFindBool("nogui")) { |
2119 |
< |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->nip, r->gpr[24], r->gpr[1], opcode); |
2119 |
> |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->pc(), r->gpr(24), r->gpr(1), opcode); |
2120 |
|
ErrorAlert(str); |
2121 |
|
QuitEmulator(); |
2122 |
|
return; |
2124 |
|
} |
2125 |
|
|
2126 |
|
// For all other errors, jump into debugger (sort of...) |
2127 |
+ |
crash_reason = "SIGILL"; |
2128 |
|
if (!ready_for_signals) { |
2129 |
< |
printf("SIGILL\n"); |
2130 |
< |
printf(" sigcontext %p, pt_regs %p\n", sc, r); |
2129 |
> |
printf("%s\n"); |
2130 |
> |
printf(" sigcontext %p, machine_regs %p\n", scp, r); |
2131 |
|
printf( |
2132 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
2133 |
|
" xer %08lx cr %08lx \n" |
2139 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
2140 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
2141 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
2142 |
< |
r->nip, r->link, r->ctr, r->msr, |
2143 |
< |
r->xer, r->ccr, |
2144 |
< |
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
2145 |
< |
r->gpr[4], r->gpr[5], r->gpr[6], r->gpr[7], |
2146 |
< |
r->gpr[8], r->gpr[9], r->gpr[10], r->gpr[11], |
2147 |
< |
r->gpr[12], r->gpr[13], r->gpr[14], r->gpr[15], |
2148 |
< |
r->gpr[16], r->gpr[17], r->gpr[18], r->gpr[19], |
2149 |
< |
r->gpr[20], r->gpr[21], r->gpr[22], r->gpr[23], |
2150 |
< |
r->gpr[24], r->gpr[25], r->gpr[26], r->gpr[27], |
2151 |
< |
r->gpr[28], r->gpr[29], r->gpr[30], r->gpr[31]); |
2142 |
> |
crash_reason, |
2143 |
> |
r->pc(), r->lr(), r->ctr(), r->msr(), |
2144 |
> |
r->xer(), r->cr(), |
2145 |
> |
r->gpr(0), r->gpr(1), r->gpr(2), r->gpr(3), |
2146 |
> |
r->gpr(4), r->gpr(5), r->gpr(6), r->gpr(7), |
2147 |
> |
r->gpr(8), r->gpr(9), r->gpr(10), r->gpr(11), |
2148 |
> |
r->gpr(12), r->gpr(13), r->gpr(14), r->gpr(15), |
2149 |
> |
r->gpr(16), r->gpr(17), r->gpr(18), r->gpr(19), |
2150 |
> |
r->gpr(20), r->gpr(21), r->gpr(22), r->gpr(23), |
2151 |
> |
r->gpr(24), r->gpr(25), r->gpr(26), r->gpr(27), |
2152 |
> |
r->gpr(28), r->gpr(29), r->gpr(30), r->gpr(31)); |
2153 |
|
exit(1); |
2154 |
|
QuitEmulator(); |
2155 |
|
return; |
2156 |
|
} else { |
2157 |
|
// We crashed. Save registers, tell tick thread and loop forever |
2158 |
< |
sigsegv_regs = *(sigregs *)r; |
2158 |
> |
build_sigregs(&sigsegv_regs, r); |
2159 |
|
emul_thread_fatal = true; |
2160 |
|
for (;;) ; |
2161 |
|
} |
2165 |
|
|
2166 |
|
|
2167 |
|
/* |
2168 |
+ |
* Helpers to share 32-bit addressable data with MacOS |
2169 |
+ |
*/ |
2170 |
+ |
|
2171 |
+ |
bool SheepMem::Init(void) |
2172 |
+ |
{ |
2173 |
+ |
// Size of a native page |
2174 |
+ |
page_size = getpagesize(); |
2175 |
+ |
|
2176 |
+ |
// Allocate SheepShaver globals |
2177 |
+ |
if (vm_acquire_fixed((char *)base, size) < 0) |
2178 |
+ |
return false; |
2179 |
+ |
|
2180 |
+ |
// Allocate page with all bits set to 0 |
2181 |
+ |
zero_page = base + size; |
2182 |
+ |
if (vm_acquire_fixed((char *)zero_page, page_size) < 0) |
2183 |
+ |
return false; |
2184 |
+ |
memset((char *)zero_page, 0, page_size); |
2185 |
+ |
if (vm_protect((char *)zero_page, page_size, VM_PAGE_READ) < 0) |
2186 |
+ |
return false; |
2187 |
+ |
|
2188 |
+ |
#if EMULATED_PPC |
2189 |
+ |
// Allocate alternate stack for PowerPC interrupt routine |
2190 |
+ |
sig_stack = zero_page + page_size; |
2191 |
+ |
if (vm_acquire_fixed((char *)sig_stack, SIG_STACK_SIZE) < 0) |
2192 |
+ |
return false; |
2193 |
+ |
#endif |
2194 |
+ |
|
2195 |
+ |
top = base + size; |
2196 |
+ |
return true; |
2197 |
+ |
} |
2198 |
+ |
|
2199 |
+ |
void SheepMem::Exit(void) |
2200 |
+ |
{ |
2201 |
+ |
if (top) { |
2202 |
+ |
// Delete SheepShaver globals |
2203 |
+ |
vm_release((void *)base, size); |
2204 |
+ |
|
2205 |
+ |
// Delete zero page |
2206 |
+ |
vm_release((void *)zero_page, page_size); |
2207 |
+ |
|
2208 |
+ |
#if EMULATED_PPC |
2209 |
+ |
// Delete alternate stack for PowerPC interrupt routine |
2210 |
+ |
vm_release((void *)sig_stack, SIG_STACK_SIZE); |
2211 |
+ |
#endif |
2212 |
+ |
} |
2213 |
+ |
} |
2214 |
+ |
|
2215 |
+ |
|
2216 |
+ |
/* |
2217 |
|
* Display alert |
2218 |
|
*/ |
2219 |
|
|
2262 |
|
|
2263 |
|
void ErrorAlert(const char *text) |
2264 |
|
{ |
2265 |
< |
#ifdef ENABLE_GTK |
2265 |
> |
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) |
2266 |
|
if (PrefsFindBool("nogui") || x_display == NULL) { |
2267 |
|
printf(GetString(STR_SHELL_ERROR_PREFIX), text); |
2268 |
|
return; |
2281 |
|
|
2282 |
|
void WarningAlert(const char *text) |
2283 |
|
{ |
2284 |
< |
#ifdef ENABLE_GTK |
2284 |
> |
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) |
2285 |
|
if (PrefsFindBool("nogui") || x_display == NULL) { |
2286 |
|
printf(GetString(STR_SHELL_WARNING_PREFIX), text); |
2287 |
|
return; |