Browse Source
spinlocks, annoyances with organistaion
spinlocks, annoyances with organistaion
Signed-off-by: lizzie <lizzie@eden-emu.dev>dynarmic-ppc64
No known key found for this signature in database
GPG Key ID: 287378CADCAB13
16 changed files with 356 additions and 135 deletions
-
107externals/powah/data2code.c
-
14externals/powah/powah_emit.hpp
-
20externals/powah/powah_gen_base.hpp
-
4src/dynarmic/src/dynarmic/CMakeLists.txt
-
4src/dynarmic/src/dynarmic/backend/ppc64/a32_core.h
-
16src/dynarmic/src/dynarmic/backend/ppc64/a32_interface.cpp
-
15src/dynarmic/src/dynarmic/backend/ppc64/a64_core.h
-
84src/dynarmic/src/dynarmic/backend/ppc64/a64_interface.cpp
-
8src/dynarmic/src/dynarmic/backend/ppc64/abi.h
-
2src/dynarmic/src/dynarmic/backend/ppc64/emit_ppc64_data_processing.cpp
-
50src/dynarmic/src/dynarmic/backend/ppc64/exclusive_monitor.cpp
-
26src/dynarmic/src/dynarmic/backend/ppc64/hostloc.h
-
43src/dynarmic/src/dynarmic/backend/ppc64/reg_alloc.cpp
-
14src/dynarmic/src/dynarmic/backend/ppc64/reg_alloc.h
-
71src/dynarmic/src/dynarmic/common/spin_lock_ppc64.cpp
-
13src/dynarmic/src/dynarmic/common/spin_lock_ppc64.h
@ -0,0 +1,50 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|||
|
|||
#include "dynarmic/interface/exclusive_monitor.h"
|
|||
#include <algorithm>
|
|||
#include "dynarmic/common/assert.h"
|
|||
|
|||
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(std::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
|
|||
@ -0,0 +1,26 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project |
|||
// SPDX-License-Identifier: GPL-3.0-or-later |
|||
|
|||
#pragma once |
|||
|
|||
#include "dynarmic/common/common_types.h" |
|||
|
|||
namespace Dynarmic::Backend::PPC64 { |
|||
|
|||
enum class HostLoc : uint8_t { |
|||
R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, |
|||
R10, R11, R12, R13, R14, R15, R16, R17, R18, R19, |
|||
R20, R21, R22, R23, R24, R25, R26, R27, R28, R29, |
|||
R30, R31, |
|||
FR0, FR1, FR2, FR3, FR4, FR5, FR6, FR7, FR8, FR9, |
|||
FR10, FR11, FR12, FR13, FR14, FR15, FR16, FR17, FR18, FR19, |
|||
FR20, FR21, FR22, FR23, FR24, FR25, FR26, FR27, FR28, FR29, |
|||
FR30, FR31, |
|||
VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9, |
|||
VR10, VR11, VR12, VR13, VR14, VR15, VR16, VR17, VR18, VR19, |
|||
VR20, VR21, VR22, VR23, VR24, VR25, VR26, VR27, VR28, VR29, |
|||
VR30, VR31, |
|||
FirstSpill, |
|||
}; |
|||
|
|||
} // namespace Dynarmic::Backend::PPC64 |
|||
@ -0,0 +1,71 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|||
|
|||
#include <mutex>
|
|||
#include <sys/mman.h>
|
|||
#include <powah_emit.hpp>
|
|||
#include "dynarmic/backend/ppc64/abi.h"
|
|||
#include "dynarmic/backend/ppc64/hostloc.h"
|
|||
#include "dynarmic/common/spin_lock.h"
|
|||
#include "dynarmic/common/assert.h"
|
|||
|
|||
namespace Dynarmic { |
|||
|
|||
/*
|
|||
void acquire(atomic_flag* lock) { |
|||
while(atomic_flag_test_and_set_explicit( lock, memory_order_acquire)) |
|||
; |
|||
} |
|||
*/ |
|||
void EmitSpinLockLock(powah::Context& code, powah::GPR const ptr, powah::GPR const tmp) { |
|||
|
|||
} |
|||
|
|||
/*
|
|||
void release(atomic_flag* lock) { |
|||
atomic_flag_clear_explicit(lock, memory_order_release); |
|||
} |
|||
*/ |
|||
void EmitSpinLockUnlock(powah::Context& code, powah::GPR const ptr, powah::GPR const tmp) { |
|||
|
|||
} |
|||
|
|||
namespace { |
|||
|
|||
struct SpinLockImpl { |
|||
void Initialize(); |
|||
powah::Context code; |
|||
void* page = nullptr; |
|||
void (*lock)(volatile int*); |
|||
void (*unlock)(volatile int*); |
|||
}; |
|||
|
|||
std::once_flag flag; |
|||
SpinLockImpl impl; |
|||
|
|||
void SpinLockImpl::Initialize() { |
|||
page = mmap(nullptr, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); |
|||
ASSERT(page != nullptr); |
|||
code = powah::Context(page, 4096); |
|||
lock = reinterpret_cast<void (*)(volatile int*)>(code.base); |
|||
EmitSpinLockLock(code, Backend::PPC64::ABI_PARAM1, Backend::PPC64::ABI_PARAM2); |
|||
code.BLR(); |
|||
unlock = reinterpret_cast<void (*)(volatile int*)>(code.base); |
|||
EmitSpinLockUnlock(code, Backend::PPC64::ABI_PARAM1, Backend::PPC64::ABI_PARAM2); |
|||
code.BLR(); |
|||
// TODO: free the page, rework the stupid spinlock API
|
|||
} |
|||
|
|||
} // namespace
|
|||
|
|||
void SpinLock::Lock() noexcept { |
|||
std::call_once(flag, &SpinLockImpl::Initialize, impl); |
|||
impl.lock(&storage); |
|||
} |
|||
|
|||
void SpinLock::Unlock() noexcept { |
|||
std::call_once(flag, &SpinLockImpl::Initialize, impl); |
|||
impl.unlock(&storage); |
|||
} |
|||
|
|||
} // namespace Dynarmic
|
|||
@ -0,0 +1,13 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project |
|||
// SPDX-License-Identifier: GPL-3.0-or-later |
|||
|
|||
#pragma once |
|||
|
|||
#include <powah_emit.hpp> |
|||
|
|||
namespace Dynarmic { |
|||
|
|||
void EmitSpinLockLock(powah::Context& code, powah::GPR const ptr, powah::GPR const tmp); |
|||
void EmitSpinLockUnlock(powah::Context& code, powah::GPR const ptr, powah::GPR const tmp); |
|||
|
|||
} // namespace Dynarmic |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue