physical_core.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. : core_index{core_index_}, system{system_}, 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. arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
  17. system, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
  18. #else
  19. #error Platform not supported yet.
  20. #endif
  21. }
  22. PhysicalCore::~PhysicalCore() = default;
  23. void PhysicalCore::Initialize([[maybe_unused]] bool is_64_bit) {
  24. #if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64)
  25. auto& kernel = system.Kernel();
  26. if (!is_64_bit) {
  27. // We already initialized a 64-bit core, replace with a 32-bit one.
  28. arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
  29. system, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
  30. }
  31. #else
  32. #error Platform not supported yet.
  33. #endif
  34. }
  35. void PhysicalCore::Run() {
  36. arm_interface->Run();
  37. arm_interface->ClearExclusiveState();
  38. }
  39. void PhysicalCore::Idle() {
  40. std::unique_lock lk{guard};
  41. on_interrupt.wait(lk, [this] { return is_interrupted; });
  42. }
  43. bool PhysicalCore::IsInterrupted() const {
  44. return is_interrupted;
  45. }
  46. void PhysicalCore::Interrupt() {
  47. std::unique_lock lk{guard};
  48. is_interrupted = true;
  49. arm_interface->SignalInterrupt();
  50. on_interrupt.notify_all();
  51. }
  52. void PhysicalCore::ClearInterrupt() {
  53. std::unique_lock lk{guard};
  54. is_interrupted = false;
  55. arm_interface->ClearInterrupt();
  56. on_interrupt.notify_all();
  57. }
  58. } // namespace Kernel