Skip to content

Commit

Permalink
Merge pull request #357 from rust-osdev/iopb
Browse files Browse the repository at this point in the history
tss: Initialize iopb to be empty instead of zero
  • Loading branch information
josephlr authored Mar 26, 2022
2 parents c79b9d3 + da97c1a commit ad2f3b3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/structures/tss.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Provides a type for the task state segment structure.
use crate::VirtAddr;
use core::mem::size_of;

/// In 64-bit mode the TSS holds information that is not
/// directly related to the task-switch mechanism,
Expand All @@ -22,18 +23,34 @@ pub struct TaskStateSegment {
}

impl TaskStateSegment {
/// Creates a new TSS with zeroed privilege and interrupt stack table and a zero
/// `iomap_base`.
/// Creates a new TSS with zeroed privilege and interrupt stack table and an
/// empty I/O-Permission Bitmap.
///
/// As we always set the TSS segment limit to
/// `size_of::<TaskStateSegment>() - 1`, this means that `iomap_base` is
/// initialized to `size_of::<TaskStateSegment>()`.
#[inline]
pub const fn new() -> TaskStateSegment {
TaskStateSegment {
privilege_stack_table: [VirtAddr::zero(); 3],
interrupt_stack_table: [VirtAddr::zero(); 7],
iomap_base: 0,
iomap_base: size_of::<TaskStateSegment>() as u16,
reserved_1: 0,
reserved_2: 0,
reserved_3: 0,
reserved_4: 0,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
pub fn check_tss_size() {
// Per the SDM, the minimum size of a TSS is 0x68 bytes, giving a
// minimum limit of 0x67.
assert_eq!(size_of::<TaskStateSegment>(), 0x68);
}
}

0 comments on commit ad2f3b3

Please sign in to comment.