Skip to content

Commit

Permalink
Add additional tests for TSS entry
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Richey <[email protected]>
  • Loading branch information
josephlr committed Apr 15, 2022
1 parent ae6385d commit 71fe5b3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions testing/src/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
(
Expand All @@ -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);
}

0 comments on commit 71fe5b3

Please sign in to comment.