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 |
+ |
#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 |
226 |
– |
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 |
|
|
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 |
|
|
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 |
+ |
// CPU specs from Linux kernel |
616 |
+ |
// TODO: make it more generic with features (e.g. AltiVec) and |
617 |
+ |
// cache information and friends for NameRegistry |
618 |
+ |
static const struct { |
619 |
+ |
uint32 pvr_mask; |
620 |
+ |
uint32 pvr_value; |
621 |
+ |
const char *cpu_name; |
622 |
+ |
} |
623 |
+ |
cpu_specs[] = { |
624 |
+ |
{ 0xffff0000, 0x00010000, "601" }, |
625 |
+ |
{ 0xffff0000, 0x00030000, "603" }, |
626 |
+ |
{ 0xffff0000, 0x00060000, "603e" }, |
627 |
+ |
{ 0xffff0000, 0x00070000, "603ev" }, |
628 |
+ |
{ 0xffff0000, 0x00040000, "604" }, |
629 |
+ |
{ 0xfffff000, 0x00090000, "604e" }, |
630 |
+ |
{ 0xffff0000, 0x00090000, "604r" }, |
631 |
+ |
{ 0xffff0000, 0x000a0000, "604ev" }, |
632 |
+ |
{ 0xffffffff, 0x00084202, "740/750" }, |
633 |
+ |
{ 0xfffff000, 0x00083000, "745/755" }, |
634 |
+ |
{ 0xfffffff0, 0x00080100, "750CX" }, |
635 |
+ |
{ 0xfffffff0, 0x00082200, "750CX" }, |
636 |
+ |
{ 0xfffffff0, 0x00082210, "750CXe" }, |
637 |
+ |
{ 0xffffff00, 0x70000100, "750FX" }, |
638 |
+ |
{ 0xffffffff, 0x70000200, "750FX" }, |
639 |
+ |
{ 0xffff0000, 0x70000000, "750FX" }, |
640 |
+ |
{ 0xffff0000, 0x70020000, "750GX" }, |
641 |
+ |
{ 0xffff0000, 0x00080000, "740/750" }, |
642 |
+ |
{ 0xffffffff, 0x000c1101, "7400 (1.1)" }, |
643 |
+ |
{ 0xffff0000, 0x000c0000, "7400" }, |
644 |
+ |
{ 0xffff0000, 0x800c0000, "7410" }, |
645 |
+ |
{ 0xffffffff, 0x80000200, "7450" }, |
646 |
+ |
{ 0xffffffff, 0x80000201, "7450" }, |
647 |
+ |
{ 0xffff0000, 0x80000000, "7450" }, |
648 |
+ |
{ 0xffffff00, 0x80010100, "7455" }, |
649 |
+ |
{ 0xffffffff, 0x80010200, "7455" }, |
650 |
+ |
{ 0xffff0000, 0x80010000, "7455" }, |
651 |
+ |
{ 0xffff0000, 0x80020000, "7457" }, |
652 |
+ |
{ 0xffff0000, 0x80030000, "7447A" }, |
653 |
+ |
{ 0x7fff0000, 0x00810000, "82xx" }, |
654 |
+ |
{ 0x7fff0000, 0x00820000, "8280" }, |
655 |
+ |
{ 0xffff0000, 0x00400000, "Power3 (630)" }, |
656 |
+ |
{ 0xffff0000, 0x00410000, "Power3 (630+)" }, |
657 |
+ |
{ 0xffff0000, 0x00360000, "I-star" }, |
658 |
+ |
{ 0xffff0000, 0x00370000, "S-star" }, |
659 |
+ |
{ 0xffff0000, 0x00350000, "Power4" }, |
660 |
+ |
{ 0xffff0000, 0x00390000, "PPC970" }, |
661 |
+ |
{ 0, 0, 0 } |
662 |
+ |
}; |
663 |
+ |
|
664 |
|
char line[256]; |
665 |
|
while(fgets(line, 255, proc_file)) { |
666 |
|
// Read line |
672 |
|
// Parse line |
673 |
|
int i; |
674 |
|
char value[256]; |
675 |
< |
if (sscanf(line, "cpu : %s", value) == 1) { |
676 |
< |
if (strcmp(value, "601") == 0) |
677 |
< |
PVR = 0x00010000; |
678 |
< |
else if (strcmp(value, "603") == 0) |
679 |
< |
PVR = 0x00030000; |
680 |
< |
else if (strcmp(value, "604") == 0) |
681 |
< |
PVR = 0x00040000; |
682 |
< |
else if (strcmp(value, "603e") == 0) |
683 |
< |
PVR = 0x00060000; |
684 |
< |
else if (strcmp(value, "603ev") == 0) |
685 |
< |
PVR = 0x00070000; |
403 |
< |
else if (strcmp(value, "604e") == 0) |
404 |
< |
PVR = 0x00090000; |
405 |
< |
else if (strcmp(value, "604ev5") == 0) |
406 |
< |
PVR = 0x000a0000; |
407 |
< |
else if (strcmp(value, "750") == 0) |
408 |
< |
PVR = 0x00080000; |
409 |
< |
else if (strcmp(value, "821") == 0) |
410 |
< |
PVR = 0x00320000; |
411 |
< |
else if (strcmp(value, "860") == 0) |
412 |
< |
PVR = 0x00500000; |
413 |
< |
else |
675 |
> |
if (sscanf(line, "cpu : %[0-9A-Za-a]", value) == 1) { |
676 |
> |
// Search by name |
677 |
> |
const char *cpu_name = NULL; |
678 |
> |
for (int i = 0; cpu_specs[i].pvr_mask != 0; i++) { |
679 |
> |
if (strcmp(cpu_specs[i].cpu_name, value) == 0) { |
680 |
> |
cpu_name = cpu_specs[i].cpu_name; |
681 |
> |
PVR = cpu_specs[i].pvr_value; |
682 |
> |
break; |
683 |
> |
} |
684 |
> |
} |
685 |
> |
if (cpu_name == NULL) |
686 |
|
printf("WARNING: Unknown CPU type '%s', assuming 604\n", value); |
687 |
+ |
else |
688 |
+ |
printf("Found a PowerPC %s processor\n", cpu_name); |
689 |
|
} |
690 |
|
if (sscanf(line, "clock : %dMHz", &i) == 1) |
691 |
|
CPUClockSpeed = BusClockSpeed = i * 1000000; |
695 |
|
sprintf(str, GetString(STR_PROC_CPUINFO_WARN), strerror(errno)); |
696 |
|
WarningAlert(str); |
697 |
|
} |
698 |
+ |
|
699 |
+ |
// Get actual bus frequency |
700 |
+ |
proc_file = fopen("/proc/device-tree/clock-frequency", "r"); |
701 |
+ |
if (proc_file) { |
702 |
+ |
union { uint8 b[4]; uint32 l; } value; |
703 |
+ |
if (fread(value.b, sizeof(value), 1, proc_file) == 1) |
704 |
+ |
BusClockSpeed = value.l; |
705 |
+ |
fclose(proc_file); |
706 |
+ |
} |
707 |
+ |
|
708 |
+ |
// Get actual timebase frequency |
709 |
+ |
TimebaseSpeed = BusClockSpeed / 4; |
710 |
+ |
DIR *cpus_dir; |
711 |
+ |
if ((cpus_dir = opendir("/proc/device-tree/cpus")) != NULL) { |
712 |
+ |
struct dirent *cpu_entry; |
713 |
+ |
while ((cpu_entry = readdir(cpus_dir)) != NULL) { |
714 |
+ |
if (strstr(cpu_entry->d_name, "PowerPC,") == cpu_entry->d_name) { |
715 |
+ |
char timebase_freq_node[256]; |
716 |
+ |
sprintf(timebase_freq_node, "/proc/device-tree/cpus/%s/timebase-frequency", cpu_entry->d_name); |
717 |
+ |
proc_file = fopen(timebase_freq_node, "r"); |
718 |
+ |
if (proc_file) { |
719 |
+ |
union { uint8 b[4]; uint32 l; } value; |
720 |
+ |
if (fread(value.b, sizeof(value), 1, proc_file) == 1) |
721 |
+ |
TimebaseSpeed = value.l; |
722 |
+ |
fclose(proc_file); |
723 |
+ |
} |
724 |
+ |
} |
725 |
+ |
} |
726 |
+ |
closedir(cpus_dir); |
727 |
+ |
} |
728 |
|
#endif |
729 |
+ |
// Remap any newer G4/G5 processor to plain G4 for compatibility |
730 |
+ |
switch (PVR >> 16) { |
731 |
+ |
case 0x8000: // 7450 |
732 |
+ |
case 0x8001: // 7455 |
733 |
+ |
case 0x8002: // 7457 |
734 |
+ |
case 0x0039: // 970 |
735 |
+ |
PVR = 0x000c0000; // 7400 |
736 |
+ |
break; |
737 |
+ |
} |
738 |
|
D(bug("PVR: %08x (assumed)\n", PVR)); |
739 |
|
|
740 |
|
// Init system routines |
758 |
|
goto quit; |
759 |
|
} |
760 |
|
|
761 |
+ |
#ifndef PAGEZERO_HACK |
762 |
|
// Create Low Memory area (0x0000..0x3000) |
763 |
|
if (vm_acquire_fixed((char *)0, 0x3000) < 0) { |
764 |
|
sprintf(str, GetString(STR_LOW_MEM_MMAP_ERR), strerror(errno)); |
766 |
|
goto quit; |
767 |
|
} |
768 |
|
lm_area_mapped = true; |
769 |
+ |
#endif |
770 |
|
|
771 |
|
// Create areas for Kernel Data |
772 |
|
kernel_area = shmget(IPC_PRIVATE, KERNEL_AREA_SIZE, 0600); |
785 |
|
ErrorAlert(str); |
786 |
|
goto quit; |
787 |
|
} |
788 |
< |
kernel_data = (KernelData *)0x68ffe000; |
788 |
> |
kernel_data = (KernelData *)KERNEL_DATA_BASE; |
789 |
|
emulator_data = &kernel_data->ed; |
790 |
< |
KernelDataAddr = (uint32)kernel_data; |
790 |
> |
KernelDataAddr = KERNEL_DATA_BASE; |
791 |
|
D(bug("Kernel Data at %p, Emulator Data at %p\n", kernel_data, emulator_data)); |
792 |
|
|
793 |
+ |
// Create area for DR Cache |
794 |
+ |
if (vm_acquire_fixed((void *)DR_EMULATOR_BASE, DR_EMULATOR_SIZE) < 0) { |
795 |
+ |
sprintf(str, GetString(STR_DR_EMULATOR_MMAP_ERR), strerror(errno)); |
796 |
+ |
ErrorAlert(str); |
797 |
+ |
goto quit; |
798 |
+ |
} |
799 |
+ |
dr_emulator_area_mapped = true; |
800 |
+ |
if (vm_acquire_fixed((void *)DR_CACHE_BASE, DR_CACHE_SIZE) < 0) { |
801 |
+ |
sprintf(str, GetString(STR_DR_CACHE_MMAP_ERR), strerror(errno)); |
802 |
+ |
ErrorAlert(str); |
803 |
+ |
goto quit; |
804 |
+ |
} |
805 |
+ |
dr_cache_area_mapped = true; |
806 |
+ |
#if !EMULATED_PPC |
807 |
+ |
if (vm_protect((char *)DR_CACHE_BASE, DR_CACHE_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) { |
808 |
+ |
sprintf(str, GetString(STR_DR_CACHE_MMAP_ERR), strerror(errno)); |
809 |
+ |
ErrorAlert(str); |
810 |
+ |
goto quit; |
811 |
+ |
} |
812 |
+ |
#endif |
813 |
+ |
DRCacheAddr = DR_CACHE_BASE; |
814 |
+ |
D(bug("DR Cache at %p\n", DRCacheAddr)); |
815 |
+ |
|
816 |
|
// Create area for SheepShaver data |
817 |
< |
if (vm_acquire_fixed((char *)SHEEP_BASE, SHEEP_SIZE) < 0) { |
817 |
> |
if (!SheepMem::Init()) { |
818 |
|
sprintf(str, GetString(STR_SHEEP_MEM_MMAP_ERR), strerror(errno)); |
819 |
|
ErrorAlert(str); |
820 |
|
goto quit; |
821 |
|
} |
484 |
– |
SheepStack1Base = SHEEP_BASE + 0x10000; |
485 |
– |
SheepStack2Base = SheepStack1Base + 0x10000; |
486 |
– |
SheepThunksBase = SheepStack2Base + 0x1000; |
487 |
– |
sheep_area_mapped = true; |
822 |
|
|
823 |
|
// Create area for Mac ROM |
824 |
|
if (vm_acquire_fixed((char *)ROM_BASE, ROM_AREA_SIZE) < 0) { |
826 |
|
ErrorAlert(str); |
827 |
|
goto quit; |
828 |
|
} |
829 |
< |
#if !EMULATED_PPC || defined(__powerpc__) |
829 |
> |
#if !EMULATED_PPC |
830 |
|
if (vm_protect((char *)ROM_BASE, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) { |
831 |
|
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); |
832 |
|
ErrorAlert(str); |
896 |
|
// Load NVRAM |
897 |
|
XPRAMInit(); |
898 |
|
|
899 |
+ |
// Load XPRAM default values if signature not found |
900 |
+ |
if (XPRAM[0x130c] != 0x4e || XPRAM[0x130d] != 0x75 |
901 |
+ |
|| XPRAM[0x130e] != 0x4d || XPRAM[0x130f] != 0x63) { |
902 |
+ |
D(bug("Loading XPRAM default values\n")); |
903 |
+ |
memset(XPRAM + 0x1300, 0, 0x100); |
904 |
+ |
XPRAM[0x130c] = 0x4e; // "NuMc" signature |
905 |
+ |
XPRAM[0x130d] = 0x75; |
906 |
+ |
XPRAM[0x130e] = 0x4d; |
907 |
+ |
XPRAM[0x130f] = 0x63; |
908 |
+ |
XPRAM[0x1301] = 0x80; // InternalWaitFlags = DynWait (don't wait for SCSI devices upon bootup) |
909 |
+ |
XPRAM[0x1310] = 0xa8; // Standard PRAM values |
910 |
+ |
XPRAM[0x1311] = 0x00; |
911 |
+ |
XPRAM[0x1312] = 0x00; |
912 |
+ |
XPRAM[0x1313] = 0x22; |
913 |
+ |
XPRAM[0x1314] = 0xcc; |
914 |
+ |
XPRAM[0x1315] = 0x0a; |
915 |
+ |
XPRAM[0x1316] = 0xcc; |
916 |
+ |
XPRAM[0x1317] = 0x0a; |
917 |
+ |
XPRAM[0x131c] = 0x00; |
918 |
+ |
XPRAM[0x131d] = 0x02; |
919 |
+ |
XPRAM[0x131e] = 0x63; |
920 |
+ |
XPRAM[0x131f] = 0x00; |
921 |
+ |
XPRAM[0x1308] = 0x13; |
922 |
+ |
XPRAM[0x1309] = 0x88; |
923 |
+ |
XPRAM[0x130a] = 0x00; |
924 |
+ |
XPRAM[0x130b] = 0xcc; |
925 |
+ |
XPRAM[0x1376] = 0x00; // OSDefault = MacOS |
926 |
+ |
XPRAM[0x1377] = 0x01; |
927 |
+ |
} |
928 |
+ |
|
929 |
|
// Set boot volume |
930 |
|
i16 = PrefsFindInt32("bootdrive"); |
931 |
|
XPRAM[0x1378] = i16 >> 8; |
943 |
|
boot_globs[1] = htonl(RAMSize); |
944 |
|
boot_globs[2] = htonl((uint32)-1); // End of bank table |
945 |
|
|
946 |
+ |
// Init thunks |
947 |
+ |
if (!ThunksInit()) |
948 |
+ |
goto quit; |
949 |
+ |
|
950 |
|
// Init drivers |
951 |
|
SonyInit(); |
952 |
|
DiskInit(); |
956 |
|
// Init external file system |
957 |
|
ExtFSInit(); |
958 |
|
|
959 |
+ |
// Init ADB |
960 |
+ |
ADBInit(); |
961 |
+ |
|
962 |
|
// Init audio |
963 |
|
AudioInit(); |
964 |
|
|
993 |
|
// Initialize Kernel Data |
994 |
|
memset(kernel_data, 0, sizeof(KernelData)); |
995 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
996 |
< |
static uint32 of_dev_tree[4] = {0, 0, 0, 0}; |
997 |
< |
static uint8 vector_lookup_tbl[128]; |
998 |
< |
static uint8 vector_mask_tbl[64]; |
996 |
> |
uintptr of_dev_tree = SheepMem::Reserve(4 * sizeof(uint32)); |
997 |
> |
memset((void *)of_dev_tree, 0, 4 * sizeof(uint32)); |
998 |
> |
uintptr vector_lookup_tbl = SheepMem::Reserve(128); |
999 |
> |
uintptr vector_mask_tbl = SheepMem::Reserve(64); |
1000 |
|
memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80); |
1001 |
< |
memset(vector_lookup_tbl, 0, 128); |
1002 |
< |
memset(vector_mask_tbl, 0, 64); |
1001 |
> |
memset((void *)vector_lookup_tbl, 0, 128); |
1002 |
> |
memset((void *)vector_mask_tbl, 0, 64); |
1003 |
|
kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE); |
1004 |
< |
kernel_data->v[0xb84 >> 2] = htonl((uint32)of_dev_tree); // OF device tree base |
1005 |
< |
kernel_data->v[0xb90 >> 2] = htonl((uint32)vector_lookup_tbl); |
1006 |
< |
kernel_data->v[0xb94 >> 2] = htonl((uint32)vector_mask_tbl); |
1004 |
> |
kernel_data->v[0xb84 >> 2] = htonl(of_dev_tree); // OF device tree base |
1005 |
> |
kernel_data->v[0xb90 >> 2] = htonl(vector_lookup_tbl); |
1006 |
> |
kernel_data->v[0xb94 >> 2] = htonl(vector_mask_tbl); |
1007 |
|
kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE); // OpenPIC base |
1008 |
|
kernel_data->v[0xbb0 >> 2] = htonl(0); // ADB base |
1009 |
|
kernel_data->v[0xc20 >> 2] = htonl(RAMSize); |
1016 |
|
kernel_data->v[0xc50 >> 2] = htonl(RAMBase); |
1017 |
|
kernel_data->v[0xc54 >> 2] = htonl(RAMSize); |
1018 |
|
kernel_data->v[0xf60 >> 2] = htonl(PVR); |
1019 |
< |
kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed); |
1020 |
< |
kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed); |
1021 |
< |
kernel_data->v[0xf6c >> 2] = htonl(CPUClockSpeed); |
1019 |
> |
kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed); // clock-frequency |
1020 |
> |
kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed); // bus-frequency |
1021 |
> |
kernel_data->v[0xf6c >> 2] = htonl(TimebaseSpeed); // timebase-frequency |
1022 |
|
} else { |
1023 |
|
kernel_data->v[0xc80 >> 2] = htonl(RAMSize); |
1024 |
|
kernel_data->v[0xc84 >> 2] = htonl(RAMSize); |
1030 |
|
kernel_data->v[0xcb0 >> 2] = htonl(RAMBase); |
1031 |
|
kernel_data->v[0xcb4 >> 2] = htonl(RAMSize); |
1032 |
|
kernel_data->v[0xf80 >> 2] = htonl(PVR); |
1033 |
< |
kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed); |
1034 |
< |
kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed); |
1035 |
< |
kernel_data->v[0xf8c >> 2] = htonl(CPUClockSpeed); |
1033 |
> |
kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed); // clock-frequency |
1034 |
> |
kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed); // bus-frequency |
1035 |
> |
kernel_data->v[0xf8c >> 2] = htonl(TimebaseSpeed); // timebase-frequency |
1036 |
|
} |
1037 |
|
|
1038 |
|
// Initialize extra low memory |
1039 |
|
D(bug("Initializing Low Memory...\n")); |
1040 |
|
memset(NULL, 0, 0x3000); |
1041 |
|
WriteMacInt32(XLM_SIGNATURE, FOURCC('B','a','a','h')); // Signature to detect SheepShaver |
1042 |
< |
WriteMacInt32(XLM_KERNEL_DATA, (uint32)kernel_data); // For trap replacement routines |
1042 |
> |
WriteMacInt32(XLM_KERNEL_DATA, KernelDataAddr); // For trap replacement routines |
1043 |
|
WriteMacInt32(XLM_PVR, PVR); // Theoretical PVR |
1044 |
|
WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch |
1045 |
|
WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode) |
1046 |
< |
#if EMULATED_PPC |
1047 |
< |
WriteMacInt32(XLM_ETHER_INIT, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_INIT)); |
1048 |
< |
WriteMacInt32(XLM_ETHER_TERM, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_TERM)); |
677 |
< |
WriteMacInt32(XLM_ETHER_OPEN, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_OPEN)); |
678 |
< |
WriteMacInt32(XLM_ETHER_CLOSE, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_CLOSE)); |
679 |
< |
WriteMacInt32(XLM_ETHER_WPUT, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_WPUT)); |
680 |
< |
WriteMacInt32(XLM_ETHER_RSRV, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_RSRV)); |
681 |
< |
WriteMacInt32(XLM_VIDEO_DOIO, POWERPC_NATIVE_OP_FUNC(NATIVE_VIDEO_DO_DRIVER_IO)); |
682 |
< |
#else |
683 |
< |
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator |
684 |
< |
WriteMacInt32(XLM_ETHER_INIT, (uint32)InitStreamModule); // DLPI ethernet driver functions |
685 |
< |
WriteMacInt32(XLM_ETHER_TERM, (uint32)TerminateStreamModule); |
686 |
< |
WriteMacInt32(XLM_ETHER_OPEN, (uint32)ether_open); |
687 |
< |
WriteMacInt32(XLM_ETHER_CLOSE, (uint32)ether_close); |
688 |
< |
WriteMacInt32(XLM_ETHER_WPUT, (uint32)ether_wput); |
689 |
< |
WriteMacInt32(XLM_ETHER_RSRV, (uint32)ether_rsrv); |
690 |
< |
WriteMacInt32(XLM_VIDEO_DOIO, (uint32)VideoDoDriverIO); |
1046 |
> |
WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage()); // Pointer to read-only page with all bits set to 0 |
1047 |
> |
#if !EMULATED_PPC |
1048 |
> |
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator |
1049 |
|
#endif |
1050 |
+ |
WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT)); // DLPI ethernet driver functions |
1051 |
+ |
WriteMacInt32(XLM_ETHER_TERM, NativeFunction(NATIVE_ETHER_TERM)); |
1052 |
+ |
WriteMacInt32(XLM_ETHER_OPEN, NativeFunction(NATIVE_ETHER_OPEN)); |
1053 |
+ |
WriteMacInt32(XLM_ETHER_CLOSE, NativeFunction(NATIVE_ETHER_CLOSE)); |
1054 |
+ |
WriteMacInt32(XLM_ETHER_WPUT, NativeFunction(NATIVE_ETHER_WPUT)); |
1055 |
+ |
WriteMacInt32(XLM_ETHER_RSRV, NativeFunction(NATIVE_ETHER_RSRV)); |
1056 |
+ |
WriteMacInt32(XLM_VIDEO_DOIO, NativeFunction(NATIVE_VIDEO_DO_DRIVER_IO)); |
1057 |
|
D(bug("Low Memory initialized\n")); |
1058 |
|
|
1059 |
|
// Start 60Hz thread |
1060 |
+ |
tick_thread_cancel = false; |
1061 |
|
tick_thread_active = (pthread_create(&tick_thread, NULL, tick_func, NULL) == 0); |
1062 |
|
D(bug("Tick thread installed (%ld)\n", tick_thread)); |
1063 |
|
|
1064 |
|
// Start NVRAM watchdog thread |
1065 |
|
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
1066 |
+ |
nvram_thread_cancel = false; |
1067 |
|
nvram_thread_active = (pthread_create(&nvram_thread, NULL, nvram_func, NULL) == 0); |
1068 |
|
D(bug("NVRAM thread installed (%ld)\n", nvram_thread)); |
1069 |
|
|
1070 |
|
#if !EMULATED_PPC |
704 |
– |
// Create and install stacks for signal handlers |
705 |
– |
sig_stack = malloc(SIG_STACK_SIZE); |
706 |
– |
D(bug("Signal stack at %p\n", sig_stack)); |
707 |
– |
if (sig_stack == NULL) { |
708 |
– |
ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); |
709 |
– |
goto quit; |
710 |
– |
} |
711 |
– |
extra_stack = malloc(SIG_STACK_SIZE); |
712 |
– |
D(bug("Extra stack at %p\n", extra_stack)); |
713 |
– |
if (extra_stack == NULL) { |
714 |
– |
ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); |
715 |
– |
goto quit; |
716 |
– |
} |
717 |
– |
struct sigaltstack new_stack; |
718 |
– |
new_stack.ss_sp = sig_stack; |
719 |
– |
new_stack.ss_flags = 0; |
720 |
– |
new_stack.ss_size = SIG_STACK_SIZE; |
721 |
– |
if (sigaltstack(&new_stack, NULL) < 0) { |
722 |
– |
sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno)); |
723 |
– |
ErrorAlert(str); |
724 |
– |
goto quit; |
725 |
– |
} |
726 |
– |
#endif |
727 |
– |
|
728 |
– |
#if !EMULATED_PPC |
729 |
– |
// Install SIGSEGV handler |
730 |
– |
sigemptyset(&sigsegv_action.sa_mask); // Block interrupts during SEGV handling |
731 |
– |
sigaddset(&sigsegv_action.sa_mask, SIGUSR2); |
732 |
– |
sigsegv_action.sa_handler = (__sighandler_t)sigsegv_handler; |
733 |
– |
sigsegv_action.sa_flags = SA_ONSTACK; |
734 |
– |
sigsegv_action.sa_restorer = NULL; |
735 |
– |
if (sigaction(SIGSEGV, &sigsegv_action, NULL) < 0) { |
736 |
– |
sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); |
737 |
– |
ErrorAlert(str); |
738 |
– |
goto quit; |
739 |
– |
} |
740 |
– |
|
1071 |
|
// Install SIGILL handler |
1072 |
|
sigemptyset(&sigill_action.sa_mask); // Block interrupts during ILL handling |
1073 |
|
sigaddset(&sigill_action.sa_mask, SIGUSR2); |
1074 |
< |
sigill_action.sa_handler = (__sighandler_t)sigill_handler; |
1075 |
< |
sigill_action.sa_flags = SA_ONSTACK; |
1074 |
> |
sigill_action.sa_sigaction = sigill_handler; |
1075 |
> |
sigill_action.sa_flags = SA_ONSTACK | SA_SIGINFO; |
1076 |
> |
#ifdef HAVE_SIGNAL_SA_RESTORER |
1077 |
|
sigill_action.sa_restorer = NULL; |
1078 |
+ |
#endif |
1079 |
|
if (sigaction(SIGILL, &sigill_action, NULL) < 0) { |
1080 |
|
sprintf(str, GetString(STR_SIGILL_INSTALL_ERR), strerror(errno)); |
1081 |
|
ErrorAlert(str); |
1083 |
|
} |
1084 |
|
#endif |
1085 |
|
|
1086 |
+ |
#if !EMULATED_PPC |
1087 |
|
// Install interrupt signal handler |
1088 |
|
sigemptyset(&sigusr2_action.sa_mask); |
1089 |
< |
sigusr2_action.sa_handler = (__sighandler_t)sigusr2_handler; |
1090 |
< |
sigusr2_action.sa_flags = 0; |
1091 |
< |
#if !EMULATED_PPC |
759 |
< |
sigusr2_action.sa_flags = SA_ONSTACK | SA_RESTART; |
760 |
< |
#endif |
1089 |
> |
sigusr2_action.sa_sigaction = sigusr2_handler; |
1090 |
> |
sigusr2_action.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; |
1091 |
> |
#ifdef HAVE_SIGNAL_SA_RESTORER |
1092 |
|
sigusr2_action.sa_restorer = NULL; |
1093 |
+ |
#endif |
1094 |
|
if (sigaction(SIGUSR2, &sigusr2_action, NULL) < 0) { |
1095 |
|
sprintf(str, GetString(STR_SIGUSR2_INSTALL_ERR), strerror(errno)); |
1096 |
|
ErrorAlert(str); |
1097 |
|
goto quit; |
1098 |
|
} |
1099 |
+ |
#endif |
1100 |
|
|
1101 |
|
// Get my thread ID and execute MacOS thread function |
1102 |
|
emul_thread = pthread_self(); |
1122 |
|
|
1123 |
|
// Stop 60Hz thread |
1124 |
|
if (tick_thread_active) { |
1125 |
+ |
tick_thread_cancel = true; |
1126 |
|
pthread_cancel(tick_thread); |
1127 |
|
pthread_join(tick_thread, NULL); |
1128 |
|
} |
1129 |
|
|
1130 |
|
// Stop NVRAM watchdog thread |
1131 |
|
if (nvram_thread_active) { |
1132 |
+ |
nvram_thread_cancel = true; |
1133 |
|
pthread_cancel(nvram_thread); |
1134 |
|
pthread_join(nvram_thread, NULL); |
1135 |
|
} |
1136 |
|
|
1137 |
|
#if !EMULATED_PPC |
1138 |
< |
// Uninstall SIGSEGV handler |
1138 |
> |
// Uninstall SIGSEGV and SIGBUS handlers |
1139 |
|
sigemptyset(&sigsegv_action.sa_mask); |
1140 |
|
sigsegv_action.sa_handler = SIG_DFL; |
1141 |
|
sigsegv_action.sa_flags = 0; |
1142 |
|
sigaction(SIGSEGV, &sigsegv_action, NULL); |
1143 |
+ |
sigaction(SIGBUS, &sigsegv_action, NULL); |
1144 |
|
|
1145 |
|
// Uninstall SIGILL handler |
1146 |
|
sigemptyset(&sigill_action.sa_mask); |
1147 |
|
sigill_action.sa_handler = SIG_DFL; |
1148 |
|
sigill_action.sa_flags = 0; |
1149 |
|
sigaction(SIGILL, &sigill_action, NULL); |
1150 |
+ |
|
1151 |
+ |
// Delete stacks for signal handlers |
1152 |
+ |
for (int i = 0; i < SIG_STACK_COUNT; i++) { |
1153 |
+ |
void *sig_stack = sig_stacks[i].ss_sp; |
1154 |
+ |
if (sig_stack) |
1155 |
+ |
free(sig_stack); |
1156 |
+ |
} |
1157 |
|
#endif |
1158 |
|
|
1159 |
|
// Save NVRAM |
1174 |
|
// Exit audio |
1175 |
|
AudioExit(); |
1176 |
|
|
1177 |
+ |
// Exit ADB |
1178 |
+ |
ADBExit(); |
1179 |
+ |
|
1180 |
|
// Exit video |
1181 |
|
VideoExit(); |
1182 |
|
|
1189 |
|
DiskExit(); |
1190 |
|
SonyExit(); |
1191 |
|
|
1192 |
+ |
// Delete thunks |
1193 |
+ |
ThunksExit(); |
1194 |
+ |
|
1195 |
+ |
// Delete SheepShaver globals |
1196 |
+ |
SheepMem::Exit(); |
1197 |
+ |
|
1198 |
|
// Delete RAM area |
1199 |
|
if (ram_area_mapped) |
1200 |
|
vm_release((char *)RAM_BASE, RAMSize); |
1203 |
|
if (rom_area_mapped) |
1204 |
|
vm_release((char *)ROM_BASE, ROM_AREA_SIZE); |
1205 |
|
|
1206 |
+ |
// Delete DR cache areas |
1207 |
+ |
if (dr_emulator_area_mapped) |
1208 |
+ |
vm_release((void *)DR_EMULATOR_BASE, DR_EMULATOR_SIZE); |
1209 |
+ |
if (dr_cache_area_mapped) |
1210 |
+ |
vm_release((void *)DR_CACHE_BASE, DR_CACHE_SIZE); |
1211 |
+ |
|
1212 |
|
// Delete Kernel Data area |
1213 |
|
if (kernel_area >= 0) { |
1214 |
|
shmdt((void *)KERNEL_DATA_BASE); |
1236 |
|
#endif |
1237 |
|
|
1238 |
|
// Close X11 server connection |
1239 |
+ |
#ifndef USE_SDL_VIDEO |
1240 |
|
if (x_display) |
1241 |
|
XCloseDisplay(x_display); |
1242 |
+ |
#endif |
1243 |
|
|
1244 |
|
exit(0); |
1245 |
|
} |
1314 |
|
uint16 proc[2] = {trap, M68K_RTS}; |
1315 |
|
Execute68k((uint32)proc, r); |
1316 |
|
} |
957 |
– |
|
958 |
– |
|
959 |
– |
/* |
960 |
– |
* Execute PPC code from EMUL_OP routine (real mode switch) |
961 |
– |
*/ |
962 |
– |
|
963 |
– |
void ExecutePPC(void (*func)()) |
964 |
– |
{ |
965 |
– |
uint32 tvect[2] = {(uint32)func, 0}; // Fake TVECT |
966 |
– |
RoutineDescriptor desc = BUILD_PPC_ROUTINE_DESCRIPTOR(0, tvect); |
967 |
– |
M68kRegisters r; |
968 |
– |
Execute68k((uint32)&desc, &r); |
969 |
– |
} |
1317 |
|
#endif |
1318 |
|
|
1319 |
|
|
1392 |
|
|
1393 |
|
void PatchAfterStartup(void) |
1394 |
|
{ |
1048 |
– |
#if EMULATED_PPC |
1395 |
|
ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL); |
1050 |
– |
#else |
1051 |
– |
ExecutePPC(VideoInstallAccel); |
1052 |
– |
#endif |
1396 |
|
InstallExtFS(); |
1397 |
|
} |
1398 |
|
|
1401 |
|
* NVRAM watchdog thread (saves NVRAM every minute) |
1402 |
|
*/ |
1403 |
|
|
1404 |
< |
static void *nvram_func(void *arg) |
1404 |
> |
static void nvram_watchdog(void) |
1405 |
|
{ |
1406 |
< |
struct timespec req = {60, 0}; // 1 minute |
1406 |
> |
if (memcmp(last_xpram, XPRAM, XPRAM_SIZE)) { |
1407 |
> |
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
1408 |
> |
SaveXPRAM(); |
1409 |
> |
} |
1410 |
> |
} |
1411 |
|
|
1412 |
< |
for (;;) { |
1413 |
< |
pthread_testcancel(); |
1414 |
< |
nanosleep(&req, NULL); |
1415 |
< |
pthread_testcancel(); |
1416 |
< |
if (memcmp(last_xpram, XPRAM, XPRAM_SIZE)) { |
1417 |
< |
memcpy(last_xpram, XPRAM, XPRAM_SIZE); |
1071 |
< |
SaveXPRAM(); |
1072 |
< |
} |
1412 |
> |
static void *nvram_func(void *arg) |
1413 |
> |
{ |
1414 |
> |
while (!nvram_thread_cancel) { |
1415 |
> |
for (int i=0; i<60 && !nvram_thread_cancel; i++) |
1416 |
> |
Delay_usec(999999); // Only wait 1 second so we quit promptly when nvram_thread_cancel becomes true |
1417 |
> |
nvram_watchdog(); |
1418 |
|
} |
1419 |
|
return NULL; |
1420 |
|
} |
1427 |
|
static void *tick_func(void *arg) |
1428 |
|
{ |
1429 |
|
int tick_counter = 0; |
1430 |
< |
struct timespec req = {0, 16625000}; |
1430 |
> |
uint64 start = GetTicks_usec(); |
1431 |
> |
int64 ticks = 0; |
1432 |
> |
uint64 next = GetTicks_usec(); |
1433 |
|
|
1434 |
< |
for (;;) { |
1434 |
> |
while (!tick_thread_cancel) { |
1435 |
|
|
1436 |
|
// Wait |
1437 |
< |
nanosleep(&req, NULL); |
1437 |
> |
next += 16625; |
1438 |
> |
int64 delay = next - GetTicks_usec(); |
1439 |
> |
if (delay > 0) |
1440 |
> |
Delay_usec(delay); |
1441 |
> |
else if (delay < -16625) |
1442 |
> |
next = GetTicks_usec(); |
1443 |
> |
ticks++; |
1444 |
|
|
1445 |
|
#if !EMULATED_PPC |
1446 |
|
// Did we crash? |
1447 |
|
if (emul_thread_fatal) { |
1448 |
|
|
1449 |
|
// Yes, dump registers |
1450 |
< |
pt_regs *r = (pt_regs *)&sigsegv_regs; |
1450 |
> |
sigregs *r = &sigsegv_regs; |
1451 |
|
char str[256]; |
1452 |
< |
sprintf(str, "SIGSEGV\n" |
1452 |
> |
if (crash_reason == NULL) |
1453 |
> |
crash_reason = "SIGSEGV"; |
1454 |
> |
sprintf(str, "%s\n" |
1455 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
1456 |
|
" xer %08lx cr %08lx \n" |
1457 |
|
" r0 %08lx r1 %08lx r2 %08lx r3 %08lx\n" |
1462 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
1463 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
1464 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
1465 |
+ |
crash_reason, |
1466 |
|
r->nip, r->link, r->ctr, r->msr, |
1467 |
|
r->xer, r->ccr, |
1468 |
|
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
1498 |
|
TriggerInterrupt(); |
1499 |
|
} |
1500 |
|
} |
1501 |
+ |
|
1502 |
+ |
uint64 end = GetTicks_usec(); |
1503 |
+ |
D(bug("%Ld ticks in %Ld usec = %f ticks/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1504 |
|
return NULL; |
1505 |
|
} |
1506 |
|
|
1511 |
|
|
1512 |
|
void Set_pthread_attr(pthread_attr_t *attr, int priority) |
1513 |
|
{ |
1514 |
< |
// nothing to do |
1514 |
> |
#ifdef HAVE_PTHREADS |
1515 |
> |
pthread_attr_init(attr); |
1516 |
> |
#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
1517 |
> |
// Some of these only work for superuser |
1518 |
> |
if (geteuid() == 0) { |
1519 |
> |
pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED); |
1520 |
> |
pthread_attr_setschedpolicy(attr, SCHED_FIFO); |
1521 |
> |
struct sched_param fifo_param; |
1522 |
> |
fifo_param.sched_priority = ((sched_get_priority_min(SCHED_FIFO) + |
1523 |
> |
sched_get_priority_max(SCHED_FIFO)) / 2 + |
1524 |
> |
priority); |
1525 |
> |
pthread_attr_setschedparam(attr, &fifo_param); |
1526 |
> |
} |
1527 |
> |
if (pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0) { |
1528 |
> |
#ifdef PTHREAD_SCOPE_BOUND_NP |
1529 |
> |
// If system scope is not available (eg. we're not running |
1530 |
> |
// with CAP_SCHED_MGT capability on an SGI box), try bound |
1531 |
> |
// scope. It exposes pthread scheduling to the kernel, |
1532 |
> |
// without setting realtime priority. |
1533 |
> |
pthread_attr_setscope(attr, PTHREAD_SCOPE_BOUND_NP); |
1534 |
> |
#endif |
1535 |
> |
} |
1536 |
> |
#endif |
1537 |
> |
#endif |
1538 |
|
} |
1539 |
|
|
1540 |
|
|
1621 |
|
* Trigger signal USR2 from another thread |
1622 |
|
*/ |
1623 |
|
|
1624 |
< |
#if !EMULATED_PPC || ASYNC_IRQ |
1624 |
> |
#if !EMULATED_PPC |
1625 |
|
void TriggerInterrupt(void) |
1626 |
|
{ |
1627 |
|
if (ready_for_signals) |
1653 |
|
|
1654 |
|
void DisableInterrupt(void) |
1655 |
|
{ |
1656 |
+ |
#if EMULATED_PPC |
1657 |
+ |
WriteMacInt32(XLM_IRQ_NEST, int32(ReadMacInt32(XLM_IRQ_NEST)) + 1); |
1658 |
+ |
#else |
1659 |
|
atomic_add((int *)XLM_IRQ_NEST, 1); |
1660 |
+ |
#endif |
1661 |
|
} |
1662 |
|
|
1663 |
|
|
1667 |
|
|
1668 |
|
void EnableInterrupt(void) |
1669 |
|
{ |
1670 |
+ |
#if EMULATED_PPC |
1671 |
+ |
WriteMacInt32(XLM_IRQ_NEST, int32(ReadMacInt32(XLM_IRQ_NEST)) - 1); |
1672 |
+ |
#else |
1673 |
|
atomic_add((int *)XLM_IRQ_NEST, -1); |
1674 |
+ |
#endif |
1675 |
|
} |
1676 |
|
|
1677 |
|
|
1679 |
|
* USR2 handler |
1680 |
|
*/ |
1681 |
|
|
1682 |
< |
#if EMULATED_PPC |
1683 |
< |
static void sigusr2_handler(int sig) |
1682 |
> |
#if !EMULATED_PPC |
1683 |
> |
static void sigusr2_handler(int sig, siginfo_t *sip, void *scp) |
1684 |
|
{ |
1685 |
< |
#if ASYNC_IRQ |
1686 |
< |
extern void HandleInterrupt(void); |
1687 |
< |
HandleInterrupt(); |
1685 |
> |
machine_regs *r = MACHINE_REGISTERS(scp); |
1686 |
> |
|
1687 |
> |
#ifdef USE_SDL_VIDEO |
1688 |
> |
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
1689 |
> |
SDL_PumpEvents(); |
1690 |
|
#endif |
1299 |
– |
} |
1300 |
– |
#else |
1301 |
– |
static void sigusr2_handler(int sig, sigcontext_struct *sc) |
1302 |
– |
{ |
1303 |
– |
pt_regs *r = sc->regs; |
1691 |
|
|
1692 |
|
// Do nothing if interrupts are disabled |
1693 |
|
if (*(int32 *)XLM_IRQ_NEST > 0) |
1701 |
|
case MODE_68K: |
1702 |
|
// 68k emulator active, trigger 68k interrupt level 1 |
1703 |
|
WriteMacInt16(ntohl(kernel_data->v[0x67c >> 2]), 1); |
1704 |
< |
r->ccr |= ntohl(kernel_data->v[0x674 >> 2]); |
1704 |
> |
r->cr() |= ntohl(kernel_data->v[0x674 >> 2]); |
1705 |
|
break; |
1706 |
|
|
1707 |
|
#if INTERRUPTS_IN_NATIVE_MODE |
1708 |
|
case MODE_NATIVE: |
1709 |
|
// 68k emulator inactive, in nanokernel? |
1710 |
< |
if (r->gpr[1] != KernelDataAddr) { |
1710 |
> |
if (r->gpr(1) != KernelDataAddr) { |
1711 |
> |
|
1712 |
> |
// Set extra stack for nested interrupts |
1713 |
> |
sig_stack_acquire(); |
1714 |
> |
|
1715 |
|
// Prepare for 68k interrupt level 1 |
1716 |
|
WriteMacInt16(ntohl(kernel_data->v[0x67c >> 2]), 1); |
1717 |
|
WriteMacInt32(ntohl(kernel_data->v[0x658 >> 2]) + 0xdc, ReadMacInt32(ntohl(kernel_data->v[0x658 >> 2]) + 0xdc) | ntohl(kernel_data->v[0x674 >> 2])); |
1718 |
|
|
1719 |
|
// Execute nanokernel interrupt routine (this will activate the 68k emulator) |
1720 |
< |
atomic_add((int32 *)XLM_IRQ_NEST, 1); |
1720 |
> |
DisableInterrupt(); |
1721 |
|
if (ROMType == ROMTYPE_NEWWORLD) |
1722 |
|
ppc_interrupt(ROM_BASE + 0x312b1c, KernelDataAddr); |
1723 |
|
else |
1724 |
|
ppc_interrupt(ROM_BASE + 0x312a3c, KernelDataAddr); |
1725 |
+ |
|
1726 |
+ |
// Reset normal signal stack |
1727 |
+ |
sig_stack_release(); |
1728 |
|
} |
1729 |
|
break; |
1730 |
|
#endif |
1735 |
|
if ((ReadMacInt32(XLM_68K_R25) & 7) == 0) { |
1736 |
|
|
1737 |
|
// Set extra stack for SIGSEGV handler |
1738 |
< |
struct sigaltstack new_stack; |
1345 |
< |
new_stack.ss_sp = extra_stack; |
1346 |
< |
new_stack.ss_flags = 0; |
1347 |
< |
new_stack.ss_size = SIG_STACK_SIZE; |
1348 |
< |
sigaltstack(&new_stack, NULL); |
1738 |
> |
sig_stack_acquire(); |
1739 |
|
#if 1 |
1740 |
|
// Execute full 68k interrupt routine |
1741 |
|
M68kRegisters r; |
1757 |
|
if (InterruptFlags & INTFLAG_VIA) { |
1758 |
|
ClearInterruptFlag(INTFLAG_VIA); |
1759 |
|
ADBInterrupt(); |
1760 |
< |
ExecutePPC(VideoVBL); |
1760 |
> |
ExecuteNative(NATIVE_VIDEO_VBL); |
1761 |
|
} |
1762 |
|
} |
1763 |
|
#endif |
1764 |
|
// Reset normal signal stack |
1765 |
< |
new_stack.ss_sp = sig_stack; |
1376 |
< |
new_stack.ss_flags = 0; |
1377 |
< |
new_stack.ss_size = SIG_STACK_SIZE; |
1378 |
< |
sigaltstack(&new_stack, NULL); |
1765 |
> |
sig_stack_release(); |
1766 |
|
} |
1767 |
|
break; |
1768 |
|
#endif |
1776 |
|
*/ |
1777 |
|
|
1778 |
|
#if !EMULATED_PPC |
1779 |
< |
static void sigsegv_handler(int sig, sigcontext_struct *sc) |
1779 |
> |
static void sigsegv_handler(int sig, siginfo_t *sip, void *scp) |
1780 |
|
{ |
1781 |
< |
pt_regs *r = sc->regs; |
1781 |
> |
machine_regs *r = MACHINE_REGISTERS(scp); |
1782 |
|
|
1783 |
|
// Get effective address |
1784 |
< |
uint32 addr = r->dar; |
1784 |
> |
uint32 addr = r->dar(); |
1785 |
|
|
1786 |
|
#if ENABLE_VOSF |
1787 |
|
// Handle screen fault. |
1788 |
|
extern bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction); |
1789 |
< |
if (Screen_fault_handler((sigsegv_address_t)addr, (sigsegv_address_t)r->nip)) |
1789 |
> |
if (Screen_fault_handler((sigsegv_address_t)addr, (sigsegv_address_t)r->pc())) |
1790 |
|
return; |
1791 |
|
#endif |
1792 |
|
|
1793 |
|
num_segv++; |
1794 |
|
|
1795 |
< |
// Fault in Mac ROM or RAM? |
1796 |
< |
bool mac_fault = (r->nip >= ROM_BASE) && (r->nip < (ROM_BASE + ROM_AREA_SIZE)) || (r->nip >= RAMBase) && (r->nip < (RAMBase + RAMSize)); |
1795 |
> |
// Fault in Mac ROM or RAM or DR Cache? |
1796 |
> |
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)); |
1797 |
|
if (mac_fault) { |
1798 |
|
|
1799 |
|
// "VM settings" during MacOS 8 installation |
1800 |
< |
if (r->nip == ROM_BASE + 0x488160 && r->gpr[20] == 0xf8000000) { |
1801 |
< |
r->nip += 4; |
1802 |
< |
r->gpr[8] = 0; |
1800 |
> |
if (r->pc() == ROM_BASE + 0x488160 && r->gpr(20) == 0xf8000000) { |
1801 |
> |
r->pc() += 4; |
1802 |
> |
r->gpr(8) = 0; |
1803 |
|
return; |
1804 |
|
|
1805 |
|
// MacOS 8.5 installation |
1806 |
< |
} else if (r->nip == ROM_BASE + 0x488140 && r->gpr[16] == 0xf8000000) { |
1807 |
< |
r->nip += 4; |
1808 |
< |
r->gpr[8] = 0; |
1806 |
> |
} else if (r->pc() == ROM_BASE + 0x488140 && r->gpr(16) == 0xf8000000) { |
1807 |
> |
r->pc() += 4; |
1808 |
> |
r->gpr(8) = 0; |
1809 |
|
return; |
1810 |
|
|
1811 |
|
// MacOS 8 serial drivers on startup |
1812 |
< |
} else if (r->nip == ROM_BASE + 0x48e080 && (r->gpr[8] == 0xf3012002 || r->gpr[8] == 0xf3012000)) { |
1813 |
< |
r->nip += 4; |
1814 |
< |
r->gpr[8] = 0; |
1812 |
> |
} else if (r->pc() == ROM_BASE + 0x48e080 && (r->gpr(8) == 0xf3012002 || r->gpr(8) == 0xf3012000)) { |
1813 |
> |
r->pc() += 4; |
1814 |
> |
r->gpr(8) = 0; |
1815 |
|
return; |
1816 |
|
|
1817 |
|
// MacOS 8.1 serial drivers on startup |
1818 |
< |
} else if (r->nip == ROM_BASE + 0x48c5e0 && (r->gpr[20] == 0xf3012002 || r->gpr[20] == 0xf3012000)) { |
1819 |
< |
r->nip += 4; |
1818 |
> |
} else if (r->pc() == ROM_BASE + 0x48c5e0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { |
1819 |
> |
r->pc() += 4; |
1820 |
> |
return; |
1821 |
> |
} else if (r->pc() == ROM_BASE + 0x4a10a0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { |
1822 |
> |
r->pc() += 4; |
1823 |
> |
return; |
1824 |
> |
|
1825 |
> |
// MacOS 8.6 serial drivers on startup (with DR Cache and OldWorld ROM) |
1826 |
> |
} else if ((r->pc() - DR_CACHE_BASE) < DR_CACHE_SIZE && (r->gpr(16) == 0xf3012002 || r->gpr(16) == 0xf3012000)) { |
1827 |
> |
r->pc() += 4; |
1828 |
|
return; |
1829 |
< |
} else if (r->nip == ROM_BASE + 0x4a10a0 && (r->gpr[20] == 0xf3012002 || r->gpr[20] == 0xf3012000)) { |
1830 |
< |
r->nip += 4; |
1829 |
> |
} else if ((r->pc() - DR_CACHE_BASE) < DR_CACHE_SIZE && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { |
1830 |
> |
r->pc() += 4; |
1831 |
|
return; |
1832 |
|
} |
1833 |
|
|
1834 |
|
// Get opcode and divide into fields |
1835 |
< |
uint32 opcode = *((uint32 *)r->nip); |
1835 |
> |
uint32 opcode = *((uint32 *)r->pc()); |
1836 |
|
uint32 primop = opcode >> 26; |
1837 |
|
uint32 exop = (opcode >> 1) & 0x3ff; |
1838 |
|
uint32 ra = (opcode >> 16) & 0x1f; |
1921 |
|
transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_NORM; break; |
1922 |
|
case 45: // sthu |
1923 |
|
transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_U; break; |
1924 |
+ |
#if EMULATE_UNALIGNED_LOADSTORE_MULTIPLE |
1925 |
+ |
case 46: // lmw |
1926 |
+ |
if ((addr % 4) != 0) { |
1927 |
+ |
uint32 ea = addr; |
1928 |
+ |
D(bug("WARNING: unaligned lmw to EA=%08x from IP=%08x\n", ea, r->pc())); |
1929 |
+ |
for (int i = rd; i <= 31; i++) { |
1930 |
+ |
r->gpr(i) = ReadMacInt32(ea); |
1931 |
+ |
ea += 4; |
1932 |
+ |
} |
1933 |
+ |
r->pc() += 4; |
1934 |
+ |
goto rti; |
1935 |
+ |
} |
1936 |
+ |
break; |
1937 |
+ |
case 47: // stmw |
1938 |
+ |
if ((addr % 4) != 0) { |
1939 |
+ |
uint32 ea = addr; |
1940 |
+ |
D(bug("WARNING: unaligned stmw to EA=%08x from IP=%08x\n", ea, r->pc())); |
1941 |
+ |
for (int i = rd; i <= 31; i++) { |
1942 |
+ |
WriteMacInt32(ea, r->gpr(i)); |
1943 |
+ |
ea += 4; |
1944 |
+ |
} |
1945 |
+ |
r->pc() += 4; |
1946 |
+ |
goto rti; |
1947 |
+ |
} |
1948 |
+ |
break; |
1949 |
+ |
#endif |
1950 |
|
} |
1951 |
|
|
1952 |
< |
// Ignore ROM writes |
1953 |
< |
if (transfer_type == TYPE_STORE && addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) { |
1954 |
< |
// 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)); |
1952 |
> |
// Ignore ROM writes (including to the zero page, which is read-only) |
1953 |
> |
if (transfer_type == TYPE_STORE && |
1954 |
> |
((addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) || |
1955 |
> |
(addr >= SheepMem::ZeroPage() && addr < SheepMem::ZeroPage() + SheepMem::PageSize()))) { |
1956 |
> |
// 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())); |
1957 |
|
if (addr_mode == MODE_U || addr_mode == MODE_UX) |
1958 |
< |
r->gpr[ra] = addr; |
1959 |
< |
r->nip += 4; |
1958 |
> |
r->gpr(ra) = addr; |
1959 |
> |
r->pc() += 4; |
1960 |
|
goto rti; |
1961 |
|
} |
1962 |
|
|
1963 |
|
// Ignore illegal memory accesses? |
1964 |
|
if (PrefsFindBool("ignoresegv")) { |
1965 |
|
if (addr_mode == MODE_U || addr_mode == MODE_UX) |
1966 |
< |
r->gpr[ra] = addr; |
1966 |
> |
r->gpr(ra) = addr; |
1967 |
|
if (transfer_type == TYPE_LOAD) |
1968 |
< |
r->gpr[rd] = 0; |
1969 |
< |
r->nip += 4; |
1968 |
> |
r->gpr(rd) = 0; |
1969 |
> |
r->pc() += 4; |
1970 |
|
goto rti; |
1971 |
|
} |
1972 |
|
|
1974 |
|
if (!PrefsFindBool("nogui")) { |
1975 |
|
char str[256]; |
1976 |
|
if (transfer_type == TYPE_LOAD || transfer_type == TYPE_STORE) |
1977 |
< |
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]); |
1977 |
> |
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)); |
1978 |
|
else |
1979 |
< |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->nip, r->gpr[24], r->gpr[1], opcode); |
1979 |
> |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->pc(), r->gpr(24), r->gpr(1), opcode); |
1980 |
|
ErrorAlert(str); |
1981 |
|
QuitEmulator(); |
1982 |
|
return; |
1984 |
|
} |
1985 |
|
|
1986 |
|
// For all other errors, jump into debugger (sort of...) |
1987 |
+ |
crash_reason = (sig == SIGBUS) ? "SIGBUS" : "SIGSEGV"; |
1988 |
|
if (!ready_for_signals) { |
1989 |
< |
printf("SIGSEGV\n"); |
1990 |
< |
printf(" sigcontext %p, pt_regs %p\n", sc, r); |
1989 |
> |
printf("%s\n"); |
1990 |
> |
printf(" sigcontext %p, machine_regs %p\n", scp, r); |
1991 |
|
printf( |
1992 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
1993 |
|
" xer %08lx cr %08lx \n" |
1999 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
2000 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
2001 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
2002 |
< |
r->nip, r->link, r->ctr, r->msr, |
2003 |
< |
r->xer, r->ccr, |
2004 |
< |
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
2005 |
< |
r->gpr[4], r->gpr[5], r->gpr[6], r->gpr[7], |
2006 |
< |
r->gpr[8], r->gpr[9], r->gpr[10], r->gpr[11], |
2007 |
< |
r->gpr[12], r->gpr[13], r->gpr[14], r->gpr[15], |
2008 |
< |
r->gpr[16], r->gpr[17], r->gpr[18], r->gpr[19], |
2009 |
< |
r->gpr[20], r->gpr[21], r->gpr[22], r->gpr[23], |
2010 |
< |
r->gpr[24], r->gpr[25], r->gpr[26], r->gpr[27], |
2011 |
< |
r->gpr[28], r->gpr[29], r->gpr[30], r->gpr[31]); |
2002 |
> |
crash_reason, |
2003 |
> |
r->pc(), r->lr(), r->ctr(), r->msr(), |
2004 |
> |
r->xer(), r->cr(), |
2005 |
> |
r->gpr(0), r->gpr(1), r->gpr(2), r->gpr(3), |
2006 |
> |
r->gpr(4), r->gpr(5), r->gpr(6), r->gpr(7), |
2007 |
> |
r->gpr(8), r->gpr(9), r->gpr(10), r->gpr(11), |
2008 |
> |
r->gpr(12), r->gpr(13), r->gpr(14), r->gpr(15), |
2009 |
> |
r->gpr(16), r->gpr(17), r->gpr(18), r->gpr(19), |
2010 |
> |
r->gpr(20), r->gpr(21), r->gpr(22), r->gpr(23), |
2011 |
> |
r->gpr(24), r->gpr(25), r->gpr(26), r->gpr(27), |
2012 |
> |
r->gpr(28), r->gpr(29), r->gpr(30), r->gpr(31)); |
2013 |
|
exit(1); |
2014 |
|
QuitEmulator(); |
2015 |
|
return; |
2016 |
|
} else { |
2017 |
|
// We crashed. Save registers, tell tick thread and loop forever |
2018 |
< |
sigsegv_regs = *(sigregs *)r; |
2018 |
> |
build_sigregs(&sigsegv_regs, r); |
2019 |
|
emul_thread_fatal = true; |
2020 |
|
for (;;) ; |
2021 |
|
} |
2027 |
|
* SIGILL handler |
2028 |
|
*/ |
2029 |
|
|
2030 |
< |
static void sigill_handler(int sig, sigcontext_struct *sc) |
2030 |
> |
static void sigill_handler(int sig, siginfo_t *sip, void *scp) |
2031 |
|
{ |
2032 |
< |
pt_regs *r = sc->regs; |
2032 |
> |
machine_regs *r = MACHINE_REGISTERS(scp); |
2033 |
|
char str[256]; |
2034 |
|
|
2035 |
|
// Fault in Mac ROM or RAM? |
2036 |
< |
bool mac_fault = (r->nip >= ROM_BASE) && (r->nip < (ROM_BASE + ROM_AREA_SIZE)) || (r->nip >= RAMBase) && (r->nip < (RAMBase + RAMSize)); |
2036 |
> |
bool mac_fault = (r->pc() >= ROM_BASE) && (r->pc() < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)); |
2037 |
|
if (mac_fault) { |
2038 |
|
|
2039 |
|
// Get opcode and divide into fields |
2040 |
< |
uint32 opcode = *((uint32 *)r->nip); |
2040 |
> |
uint32 opcode = *((uint32 *)r->pc()); |
2041 |
|
uint32 primop = opcode >> 26; |
2042 |
|
uint32 exop = (opcode >> 1) & 0x3ff; |
2043 |
|
uint32 ra = (opcode >> 16) & 0x1f; |
2048 |
|
switch (primop) { |
2049 |
|
case 9: // POWER instructions |
2050 |
|
case 22: |
2051 |
< |
power_inst: sprintf(str, GetString(STR_POWER_INSTRUCTION_ERR), r->nip, r->gpr[1], opcode); |
2051 |
> |
power_inst: sprintf(str, GetString(STR_POWER_INSTRUCTION_ERR), r->pc(), r->gpr(1), opcode); |
2052 |
|
ErrorAlert(str); |
2053 |
|
QuitEmulator(); |
2054 |
|
return; |
2056 |
|
case 31: |
2057 |
|
switch (exop) { |
2058 |
|
case 83: // mfmsr |
2059 |
< |
r->gpr[rd] = 0xf072; |
2060 |
< |
r->nip += 4; |
2059 |
> |
r->gpr(rd) = 0xf072; |
2060 |
> |
r->pc() += 4; |
2061 |
|
goto rti; |
2062 |
|
|
2063 |
|
case 210: // mtsr |
2064 |
|
case 242: // mtsrin |
2065 |
|
case 306: // tlbie |
2066 |
< |
r->nip += 4; |
2066 |
> |
r->pc() += 4; |
2067 |
|
goto rti; |
2068 |
|
|
2069 |
|
case 339: { // mfspr |
2079 |
|
case 957: // PMC3 |
2080 |
|
case 958: // PMC4 |
2081 |
|
case 959: // SDA |
2082 |
< |
r->nip += 4; |
2082 |
> |
r->pc() += 4; |
2083 |
|
goto rti; |
2084 |
|
case 25: // SDR1 |
2085 |
< |
r->gpr[rd] = 0xdead001f; |
2086 |
< |
r->nip += 4; |
2085 |
> |
r->gpr(rd) = 0xdead001f; |
2086 |
> |
r->pc() += 4; |
2087 |
|
goto rti; |
2088 |
|
case 287: // PVR |
2089 |
< |
r->gpr[rd] = PVR; |
2090 |
< |
r->nip += 4; |
2089 |
> |
r->gpr(rd) = PVR; |
2090 |
> |
r->pc() += 4; |
2091 |
|
goto rti; |
2092 |
|
} |
2093 |
|
break; |
2123 |
|
case 957: // PMC3 |
2124 |
|
case 958: // PMC4 |
2125 |
|
case 959: // SDA |
2126 |
< |
r->nip += 4; |
2126 |
> |
r->pc() += 4; |
2127 |
|
goto rti; |
2128 |
|
} |
2129 |
|
break; |
2142 |
|
|
2143 |
|
// In GUI mode, show error alert |
2144 |
|
if (!PrefsFindBool("nogui")) { |
2145 |
< |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->nip, r->gpr[24], r->gpr[1], opcode); |
2145 |
> |
sprintf(str, GetString(STR_UNKNOWN_SEGV_ERR), r->pc(), r->gpr(24), r->gpr(1), opcode); |
2146 |
|
ErrorAlert(str); |
2147 |
|
QuitEmulator(); |
2148 |
|
return; |
2150 |
|
} |
2151 |
|
|
2152 |
|
// For all other errors, jump into debugger (sort of...) |
2153 |
+ |
crash_reason = "SIGILL"; |
2154 |
|
if (!ready_for_signals) { |
2155 |
< |
printf("SIGILL\n"); |
2156 |
< |
printf(" sigcontext %p, pt_regs %p\n", sc, r); |
2155 |
> |
printf("%s\n"); |
2156 |
> |
printf(" sigcontext %p, machine_regs %p\n", scp, r); |
2157 |
|
printf( |
2158 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
2159 |
|
" xer %08lx cr %08lx \n" |
2165 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
2166 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
2167 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
2168 |
< |
r->nip, r->link, r->ctr, r->msr, |
2169 |
< |
r->xer, r->ccr, |
2170 |
< |
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
2171 |
< |
r->gpr[4], r->gpr[5], r->gpr[6], r->gpr[7], |
2172 |
< |
r->gpr[8], r->gpr[9], r->gpr[10], r->gpr[11], |
2173 |
< |
r->gpr[12], r->gpr[13], r->gpr[14], r->gpr[15], |
2174 |
< |
r->gpr[16], r->gpr[17], r->gpr[18], r->gpr[19], |
2175 |
< |
r->gpr[20], r->gpr[21], r->gpr[22], r->gpr[23], |
2176 |
< |
r->gpr[24], r->gpr[25], r->gpr[26], r->gpr[27], |
2177 |
< |
r->gpr[28], r->gpr[29], r->gpr[30], r->gpr[31]); |
2168 |
> |
crash_reason, |
2169 |
> |
r->pc(), r->lr(), r->ctr(), r->msr(), |
2170 |
> |
r->xer(), r->cr(), |
2171 |
> |
r->gpr(0), r->gpr(1), r->gpr(2), r->gpr(3), |
2172 |
> |
r->gpr(4), r->gpr(5), r->gpr(6), r->gpr(7), |
2173 |
> |
r->gpr(8), r->gpr(9), r->gpr(10), r->gpr(11), |
2174 |
> |
r->gpr(12), r->gpr(13), r->gpr(14), r->gpr(15), |
2175 |
> |
r->gpr(16), r->gpr(17), r->gpr(18), r->gpr(19), |
2176 |
> |
r->gpr(20), r->gpr(21), r->gpr(22), r->gpr(23), |
2177 |
> |
r->gpr(24), r->gpr(25), r->gpr(26), r->gpr(27), |
2178 |
> |
r->gpr(28), r->gpr(29), r->gpr(30), r->gpr(31)); |
2179 |
|
exit(1); |
2180 |
|
QuitEmulator(); |
2181 |
|
return; |
2182 |
|
} else { |
2183 |
|
// We crashed. Save registers, tell tick thread and loop forever |
2184 |
< |
sigsegv_regs = *(sigregs *)r; |
2184 |
> |
build_sigregs(&sigsegv_regs, r); |
2185 |
|
emul_thread_fatal = true; |
2186 |
|
for (;;) ; |
2187 |
|
} |
2191 |
|
|
2192 |
|
|
2193 |
|
/* |
2194 |
+ |
* Helpers to share 32-bit addressable data with MacOS |
2195 |
+ |
*/ |
2196 |
+ |
|
2197 |
+ |
bool SheepMem::Init(void) |
2198 |
+ |
{ |
2199 |
+ |
// Size of a native page |
2200 |
+ |
page_size = getpagesize(); |
2201 |
+ |
|
2202 |
+ |
// Allocate SheepShaver globals |
2203 |
+ |
if (vm_acquire_fixed((char *)base, size) < 0) |
2204 |
+ |
return false; |
2205 |
+ |
|
2206 |
+ |
// Allocate page with all bits set to 0 |
2207 |
+ |
zero_page = base + size; |
2208 |
+ |
if (vm_acquire_fixed((char *)zero_page, page_size) < 0) |
2209 |
+ |
return false; |
2210 |
+ |
memset((char *)zero_page, 0, page_size); |
2211 |
+ |
if (vm_protect((char *)zero_page, page_size, VM_PAGE_READ) < 0) |
2212 |
+ |
return false; |
2213 |
+ |
|
2214 |
+ |
#if EMULATED_PPC |
2215 |
+ |
// Allocate alternate stack for PowerPC interrupt routine |
2216 |
+ |
sig_stack = zero_page + page_size; |
2217 |
+ |
if (vm_acquire_fixed((char *)sig_stack, SIG_STACK_SIZE) < 0) |
2218 |
+ |
return false; |
2219 |
+ |
#endif |
2220 |
+ |
|
2221 |
+ |
top = base + size; |
2222 |
+ |
return true; |
2223 |
+ |
} |
2224 |
+ |
|
2225 |
+ |
void SheepMem::Exit(void) |
2226 |
+ |
{ |
2227 |
+ |
if (top) { |
2228 |
+ |
// Delete SheepShaver globals |
2229 |
+ |
vm_release((void *)base, size); |
2230 |
+ |
|
2231 |
+ |
// Delete zero page |
2232 |
+ |
vm_release((void *)zero_page, page_size); |
2233 |
+ |
|
2234 |
+ |
#if EMULATED_PPC |
2235 |
+ |
// Delete alternate stack for PowerPC interrupt routine |
2236 |
+ |
vm_release((void *)sig_stack, SIG_STACK_SIZE); |
2237 |
+ |
#endif |
2238 |
+ |
} |
2239 |
+ |
} |
2240 |
+ |
|
2241 |
+ |
|
2242 |
+ |
/* |
2243 |
|
* Display alert |
2244 |
|
*/ |
2245 |
|
|
2288 |
|
|
2289 |
|
void ErrorAlert(const char *text) |
2290 |
|
{ |
2291 |
< |
#ifdef ENABLE_GTK |
2291 |
> |
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) |
2292 |
|
if (PrefsFindBool("nogui") || x_display == NULL) { |
2293 |
|
printf(GetString(STR_SHELL_ERROR_PREFIX), text); |
2294 |
|
return; |
2307 |
|
|
2308 |
|
void WarningAlert(const char *text) |
2309 |
|
{ |
2310 |
< |
#ifdef ENABLE_GTK |
2310 |
> |
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) |
2311 |
|
if (PrefsFindBool("nogui") || x_display == NULL) { |
2312 |
|
printf(GetString(STR_SHELL_WARNING_PREFIX), text); |
2313 |
|
return; |