Merge pull request #9964 from liamwhite/typed-address
kernel: use KTypedAddress for addresses
This commit is contained in:
commit
c41a4baf06
101 changed files with 1574 additions and 1102 deletions
|
|
@ -132,6 +132,7 @@ add_library(common STATIC
|
|||
time_zone.h
|
||||
tiny_mt.h
|
||||
tree.h
|
||||
typed_address.h
|
||||
uint128.h
|
||||
unique_function.h
|
||||
uuid.cpp
|
||||
|
|
|
|||
320
src/common/typed_address.h
Normal file
320
src/common/typed_address.h
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <type_traits>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <bool Virtual, typename T>
|
||||
class TypedAddress {
|
||||
public:
|
||||
// Constructors.
|
||||
constexpr inline TypedAddress() : m_address(0) {}
|
||||
constexpr inline TypedAddress(uint64_t a) : m_address(a) {}
|
||||
|
||||
template <typename U>
|
||||
constexpr inline explicit TypedAddress(const U* ptr)
|
||||
: m_address(reinterpret_cast<uint64_t>(ptr)) {}
|
||||
|
||||
// Copy constructor.
|
||||
constexpr inline TypedAddress(const TypedAddress& rhs) = default;
|
||||
|
||||
// Assignment operator.
|
||||
constexpr inline TypedAddress& operator=(const TypedAddress& rhs) = default;
|
||||
|
||||
// Arithmetic operators.
|
||||
template <typename I>
|
||||
constexpr inline TypedAddress operator+(I rhs) const {
|
||||
static_assert(std::is_integral_v<I>);
|
||||
return m_address + rhs;
|
||||
}
|
||||
|
||||
constexpr inline TypedAddress operator+(TypedAddress rhs) const {
|
||||
return m_address + rhs.m_address;
|
||||
}
|
||||
|
||||
constexpr inline TypedAddress operator++() {
|
||||
return ++m_address;
|
||||
}
|
||||
|
||||
constexpr inline TypedAddress operator++(int) {
|
||||
return m_address++;
|
||||
}
|
||||
|
||||
template <typename I>
|
||||
constexpr inline TypedAddress operator-(I rhs) const {
|
||||
static_assert(std::is_integral_v<I>);
|
||||
return m_address - rhs;
|
||||
}
|
||||
|
||||
constexpr inline ptrdiff_t operator-(TypedAddress rhs) const {
|
||||
return m_address - rhs.m_address;
|
||||
}
|
||||
|
||||
constexpr inline TypedAddress operator--() {
|
||||
return --m_address;
|
||||
}
|
||||
|
||||
constexpr inline TypedAddress operator--(int) {
|
||||
return m_address--;
|
||||
}
|
||||
|
||||
template <typename I>
|
||||
constexpr inline TypedAddress operator+=(I rhs) {
|
||||
static_assert(std::is_integral_v<I>);
|
||||
m_address += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename I>
|
||||
constexpr inline TypedAddress operator-=(I rhs) {
|
||||
static_assert(std::is_integral_v<I>);
|
||||
m_address -= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Logical operators.
|
||||
constexpr inline uint64_t operator&(uint64_t mask) const {
|
||||
return m_address & mask;
|
||||
}
|
||||
|
||||
constexpr inline uint64_t operator|(uint64_t mask) const {
|
||||
return m_address | mask;
|
||||
}
|
||||
|
||||
template <typename I>
|
||||
constexpr inline TypedAddress operator|=(I rhs) {
|
||||
static_assert(std::is_integral_v<I>);
|
||||
m_address |= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr inline uint64_t operator<<(int shift) const {
|
||||
return m_address << shift;
|
||||
}
|
||||
|
||||
constexpr inline uint64_t operator>>(int shift) const {
|
||||
return m_address >> shift;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
constexpr inline size_t operator/(U size) const {
|
||||
return m_address / size;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const {
|
||||
return m_address != 0;
|
||||
}
|
||||
|
||||
// constexpr inline uint64_t operator%(U align) const { return m_address % align; }
|
||||
|
||||
// Comparison operators.
|
||||
constexpr bool operator==(const TypedAddress&) const = default;
|
||||
constexpr bool operator!=(const TypedAddress&) const = default;
|
||||
constexpr auto operator<=>(const TypedAddress&) const = default;
|
||||
|
||||
// For convenience, also define comparison operators versus uint64_t.
|
||||
constexpr inline bool operator==(uint64_t rhs) const {
|
||||
return m_address == rhs;
|
||||
}
|
||||
|
||||
constexpr inline bool operator!=(uint64_t rhs) const {
|
||||
return m_address != rhs;
|
||||
}
|
||||
|
||||
// Allow getting the address explicitly, for use in accessors.
|
||||
constexpr inline uint64_t GetValue() const {
|
||||
return m_address;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t m_address{};
|
||||
};
|
||||
|
||||
struct PhysicalAddressTag {};
|
||||
struct VirtualAddressTag {};
|
||||
struct ProcessAddressTag {};
|
||||
|
||||
using PhysicalAddress = TypedAddress<false, PhysicalAddressTag>;
|
||||
using VirtualAddress = TypedAddress<true, VirtualAddressTag>;
|
||||
using ProcessAddress = TypedAddress<true, ProcessAddressTag>;
|
||||
|
||||
// Define accessors.
|
||||
template <typename T>
|
||||
concept IsTypedAddress = std::same_as<T, PhysicalAddress> || std::same_as<T, VirtualAddress> ||
|
||||
std::same_as<T, ProcessAddress>;
|
||||
|
||||
template <typename T>
|
||||
constexpr inline T Null = [] {
|
||||
if constexpr (std::is_same<T, uint64_t>::value) {
|
||||
return 0;
|
||||
} else {
|
||||
static_assert(std::is_same<T, PhysicalAddress>::value ||
|
||||
std::is_same<T, VirtualAddress>::value ||
|
||||
std::is_same<T, ProcessAddress>::value);
|
||||
return T(0);
|
||||
}
|
||||
}();
|
||||
|
||||
// Basic type validations.
|
||||
static_assert(sizeof(PhysicalAddress) == sizeof(uint64_t));
|
||||
static_assert(sizeof(VirtualAddress) == sizeof(uint64_t));
|
||||
static_assert(sizeof(ProcessAddress) == sizeof(uint64_t));
|
||||
|
||||
static_assert(std::is_trivially_copyable_v<PhysicalAddress>);
|
||||
static_assert(std::is_trivially_copyable_v<VirtualAddress>);
|
||||
static_assert(std::is_trivially_copyable_v<ProcessAddress>);
|
||||
|
||||
static_assert(std::is_trivially_copy_constructible_v<PhysicalAddress>);
|
||||
static_assert(std::is_trivially_copy_constructible_v<VirtualAddress>);
|
||||
static_assert(std::is_trivially_copy_constructible_v<ProcessAddress>);
|
||||
|
||||
static_assert(std::is_trivially_move_constructible_v<PhysicalAddress>);
|
||||
static_assert(std::is_trivially_move_constructible_v<VirtualAddress>);
|
||||
static_assert(std::is_trivially_move_constructible_v<ProcessAddress>);
|
||||
|
||||
static_assert(std::is_trivially_copy_assignable_v<PhysicalAddress>);
|
||||
static_assert(std::is_trivially_copy_assignable_v<VirtualAddress>);
|
||||
static_assert(std::is_trivially_copy_assignable_v<ProcessAddress>);
|
||||
|
||||
static_assert(std::is_trivially_move_assignable_v<PhysicalAddress>);
|
||||
static_assert(std::is_trivially_move_assignable_v<VirtualAddress>);
|
||||
static_assert(std::is_trivially_move_assignable_v<ProcessAddress>);
|
||||
|
||||
static_assert(std::is_trivially_destructible_v<PhysicalAddress>);
|
||||
static_assert(std::is_trivially_destructible_v<VirtualAddress>);
|
||||
static_assert(std::is_trivially_destructible_v<ProcessAddress>);
|
||||
|
||||
static_assert(Null<uint64_t> == 0);
|
||||
static_assert(Null<PhysicalAddress> == Null<uint64_t>);
|
||||
static_assert(Null<VirtualAddress> == Null<uint64_t>);
|
||||
static_assert(Null<ProcessAddress> == Null<uint64_t>);
|
||||
|
||||
// Constructor/assignment validations.
|
||||
static_assert([] {
|
||||
const PhysicalAddress a(5);
|
||||
PhysicalAddress b(a);
|
||||
return b;
|
||||
}() == PhysicalAddress(5));
|
||||
static_assert([] {
|
||||
const PhysicalAddress a(5);
|
||||
PhysicalAddress b(10);
|
||||
b = a;
|
||||
return b;
|
||||
}() == PhysicalAddress(5));
|
||||
|
||||
// Arithmetic validations.
|
||||
static_assert(PhysicalAddress(10) + 5 == PhysicalAddress(15));
|
||||
static_assert(PhysicalAddress(10) - 5 == PhysicalAddress(5));
|
||||
static_assert([] {
|
||||
PhysicalAddress v(10);
|
||||
v += 5;
|
||||
return v;
|
||||
}() == PhysicalAddress(15));
|
||||
static_assert([] {
|
||||
PhysicalAddress v(10);
|
||||
v -= 5;
|
||||
return v;
|
||||
}() == PhysicalAddress(5));
|
||||
static_assert(PhysicalAddress(10)++ == PhysicalAddress(10));
|
||||
static_assert(++PhysicalAddress(10) == PhysicalAddress(11));
|
||||
static_assert(PhysicalAddress(10)-- == PhysicalAddress(10));
|
||||
static_assert(--PhysicalAddress(10) == PhysicalAddress(9));
|
||||
|
||||
// Logical validations.
|
||||
static_assert((PhysicalAddress(0b11111111) >> 1) == 0b01111111);
|
||||
static_assert((PhysicalAddress(0b10101010) >> 1) == 0b01010101);
|
||||
static_assert((PhysicalAddress(0b11111111) << 1) == 0b111111110);
|
||||
static_assert((PhysicalAddress(0b01010101) << 1) == 0b10101010);
|
||||
static_assert((PhysicalAddress(0b11111111) & 0b01010101) == 0b01010101);
|
||||
static_assert((PhysicalAddress(0b11111111) & 0b10101010) == 0b10101010);
|
||||
static_assert((PhysicalAddress(0b01010101) & 0b10101010) == 0b00000000);
|
||||
static_assert((PhysicalAddress(0b00000000) | 0b01010101) == 0b01010101);
|
||||
static_assert((PhysicalAddress(0b11111111) | 0b01010101) == 0b11111111);
|
||||
static_assert((PhysicalAddress(0b10101010) | 0b01010101) == 0b11111111);
|
||||
|
||||
// Comparisons.
|
||||
static_assert(PhysicalAddress(0) == PhysicalAddress(0));
|
||||
static_assert(PhysicalAddress(0) != PhysicalAddress(1));
|
||||
static_assert(PhysicalAddress(0) < PhysicalAddress(1));
|
||||
static_assert(PhysicalAddress(0) <= PhysicalAddress(1));
|
||||
static_assert(PhysicalAddress(1) > PhysicalAddress(0));
|
||||
static_assert(PhysicalAddress(1) >= PhysicalAddress(0));
|
||||
|
||||
static_assert(!(PhysicalAddress(0) == PhysicalAddress(1)));
|
||||
static_assert(!(PhysicalAddress(0) != PhysicalAddress(0)));
|
||||
static_assert(!(PhysicalAddress(1) < PhysicalAddress(0)));
|
||||
static_assert(!(PhysicalAddress(1) <= PhysicalAddress(0)));
|
||||
static_assert(!(PhysicalAddress(0) > PhysicalAddress(1)));
|
||||
static_assert(!(PhysicalAddress(0) >= PhysicalAddress(1)));
|
||||
|
||||
} // namespace Common
|
||||
|
||||
template <bool Virtual, typename T>
|
||||
constexpr inline uint64_t GetInteger(Common::TypedAddress<Virtual, T> address) {
|
||||
return address.GetValue();
|
||||
}
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Common::PhysicalAddress> {
|
||||
constexpr auto parse(fmt::format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Common::PhysicalAddress& addr, FormatContext& ctx) {
|
||||
return fmt::format_to(ctx.out(), "{:#x}", static_cast<u64>(addr.GetValue()));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Common::ProcessAddress> {
|
||||
constexpr auto parse(fmt::format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Common::ProcessAddress& addr, FormatContext& ctx) {
|
||||
return fmt::format_to(ctx.out(), "{:#x}", static_cast<u64>(addr.GetValue()));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Common::VirtualAddress> {
|
||||
constexpr auto parse(fmt::format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Common::VirtualAddress& addr, FormatContext& ctx) {
|
||||
return fmt::format_to(ctx.out(), "{:#x}", static_cast<u64>(addr.GetValue()));
|
||||
}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<Common::PhysicalAddress> {
|
||||
size_t operator()(const Common::PhysicalAddress& k) const noexcept {
|
||||
return k.GetValue();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<Common::ProcessAddress> {
|
||||
size_t operator()(const Common::ProcessAddress& k) const noexcept {
|
||||
return k.GetValue();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<Common::VirtualAddress> {
|
||||
size_t operator()(const Common::VirtualAddress& k) const noexcept {
|
||||
return k.GetValue();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
|
@ -278,6 +278,7 @@ add_library(core STATIC
|
|||
hle/kernel/k_trace.h
|
||||
hle/kernel/k_transfer_memory.cpp
|
||||
hle/kernel/k_transfer_memory.h
|
||||
hle/kernel/k_typed_address.h
|
||||
hle/kernel/k_worker_task.h
|
||||
hle/kernel/k_worker_task_manager.cpp
|
||||
hle/kernel/k_worker_task_manager.h
|
||||
|
|
|
|||
|
|
@ -168,21 +168,21 @@ void ARM_Interface::LoadWatchpointArray(const WatchpointArray& wp) {
|
|||
}
|
||||
|
||||
const Kernel::DebugWatchpoint* ARM_Interface::MatchingWatchpoint(
|
||||
VAddr addr, u64 size, Kernel::DebugWatchpointType access_type) const {
|
||||
u64 addr, u64 size, Kernel::DebugWatchpointType access_type) const {
|
||||
if (!watchpoints) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const VAddr start_address{addr};
|
||||
const VAddr end_address{addr + size};
|
||||
const u64 start_address{addr};
|
||||
const u64 end_address{addr + size};
|
||||
|
||||
for (size_t i = 0; i < Core::Hardware::NUM_WATCHPOINTS; i++) {
|
||||
const auto& watch{(*watchpoints)[i]};
|
||||
|
||||
if (end_address <= watch.start_address) {
|
||||
if (end_address <= GetInteger(watch.start_address)) {
|
||||
continue;
|
||||
}
|
||||
if (start_address >= watch.end_address) {
|
||||
if (start_address >= GetInteger(watch.end_address)) {
|
||||
continue;
|
||||
}
|
||||
if ((access_type & watch.type) == Kernel::DebugWatchpointType::None) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
* @param addr Start address of the cache range to clear
|
||||
* @param size Size of the cache range to clear, starting at addr
|
||||
*/
|
||||
virtual void InvalidateCacheRange(VAddr addr, std::size_t size) = 0;
|
||||
virtual void InvalidateCacheRange(u64 addr, std::size_t size) = 0;
|
||||
|
||||
/**
|
||||
* Notifies CPU emulation that the current page table has changed.
|
||||
|
|
@ -149,9 +149,9 @@ public:
|
|||
*/
|
||||
virtual void SetPSTATE(u32 pstate) = 0;
|
||||
|
||||
virtual VAddr GetTlsAddress() const = 0;
|
||||
virtual u64 GetTlsAddress() const = 0;
|
||||
|
||||
virtual void SetTlsAddress(VAddr address) = 0;
|
||||
virtual void SetTlsAddress(u64 address) = 0;
|
||||
|
||||
/**
|
||||
* Gets the value within the TPIDR_EL0 (read/write software thread ID) register.
|
||||
|
|
@ -214,7 +214,7 @@ protected:
|
|||
|
||||
static void SymbolicateBacktrace(Core::System& system, std::vector<BacktraceEntry>& out);
|
||||
const Kernel::DebugWatchpoint* MatchingWatchpoint(
|
||||
VAddr addr, u64 size, Kernel::DebugWatchpointType access_type) const;
|
||||
u64 addr, u64 size, Kernel::DebugWatchpointType access_type) const;
|
||||
|
||||
virtual Dynarmic::HaltReason RunJit() = 0;
|
||||
virtual Dynarmic::HaltReason StepJit() = 0;
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ public:
|
|||
return std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0);
|
||||
}
|
||||
|
||||
bool CheckMemoryAccess(VAddr addr, u64 size, Kernel::DebugWatchpointType type) {
|
||||
bool CheckMemoryAccess(u64 addr, u64 size, Kernel::DebugWatchpointType type) {
|
||||
if (!check_memory_access) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -397,7 +397,7 @@ u64 ARM_Dynarmic_32::GetTlsAddress() const {
|
|||
return cp15->uro;
|
||||
}
|
||||
|
||||
void ARM_Dynarmic_32::SetTlsAddress(VAddr address) {
|
||||
void ARM_Dynarmic_32::SetTlsAddress(u64 address) {
|
||||
cp15->uro = static_cast<u32>(address);
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +439,7 @@ void ARM_Dynarmic_32::ClearInstructionCache() {
|
|||
jit.load()->ClearCache();
|
||||
}
|
||||
|
||||
void ARM_Dynarmic_32::InvalidateCacheRange(VAddr addr, std::size_t size) {
|
||||
void ARM_Dynarmic_32::InvalidateCacheRange(u64 addr, std::size_t size) {
|
||||
jit.load()->InvalidateCacheRange(static_cast<u32>(addr), size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ public:
|
|||
void SetVectorReg(int index, u128 value) override;
|
||||
u32 GetPSTATE() const override;
|
||||
void SetPSTATE(u32 pstate) override;
|
||||
VAddr GetTlsAddress() const override;
|
||||
void SetTlsAddress(VAddr address) override;
|
||||
u64 GetTlsAddress() const override;
|
||||
void SetTlsAddress(u64 address) override;
|
||||
void SetTPIDR_EL0(u64 value) override;
|
||||
u64 GetTPIDR_EL0() const override;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ public:
|
|||
void ClearExclusiveState() override;
|
||||
|
||||
void ClearInstructionCache() override;
|
||||
void InvalidateCacheRange(VAddr addr, std::size_t size) override;
|
||||
void InvalidateCacheRange(u64 addr, std::size_t size) override;
|
||||
void PageTableChanged(Common::PageTable& new_page_table,
|
||||
std::size_t new_address_space_size_in_bits) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public:
|
|||
}
|
||||
|
||||
void InstructionCacheOperationRaised(Dynarmic::A64::InstructionCacheOperation op,
|
||||
VAddr value) override {
|
||||
u64 value) override {
|
||||
switch (op) {
|
||||
case Dynarmic::A64::InstructionCacheOperation::InvalidateByVAToPoU: {
|
||||
static constexpr u64 ICACHE_LINE_SIZE = 64;
|
||||
|
|
@ -199,7 +199,7 @@ public:
|
|||
return parent.system.CoreTiming().GetClockTicks();
|
||||
}
|
||||
|
||||
bool CheckMemoryAccess(VAddr addr, u64 size, Kernel::DebugWatchpointType type) {
|
||||
bool CheckMemoryAccess(u64 addr, u64 size, Kernel::DebugWatchpointType type) {
|
||||
if (!check_memory_access) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -452,7 +452,7 @@ u64 ARM_Dynarmic_64::GetTlsAddress() const {
|
|||
return cb->tpidrro_el0;
|
||||
}
|
||||
|
||||
void ARM_Dynarmic_64::SetTlsAddress(VAddr address) {
|
||||
void ARM_Dynarmic_64::SetTlsAddress(u64 address) {
|
||||
cb->tpidrro_el0 = address;
|
||||
}
|
||||
|
||||
|
|
@ -500,7 +500,7 @@ void ARM_Dynarmic_64::ClearInstructionCache() {
|
|||
jit.load()->ClearCache();
|
||||
}
|
||||
|
||||
void ARM_Dynarmic_64::InvalidateCacheRange(VAddr addr, std::size_t size) {
|
||||
void ARM_Dynarmic_64::InvalidateCacheRange(u64 addr, std::size_t size) {
|
||||
jit.load()->InvalidateCacheRange(addr, size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ public:
|
|||
void SetVectorReg(int index, u128 value) override;
|
||||
u32 GetPSTATE() const override;
|
||||
void SetPSTATE(u32 pstate) override;
|
||||
VAddr GetTlsAddress() const override;
|
||||
void SetTlsAddress(VAddr address) override;
|
||||
u64 GetTlsAddress() const override;
|
||||
void SetTlsAddress(u64 address) override;
|
||||
void SetTPIDR_EL0(u64 value) override;
|
||||
u64 GetTPIDR_EL0() const override;
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ public:
|
|||
void ClearExclusiveState() override;
|
||||
|
||||
void ClearInstructionCache() override;
|
||||
void InvalidateCacheRange(VAddr addr, std::size_t size) override;
|
||||
void InvalidateCacheRange(u64 addr, std::size_t size) override;
|
||||
void PageTableChanged(Common::PageTable& new_page_table,
|
||||
std::size_t new_address_space_size_in_bits) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ void System::InvalidateCpuInstructionCaches() {
|
|||
impl->kernel.InvalidateAllInstructionCaches();
|
||||
}
|
||||
|
||||
void System::InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size) {
|
||||
void System::InvalidateCpuInstructionCacheRange(u64 addr, std::size_t size) {
|
||||
impl->kernel.InvalidateCpuInstructionCacheRange(addr, size);
|
||||
}
|
||||
|
||||
|
|
@ -794,7 +794,7 @@ FileSys::VirtualFilesystem System::GetFilesystem() const {
|
|||
}
|
||||
|
||||
void System::RegisterCheatList(const std::vector<Memory::CheatEntry>& list,
|
||||
const std::array<u8, 32>& build_id, VAddr main_region_begin,
|
||||
const std::array<u8, 32>& build_id, u64 main_region_begin,
|
||||
u64 main_region_size) {
|
||||
impl->cheat_engine = std::make_unique<Memory::CheatEngine>(*this, list, build_id);
|
||||
impl->cheat_engine->SetMainMemoryParameters(main_region_begin, main_region_size);
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ public:
|
|||
*/
|
||||
void InvalidateCpuInstructionCaches();
|
||||
|
||||
void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size);
|
||||
void InvalidateCpuInstructionCacheRange(u64 addr, std::size_t size);
|
||||
|
||||
/// Shutdown the main emulated process.
|
||||
void ShutdownMainProcess();
|
||||
|
|
@ -353,7 +353,7 @@ public:
|
|||
[[nodiscard]] FileSys::VirtualFilesystem GetFilesystem() const;
|
||||
|
||||
void RegisterCheatList(const std::vector<Memory::CheatEntry>& list,
|
||||
const std::array<u8, 0x20>& build_id, VAddr main_region_begin,
|
||||
const std::array<u8, 0x20>& build_id, u64 main_region_begin,
|
||||
u64 main_region_size);
|
||||
|
||||
void SetAppletFrontendSet(Service::AM::Applets::AppletFrontendSet&& set);
|
||||
|
|
|
|||
|
|
@ -118,14 +118,14 @@ void GDBStub::Watchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint&
|
|||
|
||||
switch (watch.type) {
|
||||
case Kernel::DebugWatchpointType::Read:
|
||||
SendReply(fmt::format("{}rwatch:{:x};", status, watch.start_address));
|
||||
SendReply(fmt::format("{}rwatch:{:x};", status, GetInteger(watch.start_address)));
|
||||
break;
|
||||
case Kernel::DebugWatchpointType::Write:
|
||||
SendReply(fmt::format("{}watch:{:x};", status, watch.start_address));
|
||||
SendReply(fmt::format("{}watch:{:x};", status, GetInteger(watch.start_address)));
|
||||
break;
|
||||
case Kernel::DebugWatchpointType::ReadOrWrite:
|
||||
default:
|
||||
SendReply(fmt::format("{}awatch:{:x};", status, watch.start_address));
|
||||
SendReply(fmt::format("{}awatch:{:x};", status, GetInteger(watch.start_address)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -554,8 +554,9 @@ void GDBStub::HandleQuery(std::string_view command) {
|
|||
if (main != modules.end()) {
|
||||
SendReply(fmt::format("TextSeg={:x}", main->first));
|
||||
} else {
|
||||
SendReply(fmt::format("TextSeg={:x}",
|
||||
system.ApplicationProcess()->PageTable().GetCodeRegionStart()));
|
||||
SendReply(fmt::format(
|
||||
"TextSeg={:x}",
|
||||
GetInteger(system.ApplicationProcess()->PageTable().GetCodeRegionStart())));
|
||||
}
|
||||
} else if (command.starts_with("Xfer:libraries:read::")) {
|
||||
Loader::AppLoader::Modules modules;
|
||||
|
|
@ -757,17 +758,20 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
|
|||
reply = fmt::format("Process: {:#x} ({})\n"
|
||||
"Program Id: {:#018x}\n",
|
||||
process->GetProcessId(), process->GetName(), process->GetProgramId());
|
||||
reply +=
|
||||
fmt::format("Layout:\n"
|
||||
" Alias: {:#012x} - {:#012x}\n"
|
||||
" Heap: {:#012x} - {:#012x}\n"
|
||||
" Aslr: {:#012x} - {:#012x}\n"
|
||||
" Stack: {:#012x} - {:#012x}\n"
|
||||
"Modules:\n",
|
||||
page_table.GetAliasRegionStart(), page_table.GetAliasRegionEnd(),
|
||||
page_table.GetHeapRegionStart(), page_table.GetHeapRegionEnd(),
|
||||
page_table.GetAliasCodeRegionStart(), page_table.GetAliasCodeRegionEnd(),
|
||||
page_table.GetStackRegionStart(), page_table.GetStackRegionEnd());
|
||||
reply += fmt::format("Layout:\n"
|
||||
" Alias: {:#012x} - {:#012x}\n"
|
||||
" Heap: {:#012x} - {:#012x}\n"
|
||||
" Aslr: {:#012x} - {:#012x}\n"
|
||||
" Stack: {:#012x} - {:#012x}\n"
|
||||
"Modules:\n",
|
||||
GetInteger(page_table.GetAliasRegionStart()),
|
||||
GetInteger(page_table.GetAliasRegionEnd()),
|
||||
GetInteger(page_table.GetHeapRegionStart()),
|
||||
GetInteger(page_table.GetHeapRegionEnd()),
|
||||
GetInteger(page_table.GetAliasCodeRegionStart()),
|
||||
GetInteger(page_table.GetAliasCodeRegionEnd()),
|
||||
GetInteger(page_table.GetStackRegionStart()),
|
||||
GetInteger(page_table.GetStackRegionEnd()));
|
||||
|
||||
for (const auto& [vaddr, name] : modules) {
|
||||
reply += fmt::format(" {:#012x} - {:#012x} {}\n", vaddr,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/host_memory.h"
|
||||
#include "common/typed_address.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
|
@ -25,20 +25,22 @@ public:
|
|||
DeviceMemory(const DeviceMemory&) = delete;
|
||||
|
||||
template <typename T>
|
||||
PAddr GetPhysicalAddr(const T* ptr) const {
|
||||
Common::PhysicalAddress GetPhysicalAddr(const T* ptr) const {
|
||||
return (reinterpret_cast<uintptr_t>(ptr) -
|
||||
reinterpret_cast<uintptr_t>(buffer.BackingBasePointer())) +
|
||||
DramMemoryMap::Base;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* GetPointer(PAddr addr) {
|
||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() + (addr - DramMemoryMap::Base));
|
||||
T* GetPointer(Common::PhysicalAddress addr) {
|
||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
||||
(GetInteger(addr) - DramMemoryMap::Base));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T* GetPointer(PAddr addr) const {
|
||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() + (addr - DramMemoryMap::Base));
|
||||
const T* GetPointer(Common::PhysicalAddress addr) const {
|
||||
return reinterpret_cast<T*>(buffer.BackingBasePointer() +
|
||||
(GetInteger(addr) - DramMemoryMap::Base));
|
||||
}
|
||||
|
||||
Common::HostMemory buffer;
|
||||
|
|
|
|||
|
|
@ -76,22 +76,24 @@ void SetupDevicePhysicalMemoryRegions(KMemoryLayout& memory_layout) {
|
|||
|
||||
void SetupDramPhysicalMemoryRegions(KMemoryLayout& memory_layout) {
|
||||
const size_t intended_memory_size = KSystemControl::Init::GetIntendedMemorySize();
|
||||
const PAddr physical_memory_base_address =
|
||||
const KPhysicalAddress physical_memory_base_address =
|
||||
KSystemControl::Init::GetKernelPhysicalBaseAddress(DramPhysicalAddress);
|
||||
|
||||
// Insert blocks into the tree.
|
||||
ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert(
|
||||
physical_memory_base_address, intended_memory_size, KMemoryRegionType_Dram));
|
||||
GetInteger(physical_memory_base_address), intended_memory_size, KMemoryRegionType_Dram));
|
||||
ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert(
|
||||
physical_memory_base_address, ReservedEarlyDramSize, KMemoryRegionType_DramReservedEarly));
|
||||
GetInteger(physical_memory_base_address), ReservedEarlyDramSize,
|
||||
KMemoryRegionType_DramReservedEarly));
|
||||
|
||||
// Insert the KTrace block at the end of Dram, if KTrace is enabled.
|
||||
static_assert(!IsKTraceEnabled || KTraceBufferSize > 0);
|
||||
if constexpr (IsKTraceEnabled) {
|
||||
const PAddr ktrace_buffer_phys_addr =
|
||||
const KPhysicalAddress ktrace_buffer_phys_addr =
|
||||
physical_memory_base_address + intended_memory_size - KTraceBufferSize;
|
||||
ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert(
|
||||
ktrace_buffer_phys_addr, KTraceBufferSize, KMemoryRegionType_KernelTraceBuffer));
|
||||
GetInteger(ktrace_buffer_phys_addr), KTraceBufferSize,
|
||||
KMemoryRegionType_KernelTraceBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/kernel/k_typed_address.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
constexpr inline PAddr MainMemoryAddress = 0x80000000;
|
||||
constexpr inline KPhysicalAddress MainMemoryAddress = 0x80000000;
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ size_t KSystemControl::Init::GetIntendedMemorySize() {
|
|||
}
|
||||
}
|
||||
|
||||
PAddr KSystemControl::Init::GetKernelPhysicalBaseAddress(u64 base_address) {
|
||||
KPhysicalAddress KSystemControl::Init::GetKernelPhysicalBaseAddress(KPhysicalAddress base_address) {
|
||||
const size_t real_dram_size = KSystemControl::Init::GetRealMemorySize();
|
||||
const size_t intended_dram_size = KSystemControl::Init::GetIntendedMemorySize();
|
||||
if (intended_dram_size * 2 < real_dram_size) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/kernel/k_typed_address.h"
|
||||
|
||||
namespace Kernel::Board::Nintendo::Nx {
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ public:
|
|||
// Initialization.
|
||||
static std::size_t GetRealMemorySize();
|
||||
static std::size_t GetIntendedMemorySize();
|
||||
static PAddr GetKernelPhysicalBaseAddress(u64 base_address);
|
||||
static KPhysicalAddress GetKernelPhysicalBaseAddress(KPhysicalAddress base_address);
|
||||
static bool ShouldIncreaseThreadResourceLimit();
|
||||
static std::size_t GetApplicationPoolSize();
|
||||
static std::size_t GetAppletPoolSize();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/kernel/k_typed_address.h"
|
||||
#include "core/hle/kernel/physical_memory.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
|
@ -36,7 +36,7 @@ struct CodeSet final {
|
|||
std::size_t offset = 0;
|
||||
|
||||
/// The address to map this segment to.
|
||||
VAddr addr = 0;
|
||||
KProcessAddress addr = 0;
|
||||
|
||||
/// The size of this segment in bytes.
|
||||
u32 size = 0;
|
||||
|
|
@ -82,7 +82,7 @@ struct CodeSet final {
|
|||
std::array<Segment, 3> segments;
|
||||
|
||||
/// The entry point address for this code set.
|
||||
VAddr entrypoint = 0;
|
||||
KProcessAddress entrypoint = 0;
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include "common/alignment.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/core.h"
|
||||
#include "core/device_memory.h"
|
||||
#include "core/hardware_properties.h"
|
||||
|
|
@ -30,6 +29,7 @@
|
|||
#include "core/hle/kernel/k_thread.h"
|
||||
#include "core/hle/kernel/k_thread_local_page.h"
|
||||
#include "core/hle/kernel/k_transfer_memory.h"
|
||||
#include "core/hle/kernel/k_typed_address.h"
|
||||
|
||||
namespace Kernel::Init {
|
||||
|
||||
|
|
@ -104,17 +104,18 @@ static_assert(KernelPageBufferAdditionalSize ==
|
|||
|
||||
/// Helper function to translate from the slab virtual address to the reserved location in physical
|
||||
/// memory.
|
||||
static PAddr TranslateSlabAddrToPhysical(KMemoryLayout& memory_layout, VAddr slab_addr) {
|
||||
slab_addr -= memory_layout.GetSlabRegionAddress();
|
||||
return slab_addr + Core::DramMemoryMap::SlabHeapBase;
|
||||
static KPhysicalAddress TranslateSlabAddrToPhysical(KMemoryLayout& memory_layout,
|
||||
KVirtualAddress slab_addr) {
|
||||
slab_addr -= GetInteger(memory_layout.GetSlabRegionAddress());
|
||||
return GetInteger(slab_addr) + Core::DramMemoryMap::SlabHeapBase;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAddr address,
|
||||
size_t num_objects) {
|
||||
KVirtualAddress InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout,
|
||||
KVirtualAddress address, size_t num_objects) {
|
||||
|
||||
const size_t size = Common::AlignUp(sizeof(T) * num_objects, alignof(void*));
|
||||
VAddr start = Common::AlignUp(address, alignof(T));
|
||||
KVirtualAddress start = Common::AlignUp(GetInteger(address), alignof(T));
|
||||
|
||||
// This should use the virtual memory address passed in, but currently, we do not setup the
|
||||
// kernel virtual memory layout. Instead, we simply map these at a region of physical memory
|
||||
|
|
@ -195,7 +196,7 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
|
|||
auto& kernel = system.Kernel();
|
||||
|
||||
// Get the start of the slab region, since that's where we'll be working.
|
||||
VAddr address = memory_layout.GetSlabRegionAddress();
|
||||
KVirtualAddress address = memory_layout.GetSlabRegionAddress();
|
||||
|
||||
// Initialize slab type array to be in sorted order.
|
||||
std::array<KSlabType, KSlabType_Count> slab_types;
|
||||
|
|
@ -228,7 +229,7 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
|
|||
}
|
||||
|
||||
// Track the gaps, so that we can free them to the unused slab tree.
|
||||
VAddr gap_start = address;
|
||||
KVirtualAddress gap_start = address;
|
||||
size_t gap_size = 0;
|
||||
|
||||
for (size_t i = 0; i < slab_gaps.size(); i++) {
|
||||
|
|
@ -280,7 +281,7 @@ void KPageBufferSlabHeap::Initialize(Core::System& system) {
|
|||
// Allocate memory for the slab.
|
||||
constexpr auto AllocateOption = KMemoryManager::EncodeOption(
|
||||
KMemoryManager::Pool::System, KMemoryManager::Direction::FromFront);
|
||||
const PAddr slab_address =
|
||||
const KPhysicalAddress slab_address =
|
||||
kernel.MemoryManager().AllocateAndOpenContinuous(num_pages, 1, AllocateOption);
|
||||
ASSERT(slab_address != 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ using namespace Common::Literals;
|
|||
|
||||
constexpr std::size_t InitialProcessBinarySizeMax = 12_MiB;
|
||||
|
||||
static inline PAddr GetInitialProcessBinaryPhysicalAddress() {
|
||||
static inline KPhysicalAddress GetInitialProcessBinaryPhysicalAddress() {
|
||||
return Kernel::Board::Nintendo::Nx::KSystemControl::Init::GetKernelPhysicalBaseAddress(
|
||||
MainMemoryAddress);
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue