diff options
| author | 2019-03-02 15:20:28 -0500 | |
|---|---|---|
| committer | 2019-03-16 22:05:40 -0400 | |
| commit | 93da8e0abfcdcc6e3cb5488a0db12373429f1377 (patch) | |
| tree | 2d2cbe82cfa779add5b77025c04b19361dcbe981 /src/core/memory.h | |
| parent | Merge pull request #2244 from bunnei/gpu-mem-refactor (diff) | |
| download | yuzu-93da8e0abfcdcc6e3cb5488a0db12373429f1377.tar.gz yuzu-93da8e0abfcdcc6e3cb5488a0db12373429f1377.tar.xz yuzu-93da8e0abfcdcc6e3cb5488a0db12373429f1377.zip | |
core: Move PageTable struct into Common.
Diffstat (limited to 'src/core/memory.h')
| -rw-r--r-- | src/core/memory.h | 74 |
1 files changed, 6 insertions, 68 deletions
diff --git a/src/core/memory.h b/src/core/memory.h index c2c6643ee..3f60d868c 100644 --- a/src/core/memory.h +++ b/src/core/memory.h | |||
| @@ -10,7 +10,10 @@ | |||
| 10 | #include <vector> | 10 | #include <vector> |
| 11 | #include <boost/icl/interval_map.hpp> | 11 | #include <boost/icl/interval_map.hpp> |
| 12 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "core/memory_hook.h" | 13 | |
| 14 | namespace Common { | ||
| 15 | struct PageTable; | ||
| 16 | } | ||
| 14 | 17 | ||
| 15 | namespace Kernel { | 18 | namespace Kernel { |
| 16 | class Process; | 19 | class Process; |
| @@ -26,71 +29,6 @@ constexpr std::size_t PAGE_BITS = 12; | |||
| 26 | constexpr u64 PAGE_SIZE = 1ULL << PAGE_BITS; | 29 | constexpr u64 PAGE_SIZE = 1ULL << PAGE_BITS; |
| 27 | constexpr u64 PAGE_MASK = PAGE_SIZE - 1; | 30 | constexpr u64 PAGE_MASK = PAGE_SIZE - 1; |
| 28 | 31 | ||
| 29 | enum class PageType : u8 { | ||
| 30 | /// Page is unmapped and should cause an access error. | ||
| 31 | Unmapped, | ||
| 32 | /// Page is mapped to regular memory. This is the only type you can get pointers to. | ||
| 33 | Memory, | ||
| 34 | /// Page is mapped to regular memory, but also needs to check for rasterizer cache flushing and | ||
| 35 | /// invalidation | ||
| 36 | RasterizerCachedMemory, | ||
| 37 | /// Page is mapped to a I/O region. Writing and reading to this page is handled by functions. | ||
| 38 | Special, | ||
| 39 | }; | ||
| 40 | |||
| 41 | struct SpecialRegion { | ||
| 42 | enum class Type { | ||
| 43 | DebugHook, | ||
| 44 | IODevice, | ||
| 45 | } type; | ||
| 46 | |||
| 47 | MemoryHookPointer handler; | ||
| 48 | |||
| 49 | bool operator<(const SpecialRegion& other) const { | ||
| 50 | return std::tie(type, handler) < std::tie(other.type, other.handler); | ||
| 51 | } | ||
| 52 | |||
| 53 | bool operator==(const SpecialRegion& other) const { | ||
| 54 | return std::tie(type, handler) == std::tie(other.type, other.handler); | ||
| 55 | } | ||
| 56 | }; | ||
| 57 | |||
| 58 | /** | ||
| 59 | * A (reasonably) fast way of allowing switchable and remappable process address spaces. It loosely | ||
| 60 | * mimics the way a real CPU page table works. | ||
| 61 | */ | ||
| 62 | struct PageTable { | ||
| 63 | explicit PageTable(); | ||
| 64 | explicit PageTable(std::size_t address_space_width_in_bits); | ||
| 65 | ~PageTable(); | ||
| 66 | |||
| 67 | /** | ||
| 68 | * Resizes the page table to be able to accomodate enough pages within | ||
| 69 | * a given address space. | ||
| 70 | * | ||
| 71 | * @param address_space_width_in_bits The address size width in bits. | ||
| 72 | */ | ||
| 73 | void Resize(std::size_t address_space_width_in_bits); | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Vector of memory pointers backing each page. An entry can only be non-null if the | ||
| 77 | * corresponding entry in the `attributes` vector is of type `Memory`. | ||
| 78 | */ | ||
| 79 | std::vector<u8*> pointers; | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Contains MMIO handlers that back memory regions whose entries in the `attribute` vector is | ||
| 83 | * of type `Special`. | ||
| 84 | */ | ||
| 85 | boost::icl::interval_map<VAddr, std::set<SpecialRegion>> special_regions; | ||
| 86 | |||
| 87 | /** | ||
| 88 | * Vector of fine grained page attributes. If it is set to any value other than `Memory`, then | ||
| 89 | * the corresponding entry in `pointers` MUST be set to null. | ||
| 90 | */ | ||
| 91 | std::vector<PageType> attributes; | ||
| 92 | }; | ||
| 93 | |||
| 94 | /// Virtual user-space memory regions | 32 | /// Virtual user-space memory regions |
| 95 | enum : VAddr { | 33 | enum : VAddr { |
| 96 | /// Read-only page containing kernel and system configuration values. | 34 | /// Read-only page containing kernel and system configuration values. |
| @@ -116,8 +54,8 @@ enum : VAddr { | |||
| 116 | }; | 54 | }; |
| 117 | 55 | ||
| 118 | /// Currently active page table | 56 | /// Currently active page table |
| 119 | void SetCurrentPageTable(PageTable* page_table); | 57 | void SetCurrentPageTable(Common::PageTable* page_table); |
| 120 | PageTable* GetCurrentPageTable(); | 58 | Common::PageTable* GetCurrentPageTable(); |
| 121 | 59 | ||
| 122 | /// Determines if the given VAddr is valid for the specified process. | 60 | /// Determines if the given VAddr is valid for the specified process. |
| 123 | bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr); | 61 | bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr); |