--- BasiliskII/src/MacOSX/main_macosx.mm 2006/05/08 16:56:07 1.16 +++ BasiliskII/src/MacOSX/main_macosx.mm 2011/03/11 16:43:09 1.23 @@ -1,11 +1,11 @@ /* - * $Id: main_macosx.mm,v 1.16 2006/05/08 16:56:07 gbeauche Exp $ + * $Id: main_macosx.mm,v 1.23 2011/03/11 16:43:09 asvitkine Exp $ * * main_macosx.mm - Startup code for MacOS X * Based (in a small way) on the default main.m, and on Basilisk's main_unix.cpp * - * Basilisk II (C) 1997-2005 Christian Bauer + * Basilisk II (C) 1997-2008 Christian Bauer * * 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 @@ -40,21 +40,21 @@ using std::string; #include "cpu_emulation.h" -#include "macos_util_macosx.h" -#include "main.h" +#include "sys.h" +#include "rom_patches.h" +#include "xpram.h" +#include "video.h" #include "prefs.h" #include "prefs_editor.h" -#include "rom_patches.h" -#include "sigsegv.h" -#include "sys.h" +#include "macos_util_macosx.h" #include "user_strings.h" #include "version.h" -#include "video.h" +#include "main.h" #include "vm_alloc.h" -#include "xpram.h" +#include "sigsegv.h" #if USE_JIT -extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp +extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp #endif #ifdef ENABLE_MON @@ -73,12 +73,14 @@ const char ROM_FILE_NAME[] = "ROM"; const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area +static char *bundle = NULL; // If in an OS X application bundle, its path + + // CPU and FPU type, addressing mode int CPUType; bool CPUIs68060; int FPUType; bool TwentyFourBitAddressing; -bool ThirtyThreeBitAddressing = false; // Global variables @@ -114,31 +116,15 @@ static bool lm_area_mapped = false; // F * Helpers to map memory that can be accessed from the Mac side */ -// NOTE: VM_MAP_33BIT is only used when compiling a 64-bit JIT on specific platforms +// NOTE: VM_MAP_32BIT is only used when compiling a 64-bit JIT on specific platforms void *vm_acquire_mac(size_t size) { - void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT); -#ifdef USE_33BIT_ADDRESSING - if (m == VM_MAP_FAILED) { - printf("WARNING: Cannot acquire memory in 33-bit address space (%s)\n", strerror(errno)); - ThirtyThreeBitAddressing = false; - m = vm_acquire(size); - } -#endif - return m; + return vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); } static int vm_acquire_mac_fixed(void *addr, size_t size) { - int ret = vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_33BIT); -#ifdef USE_33BIT_ADDRESSING - if (ret < 0) { - printf("WARNING: Cannot acquire fixed memory in 33-bit address space (%s)\n", strerror(errno)); - ThirtyThreeBitAddressing = false; - ret = vm_acquire_fixed(addr, size); - } -#endif - return ret; + return vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_32BIT); } @@ -146,13 +132,13 @@ static int vm_acquire_mac_fixed(void *ad * SIGSEGV handler */ -static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, - sigsegv_address_t fault_instruction) +static sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip) { + const uintptr fault_address = (uintptr)sigsegv_get_fault_address(sip); #if ENABLE_VOSF // Handle screen fault - extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t); - if (Screen_fault_handler(fault_address, fault_instruction)) + extern bool Screen_fault_handler(sigsegv_info_t *sip); + if (Screen_fault_handler(sip)) return SIGSEGV_RETURN_SUCCESS; #endif @@ -169,15 +155,16 @@ static sigsegv_return_t sigsegv_handler( return SIGSEGV_RETURN_FAILURE; } - /* * Dump state when everything went wrong after a SEGV */ -static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) +static void sigsegv_dump_state(sigsegv_info_t *sip) { + const sigsegv_address_t fault_address = sigsegv_get_fault_address(sip); + const sigsegv_address_t fault_instruction = sigsegv_get_fault_instruction_address(sip); fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); - if (fault_instruction != SIGSEGV_INVALID_PC) + if (fault_instruction != SIGSEGV_INVALID_ADDRESS) fprintf(stderr, " [IP=%p]", fault_instruction); fprintf(stderr, "\n"); uaecptr nextpc; @@ -197,24 +184,38 @@ static void sigsegv_dump_state(sigsegv_a /* + * Screen fault handler + */ + +bool Screen_fault_handler(sigsegv_info_t *sip) +{ + return true; +} + + +/* * Main program */ static void usage(const char *prg_name) { - printf("Usage: %s [OPTION...]\n", prg_name); - printf("\nUnix options:\n"); - printf(" --help\n display this usage message\n"); - printf(" --config FILE\n read/write configuration from/to FILE\n"); - printf(" --break ADDRESS\n set ROM breakpoint\n"); - printf(" --rominfo\n dump ROM information\n"); - LoadPrefs(); // read the prefs file so PrefsPrintUsage() will print the correct default values + printf( + "Usage: %s [OPTION...]\n" + "\nUnix options:\n" + " --config FILE\n read/write configuration from/to FILE\n" + " --break ADDRESS\n set ROM breakpoint\n" + " --rominfo\n dump ROM information\n", prg_name + ); + LoadPrefs(NULL); // read the prefs file so PrefsPrintUsage() will print the correct default values PrefsPrintUsage(); exit(0); } int main(int argc, char **argv) { + const char *vmdir = NULL; + char str[256]; + // Initialize variables RAMBaseHost = NULL; ROMBaseHost = NULL; @@ -230,11 +231,13 @@ int main(int argc, char **argv) if (strcmp(argv[i], "--help") == 0) { usage(argv[0]); } else if (strncmp(argv[i], "-psn_", 5) == 0) {// OS X process identifier - i++; + argv[i++] = NULL; } else if (strcmp(argv[i], "--break") == 0) { - i++; - if (i < argc) + argv[i++] = NULL; + if (i < argc) { ROMBreakpoint = strtol(argv[i], NULL, 0); + argv[i] = NULL; + } } else if (strcmp(argv[i], "--config") == 0) { argv[i++] = NULL; if (i < argc) { @@ -243,19 +246,53 @@ int main(int argc, char **argv) argv[i] = NULL; } } else if (strcmp(argv[i], "--rominfo") == 0) { + argv[i] = NULL; PrintROMInfo = true; - } else if (argv[i][0] == '-') { - fprintf(stderr, "Unrecognized option '%s'\n", argv[i]); - usage(argv[0]); + } + } + + // Remove processed arguments + for (int i=1; i i) { + k -= i; + for (int j=i+k; j