summaryrefslogtreecommitdiff
path: root/src/common/page_table.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/page_table.h')
-rw-r--r--src/common/page_table.h53
1 files changed, 20 insertions, 33 deletions
diff --git a/src/common/page_table.h b/src/common/page_table.h
index dbc272ab7..9754fabf9 100644
--- a/src/common/page_table.h
+++ b/src/common/page_table.h
@@ -4,10 +4,11 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <vector> 7#include <tuple>
8#include <boost/icl/interval_map.hpp> 8
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/memory_hook.h" 10#include "common/memory_hook.h"
11#include "common/virtual_buffer.h"
11 12
12namespace Common { 13namespace Common {
13 14
@@ -33,11 +34,11 @@ struct SpecialRegion {
33 34
34 MemoryHookPointer handler; 35 MemoryHookPointer handler;
35 36
36 bool operator<(const SpecialRegion& other) const { 37 [[nodiscard]] bool operator<(const SpecialRegion& other) const {
37 return std::tie(type, handler) < std::tie(other.type, other.handler); 38 return std::tie(type, handler) < std::tie(other.type, other.handler);
38 } 39 }
39 40
40 bool operator==(const SpecialRegion& other) const { 41 [[nodiscard]] bool operator==(const SpecialRegion& other) const {
41 return std::tie(type, handler) == std::tie(other.type, other.handler); 42 return std::tie(type, handler) == std::tie(other.type, other.handler);
42 } 43 }
43}; 44};
@@ -47,49 +48,35 @@ struct SpecialRegion {
47 * mimics the way a real CPU page table works. 48 * mimics the way a real CPU page table works.
48 */ 49 */
49struct PageTable { 50struct PageTable {
50 explicit PageTable(std::size_t page_size_in_bits); 51 PageTable();
51 ~PageTable(); 52 ~PageTable() noexcept;
53
54 PageTable(const PageTable&) = delete;
55 PageTable& operator=(const PageTable&) = delete;
56
57 PageTable(PageTable&&) noexcept = default;
58 PageTable& operator=(PageTable&&) noexcept = default;
52 59
53 /** 60 /**
54 * Resizes the page table to be able to accomodate enough pages within 61 * Resizes the page table to be able to accomodate enough pages within
55 * a given address space. 62 * a given address space.
56 * 63 *
57 * @param address_space_width_in_bits The address size width in bits. 64 * @param address_space_width_in_bits The address size width in bits.
65 * @param page_size_in_bits The page size in bits.
66 * @param has_attribute Whether or not this page has any backing attributes.
58 */ 67 */
59 void Resize(std::size_t address_space_width_in_bits); 68 void Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits,
69 bool has_attribute);
60 70
61 /** 71 /**
62 * Vector of memory pointers backing each page. An entry can only be non-null if the 72 * Vector of memory pointers backing each page. An entry can only be non-null if the
63 * corresponding entry in the `attributes` vector is of type `Memory`. 73 * corresponding entry in the `attributes` vector is of type `Memory`.
64 */ 74 */
65 std::vector<u8*> pointers; 75 VirtualBuffer<u8*> pointers;
66
67 /**
68 * Contains MMIO handlers that back memory regions whose entries in the `attribute` vector is
69 * of type `Special`.
70 */
71 boost::icl::interval_map<u64, std::set<SpecialRegion>> special_regions;
72
73 /**
74 * Vector of fine grained page attributes. If it is set to any value other than `Memory`, then
75 * the corresponding entry in `pointers` MUST be set to null.
76 */
77 std::vector<PageType> attributes;
78
79 const std::size_t page_size_in_bits{};
80};
81
82/**
83 * A more advanced Page Table with the ability to save a backing address when using it
84 * depends on another MMU.
85 */
86struct BackingPageTable : PageTable {
87 explicit BackingPageTable(std::size_t page_size_in_bits);
88 ~BackingPageTable();
89 76
90 void Resize(std::size_t address_space_width_in_bits); 77 VirtualBuffer<u64> backing_addr;
91 78
92 std::vector<u64> backing_addr; 79 VirtualBuffer<PageType> attributes;
93}; 80};
94 81
95} // namespace Common 82} // namespace Common