test_idt_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 <gsl/gsl>
23 
24 #include <test.h>
25 #include <intrinsics/idt_x64.h>
26 
27 std::vector<idt_x64::interrupt_descriptor_type> g_idt =
28 {
29  0xFFFFFFFFFFFFFFFF,
30  0xFFFFFFFFFFFFFFFF,
31  0xFFFFFFFFFFFFFFFF,
32  0xFFFFFFFFFFFFFFFF
33 };
34 
36 
37 extern "C" void
39 { *idt_reg = g_idt_reg; }
40 
41 extern "C" void
43 { g_idt_reg = *idt_reg; }
44 
45 void
46 intrinsics_ut::test_idt_reg_set_get()
47 {
48  x64::idt::set(g_idt.data(), (4 << 3) - 1);
49 
50  this->expect_true(x64::idt::get().base == g_idt.data());
51  this->expect_true(x64::idt::get().limit == (4 << 3) - 1);
52 }
53 
54 void
55 intrinsics_ut::test_idt_reg_base_set_get()
56 {
57  x64::idt::base::set(g_idt.data());
58  this->expect_true(x64::idt::base::get() == g_idt.data());
59 }
60 
61 void
62 intrinsics_ut::test_idt_reg_limit_set_get()
63 {
64  x64::idt::limit::set((4 << 3) - 1);
65  this->expect_true(x64::idt::limit::get() == (4 << 3) - 1);
66 }
67 
68 void
69 intrinsics_ut::test_idt_constructor_no_size()
70 {
71  idt_x64 idt;
72 }
73 
74 void
75 intrinsics_ut::test_idt_constructor_zero_size()
76 {
77  this->expect_no_exception([&] { idt_x64{0}; });
78 }
79 
80 void
81 intrinsics_ut::test_idt_constructor_size()
82 {
83  idt_x64 idt{4};
84 
85  this->expect_true(idt.base() != 0);
86  this->expect_true(idt.limit() == (4 * sizeof(idt_x64::interrupt_descriptor_type)) - 1);
87 }
88 
89 void
90 intrinsics_ut::test_idt_base()
91 {
92  idt_x64 idt;
93  this->expect_true(idt.base() == reinterpret_cast<idt_x64::integer_pointer>(g_idt.data()));
94 }
95 
96 void
97 intrinsics_ut::test_idt_limit()
98 {
99  idt_x64 idt;
100  this->expect_true(idt.limit() == (4 * sizeof(idt_x64::interrupt_descriptor_type)) - 1);
101 }
std::vector< idt_x64::interrupt_descriptor_type > g_idt
void set(idt_reg_x64_t::limit_type limit) noexcept
Definition: idt_x64.h:121
idt_reg_x64_t g_idt_reg
auto get() noexcept
Definition: idt_x64.h:93
void set(idt_reg_x64_t::base_type base, idt_reg_x64_t::limit_type limit) noexcept
Definition: idt_x64.h:85
auto base() const
Definition: idt_x64.h:212
uint64_t interrupt_descriptor_type
Definition: idt_x64.h:160
#define expect_no_exception(f)
Definition: unittest.h:198
void __write_idt(idt_reg_x64_t *idt_reg) noexcept
auto get() noexcept
Definition: idt_x64.h:113
void uint64_t uint64_t uint64_t *rdx noexcept
uintptr_t integer_pointer
Definition: idt_x64.h:159
auto get() noexcept
Definition: idt_x64.h:77
void set(idt_reg_x64_t::base_type base) noexcept
Definition: idt_x64.h:101
#define expect_true(a)
auto limit() const
Definition: idt_x64.h:222
void __read_idt(idt_reg_x64_t *idt_reg) noexcept