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-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 {
|
|
|
|
|
2021-05-16 07:46:30 +02:00
|
|
|
PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& 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-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-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
|