diff options
Diffstat (limited to 'src/core/cpu_manager.cpp')
| -rw-r--r-- | src/core/cpu_manager.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp new file mode 100644 index 000000000..abc8aad9e --- /dev/null +++ b/src/core/cpu_manager.cpp | |||
| @@ -0,0 +1,84 @@ | |||
| 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 "common/assert.h" | ||
| 6 | #include "core/arm/exclusive_monitor.h" | ||
| 7 | #include "core/core.h" | ||
| 8 | #include "core/core_manager.h" | ||
| 9 | #include "core/core_timing.h" | ||
| 10 | #include "core/cpu_manager.h" | ||
| 11 | #include "core/gdbstub/gdbstub.h" | ||
| 12 | #include "core/settings.h" | ||
| 13 | |||
| 14 | namespace Core { | ||
| 15 | |||
| 16 | CpuManager::CpuManager(System& system) : system{system} {} | ||
| 17 | CpuManager::~CpuManager() = default; | ||
| 18 | |||
| 19 | void CpuManager::Initialize() { | ||
| 20 | |||
| 21 | for (std::size_t index = 0; index < core_managers.size(); ++index) { | ||
| 22 | core_managers[index] = std::make_unique<CoreManager>(system, index); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | void CpuManager::Shutdown() { | ||
| 27 | for (auto& cpu_core : core_managers) { | ||
| 28 | cpu_core.reset(); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | CoreManager& CpuManager::GetCoreManager(std::size_t index) { | ||
| 33 | return *core_managers.at(index); | ||
| 34 | } | ||
| 35 | |||
| 36 | const CoreManager& CpuManager::GetCoreManager(std::size_t index) const { | ||
| 37 | return *core_managers.at(index); | ||
| 38 | } | ||
| 39 | |||
| 40 | CoreManager& CpuManager::GetCurrentCoreManager() { | ||
| 41 | // Otherwise, use single-threaded mode active_core variable | ||
| 42 | return *core_managers[active_core]; | ||
| 43 | } | ||
| 44 | |||
| 45 | const CoreManager& CpuManager::GetCurrentCoreManager() const { | ||
| 46 | // Otherwise, use single-threaded mode active_core variable | ||
| 47 | return *core_managers[active_core]; | ||
| 48 | } | ||
| 49 | |||
| 50 | void CpuManager::RunLoop(bool tight_loop) { | ||
| 51 | if (GDBStub::IsServerEnabled()) { | ||
| 52 | GDBStub::HandlePacket(); | ||
| 53 | |||
| 54 | // If the loop is halted and we want to step, use a tiny (1) number of instructions to | ||
| 55 | // execute. Otherwise, get out of the loop function. | ||
| 56 | if (GDBStub::GetCpuHaltFlag()) { | ||
| 57 | if (GDBStub::GetCpuStepFlag()) { | ||
| 58 | tight_loop = false; | ||
| 59 | } else { | ||
| 60 | return; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | auto& core_timing = system.CoreTiming(); | ||
| 66 | core_timing.ResetRun(); | ||
| 67 | bool keep_running{}; | ||
| 68 | do { | ||
| 69 | keep_running = false; | ||
| 70 | for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) { | ||
| 71 | core_timing.SwitchContext(active_core); | ||
| 72 | if (core_timing.CanCurrentContextRun()) { | ||
| 73 | core_managers[active_core]->RunLoop(tight_loop); | ||
| 74 | } | ||
| 75 | keep_running |= core_timing.CanCurrentContextRun(); | ||
| 76 | } | ||
| 77 | } while (keep_running); | ||
| 78 | |||
| 79 | if (GDBStub::IsServerEnabled()) { | ||
| 80 | GDBStub::SetCpuStepFlag(false); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | } // namespace Core | ||