physical_core.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <condition_variable>
  5. #include <cstddef>
  6. #include <memory>
  7. #include <mutex>
  8. #include "core/arm/arm_interface.h"
  9. namespace Kernel {
  10. class KernelCore;
  11. } // namespace Kernel
  12. namespace Core {
  13. class ExclusiveMonitor;
  14. class System;
  15. } // namespace Core
  16. namespace Kernel {
  17. class PhysicalCore {
  18. public:
  19. PhysicalCore(KernelCore& kernel, std::size_t core_index);
  20. ~PhysicalCore();
  21. YUZU_NON_COPYABLE(PhysicalCore);
  22. YUZU_NON_MOVEABLE(PhysicalCore);
  23. // Execute guest code running on the given thread.
  24. void RunThread(KThread* thread);
  25. // Copy context from thread to current core.
  26. void LoadContext(const KThread* thread);
  27. void LoadSvcArguments(const KProcess& process, std::span<const uint64_t, 8> args);
  28. // Copy context from current core to thread.
  29. void SaveContext(KThread* thread) const;
  30. void SaveSvcArguments(KProcess& process, std::span<uint64_t, 8> args) const;
  31. // Copy floating point status registers to the target thread.
  32. void CloneFpuStatus(KThread* dst) const;
  33. // Log backtrace of current processor state.
  34. void LogBacktrace();
  35. // Wait for an interrupt.
  36. void Idle();
  37. // Interrupt this core.
  38. void Interrupt();
  39. // Clear this core's interrupt.
  40. void ClearInterrupt();
  41. // Check if this core is interrupted.
  42. bool IsInterrupted() const;
  43. std::size_t CoreIndex() const {
  44. return m_core_index;
  45. }
  46. private:
  47. KernelCore& m_kernel;
  48. const std::size_t m_core_index;
  49. std::mutex m_guard;
  50. std::condition_variable m_on_interrupt;
  51. Core::ArmInterface* m_arm_interface{};
  52. KThread* m_current_thread{};
  53. bool m_is_interrupted{};
  54. bool m_is_single_core{};
  55. };
  56. } // namespace Kernel