physical_core.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/arm/dynarmic/arm_dynarmic_32.h"
  4. #include "core/arm/dynarmic/arm_dynarmic_64.h"
  5. #include "core/core.h"
  6. #include "core/hle/kernel/k_scheduler.h"
  7. #include "core/hle/kernel/kernel.h"
  8. #include "core/hle/kernel/physical_core.h"
  9. namespace Kernel {
  10. PhysicalCore::PhysicalCore(std::size_t core_index, Core::System& system, KScheduler& scheduler)
  11. : m_core_index{core_index}, m_system{system}, m_scheduler{scheduler} {
  12. #if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64)
  13. // TODO(bunnei): Initialization relies on a core being available. We may later replace this with
  14. // a 32-bit instance of Dynarmic. This should be abstracted out to a CPU manager.
  15. auto& kernel = system.Kernel();
  16. m_arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
  17. system, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), m_core_index);
  18. #else
  19. #error Platform not supported yet.
  20. #endif
  21. }
  22. PhysicalCore::~PhysicalCore() = default;
  23. void PhysicalCore::Initialize(bool is_64_bit) {
  24. #if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64)
  25. auto& kernel = m_system.Kernel();
  26. if (!is_64_bit) {
  27. // We already initialized a 64-bit core, replace with a 32-bit one.
  28. m_arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
  29. m_system, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), m_core_index);
  30. }
  31. #else
  32. #error Platform not supported yet.
  33. #endif
  34. }
  35. void PhysicalCore::Run() {
  36. m_arm_interface->Run();
  37. m_arm_interface->ClearExclusiveState();
  38. }
  39. void PhysicalCore::Idle() {
  40. std::unique_lock lk{m_guard};
  41. m_on_interrupt.wait(lk, [this] { return m_is_interrupted; });
  42. }
  43. bool PhysicalCore::IsInterrupted() const {
  44. return m_is_interrupted;
  45. }
  46. void PhysicalCore::Interrupt() {
  47. std::unique_lock lk{m_guard};
  48. m_is_interrupted = true;
  49. m_arm_interface->SignalInterrupt();
  50. m_on_interrupt.notify_all();
  51. }
  52. void PhysicalCore::ClearInterrupt() {
  53. std::unique_lock lk{m_guard};
  54. m_is_interrupted = false;
  55. m_arm_interface->ClearInterrupt();
  56. }
  57. } // namespace Kernel