-
Notifications
You must be signed in to change notification settings - Fork 254
/
__asm.h
executable file
·171 lines (142 loc) · 3.81 KB
/
__asm.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright 2019 Google LLC
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
// assembly function declaration
#include <aehd_types.h>
extern u16 aehd_read_ldt(void);
extern void aehd_load_ldt(u16 sel);
extern void load_TR_desc(void);
extern u16 aehd_read_tr(void);
extern void aehd_load_tr(u16 sel);
#pragma warning(disable : 4210)
#define savesegment(seg, value) \
extern u16 save_##seg ##_segment(void); \
value = save_##seg ##_segment()
#define loadsegment(seg, value) \
extern u16 load_##seg ##_segment(u16 sel); \
load_##seg ##_segment(value)
extern void load_gs_index(u16 value);
extern void __asm_vmx_vcpu_run(void *vmx);
extern void __asm_vmx_handle_external_intr(size_t entry);
extern void __asm_svm_vcpu_run(void *svm);
extern void __int2(void);
extern void __int12(void);
//debug register
extern u64 __read_dr0();
extern u64 __read_dr1();
extern u64 __read_dr2();
extern u64 __read_dr3();
extern u64 __read_dr6();
extern u64 __read_dr7();
extern void __write_dr0(u64 val);
extern void __write_dr1(u64 val);
extern void __write_dr2(u64 val);
extern void __write_dr3(u64 val);
extern void __write_dr6(u64 val);
extern void __write_dr7(u64 val);
#define dr_read_case(regno) \
case regno: \
val = __read_dr##regno(); \
break
static __forceinline u64 __get_debugreg(int regno)
{
u64 val = 0;
switch (regno) {
dr_read_case(0);
dr_read_case(1);
dr_read_case(2);
dr_read_case(3);
dr_read_case(6);
dr_read_case(7);
default:
BUG();
}
return val;
}
#define get_debugreg(a, b) a = __get_debugreg(b)
#define dr_write_case(regno) \
case regno: \
__write_dr##regno(val); \
break
static __forceinline void set_debugreg(u64 val, int regno)
{
switch (regno) {
dr_write_case(0);
dr_write_case(1);
dr_write_case(2);
dr_write_case(3);
dr_write_case(6);
dr_write_case(7);
default:
BUG();
}
}
//mmx
extern void __asm_save_mm0(u64 *data);
extern void __asm_save_mm1(u64 *data);
extern void __asm_save_mm2(u64 *data);
extern void __asm_save_mm3(u64 *data);
extern void __asm_save_mm4(u64 *data);
extern void __asm_save_mm5(u64 *data);
extern void __asm_save_mm6(u64 *data);
extern void __asm_save_mm7(u64 *data);
extern void __asm_store_mm0(u64 *data);
extern void __asm_store_mm1(u64 *data);
extern void __asm_store_mm2(u64 *data);
extern void __asm_store_mm3(u64 *data);
extern void __asm_store_mm4(u64 *data);
extern void __asm_store_mm5(u64 *data);
extern void __asm_store_mm6(u64 *data);
extern void __asm_store_mm7(u64 *data);
//fpu
extern void __fninit(void);
extern void __fnstcw(u16 *fcw);
extern void __fnstsw(u16 *fcw);
extern void __fwait(void);
extern void __clts(void);
//bswap
extern void __bswap64(u64 *val);
extern void __bswap32(u32 *val);
#define read_cr0 __readcr0
#define read_cr3 __readcr3
#define read_cr4 __readcr4
#define write_cr4 __writecr4
#define stts() __writecr0(__readcr0() | X86_CR0_TS)
#define load_gdt(pdesc) _lgdt((void *)pdesc)
#define load_idt(pdesc) __lidt((void *)pdesc)
static __forceinline void cr4_set_bits(size_t mask)
{
size_t cr4 = __readcr4();
if ((cr4 | mask) != cr4)
{
cr4 |= mask;
__writecr4(cr4);
}
}
static __forceinline void cr4_clear_bits(size_t mask)
{
size_t cr4 = __readcr4();
if ((cr4 & ~mask) != cr4)
{
cr4 &= ~mask;
__writecr4(cr4);
}
}
static __forceinline void native_store_gdt(void *gdt)
{
_sgdt(gdt);
}
static __forceinline void native_store_idt(void *idt)
{
__sidt(idt);
}
extern void __asm_invvpid(int ext, void *op);
extern void __asm_invept(int ext, void *op);