physical_core.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <cstddef>
  7. #include <memory>
  8. #include "core/arm/arm_interface.h"
  9. namespace Common {
  10. class SpinLock;
  11. }
  12. namespace Kernel {
  13. class Scheduler;
  14. } // namespace Kernel
  15. namespace Core {
  16. class CPUInterruptHandler;
  17. class ExclusiveMonitor;
  18. class System;
  19. } // namespace Core
  20. namespace Kernel {
  21. class PhysicalCore {
  22. public:
  23. PhysicalCore(std::size_t core_index, Core::System& system, Kernel::Scheduler& scheduler,
  24. Core::CPUInterrupts& interrupts);
  25. ~PhysicalCore();
  26. PhysicalCore(const PhysicalCore&) = delete;
  27. PhysicalCore& operator=(const PhysicalCore&) = delete;
  28. PhysicalCore(PhysicalCore&&) = default;
  29. PhysicalCore& operator=(PhysicalCore&&) = delete;
  30. /// Initialize the core for the specified parameters.
  31. void Initialize(bool is_64_bit);
  32. /// Execute current jit state
  33. void Run();
  34. void Idle();
  35. /// Interrupt this physical core.
  36. void Interrupt();
  37. /// Clear this core's interrupt
  38. void ClearInterrupt();
  39. /// Check if this core is interrupted
  40. bool IsInterrupted() const;
  41. // Shutdown this physical core.
  42. void Shutdown();
  43. bool IsInitialized() const {
  44. return arm_interface != nullptr;
  45. }
  46. Core::ARM_Interface& ArmInterface() {
  47. return *arm_interface;
  48. }
  49. const Core::ARM_Interface& ArmInterface() const {
  50. return *arm_interface;
  51. }
  52. bool IsMainCore() const {
  53. return core_index == 0;
  54. }
  55. bool IsSystemCore() const {
  56. return core_index == 3;
  57. }
  58. std::size_t CoreIndex() const {
  59. return core_index;
  60. }
  61. Kernel::Scheduler& Scheduler() {
  62. return scheduler;
  63. }
  64. const Kernel::Scheduler& Scheduler() const {
  65. return scheduler;
  66. }
  67. private:
  68. const std::size_t core_index;
  69. Core::System& system;
  70. Kernel::Scheduler& scheduler;
  71. Core::CPUInterrupts& interrupts;
  72. std::unique_ptr<Common::SpinLock> guard;
  73. std::unique_ptr<Core::ARM_Interface> arm_interface;
  74. };
  75. } // namespace Kernel