yuzu/src/core/arm/dynarmic/dynarmic_cp15.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

162 lines
5.7 KiB
C++
Raw Normal View History

chore: make yuzu REUSE compliant [REUSE] is a specification that aims at making file copyright information consistent, so that it can be both human and machine readable. It basically requires that all files have a header containing copyright and licensing information. When this isn't possible, like when dealing with binary assets, generated files or embedded third-party dependencies, it is permitted to insert copyright information in the `.reuse/dep5` file. Oh, and it also requires that all the licenses used in the project are present in the `LICENSES` folder, that's why the diff is so huge. This can be done automatically with `reuse download --all`. The `reuse` tool also contains a handy subcommand that analyzes the project and tells whether or not the project is (still) compliant, `reuse lint`. Following REUSE has a few advantages over the current approach: - Copyright information is easy to access for users / downstream - Files like `dist/license.md` do not need to exist anymore, as `.reuse/dep5` is used instead - `reuse lint` makes it easy to ensure that copyright information of files like binary assets / images is always accurate and up to date To add copyright information of files that didn't have it I looked up who committed what and when, for each file. As yuzu contributors do not have to sign a CLA or similar I couldn't assume that copyright ownership was of the "yuzu Emulator Project", so I used the name and/or email of the commit author instead. [REUSE]: https://reuse.software Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-15 02:06:02 +02:00
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2020-03-01 06:40:25 +01:00
2020-06-17 17:32:08 +02:00
#include <fmt/format.h>
#include "common/logging/log.h"
#include "core/arm/dynarmic/arm_dynarmic_32.h"
#include "core/arm/dynarmic/dynarmic_cp15.h"
2020-06-17 17:32:21 +02:00
#include "core/core.h"
#include "core/core_timing.h"
2020-03-01 06:40:25 +01:00
#ifdef _MSC_VER
#include <intrin.h>
#endif
2020-03-01 06:40:25 +01:00
using Callback = Dynarmic::A32::Coprocessor::Callback;
using CallbackOrAccessOneWord = Dynarmic::A32::Coprocessor::CallbackOrAccessOneWord;
using CallbackOrAccessTwoWords = Dynarmic::A32::Coprocessor::CallbackOrAccessTwoWords;
2020-06-17 17:32:08 +02:00
template <>
struct fmt::formatter<Dynarmic::A32::CoprocReg> {
constexpr auto parse(format_parse_context& ctx) {
return ctx.begin();
}
template <typename FormatContext>
auto format(const Dynarmic::A32::CoprocReg& reg, FormatContext& ctx) {
return fmt::format_to(ctx.out(), "cp{}", static_cast<size_t>(reg));
2020-06-17 17:32:08 +02:00
}
};
namespace Core {
static u32 dummy_value;
2020-03-01 06:40:25 +01:00
std::optional<Callback> DynarmicCP15::CompileInternalOperation(bool two, unsigned opc1,
CoprocReg CRd, CoprocReg CRn,
CoprocReg CRm, unsigned opc2) {
2020-06-17 17:32:08 +02:00
LOG_CRITICAL(Core_ARM, "CP15: cdp{} p15, {}, {}, {}, {}, {}", two ? "2" : "", opc1, CRd, CRn,
CRm, opc2);
return std::nullopt;
2020-03-01 06:40:25 +01:00
}
CallbackOrAccessOneWord DynarmicCP15::CompileSendOneWord(bool two, unsigned opc1, CoprocReg CRn,
CoprocReg CRm, unsigned opc2) {
if (!two && CRn == CoprocReg::C7 && opc1 == 0 && CRm == CoprocReg::C5 && opc2 == 4) {
2020-06-17 17:32:08 +02:00
// CP15_FLUSH_PREFETCH_BUFFER
2020-03-01 06:40:25 +01:00
// This is a dummy write, we ignore the value written here.
2020-06-17 17:32:08 +02:00
return &dummy_value;
2020-03-01 06:40:25 +01:00
}
if (!two && CRn == CoprocReg::C7 && opc1 == 0 && CRm == CoprocReg::C10) {
switch (opc2) {
case 4:
2020-06-17 17:32:08 +02:00
// CP15_DATA_SYNC_BARRIER
return Callback{
2022-11-06 22:45:36 +01:00
[](void*, std::uint32_t, std::uint32_t) -> std::uint64_t {
#if defined(_MSC_VER) && defined(ARCHITECTURE_x86_64)
_mm_mfence();
_mm_lfence();
2022-11-06 22:45:36 +01:00
#elif defined(ARCHITECTURE_x86_64)
asm volatile("mfence\n\tlfence\n\t" : : : "memory");
2022-11-06 22:45:36 +01:00
#elif defined(ARCHITECTURE_arm64)
asm volatile("dsb sy\n\t" : : : "memory");
#else
#error Unsupported architecture
#endif
return 0;
},
std::nullopt,
};
2020-03-01 06:40:25 +01:00
case 5:
2020-06-17 17:32:08 +02:00
// CP15_DATA_MEMORY_BARRIER
return Callback{
2022-11-06 22:45:36 +01:00
[](void*, std::uint32_t, std::uint32_t) -> std::uint64_t {
#if defined(_MSC_VER) && defined(ARCHITECTURE_x86_64)
_mm_mfence();
2022-11-06 22:45:36 +01:00
#elif defined(ARCHITECTURE_x86_64)
asm volatile("mfence\n\t" : : : "memory");
2022-11-06 22:45:36 +01:00
#elif defined(ARCHITECTURE_arm64)
asm volatile("dmb sy\n\t" : : : "memory");
#else
#error Unsupported architecture
#endif
return 0;
},
std::nullopt,
};
2020-03-01 06:40:25 +01:00
}
}
if (!two && CRn == CoprocReg::C13 && opc1 == 0 && CRm == CoprocReg::C0 && opc2 == 2) {
2020-06-17 17:32:08 +02:00
// CP15_THREAD_UPRW
return &uprw;
2020-03-01 06:40:25 +01:00
}
2020-06-17 17:32:08 +02:00
LOG_CRITICAL(Core_ARM, "CP15: mcr{} p15, {}, <Rt>, {}, {}, {}", two ? "2" : "", opc1, CRn, CRm,
opc2);
2020-03-01 06:40:25 +01:00
return {};
}
CallbackOrAccessTwoWords DynarmicCP15::CompileSendTwoWords(bool two, unsigned opc, CoprocReg CRm) {
2020-06-17 17:32:08 +02:00
LOG_CRITICAL(Core_ARM, "CP15: mcrr{} p15, {}, <Rt>, <Rt2>, {}", two ? "2" : "", opc, CRm);
2020-03-01 06:40:25 +01:00
return {};
}
CallbackOrAccessOneWord DynarmicCP15::CompileGetOneWord(bool two, unsigned opc1, CoprocReg CRn,
CoprocReg CRm, unsigned opc2) {
if (!two && CRn == CoprocReg::C13 && opc1 == 0 && CRm == CoprocReg::C0) {
switch (opc2) {
case 2:
2020-06-17 17:32:08 +02:00
// CP15_THREAD_UPRW
return &uprw;
2020-03-01 06:40:25 +01:00
case 3:
2020-06-17 17:32:08 +02:00
// CP15_THREAD_URO
return &uro;
2020-03-01 06:40:25 +01:00
}
}
2020-06-17 17:32:08 +02:00
LOG_CRITICAL(Core_ARM, "CP15: mrc{} p15, {}, <Rt>, {}, {}, {}", two ? "2" : "", opc1, CRn, CRm,
opc2);
2020-03-01 06:40:25 +01:00
return {};
}
CallbackOrAccessTwoWords DynarmicCP15::CompileGetTwoWords(bool two, unsigned opc, CoprocReg CRm) {
2020-06-17 17:32:21 +02:00
if (!two && opc == 0 && CRm == CoprocReg::C14) {
// CNTPCT
2022-11-06 22:45:36 +01:00
const auto callback = [](void* arg, u32, u32) -> u64 {
const auto& parent_arg = *static_cast<ArmDynarmic32*>(arg);
return parent_arg.m_system.CoreTiming().GetClockTicks();
};
return Callback{callback, &parent};
2020-06-17 17:32:21 +02:00
}
2020-06-17 17:32:08 +02:00
LOG_CRITICAL(Core_ARM, "CP15: mrrc{} p15, {}, <Rt>, <Rt2>, {}", two ? "2" : "", opc, CRm);
2020-03-01 06:40:25 +01:00
return {};
}
std::optional<Callback> DynarmicCP15::CompileLoadWords(bool two, bool long_transfer, CoprocReg CRd,
std::optional<u8> option) {
2020-06-17 17:32:08 +02:00
if (option) {
LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...], {}", two ? "2" : "",
long_transfer ? "l" : "", CRd, *option);
} else {
LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...]", two ? "2" : "",
long_transfer ? "l" : "", CRd);
}
return std::nullopt;
2020-03-01 06:40:25 +01:00
}
std::optional<Callback> DynarmicCP15::CompileStoreWords(bool two, bool long_transfer, CoprocReg CRd,
std::optional<u8> option) {
2020-06-17 17:32:08 +02:00
if (option) {
LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...], {}", two ? "2" : "",
long_transfer ? "l" : "", CRd, *option);
} else {
LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...]", two ? "2" : "",
long_transfer ? "l" : "", CRd);
}
return std::nullopt;
2020-03-01 06:40:25 +01:00
}
2020-06-17 17:32:08 +02:00
} // namespace Core