VERY experimental Nintendo Switch 2 emulator
C++
core: hle: kernel: Reflect non-emulated threads as core 3.
bunneicae0bef7ec15
diff --git a/src/core/core.cpp b/src/core/core.cppindex 473ab9f817..aa96f709b5 100644--- a/src/core/core.cpp+++ b/src/core/core.cpp@@ -521,12 +521,6 @@ const ARM_Interface& System::CurrentArmInterface() const {return impl->kernel.CurrentPhysicalCore().ArmInterface();}-std::size_t System::CurrentCoreIndex() const {- std::size_t core = impl->kernel.GetCurrentHostThreadID();- ASSERT(core < Core::Hardware::NUM_CPU_CORES);- return core;-}-Kernel::PhysicalCore& System::CurrentPhysicalCore() {return impl->kernel.CurrentPhysicalCore();}diff --git a/src/core/core.h b/src/core/core.hindex 645e5c241c..52ff90359a 100644--- a/src/core/core.h+++ b/src/core/core.h@@ -208,9 +208,6 @@ public:/// Gets an ARM interface to the CPU core that is currently running[[nodiscard]] const ARM_Interface& CurrentArmInterface() const;- /// Gets the index of the currently running CPU core- [[nodiscard]] std::size_t CurrentCoreIndex() const;-/// Gets the physical core for the CPU core that is currently running[[nodiscard]] Kernel::PhysicalCore& CurrentPhysicalCore();diff --git a/src/core/hle/kernel/k_address_arbiter.cpp b/src/core/hle/kernel/k_address_arbiter.cppindex 1b429bc1e3..6771ef6213 100644--- a/src/core/hle/kernel/k_address_arbiter.cpp+++ b/src/core/hle/kernel/k_address_arbiter.cpp@@ -28,7 +28,7 @@ bool ReadFromUser(Core::System& system, s32* out, VAddr address) {bool DecrementIfLessThan(Core::System& system, s32* out, VAddr address, s32 value) {auto& monitor = system.Monitor();- const auto current_core = system.CurrentCoreIndex();+ const auto current_core = system.Kernel().CurrentPhysicalCoreIndex();// TODO(bunnei): We should disable interrupts here via KScopedInterruptDisable.// TODO(bunnei): We should call CanAccessAtomic(..) here.@@ -58,7 +58,7 @@ bool DecrementIfLessThan(Core::System& system, s32* out, VAddr address, s32 valubool UpdateIfEqual(Core::System& system, s32* out, VAddr address, s32 value, s32 new_value) {auto& monitor = system.Monitor();- const auto current_core = system.CurrentCoreIndex();+ const auto current_core = system.Kernel().CurrentPhysicalCoreIndex();// TODO(bunnei): We should disable interrupts here via KScopedInterruptDisable.// TODO(bunnei): We should call CanAccessAtomic(..) here.diff --git a/src/core/hle/kernel/k_condition_variable.cpp b/src/core/hle/kernel/k_condition_variable.cppindex 7fa9b8cc3e..ed6f328fc2 100644--- a/src/core/hle/kernel/k_condition_variable.cpp+++ b/src/core/hle/kernel/k_condition_variable.cpp@@ -33,7 +33,7 @@ bool WriteToUser(Core::System& system, VAddr address, const u32* p) {bool UpdateLockAtomic(Core::System& system, u32* out, VAddr address, u32 if_zero,u32 new_orr_mask) {auto& monitor = system.Monitor();- const auto current_core = system.CurrentCoreIndex();+ const auto current_core = system.Kernel().CurrentPhysicalCoreIndex();// Load the value from the address.const auto expected = monitor.ExclusiveRead32(current_core, address);diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 45e86a6774..04926a2916 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -845,6 +845,14 @@ const Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) const {return impl->cores[id];}+size_t KernelCore::CurrentPhysicalCoreIndex() const {+ const u32 core_id = impl->GetCurrentHostThreadID();+ if (core_id >= Core::Hardware::NUM_CPU_CORES) {+ return Core::Hardware::NUM_CPU_CORES - 1;+ }+ return core_id;+}+Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() {u32 core_id = impl->GetCurrentHostThreadID();ASSERT(core_id < Core::Hardware::NUM_CPU_CORES);diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.hindex d2ceae9505..3499f8b903 100644--- a/src/core/hle/kernel/kernel.h+++ b/src/core/hle/kernel/kernel.h@@ -148,6 +148,9 @@ public:/// Gets the an instance of the respective physical CPU core.const Kernel::PhysicalCore& PhysicalCore(std::size_t id) const;+ /// Gets the current physical core index for the running host thread.+ std::size_t CurrentPhysicalCoreIndex() const;+/// Gets the sole instance of the Scheduler at the current running core.Kernel::KScheduler* CurrentScheduler();diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cppindex f0cd8471e8..e5e879eb5d 100644--- a/src/core/hle/kernel/svc.cpp+++ b/src/core/hle/kernel/svc.cpp@@ -873,7 +873,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handleconst u64 thread_ticks = current_thread->GetCpuTime();out_ticks = thread_ticks + (core_timing.GetCPUTicks() - prev_ctx_ticks);- } else if (same_thread && info_sub_id == system.CurrentCoreIndex()) {+ } else if (same_thread && info_sub_id == system.Kernel().CurrentPhysicalCoreIndex()) {out_ticks = core_timing.GetCPUTicks() - prev_ctx_ticks;}@@ -887,7 +887,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handlereturn ResultInvalidHandle;}- if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id != system.CurrentCoreIndex()) {+ if (info_sub_id != 0xFFFFFFFFFFFFFFFF &&+ info_sub_id != system.Kernel().CurrentPhysicalCoreIndex()) {LOG_ERROR(Kernel_SVC, "Core is not the current core, got {}", info_sub_id);return ResultInvalidCombination;}