|
| 1 | +use core::fmt::{Debug, Formatter, Result}; |
| 2 | + |
| 3 | +/// VM instruction error numbers. (SDM Vol. 3C, Section 30.4) |
| 4 | +pub struct VmxInstructionError(u32); |
| 5 | + |
| 6 | +impl VmxInstructionError { |
| 7 | + pub fn as_str(&self) -> &str { |
| 8 | + match self.0 { |
| 9 | + 0 => "OK", |
| 10 | + 1 => "VMCALL executed in VMX root operation", |
| 11 | + 2 => "VMCLEAR with invalid physical address", |
| 12 | + 3 => "VMCLEAR with VMXON pointer", |
| 13 | + 4 => "VMLAUNCH with non-clear VMCS", |
| 14 | + 5 => "VMRESUME with non-launched VMCS", |
| 15 | + 6 => "VMRESUME after VMXOFF (VMXOFF and VMXON between VMLAUNCH and VMRESUME)", |
| 16 | + 7 => "VM entry with invalid control field(s)", |
| 17 | + 8 => "VM entry with invalid host-state field(s)", |
| 18 | + 9 => "VMPTRLD with invalid physical address", |
| 19 | + 10 => "VMPTRLD with VMXON pointer", |
| 20 | + 11 => "VMPTRLD with incorrect VMCS revision identifier", |
| 21 | + 12 => "VMREAD/VMWRITE from/to unsupported VMCS component", |
| 22 | + 13 => "VMWRITE to read-only VMCS component", |
| 23 | + 15 => "VMXON executed in VMX root operation", |
| 24 | + 16 => "VM entry with invalid executive-VMCS pointer", |
| 25 | + 17 => "VM entry with non-launched executive VMCS", |
| 26 | + 18 => "VM entry with executive-VMCS pointer not VMXON pointer (when attempting to deactivate the dual-monitor treatment of SMIs and SMM)", |
| 27 | + 19 => "VMCALL with non-clear VMCS (when attempting to activate the dual-monitor treatment of SMIs and SMM)", |
| 28 | + 20 => "VMCALL with invalid VM-exit control fields", |
| 29 | + 22 => "VMCALL with incorrect MSEG revision identifier (when attempting to activate the dual-monitor treatment of SMIs and SMM)", |
| 30 | + 23 => "VMXOFF under dual-monitor treatment of SMIs and SMM", |
| 31 | + 24 => "VMCALL with invalid SMM-monitor features (when attempting to activate the dual-monitor treatment of SMIs and SMM)", |
| 32 | + 25 => "VM entry with invalid VM-execution control fields in executive VMCS (when attempting to return from SMM)", |
| 33 | + 26 => "VM entry with events blocked by MOV SS", |
| 34 | + 28 => "Invalid operand to INVEPT/INVVPID", |
| 35 | + _ => "[INVALID]", |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +impl From<u32> for VmxInstructionError { |
| 41 | + fn from(value: u32) -> Self { |
| 42 | + Self(value) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +impl Debug for VmxInstructionError { |
| 47 | + fn fmt(&self, f: &mut Formatter) -> Result { |
| 48 | + write!(f, "VmxInstructionError({}, {:?})", self.0, self.as_str()) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +numeric_enum_macro::numeric_enum! { |
| 53 | +#[repr(u32)] |
| 54 | +#[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 55 | +#[allow(non_camel_case_types)] |
| 56 | +/// VMX basic exit reasons. (SDM Vol. 3D, Appendix C) |
| 57 | +pub enum VmxExitReason { |
| 58 | + EXCEPTION_NMI = 0, |
| 59 | + EXTERNAL_INTERRUPT = 1, |
| 60 | + TRIPLE_FAULT = 2, |
| 61 | + INIT = 3, |
| 62 | + SIPI = 4, |
| 63 | + SMI = 5, |
| 64 | + OTHER_SMI = 6, |
| 65 | + INTERRUPT_WINDOW = 7, |
| 66 | + NMI_WINDOW = 8, |
| 67 | + TASK_SWITCH = 9, |
| 68 | + CPUID = 10, |
| 69 | + GETSEC = 11, |
| 70 | + HLT = 12, |
| 71 | + INVD = 13, |
| 72 | + INVLPG = 14, |
| 73 | + RDPMC = 15, |
| 74 | + RDTSC = 16, |
| 75 | + RSM = 17, |
| 76 | + VMCALL = 18, |
| 77 | + VMCLEAR = 19, |
| 78 | + VMLAUNCH = 20, |
| 79 | + VMPTRLD = 21, |
| 80 | + VMPTRST = 22, |
| 81 | + VMREAD = 23, |
| 82 | + VMRESUME = 24, |
| 83 | + VMWRITE = 25, |
| 84 | + VMOFF = 26, |
| 85 | + VMON = 27, |
| 86 | + CR_ACCESS = 28, |
| 87 | + DR_ACCESS = 29, |
| 88 | + IO_INSTRUCTION = 30, |
| 89 | + MSR_READ = 31, |
| 90 | + MSR_WRITE = 32, |
| 91 | + INVALID_GUEST_STATE = 33, |
| 92 | + MSR_LOAD_FAIL = 34, |
| 93 | + MWAIT_INSTRUCTION = 36, |
| 94 | + MONITOR_TRAP_FLAG = 37, |
| 95 | + MONITOR_INSTRUCTION = 39, |
| 96 | + PAUSE_INSTRUCTION = 40, |
| 97 | + MCE_DURING_VMENTRY = 41, |
| 98 | + TPR_BELOW_THRESHOLD = 43, |
| 99 | + APIC_ACCESS = 44, |
| 100 | + VIRTUALIZED_EOI = 45, |
| 101 | + GDTR_IDTR = 46, |
| 102 | + LDTR_TR = 47, |
| 103 | + EPT_VIOLATION = 48, |
| 104 | + EPT_MISCONFIG = 49, |
| 105 | + INVEPT = 50, |
| 106 | + RDTSCP = 51, |
| 107 | + PREEMPTION_TIMER = 52, |
| 108 | + INVVPID = 53, |
| 109 | + WBINVD = 54, |
| 110 | + XSETBV = 55, |
| 111 | + APIC_WRITE = 56, |
| 112 | + RDRAND = 57, |
| 113 | + INVPCID = 58, |
| 114 | + VMFUNC = 59, |
| 115 | + ENCLS = 60, |
| 116 | + RDSEED = 61, |
| 117 | + PML_FULL = 62, |
| 118 | + XSAVES = 63, |
| 119 | + XRSTORS = 64, |
| 120 | + PCONFIG = 65, |
| 121 | + SPP_EVENT = 66, |
| 122 | + UMWAIT = 67, |
| 123 | + TPAUSE = 68, |
| 124 | + LOADIWKEY = 69, |
| 125 | +} |
| 126 | +} |
0 commit comments