From 45c87c7e6e841c11def43e5ab25160006dab6d77 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 28 Nov 2023 14:30:39 -0500 Subject: core: refactor emulated cpu core activation --- src/core/hle/kernel/k_process.cpp | 40 +++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/core/hle/kernel/k_process.cpp') diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 6c29eb72c..3a2635e1f 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp @@ -13,6 +13,12 @@ #include "core/hle/kernel/k_thread_queue.h" #include "core/hle/kernel/k_worker_task_manager.h" +#include "core/arm/dynarmic/arm_dynarmic_32.h" +#include "core/arm/dynarmic/arm_dynarmic_64.h" +#ifdef HAS_NCE +#include "core/arm/nce/arm_nce.h" +#endif + namespace Kernel { namespace { @@ -957,10 +963,8 @@ Result KProcess::Run(s32 priority, size_t stack_size) { R_TRY(m_handle_table.Add(std::addressof(thread_handle), main_thread)); // Set the thread arguments. - main_thread->GetContext32().cpu_registers[0] = 0; - main_thread->GetContext64().cpu_registers[0] = 0; - main_thread->GetContext32().cpu_registers[1] = thread_handle; - main_thread->GetContext64().cpu_registers[1] = thread_handle; + main_thread->GetContext().r[0] = 0; + main_thread->GetContext().r[1] = thread_handle; // Update our state. this->ChangeState((state == State::Created) ? State::Running : State::RunningAttached); @@ -1199,6 +1203,9 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: m_is_hbl = is_hbl; m_ideal_core_id = metadata.GetMainThreadCore(); + // Set up emulation context. + this->InitializeInterfaces(); + // We succeeded. R_SUCCEED(); } @@ -1227,6 +1234,31 @@ void KProcess::LoadModule(CodeSet code_set, KProcessAddress base_addr) { #endif } +void KProcess::InitializeInterfaces() { + this->GetMemory().SetCurrentPageTable(*this); + +#ifdef HAS_NCE + if (this->Is64Bit() && Settings::IsNceEnabled()) { + for (size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { + m_arm_interfaces[i] = std::make_unique(m_kernel.System(), true, i); + } + } else +#endif + if (this->Is64Bit()) { + for (size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { + m_arm_interfaces[i] = std::make_unique( + m_kernel.System(), m_kernel.IsMulticore(), this, + static_cast(m_kernel.GetExclusiveMonitor()), i); + } + } else { + for (size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { + m_arm_interfaces[i] = std::make_unique( + m_kernel.System(), m_kernel.IsMulticore(), this, + static_cast(m_kernel.GetExclusiveMonitor()), i); + } + } +} + bool KProcess::InsertWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type) { const auto watch{std::find_if(m_watchpoints.begin(), m_watchpoints.end(), [&](const auto& wp) { return wp.type == DebugWatchpointType::None; -- cgit v1.2.3