diff options
| author | 2020-06-28 12:37:50 -0400 | |
|---|---|---|
| committer | 2020-06-28 12:37:50 -0400 | |
| commit | b05795d704e0c194215f815a5703db09e524b59a (patch) | |
| tree | ecf4023b4ee0c91555c1d8263762fcb9dcb04a17 /src/core/arm | |
| parent | Merge pull request #4196 from ogniK5377/nrr-nro-fixes (diff) | |
| parent | Core/Common: Address Feedback. (diff) | |
| download | yuzu-b05795d704e0c194215f815a5703db09e524b59a.tar.gz yuzu-b05795d704e0c194215f815a5703db09e524b59a.tar.xz yuzu-b05795d704e0c194215f815a5703db09e524b59a.zip | |
Merge pull request #3955 from FernandoS27/prometheus-2b
Remake Kernel Scheduling, CPU Management & Boot Management (Prometheus)
Diffstat (limited to 'src/core/arm')
| -rw-r--r-- | src/core/arm/arm_interface.cpp | 57 | ||||
| -rw-r--r-- | src/core/arm/arm_interface.h | 20 | ||||
| -rw-r--r-- | src/core/arm/cpu_interrupt_handler.cpp | 29 | ||||
| -rw-r--r-- | src/core/arm/cpu_interrupt_handler.h | 39 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_32.cpp | 82 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_32.h | 7 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_64.cpp | 106 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_64.h | 26 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_cp15.cpp | 2 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_exclusive_monitor.cpp | 76 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_exclusive_monitor.h | 48 | ||||
| -rw-r--r-- | src/core/arm/exclusive_monitor.cpp | 2 | ||||
| -rw-r--r-- | src/core/arm/exclusive_monitor.h | 6 | ||||
| -rw-r--r-- | src/core/arm/unicorn/arm_unicorn.cpp | 19 | ||||
| -rw-r--r-- | src/core/arm/unicorn/arm_unicorn.h | 5 |
15 files changed, 423 insertions, 101 deletions
diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp index d079a1bc8..d2295ed90 100644 --- a/src/core/arm/arm_interface.cpp +++ b/src/core/arm/arm_interface.cpp | |||
| @@ -139,6 +139,63 @@ std::optional<std::string> GetSymbolName(const Symbols& symbols, VAddr func_addr | |||
| 139 | 139 | ||
| 140 | constexpr u64 SEGMENT_BASE = 0x7100000000ull; | 140 | constexpr u64 SEGMENT_BASE = 0x7100000000ull; |
| 141 | 141 | ||
| 142 | std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktraceFromContext( | ||
| 143 | System& system, const ThreadContext64& ctx) { | ||
| 144 | std::vector<BacktraceEntry> out; | ||
| 145 | auto& memory = system.Memory(); | ||
| 146 | |||
| 147 | auto fp = ctx.cpu_registers[29]; | ||
| 148 | auto lr = ctx.cpu_registers[30]; | ||
| 149 | while (true) { | ||
| 150 | out.push_back({"", 0, lr, 0}); | ||
| 151 | if (!fp) { | ||
| 152 | break; | ||
| 153 | } | ||
| 154 | lr = memory.Read64(fp + 8) - 4; | ||
| 155 | fp = memory.Read64(fp); | ||
| 156 | } | ||
| 157 | |||
| 158 | std::map<VAddr, std::string> modules; | ||
| 159 | auto& loader{system.GetAppLoader()}; | ||
| 160 | if (loader.ReadNSOModules(modules) != Loader::ResultStatus::Success) { | ||
| 161 | return {}; | ||
| 162 | } | ||
| 163 | |||
| 164 | std::map<std::string, Symbols> symbols; | ||
| 165 | for (const auto& module : modules) { | ||
| 166 | symbols.insert_or_assign(module.second, GetSymbols(module.first, memory)); | ||
| 167 | } | ||
| 168 | |||
| 169 | for (auto& entry : out) { | ||
| 170 | VAddr base = 0; | ||
| 171 | for (auto iter = modules.rbegin(); iter != modules.rend(); ++iter) { | ||
| 172 | const auto& module{*iter}; | ||
| 173 | if (entry.original_address >= module.first) { | ||
| 174 | entry.module = module.second; | ||
| 175 | base = module.first; | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | entry.offset = entry.original_address - base; | ||
| 181 | entry.address = SEGMENT_BASE + entry.offset; | ||
| 182 | |||
| 183 | if (entry.module.empty()) | ||
| 184 | entry.module = "unknown"; | ||
| 185 | |||
| 186 | const auto symbol_set = symbols.find(entry.module); | ||
| 187 | if (symbol_set != symbols.end()) { | ||
| 188 | const auto symbol = GetSymbolName(symbol_set->second, entry.offset); | ||
| 189 | if (symbol.has_value()) { | ||
| 190 | // TODO(DarkLordZach): Add demangling of symbol names. | ||
| 191 | entry.name = *symbol; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | return out; | ||
| 197 | } | ||
| 198 | |||
| 142 | std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktrace() const { | 199 | std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktrace() const { |
| 143 | std::vector<BacktraceEntry> out; | 200 | std::vector<BacktraceEntry> out; |
| 144 | auto& memory = system.Memory(); | 201 | auto& memory = system.Memory(); |
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index cb2e640e2..1f24051e4 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <vector> | 8 | #include <vector> |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "core/hardware_properties.h" | ||
| 10 | 11 | ||
| 11 | namespace Common { | 12 | namespace Common { |
| 12 | struct PageTable; | 13 | struct PageTable; |
| @@ -18,25 +19,29 @@ enum class VMAPermission : u8; | |||
| 18 | 19 | ||
| 19 | namespace Core { | 20 | namespace Core { |
| 20 | class System; | 21 | class System; |
| 22 | class CPUInterruptHandler; | ||
| 23 | |||
| 24 | using CPUInterrupts = std::array<CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>; | ||
| 21 | 25 | ||
| 22 | /// Generic ARMv8 CPU interface | 26 | /// Generic ARMv8 CPU interface |
| 23 | class ARM_Interface : NonCopyable { | 27 | class ARM_Interface : NonCopyable { |
| 24 | public: | 28 | public: |
| 25 | explicit ARM_Interface(System& system_) : system{system_} {} | 29 | explicit ARM_Interface(System& system_, CPUInterrupts& interrupt_handlers, bool uses_wall_clock) |
| 30 | : system{system_}, interrupt_handlers{interrupt_handlers}, uses_wall_clock{ | ||
| 31 | uses_wall_clock} {} | ||
| 26 | virtual ~ARM_Interface() = default; | 32 | virtual ~ARM_Interface() = default; |
| 27 | 33 | ||
| 28 | struct ThreadContext32 { | 34 | struct ThreadContext32 { |
| 29 | std::array<u32, 16> cpu_registers{}; | 35 | std::array<u32, 16> cpu_registers{}; |
| 36 | std::array<u32, 64> extension_registers{}; | ||
| 30 | u32 cpsr{}; | 37 | u32 cpsr{}; |
| 31 | std::array<u8, 4> padding{}; | ||
| 32 | std::array<u64, 32> fprs{}; | ||
| 33 | u32 fpscr{}; | 38 | u32 fpscr{}; |
| 34 | u32 fpexc{}; | 39 | u32 fpexc{}; |
| 35 | u32 tpidr{}; | 40 | u32 tpidr{}; |
| 36 | }; | 41 | }; |
| 37 | // Internally within the kernel, it expects the AArch32 version of the | 42 | // Internally within the kernel, it expects the AArch32 version of the |
| 38 | // thread context to be 344 bytes in size. | 43 | // thread context to be 344 bytes in size. |
| 39 | static_assert(sizeof(ThreadContext32) == 0x158); | 44 | static_assert(sizeof(ThreadContext32) == 0x150); |
| 40 | 45 | ||
| 41 | struct ThreadContext64 { | 46 | struct ThreadContext64 { |
| 42 | std::array<u64, 31> cpu_registers{}; | 47 | std::array<u64, 31> cpu_registers{}; |
| @@ -143,6 +148,8 @@ public: | |||
| 143 | */ | 148 | */ |
| 144 | virtual void SetTPIDR_EL0(u64 value) = 0; | 149 | virtual void SetTPIDR_EL0(u64 value) = 0; |
| 145 | 150 | ||
| 151 | virtual void ChangeProcessorID(std::size_t new_core_id) = 0; | ||
| 152 | |||
| 146 | virtual void SaveContext(ThreadContext32& ctx) = 0; | 153 | virtual void SaveContext(ThreadContext32& ctx) = 0; |
| 147 | virtual void SaveContext(ThreadContext64& ctx) = 0; | 154 | virtual void SaveContext(ThreadContext64& ctx) = 0; |
| 148 | virtual void LoadContext(const ThreadContext32& ctx) = 0; | 155 | virtual void LoadContext(const ThreadContext32& ctx) = 0; |
| @@ -162,6 +169,9 @@ public: | |||
| 162 | std::string name; | 169 | std::string name; |
| 163 | }; | 170 | }; |
| 164 | 171 | ||
| 172 | static std::vector<BacktraceEntry> GetBacktraceFromContext(System& system, | ||
| 173 | const ThreadContext64& ctx); | ||
| 174 | |||
| 165 | std::vector<BacktraceEntry> GetBacktrace() const; | 175 | std::vector<BacktraceEntry> GetBacktrace() const; |
| 166 | 176 | ||
| 167 | /// fp (= r29) points to the last frame record. | 177 | /// fp (= r29) points to the last frame record. |
| @@ -175,6 +185,8 @@ public: | |||
| 175 | protected: | 185 | protected: |
| 176 | /// System context that this ARM interface is running under. | 186 | /// System context that this ARM interface is running under. |
| 177 | System& system; | 187 | System& system; |
| 188 | CPUInterrupts& interrupt_handlers; | ||
| 189 | bool uses_wall_clock; | ||
| 178 | }; | 190 | }; |
| 179 | 191 | ||
| 180 | } // namespace Core | 192 | } // namespace Core |
diff --git a/src/core/arm/cpu_interrupt_handler.cpp b/src/core/arm/cpu_interrupt_handler.cpp new file mode 100644 index 000000000..2f1a1a269 --- /dev/null +++ b/src/core/arm/cpu_interrupt_handler.cpp | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | // Copyright 2020 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/thread.h" | ||
| 8 | #include "core/arm/cpu_interrupt_handler.h" | ||
| 9 | |||
| 10 | namespace Core { | ||
| 11 | |||
| 12 | CPUInterruptHandler::CPUInterruptHandler() : is_interrupted{} { | ||
| 13 | interrupt_event = std::make_unique<Common::Event>(); | ||
| 14 | } | ||
| 15 | |||
| 16 | CPUInterruptHandler::~CPUInterruptHandler() = default; | ||
| 17 | |||
| 18 | void CPUInterruptHandler::SetInterrupt(bool is_interrupted_) { | ||
| 19 | if (is_interrupted_) { | ||
| 20 | interrupt_event->Set(); | ||
| 21 | } | ||
| 22 | this->is_interrupted = is_interrupted_; | ||
| 23 | } | ||
| 24 | |||
| 25 | void CPUInterruptHandler::AwaitInterrupt() { | ||
| 26 | interrupt_event->Wait(); | ||
| 27 | } | ||
| 28 | |||
| 29 | } // namespace Core | ||
diff --git a/src/core/arm/cpu_interrupt_handler.h b/src/core/arm/cpu_interrupt_handler.h new file mode 100644 index 000000000..3d062d326 --- /dev/null +++ b/src/core/arm/cpu_interrupt_handler.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | // Copyright 2020 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | class Event; | ||
| 11 | } | ||
| 12 | |||
| 13 | namespace Core { | ||
| 14 | |||
| 15 | class CPUInterruptHandler { | ||
| 16 | public: | ||
| 17 | CPUInterruptHandler(); | ||
| 18 | ~CPUInterruptHandler(); | ||
| 19 | |||
| 20 | CPUInterruptHandler(const CPUInterruptHandler&) = delete; | ||
| 21 | CPUInterruptHandler& operator=(const CPUInterruptHandler&) = delete; | ||
| 22 | |||
| 23 | CPUInterruptHandler(CPUInterruptHandler&&) = default; | ||
| 24 | CPUInterruptHandler& operator=(CPUInterruptHandler&&) = default; | ||
| 25 | |||
| 26 | bool IsInterrupted() const { | ||
| 27 | return is_interrupted; | ||
| 28 | } | ||
| 29 | |||
| 30 | void SetInterrupt(bool is_interrupted); | ||
| 31 | |||
| 32 | void AwaitInterrupt(); | ||
| 33 | |||
| 34 | private: | ||
| 35 | bool is_interrupted{}; | ||
| 36 | std::unique_ptr<Common::Event> interrupt_event; | ||
| 37 | }; | ||
| 38 | |||
| 39 | } // namespace Core | ||
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index 4c8663d03..0d4ab95b7 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp | |||
| @@ -7,15 +7,17 @@ | |||
| 7 | #include <dynarmic/A32/a32.h> | 7 | #include <dynarmic/A32/a32.h> |
| 8 | #include <dynarmic/A32/config.h> | 8 | #include <dynarmic/A32/config.h> |
| 9 | #include <dynarmic/A32/context.h> | 9 | #include <dynarmic/A32/context.h> |
| 10 | #include "common/microprofile.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/page_table.h" | ||
| 12 | #include "core/arm/cpu_interrupt_handler.h" | ||
| 11 | #include "core/arm/dynarmic/arm_dynarmic_32.h" | 13 | #include "core/arm/dynarmic/arm_dynarmic_32.h" |
| 12 | #include "core/arm/dynarmic/arm_dynarmic_64.h" | ||
| 13 | #include "core/arm/dynarmic/arm_dynarmic_cp15.h" | 14 | #include "core/arm/dynarmic/arm_dynarmic_cp15.h" |
| 15 | #include "core/arm/dynarmic/arm_exclusive_monitor.h" | ||
| 14 | #include "core/core.h" | 16 | #include "core/core.h" |
| 15 | #include "core/core_manager.h" | ||
| 16 | #include "core/core_timing.h" | 17 | #include "core/core_timing.h" |
| 17 | #include "core/hle/kernel/svc.h" | 18 | #include "core/hle/kernel/svc.h" |
| 18 | #include "core/memory.h" | 19 | #include "core/memory.h" |
| 20 | #include "core/settings.h" | ||
| 19 | 21 | ||
| 20 | namespace Core { | 22 | namespace Core { |
| 21 | 23 | ||
| @@ -49,6 +51,19 @@ public: | |||
| 49 | parent.system.Memory().Write64(vaddr, value); | 51 | parent.system.Memory().Write64(vaddr, value); |
| 50 | } | 52 | } |
| 51 | 53 | ||
| 54 | bool MemoryWriteExclusive8(u32 vaddr, u8 value, u8 expected) override { | ||
| 55 | return parent.system.Memory().WriteExclusive8(vaddr, value, expected); | ||
| 56 | } | ||
| 57 | bool MemoryWriteExclusive16(u32 vaddr, u16 value, u16 expected) override { | ||
| 58 | return parent.system.Memory().WriteExclusive16(vaddr, value, expected); | ||
| 59 | } | ||
| 60 | bool MemoryWriteExclusive32(u32 vaddr, u32 value, u32 expected) override { | ||
| 61 | return parent.system.Memory().WriteExclusive32(vaddr, value, expected); | ||
| 62 | } | ||
| 63 | bool MemoryWriteExclusive64(u32 vaddr, u64 value, u64 expected) override { | ||
| 64 | return parent.system.Memory().WriteExclusive64(vaddr, value, expected); | ||
| 65 | } | ||
| 66 | |||
| 52 | void InterpreterFallback(u32 pc, std::size_t num_instructions) override { | 67 | void InterpreterFallback(u32 pc, std::size_t num_instructions) override { |
| 53 | UNIMPLEMENTED_MSG("This should never happen, pc = {:08X}, code = {:08X}", pc, | 68 | UNIMPLEMENTED_MSG("This should never happen, pc = {:08X}, code = {:08X}", pc, |
| 54 | MemoryReadCode(pc)); | 69 | MemoryReadCode(pc)); |
| @@ -72,24 +87,36 @@ public: | |||
| 72 | } | 87 | } |
| 73 | 88 | ||
| 74 | void AddTicks(u64 ticks) override { | 89 | void AddTicks(u64 ticks) override { |
| 90 | if (parent.uses_wall_clock) { | ||
| 91 | return; | ||
| 92 | } | ||
| 75 | // Divide the number of ticks by the amount of CPU cores. TODO(Subv): This yields only a | 93 | // Divide the number of ticks by the amount of CPU cores. TODO(Subv): This yields only a |
| 76 | // rough approximation of the amount of executed ticks in the system, it may be thrown off | 94 | // rough approximation of the amount of executed ticks in the system, it may be thrown off |
| 77 | // if not all cores are doing a similar amount of work. Instead of doing this, we should | 95 | // if not all cores are doing a similar amount of work. Instead of doing this, we should |
| 78 | // device a way so that timing is consistent across all cores without increasing the ticks 4 | 96 | // device a way so that timing is consistent across all cores without increasing the ticks 4 |
| 79 | // times. | 97 | // times. |
| 80 | u64 amortized_ticks = (ticks - num_interpreted_instructions) / Core::NUM_CPU_CORES; | 98 | u64 amortized_ticks = |
| 99 | (ticks - num_interpreted_instructions) / Core::Hardware::NUM_CPU_CORES; | ||
| 81 | // Always execute at least one tick. | 100 | // Always execute at least one tick. |
| 82 | amortized_ticks = std::max<u64>(amortized_ticks, 1); | 101 | amortized_ticks = std::max<u64>(amortized_ticks, 1); |
| 83 | 102 | ||
| 84 | parent.system.CoreTiming().AddTicks(amortized_ticks); | 103 | parent.system.CoreTiming().AddTicks(amortized_ticks); |
| 85 | num_interpreted_instructions = 0; | 104 | num_interpreted_instructions = 0; |
| 86 | } | 105 | } |
| 106 | |||
| 87 | u64 GetTicksRemaining() override { | 107 | u64 GetTicksRemaining() override { |
| 88 | return std::max(parent.system.CoreTiming().GetDowncount(), {}); | 108 | if (parent.uses_wall_clock) { |
| 109 | if (!parent.interrupt_handlers[parent.core_index].IsInterrupted()) { | ||
| 110 | return minimum_run_cycles; | ||
| 111 | } | ||
| 112 | return 0U; | ||
| 113 | } | ||
| 114 | return std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0); | ||
| 89 | } | 115 | } |
| 90 | 116 | ||
| 91 | ARM_Dynarmic_32& parent; | 117 | ARM_Dynarmic_32& parent; |
| 92 | std::size_t num_interpreted_instructions{}; | 118 | std::size_t num_interpreted_instructions{}; |
| 119 | static constexpr u64 minimum_run_cycles = 1000U; | ||
| 93 | }; | 120 | }; |
| 94 | 121 | ||
| 95 | std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable& page_table, | 122 | std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable& page_table, |
| @@ -100,13 +127,31 @@ std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable& | |||
| 100 | // config.page_table = &page_table.pointers; | 127 | // config.page_table = &page_table.pointers; |
| 101 | config.coprocessors[15] = cp15; | 128 | config.coprocessors[15] = cp15; |
| 102 | config.define_unpredictable_behaviour = true; | 129 | config.define_unpredictable_behaviour = true; |
| 130 | static constexpr std::size_t PAGE_BITS = 12; | ||
| 131 | static constexpr std::size_t NUM_PAGE_TABLE_ENTRIES = 1 << (32 - PAGE_BITS); | ||
| 132 | config.page_table = reinterpret_cast<std::array<std::uint8_t*, NUM_PAGE_TABLE_ENTRIES>*>( | ||
| 133 | page_table.pointers.data()); | ||
| 134 | config.absolute_offset_page_table = true; | ||
| 135 | config.detect_misaligned_access_via_page_table = 16 | 32 | 64 | 128; | ||
| 136 | config.only_detect_misalignment_via_page_table_on_page_boundary = true; | ||
| 137 | |||
| 138 | // Multi-process state | ||
| 139 | config.processor_id = core_index; | ||
| 140 | config.global_monitor = &exclusive_monitor.monitor; | ||
| 141 | |||
| 142 | // Timing | ||
| 143 | config.wall_clock_cntpct = uses_wall_clock; | ||
| 144 | |||
| 145 | // Optimizations | ||
| 146 | if (Settings::values.disable_cpu_opt) { | ||
| 147 | config.enable_optimizations = false; | ||
| 148 | config.enable_fast_dispatch = false; | ||
| 149 | } | ||
| 150 | |||
| 103 | return std::make_unique<Dynarmic::A32::Jit>(config); | 151 | return std::make_unique<Dynarmic::A32::Jit>(config); |
| 104 | } | 152 | } |
| 105 | 153 | ||
| 106 | MICROPROFILE_DEFINE(ARM_Jit_Dynarmic_32, "ARM JIT", "Dynarmic", MP_RGB(255, 64, 64)); | ||
| 107 | |||
| 108 | void ARM_Dynarmic_32::Run() { | 154 | void ARM_Dynarmic_32::Run() { |
| 109 | MICROPROFILE_SCOPE(ARM_Jit_Dynarmic_32); | ||
| 110 | jit->Run(); | 155 | jit->Run(); |
| 111 | } | 156 | } |
| 112 | 157 | ||
| @@ -114,9 +159,11 @@ void ARM_Dynarmic_32::Step() { | |||
| 114 | jit->Step(); | 159 | jit->Step(); |
| 115 | } | 160 | } |
| 116 | 161 | ||
| 117 | ARM_Dynarmic_32::ARM_Dynarmic_32(System& system, ExclusiveMonitor& exclusive_monitor, | 162 | ARM_Dynarmic_32::ARM_Dynarmic_32(System& system, CPUInterrupts& interrupt_handlers, |
| 163 | bool uses_wall_clock, ExclusiveMonitor& exclusive_monitor, | ||
| 118 | std::size_t core_index) | 164 | std::size_t core_index) |
| 119 | : ARM_Interface{system}, cb(std::make_unique<DynarmicCallbacks32>(*this)), | 165 | : ARM_Interface{system, interrupt_handlers, uses_wall_clock}, |
| 166 | cb(std::make_unique<DynarmicCallbacks32>(*this)), | ||
| 120 | cp15(std::make_shared<DynarmicCP15>(*this)), core_index{core_index}, | 167 | cp15(std::make_shared<DynarmicCP15>(*this)), core_index{core_index}, |
| 121 | exclusive_monitor{dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {} | 168 | exclusive_monitor{dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {} |
| 122 | 169 | ||
| @@ -168,17 +215,25 @@ void ARM_Dynarmic_32::SetTPIDR_EL0(u64 value) { | |||
| 168 | cp15->uprw = static_cast<u32>(value); | 215 | cp15->uprw = static_cast<u32>(value); |
| 169 | } | 216 | } |
| 170 | 217 | ||
| 218 | void ARM_Dynarmic_32::ChangeProcessorID(std::size_t new_core_id) { | ||
| 219 | jit->ChangeProcessorID(new_core_id); | ||
| 220 | } | ||
| 221 | |||
| 171 | void ARM_Dynarmic_32::SaveContext(ThreadContext32& ctx) { | 222 | void ARM_Dynarmic_32::SaveContext(ThreadContext32& ctx) { |
| 172 | Dynarmic::A32::Context context; | 223 | Dynarmic::A32::Context context; |
| 173 | jit->SaveContext(context); | 224 | jit->SaveContext(context); |
| 174 | ctx.cpu_registers = context.Regs(); | 225 | ctx.cpu_registers = context.Regs(); |
| 226 | ctx.extension_registers = context.ExtRegs(); | ||
| 175 | ctx.cpsr = context.Cpsr(); | 227 | ctx.cpsr = context.Cpsr(); |
| 228 | ctx.fpscr = context.Fpscr(); | ||
| 176 | } | 229 | } |
| 177 | 230 | ||
| 178 | void ARM_Dynarmic_32::LoadContext(const ThreadContext32& ctx) { | 231 | void ARM_Dynarmic_32::LoadContext(const ThreadContext32& ctx) { |
| 179 | Dynarmic::A32::Context context; | 232 | Dynarmic::A32::Context context; |
| 180 | context.Regs() = ctx.cpu_registers; | 233 | context.Regs() = ctx.cpu_registers; |
| 234 | context.ExtRegs() = ctx.extension_registers; | ||
| 181 | context.SetCpsr(ctx.cpsr); | 235 | context.SetCpsr(ctx.cpsr); |
| 236 | context.SetFpscr(ctx.fpscr); | ||
| 182 | jit->LoadContext(context); | 237 | jit->LoadContext(context); |
| 183 | } | 238 | } |
| 184 | 239 | ||
| @@ -187,10 +242,15 @@ void ARM_Dynarmic_32::PrepareReschedule() { | |||
| 187 | } | 242 | } |
| 188 | 243 | ||
| 189 | void ARM_Dynarmic_32::ClearInstructionCache() { | 244 | void ARM_Dynarmic_32::ClearInstructionCache() { |
| 245 | if (!jit) { | ||
| 246 | return; | ||
| 247 | } | ||
| 190 | jit->ClearCache(); | 248 | jit->ClearCache(); |
| 191 | } | 249 | } |
| 192 | 250 | ||
| 193 | void ARM_Dynarmic_32::ClearExclusiveState() {} | 251 | void ARM_Dynarmic_32::ClearExclusiveState() { |
| 252 | jit->ClearExclusiveState(); | ||
| 253 | } | ||
| 194 | 254 | ||
| 195 | void ARM_Dynarmic_32::PageTableChanged(Common::PageTable& page_table, | 255 | void ARM_Dynarmic_32::PageTableChanged(Common::PageTable& page_table, |
| 196 | std::size_t new_address_space_size_in_bits) { | 256 | std::size_t new_address_space_size_in_bits) { |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.h b/src/core/arm/dynarmic/arm_dynarmic_32.h index e5b92d7bb..2bab31b92 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.h +++ b/src/core/arm/dynarmic/arm_dynarmic_32.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include <dynarmic/A32/a32.h> | 10 | #include <dynarmic/A32/a32.h> |
| 11 | #include <dynarmic/A64/a64.h> | 11 | #include <dynarmic/A64/a64.h> |
| 12 | #include <dynarmic/A64/exclusive_monitor.h> | 12 | #include <dynarmic/exclusive_monitor.h> |
| 13 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 14 | #include "common/hash.h" | 14 | #include "common/hash.h" |
| 15 | #include "core/arm/arm_interface.h" | 15 | #include "core/arm/arm_interface.h" |
| @@ -21,6 +21,7 @@ class Memory; | |||
| 21 | 21 | ||
| 22 | namespace Core { | 22 | namespace Core { |
| 23 | 23 | ||
| 24 | class CPUInterruptHandler; | ||
| 24 | class DynarmicCallbacks32; | 25 | class DynarmicCallbacks32; |
| 25 | class DynarmicCP15; | 26 | class DynarmicCP15; |
| 26 | class DynarmicExclusiveMonitor; | 27 | class DynarmicExclusiveMonitor; |
| @@ -28,7 +29,8 @@ class System; | |||
| 28 | 29 | ||
| 29 | class ARM_Dynarmic_32 final : public ARM_Interface { | 30 | class ARM_Dynarmic_32 final : public ARM_Interface { |
| 30 | public: | 31 | public: |
| 31 | ARM_Dynarmic_32(System& system, ExclusiveMonitor& exclusive_monitor, std::size_t core_index); | 32 | ARM_Dynarmic_32(System& system, CPUInterrupts& interrupt_handlers, bool uses_wall_clock, |
| 33 | ExclusiveMonitor& exclusive_monitor, std::size_t core_index); | ||
| 32 | ~ARM_Dynarmic_32() override; | 34 | ~ARM_Dynarmic_32() override; |
| 33 | 35 | ||
| 34 | void SetPC(u64 pc) override; | 36 | void SetPC(u64 pc) override; |
| @@ -45,6 +47,7 @@ public: | |||
| 45 | void SetTlsAddress(VAddr address) override; | 47 | void SetTlsAddress(VAddr address) override; |
| 46 | void SetTPIDR_EL0(u64 value) override; | 48 | void SetTPIDR_EL0(u64 value) override; |
| 47 | u64 GetTPIDR_EL0() const override; | 49 | u64 GetTPIDR_EL0() const override; |
| 50 | void ChangeProcessorID(std::size_t new_core_id) override; | ||
| 48 | 51 | ||
| 49 | void SaveContext(ThreadContext32& ctx) override; | 52 | void SaveContext(ThreadContext32& ctx) override; |
| 50 | void SaveContext(ThreadContext64& ctx) override {} | 53 | void SaveContext(ThreadContext64& ctx) override {} |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index 5f5e36d94..790981034 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp | |||
| @@ -7,11 +7,11 @@ | |||
| 7 | #include <dynarmic/A64/a64.h> | 7 | #include <dynarmic/A64/a64.h> |
| 8 | #include <dynarmic/A64/config.h> | 8 | #include <dynarmic/A64/config.h> |
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "common/microprofile.h" | ||
| 11 | #include "common/page_table.h" | 10 | #include "common/page_table.h" |
| 11 | #include "core/arm/cpu_interrupt_handler.h" | ||
| 12 | #include "core/arm/dynarmic/arm_dynarmic_64.h" | 12 | #include "core/arm/dynarmic/arm_dynarmic_64.h" |
| 13 | #include "core/arm/dynarmic/arm_exclusive_monitor.h" | ||
| 13 | #include "core/core.h" | 14 | #include "core/core.h" |
| 14 | #include "core/core_manager.h" | ||
| 15 | #include "core/core_timing.h" | 15 | #include "core/core_timing.h" |
| 16 | #include "core/core_timing_util.h" | 16 | #include "core/core_timing_util.h" |
| 17 | #include "core/gdbstub/gdbstub.h" | 17 | #include "core/gdbstub/gdbstub.h" |
| @@ -65,6 +65,22 @@ public: | |||
| 65 | memory.Write64(vaddr + 8, value[1]); | 65 | memory.Write64(vaddr + 8, value[1]); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | bool MemoryWriteExclusive8(u64 vaddr, std::uint8_t value, std::uint8_t expected) override { | ||
| 69 | return parent.system.Memory().WriteExclusive8(vaddr, value, expected); | ||
| 70 | } | ||
| 71 | bool MemoryWriteExclusive16(u64 vaddr, std::uint16_t value, std::uint16_t expected) override { | ||
| 72 | return parent.system.Memory().WriteExclusive16(vaddr, value, expected); | ||
| 73 | } | ||
| 74 | bool MemoryWriteExclusive32(u64 vaddr, std::uint32_t value, std::uint32_t expected) override { | ||
| 75 | return parent.system.Memory().WriteExclusive32(vaddr, value, expected); | ||
| 76 | } | ||
| 77 | bool MemoryWriteExclusive64(u64 vaddr, std::uint64_t value, std::uint64_t expected) override { | ||
| 78 | return parent.system.Memory().WriteExclusive64(vaddr, value, expected); | ||
| 79 | } | ||
| 80 | bool MemoryWriteExclusive128(u64 vaddr, Vector value, Vector expected) override { | ||
| 81 | return parent.system.Memory().WriteExclusive128(vaddr, value, expected); | ||
| 82 | } | ||
| 83 | |||
| 68 | void InterpreterFallback(u64 pc, std::size_t num_instructions) override { | 84 | void InterpreterFallback(u64 pc, std::size_t num_instructions) override { |
| 69 | LOG_INFO(Core_ARM, "Unicorn fallback @ 0x{:X} for {} instructions (instr = {:08X})", pc, | 85 | LOG_INFO(Core_ARM, "Unicorn fallback @ 0x{:X} for {} instructions (instr = {:08X})", pc, |
| 70 | num_instructions, MemoryReadCode(pc)); | 86 | num_instructions, MemoryReadCode(pc)); |
| @@ -108,29 +124,42 @@ public: | |||
| 108 | } | 124 | } |
| 109 | 125 | ||
| 110 | void AddTicks(u64 ticks) override { | 126 | void AddTicks(u64 ticks) override { |
| 127 | if (parent.uses_wall_clock) { | ||
| 128 | return; | ||
| 129 | } | ||
| 111 | // Divide the number of ticks by the amount of CPU cores. TODO(Subv): This yields only a | 130 | // Divide the number of ticks by the amount of CPU cores. TODO(Subv): This yields only a |
| 112 | // rough approximation of the amount of executed ticks in the system, it may be thrown off | 131 | // rough approximation of the amount of executed ticks in the system, it may be thrown off |
| 113 | // if not all cores are doing a similar amount of work. Instead of doing this, we should | 132 | // if not all cores are doing a similar amount of work. Instead of doing this, we should |
| 114 | // device a way so that timing is consistent across all cores without increasing the ticks 4 | 133 | // device a way so that timing is consistent across all cores without increasing the ticks 4 |
| 115 | // times. | 134 | // times. |
| 116 | u64 amortized_ticks = (ticks - num_interpreted_instructions) / Core::NUM_CPU_CORES; | 135 | u64 amortized_ticks = |
| 136 | (ticks - num_interpreted_instructions) / Core::Hardware::NUM_CPU_CORES; | ||
| 117 | // Always execute at least one tick. | 137 | // Always execute at least one tick. |
| 118 | amortized_ticks = std::max<u64>(amortized_ticks, 1); | 138 | amortized_ticks = std::max<u64>(amortized_ticks, 1); |
| 119 | 139 | ||
| 120 | parent.system.CoreTiming().AddTicks(amortized_ticks); | 140 | parent.system.CoreTiming().AddTicks(amortized_ticks); |
| 121 | num_interpreted_instructions = 0; | 141 | num_interpreted_instructions = 0; |
| 122 | } | 142 | } |
| 143 | |||
| 123 | u64 GetTicksRemaining() override { | 144 | u64 GetTicksRemaining() override { |
| 124 | return std::max(parent.system.CoreTiming().GetDowncount(), s64{0}); | 145 | if (parent.uses_wall_clock) { |
| 146 | if (!parent.interrupt_handlers[parent.core_index].IsInterrupted()) { | ||
| 147 | return minimum_run_cycles; | ||
| 148 | } | ||
| 149 | return 0U; | ||
| 150 | } | ||
| 151 | return std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0); | ||
| 125 | } | 152 | } |
| 153 | |||
| 126 | u64 GetCNTPCT() override { | 154 | u64 GetCNTPCT() override { |
| 127 | return Timing::CpuCyclesToClockCycles(parent.system.CoreTiming().GetTicks()); | 155 | return parent.system.CoreTiming().GetClockTicks(); |
| 128 | } | 156 | } |
| 129 | 157 | ||
| 130 | ARM_Dynarmic_64& parent; | 158 | ARM_Dynarmic_64& parent; |
| 131 | std::size_t num_interpreted_instructions = 0; | 159 | std::size_t num_interpreted_instructions = 0; |
| 132 | u64 tpidrro_el0 = 0; | 160 | u64 tpidrro_el0 = 0; |
| 133 | u64 tpidr_el0 = 0; | 161 | u64 tpidr_el0 = 0; |
| 162 | static constexpr u64 minimum_run_cycles = 1000U; | ||
| 134 | }; | 163 | }; |
| 135 | 164 | ||
| 136 | std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable& page_table, | 165 | std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable& page_table, |
| @@ -168,14 +197,13 @@ std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable& | |||
| 168 | config.enable_fast_dispatch = false; | 197 | config.enable_fast_dispatch = false; |
| 169 | } | 198 | } |
| 170 | 199 | ||
| 200 | // Timing | ||
| 201 | config.wall_clock_cntpct = uses_wall_clock; | ||
| 202 | |||
| 171 | return std::make_shared<Dynarmic::A64::Jit>(config); | 203 | return std::make_shared<Dynarmic::A64::Jit>(config); |
| 172 | } | 204 | } |
| 173 | 205 | ||
| 174 | MICROPROFILE_DEFINE(ARM_Jit_Dynarmic_64, "ARM JIT", "Dynarmic", MP_RGB(255, 64, 64)); | ||
| 175 | |||
| 176 | void ARM_Dynarmic_64::Run() { | 206 | void ARM_Dynarmic_64::Run() { |
| 177 | MICROPROFILE_SCOPE(ARM_Jit_Dynarmic_64); | ||
| 178 | |||
| 179 | jit->Run(); | 207 | jit->Run(); |
| 180 | } | 208 | } |
| 181 | 209 | ||
| @@ -183,11 +211,16 @@ void ARM_Dynarmic_64::Step() { | |||
| 183 | cb->InterpreterFallback(jit->GetPC(), 1); | 211 | cb->InterpreterFallback(jit->GetPC(), 1); |
| 184 | } | 212 | } |
| 185 | 213 | ||
| 186 | ARM_Dynarmic_64::ARM_Dynarmic_64(System& system, ExclusiveMonitor& exclusive_monitor, | 214 | ARM_Dynarmic_64::ARM_Dynarmic_64(System& system, CPUInterrupts& interrupt_handlers, |
| 215 | bool uses_wall_clock, ExclusiveMonitor& exclusive_monitor, | ||
| 187 | std::size_t core_index) | 216 | std::size_t core_index) |
| 188 | : ARM_Interface{system}, cb(std::make_unique<DynarmicCallbacks64>(*this)), | 217 | : ARM_Interface{system, interrupt_handlers, uses_wall_clock}, |
| 189 | inner_unicorn{system, ARM_Unicorn::Arch::AArch64}, core_index{core_index}, | 218 | cb(std::make_unique<DynarmicCallbacks64>(*this)), inner_unicorn{system, interrupt_handlers, |
| 190 | exclusive_monitor{dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {} | 219 | uses_wall_clock, |
| 220 | ARM_Unicorn::Arch::AArch64, | ||
| 221 | core_index}, | ||
| 222 | core_index{core_index}, exclusive_monitor{ | ||
| 223 | dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {} | ||
| 191 | 224 | ||
| 192 | ARM_Dynarmic_64::~ARM_Dynarmic_64() = default; | 225 | ARM_Dynarmic_64::~ARM_Dynarmic_64() = default; |
| 193 | 226 | ||
| @@ -239,6 +272,10 @@ void ARM_Dynarmic_64::SetTPIDR_EL0(u64 value) { | |||
| 239 | cb->tpidr_el0 = value; | 272 | cb->tpidr_el0 = value; |
| 240 | } | 273 | } |
| 241 | 274 | ||
| 275 | void ARM_Dynarmic_64::ChangeProcessorID(std::size_t new_core_id) { | ||
| 276 | jit->ChangeProcessorID(new_core_id); | ||
| 277 | } | ||
| 278 | |||
| 242 | void ARM_Dynarmic_64::SaveContext(ThreadContext64& ctx) { | 279 | void ARM_Dynarmic_64::SaveContext(ThreadContext64& ctx) { |
| 243 | ctx.cpu_registers = jit->GetRegisters(); | 280 | ctx.cpu_registers = jit->GetRegisters(); |
| 244 | ctx.sp = jit->GetSP(); | 281 | ctx.sp = jit->GetSP(); |
| @@ -266,6 +303,9 @@ void ARM_Dynarmic_64::PrepareReschedule() { | |||
| 266 | } | 303 | } |
| 267 | 304 | ||
| 268 | void ARM_Dynarmic_64::ClearInstructionCache() { | 305 | void ARM_Dynarmic_64::ClearInstructionCache() { |
| 306 | if (!jit) { | ||
| 307 | return; | ||
| 308 | } | ||
| 269 | jit->ClearCache(); | 309 | jit->ClearCache(); |
| 270 | } | 310 | } |
| 271 | 311 | ||
| @@ -285,44 +325,4 @@ void ARM_Dynarmic_64::PageTableChanged(Common::PageTable& page_table, | |||
| 285 | jit_cache.emplace(key, jit); | 325 | jit_cache.emplace(key, jit); |
| 286 | } | 326 | } |
| 287 | 327 | ||
| 288 | DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(Memory::Memory& memory, std::size_t core_count) | ||
| 289 | : monitor(core_count), memory{memory} {} | ||
| 290 | |||
| 291 | DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; | ||
| 292 | |||
| 293 | void DynarmicExclusiveMonitor::SetExclusive(std::size_t core_index, VAddr addr) { | ||
| 294 | // Size doesn't actually matter. | ||
| 295 | monitor.Mark(core_index, addr, 16); | ||
| 296 | } | ||
| 297 | |||
| 298 | void DynarmicExclusiveMonitor::ClearExclusive() { | ||
| 299 | monitor.Clear(); | ||
| 300 | } | ||
| 301 | |||
| 302 | bool DynarmicExclusiveMonitor::ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) { | ||
| 303 | return monitor.DoExclusiveOperation(core_index, vaddr, 1, [&] { memory.Write8(vaddr, value); }); | ||
| 304 | } | ||
| 305 | |||
| 306 | bool DynarmicExclusiveMonitor::ExclusiveWrite16(std::size_t core_index, VAddr vaddr, u16 value) { | ||
| 307 | return monitor.DoExclusiveOperation(core_index, vaddr, 2, | ||
| 308 | [&] { memory.Write16(vaddr, value); }); | ||
| 309 | } | ||
| 310 | |||
| 311 | bool DynarmicExclusiveMonitor::ExclusiveWrite32(std::size_t core_index, VAddr vaddr, u32 value) { | ||
| 312 | return monitor.DoExclusiveOperation(core_index, vaddr, 4, | ||
| 313 | [&] { memory.Write32(vaddr, value); }); | ||
| 314 | } | ||
| 315 | |||
| 316 | bool DynarmicExclusiveMonitor::ExclusiveWrite64(std::size_t core_index, VAddr vaddr, u64 value) { | ||
| 317 | return monitor.DoExclusiveOperation(core_index, vaddr, 8, | ||
| 318 | [&] { memory.Write64(vaddr, value); }); | ||
| 319 | } | ||
| 320 | |||
| 321 | bool DynarmicExclusiveMonitor::ExclusiveWrite128(std::size_t core_index, VAddr vaddr, u128 value) { | ||
| 322 | return monitor.DoExclusiveOperation(core_index, vaddr, 16, [&] { | ||
| 323 | memory.Write64(vaddr + 0, value[0]); | ||
| 324 | memory.Write64(vaddr + 8, value[1]); | ||
| 325 | }); | ||
| 326 | } | ||
| 327 | |||
| 328 | } // namespace Core | 328 | } // namespace Core |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.h b/src/core/arm/dynarmic/arm_dynarmic_64.h index 647cecaf0..403c55961 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.h +++ b/src/core/arm/dynarmic/arm_dynarmic_64.h | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <unordered_map> | 8 | #include <unordered_map> |
| 9 | 9 | ||
| 10 | #include <dynarmic/A64/a64.h> | 10 | #include <dynarmic/A64/a64.h> |
| 11 | #include <dynarmic/A64/exclusive_monitor.h> | ||
| 12 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 13 | #include "common/hash.h" | 12 | #include "common/hash.h" |
| 14 | #include "core/arm/arm_interface.h" | 13 | #include "core/arm/arm_interface.h" |
| @@ -22,12 +21,14 @@ class Memory; | |||
| 22 | namespace Core { | 21 | namespace Core { |
| 23 | 22 | ||
| 24 | class DynarmicCallbacks64; | 23 | class DynarmicCallbacks64; |
| 24 | class CPUInterruptHandler; | ||
| 25 | class DynarmicExclusiveMonitor; | 25 | class DynarmicExclusiveMonitor; |
| 26 | class System; | 26 | class System; |
| 27 | 27 | ||
| 28 | class ARM_Dynarmic_64 final : public ARM_Interface { | 28 | class ARM_Dynarmic_64 final : public ARM_Interface { |
| 29 | public: | 29 | public: |
| 30 | ARM_Dynarmic_64(System& system, ExclusiveMonitor& exclusive_monitor, std::size_t core_index); | 30 | ARM_Dynarmic_64(System& system, CPUInterrupts& interrupt_handlers, bool uses_wall_clock, |
| 31 | ExclusiveMonitor& exclusive_monitor, std::size_t core_index); | ||
| 31 | ~ARM_Dynarmic_64() override; | 32 | ~ARM_Dynarmic_64() override; |
| 32 | 33 | ||
| 33 | void SetPC(u64 pc) override; | 34 | void SetPC(u64 pc) override; |
| @@ -44,6 +45,7 @@ public: | |||
| 44 | void SetTlsAddress(VAddr address) override; | 45 | void SetTlsAddress(VAddr address) override; |
| 45 | void SetTPIDR_EL0(u64 value) override; | 46 | void SetTPIDR_EL0(u64 value) override; |
| 46 | u64 GetTPIDR_EL0() const override; | 47 | u64 GetTPIDR_EL0() const override; |
| 48 | void ChangeProcessorID(std::size_t new_core_id) override; | ||
| 47 | 49 | ||
| 48 | void SaveContext(ThreadContext32& ctx) override {} | 50 | void SaveContext(ThreadContext32& ctx) override {} |
| 49 | void SaveContext(ThreadContext64& ctx) override; | 51 | void SaveContext(ThreadContext64& ctx) override; |
| @@ -75,24 +77,4 @@ private: | |||
| 75 | DynarmicExclusiveMonitor& exclusive_monitor; | 77 | DynarmicExclusiveMonitor& exclusive_monitor; |
| 76 | }; | 78 | }; |
| 77 | 79 | ||
| 78 | class DynarmicExclusiveMonitor final : public ExclusiveMonitor { | ||
| 79 | public: | ||
| 80 | explicit DynarmicExclusiveMonitor(Memory::Memory& memory, std::size_t core_count); | ||
| 81 | ~DynarmicExclusiveMonitor() override; | ||
| 82 | |||
| 83 | void SetExclusive(std::size_t core_index, VAddr addr) override; | ||
| 84 | void ClearExclusive() override; | ||
| 85 | |||
| 86 | bool ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) override; | ||
| 87 | bool ExclusiveWrite16(std::size_t core_index, VAddr vaddr, u16 value) override; | ||
| 88 | bool ExclusiveWrite32(std::size_t core_index, VAddr vaddr, u32 value) override; | ||
| 89 | bool ExclusiveWrite64(std::size_t core_index, VAddr vaddr, u64 value) override; | ||
| 90 | bool ExclusiveWrite128(std::size_t core_index, VAddr vaddr, u128 value) override; | ||
| 91 | |||
| 92 | private: | ||
| 93 | friend class ARM_Dynarmic_64; | ||
| 94 | Dynarmic::A64::ExclusiveMonitor monitor; | ||
| 95 | Core::Memory::Memory& memory; | ||
| 96 | }; | ||
| 97 | |||
| 98 | } // namespace Core | 80 | } // namespace Core |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp index d43e4dd70..54556e0f9 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp | |||
| @@ -97,7 +97,7 @@ CallbackOrAccessTwoWords DynarmicCP15::CompileGetTwoWords(bool two, unsigned opc | |||
| 97 | const auto callback = static_cast<u64 (*)(Dynarmic::A32::Jit*, void*, u32, u32)>( | 97 | const auto callback = static_cast<u64 (*)(Dynarmic::A32::Jit*, void*, u32, u32)>( |
| 98 | [](Dynarmic::A32::Jit*, void* arg, u32, u32) -> u64 { | 98 | [](Dynarmic::A32::Jit*, void* arg, u32, u32) -> u64 { |
| 99 | ARM_Dynarmic_32& parent = *(ARM_Dynarmic_32*)arg; | 99 | ARM_Dynarmic_32& parent = *(ARM_Dynarmic_32*)arg; |
| 100 | return Timing::CpuCyclesToClockCycles(parent.system.CoreTiming().GetTicks()); | 100 | return parent.system.CoreTiming().GetClockTicks(); |
| 101 | }); | 101 | }); |
| 102 | return Dynarmic::A32::Coprocessor::Callback{callback, (void*)&parent}; | 102 | return Dynarmic::A32::Coprocessor::Callback{callback, (void*)&parent}; |
| 103 | } | 103 | } |
diff --git a/src/core/arm/dynarmic/arm_exclusive_monitor.cpp b/src/core/arm/dynarmic/arm_exclusive_monitor.cpp new file mode 100644 index 000000000..4e209f6a5 --- /dev/null +++ b/src/core/arm/dynarmic/arm_exclusive_monitor.cpp | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cinttypes> | ||
| 6 | #include <memory> | ||
| 7 | #include "core/arm/dynarmic/arm_exclusive_monitor.h" | ||
| 8 | #include "core/memory.h" | ||
| 9 | |||
| 10 | namespace Core { | ||
| 11 | |||
| 12 | DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(Memory::Memory& memory, std::size_t core_count) | ||
| 13 | : monitor(core_count), memory{memory} {} | ||
| 14 | |||
| 15 | DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; | ||
| 16 | |||
| 17 | u8 DynarmicExclusiveMonitor::ExclusiveRead8(std::size_t core_index, VAddr addr) { | ||
| 18 | return monitor.ReadAndMark<u8>(core_index, addr, [&]() -> u8 { return memory.Read8(addr); }); | ||
| 19 | } | ||
| 20 | |||
| 21 | u16 DynarmicExclusiveMonitor::ExclusiveRead16(std::size_t core_index, VAddr addr) { | ||
| 22 | return monitor.ReadAndMark<u16>(core_index, addr, [&]() -> u16 { return memory.Read16(addr); }); | ||
| 23 | } | ||
| 24 | |||
| 25 | u32 DynarmicExclusiveMonitor::ExclusiveRead32(std::size_t core_index, VAddr addr) { | ||
| 26 | return monitor.ReadAndMark<u32>(core_index, addr, [&]() -> u32 { return memory.Read32(addr); }); | ||
| 27 | } | ||
| 28 | |||
| 29 | u64 DynarmicExclusiveMonitor::ExclusiveRead64(std::size_t core_index, VAddr addr) { | ||
| 30 | return monitor.ReadAndMark<u64>(core_index, addr, [&]() -> u64 { return memory.Read64(addr); }); | ||
| 31 | } | ||
| 32 | |||
| 33 | u128 DynarmicExclusiveMonitor::ExclusiveRead128(std::size_t core_index, VAddr addr) { | ||
| 34 | return monitor.ReadAndMark<u128>(core_index, addr, [&]() -> u128 { | ||
| 35 | u128 result; | ||
| 36 | result[0] = memory.Read64(addr); | ||
| 37 | result[1] = memory.Read64(addr + 8); | ||
| 38 | return result; | ||
| 39 | }); | ||
| 40 | } | ||
| 41 | |||
| 42 | void DynarmicExclusiveMonitor::ClearExclusive() { | ||
| 43 | monitor.Clear(); | ||
| 44 | } | ||
| 45 | |||
| 46 | bool DynarmicExclusiveMonitor::ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) { | ||
| 47 | return monitor.DoExclusiveOperation<u8>(core_index, vaddr, [&](u8 expected) -> bool { | ||
| 48 | return memory.WriteExclusive8(vaddr, value, expected); | ||
| 49 | }); | ||
| 50 | } | ||
| 51 | |||
| 52 | bool DynarmicExclusiveMonitor::ExclusiveWrite16(std::size_t core_index, VAddr vaddr, u16 value) { | ||
| 53 | return monitor.DoExclusiveOperation<u16>(core_index, vaddr, [&](u16 expected) -> bool { | ||
| 54 | return memory.WriteExclusive16(vaddr, value, expected); | ||
| 55 | }); | ||
| 56 | } | ||
| 57 | |||
| 58 | bool DynarmicExclusiveMonitor::ExclusiveWrite32(std::size_t core_index, VAddr vaddr, u32 value) { | ||
| 59 | return monitor.DoExclusiveOperation<u32>(core_index, vaddr, [&](u32 expected) -> bool { | ||
| 60 | return memory.WriteExclusive32(vaddr, value, expected); | ||
| 61 | }); | ||
| 62 | } | ||
| 63 | |||
| 64 | bool DynarmicExclusiveMonitor::ExclusiveWrite64(std::size_t core_index, VAddr vaddr, u64 value) { | ||
| 65 | return monitor.DoExclusiveOperation<u64>(core_index, vaddr, [&](u64 expected) -> bool { | ||
| 66 | return memory.WriteExclusive64(vaddr, value, expected); | ||
| 67 | }); | ||
| 68 | } | ||
| 69 | |||
| 70 | bool DynarmicExclusiveMonitor::ExclusiveWrite128(std::size_t core_index, VAddr vaddr, u128 value) { | ||
| 71 | return monitor.DoExclusiveOperation<u128>(core_index, vaddr, [&](u128 expected) -> bool { | ||
| 72 | return memory.WriteExclusive128(vaddr, value, expected); | ||
| 73 | }); | ||
| 74 | } | ||
| 75 | |||
| 76 | } // namespace Core | ||
diff --git a/src/core/arm/dynarmic/arm_exclusive_monitor.h b/src/core/arm/dynarmic/arm_exclusive_monitor.h new file mode 100644 index 000000000..964f4a55d --- /dev/null +++ b/src/core/arm/dynarmic/arm_exclusive_monitor.h | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | // Copyright 2020 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <unordered_map> | ||
| 9 | |||
| 10 | #include <dynarmic/exclusive_monitor.h> | ||
| 11 | |||
| 12 | #include "common/common_types.h" | ||
| 13 | #include "core/arm/dynarmic/arm_dynarmic_32.h" | ||
| 14 | #include "core/arm/dynarmic/arm_dynarmic_64.h" | ||
| 15 | #include "core/arm/exclusive_monitor.h" | ||
| 16 | |||
| 17 | namespace Core::Memory { | ||
| 18 | class Memory; | ||
| 19 | } | ||
| 20 | |||
| 21 | namespace Core { | ||
| 22 | |||
| 23 | class DynarmicExclusiveMonitor final : public ExclusiveMonitor { | ||
| 24 | public: | ||
| 25 | explicit DynarmicExclusiveMonitor(Memory::Memory& memory, std::size_t core_count); | ||
| 26 | ~DynarmicExclusiveMonitor() override; | ||
| 27 | |||
| 28 | u8 ExclusiveRead8(std::size_t core_index, VAddr addr) override; | ||
| 29 | u16 ExclusiveRead16(std::size_t core_index, VAddr addr) override; | ||
| 30 | u32 ExclusiveRead32(std::size_t core_index, VAddr addr) override; | ||
| 31 | u64 ExclusiveRead64(std::size_t core_index, VAddr addr) override; | ||
| 32 | u128 ExclusiveRead128(std::size_t core_index, VAddr addr) override; | ||
| 33 | void ClearExclusive() override; | ||
| 34 | |||
| 35 | bool ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) override; | ||
| 36 | bool ExclusiveWrite16(std::size_t core_index, VAddr vaddr, u16 value) override; | ||
| 37 | bool ExclusiveWrite32(std::size_t core_index, VAddr vaddr, u32 value) override; | ||
| 38 | bool ExclusiveWrite64(std::size_t core_index, VAddr vaddr, u64 value) override; | ||
| 39 | bool ExclusiveWrite128(std::size_t core_index, VAddr vaddr, u128 value) override; | ||
| 40 | |||
| 41 | private: | ||
| 42 | friend class ARM_Dynarmic_32; | ||
| 43 | friend class ARM_Dynarmic_64; | ||
| 44 | Dynarmic::ExclusiveMonitor monitor; | ||
| 45 | Core::Memory::Memory& memory; | ||
| 46 | }; | ||
| 47 | |||
| 48 | } // namespace Core | ||
diff --git a/src/core/arm/exclusive_monitor.cpp b/src/core/arm/exclusive_monitor.cpp index b32401e0b..d8cba369d 100644 --- a/src/core/arm/exclusive_monitor.cpp +++ b/src/core/arm/exclusive_monitor.cpp | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #ifdef ARCHITECTURE_x86_64 | 5 | #ifdef ARCHITECTURE_x86_64 |
| 6 | #include "core/arm/dynarmic/arm_dynarmic_64.h" | 6 | #include "core/arm/dynarmic/arm_exclusive_monitor.h" |
| 7 | #endif | 7 | #endif |
| 8 | #include "core/arm/exclusive_monitor.h" | 8 | #include "core/arm/exclusive_monitor.h" |
| 9 | #include "core/memory.h" | 9 | #include "core/memory.h" |
diff --git a/src/core/arm/exclusive_monitor.h b/src/core/arm/exclusive_monitor.h index ccd73b80f..62f6e6023 100644 --- a/src/core/arm/exclusive_monitor.h +++ b/src/core/arm/exclusive_monitor.h | |||
| @@ -18,7 +18,11 @@ class ExclusiveMonitor { | |||
| 18 | public: | 18 | public: |
| 19 | virtual ~ExclusiveMonitor(); | 19 | virtual ~ExclusiveMonitor(); |
| 20 | 20 | ||
| 21 | virtual void SetExclusive(std::size_t core_index, VAddr addr) = 0; | 21 | virtual u8 ExclusiveRead8(std::size_t core_index, VAddr addr) = 0; |
| 22 | virtual u16 ExclusiveRead16(std::size_t core_index, VAddr addr) = 0; | ||
| 23 | virtual u32 ExclusiveRead32(std::size_t core_index, VAddr addr) = 0; | ||
| 24 | virtual u64 ExclusiveRead64(std::size_t core_index, VAddr addr) = 0; | ||
| 25 | virtual u128 ExclusiveRead128(std::size_t core_index, VAddr addr) = 0; | ||
| 22 | virtual void ClearExclusive() = 0; | 26 | virtual void ClearExclusive() = 0; |
| 23 | 27 | ||
| 24 | virtual bool ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) = 0; | 28 | virtual bool ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) = 0; |
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index e40e9626a..1df3f3ed1 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <unicorn/arm64.h> | 6 | #include <unicorn/arm64.h> |
| 7 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 8 | #include "common/microprofile.h" | 8 | #include "common/microprofile.h" |
| 9 | #include "core/arm/cpu_interrupt_handler.h" | ||
| 9 | #include "core/arm/unicorn/arm_unicorn.h" | 10 | #include "core/arm/unicorn/arm_unicorn.h" |
| 10 | #include "core/core.h" | 11 | #include "core/core.h" |
| 11 | #include "core/core_timing.h" | 12 | #include "core/core_timing.h" |
| @@ -62,7 +63,9 @@ static bool UnmappedMemoryHook(uc_engine* uc, uc_mem_type type, u64 addr, int si | |||
| 62 | return false; | 63 | return false; |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | ARM_Unicorn::ARM_Unicorn(System& system, Arch architecture) : ARM_Interface{system} { | 66 | ARM_Unicorn::ARM_Unicorn(System& system, CPUInterrupts& interrupt_handlers, bool uses_wall_clock, |
| 67 | Arch architecture, std::size_t core_index) | ||
| 68 | : ARM_Interface{system, interrupt_handlers, uses_wall_clock}, core_index{core_index} { | ||
| 66 | const auto arch = architecture == Arch::AArch32 ? UC_ARCH_ARM : UC_ARCH_ARM64; | 69 | const auto arch = architecture == Arch::AArch32 ? UC_ARCH_ARM : UC_ARCH_ARM64; |
| 67 | CHECKED(uc_open(arch, UC_MODE_ARM, &uc)); | 70 | CHECKED(uc_open(arch, UC_MODE_ARM, &uc)); |
| 68 | 71 | ||
| @@ -156,12 +159,20 @@ void ARM_Unicorn::SetTPIDR_EL0(u64 value) { | |||
| 156 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDR_EL0, &value)); | 159 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDR_EL0, &value)); |
| 157 | } | 160 | } |
| 158 | 161 | ||
| 162 | void ARM_Unicorn::ChangeProcessorID(std::size_t new_core_id) { | ||
| 163 | core_index = new_core_id; | ||
| 164 | } | ||
| 165 | |||
| 159 | void ARM_Unicorn::Run() { | 166 | void ARM_Unicorn::Run() { |
| 160 | if (GDBStub::IsServerEnabled()) { | 167 | if (GDBStub::IsServerEnabled()) { |
| 161 | ExecuteInstructions(std::max(4000000U, 0U)); | 168 | ExecuteInstructions(std::max(4000000U, 0U)); |
| 162 | } else { | 169 | } else { |
| 163 | ExecuteInstructions( | 170 | while (true) { |
| 164 | std::max(std::size_t(system.CoreTiming().GetDowncount()), std::size_t{0})); | 171 | if (interrupt_handlers[core_index].IsInterrupted()) { |
| 172 | return; | ||
| 173 | } | ||
| 174 | ExecuteInstructions(10); | ||
| 175 | } | ||
| 165 | } | 176 | } |
| 166 | } | 177 | } |
| 167 | 178 | ||
| @@ -183,8 +194,6 @@ void ARM_Unicorn::ExecuteInstructions(std::size_t num_instructions) { | |||
| 183 | UC_PROT_READ | UC_PROT_WRITE | UC_PROT_EXEC, page_buffer.data())); | 194 | UC_PROT_READ | UC_PROT_WRITE | UC_PROT_EXEC, page_buffer.data())); |
| 184 | CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions)); | 195 | CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions)); |
| 185 | CHECKED(uc_mem_unmap(uc, map_addr, page_buffer.size())); | 196 | CHECKED(uc_mem_unmap(uc, map_addr, page_buffer.size())); |
| 186 | |||
| 187 | system.CoreTiming().AddTicks(num_instructions); | ||
| 188 | if (GDBStub::IsServerEnabled()) { | 197 | if (GDBStub::IsServerEnabled()) { |
| 189 | if (last_bkpt_hit && last_bkpt.type == GDBStub::BreakpointType::Execute) { | 198 | if (last_bkpt_hit && last_bkpt.type == GDBStub::BreakpointType::Execute) { |
| 190 | uc_reg_write(uc, UC_ARM64_REG_PC, &last_bkpt.address); | 199 | uc_reg_write(uc, UC_ARM64_REG_PC, &last_bkpt.address); |
diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index 725c65085..810aff311 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h | |||
| @@ -20,7 +20,8 @@ public: | |||
| 20 | AArch64, // 64-bit ARM | 20 | AArch64, // 64-bit ARM |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | explicit ARM_Unicorn(System& system, Arch architecture); | 23 | explicit ARM_Unicorn(System& system, CPUInterrupts& interrupt_handlers, bool uses_wall_clock, |
| 24 | Arch architecture, std::size_t core_index); | ||
| 24 | ~ARM_Unicorn() override; | 25 | ~ARM_Unicorn() override; |
| 25 | 26 | ||
| 26 | void SetPC(u64 pc) override; | 27 | void SetPC(u64 pc) override; |
| @@ -35,6 +36,7 @@ public: | |||
| 35 | void SetTlsAddress(VAddr address) override; | 36 | void SetTlsAddress(VAddr address) override; |
| 36 | void SetTPIDR_EL0(u64 value) override; | 37 | void SetTPIDR_EL0(u64 value) override; |
| 37 | u64 GetTPIDR_EL0() const override; | 38 | u64 GetTPIDR_EL0() const override; |
| 39 | void ChangeProcessorID(std::size_t new_core_id) override; | ||
| 38 | void PrepareReschedule() override; | 40 | void PrepareReschedule() override; |
| 39 | void ClearExclusiveState() override; | 41 | void ClearExclusiveState() override; |
| 40 | void ExecuteInstructions(std::size_t num_instructions); | 42 | void ExecuteInstructions(std::size_t num_instructions); |
| @@ -55,6 +57,7 @@ private: | |||
| 55 | uc_engine* uc{}; | 57 | uc_engine* uc{}; |
| 56 | GDBStub::BreakpointAddress last_bkpt{}; | 58 | GDBStub::BreakpointAddress last_bkpt{}; |
| 57 | bool last_bkpt_hit = false; | 59 | bool last_bkpt_hit = false; |
| 60 | std::size_t core_index; | ||
| 58 | }; | 61 | }; |
| 59 | 62 | ||
| 60 | } // namespace Core | 63 | } // namespace Core |