x86_64/structures/
mod.rs

1//! Representations of various x86 specific structures and descriptor tables.
2
3use crate::VirtAddr;
4
5pub mod gdt;
6
7pub mod idt;
8
9#[cfg(feature = "memory_encryption")]
10pub mod mem_encrypt;
11pub mod paging;
12pub mod port;
13pub mod tss;
14
15/// A struct describing a pointer to a descriptor table (GDT / IDT).
16/// This is in a format suitable for giving to 'lgdt' or 'lidt'.
17#[derive(Debug, Clone, Copy)]
18#[repr(C, packed(2))]
19pub struct DescriptorTablePointer {
20    /// Size of the DT in bytes - 1.
21    pub limit: u16,
22    /// Pointer to the memory region containing the DT.
23    pub base: VirtAddr,
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use std::mem::size_of;
30
31    #[test]
32    pub fn check_descriptor_pointer_size() {
33        // Per the SDM, a descriptor pointer has to be 2+8=10 bytes
34        assert_eq!(size_of::<DescriptorTablePointer>(), 10);
35        // Make sure that we can reference a pointer's limit
36        let p = DescriptorTablePointer {
37            limit: 5,
38            base: VirtAddr::zero(),
39        };
40        let _: &u16 = &p.limit;
41    }
42}