1
- use crate :: apic:: get_local_apic;
2
1
use crate :: error:: Result ;
3
2
use crate :: vcpu:: VCpu ;
4
3
use crate :: { vcpu, vmexit} ;
5
4
use arrayvec:: ArrayVec ;
6
5
use bitfield:: bitfield;
7
- use bitflags:: _core:: num:: flt2dec:: to_shortest_exp_str;
8
6
use core:: convert:: TryInto ;
9
7
use raw_cpuid:: CpuIdResult ;
10
8
@@ -26,17 +24,18 @@ const MAX_CPUID_INPUT: u32 = 0x80000008;
26
24
//todo //CPUID leaves above 2 and below 80000000H are visible only when
27
25
// // IA32_MISC_ENABLE[bit 22] has its default value of 0.
28
26
27
+ const NAME_CREATION_ERROR_MESSAGE : & ' static str =
28
+ "Somehow bytes was not actually a 12 element array" ;
29
+
29
30
fn get_cpu_id_result (
30
31
vcpu : & vcpu:: VCpu ,
31
32
eax_in : u32 ,
32
33
ecx_in : u32 ,
33
34
) -> CpuIdResult {
34
- const NAME_CREATION_ERROR_MESSAGE : & ' static str =
35
- "Somehow bytes was not actually a 12 element array" ;
36
35
37
36
let mut actual = raw_cpuid:: native_cpuid:: cpuid_count (
38
- guest_cpu . rax as u32 ,
39
- guest_cpu . rcx as u32 ,
37
+ eax_in ,
38
+ ecx_in ,
40
39
) ;
41
40
42
41
match eax_in {
@@ -78,7 +77,7 @@ fn get_cpu_id_result(
78
77
}
79
78
}
80
79
CPUID_BRAND_STRING_1 ..=CPUID_BRAND_STRING_3 => {
81
- if vcpu. vm . read ( ) . config . override_cpu_name ( ) { todo ! ( "CPU Brand string not implemented yet" ) }
80
+ if vcpu. vm . config . override_cpu_name ( ) { todo ! ( "CPU Brand string not implemented yet" ) }
82
81
actual
83
82
}
84
83
_ => {
@@ -92,12 +91,12 @@ fn get_cpu_id_result(
92
91
bitfield ! {
93
92
pub struct IntelCoreCacheTopologyEaxRes ( u32 ) ;
94
93
impl Debug ;
95
- cache_type, _ : 4 , 0 ;
96
- cache_level, _ : 7 , 5 ;
97
- self_init_cache_level, _ : 8 ;
98
- fully_associative, _ : 9 ;
99
- max_addressable_ids_logical, _ : 14 , 25 ;
100
- max_addressable_ids_physical, _ : 26 , 31 ;
94
+ cache_type, set_cache_type : 4 , 0 ;
95
+ cache_level, set_cache_level : 7 , 5 ;
96
+ self_init_cache_level, set_self_init_cache_level : 8 ;
97
+ fully_associative, set_fully_associative : 9 ;
98
+ max_addressable_ids_logical, set_max_addressable_ids_logical : 14 , 25 ;
99
+ max_addressable_ids_physical, set_max_addressable_ids_physical : 26 , 31 ;
101
100
}
102
101
103
102
fn intel_cache_topo ( mut actual : CpuIdResult ) -> CpuIdResult {
@@ -130,23 +129,23 @@ bitfield! {
130
129
impl Debug ;
131
130
brand_idx, _: 7 , 0 ;
132
131
cflush, _: 15 , 8 ;
133
- max_processor_ids, _ : 23 , 16 ;
134
- apic_id, _ : 31 , 24 ;
132
+ max_processor_ids, set_max_processor_ids : 23 , 16 ;
133
+ apic_id, set_apic_id : 31 , 24 ;
135
134
}
136
135
137
136
bitfield ! {
138
137
pub struct FeatureInformationECX ( u32 ) ;
139
138
impl Debug ;
140
139
//there are a lot of features here, so only add the ones we care about for now.
141
- xsave, _ : 26 ;
142
- hypervissor , _ : 31 ;
140
+ xsave, set_xsave : 26 ;
141
+ hypervisor , set_hypervisor : 31 ;
143
142
}
144
143
145
144
bitfield ! {
146
145
pub struct FeatureInformationEDX ( u32 ) ;
147
146
impl Debug ;
148
147
//there are a lot of features here, so only add the ones we care about for now.
149
- mtrr, _ : 12 ;
148
+ mtrr, set_mtrr : 12 ;
150
149
}
151
150
152
151
fn cpuid_model_family_stepping ( actual : CpuIdResult ) -> CpuIdResult {
@@ -164,21 +163,21 @@ fn cpuid_model_family_stepping(actual: CpuIdResult) -> CpuIdResult {
164
163
// I would have made type safe bindings for this but then I saw how many fields there where...
165
164
166
165
// Disable MTRR
167
- features_edx. set_mtrr ( 0 ) ;
166
+ features_edx. set_mtrr ( false ) ;
168
167
169
168
// Disable XSAVE
170
169
// ecx &= !(1 << 26);
171
- features_ecx. set_xsave ( 0 ) ;
170
+ features_ecx. set_xsave ( false ) ;
172
171
173
172
// Hide hypervisor feature
174
- features_ecx. set_hypervisor ( 0 ) ;
173
+ features_ecx. set_hypervisor ( false ) ;
175
174
let ecx = features_ecx. 0 ;
176
175
let edx = features_edx. 0 ;
177
176
CpuIdResult { eax, ebx, ecx, edx }
178
177
}
179
178
180
179
fn cpuid_name ( vcpu : & VCpu , actual : CpuIdResult ) -> CpuIdResult {
181
- if vcpu. vm . read ( ) . config . override_cpu_name ( ) {
180
+ if vcpu. vm . config . override_cpu_name ( ) {
182
181
let cpu_name = "MythrilCPU__" ;
183
182
let bytes = cpu_name
184
183
. chars ( )
0 commit comments