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/dynarmic | |
| 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/dynarmic')
| -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 |
7 files changed, 258 insertions, 89 deletions
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 | ||