109 |
|
#include "user_strings.h" |
110 |
|
#include "vm_alloc.h" |
111 |
|
#include "sigsegv.h" |
112 |
+ |
#include "thunks.h" |
113 |
|
|
114 |
|
#define DEBUG 0 |
115 |
|
#include "debug.h" |
132 |
|
#endif |
133 |
|
|
134 |
|
|
135 |
+ |
// Enable emulation of unaligned lmw/stmw? |
136 |
+ |
#define EMULATE_UNALIGNED_LOADSTORE_MULTIPLE 1 |
137 |
+ |
|
138 |
|
// Enable Execute68k() safety checks? |
139 |
|
#define SAFE_EXEC_68K 0 |
140 |
|
|
149 |
|
const char ROM_FILE_NAME[] = "ROM"; |
150 |
|
const char ROM_FILE_NAME2[] = "Mac OS ROM"; |
151 |
|
|
152 |
< |
const uint32 RAM_BASE = 0x20000000; // Base address of RAM |
152 |
> |
const uintptr RAM_BASE = 0x20000000; // Base address of RAM |
153 |
|
const uint32 SIG_STACK_SIZE = 0x10000; // Size of signal stack |
154 |
|
|
155 |
|
|
176 |
|
#endif |
177 |
|
uint32 RAMBase; // Base address of Mac RAM |
178 |
|
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 |
179 |
|
uint32 KernelDataAddr; // Address of Kernel Data |
180 |
|
uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM |
181 |
|
uint32 PVR; // Theoretical PVR |
184 |
|
|
185 |
|
|
186 |
|
// Global variables |
187 |
< |
static char *x_display_name = NULL; // X11 display name |
187 |
> |
char *x_display_name = NULL; // X11 display name |
188 |
|
Display *x_display = NULL; // X11 display handle |
189 |
+ |
#ifdef X11_LOCK_TYPE |
190 |
+ |
X11_LOCK_TYPE x_display_lock = X11_LOCK_INIT; // X11 display lock |
191 |
+ |
#endif |
192 |
|
|
193 |
|
static int zero_fd = 0; // FD of /dev/zero |
190 |
– |
static bool sheep_area_mapped = false; // Flag: SheepShaver data area mmap()ed |
194 |
|
static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped |
195 |
|
static int kernel_area = -1; // SHM ID of Kernel Data area |
196 |
|
static bool rom_area_mapped = false; // Flag: Mac ROM mmap()ped |
210 |
|
static int64 num_segv = 0; // Number of handled SEGV signals |
211 |
|
|
212 |
|
static struct sigaction sigusr2_action; // Interrupt signal (of emulator thread) |
213 |
< |
#if !EMULATED_PPC |
213 |
> |
#if EMULATED_PPC |
214 |
> |
static uintptr sig_stack = 0; // Stack for PowerPC interrupt routine |
215 |
> |
#else |
216 |
|
static struct sigaction sigsegv_action; // Data access exception signal (of emulator thread) |
217 |
|
static struct sigaction sigill_action; // Illegal instruction signal (of emulator thread) |
218 |
|
static void *sig_stack = NULL; // Stack for signal handlers |
219 |
|
static void *extra_stack = NULL; // Stack for SIGSEGV inside interrupt handler |
220 |
|
static bool emul_thread_fatal = false; // Flag: MacOS thread crashed, tick thread shall dump debug output |
221 |
|
static sigregs sigsegv_regs; // Register dump when crashed |
222 |
+ |
static const char *crash_reason = NULL; // Reason of the crash (SIGSEGV, SIGBUS, SIGILL) |
223 |
|
#endif |
224 |
|
|
225 |
+ |
uintptr SheepMem::zero_page = 0; // Address of ro page filled in with zeros |
226 |
+ |
uintptr SheepMem::base = 0x60000000; // Address of SheepShaver data |
227 |
+ |
uintptr SheepMem::top = 0; // Top of SheepShaver data (stack like storage) |
228 |
+ |
|
229 |
|
|
230 |
|
// Prototypes |
231 |
|
static void Quit(void); |
234 |
|
static void *tick_func(void *arg); |
235 |
|
#if EMULATED_PPC |
236 |
|
static void sigusr2_handler(int sig); |
237 |
+ |
extern void emul_ppc(uint32 start); |
238 |
+ |
extern void init_emul_ppc(void); |
239 |
+ |
extern void exit_emul_ppc(void); |
240 |
|
#else |
241 |
|
static void sigusr2_handler(int sig, sigcontext_struct *sc); |
242 |
|
static void sigsegv_handler(int sig, sigcontext_struct *sc); |
245 |
|
|
246 |
|
|
247 |
|
// From asm_linux.S |
248 |
< |
#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 |
248 |
> |
#if !EMULATED_PPC |
249 |
|
extern "C" void *get_toc(void); |
250 |
|
extern "C" void *get_sp(void); |
251 |
|
extern "C" void flush_icache_range(void *start, void *end); |
260 |
|
#endif |
261 |
|
|
262 |
|
|
263 |
+ |
#if EMULATED_PPC |
264 |
+ |
/* |
265 |
+ |
* Return signal stack base |
266 |
+ |
*/ |
267 |
+ |
|
268 |
+ |
uintptr SignalStackBase(void) |
269 |
+ |
{ |
270 |
+ |
return sig_stack + SIG_STACK_SIZE; |
271 |
+ |
} |
272 |
+ |
|
273 |
+ |
|
274 |
+ |
/* |
275 |
+ |
* Atomic operations |
276 |
+ |
*/ |
277 |
+ |
|
278 |
+ |
#if HAVE_SPINLOCKS |
279 |
+ |
static spinlock_t atomic_ops_lock = SPIN_LOCK_UNLOCKED; |
280 |
+ |
#else |
281 |
+ |
#define spin_lock(LOCK) |
282 |
+ |
#define spin_unlock(LOCK) |
283 |
+ |
#endif |
284 |
+ |
|
285 |
+ |
int atomic_add(int *var, int v) |
286 |
+ |
{ |
287 |
+ |
spin_lock(&atomic_ops_lock); |
288 |
+ |
int ret = *var; |
289 |
+ |
*var += v; |
290 |
+ |
spin_unlock(&atomic_ops_lock); |
291 |
+ |
return ret; |
292 |
+ |
} |
293 |
+ |
|
294 |
+ |
int atomic_and(int *var, int v) |
295 |
+ |
{ |
296 |
+ |
spin_lock(&atomic_ops_lock); |
297 |
+ |
int ret = *var; |
298 |
+ |
*var &= v; |
299 |
+ |
spin_unlock(&atomic_ops_lock); |
300 |
+ |
return ret; |
301 |
+ |
} |
302 |
+ |
|
303 |
+ |
int atomic_or(int *var, int v) |
304 |
+ |
{ |
305 |
+ |
spin_lock(&atomic_ops_lock); |
306 |
+ |
int ret = *var; |
307 |
+ |
*var |= v; |
308 |
+ |
spin_unlock(&atomic_ops_lock); |
309 |
+ |
return ret; |
310 |
+ |
} |
311 |
+ |
#endif |
312 |
+ |
|
313 |
+ |
|
314 |
|
/* |
315 |
|
* Main program |
316 |
|
*/ |
329 |
|
char str[256]; |
330 |
|
uint32 *boot_globs; |
331 |
|
int16 i16; |
272 |
– |
int drive, driver; |
332 |
|
int rom_fd; |
333 |
|
FILE *proc_file; |
334 |
|
const char *rom_path; |
490 |
|
ErrorAlert(str); |
491 |
|
goto quit; |
492 |
|
} |
493 |
< |
kernel_data = (KernelData *)0x68ffe000; |
493 |
> |
kernel_data = (KernelData *)KERNEL_DATA_BASE; |
494 |
|
emulator_data = &kernel_data->ed; |
495 |
< |
KernelDataAddr = (uint32)kernel_data; |
495 |
> |
KernelDataAddr = KERNEL_DATA_BASE; |
496 |
|
D(bug("Kernel Data at %p, Emulator Data at %p\n", kernel_data, emulator_data)); |
497 |
|
|
498 |
|
// Create area for SheepShaver data |
499 |
< |
if (vm_acquire_fixed((char *)SHEEP_BASE, SHEEP_SIZE) < 0) { |
499 |
> |
if (!SheepMem::Init()) { |
500 |
|
sprintf(str, GetString(STR_SHEEP_MEM_MMAP_ERR), strerror(errno)); |
501 |
|
ErrorAlert(str); |
502 |
|
goto quit; |
503 |
|
} |
445 |
– |
SheepStack1Base = SHEEP_BASE + 0x10000; |
446 |
– |
SheepStack2Base = SheepStack1Base + 0x10000; |
447 |
– |
SheepThunksBase = SheepStack2Base + 0x1000; |
448 |
– |
sheep_area_mapped = true; |
504 |
|
|
505 |
|
// Create area for Mac ROM |
506 |
|
if (vm_acquire_fixed((char *)ROM_BASE, ROM_AREA_SIZE) < 0) { |
579 |
|
XPRAMInit(); |
580 |
|
|
581 |
|
// Set boot volume |
582 |
< |
drive = PrefsFindInt32("bootdrive"); |
582 |
> |
i16 = PrefsFindInt32("bootdrive"); |
583 |
|
XPRAM[0x1378] = i16 >> 8; |
584 |
|
XPRAM[0x1379] = i16 & 0xff; |
585 |
< |
driver = PrefsFindInt32("bootdriver"); |
585 |
> |
i16 = PrefsFindInt32("bootdriver"); |
586 |
|
XPRAM[0x137a] = i16 >> 8; |
587 |
|
XPRAM[0x137b] = i16 & 0xff; |
588 |
|
|
595 |
|
boot_globs[1] = htonl(RAMSize); |
596 |
|
boot_globs[2] = htonl((uint32)-1); // End of bank table |
597 |
|
|
598 |
+ |
// Init thunks |
599 |
+ |
if (!ThunksInit()) |
600 |
+ |
goto quit; |
601 |
+ |
|
602 |
|
// Init drivers |
603 |
|
SonyInit(); |
604 |
|
DiskInit(); |
608 |
|
// Init external file system |
609 |
|
ExtFSInit(); |
610 |
|
|
611 |
+ |
// Init ADB |
612 |
+ |
ADBInit(); |
613 |
+ |
|
614 |
|
// Init audio |
615 |
|
AudioInit(); |
616 |
|
|
645 |
|
// Initialize Kernel Data |
646 |
|
memset(kernel_data, 0, sizeof(KernelData)); |
647 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
648 |
< |
static uint32 of_dev_tree[4] = {0, 0, 0, 0}; |
649 |
< |
static uint8 vector_lookup_tbl[128]; |
650 |
< |
static uint8 vector_mask_tbl[64]; |
648 |
> |
uintptr of_dev_tree = SheepMem::Reserve(4 * sizeof(uint32)); |
649 |
> |
memset((void *)of_dev_tree, 0, 4 * sizeof(uint32)); |
650 |
> |
uintptr vector_lookup_tbl = SheepMem::Reserve(128); |
651 |
> |
uintptr vector_mask_tbl = SheepMem::Reserve(64); |
652 |
|
memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80); |
653 |
< |
memset(vector_lookup_tbl, 0, 128); |
654 |
< |
memset(vector_mask_tbl, 0, 64); |
653 |
> |
memset((void *)vector_lookup_tbl, 0, 128); |
654 |
> |
memset((void *)vector_mask_tbl, 0, 64); |
655 |
|
kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE); |
656 |
< |
kernel_data->v[0xb84 >> 2] = htonl((uint32)of_dev_tree); // OF device tree base |
657 |
< |
kernel_data->v[0xb90 >> 2] = htonl((uint32)vector_lookup_tbl); |
658 |
< |
kernel_data->v[0xb94 >> 2] = htonl((uint32)vector_mask_tbl); |
656 |
> |
kernel_data->v[0xb84 >> 2] = htonl(of_dev_tree); // OF device tree base |
657 |
> |
kernel_data->v[0xb90 >> 2] = htonl(vector_lookup_tbl); |
658 |
> |
kernel_data->v[0xb94 >> 2] = htonl(vector_mask_tbl); |
659 |
|
kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE); // OpenPIC base |
660 |
|
kernel_data->v[0xbb0 >> 2] = htonl(0); // ADB base |
661 |
|
kernel_data->v[0xc20 >> 2] = htonl(RAMSize); |
691 |
|
D(bug("Initializing Low Memory...\n")); |
692 |
|
memset(NULL, 0, 0x3000); |
693 |
|
WriteMacInt32(XLM_SIGNATURE, FOURCC('B','a','a','h')); // Signature to detect SheepShaver |
694 |
< |
WriteMacInt32(XLM_KERNEL_DATA, (uint32)kernel_data); // For trap replacement routines |
694 |
> |
WriteMacInt32(XLM_KERNEL_DATA, KernelDataAddr); // For trap replacement routines |
695 |
|
WriteMacInt32(XLM_PVR, PVR); // Theoretical PVR |
696 |
|
WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch |
697 |
|
WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode) |
698 |
< |
#if EMULATED_PPC |
699 |
< |
WriteMacInt32(XLM_ETHER_INIT, POWERPC_NATIVE_OP_FUNC(NATIVE_ETHER_INIT)); |
700 |
< |
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); |
698 |
> |
WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage()); // Pointer to read-only page with all bits set to 0 |
699 |
> |
#if !EMULATED_PPC |
700 |
> |
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator |
701 |
|
#endif |
702 |
+ |
WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT)); // DLPI ethernet driver functions |
703 |
+ |
WriteMacInt32(XLM_ETHER_TERM, NativeFunction(NATIVE_ETHER_TERM)); |
704 |
+ |
WriteMacInt32(XLM_ETHER_OPEN, NativeFunction(NATIVE_ETHER_OPEN)); |
705 |
+ |
WriteMacInt32(XLM_ETHER_CLOSE, NativeFunction(NATIVE_ETHER_CLOSE)); |
706 |
+ |
WriteMacInt32(XLM_ETHER_WPUT, NativeFunction(NATIVE_ETHER_WPUT)); |
707 |
+ |
WriteMacInt32(XLM_ETHER_RSRV, NativeFunction(NATIVE_ETHER_RSRV)); |
708 |
+ |
WriteMacInt32(XLM_VIDEO_DOIO, NativeFunction(NATIVE_VIDEO_DO_DRIVER_IO)); |
709 |
|
D(bug("Low Memory initialized\n")); |
710 |
|
|
711 |
|
// Start 60Hz thread |
743 |
|
#endif |
744 |
|
|
745 |
|
#if !EMULATED_PPC |
746 |
< |
// Install SIGSEGV handler |
746 |
> |
// Install SIGSEGV and SIGBUS handlers |
747 |
|
sigemptyset(&sigsegv_action.sa_mask); // Block interrupts during SEGV handling |
748 |
|
sigaddset(&sigsegv_action.sa_mask, SIGUSR2); |
749 |
|
sigsegv_action.sa_handler = (__sighandler_t)sigsegv_handler; |
754 |
|
ErrorAlert(str); |
755 |
|
goto quit; |
756 |
|
} |
757 |
+ |
if (sigaction(SIGBUS, &sigsegv_action, NULL) < 0) { |
758 |
+ |
sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); |
759 |
+ |
ErrorAlert(str); |
760 |
+ |
goto quit; |
761 |
+ |
} |
762 |
|
|
763 |
|
// Install SIGILL handler |
764 |
|
sigemptyset(&sigill_action.sa_mask); // Block interrupts during ILL handling |
804 |
|
|
805 |
|
static void Quit(void) |
806 |
|
{ |
807 |
+ |
#if EMULATED_PPC |
808 |
+ |
// Exit PowerPC emulation |
809 |
+ |
exit_emul_ppc(); |
810 |
+ |
#endif |
811 |
+ |
|
812 |
|
// Stop 60Hz thread |
813 |
|
if (tick_thread_active) { |
814 |
|
pthread_cancel(tick_thread); |
822 |
|
} |
823 |
|
|
824 |
|
#if !EMULATED_PPC |
825 |
< |
// Uninstall SIGSEGV handler |
825 |
> |
// Uninstall SIGSEGV and SIGBUS handlers |
826 |
|
sigemptyset(&sigsegv_action.sa_mask); |
827 |
|
sigsegv_action.sa_handler = SIG_DFL; |
828 |
|
sigsegv_action.sa_flags = 0; |
829 |
|
sigaction(SIGSEGV, &sigsegv_action, NULL); |
830 |
+ |
sigaction(SIGBUS, &sigsegv_action, NULL); |
831 |
|
|
832 |
|
// Uninstall SIGILL handler |
833 |
|
sigemptyset(&sigill_action.sa_mask); |
854 |
|
// Exit audio |
855 |
|
AudioExit(); |
856 |
|
|
857 |
+ |
// Exit ADB |
858 |
+ |
ADBExit(); |
859 |
+ |
|
860 |
|
// Exit video |
861 |
|
VideoExit(); |
862 |
|
|
869 |
|
DiskExit(); |
870 |
|
SonyExit(); |
871 |
|
|
872 |
+ |
// Delete thunks |
873 |
+ |
ThunksExit(); |
874 |
+ |
|
875 |
+ |
// Delete SheepShaver globals |
876 |
+ |
SheepMem::Exit(); |
877 |
+ |
|
878 |
|
// Delete RAM area |
879 |
|
if (ram_area_mapped) |
880 |
|
vm_release((char *)RAM_BASE, RAMSize); |
922 |
|
*/ |
923 |
|
|
924 |
|
#if EMULATED_PPC |
849 |
– |
extern void emul_ppc(uint32 start); |
850 |
– |
extern void init_emul_ppc(void); |
925 |
|
void jump_to_rom(uint32 entry) |
926 |
|
{ |
927 |
|
init_emul_ppc(); |
986 |
|
uint16 proc[2] = {trap, M68K_RTS}; |
987 |
|
Execute68k((uint32)proc, r); |
988 |
|
} |
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 |
– |
} |
989 |
|
#endif |
990 |
|
|
991 |
|
|
1048 |
|
|
1049 |
|
void MakeExecutable(int dummy, void *start, uint32 length) |
1050 |
|
{ |
1051 |
< |
#if !EMULATED_PPC |
991 |
< |
if (((uint32)start >= ROM_BASE) && ((uint32)start < (ROM_BASE + ROM_SIZE))) |
1051 |
> |
if (((uintptr)start >= ROM_BASE) && ((uintptr)start < (ROM_BASE + ROM_SIZE))) |
1052 |
|
return; |
1053 |
< |
flush_icache_range(start, (void *)((uint32)start + length)); |
1053 |
> |
#if EMULATED_PPC |
1054 |
> |
FlushCodeCache((uintptr)start, (uintptr)start + length); |
1055 |
> |
#else |
1056 |
> |
flush_icache_range(start, (void *)((uintptr)start + length)); |
1057 |
|
#endif |
1058 |
|
} |
1059 |
|
|
1064 |
|
|
1065 |
|
void PatchAfterStartup(void) |
1066 |
|
{ |
1004 |
– |
#if EMULATED_PPC |
1067 |
|
ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL); |
1006 |
– |
#else |
1007 |
– |
ExecutePPC(VideoInstallAccel); |
1008 |
– |
#endif |
1068 |
|
InstallExtFS(); |
1069 |
|
} |
1070 |
|
|
1111 |
|
// Yes, dump registers |
1112 |
|
pt_regs *r = (pt_regs *)&sigsegv_regs; |
1113 |
|
char str[256]; |
1114 |
< |
sprintf(str, "SIGSEGV\n" |
1114 |
> |
if (crash_reason == NULL) |
1115 |
> |
crash_reason = "SIGSEGV"; |
1116 |
> |
sprintf(str, "%s\n" |
1117 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
1118 |
|
" xer %08lx cr %08lx \n" |
1119 |
|
" r0 %08lx r1 %08lx r2 %08lx r3 %08lx\n" |
1124 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
1125 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
1126 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
1127 |
+ |
crash_reason, |
1128 |
|
r->nip, r->link, r->ctr, r->msr, |
1129 |
|
r->xer, r->ccr, |
1130 |
|
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
1170 |
|
|
1171 |
|
void Set_pthread_attr(pthread_attr_t *attr, int priority) |
1172 |
|
{ |
1173 |
< |
// nothing to do |
1173 |
> |
#ifdef HAVE_PTHREADS |
1174 |
> |
pthread_attr_init(attr); |
1175 |
> |
#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
1176 |
> |
// Some of these only work for superuser |
1177 |
> |
if (geteuid() == 0) { |
1178 |
> |
pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED); |
1179 |
> |
pthread_attr_setschedpolicy(attr, SCHED_FIFO); |
1180 |
> |
struct sched_param fifo_param; |
1181 |
> |
fifo_param.sched_priority = ((sched_get_priority_min(SCHED_FIFO) + |
1182 |
> |
sched_get_priority_max(SCHED_FIFO)) / 2 + |
1183 |
> |
priority); |
1184 |
> |
pthread_attr_setschedparam(attr, &fifo_param); |
1185 |
> |
} |
1186 |
> |
if (pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0) { |
1187 |
> |
#ifdef PTHREAD_SCOPE_BOUND_NP |
1188 |
> |
// If system scope is not available (eg. we're not running |
1189 |
> |
// with CAP_SCHED_MGT capability on an SGI box), try bound |
1190 |
> |
// scope. It exposes pthread scheduling to the kernel, |
1191 |
> |
// without setting realtime priority. |
1192 |
> |
pthread_attr_setscope(attr, PTHREAD_SCOPE_BOUND_NP); |
1193 |
> |
#endif |
1194 |
> |
} |
1195 |
> |
#endif |
1196 |
> |
#endif |
1197 |
|
} |
1198 |
|
|
1199 |
|
|
1408 |
|
if (InterruptFlags & INTFLAG_VIA) { |
1409 |
|
ClearInterruptFlag(INTFLAG_VIA); |
1410 |
|
ADBInterrupt(); |
1411 |
< |
ExecutePPC(VideoVBL); |
1411 |
> |
ExecuteNative(NATIVE_VIDEO_VBL); |
1412 |
|
} |
1413 |
|
} |
1414 |
|
#endif |
1567 |
|
transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_NORM; break; |
1568 |
|
case 45: // sthu |
1569 |
|
transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_U; break; |
1570 |
+ |
#if EMULATE_UNALIGNED_LOADSTORE_MULTIPLE |
1571 |
+ |
case 46: // lmw |
1572 |
+ |
if (sig == SIGBUS) { |
1573 |
+ |
uint32 ea = (ra == 0 ? 0 : r->gpr[ra]) + imm; |
1574 |
+ |
D(bug("WARNING: unaligned lmw to EA=%08x from IP=%08x\n", ea, r->nip)); |
1575 |
+ |
for (int i = rd; i <= 31; i++) { |
1576 |
+ |
r->gpr[i] = ReadMacInt32(ea); |
1577 |
+ |
ea += 4; |
1578 |
+ |
} |
1579 |
+ |
r->nip += 4; |
1580 |
+ |
goto rti; |
1581 |
+ |
} |
1582 |
+ |
break; |
1583 |
+ |
case 47: // stmw |
1584 |
+ |
if (sig == SIGBUS) { |
1585 |
+ |
uint32 ea = (ra == 0 ? 0 : r->gpr[ra]) + imm; |
1586 |
+ |
D(bug("WARNING: unaligned stmw to EA=%08x from IP=%08x\n", ea, r->nip)); |
1587 |
+ |
for (int i = rd; i <= 31; i++) { |
1588 |
+ |
WriteMacInt32(ea, r->gpr[i]); |
1589 |
+ |
ea += 4; |
1590 |
+ |
} |
1591 |
+ |
r->nip += 4; |
1592 |
+ |
goto rti; |
1593 |
+ |
} |
1594 |
+ |
break; |
1595 |
+ |
#endif |
1596 |
|
} |
1597 |
|
|
1598 |
|
// Ignore ROM writes |
1628 |
|
} |
1629 |
|
|
1630 |
|
// For all other errors, jump into debugger (sort of...) |
1631 |
+ |
crash_reason = (sig == SIGBUS) ? "SIGBUS" : "SIGSEGV"; |
1632 |
|
if (!ready_for_signals) { |
1633 |
< |
printf("SIGSEGV\n"); |
1633 |
> |
printf("%s\n"); |
1634 |
|
printf(" sigcontext %p, pt_regs %p\n", sc, r); |
1635 |
|
printf( |
1636 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
1643 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
1644 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
1645 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
1646 |
+ |
crash_reason, |
1647 |
|
r->nip, r->link, r->ctr, r->msr, |
1648 |
|
r->xer, r->ccr, |
1649 |
|
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
1794 |
|
} |
1795 |
|
|
1796 |
|
// For all other errors, jump into debugger (sort of...) |
1797 |
+ |
crash_reason = "SIGILL"; |
1798 |
|
if (!ready_for_signals) { |
1799 |
< |
printf("SIGILL\n"); |
1799 |
> |
printf("%s\n"); |
1800 |
|
printf(" sigcontext %p, pt_regs %p\n", sc, r); |
1801 |
|
printf( |
1802 |
|
" pc %08lx lr %08lx ctr %08lx msr %08lx\n" |
1809 |
|
" r20 %08lx r21 %08lx r22 %08lx r23 %08lx\n" |
1810 |
|
" r24 %08lx r25 %08lx r26 %08lx r27 %08lx\n" |
1811 |
|
" r28 %08lx r29 %08lx r30 %08lx r31 %08lx\n", |
1812 |
+ |
crash_reason, |
1813 |
|
r->nip, r->link, r->ctr, r->msr, |
1814 |
|
r->xer, r->ccr, |
1815 |
|
r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3], |
1835 |
|
|
1836 |
|
|
1837 |
|
/* |
1838 |
+ |
* Helpers to share 32-bit addressable data with MacOS |
1839 |
+ |
*/ |
1840 |
+ |
|
1841 |
+ |
bool SheepMem::Init(void) |
1842 |
+ |
{ |
1843 |
+ |
const int page_size = getpagesize(); |
1844 |
+ |
|
1845 |
+ |
// Allocate SheepShaver globals |
1846 |
+ |
if (vm_acquire_fixed((char *)base, size) < 0) |
1847 |
+ |
return false; |
1848 |
+ |
|
1849 |
+ |
// Allocate page with all bits set to 0 |
1850 |
+ |
zero_page = base + size; |
1851 |
+ |
if (vm_acquire_fixed((char *)zero_page, page_size) < 0) |
1852 |
+ |
return false; |
1853 |
+ |
memset((char *)zero_page, 0, page_size); |
1854 |
+ |
if (vm_protect((char *)zero_page, page_size, VM_PAGE_READ) < 0) |
1855 |
+ |
return false; |
1856 |
+ |
|
1857 |
+ |
#if EMULATED_PPC |
1858 |
+ |
// Allocate alternate stack for PowerPC interrupt routine |
1859 |
+ |
sig_stack = zero_page + page_size; |
1860 |
+ |
if (vm_acquire_fixed((char *)sig_stack, SIG_STACK_SIZE) < 0) |
1861 |
+ |
return false; |
1862 |
+ |
#endif |
1863 |
+ |
|
1864 |
+ |
top = base + size; |
1865 |
+ |
return true; |
1866 |
+ |
} |
1867 |
+ |
|
1868 |
+ |
void SheepMem::Exit(void) |
1869 |
+ |
{ |
1870 |
+ |
if (top) { |
1871 |
+ |
const int page_size = getpagesize(); |
1872 |
+ |
|
1873 |
+ |
// Delete SheepShaver globals |
1874 |
+ |
vm_release((void *)base, size); |
1875 |
+ |
|
1876 |
+ |
// Delete zero page |
1877 |
+ |
vm_release((void *)zero_page, page_size); |
1878 |
+ |
|
1879 |
+ |
#if EMULATED_PPC |
1880 |
+ |
// Delete alternate stack for PowerPC interrupt routine |
1881 |
+ |
vm_release((void *)sig_stack, SIG_STACK_SIZE); |
1882 |
+ |
#endif |
1883 |
+ |
} |
1884 |
+ |
} |
1885 |
+ |
|
1886 |
+ |
|
1887 |
+ |
/* |
1888 |
|
* Display alert |
1889 |
|
*/ |
1890 |
|
|