From e3710843b1cafc4675e38d8fb247360e20c1b934 Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Thu, 30 May 2013 21:34:30 -0400 Subject: [PATCH] FreeBSD amd64 fixups * Look for CPU named "amd64" as well as "x86_64" * Don't use /dev/ptmx on FreeBSD * On amd64 FreeBSD uses SIGSEGV, not SIGBUS * Use MAP_FIXED to force allocations within 32-bits, it's the only way * Need for SHMLBA * The old offsetof() fix is no longer needed * Preliminary work on instruction skipping --- BasiliskII/src/Unix/configure.ac | 5 ++++- BasiliskII/src/Unix/sigsegv.cpp | 29 ++++++++++++++++++++++++++--- BasiliskII/src/Unix/vm_alloc.cpp | 9 +++++++-- SheepShaver/src/Unix/configure.ac | 3 +++ SheepShaver/src/Unix/main_unix.cpp | 1 + SheepShaver/src/Unix/sysdeps.h | 2 +- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/BasiliskII/src/Unix/configure.ac b/BasiliskII/src/Unix/configure.ac index 62d45f57..e12f3bea 100644 --- a/BasiliskII/src/Unix/configure.ac +++ b/BasiliskII/src/Unix/configure.ac @@ -112,7 +112,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. @@ -510,6 +510,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/BasiliskII/src/Unix/sigsegv.cpp b/BasiliskII/src/Unix/sigsegv.cpp index 951b4c66..fcc857bf 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__) @@ -805,6 +809,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 11c3fddc..17280a46 100644 --- a/BasiliskII/src/Unix/vm_alloc.cpp +++ b/BasiliskII/src/Unix/vm_alloc.cpp @@ -71,6 +71,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 @@ -81,7 +86,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. */ @@ -117,7 +122,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/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. */