Skip to content

Commit 223e53d

Browse files
a sort of initial skeleton for cpuid.
1 parent 74e20ba commit 223e53d

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

mythril/src/emulate/cpuid.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
use crate::error::Result;
22
use crate::{vcpu, vmexit};
33

4+
//Used https://c9x.me/x86/html/file_module_x86_id_45.html as guid for implementing this.
5+
const CPUID_NAME: u32 = 0;
6+
const CPUID_MODEL_FAMILY_STEPPING: u32 = 1;
7+
const CPUID_CACHE_TLB_INFO: u32 = 2;
8+
const INTEL_CORE_CACHE_TOPOLOGY : u32 = 4;
9+
const CPUID_BRAND_STRING_1: u32 = 0x80000002;
10+
const CPUID_BRAND_STRING_2: u32 = 0x80000003;
11+
const CPUID_BRAND_STRING_3: u32 = 0x80000004;
12+
//todo //CPUID leaves above 2 and below 80000000H are visible only when
13+
// // IA32_MISC_ENABLE[bit 22] has its default value of 0.
14+
15+
16+
417
pub fn emulate_cpuid(
5-
_vcpu: &mut vcpu::VCpu,
18+
vcpu: &mut vcpu::VCpu,
619
guest_cpu: &mut vmexit::GuestCpuState,
720
) -> Result<()> {
21+
let eax = guest_cpu.rax as u32;
22+
23+
match eax {
24+
CPUID_NAME => {
25+
if vcpu.vm.read().config.override_cpu_name(){
26+
todo!()
27+
}
28+
},
29+
CPUID_MODEL_FAMILY_STEPPING => todo!(),
30+
INTEL_CORE_CACHE_TOPOLOGY => {
31+
_vcpu.vm.read().config.cpus()
32+
}
33+
CPUID_BRAND_STRING_1 => todo!(),
34+
CPUID_BRAND_STRING_2 => todo!(),
35+
_ => {
36+
// dbg!(eax);
37+
// todo!("If you are reading this then a invalid arg was passed to cpuid. In principle we should prob fault here or something, but this probably indicates a bug.")
38+
}
39+
}
40+
841
//FIXME: for now just use the actual cpuid
942
let mut res = raw_cpuid::native_cpuid::cpuid_count(
1043
guest_cpu.rax as u32,

mythril/src/vm.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ pub struct VirtualMachineConfig {
223223
virtual_devices: DeviceMap,
224224
physical_devices: PhysicalDeviceConfig,
225225
memory: u64, // in MB
226+
override_cpu_name: bool
226227
}
227228

228229
impl VirtualMachineConfig {
@@ -238,11 +239,12 @@ impl VirtualMachineConfig {
238239
physical_devices: PhysicalDeviceConfig,
239240
) -> VirtualMachineConfig {
240241
VirtualMachineConfig {
241-
cpus: cpus,
242+
cpus,
242243
images: vec![],
243244
virtual_devices: DeviceMap::default(),
244-
physical_devices: physical_devices,
245-
memory: memory,
245+
physical_devices,
246+
memory,
247+
override_cpu_name: false
246248
}
247249
}
248250

@@ -280,6 +282,11 @@ impl VirtualMachineConfig {
280282
pub fn cpus(&self) -> &Vec<percore::CoreId> {
281283
&self.cpus
282284
}
285+
286+
287+
pub fn override_cpu_name(&self) -> bool {
288+
self.override_cpu_name
289+
}
283290
}
284291

285292
/// A virtual machine

0 commit comments

Comments
 (0)