Skip to content

Commit ad2f3b3

Browse files
authored
Merge pull request #357 from rust-osdev/iopb
tss: Initialize iopb to be empty instead of zero
2 parents c79b9d3 + da97c1a commit ad2f3b3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Diff for: src/structures/tss.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Provides a type for the task state segment structure.
22
33
use crate::VirtAddr;
4+
use core::mem::size_of;
45

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

2425
impl TaskStateSegment {
25-
/// Creates a new TSS with zeroed privilege and interrupt stack table and a zero
26-
/// `iomap_base`.
26+
/// Creates a new TSS with zeroed privilege and interrupt stack table and an
27+
/// empty I/O-Permission Bitmap.
28+
///
29+
/// As we always set the TSS segment limit to
30+
/// `size_of::<TaskStateSegment>() - 1`, this means that `iomap_base` is
31+
/// initialized to `size_of::<TaskStateSegment>()`.
2732
#[inline]
2833
pub const fn new() -> TaskStateSegment {
2934
TaskStateSegment {
3035
privilege_stack_table: [VirtAddr::zero(); 3],
3136
interrupt_stack_table: [VirtAddr::zero(); 7],
32-
iomap_base: 0,
37+
iomap_base: size_of::<TaskStateSegment>() as u16,
3338
reserved_1: 0,
3439
reserved_2: 0,
3540
reserved_3: 0,
3641
reserved_4: 0,
3742
}
3843
}
3944
}
45+
46+
#[cfg(test)]
47+
mod tests {
48+
use super::*;
49+
50+
#[test]
51+
pub fn check_tss_size() {
52+
// Per the SDM, the minimum size of a TSS is 0x68 bytes, giving a
53+
// minimum limit of 0x67.
54+
assert_eq!(size_of::<TaskStateSegment>(), 0x68);
55+
}
56+
}

0 commit comments

Comments
 (0)