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
28
29
30
31
32
//! Task state segment register

use core::arch::asm;
use core::mem::size_of;

use crate::arch::gdt::SegmentSelector;

/// Task state segment register, that holds information about hardware tasks.
///
/// Its fields are mostly unused nowdays, with the exception of esp0 and ss0.
/// These fields containt the kernel stack pointer and segment used for interrupt handling.
///
/// - <https://wiki.osdev.org/Task_State_Segment>
#[repr(C, align(4))]
#[allow(non_snake_case)]
pub struct TaskStateSegment {
    // TODO: BSB B1 - Create task state register
    __: [u8; 108],
}

const _: () = assert!(size_of::<TaskStateSegment>() == 108);

impl TaskStateSegment {
    /// Create a new task state segment
    pub const fn new() -> Self {
        todo!() // BSB B1 - Create task state register
    }
}

pub unsafe fn load_tss(sel: SegmentSelector) {
    asm!("ltr {0:x}", in(reg) u16::from(sel), options(nostack, nomem));
}