vmcs_intel_x64_vmm_state.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 
23 
24 #include <memory_manager/pat_x64.h>
26 
27 using namespace x64;
28 using namespace intel_x64;
29 
33 
34 static auto gdt_setup = false;
35 
37 {
38  if (!gdt_setup)
39  {
45 
46  g_gdt.set_base(1, 0);
47  g_gdt.set_base(2, 0);
48  g_gdt.set_base(3, 0);
49  g_gdt.set_base(4, 0);
50  g_gdt.set_base(5, reinterpret_cast<gdt_x64::base_type>(&g_tss));
51 
52  g_gdt.set_limit(1, 0xFFFFFFFF);
53  g_gdt.set_limit(2, 0xFFFFFFFF);
54  g_gdt.set_limit(3, 0xFFFFFFFF);
55  g_gdt.set_limit(4, 0xFFFFFFFF);
56  g_gdt.set_limit(5, sizeof(g_tss));
57 
58  gdt_setup = true;
59  }
60 
61  m_cs_index = 1;
62  m_ss_index = 2;
63  m_fs_index = 3;
64  m_gs_index = 4;
65  m_tr_index = 5;
66 
67  m_cs = gsl::narrow_cast<segment_register::type>(m_cs_index << 3);
68  m_ss = gsl::narrow_cast<segment_register::type>(m_ss_index << 3);
69  m_fs = gsl::narrow_cast<segment_register::type>(m_fs_index << 3);
70  m_gs = gsl::narrow_cast<segment_register::type>(m_gs_index << 3);
71  m_tr = gsl::narrow_cast<segment_register::type>(m_tr_index << 3);
72 
73  m_cr0 = 0;
77  m_cr0 |= cr0::numeric_error::mask;
78  m_cr0 |= cr0::write_protect::mask;
79  m_cr0 |= cr0::paging::mask;
80 
81  m_cr3 = g_pt->cr3();
82 
83  m_cr4 = 0;
93  m_cr4 |= cr4::osfxsr::mask;
94  m_cr4 |= cr4::osxmmexcpt::mask;
96 
98  m_cr4 |= cr4::osxsave::mask;
99 
102 
105 
106  m_rflags = 0;
107 
108  m_ia32_pat_msr = x64::pat::pat_value;
109 
110  m_ia32_efer_msr = 0;
111  m_ia32_efer_msr |= msrs::ia32_efer::lme::mask;
112  m_ia32_efer_msr |= msrs::ia32_efer::lma::mask;
113  m_ia32_efer_msr |= msrs::ia32_efer::nxe::mask;
114 }
#define g_pt
tss_x64 g_tss
constexpr const auto ring0_cs_descriptor
Definition: x64.h:84
constexpr const auto mask
Definition: cpuid_x64.h:85
void set_base(index_type index, base_type base)
Definition: gdt_x64.h:293
void set_access_rights(index_type index, access_rights_type access_rights)
Definition: gdt_x64.h:501
void set_limit(index_type index, limit_type limit)
Definition: gdt_x64.h:416
constexpr const auto pat_value
Definition: pat_x64.h:51
constexpr const auto ring0_tr_descriptor
Definition: x64.h:88
constexpr const auto ring0_gs_descriptor
Definition: x64.h:87
constexpr const auto ring0_ss_descriptor
Definition: x64.h:85
Definition: cache_x64.h:31
constexpr const auto ring0_fs_descriptor
Definition: x64.h:86
idt_x64 g_idt
gdt_x64 g_gdt