diff --git a/testing/src/gdt.rs b/testing/src/gdt.rs index 2e8440642..28024da9e 100644 --- a/testing/src/gdt.rs +++ b/testing/src/gdt.rs @@ -20,6 +20,8 @@ lazy_static! { }; static ref GDT: (GlobalDescriptorTable, Selectors) = { let mut gdt = GlobalDescriptorTable::new(); + // Add an unused segment so we get a different value for CS + gdt.append(Descriptor::kernel_data_segment()); let code_selector = gdt.append(Descriptor::kernel_code_segment()); let tss_selector = gdt.append(Descriptor::tss_segment(&TSS)); ( @@ -41,9 +43,16 @@ pub fn init() { use x86_64::instructions::segmentation::{Segment, CS}; use x86_64::instructions::tables::load_tss; + // Make sure loading CS actually changes the value GDT.0.load(); - unsafe { - CS::set_reg(GDT.1.code_selector); - load_tss(GDT.1.tss_selector); - } + assert_ne!(CS::get_reg(), GDT.1.code_selector); + unsafe { CS::set_reg(GDT.1.code_selector) }; + assert_eq!(CS::get_reg(), GDT.1.code_selector); + + // Loading the TSS should mark the GDT entry as busy + let tss_idx: usize = GDT.1.tss_selector.index().into(); + let old_tss_entry = GDT.0.entries()[tss_idx].clone(); + unsafe { load_tss(GDT.1.tss_selector) }; + let new_tss_entry = GDT.0.entries()[tss_idx].clone(); + assert_ne!(old_tss_entry, new_tss_entry); }