2020-01-24 20:38:20 +01:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-02-25 03:04:12 +01:00
|
|
|
#include "common/spin_lock.h"
|
|
|
|
#include "core/arm/cpu_interrupt_handler.h"
|
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-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"
|
|
|
|
#include "core/hle/kernel/scheduler.h"
|
|
|
|
|
2020-01-24 20:38:20 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-11-13 20:11:12 +01:00
|
|
|
PhysicalCore::PhysicalCore(std::size_t core_index, Core::System& system,
|
|
|
|
Kernel::Scheduler& scheduler, Core::CPUInterrupts& interrupts)
|
|
|
|
: core_index{core_index}, system{system}, scheduler{scheduler},
|
|
|
|
interrupts{interrupts}, guard{std::make_unique<Common::SpinLock>()} {}
|
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) {
|
|
|
|
#ifdef ARCHITECTURE_x86_64
|
|
|
|
auto& kernel = system.Kernel();
|
|
|
|
if (is_64_bit) {
|
|
|
|
arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
|
|
|
|
system, interrupts, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
|
|
|
|
} else {
|
|
|
|
arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
|
|
|
|
system, interrupts, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#error Platform not supported yet.
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicalCore::Run() {
|
|
|
|
arm_interface->Run();
|
2020-12-02 05:53:51 +01:00
|
|
|
arm_interface->ClearExclusiveState();
|
2020-11-13 20:11:12 +01:00
|
|
|
}
|
|
|
|
|
2020-02-25 03:04:12 +01:00
|
|
|
void PhysicalCore::Idle() {
|
2020-11-13 20:11:12 +01:00
|
|
|
interrupts[core_index].AwaitInterrupt();
|
2020-02-25 03:04:12 +01:00
|
|
|
}
|
|
|
|
|
2020-01-25 23:55:32 +01:00
|
|
|
void PhysicalCore::Shutdown() {
|
2020-03-01 17:14:17 +01:00
|
|
|
scheduler.Shutdown();
|
2020-03-02 05:46:10 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 00:20:06 +02:00
|
|
|
bool PhysicalCore::IsInterrupted() const {
|
2020-11-13 20:11:12 +01:00
|
|
|
return interrupts[core_index].IsInterrupted();
|
2020-06-28 00:20:06 +02:00
|
|
|
}
|
|
|
|
|
2020-02-25 03:04:12 +01:00
|
|
|
void PhysicalCore::Interrupt() {
|
|
|
|
guard->lock();
|
2020-11-13 20:11:12 +01:00
|
|
|
interrupts[core_index].SetInterrupt(true);
|
2020-02-25 03:04:12 +01:00
|
|
|
guard->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicalCore::ClearInterrupt() {
|
|
|
|
guard->lock();
|
2020-11-13 20:11:12 +01:00
|
|
|
interrupts[core_index].SetInterrupt(false);
|
2020-02-25 03:04:12 +01:00
|
|
|
guard->unlock();
|
|
|
|
}
|
|
|
|
|
2020-01-24 20:38:20 +01:00
|
|
|
} // namespace Kernel
|