|
1 | 1 | use crate::error::Result;
|
2 | 2 | use crate::{vcpu, vmexit};
|
3 | 3 |
|
| 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 | + |
4 | 17 | pub fn emulate_cpuid(
|
5 |
| - _vcpu: &mut vcpu::VCpu, |
| 18 | + vcpu: &mut vcpu::VCpu, |
6 | 19 | guest_cpu: &mut vmexit::GuestCpuState,
|
7 | 20 | ) -> 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 | + |
8 | 41 | //FIXME: for now just use the actual cpuid
|
9 | 42 | let mut res = raw_cpuid::native_cpuid::cpuid_count(
|
10 | 43 | guest_cpu.rax as u32,
|
|
0 commit comments