-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathVcpu.hpp
More file actions
84 lines (69 loc) · 1.64 KB
/
Copy pathVcpu.hpp
File metadata and controls
84 lines (69 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include <iostream>
#include <WinHvPlatform.h>
#include <windows.h>
class Vm;
class Vcpu
{
public:
enum RegName {
VCPU_REG_RAX = WHvX64RegisterRax,
VCPU_REG_RCX = WHvX64RegisterRcx,
VCPU_REG_RDX = WHvX64RegisterRdx,
VCPU_REG_RBX = WHvX64RegisterRbx,
VCPU_REG_RSP = WHvX64RegisterRsp,
VCPU_REG_RBP = WHvX64RegisterRbp,
VCPU_REG_RSI = WHvX64RegisterRsi,
VCPU_REG_RDI = WHvX64RegisterRdi,
VCPU_REG_R8 = WHvX64RegisterR8,
VCPU_REG_R9 = WHvX64RegisterR9,
VCPU_REG_R10 = WHvX64RegisterR10,
VCPU_REG_R11 = WHvX64RegisterR11,
VCPU_REG_R12 = WHvX64RegisterR12,
VCPU_REG_R13 = WHvX64RegisterR13,
VCPU_REG_R14 = WHvX64RegisterR14,
VCPU_REG_R15 = WHvX64RegisterR15,
VCPU_REG_RIP = WHvX64RegisterRip,
VCPU_REG_RFLAGS = WHvX64RegisterRflags,
VCPU_SEG_FS = WHvX64RegisterFs,
VCPU_SEG_GS = WHvX64RegisterGs,
};
struct Reg {
RegName name;
union {
uint64_t value;
uint64_t *ptr;
};
};
#define VCPU_REGS_ENTRY_GET(reg, val) { VCPU_REG_##reg, { (vcpu_regvalue_t)val } }
#define VCPU_REGS_ENTRY_SET(reg, val) { VCPU_REG_##reg, { val } }
struct SysRegs {
uint64_t cr3;
uint64_t gdt_base;
uint16_t gdt_limit;
uint64_t idt_base;
uint16_t idt_limit;
uint64_t tss_base;
uint16_t tss_limit;
};
private:
WHV_RUN_VP_EXIT_CONTEXT exit_context;
Vm& m_vm;
UINT32 m_id;
bool m_running;
public:
Vcpu(Vm& vm, UINT32 id);
~Vcpu();
void
get_regs(Reg *regs, int count);
void
set_regs(Reg *regs, int count);
void
init_sysregs(SysRegs *sysregs);
void
set_segbase(RegName seg, uint64_t base);
void
run();
void
stop();
};