-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to add iomap to TSS (take 2) #194
Open
Restioson
wants to merge
16
commits into
rust-osdev:master
Choose a base branch
from
Restioson:iomap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0e66d82
Add ability to add iomap to TSS
Restioson e17b928
formatting
Restioson 6cd1a99
doc & iomap limit calculation
Restioson d19a5ae
missed a cast :(
Restioson 5a0ffc2
expand on safety requirements
Restioson 2fef3bd
-1 after max
Restioson 05c0828
fmt
Restioson f13551e
slice for safety
Restioson c03a90a
error if base =/= expected base
Restioson a85c1e2
fmt (i always forget this...)
Restioson 9c30209
doc
Restioson 7e49ece
fmt
Restioson cfa2083
handle iomap before tss
Restioson 411b42b
use From instead of casts
Freax13 6667531
add Display impl for InvalidIoMap
Freax13 8e1d5f8
add an example for Descriptor::tss_segment_with_iomap
Freax13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
//! Provides a type for the task state segment structure. | ||
|
||
use crate::VirtAddr; | ||
use core::mem::size_of; | ||
use core::{ | ||
fmt::{self, Display}, | ||
mem::size_of, | ||
}; | ||
|
||
/// In 64-bit mode the TSS holds information that is not | ||
/// directly related to the task-switch mechanism, | ||
|
@@ -19,7 +22,8 @@ pub struct TaskStateSegment { | |
pub interrupt_stack_table: [VirtAddr; 7], | ||
reserved_3: u64, | ||
reserved_4: u16, | ||
/// The 16-bit offset to the I/O permission bit map from the 64-bit TSS base. | ||
/// The 16-bit offset to the I/O permission bit map from the 64-bit TSS base. It must not | ||
/// exceed `0xDFFF`. | ||
pub iomap_base: u16, | ||
} | ||
|
||
|
@@ -51,6 +55,65 @@ impl Default for TaskStateSegment { | |
} | ||
} | ||
|
||
/// The given IO permissions bitmap is invalid. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
pub enum InvalidIoMap { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to have a |
||
/// The IO permissions bitmap is before the TSS. It must be located after the TSS. | ||
IoMapBeforeTss, | ||
/// The IO permissions bitmap is too far from the TSS. It must be within `0xdfff` bytes of the | ||
/// start of the TSS. Note that if the IO permissions bitmap is located before the TSS, then | ||
/// `IoMapBeforeTss` will be returned instead. | ||
TooFarFromTss { | ||
/// The distance of the IO permissions bitmap from the beginning of the TSS. | ||
distance: usize, | ||
phil-opp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
/// The final byte of the IO permissions bitmap was not 0xff | ||
InvalidTerminatingByte { | ||
/// The byte found at the end of the IO permissions bitmap. | ||
byte: u8, | ||
}, | ||
/// The IO permissions bitmap exceeds the maximum length (8193). | ||
TooLong { | ||
/// The length of the IO permissions bitmap. | ||
len: usize, | ||
}, | ||
/// The `iomap_base` in the `TaskStateSegment` struct was not what was expected. | ||
InvalidBase { | ||
/// The expected `iomap_base` to be set in the `TaskStateSegment` struct. | ||
expected: u16, | ||
/// The actual `iomap_base` set in the `TaskStateSegment` struct. | ||
got: u16, | ||
}, | ||
} | ||
|
||
impl Display for InvalidIoMap { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match *self { | ||
InvalidIoMap::IoMapBeforeTss => { | ||
write!(f, "the IO permissions bitmap is before the TSS") | ||
} | ||
InvalidIoMap::TooFarFromTss { distance } => write!( | ||
f, | ||
"the IO permissions bitmap is too far from the TSS (distance {distance})" | ||
), | ||
InvalidIoMap::InvalidTerminatingByte { byte } => write!( | ||
f, | ||
"The final byte of the IO permissions bitmap was not 0xff ({byte}" | ||
), | ||
InvalidIoMap::TooLong { len } => { | ||
write!( | ||
f, | ||
"The IO permissions bitmap exceeds the maximum length ({len} > 8193)" | ||
) | ||
} | ||
InvalidIoMap::InvalidBase { expected, got } => write!( | ||
f, | ||
"the `iomap_base` in the `TaskStateSegment` struct was not what was expected (expected {expected}, got {got})" | ||
), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like how this makes the caller of this function have to make sure that the
tss
andiomap
are close enough to each other. Also idk if it's bad to put other data between thetss
andiomap
but personally I think it's better to have theiomap
go right after thetss
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's certainly a trade-off, but I think it's one worth making. The big advantage of this approach is that we don't force a given layout and users are free to choose their own. This API is compatible with both statically sized and dynamically sized I/O maps and I'm not sure if we can easily achieve this if we enforce a given layout with a struct in this crate.
When it comes to actually using this, I think runtime errors can be easily avoided. Users can define their own structs containing the TSS and an I/O map of their choice:
We might want to consider adding something like this as an example in the doc comment.
For more advanced uses (e.g. dynamically sized I/O maps on the heap) users can implement whatever layout fits them.
Having other data between the two should be completely fine.