Browse Source

[core] don't change how we store pointers

pull/4219/head
Exverge 1 week ago
parent
commit
01fbf20557
No known key found for this signature in database GPG Key ID: DAD399BCC5FB77E4
  1. 4
      src/common/page_table.h
  2. 4
      src/core/hle/kernel/k_page_table_base.cpp
  3. 2
      src/core/hle/kernel/k_page_table_base.h
  4. 17
      src/core/memory.cpp

4
src/common/page_table.h

@ -55,8 +55,8 @@ struct PageTable {
class PageEntryData { class PageEntryData {
public: public:
struct Data { struct Data {
Data(bool marked_, PageType type_, u16 block_, u64 page)
: marked(marked_), type(static_cast<u64>(type_)), block(block_), page(page >> ATTRIBUTE_BITS) {}
Data(bool marked_, PageType type_, u16 block_, u64 page_)
: marked(marked_), type(static_cast<u64>(type_)), block(block_), page(page_ >> ATTRIBUTE_BITS) {}
u64 marked : 1; u64 marked : 1;
u64 type : 2; u64 type : 2;
u64 block : 9; // TODO: is 9 bits to little? we can use the upper 8 bits if needed u64 block : 9; // TODO: is 9 bits to little? we can use the upper 8 bits if needed

4
src/core/hle/kernel/k_page_table_base.cpp

@ -651,9 +651,9 @@ bool KPageTableBase::ContinueTraversal(const Common::PageTable &impl, TraversalE
// Validate that we can read the actual entry. // Validate that we can read the actual entry.
if (auto const page = context->next_page; page < impl.entries.size()) { if (auto const page = context->next_page; page < impl.entries.size()) {
// Validate that the entry is mapped. // Validate that the entry is mapped.
if (auto const paddr = impl.entries[page].Pointer(); paddr != 0) {
if (auto const paddr = impl.entries[page].Pointer(true); paddr != 0) {
// Populate the results and return true // Populate the results and return true
out_entry->phys_addr = GetInteger(m_system.DeviceMemory().GetPhysicalAddr(paddr)) + context->next_offset % PageSize;
out_entry->phys_addr = GetInteger(m_system.DeviceMemory().GetPhysicalAddr(paddr)) + context->next_offset;
context->next_page += 1; context->next_page += 1;
context->next_offset += PageSize; context->next_offset += PageSize;
return true; return true;

2
src/core/hle/kernel/k_page_table_base.h

@ -482,7 +482,7 @@ private:
} }
*out = m_system.DeviceMemory().GetPhysicalAddr( *out = m_system.DeviceMemory().GetPhysicalAddr(
this->GetImpl().entries[virt_addr >> PageBits].Pointer());
this->GetImpl().entries[virt_addr >> PageBits].Pointer(true));
return true; return true;
} }

17
src/core/memory.cpp

@ -126,13 +126,13 @@ struct Memory::Impl {
[[nodiscard]] u8* GetPointerFromRasterizerCachedMemory(u64 vaddr) const { [[nodiscard]] u8* GetPointerFromRasterizerCachedMemory(u64 vaddr) const {
if (u64 paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].Pointer(true); paddr) if (u64 paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].Pointer(true); paddr)
return reinterpret_cast<u8*>(paddr) + (vaddr % YUZU_PAGESIZE);
return reinterpret_cast<u8*>(paddr) + vaddr;
return {}; return {};
} }
[[nodiscard]] u8* GetPointerFromDebugMemory(u64 vaddr) const { [[nodiscard]] u8* GetPointerFromDebugMemory(u64 vaddr) const {
if (u64 paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].Pointer(true); paddr) if (u64 paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].Pointer(true); paddr)
return reinterpret_cast<u8*>(paddr) + (vaddr % YUZU_PAGESIZE);
return reinterpret_cast<u8*>(paddr) + vaddr;
return {}; return {};
} }
@ -256,7 +256,7 @@ struct Memory::Impl {
break; break;
} }
case Common::PageType::Memory: { case Common::PageType::Memory: {
u8* mem_ptr = reinterpret_cast<u8*>(pointer + page_offset);
u8* mem_ptr = reinterpret_cast<u8*>(pointer + page_offset + (page_index << YUZU_PAGEBITS));
on_memory(offset, copy_amount, mem_ptr); on_memory(offset, copy_amount, mem_ptr);
break; break;
} }
@ -554,7 +554,7 @@ struct Memory::Impl {
page_table.entries.CommitRegion(base, end); page_table.entries.CommitRegion(base, end);
while (base != end) { while (base != end) {
auto host_ptr = reinterpret_cast<u64>(system.DeviceMemory().GetPointer<u8>(target));
auto host_ptr = reinterpret_cast<u64>(system.DeviceMemory().GetPointer<u8>(target)) - (base << YUZU_PAGEBITS);;
auto& entry = page_table.entries.GetUnchecked(base); auto& entry = page_table.entries.GetUnchecked(base);
entry.Store(false, type, current_block, host_ptr); entry.Store(false, type, current_block, host_ptr);
@ -575,7 +575,7 @@ struct Memory::Impl {
// Avoid adding any extra logic to this fast-path block // Avoid adding any extra logic to this fast-path block
const auto raw = current_page_table->entries[vaddr >> YUZU_PAGEBITS].Raw(); const auto raw = current_page_table->entries[vaddr >> YUZU_PAGEBITS].Raw();
if (auto pointer = Common::PageTable::PageEntryData::ExtractPointer(raw); pointer) [[likely]] { if (auto pointer = Common::PageTable::PageEntryData::ExtractPointer(raw); pointer) [[likely]] {
return reinterpret_cast<u8*>(pointer + vaddr % YUZU_PAGESIZE);
return reinterpret_cast<u8*>(pointer + vaddr);
} else { } else {
switch (static_cast<Common::PageType>(raw.type)) { switch (static_cast<Common::PageType>(raw.type)) {
case Common::PageType::Memory: case Common::PageType::Memory:
@ -625,6 +625,7 @@ struct Memory::Impl {
inline T Read(Common::ProcessAddress vaddr) noexcept requires(std::is_trivially_copyable_v<T>) { inline T Read(Common::ProcessAddress vaddr) noexcept requires(std::is_trivially_copyable_v<T>) {
const u64 addr = GetInteger(vaddr); const u64 addr = GetInteger(vaddr);
if (auto const ptr = GetPointerImpl(addr, [addr]() { if (auto const ptr = GetPointerImpl(addr, [addr]() {
__builtin_debugtrap();
LOG_ERROR(HW_Memory, "Unmapped Read{} @ {:#016x}", sizeof(T) * 8, addr); LOG_ERROR(HW_Memory, "Unmapped Read{} @ {:#016x}", sizeof(T) * 8, addr);
}, [&]() { }, [&]() {
HandleRasterizerDownload(addr, sizeof(T)); HandleRasterizerDownload(addr, sizeof(T));
@ -815,10 +816,8 @@ bool Memory::IsValidVirtualAddress(const Common::ProcessAddress vaddr) const {
if (page >= page_table.entries.size()) { if (page >= page_table.entries.size()) {
return false; return false;
} }
const auto raw = page_table.entries[page].Raw();
const auto type = static_cast<Common::PageType>(raw.type);
return raw.page != 0 || type == Common::PageType::RasterizerCachedMemory ||
const auto [pointer, type, _] = page_table.entries[page].PointerTypeBlock();
return pointer != 0 || type == Common::PageType::RasterizerCachedMemory ||
type == Common::PageType::DebugMemory; type == Common::PageType::DebugMemory;
} }

Loading…
Cancel
Save