2018-11-22 01:27:23 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "core/arm/exclusive_monitor.h"
|
|
|
|
#include "core/core.h"
|
2020-01-26 13:07:22 -05:00
|
|
|
#include "core/core_manager.h"
|
2019-09-09 21:37:29 -04:00
|
|
|
#include "core/core_timing.h"
|
2020-01-26 13:07:22 -05:00
|
|
|
#include "core/cpu_manager.h"
|
2018-11-22 01:27:23 -05:00
|
|
|
#include "core/gdbstub/gdbstub.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
CpuManager::CpuManager(System& system) : system{system} {}
|
|
|
|
CpuManager::~CpuManager() = default;
|
2018-11-22 01:27:23 -05:00
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
void CpuManager::Initialize() {
|
|
|
|
for (std::size_t index = 0; index < core_managers.size(); ++index) {
|
|
|
|
core_managers[index] = std::make_unique<CoreManager>(system, index);
|
2018-11-22 01:27:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
void CpuManager::Shutdown() {
|
|
|
|
for (auto& cpu_core : core_managers) {
|
2018-11-22 01:27:23 -05:00
|
|
|
cpu_core.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
CoreManager& CpuManager::GetCoreManager(std::size_t index) {
|
|
|
|
return *core_managers.at(index);
|
2018-11-22 01:27:23 -05:00
|
|
|
}
|
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
const CoreManager& CpuManager::GetCoreManager(std::size_t index) const {
|
|
|
|
return *core_managers.at(index);
|
2018-11-22 01:27:23 -05:00
|
|
|
}
|
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
CoreManager& CpuManager::GetCurrentCoreManager() {
|
2018-11-22 01:27:23 -05:00
|
|
|
// Otherwise, use single-threaded mode active_core variable
|
2020-01-26 13:07:22 -05:00
|
|
|
return *core_managers[active_core];
|
2018-11-22 01:27:23 -05:00
|
|
|
}
|
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
const CoreManager& CpuManager::GetCurrentCoreManager() const {
|
2018-11-22 01:27:23 -05:00
|
|
|
// Otherwise, use single-threaded mode active_core variable
|
2020-01-26 13:07:22 -05:00
|
|
|
return *core_managers[active_core];
|
2018-11-22 01:27:23 -05:00
|
|
|
}
|
|
|
|
|
2020-01-26 13:07:22 -05:00
|
|
|
void CpuManager::RunLoop(bool tight_loop) {
|
2018-11-22 01:27:23 -05:00
|
|
|
if (GDBStub::IsServerEnabled()) {
|
|
|
|
GDBStub::HandlePacket();
|
|
|
|
|
|
|
|
// If the loop is halted and we want to step, use a tiny (1) number of instructions to
|
|
|
|
// execute. Otherwise, get out of the loop function.
|
|
|
|
if (GDBStub::GetCpuHaltFlag()) {
|
|
|
|
if (GDBStub::GetCpuStepFlag()) {
|
|
|
|
tight_loop = false;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:37:29 -04:00
|
|
|
auto& core_timing = system.CoreTiming();
|
|
|
|
core_timing.ResetRun();
|
|
|
|
bool keep_running{};
|
|
|
|
do {
|
|
|
|
keep_running = false;
|
|
|
|
for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
|
|
|
|
core_timing.SwitchContext(active_core);
|
2019-10-11 14:44:14 -04:00
|
|
|
if (core_timing.CanCurrentContextRun()) {
|
2020-01-26 13:07:22 -05:00
|
|
|
core_managers[active_core]->RunLoop(tight_loop);
|
2019-09-09 21:37:29 -04:00
|
|
|
}
|
2019-10-11 14:44:14 -04:00
|
|
|
keep_running |= core_timing.CanCurrentContextRun();
|
2018-11-22 01:27:23 -05:00
|
|
|
}
|
2019-09-09 21:37:29 -04:00
|
|
|
} while (keep_running);
|
2018-11-22 01:27:23 -05:00
|
|
|
|
|
|
|
if (GDBStub::IsServerEnabled()) {
|
|
|
|
GDBStub::SetCpuStepFlag(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Core
|