Core: Refactor ARM Interface.

This commit is contained in:
Fernando Sahmkow 2020-02-29 13:58:50 -04:00
parent 534466754f
commit 1b82ccec22
10 changed files with 69 additions and 42 deletions

View file

@ -7,6 +7,7 @@
#include <array> #include <array>
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hardware_properties.h"
namespace Common { namespace Common {
struct PageTable; struct PageTable;
@ -20,11 +21,13 @@ namespace Core {
class System; class System;
class CPUInterruptHandler; class CPUInterruptHandler;
using CPUInterrupts = std::array<CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>;
/// Generic ARMv8 CPU interface /// Generic ARMv8 CPU interface
class ARM_Interface : NonCopyable { class ARM_Interface : NonCopyable {
public: public:
explicit ARM_Interface(System& system_, CPUInterruptHandler& interrupt_handler) explicit ARM_Interface(System& system_, CPUInterrupts& interrupt_handlers)
: system{system_}, interrupt_handler{interrupt_handler} {} : system{system_}, interrupt_handlers{interrupt_handlers} {}
virtual ~ARM_Interface() = default; virtual ~ARM_Interface() = default;
struct ThreadContext32 { struct ThreadContext32 {
@ -180,7 +183,7 @@ public:
protected: protected:
/// System context that this ARM interface is running under. /// System context that this ARM interface is running under.
System& system; System& system;
CPUInterruptHandler& interrupt_handler; CPUInterrupts& interrupt_handlers;
}; };
} // namespace Core } // namespace Core

View file

@ -76,7 +76,7 @@ public:
} }
u64 GetTicksRemaining() override { u64 GetTicksRemaining() override {
if (!parent.interrupt_handler.IsInterrupted()) { if (!parent.interrupt_handlers[parent.core_index].IsInterrupted()) {
return std::max<s64>(ticks, 0); return std::max<s64>(ticks, 0);
} }
return 0ULL; return 0ULL;
@ -111,9 +111,9 @@ void ARM_Dynarmic_32::Step() {
jit->Step(); jit->Step();
} }
ARM_Dynarmic_32::ARM_Dynarmic_32(System& system, CPUInterruptHandler& interrupt_handler, ARM_Dynarmic_32::ARM_Dynarmic_32(System& system, CPUInterrupts& interrupt_handlers,
ExclusiveMonitor& exclusive_monitor, std::size_t core_index) ExclusiveMonitor& exclusive_monitor, std::size_t core_index)
: ARM_Interface{system, interrupt_handler}, cb(std::make_unique<DynarmicCallbacks32>(*this)), : ARM_Interface{system, interrupt_handlers}, cb(std::make_unique<DynarmicCallbacks32>(*this)),
cp15(std::make_shared<DynarmicCP15>(*this)), core_index{core_index}, cp15(std::make_shared<DynarmicCP15>(*this)), core_index{core_index},
exclusive_monitor{dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {} exclusive_monitor{dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {}

View file

@ -29,7 +29,7 @@ class System;
class ARM_Dynarmic_32 final : public ARM_Interface { class ARM_Dynarmic_32 final : public ARM_Interface {
public: public:
ARM_Dynarmic_32(System& system, CPUInterruptHandler& interrupt_handler, ARM_Dynarmic_32(System& system, CPUInterrupts& interrupt_handlers,
ExclusiveMonitor& exclusive_monitor, std::size_t core_index); ExclusiveMonitor& exclusive_monitor, std::size_t core_index);
~ARM_Dynarmic_32() override; ~ARM_Dynarmic_32() override;

View file

@ -128,7 +128,7 @@ public:
} }
u64 GetTicksRemaining() override { u64 GetTicksRemaining() override {
if (!parent.interrupt_handler.IsInterrupted()) { if (!parent.interrupt_handlers[parent.core_index].IsInterrupted()) {
return std::max<s64>(ticks, 0); return std::max<s64>(ticks, 0);
} }
return 0ULL; return 0ULL;
@ -199,11 +199,14 @@ void ARM_Dynarmic_64::Step() {
cb->InterpreterFallback(jit->GetPC(), 1); cb->InterpreterFallback(jit->GetPC(), 1);
} }
ARM_Dynarmic_64::ARM_Dynarmic_64(System& system, CPUInterruptHandler& interrupt_handler, ARM_Dynarmic_64::ARM_Dynarmic_64(System& system, CPUInterrupts& interrupt_handlers,
ExclusiveMonitor& exclusive_monitor, std::size_t core_index) ExclusiveMonitor& exclusive_monitor, std::size_t core_index)
: ARM_Interface{system, interrupt_handler}, cb(std::make_unique<DynarmicCallbacks64>(*this)), : ARM_Interface{system, interrupt_handler},
inner_unicorn{system, interrupt_handler, ARM_Unicorn::Arch::AArch64}, core_index{core_index}, cb(std::make_unique<DynarmicCallbacks64>(*this)), inner_unicorn{system, interrupt_handler,
exclusive_monitor{dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {} ARM_Unicorn::Arch::AArch64,
core_index},
core_index{core_index}, exclusive_monitor{
dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {}
ARM_Dynarmic_64::~ARM_Dynarmic_64() = default; ARM_Dynarmic_64::~ARM_Dynarmic_64() = default;

View file

@ -28,7 +28,7 @@ class System;
class ARM_Dynarmic_64 final : public ARM_Interface { class ARM_Dynarmic_64 final : public ARM_Interface {
public: public:
ARM_Dynarmic_64(System& system, CPUInterruptHandler& interrupt_handler, ARM_Dynarmic_64(System& system, CPUInterrupts& interrupt_handlers,
ExclusiveMonitor& exclusive_monitor, std::size_t core_index); ExclusiveMonitor& exclusive_monitor, std::size_t core_index);
~ARM_Dynarmic_64() override; ~ARM_Dynarmic_64() override;

View file

@ -63,8 +63,9 @@ static bool UnmappedMemoryHook(uc_engine* uc, uc_mem_type type, u64 addr, int si
return false; return false;
} }
ARM_Unicorn::ARM_Unicorn(System& system, CPUInterruptHandler& interrupt_handler, Arch architecture) ARM_Unicorn::ARM_Unicorn(System& system, CPUInterruptHandler& interrupt_handler, Arch architecture,
: ARM_Interface{system, interrupt_handler} { std::size_t core_index)
: ARM_Interface{system, interrupt_handler}, core_index{core_index} {
const auto arch = architecture == Arch::AArch32 ? UC_ARCH_ARM : UC_ARCH_ARM64; const auto arch = architecture == Arch::AArch32 ? UC_ARCH_ARM : UC_ARCH_ARM64;
CHECKED(uc_open(arch, UC_MODE_ARM, &uc)); CHECKED(uc_open(arch, UC_MODE_ARM, &uc));
@ -163,7 +164,7 @@ void ARM_Unicorn::Run() {
ExecuteInstructions(std::max(4000000U, 0U)); ExecuteInstructions(std::max(4000000U, 0U));
} else { } else {
while (true) { while (true) {
if (interrupt_handler.IsInterrupted()) { if (interrupt_handlers[core_index].IsInterrupted()) {
return; return;
} }
ExecuteInstructions(10); ExecuteInstructions(10);

View file

@ -11,7 +11,6 @@
namespace Core { namespace Core {
class CPUInterruptHandler;
class System; class System;
class ARM_Unicorn final : public ARM_Interface { class ARM_Unicorn final : public ARM_Interface {
@ -21,7 +20,8 @@ public:
AArch64, // 64-bit ARM AArch64, // 64-bit ARM
}; };
explicit ARM_Unicorn(System& system, CPUInterruptHandler& interrupt_handler, Arch architecture); explicit ARM_Unicorn(System& system, CPUInterruptHandler& interrupt_handler, Arch architecture,
std::size_t core_index);
~ARM_Unicorn() override; ~ARM_Unicorn() override;
void SetPC(u64 pc) override; void SetPC(u64 pc) override;
@ -56,6 +56,7 @@ private:
uc_engine* uc{}; uc_engine* uc{};
GDBStub::BreakpointAddress last_bkpt{}; GDBStub::BreakpointAddress last_bkpt{};
bool last_bkpt_hit = false; bool last_bkpt_hit = false;
std::size_t core_index;
}; };
} // namespace Core } // namespace Core

View file

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <array>
#include <atomic> #include <atomic>
#include <bitset> #include <bitset>
#include <functional> #include <functional>
@ -16,7 +17,9 @@
#include "common/microprofile.h" #include "common/microprofile.h"
#include "common/thread.h" #include "common/thread.h"
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
#include "core/arm/cpu_interrupt_handler.h"
#include "core/arm/exclusive_monitor.h" #include "core/arm/exclusive_monitor.h"
#include "core/arm/unicorn/arm_unicorn.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/core_timing_util.h" #include "core/core_timing_util.h"
@ -42,6 +45,11 @@
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/memory.h" #include "core/memory.h"
#ifdef ARCHITECTURE_x86_64
#include "core/arm/dynarmic/arm_dynarmic_32.h"
#include "core/arm/dynarmic/arm_dynarmic_64.h"
#endif
MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70)); MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));
namespace Kernel { namespace Kernel {
@ -178,7 +186,20 @@ struct KernelCore::Impl {
exclusive_monitor = exclusive_monitor =
Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES); Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES);
for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) {
cores.emplace_back(system, i, *exclusive_monitor); #ifdef ARCHITECTURE_x86_64
arm_interfaces_32[i] =
std::make_unique<Core::ARM_Dynarmic_32>(system, interrupts, *exclusive_monitor, i);
arm_interfaces_64[i] =
std::make_unique<Core::ARM_Dynarmic_64>(system, interrupts, *exclusive_monitor, i);
#else
arm_interfaces_32[i] = std::make_shared<Core::ARM_Unicorn>(
system, interrupts, ARM_Unicorn::Arch::AArch32, i);
arm_interfaces_64[i] = std::make_shared<Core::ARM_Unicorn>(
system, interrupts, ARM_Unicorn::Arch::AArch64, i);
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
#endif
cores.emplace_back(system, i, *exclusive_monitor, interrupts[i], *arm_interfaces_32[i],
*arm_interfaces_64[i]);
} }
} }
@ -407,6 +428,11 @@ struct KernelCore::Impl {
std::shared_ptr<Kernel::SharedMemory> time_shared_mem; std::shared_ptr<Kernel::SharedMemory> time_shared_mem;
std::array<std::shared_ptr<Thread>, Core::Hardware::NUM_CPU_CORES> suspend_threads{}; std::array<std::shared_ptr<Thread>, Core::Hardware::NUM_CPU_CORES> suspend_threads{};
std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{};
std::array<std::unique_ptr<Core::ARM_Interface>, Core::Hardware::NUM_CPU_CORES>
arm_interfaces_32{};
std::array<std::unique_ptr<Core::ARM_Interface>, Core::Hardware::NUM_CPU_CORES>
arm_interfaces_64{};
bool is_multicore{}; bool is_multicore{};
std::thread::id single_core_thread_id{}; std::thread::id single_core_thread_id{};

View file

@ -21,21 +21,12 @@
namespace Kernel { namespace Kernel {
PhysicalCore::PhysicalCore(Core::System& system, std::size_t id, PhysicalCore::PhysicalCore(Core::System& system, std::size_t id,
Core::ExclusiveMonitor& exclusive_monitor) Core::ExclusiveMonitor& exclusive_monitor,
: interrupt_handler{}, core_index{id} { Core::CPUInterruptHandler& interrupt_handler,
#ifdef ARCHITECTURE_x86_64 Core::ARM_Interface& arm_interface32,
arm_interface_32 = std::make_unique<Core::ARM_Dynarmic_32>(system, interrupt_handler, Core::ARM_Interface& arm_interface64)
exclusive_monitor, core_index); : interrupt_handler{interrupt_handler}, core_index{id}, arm_interface_32{arm_interface32},
arm_interface_64 = std::make_unique<Core::ARM_Dynarmic_64>(system, interrupt_handler, arm_interface_64{arm_interface64} {
exclusive_monitor, core_index);
#else
using Core::ARM_Unicorn;
arm_interface_32 =
std::make_unique<ARM_Unicorn>(system, interrupt_handler, ARM_Unicorn::Arch::AArch32);
arm_interface_64 =
std::make_unique<ARM_Unicorn>(system, interrupt_handler, ARM_Unicorn::Arch::AArch64);
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
#endif
scheduler = std::make_unique<Kernel::Scheduler>(system, core_index); scheduler = std::make_unique<Kernel::Scheduler>(system, core_index);
guard = std::make_unique<Common::SpinLock>(); guard = std::make_unique<Common::SpinLock>();
@ -69,9 +60,9 @@ void PhysicalCore::Shutdown() {
void PhysicalCore::SetIs64Bit(bool is_64_bit) { void PhysicalCore::SetIs64Bit(bool is_64_bit) {
if (is_64_bit) { if (is_64_bit) {
arm_interface = arm_interface_64.get(); arm_interface = &arm_interface_64;
} else { } else {
arm_interface = arm_interface_32.get(); arm_interface = &arm_interface_32;
} }
} }

View file

@ -10,7 +10,7 @@
#include "core/arm/cpu_interrupt_handler.h" #include "core/arm/cpu_interrupt_handler.h"
namespace Common { namespace Common {
class SpinLock; class SpinLock;
} }
namespace Kernel { namespace Kernel {
@ -27,7 +27,9 @@ namespace Kernel {
class PhysicalCore { class PhysicalCore {
public: public:
PhysicalCore(Core::System& system, std::size_t id, Core::ExclusiveMonitor& exclusive_monitor); PhysicalCore(Core::System& system, std::size_t id, Core::ExclusiveMonitor& exclusive_monitor,
Core::CPUInterruptHandler& interrupt_handler, Core::ARM_Interface& arm_interface32,
Core::ARM_Interface& arm_interface64);
~PhysicalCore(); ~PhysicalCore();
PhysicalCore(const PhysicalCore&) = delete; PhysicalCore(const PhysicalCore&) = delete;
@ -92,13 +94,13 @@ public:
void SetIs64Bit(bool is_64_bit); void SetIs64Bit(bool is_64_bit);
private: private:
Core::CPUInterruptHandler interrupt_handler; Core::CPUInterruptHandler& interrupt_handler;
std::size_t core_index; std::size_t core_index;
std::unique_ptr<Core::ARM_Interface> arm_interface_32; Core::ARM_Interface& arm_interface_32;
std::unique_ptr<Core::ARM_Interface> arm_interface_64; Core::ARM_Interface& arm_interface_64;
std::unique_ptr<Kernel::Scheduler> scheduler; std::unique_ptr<Kernel::Scheduler> scheduler;
Core::ARM_Interface* arm_interface{}; Core::ARM_Interface* arm_interface{};
std::unique_ptr<Common::SpinLock> guard; std::unique_ptr<Common::SpinLock> guard;
}; };
} // namespace Kernel } // namespace Kernel