2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-01-24 20:38:20 +01:00
|
|
|
|
2020-11-13 20:11:12 +01:00
|
|
|
#include "core/arm/dynarmic/arm_dynarmic_32.h"
|
|
|
|
#include "core/arm/dynarmic/arm_dynarmic_64.h"
|
2020-01-25 23:55:32 +01:00
|
|
|
#include "core/core.h"
|
2020-12-03 03:08:35 +01:00
|
|
|
#include "core/hle/kernel/k_scheduler.h"
|
2020-11-13 20:11:12 +01:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
2020-01-25 23:55:32 +01:00
|
|
|
#include "core/hle/kernel/physical_core.h"
|
|
|
|
|
2020-01-24 20:38:20 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2022-07-08 02:06:46 +02:00
|
|
|
PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_)
|
|
|
|
: core_index{core_index_}, system{system_}, scheduler{scheduler_} {
|
2022-11-06 22:45:36 +01:00
|
|
|
#if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64)
|
2022-01-09 11:17:17 +01:00
|
|
|
// TODO(bunnei): Initialization relies on a core being available. We may later replace this with
|
|
|
|
// a 32-bit instance of Dynarmic. This should be abstracted out to a CPU manager.
|
|
|
|
auto& kernel = system.Kernel();
|
|
|
|
arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
|
2022-07-08 02:06:46 +02:00
|
|
|
system, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
|
2022-01-09 11:17:17 +01:00
|
|
|
#else
|
|
|
|
#error Platform not supported yet.
|
|
|
|
#endif
|
|
|
|
}
|
2020-01-24 20:38:20 +01:00
|
|
|
|
2020-01-26 21:14:18 +01:00
|
|
|
PhysicalCore::~PhysicalCore() = default;
|
|
|
|
|
2020-11-13 20:11:12 +01:00
|
|
|
void PhysicalCore::Initialize([[maybe_unused]] bool is_64_bit) {
|
2022-11-06 22:45:36 +01:00
|
|
|
#if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64)
|
2020-11-13 20:11:12 +01:00
|
|
|
auto& kernel = system.Kernel();
|
2022-01-09 11:17:17 +01:00
|
|
|
if (!is_64_bit) {
|
|
|
|
// We already initialized a 64-bit core, replace with a 32-bit one.
|
2020-11-13 20:11:12 +01:00
|
|
|
arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
|
2022-07-08 02:06:46 +02:00
|
|
|
system, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
|
2020-11-13 20:11:12 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#error Platform not supported yet.
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicalCore::Run() {
|
|
|
|
arm_interface->Run();
|
2022-07-06 05:27:25 +02:00
|
|
|
arm_interface->ClearExclusiveState();
|
2020-11-13 20:11:12 +01:00
|
|
|
}
|
|
|
|
|
2020-02-25 03:04:12 +01:00
|
|
|
void PhysicalCore::Idle() {
|
2022-07-08 02:06:46 +02:00
|
|
|
std::unique_lock lk{guard};
|
|
|
|
on_interrupt.wait(lk, [this] { return is_interrupted; });
|
2020-02-25 03:04:12 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 00:20:06 +02:00
|
|
|
bool PhysicalCore::IsInterrupted() const {
|
2022-07-08 02:06:46 +02:00
|
|
|
return is_interrupted;
|
2020-06-28 00:20:06 +02:00
|
|
|
}
|
|
|
|
|
2020-02-25 03:04:12 +01:00
|
|
|
void PhysicalCore::Interrupt() {
|
2022-07-08 02:06:46 +02:00
|
|
|
std::unique_lock lk{guard};
|
|
|
|
is_interrupted = true;
|
2022-04-03 17:29:05 +02:00
|
|
|
arm_interface->SignalInterrupt();
|
2022-07-08 02:06:46 +02:00
|
|
|
on_interrupt.notify_all();
|
2020-02-25 03:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicalCore::ClearInterrupt() {
|
2022-07-08 02:06:46 +02:00
|
|
|
std::unique_lock lk{guard};
|
|
|
|
is_interrupted = false;
|
|
|
|
arm_interface->ClearInterrupt();
|
|
|
|
on_interrupt.notify_all();
|
2020-02-25 03:04:12 +01:00
|
|
|
}
|
|
|
|
|
2020-01-24 20:38:20 +01:00
|
|
|
} // namespace Kernel
|