From 20d2de95cec645c80082b457bbec37035d1aaf96 Mon Sep 17 00:00:00 2001 From: kanjitalk755 Date: Fri, 23 Apr 2021 10:19:48 +0900 Subject: [PATCH] marged Jagmn's patch https://emaculation.com/forum/viewtopic.php?p=70121#p70121 --- BasiliskII/src/CrossPlatform/vm_alloc.cpp | 7 +++++++ BasiliskII/src/slirp/slirp.c | 2 +- SheepShaver/src/MacOSX/Info.plist.in | 4 ---- .../project.pbxproj | 20 ++++++------------- .../src/MacOSX/config/config-macosx-aarch64.h | 6 +++--- SheepShaver/src/Unix/configure.ac | 4 ++-- SheepShaver/src/Unix/main_unix.cpp | 9 +++++++++ SheepShaver/src/gfxaccel.cpp | 4 ++-- SheepShaver/src/kpx_cpu/src/cpu/jit/dyngen.c | 1 + SheepShaver/src/kpx_cpu/src/cpu/vm.hpp | 4 ++-- 10 files changed, 33 insertions(+), 28 deletions(-) diff --git a/BasiliskII/src/CrossPlatform/vm_alloc.cpp b/BasiliskII/src/CrossPlatform/vm_alloc.cpp index 3aa369da..19d109e9 100755 --- a/BasiliskII/src/CrossPlatform/vm_alloc.cpp +++ b/BasiliskII/src/CrossPlatform/vm_alloc.cpp @@ -229,6 +229,13 @@ void *vm_acquire_reserved(size_t size) { return reserved_buf && size <= RESERVED_SIZE ? reserved_buf : VM_MAP_FAILED; } +int vm_init_reserved(void *hostAddress) { + int result = vm_acquire_fixed(hostAddress, RESERVED_SIZE); + if (result >= 0) + reserved_buf = hostAddress; + return result; +} + /* Allocate zero-filled memory of SIZE bytes. The mapping is private and default protection bits are read / write. The return value is the actual mapping address chosen or VM_MAP_FAILED for errors. */ diff --git a/BasiliskII/src/slirp/slirp.c b/BasiliskII/src/slirp/slirp.c index 4aad7ba4..45c97612 100755 --- a/BasiliskII/src/slirp/slirp.c +++ b/BasiliskII/src/slirp/slirp.c @@ -87,7 +87,7 @@ static int get_dns_addr(struct in_addr *pdns_addr) static int get_dns_addr(struct in_addr *pdns_addr) { char buff[512]; - char buff2[256]; + char buff2[257]; FILE *f; int found = 0; struct in_addr tmp_addr; diff --git a/SheepShaver/src/MacOSX/Info.plist.in b/SheepShaver/src/MacOSX/Info.plist.in index dfe70240..a70e1ec9 100644 --- a/SheepShaver/src/MacOSX/Info.plist.in +++ b/SheepShaver/src/MacOSX/Info.plist.in @@ -39,10 +39,6 @@ @PACKAGE_VERSION@ CSResourcesFileMapped - LSArchitecturePriority - - x86_64 - LSMinimumSystemVersion 10.7.0 NSHighResolutionCapable diff --git a/SheepShaver/src/MacOSX/SheepShaver_Xcode8.xcodeproj/project.pbxproj b/SheepShaver/src/MacOSX/SheepShaver_Xcode8.xcodeproj/project.pbxproj index 8002534c..79681aa2 100755 --- a/SheepShaver/src/MacOSX/SheepShaver_Xcode8.xcodeproj/project.pbxproj +++ b/SheepShaver/src/MacOSX/SheepShaver_Xcode8.xcodeproj/project.pbxproj @@ -1210,7 +1210,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.7; OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)"; PRODUCT_NAME = kpx_cpu; - VALID_ARCHS = x86_64; + VALID_ARCHS = "x86_64 arm64"; }; name = Debug; }; @@ -1249,7 +1249,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.7; OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)"; PRODUCT_NAME = kpx_cpu; - VALID_ARCHS = x86_64; + VALID_ARCHS = "x86_64 arm64"; }; name = Release; }; @@ -1328,15 +1328,11 @@ MACOSX_DEPLOYMENT_TARGET = 10.7; OTHER_CFLAGS = ""; OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)"; - OTHER_LDFLAGS = ( - "-pagezero_size", - 0x3000, - "-lkpx_cpu", - ); + OTHER_LDFLAGS = "-lkpx_cpu"; PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO; PRODUCT_BUNDLE_IDENTIFIER = net.cebix.sheepshaver; PRODUCT_NAME = SheepShaver; - VALID_ARCHS = x86_64; + VALID_ARCHS = "x86_64 arm64"; WARNING_LDFLAGS = ""; }; name = Debug; @@ -1394,15 +1390,11 @@ MACOSX_DEPLOYMENT_TARGET = 10.7; OTHER_CFLAGS = ""; OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)"; - OTHER_LDFLAGS = ( - "-pagezero_size", - 0x3000, - "-lkpx_cpu", - ); + OTHER_LDFLAGS = "-lkpx_cpu"; PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO; PRODUCT_BUNDLE_IDENTIFIER = net.cebix.sheepshaver; PRODUCT_NAME = SheepShaver; - VALID_ARCHS = x86_64; + VALID_ARCHS = "x86_64 arm64"; }; name = Release; }; diff --git a/SheepShaver/src/MacOSX/config/config-macosx-aarch64.h b/SheepShaver/src/MacOSX/config/config-macosx-aarch64.h index aa04b6a9..c904f671 100644 --- a/SheepShaver/src/MacOSX/config/config-macosx-aarch64.h +++ b/SheepShaver/src/MacOSX/config/config-macosx-aarch64.h @@ -405,8 +405,8 @@ ordering is the same as for multi-word integers. */ /* #undef HOST_FLOAT_WORDS_BIG_ENDIAN */ -/* Define constant offset for Mac address translation */ -/* #undef NATMEM_OFFSET */ +/* Define constant offset for Mac address translation: macosx-aarch64 is always 64bit */ +#define NATMEM_OFFSET 0x400000000000 /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "Christian.Bauer@uni-mainz.de" @@ -428,7 +428,7 @@ /* Define if the __PAGEZERO Mach-O Low Memory Globals hack works on this system. */ -#define PAGEZERO_HACK 1 +/* #define PAGEZERO_HACK 1 */ /* Define as the return type of signal handlers (`int' or `void'). */ #define RETSIGTYPE void diff --git a/SheepShaver/src/Unix/configure.ac b/SheepShaver/src/Unix/configure.ac index 35f3495e..3b3480ca 100755 --- a/SheepShaver/src/Unix/configure.ac +++ b/SheepShaver/src/Unix/configure.ac @@ -1640,13 +1640,13 @@ if [[ "x$EMULATED_PPC" = "xyes" ]]; then esac fi if [[ "x$have_dyngen_gcc3" = "xyes" ]]; then - DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -fno-align-functions" + DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -fno-align-functions -fno-stack-protector" else DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -malign-functions=0" fi DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -finline-functions -finline-limit=10000 -fno-exceptions -g0" if [[ "x$have_dyngen_gcc3" = "xyes" ]]; then - DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -fno-reorder-blocks -fno-optimize-sibling-calls" + DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -fno-reorder-blocks -fno-optimize-sibling-calls -fno-reorder-blocks-and-partition" fi if [[ "x$DYNGEN_CC" != "x$CXX" ]]; then DYNGEN_CFLAGS="-O2 $CFLAGS" diff --git a/SheepShaver/src/Unix/main_unix.cpp b/SheepShaver/src/Unix/main_unix.cpp index 0c5b76a1..5a470e6c 100755 --- a/SheepShaver/src/Unix/main_unix.cpp +++ b/SheepShaver/src/Unix/main_unix.cpp @@ -2210,6 +2210,7 @@ rti:; } #endif +extern int vm_init_reserved(void *hostAddress); /* * Helpers to share 32-bit addressable data with MacOS @@ -2221,7 +2222,15 @@ bool SheepMem::Init(void) page_size = getpagesize(); // Allocate SheepShaver globals +#ifdef NATMEM_OFFSET + if (vm_mac_acquire_fixed(ROM_BASE + ROM_AREA_SIZE + SIG_STACK_SIZE, size) < 0) + return false; + uint8 *adr = Mac2HostAddr(ROM_BASE + ROM_AREA_SIZE + SIG_STACK_SIZE); + if (vm_init_reserved(adr + size) < 0) + return false; +#else uint8 *adr = vm_mac_acquire(size); +#endif if (adr == VM_MAP_FAILED) return false; proc = base = Host2MacAddr(adr); diff --git a/SheepShaver/src/gfxaccel.cpp b/SheepShaver/src/gfxaccel.cpp index ed65e5d8..ec1e96a3 100644 --- a/SheepShaver/src/gfxaccel.cpp +++ b/SheepShaver/src/gfxaccel.cpp @@ -85,7 +85,7 @@ static inline void do_invrect(uint8 *dest, uint32 length) } // Align on 32-bit boundaries - if (bpp < 32 && (((uintptr)dest) & 2)) { + if (bpp < 32 && (((uintptr)dest) & 2) && length >= 2) { INVERT_2(dest, 0); dest += 2; length -= 2; } @@ -198,7 +198,7 @@ static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) } // Align on 32-bit boundaries - if (bpp < 32 && (((uintptr)dest) & 2)) { + if (bpp < 32 && (((uintptr)dest) & 2) && length >= 2) { FILL_2(dest, 0, color); dest += 2; length -= 2; } diff --git a/SheepShaver/src/kpx_cpu/src/cpu/jit/dyngen.c b/SheepShaver/src/kpx_cpu/src/cpu/jit/dyngen.c index b6ead792..2fdeebd1 100644 --- a/SheepShaver/src/kpx_cpu/src/cpu/jit/dyngen.c +++ b/SheepShaver/src/kpx_cpu/src/cpu/jit/dyngen.c @@ -2396,6 +2396,7 @@ void patch_relocations(FILE *outfile, const char *name, host_ulong size, host_ul fprintf(outfile, " *(uint32_t *)(code_ptr() + %d) = (int32_t)%s + %d;\n", slide, final_sym_name, addend); break; case R_X86_64_PC32: + case R_X86_64_PLT32: fprintf(outfile, " *(uint32_t *)(code_ptr() + %d) = %s - (long)(code_ptr() + %d) + %d;\n", slide, final_sym_name, slide, addend); break; diff --git a/SheepShaver/src/kpx_cpu/src/cpu/vm.hpp b/SheepShaver/src/kpx_cpu/src/cpu/vm.hpp index 5c0b7330..c01dc6ac 100755 --- a/SheepShaver/src/kpx_cpu/src/cpu/vm.hpp +++ b/SheepShaver/src/kpx_cpu/src/cpu/vm.hpp @@ -205,13 +205,13 @@ const uintptr VMBaseDiff = NATMEM_OFFSET; #if REAL_ADDRESSING || DIRECT_ADDRESSING static inline uint8 * vm_do_get_real_address(vm_addr_t addr) { - uintptr a = vm_wrap_address(VMBaseDiff + addr); + uintptr a = vm_wrap_address(addr); #if defined(__APPLE__) && defined(__x86_64__) extern uint8 gZeroPage[0x3000], gKernelData[0x2000]; if (a < 0x3000) return &gZeroPage[a]; else if ((a & ~0x1fff) == 0x68ffe000 || (a & ~0x1fff) == 0x5fffe000) return &gKernelData[a & 0x1fff]; #endif - return (uint8 *)a; + return (uint8 *)(VMBaseDiff + a); } static inline vm_addr_t vm_do_get_virtual_address(uint8 *addr) {