physical_core.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/spin_lock.h"
  5. #include "core/arm/cpu_interrupt_handler.h"
  6. #include "core/arm/dynarmic/arm_dynarmic_32.h"
  7. #include "core/arm/dynarmic/arm_dynarmic_64.h"
  8. #include "core/core.h"
  9. #include "core/hle/kernel/k_scheduler.h"
  10. #include "core/hle/kernel/kernel.h"
  11. #include "core/hle/kernel/physical_core.h"
  12. namespace Kernel {
  13. PhysicalCore::PhysicalCore(std::size_t core_index, Core::System& system,
  14. Kernel::KScheduler& scheduler, Core::CPUInterrupts& interrupts)
  15. : core_index{core_index}, system{system}, scheduler{scheduler},
  16. interrupts{interrupts}, guard{std::make_unique<Common::SpinLock>()} {}
  17. PhysicalCore::~PhysicalCore() = default;
  18. void PhysicalCore::Initialize([[maybe_unused]] bool is_64_bit) {
  19. #ifdef ARCHITECTURE_x86_64
  20. auto& kernel = system.Kernel();
  21. if (is_64_bit) {
  22. arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
  23. system, interrupts, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
  24. } else {
  25. arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
  26. system, interrupts, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
  27. }
  28. #else
  29. #error Platform not supported yet.
  30. #endif
  31. }
  32. void PhysicalCore::Run() {
  33. arm_interface->Run();
  34. }
  35. void PhysicalCore::Idle() {
  36. interrupts[core_index].AwaitInterrupt();
  37. }
  38. bool PhysicalCore::IsInterrupted() const {
  39. return interrupts[core_index].IsInterrupted();
  40. }
  41. void PhysicalCore::Interrupt() {
  42. guard->lock();
  43. interrupts[core_index].SetInterrupt(true);
  44. guard->unlock();
  45. }
  46. void PhysicalCore::ClearInterrupt() {
  47. guard->lock();
  48. interrupts[core_index].SetInterrupt(false);
  49. guard->unlock();
  50. }
  51. } // namespace Kernel