--- SheepShaver/src/Unix/main_unix.cpp 2006/01/18 22:12:26 1.73 +++ SheepShaver/src/Unix/main_unix.cpp 2011/12/30 17:38:39 1.98 @@ -1,7 +1,7 @@ /* * main_unix.cpp - Emulation core, Unix implementation * - * SheepShaver (C) 1997-2005 Christian Bauer and Marc Hellwig + * SheepShaver (C) Christian Bauer and Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -89,6 +89,7 @@ #include #include #include +#include #include #include "sysdeps.h" @@ -110,6 +111,7 @@ #include "vm_alloc.h" #include "sigsegv.h" #include "sigregs.h" +#include "rpc.h" #define DEBUG 0 #include "debug.h" @@ -134,7 +136,7 @@ #ifdef ENABLE_XF86_DGA #include #include -#include +#include #endif #ifdef ENABLE_MON @@ -159,12 +161,14 @@ const char ROM_FILE_NAME[] = "ROM"; const char ROM_FILE_NAME2[] = "Mac OS ROM"; -#if REAL_ADDRESSING -const uintptr RAM_BASE = 0x20000000; // Base address of RAM -#else +#if !REAL_ADDRESSING // FIXME: needs to be >= 0x04000000 const uintptr RAM_BASE = 0x10000000; // Base address of RAM #endif +const uintptr ROM_BASE = 0x40800000; // Base address of ROM +#if REAL_ADDRESSING +const uint32 ROM_ALIGNMENT = 0x100000; // ROM must be aligned to a 1MB boundary +#endif const uint32 SIG_STACK_SIZE = 0x10000; // Size of signal stack @@ -175,6 +179,7 @@ void *R13 = NULL; // Pointer to .sdata #endif uint32 RAMBase; // Base address of Mac RAM uint32 RAMSize; // Size of Mac RAM +uint32 ROMBase; // Base address of Mac ROM uint32 KernelDataAddr; // Address of Kernel Data uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM uint32 DRCacheAddr; // Address of DR Cache @@ -224,13 +229,16 @@ static uintptr sig_stack = 0; // Stac #else static struct sigaction sigsegv_action; // Data access exception signal (of emulator thread) static struct sigaction sigill_action; // Illegal instruction signal (of emulator thread) -static struct sigaltstack sig_stack; // Stack for signal handlers -static struct sigaltstack extra_stack; // Stack for SIGSEGV inside interrupt handler +static stack_t sig_stack; // Stack for signal handlers +static stack_t extra_stack; // Stack for SIGSEGV inside interrupt handler static bool emul_thread_fatal = false; // Flag: MacOS thread crashed, tick thread shall dump debug output static sigregs sigsegv_regs; // Register dump when crashed static const char *crash_reason = NULL; // Reason of the crash (SIGSEGV, SIGBUS, SIGILL) #endif +static rpc_connection_t *gui_connection = NULL; // RPC connection to the GUI +static const char *gui_connection_path = NULL; // GUI connection identifier + uint32 SheepMem::page_size; // Size of a native page uintptr SheepMem::zero_page = 0; // Address of ro page filled in with zeros uintptr SheepMem::base = 0x60000000; // Address of SheepShaver data @@ -249,7 +257,7 @@ static void *tick_func(void *arg); extern void emul_ppc(uint32 start); extern void init_emul_ppc(void); extern void exit_emul_ppc(void); -sigsegv_return_t sigsegv_handler(sigsegv_address_t, sigsegv_address_t); +sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip); #else extern "C" void sigusr2_handler_init(int sig, siginfo_t *sip, void *scp); extern "C" void sigusr2_handler(int sig, siginfo_t *sip, void *scp); @@ -332,7 +340,12 @@ int atomic_or(int *var, int v) * Memory management helpers */ -static inline int vm_mac_acquire(uint32 addr, uint32 size) +static inline uint8 *vm_mac_acquire(uint32 size) +{ + return (uint8 *)vm_acquire(size); +} + +static inline int vm_mac_acquire_fixed(uint32 addr, uint32 size) { return vm_acquire_fixed(Mac2HostAddr(addr), size); } @@ -356,161 +369,32 @@ static void usage(const char *prg_name) exit(0); } -int main(int argc, char **argv) +static bool valid_vmdir(const char *path) { - char str[256]; - int rom_fd; - FILE *proc_file; - const char *rom_path; - uint32 rom_size, actual; - uint8 *rom_tmp; - time_t now, expire; - - // Initialize variables - RAMBase = 0; - tzset(); - - // Print some info - printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR); - printf(" %s\n", GetString(STR_ABOUT_TEXT2)); - -#if !EMULATED_PPC -#ifdef SYSTEM_CLOBBERS_R2 - // Get TOC pointer - TOC = get_r2(); -#endif -#ifdef SYSTEM_CLOBBERS_R13 - // Get r13 register - R13 = get_r13(); -#endif -#endif - -#ifdef ENABLE_GTK - // Init GTK - gtk_set_locale(); - gtk_init(&argc, &argv); -#endif - - // Read preferences - PrefsInit(argc, argv); - - // Parse command line arguments - for (int i=1; i suffix_len && !strncmp(path + len - suffix_len, ".sheepvm", suffix_len)) { + struct stat d; + if (!stat(path, &d) && S_ISDIR(d.st_mode)) { + return true; } } + return false; +} -#ifdef USE_SDL - // Initialize SDL system - int sdl_flags = 0; -#ifdef USE_SDL_VIDEO - sdl_flags |= SDL_INIT_VIDEO; -#endif -#ifdef USE_SDL_AUDIO - sdl_flags |= SDL_INIT_AUDIO; -#endif - assert(sdl_flags != 0); - if (SDL_Init(sdl_flags) == -1) { - char str[256]; - sprintf(str, "Could not initialize SDL: %s.\n", SDL_GetError()); - ErrorAlert(str); - goto quit; - } - atexit(SDL_Quit); -#endif - -#ifndef USE_SDL_VIDEO - // Open display - x_display = XOpenDisplay(x_display_name); - if (x_display == NULL) { - char str[256]; - sprintf(str, GetString(STR_NO_XSERVER_ERR), XDisplayName(x_display_name)); - ErrorAlert(str); - goto quit; - } - -#if defined(ENABLE_XF86_DGA) && !defined(ENABLE_MON) - // Fork out, so we can return from fullscreen mode when things get ugly - XF86DGAForkApp(DefaultScreen(x_display)); -#endif -#endif - -#ifdef ENABLE_MON - // Initialize mon - mon_init(); -#endif - -#if !EMULATED_PPC - // Create and install stacks for signal handlers - sig_stack.ss_sp = malloc(SIG_STACK_SIZE); - D(bug("Signal stack at %p\n", sig_stack.ss_sp)); - if (sig_stack.ss_sp == NULL) { - ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); - goto quit; - } - sig_stack.ss_flags = 0; - sig_stack.ss_size = SIG_STACK_SIZE; - if (sigaltstack(&sig_stack, NULL) < 0) { - sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno)); - ErrorAlert(str); - goto quit; - } - extra_stack.ss_sp = malloc(SIG_STACK_SIZE); - D(bug("Extra stack at %p\n", extra_stack.ss_sp)); - if (extra_stack.ss_sp == NULL) { - ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); - goto quit; - } - extra_stack.ss_flags = 0; - extra_stack.ss_size = SIG_STACK_SIZE; -#endif - +static void get_system_info(void) +{ #if !EMULATED_PPC - // Install SIGSEGV and SIGBUS handlers - sigemptyset(&sigsegv_action.sa_mask); // Block interrupts during SEGV handling - sigaddset(&sigsegv_action.sa_mask, SIGUSR2); - sigsegv_action.sa_sigaction = sigsegv_handler; - sigsegv_action.sa_flags = SA_ONSTACK | SA_SIGINFO; -#ifdef HAVE_SIGNAL_SA_RESTORER - sigsegv_action.sa_restorer = NULL; -#endif - if (sigaction(SIGSEGV, &sigsegv_action, NULL) < 0) { - sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); - ErrorAlert(str); - goto quit; - } - if (sigaction(SIGBUS, &sigsegv_action, NULL) < 0) { - sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); - ErrorAlert(str); - goto quit; - } -#else - // Install SIGSEGV handler for CPU emulator - if (!sigsegv_install_handler(sigsegv_handler)) { - sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno)); - ErrorAlert(str); - goto quit; - } + FILE *proc_file; #endif - // Initialize VM system - vm_init(); - - // Get system info PVR = 0x00040000; // Default: 604 CPUClockSpeed = 100000000; // Default: 100MHz BusClockSpeed = 100000000; // Default: 100MHz TimebaseSpeed = 25000000; // Default: 25MHz + #if EMULATED_PPC PVR = 0x000c0000; // Default: 7400 (with AltiVec) #elif defined(__APPLE__) && defined(__MACH__) @@ -545,6 +429,7 @@ int main(int argc, char **argv) } fclose(proc_file); } else { + char str[256]; sprintf(str, GetString(STR_PROC_CPUINFO_WARN), strerror(errno)); WarningAlert(str); } @@ -599,8 +484,12 @@ int main(int argc, char **argv) { 0xffff0000, 0x00350000, "Power4" }, { 0xffff0000, 0x00390000, "PPC970" }, { 0xffff0000, 0x003c0000, "PPC970FX" }, + { 0xffff0000, 0x00440000, "PPC970MP" }, { 0xffff0000, 0x003a0000, "POWER5 (gr)" }, - { 0xffff0000, 0x003b0000, "POWER5 (gs)" }, + { 0xffff0000, 0x003b0000, "POWER5+ (gs)" }, + { 0xffff0000, 0x003e0000, "POWER6" }, + { 0xffff0000, 0x00700000, "Cell Broadband Engine" }, + { 0x7fff0000, 0x00900000, "PA6T" }, { 0, 0, 0 } }; @@ -614,8 +503,9 @@ int main(int argc, char **argv) // Parse line int i; + float f; char value[256]; - if (sscanf(line, "cpu : %[0-9A-Za-a]", value) == 1) { + if (sscanf(line, "cpu : %[^,]", value) == 1) { // Search by name const char *cpu_name = NULL; for (int i = 0; cpu_specs[i].pvr_mask != 0; i++) { @@ -630,7 +520,9 @@ int main(int argc, char **argv) else printf("Found a PowerPC %s processor\n", cpu_name); } - if (sscanf(line, "clock : %dMHz", &i) == 1) + if (sscanf(line, "clock : %fMHz", &f) == 1) + CPUClockSpeed = BusClockSpeed = ((int64)f) * 1000000; + else if (sscanf(line, "clock : %dMHz", &i) == 1) CPUClockSpeed = BusClockSpeed = i * 1000000; } fclose(proc_file); @@ -669,6 +561,7 @@ int main(int argc, char **argv) closedir(cpus_dir); } #endif + // Remap any newer G4/G5 processor to plain G4 for compatibility switch (PVR >> 16) { case 0x8000: // 7450 @@ -678,10 +571,266 @@ int main(int argc, char **argv) case 0x8004: // 7448 case 0x0039: // 970 case 0x003c: // 970FX + case 0x0044: // 970MP PVR = 0x000c0000; // 7400 break; } D(bug("PVR: %08x (assumed)\n", PVR)); +} + +static bool load_mac_rom(void) +{ + uint32 rom_size, actual; + uint8 *rom_tmp; + const char *rom_path = PrefsFindString("rom"); + int rom_fd = open(rom_path && *rom_path ? rom_path : ROM_FILE_NAME, O_RDONLY); + if (rom_fd < 0) { + rom_fd = open(ROM_FILE_NAME2, O_RDONLY); + if (rom_fd < 0) { + ErrorAlert(GetString(STR_NO_ROM_FILE_ERR)); + return false; + } + } + printf("%s", GetString(STR_READING_ROM_FILE)); + rom_size = lseek(rom_fd, 0, SEEK_END); + lseek(rom_fd, 0, SEEK_SET); + rom_tmp = new uint8[ROM_SIZE]; + actual = read(rom_fd, (void *)rom_tmp, ROM_SIZE); + close(rom_fd); + + // Decode Mac ROM + if (!DecodeROM(rom_tmp, actual)) { + if (rom_size != 4*1024*1024) { + ErrorAlert(GetString(STR_ROM_SIZE_ERR)); + return false; + } else { + ErrorAlert(GetString(STR_ROM_FILE_READ_ERR)); + return false; + } + } + delete[] rom_tmp; + return true; +} + +static bool install_signal_handlers(void) +{ + char str[256]; +#if !EMULATED_PPC + // Create and install stacks for signal handlers + sig_stack.ss_sp = malloc(SIG_STACK_SIZE); + D(bug("Signal stack at %p\n", sig_stack.ss_sp)); + if (sig_stack.ss_sp == NULL) { + ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); + return false; + } + sig_stack.ss_flags = 0; + sig_stack.ss_size = SIG_STACK_SIZE; + if (sigaltstack(&sig_stack, NULL) < 0) { + sprintf(str, GetString(STR_SIGALTSTACK_ERR), strerror(errno)); + ErrorAlert(str); + return false; + } + extra_stack.ss_sp = malloc(SIG_STACK_SIZE); + D(bug("Extra stack at %p\n", extra_stack.ss_sp)); + if (extra_stack.ss_sp == NULL) { + ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR)); + return false; + } + extra_stack.ss_flags = 0; + extra_stack.ss_size = SIG_STACK_SIZE; + + // Install SIGSEGV and SIGBUS handlers + sigemptyset(&sigsegv_action.sa_mask); // Block interrupts during SEGV handling + sigaddset(&sigsegv_action.sa_mask, SIGUSR2); + sigsegv_action.sa_sigaction = sigsegv_handler; + sigsegv_action.sa_flags = SA_ONSTACK | SA_SIGINFO; +#ifdef HAVE_SIGNAL_SA_RESTORER + sigsegv_action.sa_restorer = NULL; +#endif + if (sigaction(SIGSEGV, &sigsegv_action, NULL) < 0) { + sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGSEGV", strerror(errno)); + ErrorAlert(str); + return false; + } + if (sigaction(SIGBUS, &sigsegv_action, NULL) < 0) { + sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGBUS", strerror(errno)); + ErrorAlert(str); + return false; + } +#else + // Install SIGSEGV handler for CPU emulator + if (!sigsegv_install_handler(sigsegv_handler)) { + sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGSEGV", strerror(errno)); + ErrorAlert(str); + return false; + } +#endif + return true; +} + +static bool init_sdl() +{ + int sdl_flags = 0; +#ifdef USE_SDL_VIDEO + sdl_flags |= SDL_INIT_VIDEO; +#endif +#ifdef USE_SDL_AUDIO + sdl_flags |= SDL_INIT_AUDIO; +#endif + assert(sdl_flags != 0); + +#ifdef USE_SDL_VIDEO + // Don't let SDL block the screensaver + setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", TRUE); + + // Make SDL pass through command-clicks and option-clicks unaltered + setenv("SDL_HAS3BUTTONMOUSE", "1", TRUE); +#endif + + if (SDL_Init(sdl_flags) == -1) { + char str[256]; + sprintf(str, "Could not initialize SDL: %s.\n", SDL_GetError()); + ErrorAlert(str); + return false; + } + atexit(SDL_Quit); + + // Don't let SDL catch SIGINT and SIGTERM signals + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + return true; +} + +int main(int argc, char **argv) +{ + char str[256]; + bool memory_mapped_from_zero, ram_rom_areas_contiguous; + const char *vmdir = NULL; + + // Initialize variables + RAMBase = 0; + tzset(); + + // Print some info + printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR); + printf(" %s\n", GetString(STR_ABOUT_TEXT2)); + +#if !EMULATED_PPC +#ifdef SYSTEM_CLOBBERS_R2 + // Get TOC pointer + TOC = get_r2(); +#endif +#ifdef SYSTEM_CLOBBERS_R13 + // Get r13 register + R13 = get_r13(); +#endif +#endif + + // Parse command line arguments + for (int i=1; i i) { + k -= i; + for (int j=i+k; j ROM_BASE) { - ErrorAlert(GetString(STR_RAM_HIGHER_THAN_ROM_ERR)); + if (RAMBase > KernelDataAddr) { + ErrorAlert(GetString(STR_RAM_AREA_TOO_HIGH_ERR)); goto quit; } - - // Load Mac ROM - rom_path = PrefsFindString("rom"); - rom_fd = open(rom_path ? rom_path : ROM_FILE_NAME, O_RDONLY); - if (rom_fd < 0) { - rom_fd = open(rom_path ? rom_path : ROM_FILE_NAME2, O_RDONLY); - if (rom_fd < 0) { - ErrorAlert(GetString(STR_NO_ROM_FILE_ERR)); - goto quit; - } - } - printf(GetString(STR_READING_ROM_FILE)); - rom_size = lseek(rom_fd, 0, SEEK_END); - lseek(rom_fd, 0, SEEK_SET); - rom_tmp = new uint8[ROM_SIZE]; - actual = read(rom_fd, (void *)rom_tmp, ROM_SIZE); - close(rom_fd); - // Decode Mac ROM - if (!DecodeROM(rom_tmp, actual)) { - if (rom_size != 4*1024*1024) { - ErrorAlert(GetString(STR_ROM_SIZE_ERR)); - goto quit; - } else { - ErrorAlert(GetString(STR_ROM_FILE_READ_ERR)); + // Create area for Mac ROM + if (!ram_rom_areas_contiguous) { + if (vm_mac_acquire_fixed(ROM_BASE, ROM_AREA_SIZE) < 0) { + sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); + ErrorAlert(str); goto quit; } + ROMBase = ROM_BASE; + ROMBaseHost = Mac2HostAddr(ROMBase); + } +#if !EMULATED_PPC + if (vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) { + sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); + ErrorAlert(str); + goto quit; + } +#endif + rom_area_mapped = true; + D(bug("ROM area at %p (%08x)\n", ROMBaseHost, ROMBase)); + + if (RAMBase > ROMBase) { + ErrorAlert(GetString(STR_RAM_HIGHER_THAN_ROM_ERR)); + goto quit; } - delete[] rom_tmp; + + // Load Mac ROM + if (!load_mac_rom()) + goto quit; // Initialize everything - if (!InitAll()) + if (!InitAll(vmdir)) goto quit; D(bug("Initialization complete\n")); // Clear caches (as we loaded and patched code) and write protect ROM #if !EMULATED_PPC - flush_icache_range(ROM_BASE, ROM_BASE + ROM_AREA_SIZE); + flush_icache_range(ROMBase, ROMBase + ROM_AREA_SIZE); #endif vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_EXECUTE); @@ -860,7 +1017,7 @@ int main(int argc, char **argv) sigill_action.sa_restorer = NULL; #endif if (sigaction(SIGILL, &sigill_action, NULL) < 0) { - sprintf(str, GetString(STR_SIGILL_INSTALL_ERR), strerror(errno)); + sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGILL", strerror(errno)); ErrorAlert(str); goto quit; } @@ -875,7 +1032,7 @@ int main(int argc, char **argv) sigusr2_action.sa_restorer = NULL; #endif if (sigaction(SIGUSR2, &sigusr2_action, NULL) < 0) { - sprintf(str, GetString(STR_SIGUSR2_INSTALL_ERR), strerror(errno)); + sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGUSR2", strerror(errno)); ErrorAlert(str); goto quit; } @@ -946,11 +1103,11 @@ static void Quit(void) // Delete RAM area if (ram_area_mapped) - vm_mac_release(RAM_BASE, RAMSize); + vm_mac_release(RAMBase, RAMSize); // Delete ROM area if (rom_area_mapped) - vm_mac_release(ROM_BASE, ROM_AREA_SIZE); + vm_mac_release(ROMBase, ROM_AREA_SIZE); // Delete DR cache areas if (dr_emulator_area_mapped) @@ -986,6 +1143,12 @@ static void Quit(void) XCloseDisplay(x_display); #endif + // Notify GUI we are about to leave + if (gui_connection) { + if (rpc_method_invoke(gui_connection, RPC_METHOD_EXIT, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR) + rpc_method_wait_for_reply(gui_connection, RPC_TYPE_INVALID); + } + exit(0); } @@ -1063,9 +1226,9 @@ static void *emul_func(void *arg) // Jump to ROM boot routine D(bug("Jumping to ROM\n")); #if EMULATED_PPC - jump_to_rom(ROM_BASE + 0x310000); + jump_to_rom(ROMBase + 0x310000); #else - jump_to_rom(ROM_BASE + 0x310000, (uint32)emulator_data); + jump_to_rom(ROMBase + 0x310000, (uint32)emulator_data); #endif D(bug("Returned from ROM\n")); @@ -1151,7 +1314,7 @@ void Dump68kRegs(M68kRegisters *r) void MakeExecutable(int dummy, uint32 start, uint32 length) { - if ((start >= ROM_BASE) && (start < (ROM_BASE + ROM_SIZE))) + if ((start >= ROMBase) && (start < (ROMBase + ROM_SIZE))) return; #if EMULATED_PPC FlushCodeCache(start, start + length); @@ -1494,9 +1657,9 @@ void sigusr2_handler(int sig, siginfo_t // Execute nanokernel interrupt routine (this will activate the 68k emulator) DisableInterrupt(); if (ROMType == ROMTYPE_NEWWORLD) - ppc_interrupt(ROM_BASE + 0x312b1c, KernelDataAddr); + ppc_interrupt(ROMBase + 0x312b1c, KernelDataAddr); else - ppc_interrupt(ROM_BASE + 0x312a3c, KernelDataAddr); + ppc_interrupt(ROMBase + 0x312a3c, KernelDataAddr); // Reset normal stack sigaltstack(&sig_stack, NULL); @@ -1568,41 +1731,46 @@ static void sigsegv_handler(int sig, sig #endif #if ENABLE_VOSF - // Handle screen fault. - extern bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction); - if (Screen_fault_handler((sigsegv_address_t)addr, (sigsegv_address_t)r->pc())) + // Handle screen fault +#if SIGSEGV_CHECK_VERSION(1,0,0) + sigsegv_info_t si; + si.addr = (sigsegv_address_t)addr; + si.pc = (sigsegv_address_t)r->pc(); +#endif + extern bool Screen_fault_handler(sigsegv_info_t *sip); + if (Screen_fault_handler(&si)) return; #endif num_segv++; // Fault in Mac ROM or RAM or DR Cache? - 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)); + bool mac_fault = (r->pc() >= ROMBase) && (r->pc() < (ROMBase + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)) || (r->pc() >= DR_CACHE_BASE && r->pc() < (DR_CACHE_BASE + DR_CACHE_SIZE)); if (mac_fault) { // "VM settings" during MacOS 8 installation - if (r->pc() == ROM_BASE + 0x488160 && r->gpr(20) == 0xf8000000) { + if (r->pc() == ROMBase + 0x488160 && r->gpr(20) == 0xf8000000) { r->pc() += 4; r->gpr(8) = 0; return; // MacOS 8.5 installation - } else if (r->pc() == ROM_BASE + 0x488140 && r->gpr(16) == 0xf8000000) { + } else if (r->pc() == ROMBase + 0x488140 && r->gpr(16) == 0xf8000000) { r->pc() += 4; r->gpr(8) = 0; return; // MacOS 8 serial drivers on startup - } else if (r->pc() == ROM_BASE + 0x48e080 && (r->gpr(8) == 0xf3012002 || r->gpr(8) == 0xf3012000)) { + } else if (r->pc() == ROMBase + 0x48e080 && (r->gpr(8) == 0xf3012002 || r->gpr(8) == 0xf3012000)) { r->pc() += 4; r->gpr(8) = 0; return; // MacOS 8.1 serial drivers on startup - } else if (r->pc() == ROM_BASE + 0x48c5e0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { + } else if (r->pc() == ROMBase + 0x48c5e0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { r->pc() += 4; return; - } else if (r->pc() == ROM_BASE + 0x4a10a0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { + } else if (r->pc() == ROMBase + 0x4a10a0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) { r->pc() += 4; return; @@ -1735,7 +1903,7 @@ static void sigsegv_handler(int sig, sig // Ignore ROM writes (including to the zero page, which is read-only) if (transfer_type == TYPE_STORE && - ((addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) || + ((addr >= ROMBase && addr < ROMBase + ROM_SIZE) || (addr >= SheepMem::ZeroPage() && addr < SheepMem::ZeroPage() + SheepMem::PageSize()))) { // 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())); if (addr_mode == MODE_U || addr_mode == MODE_UX) @@ -1826,7 +1994,7 @@ static void sigill_handler(int sig, sigi #endif // Fault in Mac ROM or RAM? - bool mac_fault = (r->pc() >= ROM_BASE) && (r->pc() < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)); + bool mac_fault = (r->pc() >= ROMBase) && (r->pc() < (ROMBase + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)); if (mac_fault) { // Get opcode and divide into fields @@ -1994,7 +2162,7 @@ bool SheepMem::Init(void) // Allocate SheepShaver globals proc = base; - if (vm_mac_acquire(base, size) < 0) + if (vm_mac_acquire_fixed(base, size) < 0) return false; // Allocate page with all bits set to 0, right in the middle @@ -2007,7 +2175,7 @@ bool SheepMem::Init(void) #if EMULATED_PPC // Allocate alternate stack for PowerPC interrupt routine sig_stack = base + size; - if (vm_mac_acquire(sig_stack, SIG_STACK_SIZE) < 0) + if (vm_mac_acquire_fixed(sig_stack, SIG_STACK_SIZE) < 0) return false; #endif @@ -2078,6 +2246,11 @@ void display_alert(int title_id, int pre void ErrorAlert(const char *text) { + if (gui_connection) { + if (rpc_method_invoke(gui_connection, RPC_METHOD_ERROR_ALERT, RPC_TYPE_STRING, text, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR && + rpc_method_wait_for_reply(gui_connection, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR) + return; + } #if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) if (PrefsFindBool("nogui") || x_display == NULL) { printf(GetString(STR_SHELL_ERROR_PREFIX), text); @@ -2097,6 +2270,11 @@ void ErrorAlert(const char *text) void WarningAlert(const char *text) { + if (gui_connection) { + if (rpc_method_invoke(gui_connection, RPC_METHOD_WARNING_ALERT, RPC_TYPE_STRING, text, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR && + rpc_method_wait_for_reply(gui_connection, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR) + return; + } #if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO) if (PrefsFindBool("nogui") || x_display == NULL) { printf(GetString(STR_SHELL_WARNING_PREFIX), text);