page_table_entry_x64.cpp
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #include <bitmanip.h>
24 
25 #include <intrinsics/x64.h>
26 using namespace x64;
27 
29  m_pte(pte.get())
30 { }
31 
32 bool
34 { return is_bit_set(*m_pte, 0); }
35 
36 void
38 { *m_pte = enabled ? set_bit(*m_pte, 0) : clear_bit(*m_pte, 0); }
39 
40 bool
42 { return is_bit_set(*m_pte, 1); }
43 
44 void
46 { *m_pte = enabled ? set_bit(*m_pte, 1) : clear_bit(*m_pte, 1); }
47 
48 bool
50 { return is_bit_set(*m_pte, 2); }
51 
52 void
54 { *m_pte = enabled ? set_bit(*m_pte, 2) : clear_bit(*m_pte, 2); }
55 
56 bool
58 { return is_bit_set(*m_pte, 3); }
59 
60 void
62 { *m_pte = enabled ? set_bit(*m_pte, 3) : clear_bit(*m_pte, 3); }
63 
64 bool
66 { return is_bit_set(*m_pte, 4); }
67 
68 void
70 { *m_pte = enabled ? set_bit(*m_pte, 4) : clear_bit(*m_pte, 4); }
71 
72 bool
74 { return is_bit_set(*m_pte, 5); }
75 
76 void
78 { *m_pte = enabled ? set_bit(*m_pte, 5) : clear_bit(*m_pte, 5); }
79 
80 bool
82 { return is_bit_set(*m_pte, 6); }
83 
84 void
86 { *m_pte = enabled ? set_bit(*m_pte, 6) : clear_bit(*m_pte, 6); }
87 
88 bool
90 { return is_bit_set(*m_pte, 7); }
91 
92 void
94 { *m_pte = enabled ? set_bit(*m_pte, 7) : clear_bit(*m_pte, 7); }
95 
96 bool
98 { return is_bit_set(*m_pte, 7); }
99 
100 void
102 { *m_pte = enabled ? set_bit(*m_pte, 7) : clear_bit(*m_pte, 7); }
103 
104 bool
106 { return is_bit_set(*m_pte, 12); }
107 
108 void
110 { *m_pte = enabled ? set_bit(*m_pte, 12) : clear_bit(*m_pte, 12); }
111 
112 bool
114 { return is_bit_set(*m_pte, 8); }
115 
116 void
118 { *m_pte = enabled ? set_bit(*m_pte, 8) : clear_bit(*m_pte, 8); }
119 
122 { return get_bits(*m_pte, 0x0000FFFFFFFFF000UL); }
123 
124 void
126 { *m_pte = set_bits(*m_pte, 0x0000FFFFFFFFF000UL, addr); }
127 
128 bool
130 { return is_bit_set(*m_pte, 63); }
131 
132 void
134 { *m_pte = enabled ? set_bit(*m_pte, 63) : clear_bit(*m_pte, 63); }
135 
138 {
139  pat_index_type index = 0;
140 
141  if (this->pwt()) index += 1;
142  if (this->pcd()) index += 2;
143  if (this->pat_4k()) index += 4;
144 
145  return index;
146 }
147 
148 void
150 {
151  expects(index <= 7);
152 
153  switch (index)
154  {
155  case 0:
156  this->set_pwt(false);
157  this->set_pcd(false);
158  this->set_pat_4k(false);
159  break;
160 
161  case 1:
162  this->set_pwt(true);
163  this->set_pcd(false);
164  this->set_pat_4k(false);
165  break;
166 
167  case 2:
168  this->set_pwt(false);
169  this->set_pcd(true);
170  this->set_pat_4k(false);
171  break;
172 
173  case 3:
174  this->set_pwt(true);
175  this->set_pcd(true);
176  this->set_pat_4k(false);
177  break;
178 
179  case 4:
180  this->set_pwt(false);
181  this->set_pcd(false);
182  this->set_pat_4k(true);
183  break;
184 
185  case 5:
186  this->set_pwt(true);
187  this->set_pcd(false);
188  this->set_pat_4k(true);
189  break;
190 
191  case 6:
192  this->set_pwt(false);
193  this->set_pcd(true);
194  this->set_pat_4k(true);
195  break;
196 
197  case 7:
198  this->set_pwt(true);
199  this->set_pcd(true);
200  this->set_pat_4k(true);
201  break;
202  };
203 }
204 
207 {
208  pat_index_type index = 0;
209 
210  if (this->pwt()) index += 1;
211  if (this->pcd()) index += 2;
212  if (this->pat_large()) index += 4;
213 
214  return index;
215 }
216 
217 void
219 {
220  expects(index <= 7);
221 
222  switch (index)
223  {
224  case 0:
225  this->set_pwt(false);
226  this->set_pcd(false);
227  this->set_pat_large(false);
228  break;
229 
230  case 1:
231  this->set_pwt(true);
232  this->set_pcd(false);
233  this->set_pat_large(false);
234  break;
235 
236  case 2:
237  this->set_pwt(false);
238  this->set_pcd(true);
239  this->set_pat_large(false);
240  break;
241 
242  case 3:
243  this->set_pwt(true);
244  this->set_pcd(true);
245  this->set_pat_large(false);
246  break;
247 
248  case 4:
249  this->set_pwt(false);
250  this->set_pcd(false);
251  this->set_pat_large(true);
252  break;
253 
254  case 5:
255  this->set_pwt(true);
256  this->set_pcd(false);
257  this->set_pat_large(true);
258  break;
259 
260  case 6:
261  this->set_pwt(false);
262  this->set_pcd(true);
263  this->set_pat_large(true);
264  break;
265 
266  case 7:
267  this->set_pwt(true);
268  this->set_pcd(true);
269  this->set_pat_large(true);
270  break;
271  };
272 }
273 
274 void
276 { *m_pte = 0; }
uintptr_t integer_pointer
bool pwt() const noexcept
expects(rbx)
void set_pat_index_4k(pat_index_type index)
void set_nx(bool enabled) noexcept
page_table_entry_x64(gsl::not_null< pointer > pte) noexcept
bool rw() const noexcept
void set_us(bool enabled) noexcept
void set_dirty(bool enabled) noexcept
void set_pat_large(bool enabled) noexcept
void set_pcd(bool enabled) noexcept
bool pat_4k() const noexcept
void set_pat_4k(bool enabled) noexcept
bool present() const noexcept
void set_phys_addr(integer_pointer addr) noexcept
void clear() noexcept
void set_present(bool enabled) noexcept
bool pcd() const noexcept
bool dirty() const noexcept
void uint64_t uint64_t uint64_t *rdx noexcept
uint64_t pat_index_type
void set_global(bool enabled) noexcept
auto index(const T virt, const F from)
constexpr const auto addr
Definition: cpuid_x64.h:80
void set_accessed(bool enabled) noexcept
bool pat_large() const noexcept
auto clear_bit(T t, B b) noexcept
Definition: bitmanip.h:36
bool ps() const noexcept
auto set_bit(T t, B b) noexcept
Definition: bitmanip.h:30
auto get_bits(T t, M m) noexcept
Definition: bitmanip.h:65
pat_index_type pat_index_large() const noexcept
void set_rw(bool enabled) noexcept
bool accessed() const noexcept
pat_index_type pat_index_4k() const noexcept
Definition: cache_x64.h:31
void set_pat_index_large(pat_index_type index)
auto is_bit_set(T t, B b) noexcept
Definition: bitmanip.h:48
void set_pwt(bool enabled) noexcept
integer_pointer phys_addr() const noexcept
bool nx() const noexcept
auto set_bits(T t, M m, V v) noexcept
Definition: bitmanip.h:72
void set_ps(bool enabled) noexcept
bool global() const noexcept
bool us() const noexcept