diff --git a/src/dynarmic/src/dynarmic/CMakeLists.txt b/src/dynarmic/src/dynarmic/CMakeLists.txt index 852b417616..2e3e7eb55e 100644 --- a/src/dynarmic/src/dynarmic/CMakeLists.txt +++ b/src/dynarmic/src/dynarmic/CMakeLists.txt @@ -278,6 +278,7 @@ if ("riscv64" IN_LIST ARCHITECTURE) backend/riscv64/emit_riscv64_vector.cpp backend/riscv64/emit_riscv64.cpp backend/riscv64/emit_riscv64.h + backend/riscv64/exclusive_monitor.cpp backend/riscv64/reg_alloc.cpp backend/riscv64/reg_alloc.h backend/riscv64/stack_layout.h @@ -288,6 +289,8 @@ if ("riscv64" IN_LIST ARCHITECTURE) backend/riscv64/a32_interface.cpp backend/riscv64/a64_interface.cpp backend/riscv64/code_block.h + + common/spin_lock_riscv64.cpp ) message(WARNING "TODO: Incomplete frontend for this host architecture") endif() diff --git a/src/dynarmic/src/dynarmic/backend/riscv64/exclusive_monitor.cpp b/src/dynarmic/src/dynarmic/backend/riscv64/exclusive_monitor.cpp new file mode 100644 index 0000000000..3aae1f1eb5 --- /dev/null +++ b/src/dynarmic/src/dynarmic/backend/riscv64/exclusive_monitor.cpp @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "dynarmic/interface/exclusive_monitor.h" + +#include + +namespace Dynarmic { + +ExclusiveMonitor::ExclusiveMonitor(std::size_t processor_count) + : exclusive_addresses(processor_count, INVALID_EXCLUSIVE_ADDRESS), exclusive_values(processor_count) {} + +size_t ExclusiveMonitor::GetProcessorCount() const { + return exclusive_addresses.size(); +} + +void ExclusiveMonitor::Lock() { + lock.Lock(); +} + +void ExclusiveMonitor::Unlock() { + lock.Unlock(); +} + +bool ExclusiveMonitor::CheckAndClear(size_t processor_id, VAddr address) { + const VAddr masked_address = address & RESERVATION_GRANULE_MASK; + + Lock(); + if (exclusive_addresses[processor_id] != masked_address) { + Unlock(); + return false; + } + + for (VAddr& other_address : exclusive_addresses) { + if (other_address == masked_address) { + other_address = INVALID_EXCLUSIVE_ADDRESS; + } + } + return true; +} + +void ExclusiveMonitor::Clear() { + Lock(); + std::fill(exclusive_addresses.begin(), exclusive_addresses.end(), INVALID_EXCLUSIVE_ADDRESS); + Unlock(); +} + +void ExclusiveMonitor::ClearProcessor(size_t processor_id) { + Lock(); + exclusive_addresses[processor_id] = INVALID_EXCLUSIVE_ADDRESS; + Unlock(); +} + +} // namespace Dynarmic diff --git a/src/dynarmic/src/dynarmic/common/spin_lock_riscv64.cpp b/src/dynarmic/src/dynarmic/common/spin_lock_riscv64.cpp new file mode 100644 index 0000000000..c9e21d0b14 --- /dev/null +++ b/src/dynarmic/src/dynarmic/common/spin_lock_riscv64.cpp @@ -0,0 +1,13 @@ +#include + +#include "dynarmic/common/spin_lock.h" + +namespace Dynarmic { + +void SpinLock::Lock() noexcept { +} + +void SpinLock::Unlock() noexcept { +} + +} // namespace Dynarmic