pub struct CpuState {}Expand description
Architectural state of one vCPU at an instruction boundary.
General-purpose registers are stored in the hardware encoding order
(rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8 … r15), so that
gpr[n] is register number n in a ModRM byte.
Fields§
§gpr: [u64; 16]General-purpose registers in encoding order.
rip: u64Instruction pointer (an offset inside CS).
rflags: u64RFLAGS as the guest sees it. KVM hides the TF bit it sets for single-stepping, so this is the guest’s own view.
seg: [Segment; 6]Segment registers, indexed by SegReg.
cr0: u64CR0.
cr2: u64CR2 (last page-fault linear address).
cr3: u64CR3 (page-table root, plus PCID in the low 12 bits when CR4.PCIDE is set).
cr4: u64CR4.
cr8: u64CR8 (task priority).
efer: u64IA32_EFER.
gdt_base: u64GDTR base.
gdt_limit: u16GDTR limit.
idt_base: u64IDTR base.
idt_limit: u16IDTR limit.
tr: SegmentThe task register (its base locates the TSS, which holds the I/O permission bitmap).
Implementations§
Source§impl CpuState
impl CpuState
Sourcepub fn from_kvm(r: &kvm_regs, s: &kvm_sregs) -> CpuState
pub fn from_kvm(r: &kvm_regs, s: &kvm_sregs) -> CpuState
Builds a snapshot from the two structures KVM returns.
Sourcepub fn mode(&self) -> CpuMode
pub fn mode(&self) -> CpuMode
The CPU mode, worked out from CR0, EFER, RFLAGS and the CS descriptor.
Sourcepub fn cpl(&self) -> u8
pub fn cpl(&self) -> u8
Current privilege level (0 = most privileged, 3 = user).
The CPL is the DPL of the SS descriptor, which is what KVM itself uses. In real mode it is 0; in virtual-8086 mode it is 3.
Sourcepub fn page_table_root(&self) -> u64
pub fn page_table_root(&self) -> u64
The page-table root without the PCID / flag bits.
Sourcepub fn linear_rip(&self) -> u64
pub fn linear_rip(&self) -> u64
Linear address of the current instruction (CS.base + RIP, truncated to the address width of the mode).
Sourcepub fn effective_segment_base(&self, r: SegReg) -> u64
pub fn effective_segment_base(&self, r: SegReg) -> u64
Segment base as used by address generation: in 64-bit mode only FS and GS have a non-zero base.
Sourcepub fn linear_mask(&self) -> u64
pub fn linear_mask(&self) -> u64
Width of a linear address in this mode, as a mask.
Sourcepub fn stack_pointer(&self) -> u64
pub fn stack_pointer(&self) -> u64
The stack pointer, sized for the current stack segment.