Struct hal_x86_64::cpu::msr::Msr

source ·
pub struct Msr<V = u64> { /* private fields */ }
Expand description

An x86_64 Model-Specific Register (MSR).

Model-specific registers are used to configure features of the CPU that may not be available on all x86 processors, such as memory type-range, sysenter/sysexit, local APIC, et cetera. MSRs are available on P6 and later x86 processors (and are present on all 64-bit x86 CPUs). The Msr::has_msrs method can be used to check if the CPU has MSRs. Note that this method does not check whether a particular MSR is available.

See sandpile.org’s MSR list for a list of documented MSRs and their values.

Typed MSRs

MSRs may be accessed as raw u64 values (using Msr::read_raw and Msr::write_raw), or may be constructed with a type parameter implementing the [mycelium_util::bits::FromBits] trait, which is automatically converted to and from its binary representation when reading/writing to the MSR.

When a typed representation of a MSR’s value is available, a special constructor is provided for accessing that MSR in a typed manner.

MSR Constructors

This type provides a number of constructors which construct a Msr for accessing a specific model-specific register by name. The following constructors are currently provided:

Implementations§

source§

impl Msr

source

pub fn has_msrs() -> bool

Returns true if this processor has MSRs.

Notes

This does not check whether the given MSR number is valid on this platform.

source

pub fn try_new(num: u32) -> Option<Self>

Returns a new Msr for reading/writing to the given MSR number, or None if this CPU does not support MSRs.

Notes

This does not check whether the given MSR number is valid on this platform.

source

pub fn new(num: u32) -> Self

Returns a new Msr for reading/writing to the given MSR number.

Panics

If this CPU does not support MSRs.

Notes

This does not check whether the given MSR number is valid on this platform.

source

pub const fn ia32_apic_base() -> Self

Returns a Msr for reading and writing to the IA32_APIC_BASE model-specific register.

This register has MSR number 0x1B, and stores the base address of the local APIC memory-mapped configuration area.

source

pub const fn ia32_gs_base() -> Self

Returns a Msr for reading and writing to the IA32_GS_BASE model-specific register.

This register has MSR number 0xC0000101, and contains the base address of the GS segment.

source

pub const fn ia32_efer() -> Msr<Efer>

Returns a Msr for reading and writing to the IA32_EFER (Extended Flags Enable Register) MSR.

The EFER register has MSR number 0xC0000080, and contains flags for enabling the SYSCALL and SYSRET instructions, and for entering and exiting long mode, and for enabling features related to long mode.

Flags for the IA32_EFER MSR are represented by the Efer type.

source§

impl<V: FromBits<u64>> Msr<V>

source

pub fn try_read(self) -> Result<V, V::Error>

Attempt to read a V-typed value from the MSR, returning an error if that value is an invalid bit pattern for a V-typed value.

Returns
  • Ok(V)if aV`-typed value was successfully read from the MSR.
  • Err(V::Error) if the value read from the MSR was an invalid bit pattern for a V, as determined by V’s implementation of the [FromBits::try_from_bits]) method.
source

pub fn read(self) -> V

Read a V-typed value from the MSR.

Panics

If the bits in the MSR are an invalid bit pattern for a V-typed value (as determined by V’s implementation of the [FromBits::try_from_bits]) method).

source

pub unsafe fn write(self, value: V)

Write a value to this MSR.

Safety

The caller is responsible for ensuring that writing the provided value to this MSR doesn’t violate memory safety.

source

pub unsafe fn update(self, f: impl FnOnce(V) -> V)

Read this MSR’s current value, modify it using a closure, and write back the modified value.

This is a convenience method for cases where some bits in a MSR should be changed while leaving other values in place.

Safety

The caller is responsible for ensuring that writing the provided value to this MSR doesn’t violate memory safety.

source§

impl<V> Msr<V>

source

pub fn read_raw(self) -> u64

Reads this MSR, returning the raw u64 value.

source

pub unsafe fn write_raw(self, value: u64)

Writes the given raw u64 value to this MSR.

Safety

The caller is responsible for ensuring that writing the provided value to this MSR doesn’t violate memory safety.

Trait Implementations§

source§

impl<V> Clone for Msr<V>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<V> Debug for Msr<V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<V> Display for Msr<V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<V> PartialEq for Msr<V>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<V> Copy for Msr<V>

source§

impl<V> Eq for Msr<V>

Auto Trait Implementations§

§

impl<V> RefUnwindSafe for Msr<V>

§

impl<V> Send for Msr<V>

§

impl<V> Sync for Msr<V>

§

impl<V> Unpin for Msr<V>

§

impl<V> UnwindSafe for Msr<V>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.