aboutsummaryrefslogtreecommitdiff
path: root/src/task.rs
blob: a4a9044df98989dcbff789d780f000a2c849f35e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! Helpers to program the task state segment.
//! See Intel 3a, Chapter 7

pub use crate::segmentation;
use core::arch::asm;

/// Returns the current value of the task register.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn tr() -> segmentation::SegmentSelector {
    let segment: u16;
    asm!("str {0:x}",
        out(reg) segment,
        options(att_syntax, nostack, nomem, preserves_flags));
    segmentation::SegmentSelector::from_raw(segment)
}

/// Loads the task register.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn load_tr(sel: segmentation::SegmentSelector) {
    asm!("ltr {0:x}",
        in(reg) sel.bits(),
        options(att_syntax, nostack, nomem, preserves_flags));
}