test_crs_intel_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 <test.h>
24 
25 using namespace intel_x64;
26 
31 
32 extern "C" uint64_t
34 { return g_cr0; }
35 
36 extern "C" void
37 __write_cr0(uint64_t val) noexcept
38 { g_cr0 = val; }
39 
40 extern "C" uint64_t
42 { return g_cr2; }
43 
44 extern "C" void
45 __write_cr2(uint64_t val) noexcept
46 { g_cr2 = val; }
47 
48 extern "C" uint64_t
50 { return g_cr3; }
51 
52 extern "C" void
53 __write_cr3(uint64_t val) noexcept
54 { g_cr3 = val; }
55 
56 extern "C" uint64_t
58 { return g_cr4; }
59 
60 extern "C" void
61 __write_cr4(uint64_t val) noexcept
62 { g_cr4 = val; }
63 
64 void
65 intrinsics_ut::test_cr0_intel_x64()
66 {
67  cr0::set(0xFFFFFFFFU);
68  this->expect_true(cr0::get() == 0xFFFFFFFFU);
69 
70  cr0::dump();
71 
72  cr0::set(0x0U);
73  this->expect_true(cr0::get() == 0x0U);
74 }
75 
76 void
77 intrinsics_ut::test_cr0_intel_x64_protection_enable()
78 {
81 
84 
85  this->expect_true(cr0::get() == 0x0);
86 }
87 
88 void
89 intrinsics_ut::test_cr0_intel_x64_monitor_coprocessor()
90 {
93 
96 
97  this->expect_true(cr0::get() == 0x0);
98 }
99 
100 void
101 intrinsics_ut::test_cr0_intel_x64_emulation()
102 {
103  cr0::emulation::set(true);
105 
106  cr0::emulation::set(false);
108 
109  this->expect_true(cr0::get() == 0x0);
110 }
111 
112 void
113 intrinsics_ut::test_cr0_intel_x64_task_switched()
114 {
117 
120 
121  this->expect_true(cr0::get() == 0x0);
122 }
123 
124 void
125 intrinsics_ut::test_cr0_intel_x64_extension_type()
126 {
129 
132 
133  this->expect_true(cr0::get() == 0x0);
134 }
135 
136 void
137 intrinsics_ut::test_cr0_intel_x64_numeric_error()
138 {
141 
144 
145  this->expect_true(cr0::get() == 0x0);
146 }
147 
148 void
149 intrinsics_ut::test_cr0_intel_x64_write_protect()
150 {
153 
156 
157  this->expect_true(cr0::get() == 0x0);
158 }
159 
160 void
161 intrinsics_ut::test_cr0_intel_x64_alignment_mask()
162 {
165 
168 
169  this->expect_true(cr0::get() == 0x0);
170 }
171 
172 void
173 intrinsics_ut::test_cr0_intel_x64_not_write_through()
174 {
177 
180 
181  this->expect_true(cr0::get() == 0x0);
182 }
183 
184 void
185 intrinsics_ut::test_cr0_intel_x64_cache_disable()
186 {
189 
192 
193  this->expect_true(cr0::get() == 0x0);
194 }
195 
196 void
197 intrinsics_ut::test_cr0_intel_x64_paging()
198 {
199  cr0::paging::set(true);
200  this->expect_true(cr0::paging::get());
201 
202  cr0::paging::set(false);
204 
205  this->expect_true(cr0::get() == 0x0);
206 }
207 
208 void
209 intrinsics_ut::test_cr2_intel_x64()
210 {
211  cr2::set(0x100U);
212  this->expect_true(cr2::get() == 0x100U);
213 }
214 
215 void
216 intrinsics_ut::test_cr3_intel_x64()
217 {
218  cr3::set(0x100U);
219  this->expect_true(cr3::get() == 0x100U);
220 }
221 
222 void
223 intrinsics_ut::test_cr4_intel_x64()
224 {
225  cr4::set(0xFFFFFFFFU);
226  this->expect_true(cr4::get() == 0xFFFFFFFFU);
227 
228  cr4::dump();
229 
230  cr4::set(0x0U);
231  this->expect_true(cr4::get() == 0x0U);
232 }
233 
234 void
235 intrinsics_ut::test_cr4_intel_x64_v8086_mode_extensions()
236 {
239 
242 
243  this->expect_true(cr4::get() == 0x0);
244 }
245 
246 void
247 intrinsics_ut::test_cr4_intel_x64_protected_mode_virtual_interrupts()
248 {
251 
254 
255  this->expect_true(cr4::get() == 0x0);
256 }
257 
258 void
259 intrinsics_ut::test_cr4_intel_x64_time_stamp_disable()
260 {
263 
266 
267  this->expect_true(cr4::get() == 0x0);
268 }
269 
270 void
271 intrinsics_ut::test_cr4_intel_x64_debugging_extensions()
272 {
275 
278 
279  this->expect_true(cr4::get() == 0x0);
280 }
281 
282 void
283 intrinsics_ut::test_cr4_intel_x64_page_size_extensions()
284 {
287 
290 
291  this->expect_true(cr4::get() == 0x0);
292 }
293 
294 void
295 intrinsics_ut::test_cr4_intel_x64_physical_address_extensions()
296 {
299 
302 
303  this->expect_true(cr4::get() == 0x0);
304 }
305 
306 void
307 intrinsics_ut::test_cr4_intel_x64_machine_check_enable()
308 {
311 
314 
315  this->expect_true(cr4::get() == 0x0);
316 }
317 
318 void
319 intrinsics_ut::test_cr4_intel_x64_page_global_enable()
320 {
323 
326 
327  this->expect_true(cr4::get() == 0x0);
328 }
329 
330 void
331 intrinsics_ut::test_cr4_intel_x64_performance_monitor_counter_enable()
332 {
335 
338 
339  this->expect_true(cr4::get() == 0x0);
340 }
341 
342 void
343 intrinsics_ut::test_cr4_intel_x64_osfxsr()
344 {
345  cr4::osfxsr::set(true);
346  this->expect_true(cr4::osfxsr::get());
347 
348  cr4::osfxsr::set(false);
350 
351  this->expect_true(cr4::get() == 0x0);
352 }
353 
354 void
355 intrinsics_ut::test_cr4_intel_x64_osxmmexcpt()
356 {
357  cr4::osxmmexcpt::set(true);
359 
360  cr4::osxmmexcpt::set(false);
362 
363  this->expect_true(cr4::get() == 0x0);
364 }
365 
366 void
367 intrinsics_ut::test_cr4_intel_x64_vmx_enable_bit()
368 {
371 
374 
375  this->expect_true(cr4::get() == 0x0);
376 }
377 
378 void
379 intrinsics_ut::test_cr4_intel_x64_smx_enable_bit()
380 {
383 
386 
387  this->expect_true(cr4::get() == 0x0);
388 }
389 
390 void
391 intrinsics_ut::test_cr4_intel_x64_fsgsbase_enable_bit()
392 {
395 
398 
399  this->expect_true(cr4::get() == 0x0);
400 }
401 
402 void
403 intrinsics_ut::test_cr4_intel_x64_pcid_enable_bit()
404 {
407 
410 
411  this->expect_true(cr4::get() == 0x0);
412 }
413 
414 void
415 intrinsics_ut::test_cr4_intel_x64_osxsave()
416 {
417  cr4::osxsave::set(true);
419 
420  cr4::osxsave::set(false);
422 
423  this->expect_true(cr4::get() == 0x0);
424 }
425 
426 void
427 intrinsics_ut::test_cr4_intel_x64_smep_enable_bit()
428 {
431 
434 
435  this->expect_true(cr4::get() == 0x0);
436 }
437 
438 void
439 intrinsics_ut::test_cr4_intel_x64_smap_enable_bit()
440 {
443 
446 
447  this->expect_true(cr4::get() == 0x0);
448 }
449 
450 void
451 intrinsics_ut::test_cr4_intel_x64_protection_key_enable_bit()
452 {
455 
458 
459  this->expect_true(cr4::get() == 0x0);
460 }
void __write_cr2(uint64_t val) noexcept
void set(bool val) noexcept
void set(bool val) noexcept
void set(bool val) noexcept
auto get() noexcept
cr0::value_type g_cr0
void set(T val) noexcept
void __write_cr0(uint64_t val) noexcept
cr4::value_type g_cr4
auto get() noexcept
void dump() noexcept
void set(bool val) noexcept
Definition: crs_intel_x64.h:76
uint64_t __read_cr4(void) noexcept
void set(bool val) noexcept
void __write_cr4(uint64_t val) noexcept
void set(T val) noexcept
void set(bool val) noexcept
auto get() noexcept
void set(bool val) noexcept
uint64_t value_type
Definition: crs_intel_x64.h:46
void set(bool val) noexcept
void set(bool val) noexcept
void uint64_t uint64_t uint64_t *rdx noexcept
uint64_t __read_cr3(void) noexcept
void set(bool val) noexcept
uint64_t __read_cr0(void) noexcept
void set(bool val) noexcept
auto get() noexcept
void set(bool val) noexcept
void set(bool val) noexcept
Definition: crs_intel_x64.h:89
uint64_t __read_cr2(void) noexcept
cr2::value_type g_cr2
void set(bool val) noexcept
void dump() noexcept
void set(bool val) noexcept
Definition: crs_intel_x64.h:63
void set(bool val) noexcept
void set(bool val) noexcept
void set(bool val) noexcept
void set(T val) noexcept
uint64_t value_type
#define expect_false(a)
cr3::value_type g_cr3
void set(T val) noexcept
Definition: crs_intel_x64.h:52
void __write_cr3(uint64_t val) noexcept
void set(bool val) noexcept
void set(bool val) noexcept
uint64_t value_type
void set(bool val) noexcept
auto get() noexcept
#define expect_true(a)
uint64_t value_type
auto get() noexcept
Definition: crs_intel_x64.h:48