physical_core.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "common/logging/log.h"
  6. #include "common/spin_lock.h"
  7. #include "core/arm/arm_interface.h"
  8. #ifdef ARCHITECTURE_x86_64
  9. #include "core/arm/dynarmic/arm_dynarmic_32.h"
  10. #include "core/arm/dynarmic/arm_dynarmic_64.h"
  11. #endif
  12. #include "core/arm/cpu_interrupt_handler.h"
  13. #include "core/arm/exclusive_monitor.h"
  14. #include "core/arm/unicorn/arm_unicorn.h"
  15. #include "core/core.h"
  16. #include "core/hle/kernel/physical_core.h"
  17. #include "core/hle/kernel/scheduler.h"
  18. #include "core/hle/kernel/thread.h"
  19. namespace Kernel {
  20. PhysicalCore::PhysicalCore(Core::System& system, std::size_t id,
  21. Core::ExclusiveMonitor& exclusive_monitor)
  22. : interrupt_handler{}, core_index{id} {
  23. #ifdef ARCHITECTURE_x86_64
  24. arm_interface_32 = std::make_unique<Core::ARM_Dynarmic_32>(system, interrupt_handler,
  25. exclusive_monitor, core_index);
  26. arm_interface_64 = std::make_unique<Core::ARM_Dynarmic_64>(system, interrupt_handler,
  27. exclusive_monitor, core_index);
  28. #else
  29. using Core::ARM_Unicorn;
  30. arm_interface_32 =
  31. std::make_unique<ARM_Unicorn>(system, interrupt_handler, ARM_Unicorn::Arch::AArch32);
  32. arm_interface_64 =
  33. std::make_unique<ARM_Unicorn>(system, interrupt_handler, ARM_Unicorn::Arch::AArch64);
  34. LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
  35. #endif
  36. scheduler = std::make_unique<Kernel::Scheduler>(system, core_index);
  37. guard = std::make_unique<Common::SpinLock>();
  38. }
  39. PhysicalCore::~PhysicalCore() = default;
  40. void PhysicalCore::Run() {
  41. arm_interface->Run();
  42. arm_interface->ClearExclusiveState();
  43. }
  44. void PhysicalCore::Step() {
  45. arm_interface->Step();
  46. }
  47. void PhysicalCore::Idle() {
  48. interrupt_handler.AwaitInterrupt();
  49. }
  50. void PhysicalCore::Stop() {
  51. arm_interface->PrepareReschedule();
  52. }
  53. void PhysicalCore::Shutdown() {
  54. scheduler->Shutdown();
  55. }
  56. void PhysicalCore::SetIs64Bit(bool is_64_bit) {
  57. if (is_64_bit) {
  58. arm_interface = arm_interface_64.get();
  59. } else {
  60. arm_interface = arm_interface_32.get();
  61. }
  62. }
  63. void PhysicalCore::Interrupt() {
  64. guard->lock();
  65. interrupt_handler.SetInterrupt(true);
  66. guard->unlock();
  67. }
  68. void PhysicalCore::ClearInterrupt() {
  69. guard->lock();
  70. interrupt_handler.SetInterrupt(false);
  71. guard->unlock();
  72. }
  73. } // namespace Kernel