From 7c3242f6da26debc53ca8c5344c3590096bf6516 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Thu, 10 Nov 2022 00:45:30 +0100 Subject: [PATCH] early-access version 3101 --- CMakeLists.txt | 8 ++++---- README.md | 2 +- externals/CMakeLists.txt | 11 +++++------ src/audio_core/CMakeLists.txt | 2 +- src/common/common_funcs.h | 4 +++- src/common/host_memory.cpp | 6 ++++++ src/core/CMakeLists.txt | 14 ++++++------- src/core/arm/dynarmic/arm_dynarmic_32.cpp | 5 +++++ src/core/arm/dynarmic/arm_dynarmic_cp15.cpp | 22 ++++++++++++++------- src/core/arm/exclusive_monitor.cpp | 4 ++-- src/core/hle/kernel/physical_core.cpp | 4 ++-- src/video_core/CMakeLists.txt | 15 +++++++++++--- src/video_core/macro/macro.cpp | 3 +++ src/yuzu/CMakeLists.txt | 2 +- 14 files changed, 67 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8efbe6129..21a30c667 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,13 +133,13 @@ if (NOT ENABLE_GENERIC) if (MSVC) detect_architecture("_M_AMD64" x86_64) detect_architecture("_M_IX86" x86) - detect_architecture("_M_ARM" ARM) - detect_architecture("_M_ARM64" ARM64) + detect_architecture("_M_ARM" arm) + detect_architecture("_M_ARM64" arm64) else() detect_architecture("__x86_64__" x86_64) detect_architecture("__i386__" x86) - detect_architecture("__arm__" ARM) - detect_architecture("__aarch64__" ARM64) + detect_architecture("__arm__" arm) + detect_architecture("__aarch64__" arm64) endif() endif() diff --git a/README.md b/README.md index 99c269ba6..10045617a 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3100. +This is the source code for early-access 3101. ## Legal Notice diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 746dd11c5..c5fc4af62 100755 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -7,15 +7,14 @@ include(DownloadExternals) # xbyak if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) - add_library(xbyak INTERFACE) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include) - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/xbyak/xbyak DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include) - target_include_directories(xbyak SYSTEM INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include) - target_compile_definitions(xbyak INTERFACE XBYAK_NO_OP_NAMES) + add_subdirectory(xbyak) endif() # Dynarmic -if (ARCHITECTURE_x86_64) +if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) + if (ARCHITECTURE_arm64) + set(DYNARMIC_FRONTENDS "A32") + endif() set(DYNARMIC_NO_BUNDLED_FMT ON) set(DYNARMIC_IGNORE_ASSERTS ON CACHE BOOL "" FORCE) add_subdirectory(dynarmic) diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 87891cabc..e4ab6795f 100755 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -217,7 +217,7 @@ else() endif() target_link_libraries(audio_core PUBLIC common core) -if (ARCHITECTURE_x86_64) +if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) target_link_libraries(audio_core PRIVATE dynarmic) endif() diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 4f2291f2e..2eabb56af 100755 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -31,8 +31,10 @@ #ifndef _MSC_VER -#ifdef ARCHITECTURE_x86_64 +#if defined(ARCHITECTURE_x86_64) #define Crash() __asm__ __volatile__("int $3") +#elif defined(ARCHITECTURE_arm64) +#define Crash() __asm__ __volatile__("brk #0") #else #define Crash() exit(1) #endif diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 35dbd2a9e..99849ea8f 100755 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -359,6 +359,12 @@ public: } }); + long page_size = sysconf(_SC_PAGESIZE); + if (page_size != 0x1000) { + LOG_CRITICAL(HW_Memory, "page size {:#x} is incompatible with 4K paging", page_size); + throw std::bad_alloc{}; + } + // Backing memory initialization #if defined(__FreeBSD__) && __FreeBSD__ < 13 // XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30 diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 9339e40da..e4eca57f4 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -497,10 +497,6 @@ add_library(core STATIC hle/service/hid/irsensor/processor_base.h hle/service/hid/irsensor/tera_plugin_processor.cpp hle/service/hid/irsensor/tera_plugin_processor.h - hle/service/jit/jit_context.cpp - hle/service/jit/jit_context.h - hle/service/jit/jit.cpp - hle/service/jit/jit.h hle/service/lbl/lbl.cpp hle/service/lbl/lbl.h hle/service/ldn/lan_discovery.cpp @@ -805,14 +801,18 @@ if (ENABLE_WEB_SERVICE) target_link_libraries(core PRIVATE web_service) endif() -if (ARCHITECTURE_x86_64) +if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) target_sources(core PRIVATE - arm/dynarmic/arm_dynarmic_32.cpp - arm/dynarmic/arm_dynarmic_32.h arm/dynarmic/arm_dynarmic_64.cpp arm/dynarmic/arm_dynarmic_64.h + arm/dynarmic/arm_dynarmic_32.cpp + arm/dynarmic/arm_dynarmic_32.h arm/dynarmic/arm_dynarmic_cp15.cpp arm/dynarmic/arm_dynarmic_cp15.h + hle/service/jit/jit_context.cpp + hle/service/jit/jit_context.h + hle/service/jit/jit.cpp + hle/service/jit/jit.h ) target_link_libraries(core PRIVATE dynarmic) endif() diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index 22295b325..36d778966 100755 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp @@ -301,6 +301,11 @@ std::shared_ptr ARM_Dynarmic_32::MakeJit(Common::PageTable* } } +#ifdef ARCHITECTURE_arm64 + // TODO: remove when fixed in dynarmic + config.optimizations &= ~Dynarmic::OptimizationFlag::BlockLinking; +#endif + return std::make_unique(config); } diff --git a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp index d754a7890..b2fe154f5 100755 --- a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp @@ -52,12 +52,16 @@ CallbackOrAccessOneWord DynarmicCP15::CompileSendOneWord(bool two, unsigned opc1 case 4: // CP15_DATA_SYNC_BARRIER return Callback{ - [](Dynarmic::A32::Jit*, void*, std::uint32_t, std::uint32_t) -> std::uint64_t { -#ifdef _MSC_VER + [](void*, std::uint32_t, std::uint32_t) -> std::uint64_t { +#if defined(_MSC_VER) && defined(ARCHITECTURE_x86_64) _mm_mfence(); _mm_lfence(); -#else +#elif defined(ARCHITECTURE_x86_64) asm volatile("mfence\n\tlfence\n\t" : : : "memory"); +#elif defined(ARCHITECTURE_arm64) + asm volatile("dsb sy\n\t" : : : "memory"); +#else +#error Unsupported architecture #endif return 0; }, @@ -66,11 +70,15 @@ CallbackOrAccessOneWord DynarmicCP15::CompileSendOneWord(bool two, unsigned opc1 case 5: // CP15_DATA_MEMORY_BARRIER return Callback{ - [](Dynarmic::A32::Jit*, void*, std::uint32_t, std::uint32_t) -> std::uint64_t { -#ifdef _MSC_VER + [](void*, std::uint32_t, std::uint32_t) -> std::uint64_t { +#if defined(_MSC_VER) && defined(ARCHITECTURE_x86_64) _mm_mfence(); -#else +#elif defined(ARCHITECTURE_x86_64) asm volatile("mfence\n\t" : : : "memory"); +#elif defined(ARCHITECTURE_arm64) + asm volatile("dmb sy\n\t" : : : "memory"); +#else +#error Unsupported architecture #endif return 0; }, @@ -115,7 +123,7 @@ CallbackOrAccessOneWord DynarmicCP15::CompileGetOneWord(bool two, unsigned opc1, CallbackOrAccessTwoWords DynarmicCP15::CompileGetTwoWords(bool two, unsigned opc, CoprocReg CRm) { if (!two && opc == 0 && CRm == CoprocReg::C14) { // CNTPCT - const auto callback = [](Dynarmic::A32::Jit*, void* arg, u32, u32) -> u64 { + const auto callback = [](void* arg, u32, u32) -> u64 { const auto& parent_arg = *static_cast(arg); return parent_arg.system.CoreTiming().GetClockTicks(); }; diff --git a/src/core/arm/exclusive_monitor.cpp b/src/core/arm/exclusive_monitor.cpp index 6683bf592..88d3cd4a2 100755 --- a/src/core/arm/exclusive_monitor.cpp +++ b/src/core/arm/exclusive_monitor.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#ifdef ARCHITECTURE_x86_64 +#if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64) #include "core/arm/dynarmic/arm_exclusive_monitor.h" #endif #include "core/arm/exclusive_monitor.h" @@ -13,7 +13,7 @@ ExclusiveMonitor::~ExclusiveMonitor() = default; std::unique_ptr MakeExclusiveMonitor(Memory::Memory& memory, std::size_t num_cores) { -#ifdef ARCHITECTURE_x86_64 +#if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64) return std::make_unique(memory, num_cores); #else // TODO(merry): Passthrough exclusive monitor diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cpp index c8e3040b5..dd3518b85 100755 --- a/src/core/hle/kernel/physical_core.cpp +++ b/src/core/hle/kernel/physical_core.cpp @@ -12,7 +12,7 @@ namespace Kernel { PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_) : core_index{core_index_}, system{system_}, scheduler{scheduler_} { -#ifdef ARCHITECTURE_x86_64 +#if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64) // TODO(bunnei): Initialization relies on a core being available. We may later replace this with // a 32-bit instance of Dynarmic. This should be abstracted out to a CPU manager. auto& kernel = system.Kernel(); @@ -26,7 +26,7 @@ PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KSche PhysicalCore::~PhysicalCore() = default; void PhysicalCore::Initialize([[maybe_unused]] bool is_64_bit) { -#ifdef ARCHITECTURE_x86_64 +#if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64) auto& kernel = system.Kernel(); if (!is_64_bit) { // We already initialized a 64-bit core, replace with a 32-bit one. diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 02ea0e2d6..4b4e26507 100755 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -77,8 +77,6 @@ add_library(video_core STATIC macro/macro_hle.h macro/macro_interpreter.cpp macro/macro_interpreter.h - macro/macro_jit_x64.cpp - macro/macro_jit_x64.h fence_manager.h gpu.cpp gpu.h @@ -249,7 +247,7 @@ add_library(video_core STATIC create_target_directory_groups(video_core) target_link_libraries(video_core PUBLIC common core) -target_link_libraries(video_core PUBLIC glad shader_recompiler xbyak) +target_link_libraries(video_core PUBLIC glad shader_recompiler) if (YUZU_USE_BUNDLED_FFMPEG AND NOT WIN32) add_dependencies(video_core ffmpeg-build) @@ -286,8 +284,19 @@ else() -Wno-sign-conversion ) + + # xbyak + set_source_files_properties(macro/macro_jit_x64.cpp PROPERTIES COMPILE_OPTIONS "-Wno-conversion;-Wno-shadow") endif() if (ARCHITECTURE_x86_64) + target_sources(video_core PRIVATE + macro/macro_jit_x64.cpp + macro/macro_jit_x64.h + ) + target_link_libraries(video_core PUBLIC xbyak) +endif() + +if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) target_link_libraries(video_core PRIVATE dynarmic) endif() diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp index 93499658e..257e08e84 100755 --- a/src/video_core/macro/macro.cpp +++ b/src/video_core/macro/macro.cpp @@ -16,7 +16,10 @@ #include "video_core/macro/macro.h" #include "video_core/macro/macro_hle.h" #include "video_core/macro/macro_interpreter.h" + +#ifdef ARCHITECTURE_x86_64 #include "video_core/macro/macro_jit_x64.h" +#endif namespace Tegra { diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 0cd9921bd..c3b085d39 100755 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -385,6 +385,6 @@ if (NOT APPLE) target_compile_definitions(yuzu PRIVATE HAS_OPENGL) endif() -if (ARCHITECTURE_x86_64) +if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) target_link_libraries(yuzu PRIVATE dynarmic) endif()