cpu_manager.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/arm/exclusive_monitor.h"
  5. #include "core/core.h"
  6. #include "core/core_manager.h"
  7. #include "core/core_timing.h"
  8. #include "core/cpu_manager.h"
  9. #include "core/gdbstub/gdbstub.h"
  10. namespace Core {
  11. CpuManager::CpuManager(System& system) : system{system} {}
  12. CpuManager::~CpuManager() = default;
  13. void CpuManager::Initialize() {
  14. for (std::size_t index = 0; index < core_managers.size(); ++index) {
  15. core_managers[index] = std::make_unique<CoreManager>(system, index);
  16. }
  17. }
  18. void CpuManager::Shutdown() {
  19. for (auto& cpu_core : core_managers) {
  20. cpu_core.reset();
  21. }
  22. }
  23. CoreManager& CpuManager::GetCoreManager(std::size_t index) {
  24. return *core_managers.at(index);
  25. }
  26. const CoreManager& CpuManager::GetCoreManager(std::size_t index) const {
  27. return *core_managers.at(index);
  28. }
  29. CoreManager& CpuManager::GetCurrentCoreManager() {
  30. // Otherwise, use single-threaded mode active_core variable
  31. return *core_managers[active_core];
  32. }
  33. const CoreManager& CpuManager::GetCurrentCoreManager() const {
  34. // Otherwise, use single-threaded mode active_core variable
  35. return *core_managers[active_core];
  36. }
  37. void CpuManager::RunLoop(bool tight_loop) {
  38. if (GDBStub::IsServerEnabled()) {
  39. GDBStub::HandlePacket();
  40. // If the loop is halted and we want to step, use a tiny (1) number of instructions to
  41. // execute. Otherwise, get out of the loop function.
  42. if (GDBStub::GetCpuHaltFlag()) {
  43. if (GDBStub::GetCpuStepFlag()) {
  44. tight_loop = false;
  45. } else {
  46. return;
  47. }
  48. }
  49. }
  50. auto& core_timing = system.CoreTiming();
  51. core_timing.ResetRun();
  52. bool keep_running{};
  53. do {
  54. keep_running = false;
  55. for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
  56. core_timing.SwitchContext(active_core);
  57. if (core_timing.CanCurrentContextRun()) {
  58. core_managers[active_core]->RunLoop(tight_loop);
  59. }
  60. keep_running |= core_timing.CanCurrentContextRun();
  61. }
  62. } while (keep_running);
  63. if (GDBStub::IsServerEnabled()) {
  64. GDBStub::SetCpuStepFlag(false);
  65. }
  66. }
  67. } // namespace Core