Struct TaskStateSegment

Source
#[repr(C, packed(1))]
pub struct TaskStateSegment { pub reserved: u32, pub rsp: [u64; 3], pub reserved2: u64, pub ist: [u64; 7], pub reserved3: u64, pub reserved4: u16, pub iomap_base: u16, }
Expand description

Although hardware task-switching is not supported in 64-bit mode, a 64-bit task state segment (TSS) must exist.

The TSS holds information important to 64-bit mode and that is not directly related to the task-switch mechanism. This information includes:

§RSPn

The full 64-bit canonical forms of the stack pointers (RSP) for privilege levels 0-2. RSPx is loaded in whenever an interrupt causes the CPU to change RPL to x. Note on a syscall entry this field is not used to load a stack, setting the stack there is the handler’s responsibility (however when using the int instruction in user-space, we load the stack from RSPn).

§ISTn

The full 64-bit canonical forms of the interrupt stack table (IST) pointers. You can set an interrupt vector to use an IST entry in the Interrupt Descriptor Table by giving it a number from 0 - 7. If 0 is selected, then the IST mechanism is not used. If any other number is selected then when that interrupt vector is called the CPU will load RSP from the corresponding IST entry. This is useful for handling things like double faults, since you don’t have to worry about switching stacks; the CPU will do it for you.

§I/O map base address

The 16-bit offset to the I/O permission bit map from the 64-bit TSS base.

The operating system must create at least one 64-bit TSS after activating IA-32e mode. It must execute the LTR instruction (in 64-bit mode) to load the TR register with a pointer to the 64-bit TSS responsible for both 64-bitmode programs and compatibility-mode programs (load_tr).

Fields§

§reserved: u32§rsp: [u64; 3]

The full 64-bit canonical forms of the stack pointers (RSP) for privilege levels 0-2.

§reserved2: u64§ist: [u64; 7]

The full 64-bit canonical forms of the interrupt stack table (IST) pointers.

§reserved3: u64§reserved4: u16§iomap_base: u16

The 16-bit offset to the I/O permission bit map from the 64-bit TSS base.

Implementations§

Source§

impl TaskStateSegment

Source

pub const fn new() -> TaskStateSegment

Creates a new empty TSS.

Source

pub fn set_rsp(&mut self, pl: Ring, stack_ptr: u64)

Sets the stack pointer (stack_ptr) to be used for when an interrupt causes the CPU to change RPL to pl.

Source

pub fn set_ist(&mut self, index: usize, stack_ptr: u64)

Sets the stack pointer (stack_ptr) to be used when an interrupt with a corresponding IST entry in the Interrupt Descriptor table pointing to the given index is raised.

Trait Implementations§

Source§

impl Clone for TaskStateSegment

Source§

fn clone(&self) -> TaskStateSegment

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 Debug for TaskStateSegment

Source§

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

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

impl Default for TaskStateSegment

Source§

fn default() -> TaskStateSegment

Returns the “default value” for a type. Read more
Source§

impl Copy for TaskStateSegment

Auto Trait Implementations§

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.