pub struct LocalApic {Show 19 fields
id: u32,
tpr: u8,
svr: u32,
esr: u32,
isr: [u32; 8],
irr: [u32; 8],
lvt: [u32; 6],
icr_low: u32,
icr_high: u32,
initial_count: u32,
current_count: u32,
divide_config: u32,
timer_armed: bool,
timer_fraction: u64,
apic_bus_hz: u64,
tsc_fraction: u64,
tsc: u64,
tsc_deadline: u64,
tsc_deadline_armed: bool,
}Expand description
Complete state of a guest local APIC.
Fields§
§id: u32APIC identifier (ID register, 8 significant bits in field 31:24).
tpr: u8Task priority (TPR), bits 7:0 significant.
svr: u32Spurious register (SVR).
esr: u32Error status register.
isr: [u32; 8]In-Service registers (8 x 32 bits = 256 vectors).
irr: [u32; 8]In-Request registers (8 x 32 bits = 256 vectors).
lvt: [u32; 6]LVT: timer, thermal, perf, LINT0, LINT1, error.
icr_low: u32ICR low/high.
icr_high: u32§initial_count: u32Initial and current timer count.
current_count: u32§divide_config: u32Timer divider.
timer_armed: boolTrue while a one-shot/periodic count is running.
timer_fraction: u64Sub-tick remainder of the divide scaling, in APIC timer input units.
apic_bus_hz: u64Nominal APIC timer bus frequency used by LocalApic::advance_tsc.
tsc_fraction: u64Remainder of the TSC-to-bus-tick conversion, in TSC cycles.
tsc: u64Monotonic model TSC, advanced by LocalApic::advance.
tsc_deadline: u64Absolute TSC-deadline value written to IA32_TSC_DEADLINE.
tsc_deadline_armed: boolTrue while the TSC-deadline timer is armed.
Implementations§
Source§impl LocalApic
impl LocalApic
Sourcepub const fn new(apic_id: u32) -> Self
pub const fn new(apic_id: u32) -> Self
Creates a local APIC for apic_id, LVTs masked, SVR enabled.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
True if at least one vector is pending.
Sourcepub fn pending_vector(&self) -> Option<u8>
pub fn pending_vector(&self) -> Option<u8>
Highest-priority deliverable vector, without modifying the state.
Sourcepub fn service(&mut self) -> Option<u8>
pub fn service(&mut self) -> Option<u8>
Moves the deliverable vector from the IRR to the ISR and returns it.
Sourcepub fn in_service(&self) -> bool
pub fn in_service(&self) -> bool
True if a vector is in service.
Sourcepub const fn timer_vector(&self) -> u8
pub const fn timer_vector(&self) -> u8
Vector programmed in the LVT timer entry.
Sourcepub const fn timer_masked(&self) -> bool
pub const fn timer_masked(&self) -> bool
True if the LVT timer entry is masked.
Sourcepub const fn timer_mode(&self) -> TimerMode
pub const fn timer_mode(&self) -> TimerMode
Operating mode of the timer, decoded from the LVT entry.
Sourcepub const fn timer_divide(&self) -> u32
pub const fn timer_divide(&self) -> u32
Current divide value decoded from the divide configuration register.
Sourcepub const fn timer_armed(&self) -> bool
pub const fn timer_armed(&self) -> bool
True while either count-based or TSC-deadline timer is running.
Sourcepub const fn current_count(&self) -> u32
pub const fn current_count(&self) -> u32
Current timer count (0 once a one-shot timer has expired).
Sourcepub const fn initial_count(&self) -> u32
pub const fn initial_count(&self) -> u32
Last value written to the initial-count register.
Sourcepub const fn tsc_deadline(&self) -> u64
pub const fn tsc_deadline(&self) -> u64
Absolute TSC-deadline value last written to IA32_TSC_DEADLINE.
Sourcepub fn arm(&mut self, initial_count: u32)
pub fn arm(&mut self, initial_count: u32)
Programs the timer with initial_count (0 disables it).
In one-shot and periodic modes this loads the current count and starts counting. In TSC-deadline and reserved modes the register is stored but the count-based timer stays stopped, matching the architectural rule that the initial count is ignored in TSC-deadline mode.
Sourcepub fn set_tsc_deadline(&mut self, deadline: u64)
pub fn set_tsc_deadline(&mut self, deadline: u64)
Writes the IA32_TSC_DEADLINE MSR.
A zero value disables the deadline. The value is absolute in model-TSC units; a deadline already in the past raises the LVT vector immediately (unless masked). Writes are ignored for the timer state unless the LVT entry is in TSC-deadline mode.
Sourcepub fn set_tsc(&mut self, tsc: u64)
pub fn set_tsc(&mut self, tsc: u64)
Aligns the model TSC with a caller-known absolute value.
The model starts at zero and is normally advanced by
Self::advance; this hook lets a caller that knows the guest TSC
epoch seed it once, so absolute IA32_TSC_DEADLINE values can be
interpreted.
Sourcepub fn advance(&mut self, cycles: u64)
pub fn advance(&mut self, cycles: u64)
Advances the timer by cycles APIC timer input units.
The caller passes the elapsed time already expressed in APIC timer input units (bus ticks before the divide). Count-based modes divide it by the configured divide value and decrement the current count; TSC-deadline mode compares the model TSC with the programmed deadline. Expiry raises the LVT vector through the IRR, except when the LVT entry is masked.
This is the raw model helper, kept for tests and for callers that
already work in bus ticks. A caller holding host TSC cycles and a TSC
frequency must use Self::advance_tsc, which performs the
conversion.
Sourcepub const fn apic_bus_hz(&self) -> u64
pub const fn apic_bus_hz(&self) -> u64
Nominal APIC timer bus frequency, in hertz.
Sourcepub fn set_apic_bus_hz(&mut self, bus_hz: u64)
pub fn set_apic_bus_hz(&mut self, bus_hz: u64)
Changes the nominal APIC timer bus frequency.
The conversion remainder is reset because its unit depends on the bus
frequency. A zero value disables the count-based conversion of
Self::advance_tsc (the model TSC still advances).
Sourcepub fn advance_tsc(&mut self, cycles: u64, tsc_hz: u64)
pub fn advance_tsc(&mut self, cycles: u64, tsc_hz: u64)
Advances the model by host TSC cycles, converting to APIC ticks.
tsc_hz is the host TSC frequency in hertz. The count-based timer is
decremented by:
bus_ticks = (cycles * apic_bus_hz + remainder) / tsc_hz
where remainder is carried across calls so that the average
conversion rate stays exact even when a call spans less than one bus
tick. The model TSC used by TSC-deadline mode advances by the raw
cycles, without conversion: a deadline is an absolute TSC value.
A zero tsc_hz or a zero bus frequency disables the count conversion
(the model TSC still advances and deadlines are still detected), so a
caller without a detected frequency degrades gracefully instead of
dividing by zero. Arithmetic saturates.
Sourcefn advance_count(&mut self, cycles: u64)
fn advance_count(&mut self, cycles: u64)
Decrements the count-based timer by the divided elapsed cycles.
Sourcefn raise_timer_vector(&mut self)
fn raise_timer_vector(&mut self)
Raises the LVT vector unless the entry is masked.
Sourcefn expire_tsc_deadline(&mut self)
fn expire_tsc_deadline(&mut self)
Completes a TSC-deadline expiry.
Sourcefn write_lvt_timer(&mut self, value: u32)
fn write_lvt_timer(&mut self, value: u32)
Applies a write to the LVT timer entry, keeping the timer state consistent with the newly selected mode.
Sourcepub fn mmio_read(&self, offset: usize) -> u32
pub fn mmio_read(&self, offset: usize) -> u32
Reads an MMIO register (address relative to the APIC page).
Unimplemented offsets return 0 (guest access tolerated).
Sourcepub fn mmio_write(&mut self, offset: usize, value: u32)
pub fn mmio_write(&mut self, offset: usize, value: u32)
Writes an MMIO register. Unimplemented offsets are ignored.
Sourcefn write_icr_low(&mut self, value: u32)
fn write_icr_low(&mut self, value: u32)
Handles an ICR-low write: fixed IPI to self or NMI.
Sourcepub fn x2apic_read(&self, msr: u32) -> Option<u64>
pub fn x2apic_read(&self, msr: u32) -> Option<u64>
Reads an x2APIC MSR. Returns None outside the 0x800..=0x8FF range.
Sourcepub fn x2apic_write(&mut self, msr: u32, value: u64) -> bool
pub fn x2apic_write(&mut self, msr: u32, value: u64) -> bool
Writes an x2APIC MSR. Returns false if the MSR is not modeled.
Trait Implementations§
impl Copy for LocalApic
impl Eq for LocalApic
impl StructuralPartialEq for LocalApic
Auto Trait Implementations§
impl Forget for LocalApic
impl Freeze for LocalApic
impl Move for LocalApic
impl RefUnwindSafe for LocalApic
impl Send for LocalApic
impl Sync for LocalApic
impl Unpin for LocalApic
impl UnsafeUnpin for LocalApic
impl UnwindSafe for LocalApic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more