1
+ use crate :: apic:: get_local_apic;
1
2
use crate :: error:: Result ;
3
+ use crate :: vcpu:: VCpu ;
2
4
use crate :: { vcpu, vmexit} ;
3
- use raw_cpuid:: CpuIdResult ;
4
5
use arrayvec:: ArrayVec ;
5
- use core:: convert:: TryInto ;
6
6
use bitfield:: bitfield;
7
- use crate :: apic:: get_local_apic;
8
- use crate :: vcpu:: VCpu ;
7
+ use bitflags:: _core:: num:: flt2dec:: to_shortest_exp_str;
8
+ use core:: convert:: TryInto ;
9
+ use raw_cpuid:: CpuIdResult ;
9
10
10
11
const CPUID_NAME : u32 = 0 ;
11
12
const CPUID_MODEL_FAMILY_STEPPING : u32 = 1 ;
@@ -25,13 +26,13 @@ const MAX_CPUID_INPUT: u32 = 0x80000008;
25
26
//todo //CPUID leaves above 2 and below 80000000H are visible only when
26
27
// // IA32_MISC_ENABLE[bit 22] has its default value of 0.
27
28
28
-
29
-
30
-
31
-
32
- fn get_cpu_id_result ( vcpu : & vcpu :: VCpu , eax_in : u32 , ecx_in : u32 ) -> CpuIdResult {
33
- const NAME_CREATION_ERROR_MESSAGE : & ' static str = "Somehow bytes was not actually a 12 element array" ;
34
-
29
+ fn get_cpu_id_result (
30
+ vcpu : & vcpu :: VCpu ,
31
+ eax_in : u32 ,
32
+ ecx_in : u32 ,
33
+ ) -> CpuIdResult {
34
+ const NAME_CREATION_ERROR_MESSAGE : & ' static str =
35
+ "Somehow bytes was not actually a 12 element array" ;
35
36
36
37
let mut actual = raw_cpuid:: native_cpuid:: cpuid_count (
37
38
guest_cpu. rax as u32 ,
@@ -99,8 +100,6 @@ bitfield! {
99
100
max_addressable_ids_physical, _: 26 , 31 ;
100
101
}
101
102
102
-
103
-
104
103
fn intel_cache_topo ( mut actual : CpuIdResult ) -> CpuIdResult {
105
104
let mut cache_topo_eax = IntelCoreCacheTopologyEaxRes ( actual. eax ) ;
106
105
cache_topo_eax. set_max_addressable_ids_logical ( todo ! ( "waiting on apics" ) ) ;
@@ -111,7 +110,7 @@ fn intel_cache_topo(mut actual: CpuIdResult) -> CpuIdResult {
111
110
//no changes should be required for these:
112
111
ebx : actual. ebx ,
113
112
ecx : actual. ecx ,
114
- edx : actual. edx
113
+ edx : actual. edx ,
115
114
}
116
115
}
117
116
@@ -151,12 +150,14 @@ bitfield! {
151
150
}
152
151
153
152
fn cpuid_model_family_stepping ( actual : CpuIdResult ) -> CpuIdResult {
154
- let family_model_stepping = IntelTypeFamilyModelSteppingIDEaxRes ( actual. eax ) ;
153
+ let family_model_stepping =
154
+ IntelTypeFamilyModelSteppingIDEaxRes ( actual. eax ) ;
155
155
//we can change family_model_stepping, but for now just use actual.
156
156
let eax = family_model_stepping. 0 ;
157
157
let mut brand_cflush_max_initial = BrandCFlushMaxIDsInitialAPIC ( actual. ebx ) ;
158
158
brand_cflush_max_initial. set_apic_id ( todo ! ( "Waiting on virtual APICs" ) ) ;
159
- brand_cflush_max_initial. set_max_processor_ids ( todo ! ( "Waiting on virtual APICs" ) ) ;
159
+ brand_cflush_max_initial
160
+ . set_max_processor_ids ( todo ! ( "Waiting on virtual APICs" ) ) ;
160
161
let ebx = brand_cflush_max_initial. 0 ;
161
162
let mut features_ecx = FeatureInformationECX ( actual. ecx ) ;
162
163
let mut features_edx = FeatureInformationEDX ( actual. edx ) ;
@@ -173,21 +174,22 @@ fn cpuid_model_family_stepping(actual: CpuIdResult) -> CpuIdResult {
173
174
features_ecx. set_hypervisor ( 0 ) ;
174
175
let ecx = features_ecx. 0 ;
175
176
let edx = features_edx. 0 ;
176
- CpuIdResult {
177
- eax,
178
- ebx,
179
- ecx,
180
- edx
181
- }
177
+ CpuIdResult { eax, ebx, ecx, edx }
182
178
}
183
179
184
180
fn cpuid_name ( vcpu : & VCpu , actual : CpuIdResult ) -> CpuIdResult {
185
181
if vcpu. vm . read ( ) . config . override_cpu_name ( ) {
186
182
let cpu_name = "MythrilCPU__" ;
187
- let bytes = cpu_name. chars ( ) . map ( |char| char as u8 ) . collect :: < ArrayVec < [ u8 ; 12 ] > > ( ) ;
188
- let first_bytes: [ u8 ; 4 ] = bytes[ 0 ..4 ] . try_into ( ) . expect ( NAME_CREATION_ERROR_MESSAGE ) ;
189
- let second_bytes: [ u8 ; 4 ] = bytes[ 4 ..8 ] . try_into ( ) . expect ( NAME_CREATION_ERROR_MESSAGE ) ;
190
- let third_bytes: [ u8 ; 4 ] = bytes[ 8 ..12 ] . try_into ( ) . expect ( NAME_CREATION_ERROR_MESSAGE ) ;
183
+ let bytes = cpu_name
184
+ . chars ( )
185
+ . map ( |char| char as u8 )
186
+ . collect :: < ArrayVec < [ u8 ; 12 ] > > ( ) ;
187
+ let first_bytes: [ u8 ; 4 ] =
188
+ bytes[ 0 ..4 ] . try_into ( ) . expect ( NAME_CREATION_ERROR_MESSAGE ) ;
189
+ let second_bytes: [ u8 ; 4 ] =
190
+ bytes[ 4 ..8 ] . try_into ( ) . expect ( NAME_CREATION_ERROR_MESSAGE ) ;
191
+ let third_bytes: [ u8 ; 4 ] =
192
+ bytes[ 8 ..12 ] . try_into ( ) . expect ( NAME_CREATION_ERROR_MESSAGE ) ;
191
193
return CpuIdResult {
192
194
eax : MAX_CPUID_INPUT ,
193
195
ebx : u32:: from_le_bytes ( first_bytes) ,
0 commit comments