diff --git a/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c b/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c index 80a585e1..ad55fb65 100644 --- a/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c +++ b/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c @@ -21,7 +21,11 @@ #include #include #include +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0) +#define LINUX_3_15 +#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35) #define LINUX_26_35 @@ -153,6 +157,9 @@ struct SheepVars { u32 ipfilter; /* Only receive IP packets destined for this address (host byte order) */ char eth_addr[6]; /* Hardware address of the Ethernet card */ char fake_addr[6]; /* Local faked hardware address (what SheepShaver sees) */ +#ifdef LINUX_3_15 + atomic_t got_packet; +#endif }; @@ -390,7 +397,12 @@ static ssize_t sheep_net_read(struct file *f, char *buf, size_t count, loff_t *o break; /* No packet in queue and in blocking mode, so block */ +#ifdef LINUX_3_15 + atomic_set(&v->got_packet, 0); + wait_event_interruptible(v->wait, atomic_read(&v->got_packet)); +#else interruptible_sleep_on(&v->wait); +#endif /* Signal received? Then bail out */ if (signal_pending(current)) @@ -731,7 +743,17 @@ static int sheep_net_receiver(struct sk_buff *skb, struct net_device *dev, struc skb_queue_tail(&v->queue, skb); /* Unblock blocked read */ +#ifdef LINUX_3_15 + + atomic_set(&v->got_packet, 1); + + wake_up_interruptible(&v->wait); + +#else + wake_up(&v->wait); + +#endif return 0; drop: diff --git a/BasiliskII/src/Unix/Makefile.in b/BasiliskII/src/Unix/Makefile.in index d1c8bb70..cc82326d 100644 --- a/BasiliskII/src/Unix/Makefile.in +++ b/BasiliskII/src/Unix/Makefile.in @@ -97,7 +97,7 @@ OBJS := $(SRCS_LIST_TO_OBJS) SRCS := $(SRCS:%=@top_srcdir@/%) define GUI_SRCS_LIST_TO_OBJS - $(addprefix $(OBJ_DIR)/, $(addsuffix .go, $(foreach file, $(GUI_SRCS), \ + $(addprefix $(OBJ_DIR)/, $(addsuffix .guio, $(foreach file, $(GUI_SRCS), \ $(basename $(notdir $(file)))))) endef GUI_OBJS = $(GUI_SRCS_LIST_TO_OBJS) @@ -204,7 +204,7 @@ $(OBJ_DIR)/%.o : %.mm $(CXX) $(CPPFLAGS) $(DEFS) $(CXXFLAGS) -c $< -o $@ $(OBJ_DIR)/%.o : %.s $(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -c $< -o $@ -$(OBJ_DIR)/%.go : %.cpp +$(OBJ_DIR)/%.guio : %.cpp $(CXX) $(CPPFLAGS) $(DEFS) $(CXXFLAGS) $(GUI_CFLAGS) -DSTANDALONE_GUI -c $< -o $@ # Windows resources diff --git a/BasiliskII/src/Unix/configure.ac b/BasiliskII/src/Unix/configure.ac index 7dc71bce..62dd5adc 100644 --- a/BasiliskII/src/Unix/configure.ac +++ b/BasiliskII/src/Unix/configure.ac @@ -124,7 +124,7 @@ case "$target_cpu" in m68k* ) HAVE_M68K=yes;; sparc* ) HAVE_SPARC=yes;; powerpc* ) HAVE_POWERPC=yes;; - x86_64* ) HAVE_X86_64=yes;; + x86_64* | amd64* ) HAVE_X86_64=yes;; esac dnl Check if we should really be assuming x86_64 even if we detected HAVE_I386 above. @@ -534,6 +534,9 @@ mips-sony-bsd|mips-sony-newsos4) no_dev_ptmx=1 LIBS="$LIBS -lstdc++" ;; +*-*-freebsd*) + no_dev_ptmx=1 + ;; esac if test -z "$no_dev_ptmx" ; then diff --git a/BasiliskII/src/Unix/sigsegv.cpp b/BasiliskII/src/Unix/sigsegv.cpp index 347e0f4f..7e94b761 100644 --- a/BasiliskII/src/Unix/sigsegv.cpp +++ b/BasiliskII/src/Unix/sigsegv.cpp @@ -243,9 +243,7 @@ static void powerpc_decode_instruction(instruction_t *instruction, unsigned int #if HAVE_SIGINFO_T // Generic extended signal handler -#if defined(__FreeBSD__) -#define SIGSEGV_ALL_SIGNALS FAULT_HANDLER(SIGBUS) -#elif defined(__hpux) +#if defined(__hpux) #define SIGSEGV_ALL_SIGNALS FAULT_HANDLER(SIGSEGV) FAULT_HANDLER(SIGBUS) #else #define SIGSEGV_ALL_SIGNALS FAULT_HANDLER(SIGSEGV) @@ -285,9 +283,15 @@ static void powerpc_decode_instruction(instruction_t *instruction, unsigned int #endif #if defined(__FreeBSD__) || defined(__OpenBSD__) #if (defined(i386) || defined(__i386__)) +#undef SIGSEGV_ALL_SIGNALS +#define SIGSEGV_ALL_SIGNALS FAULT_HANDLER(SIGBUS) #define SIGSEGV_FAULT_INSTRUCTION (((struct sigcontext *)scp)->sc_eip) #define SIGSEGV_REGISTER_FILE ((SIGSEGV_REGISTER_TYPE *)&(((struct sigcontext *)scp)->sc_edi)) /* EDI is the first GPR (even below EIP) in sigcontext */ #define SIGSEGV_SKIP_INSTRUCTION ix86_skip_instruction +#elif (defined(x86_64) || defined(__x86_64__)) +#define SIGSEGV_FAULT_INSTRUCTION (((struct sigcontext *)scp)->sc_rip) +#define SIGSEGV_REGISTER_FILE ((SIGSEGV_REGISTER_TYPE *)&(((struct sigcontext *)scp)->sc_rdi)) +#define SIGSEGV_SKIP_INSTRUCTION ix86_skip_instruction #endif #endif #if defined(__NetBSD__) @@ -807,6 +811,25 @@ enum { X86_REG_ESI = 1, X86_REG_EDI = 0 #endif +#if (defined(x86_64) || defined(__x86_64__)) + X86_REG_EDI = 0, + X86_REG_ESI = 1, + X86_REG_EDX = 2, + X86_REG_ECX = 3, + X86_REG_R8 = 4, + X86_REG_R9 = 5, + X86_REG_EAX = 6, + X86_REG_EBX = 7, + X86_REG_EBP = 8, + X86_REG_R10 = 9, + X86_REG_R11 = 10, + X86_REG_R12 = 11, + X86_REG_R13 = 12, + X86_REG_R14 = 13, + X86_REG_R15 = 14, + X86_REG_EIP = 19, + X86_REG_ESP = 22, +#endif }; #endif #if defined(__OpenBSD__) diff --git a/BasiliskII/src/Unix/vm_alloc.cpp b/BasiliskII/src/Unix/vm_alloc.cpp index 4d3569c0..0a669292 100644 --- a/BasiliskII/src/Unix/vm_alloc.cpp +++ b/BasiliskII/src/Unix/vm_alloc.cpp @@ -72,6 +72,11 @@ typedef unsigned long vm_uintptr_t; #ifndef MAP_32BIT #define MAP_32BIT 0 #endif +#ifdef __FreeBSD__ +#define FORCE_MAP_32BIT MAP_FIXED +#else +#define FORCE_MAP_32BIT MAP_32BIT +#endif #ifndef MAP_ANON #define MAP_ANON 0 #endif @@ -82,7 +87,7 @@ typedef unsigned long vm_uintptr_t; #define MAP_EXTRA_FLAGS (MAP_32BIT) #ifdef HAVE_MMAP_VM -#if (defined(__linux__) && defined(__i386__)) || HAVE_LINKER_SCRIPT +#if (defined(__linux__) && defined(__i386__)) || defined(__FreeBSD__) || HAVE_LINKER_SCRIPT /* Force a reasonnable address below 0x80000000 on x86 so that we don't get addresses above when the program is run on AMD64. NOTE: this is empirically determined on Linux/x86. */ @@ -118,7 +123,7 @@ static int translate_map_flags(int vm_flags) if (vm_flags & VM_MAP_FIXED) flags |= MAP_FIXED; if (vm_flags & VM_MAP_32BIT) - flags |= MAP_32BIT; + flags |= FORCE_MAP_32BIT; return flags; } #endif diff --git a/SheepShaver/src/MacOSX/Launcher/VMListController.h b/SheepShaver/src/MacOSX/Launcher/VMListController.h index f0437fae..70b453d9 100644 --- a/SheepShaver/src/MacOSX/Launcher/VMListController.h +++ b/SheepShaver/src/MacOSX/Launcher/VMListController.h @@ -20,7 +20,11 @@ #import -@interface VMListController : NSWindowController { +@interface VMListController : NSWindowController +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + +#endif +{ IBOutlet NSTableView *vmList; IBOutlet NSButton *newButton; IBOutlet NSButton *importButton; diff --git a/SheepShaver/src/MacOSX/Launcher/VMSettingsController.h b/SheepShaver/src/MacOSX/Launcher/VMSettingsController.h index 82b85865..2e3a237a 100644 --- a/SheepShaver/src/MacOSX/Launcher/VMSettingsController.h +++ b/SheepShaver/src/MacOSX/Launcher/VMSettingsController.h @@ -21,6 +21,9 @@ #import @interface VMSettingsController : NSWindowController +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + +#endif { BOOL cancelWasClicked; diff --git a/SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm b/SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm index 8dc2c099..c45eacf8 100644 --- a/SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm +++ b/SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm @@ -211,7 +211,7 @@ static NSString *makeRelativeIfNecessary(NSString *path) - (IBAction) addDisk: (id) sender { NSOpenPanel *open = [NSOpenPanel openPanel]; - [open setCanChooseDirectories:NO]; + [open setCanChooseDirectories:YES]; [open setAllowsMultipleSelection:NO]; [open setTreatsFilePackagesAsDirectories:YES]; [open beginSheetForDirectory: [[NSFileManager defaultManager] currentDirectoryPath] diff --git a/SheepShaver/src/MacOSX/XcodeBuildHowTo.txt b/SheepShaver/src/MacOSX/XcodeBuildHowTo.txt new file mode 100644 index 00000000..2a8899ba --- /dev/null +++ b/SheepShaver/src/MacOSX/XcodeBuildHowTo.txt @@ -0,0 +1,26 @@ +The Xcode SheepShaver project makes it easier to build SheepShaver as a +Universal Binary (with 3 architectures: i386, x86_64 and ppc). + +This is an optional build system that does not affect the existing +autogen/configure based build system, which is still fully supported. +The Xcode project will build SheepShaver with configuration +"--enable-sdl-audio --enable-sdl-video --disable-vosf". + +The Xcode project lives in has been tested to work on Snow Leopard +64-bit with Xcode 3.2.6 and the 10.4 SDK installed. It may not work +under newer versions of Xcode or Mac OS X. + +To use it, you need the following: + +1. A complete 'macemu' git checkout of SheepShaver and BasiliskII. +2. SDL installed as a framework in /Library/Frameworks/SDL.framework. +3. You do not need to run autogen.sh / configure to use the Xcode +project. If you've done so already, you should remove or temporarily +move/rename src/Unix/config.h, as the presence of that file currently +conflicts with the Xcode build and will cause errors in Xcode. + +With the above all set, you should be able to launch the Xcode project +and build SheepShaver, resulting in a UB build containing SDL as a +private framework in the bundle. The result will be located in either +SheepShaver/src/MacOSX/build/Debug or SheepShaver/src/MacOSX/build/Release +directories, depending if you do a Debug or Release build. diff --git a/SheepShaver/src/Unix/Linux/sheepthreads.c b/SheepShaver/src/Unix/Linux/sheepthreads.c index 7cff5b75..a286d067 100644 --- a/SheepShaver/src/Unix/Linux/sheepthreads.c +++ b/SheepShaver/src/Unix/Linux/sheepthreads.c @@ -48,19 +48,19 @@ extern int test_and_set(int *var, int val); /* Linux kernel calls */ extern int __clone(int (*fn)(void *), void *, int, void *); -/* struct sem_t */ +/* libc no longer provides struct _pthread_fastlock in pthread.h */ +struct fastlock { + int status; + int spinlock; +}; + typedef struct { - struct _pthread_fastlock __sem_lock; - int __sem_value; - _pthread_descr __sem_waiting; + struct fastlock sem_lock; + int sem_value; + int sem_waiting; } sem_t; #define SEM_VALUE_MAX 64 -#define status __status -#define spinlock __spinlock -#define sem_lock __sem_lock -#define sem_value __sem_value -#define sem_waiting __sem_waiting /* Wait for "clone" children only (Linux 2.4+ specific) */ #ifndef __WCLONE @@ -185,13 +185,13 @@ void pthread_testcancel(void) need to make sure that the compiler has flushed everything to memory. */ #define MEMORY_BARRIER() __asm__ __volatile__ ("sync" : : : "memory") -static void fastlock_init(struct _pthread_fastlock *lock) +static void fastlock_init(struct fastlock *lock) { lock->status = 0; lock->spinlock = 0; } -static int fastlock_try_acquire(struct _pthread_fastlock *lock) +static int fastlock_try_acquire(struct fastlock *lock) { int res = EBUSY; if (test_and_set(&lock->spinlock, 1) == 0) { @@ -205,14 +205,14 @@ static int fastlock_try_acquire(struct _pthread_fastlock *lock) return res; } -static void fastlock_acquire(struct _pthread_fastlock *lock) +static void fastlock_acquire(struct fastlock *lock) { MEMORY_BARRIER(); while (test_and_set(&lock->spinlock, 1)) usleep(0); } -static void fastlock_release(struct _pthread_fastlock *lock) +static void fastlock_release(struct fastlock *lock) { MEMORY_BARRIER(); lock->spinlock = 0; @@ -226,10 +226,7 @@ static void fastlock_release(struct _pthread_fastlock *lock) int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex_attr) { - fastlock_init(&mutex->__m_lock); - mutex->__m_kind = mutex_attr ? mutex_attr->__mutexkind : PTHREAD_MUTEX_TIMED_NP; - mutex->__m_count = 0; - mutex->__m_owner = NULL; + fastlock_init((struct fastlock *)mutex); return 0; } @@ -240,12 +237,7 @@ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex_ int pthread_mutex_destroy(pthread_mutex_t *mutex) { - switch (mutex->__m_kind) { - case PTHREAD_MUTEX_TIMED_NP: - return (mutex->__m_lock.__status != 0) ? EBUSY : 0; - default: - return EINVAL; - } + return (((struct fastlock *)mutex)->status != 0) ? EBUSY : 0; } @@ -255,13 +247,8 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex) int pthread_mutex_lock(pthread_mutex_t *mutex) { - switch (mutex->__m_kind) { - case PTHREAD_MUTEX_TIMED_NP: - fastlock_acquire(&mutex->__m_lock); - return 0; - default: - return EINVAL; - } + fastlock_acquire((struct fastlock *)mutex); + return 0; } @@ -271,12 +258,7 @@ int pthread_mutex_lock(pthread_mutex_t *mutex) int pthread_mutex_trylock(pthread_mutex_t *mutex) { - switch (mutex->__m_kind) { - case PTHREAD_MUTEX_TIMED_NP: - return fastlock_try_acquire(&mutex->__m_lock); - default: - return EINVAL; - } + return fastlock_try_acquire((struct fastlock *)mutex); } @@ -286,13 +268,8 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex) int pthread_mutex_unlock(pthread_mutex_t *mutex) { - switch (mutex->__m_kind) { - case PTHREAD_MUTEX_TIMED_NP: - fastlock_release(&mutex->__m_lock); - return 0; - default: - return EINVAL; - } + fastlock_release((struct fastlock *)mutex); + return 0; } @@ -302,7 +279,6 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex) int pthread_mutexattr_init(pthread_mutexattr_t *attr) { - attr->__mutexkind = PTHREAD_MUTEX_TIMED_NP; return 0; } @@ -333,7 +309,7 @@ int sem_init(sem_t *sem, int pshared, unsigned int value) } fastlock_init(&sem->sem_lock); sem->sem_value = value; - sem->sem_waiting = NULL; + sem->sem_waiting = 0; return 0; } @@ -353,7 +329,7 @@ int sem_destroy(sem_t *sem) return -1; } sem->sem_value = 0; - sem->sem_waiting = NULL; + sem->sem_waiting = 0; return 0; } @@ -374,7 +350,7 @@ int sem_wait(sem_t *sem) fastlock_release(&sem->sem_lock); return 0; } - sem->sem_waiting = (struct _pthread_descr_struct *)((long)sem->sem_waiting + 1); + sem->sem_waiting++; while (sem->sem_value == 0) { fastlock_release(&sem->sem_lock); usleep(0); @@ -398,7 +374,7 @@ int sem_post(sem_t *sem) } fastlock_acquire(&sem->sem_lock); if (sem->sem_waiting) - sem->sem_waiting = (struct _pthread_descr_struct *)((long)sem->sem_waiting - 1); + sem->sem_waiting--; else { if (sem->sem_value >= SEM_VALUE_MAX) { errno = ERANGE; @@ -466,4 +442,4 @@ int main(void) return 5; return 0; } -#endif +#endif \ No newline at end of file diff --git a/SheepShaver/src/Unix/Makefile.in b/SheepShaver/src/Unix/Makefile.in index e779835e..9bb39077 100644 --- a/SheepShaver/src/Unix/Makefile.in +++ b/SheepShaver/src/Unix/Makefile.in @@ -97,7 +97,7 @@ endef OBJS = $(SRCS_LIST_TO_OBJS) define GUI_SRCS_LIST_TO_OBJS - $(addprefix $(OBJ_DIR)/, $(addsuffix .go, $(foreach file, $(GUI_SRCS), \ + $(addprefix $(OBJ_DIR)/, $(addsuffix .guio, $(foreach file, $(GUI_SRCS), \ $(basename $(notdir $(file)))))) endef GUI_OBJS = $(GUI_SRCS_LIST_TO_OBJS) @@ -195,7 +195,7 @@ $(OBJ_DIR)/%.o : %.S $(CPP) $(CPPFLAGS) -D__ASSEMBLY__ $< -o $*.out.s $(AS) $(ASFLAGS) -o $@ $*.out.s rm $*.out.s -$(OBJ_DIR)/%.go : %.cpp +$(OBJ_DIR)/%.guio : %.cpp $(CXX) $(CPPFLAGS) $(DEFS) $(CXXFLAGS) $(GUI_CFLAGS) -DSTANDALONE_GUI -c $< -o $@ # Kheperix CPU emulator diff --git a/SheepShaver/src/Unix/configure.ac b/SheepShaver/src/Unix/configure.ac index f44ed628..d4f56097 100644 --- a/SheepShaver/src/Unix/configure.ac +++ b/SheepShaver/src/Unix/configure.ac @@ -484,6 +484,9 @@ mips-sony-bsd|mips-sony-newsos4) *-*-darwin*) no_dev_ptmx=1 ;; +*-*-freebsd*) + no_dev_ptmx=1 + ;; esac if test -z "$no_dev_ptmx" ; then diff --git a/SheepShaver/src/Unix/main_unix.cpp b/SheepShaver/src/Unix/main_unix.cpp index aa23fc86..3d0ee43e 100644 --- a/SheepShaver/src/Unix/main_unix.cpp +++ b/SheepShaver/src/Unix/main_unix.cpp @@ -90,6 +90,7 @@ #include #include #include +#include #include #include "sysdeps.h" diff --git a/SheepShaver/src/Unix/sysdeps.h b/SheepShaver/src/Unix/sysdeps.h index 3f34375d..0099527b 100644 --- a/SheepShaver/src/Unix/sysdeps.h +++ b/SheepShaver/src/Unix/sysdeps.h @@ -69,7 +69,7 @@ #endif // Fix offsetof() on FreeBSD and GCC >= 3.4 -#if defined(__FreeBSD__) && defined(__cplusplus) +#if defined(__FreeBSD__) && defined(__cplusplus) && __GNUC__ < 4 #undef offsetof /* The cast to "char &" below avoids problems with user-defined "operator &", which can appear in a POD type. */