Struct hal_x86_64::segment::Selector
source · pub struct Selector(/* private fields */);
Expand description
A segment selector.
These values are stored in a segmentation register (ss
, cs
, ds
, es
,
gs
, or fs
) to select the current segment in that register. A selector
consists of two bits indicating the privilege ring of that segment, a bit
indicating whether it selects a GDT or LDT, and a 5-bit index into GDT
or LDT indicating which segment is selected.
Refer to sections 3.4.3 and 3.4.4 in Vol. 3A of the Intel® 64 and IA-32 Architectures Developer’s Manual for details.
Implementations§
source§impl Selector
impl Selector
sourcepub const fn from_bits(bits: u16) -> Self
pub const fn from_bits(bits: u16) -> Self
Constructs a new instance of Self
from the provided raw bits.
sourcepub fn with<T>(self, field: Pack16<T, Self>, value: T) -> Selfwhere
T: FromBits<u16>,
pub fn with<T>(self, field: Pack16<T, Self>, value: T) -> Selfwhere
T: FromBits<u16>,
Packs the bit representation of value
into self
at the bit
range designated by field
, returning a new bitfield.
sourcepub fn set<T>(&mut self, field: Pack16<T, Self>, value: T) -> &mut Selfwhere
T: FromBits<u16>,
pub fn set<T>(&mut self, field: Pack16<T, Self>, value: T) -> &mut Selfwhere
T: FromBits<u16>,
Packs the bit representation of value
into self
at the range
designated by field
, mutating self
in place.
sourcepub fn get<T>(self, field: Pack16<T, Self>) -> Twhere
T: FromBits<u16>,
pub fn get<T>(self, field: Pack16<T, Self>) -> Twhere
T: FromBits<u16>,
Unpacks the bit range represented by field
from self
, and
converts it into a T
-typed value.
Panics
This method panics if self
does not contain a valid bit
pattern for a T
-typed value, as determined by T
’s
FromBits::try_from_bits
implementation.
sourcepub fn try_get<T>(self, field: Pack16<T, Self>) -> Result<T, T::Error>where
T: FromBits<u16>,
pub fn try_get<T>(self, field: Pack16<T, Self>) -> Result<T, T::Error>where
T: FromBits<u16>,
Unpacks the bit range represented by field
from self
and attempts to convert it into a T
-typed value.
Returns
Ok(T)
if aT
-typed value could be constructed from the bits insrc
Err(T::Error)
ifsrc
does not contain a valid bit pattern for aT
-typed value, as determined byT
’s [FromBits::try_from_bits
implementation.
sourcepub fn assert_valid()
pub fn assert_valid()
Asserts that all the packing specs for this type are valid.
This is intended to be used in unit tests.
sourcepub fn display_ascii(&self) -> impl Display
pub fn display_ascii(&self) -> impl Display
Returns a value that formats this bitfield in a multi-line format, using only ASCII characters.
This is equivalent to formatting this bitfield using a {}
display specifier, but will never use Unicode box-drawing
characters, even when an upstream formatter uses the {:#}
fmt::Display
specifier. This is intended for use on platforms
where Unicode box drawing characters are never available.
sourcepub fn display_unicode(&self) -> impl Display
pub fn display_unicode(&self) -> impl Display
Returns a value that formats this bitfield in a multi-line format, always using Unicode box-drawing characters.
This is equivalent to formatting this bitfield using a {:#}
format specifier, but will always use Unicode box-drawing
characters, even when an upstream formatter uses the {}
fmt::Display
specifier.
source§impl Selector
impl Selector
pub const fn null() -> Self
pub const fn from_index(u: u16) -> Self
pub const fn from_raw(u: u16) -> Self
pub fn ring(self) -> Ring
sourcepub fn table(&self) -> DescriptorTable
pub fn table(&self) -> DescriptorTable
Returns which descriptor table (GDT or LDT) this selector references.
Note
This will never return cpu::DescriptorTable::Idt
, as a segment
selector only references segmentation table descriptors.
sourcepub const fn index(&self) -> u16
pub const fn index(&self) -> u16
Returns the index into the LDT or GDT this selector refers to.
pub fn set_gdt(&mut self) -> &mut Self
pub fn set_ldt(&mut self) -> &mut Self
pub fn set_ring(&mut self, ring: Ring) -> &mut Self
pub fn set_index(&mut self, index: u16) -> &mut Self
sourcepub fn current_cs() -> Self
pub fn current_cs() -> Self
Returns the current selector in the cs
(code segment) register
sourcepub unsafe fn set_fs(self)
pub unsafe fn set_fs(self)
Sets self
as the current segment in the general-purpose data segment
register fs
(“File Segment”).
Notes
Unlike the cs
, ss
, ds
, and es
registers, the fs
register need
not be zeroed in long mode, and can be used by the operating system. In
particular, the gs
and fs
registers may be useful for storing
thread- or CPU-local data.
Safety
lol
sourcepub unsafe fn set_gs(self)
pub unsafe fn set_gs(self)
Sets self
as the current segment in the general-purpose data segment
register gs
(“G Segment”).
Notes
Unlike the cs
, ss
, ds
, and es
registers, the gs
register need
not be zeroed in long mode, and can be used by the operating system. In
particular, the gs
and fs
registers may be useful for storing
thread- or CPU-local data.
Safety
lol