diff options
author | bunnei <bunneidev@gmail.com> | 2019-03-17 19:42:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-17 19:42:57 +0100 |
commit | 57ca1e3e6942d1ef1b59c458e76ba969f0b739d5 (patch) | |
tree | 1d7a026c695a73932030048329a2c0707656666e /src/common | |
parent | Merge pull request #2251 from bunnei/skip-zero-flush (diff) | |
parent | core: Move PageTable struct into Common. (diff) | |
download | yuzu-57ca1e3e6942d1ef1b59c458e76ba969f0b739d5.tar yuzu-57ca1e3e6942d1ef1b59c458e76ba969f0b739d5.tar.gz yuzu-57ca1e3e6942d1ef1b59c458e76ba969f0b739d5.tar.bz2 yuzu-57ca1e3e6942d1ef1b59c458e76ba969f0b739d5.tar.lz yuzu-57ca1e3e6942d1ef1b59c458e76ba969f0b739d5.tar.xz yuzu-57ca1e3e6942d1ef1b59c458e76ba969f0b739d5.tar.zst yuzu-57ca1e3e6942d1ef1b59c458e76ba969f0b739d5.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/common/memory_hook.cpp (renamed from src/core/memory_hook.cpp) | 6 | ||||
-rw-r--r-- | src/common/memory_hook.h (renamed from src/core/memory_hook.h) | 4 | ||||
-rw-r--r-- | src/common/page_table.cpp | 29 | ||||
-rw-r--r-- | src/common/page_table.h | 80 |
5 files changed, 118 insertions, 5 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index c538c6415..43ae8a9e7 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -92,10 +92,14 @@ add_library(common STATIC logging/text_formatter.cpp logging/text_formatter.h math_util.h + memory_hook.cpp + memory_hook.h microprofile.cpp microprofile.h microprofileui.h misc.cpp + page_table.cpp + page_table.h param_package.cpp param_package.h quaternion.h diff --git a/src/core/memory_hook.cpp b/src/common/memory_hook.cpp index c61c6c1fb..3986986d6 100644 --- a/src/core/memory_hook.cpp +++ b/src/common/memory_hook.cpp @@ -2,10 +2,10 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "core/memory_hook.h" +#include "common/memory_hook.h" -namespace Memory { +namespace Common { MemoryHook::~MemoryHook() = default; -} // namespace Memory +} // namespace Common diff --git a/src/core/memory_hook.h b/src/common/memory_hook.h index 940777107..adaa4c2c5 100644 --- a/src/core/memory_hook.h +++ b/src/common/memory_hook.h @@ -9,7 +9,7 @@ #include "common/common_types.h" -namespace Memory { +namespace Common { /** * Memory hooks have two purposes: @@ -44,4 +44,4 @@ public: }; using MemoryHookPointer = std::shared_ptr<MemoryHook>; -} // namespace Memory +} // namespace Common diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp new file mode 100644 index 000000000..8eba1c3f1 --- /dev/null +++ b/src/common/page_table.cpp @@ -0,0 +1,29 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/page_table.h" + +namespace Common { + +PageTable::PageTable(std::size_t page_size_in_bits) : page_size_in_bits{page_size_in_bits} {} + +PageTable::~PageTable() = default; + +void PageTable::Resize(std::size_t address_space_width_in_bits) { + const std::size_t num_page_table_entries = 1ULL + << (address_space_width_in_bits - page_size_in_bits); + + pointers.resize(num_page_table_entries); + attributes.resize(num_page_table_entries); + + // The default is a 39-bit address space, which causes an initial 1GB allocation size. If the + // vector size is subsequently decreased (via resize), the vector might not automatically + // actually reallocate/resize its underlying allocation, which wastes up to ~800 MB for + // 36-bit titles. Call shrink_to_fit to reduce capacity to what's actually in use. + + pointers.shrink_to_fit(); + attributes.shrink_to_fit(); +} + +} // namespace Common diff --git a/src/common/page_table.h b/src/common/page_table.h new file mode 100644 index 000000000..8339f2890 --- /dev/null +++ b/src/common/page_table.h @@ -0,0 +1,80 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <vector> +#include <boost/icl/interval_map.hpp> +#include "common/common_types.h" +#include "common/memory_hook.h" + +namespace Common { + +enum class PageType : u8 { + /// Page is unmapped and should cause an access error. + Unmapped, + /// Page is mapped to regular memory. This is the only type you can get pointers to. + Memory, + /// Page is mapped to regular memory, but also needs to check for rasterizer cache flushing and + /// invalidation + RasterizerCachedMemory, + /// Page is mapped to a I/O region. Writing and reading to this page is handled by functions. + Special, +}; + +struct SpecialRegion { + enum class Type { + DebugHook, + IODevice, + } type; + + MemoryHookPointer handler; + + bool operator<(const SpecialRegion& other) const { + return std::tie(type, handler) < std::tie(other.type, other.handler); + } + + bool operator==(const SpecialRegion& other) const { + return std::tie(type, handler) == std::tie(other.type, other.handler); + } +}; + +/** + * A (reasonably) fast way of allowing switchable and remappable process address spaces. It loosely + * mimics the way a real CPU page table works. + */ +struct PageTable { + explicit PageTable(std::size_t page_size_in_bits); + ~PageTable(); + + /** + * Resizes the page table to be able to accomodate enough pages within + * a given address space. + * + * @param address_space_width_in_bits The address size width in bits. + */ + void Resize(std::size_t address_space_width_in_bits); + + /** + * Vector of memory pointers backing each page. An entry can only be non-null if the + * corresponding entry in the `attributes` vector is of type `Memory`. + */ + std::vector<u8*> pointers; + + /** + * Contains MMIO handlers that back memory regions whose entries in the `attribute` vector is + * of type `Special`. + */ + boost::icl::interval_map<VAddr, std::set<SpecialRegion>> special_regions; + + /** + * Vector of fine grained page attributes. If it is set to any value other than `Memory`, then + * the corresponding entry in `pointers` MUST be set to null. + */ + std::vector<PageType> attributes; + + const std::size_t page_size_in_bits{}; +}; + +} // namespace Common |