x86/
task.rs

1//! Helpers to program the task state segment.
2//! See Intel 3a, Chapter 7
3
4pub use crate::segmentation;
5use core::arch::asm;
6
7/// Returns the current value of the task register.
8///
9/// # Safety
10/// Needs CPL 0.
11pub unsafe fn tr() -> segmentation::SegmentSelector {
12    let segment: u16;
13    asm!("str {0:x}",
14        out(reg) segment,
15        options(att_syntax, nostack, nomem, preserves_flags));
16    segmentation::SegmentSelector::from_raw(segment)
17}
18
19/// Loads the task register.
20///
21/// # Safety
22/// Needs CPL 0.
23pub unsafe fn load_tr(sel: segmentation::SegmentSelector) {
24    asm!("ltr {0:x}",
25        in(reg) sel.bits(),
26        options(att_syntax, nostack, nomem, preserves_flags));
27}