vcpu.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 <exception.h>
23 #include <vcpu/vcpu.h>
24 
25 vcpu::vcpu(vcpuid::type id, std::unique_ptr<debug_ring> dr) :
26  m_id(id),
27  m_debug_ring(std::move(dr)),
28  m_is_running(false),
29  m_is_initialized(false)
30 {
31  if ((id & vcpuid::reserved) != 0)
32  throw std::invalid_argument("invalid vcpuid");
33 
34  if (!m_debug_ring)
35  m_debug_ring = std::make_unique<debug_ring>(id);
36 }
37 
38 void
40 {
41  (void) data;
42 
43  m_is_initialized = true;
44 }
45 
46 void
48 {
49  (void) data;
50 
51  if (m_is_running)
52  this->hlt();
53 
54  m_is_initialized = false;
55 }
56 
57 void
59 {
60  (void) data;
61 
62  m_is_running = true;
63 }
64 
65 void
67 {
68  (void) data;
69 
70  m_is_running = false;
71 }
72 
73 void
75 { m_debug_ring->write(str); }
uint64_t type
Definition: vcpuid.h:31
int64_t unsigned long void * data
virtual void run(user_data *data=nullptr)
Definition: vcpu.cpp:58
void uint64_t uint64_t uint64_t *rdx noexcept
virtual void init(user_data *data=nullptr)
Definition: vcpu.cpp:39
constexpr const auto reserved
Definition: vcpuid.h:33
virtual void hlt(user_data *data=nullptr)
Definition: vcpu.cpp:66
vcpu(vcpuid::type id, std::unique_ptr< debug_ring > dr=nullptr)
Definition: vcpu.cpp:25
debug_ring * dr
virtual vcpuid::type id() const
Definition: vcpu.h:209
virtual void write(const std::string &str) noexcept
Definition: vcpu.cpp:74
virtual void fini(user_data *data=nullptr)
Definition: vcpu.cpp:47