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