Skip to content

Commit be47bfc

Browse files
a sort of initial skeleton for cpuid.
1 parent 9ed8d0a commit be47bfc

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ pub struct VirtualMachineConfig {
301301
virtual_devices: DeviceMap,
302302
physical_devices: PhysicalDeviceConfig,
303303
memory: u64, // in MB
304+
override_cpu_name: bool
304305
}
305306

306307
impl VirtualMachineConfig {
@@ -323,6 +324,7 @@ impl VirtualMachineConfig {
323324
virtual_devices: DeviceMap::default(),
324325
physical_devices: physical_devices,
325326
memory: memory,
327+
override_cpu_name: todo!()
326328
})
327329
}
328330

@@ -363,6 +365,11 @@ impl VirtualMachineConfig {
363365
pub fn bsp_id(&self) -> percore::CoreId {
364366
self.cpus[0]
365367
}
368+
369+
370+
pub fn override_cpu_name(&self) -> bool {
371+
self.override_cpu_name
372+
}
366373
}
367374

368375
/// A virtual machine
@@ -406,7 +413,7 @@ impl VirtualMachine {
406413
// Prepare the portion of per-core local apic state that is stored at the
407414
// VM level (as needed for logical addressing)
408415
let mut logical_apic_states = BTreeMap::new();
409-
for core in config.cpus.iter() {
416+
for core in config.cpus.as_slice() {
410417
logical_apic_states.insert(
411418
core.clone(),
412419
virtdev::lapic::LogicalApicState::default(),

0 commit comments

Comments
 (0)