Skip to content
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

Minor lint fixes #253

Merged
merged 3 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Unreleased

- Add `Debug` implementation for `InterruptDescriptorTable` ([#253](https://github.com/rust-osdev/x86_64/pull/253))
- Improve `Debug` implementations for `Entry` and `EntryOptions`

# 0.14.2 – 2021-05-13

- Multiple improvements to assembly code ([#251](https://github.com/rust-osdev/x86_64/pull/251))
Expand Down
26 changes: 18 additions & 8 deletions src/structures/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ use volatile::Volatile;
/// The field descriptions are taken from the
/// [AMD64 manual volume 2](https://support.amd.com/TechDocs/24593.pdf)
/// (with slight modifications).
#[allow(missing_debug_implementations)]
#[derive(Clone)]
#[derive(Clone, Debug)]
#[repr(C)]
#[repr(align(16))]
pub struct InterruptDescriptorTable {
Expand Down Expand Up @@ -575,12 +574,9 @@ pub struct Entry<F> {
impl<T> fmt::Debug for Entry<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Entry")
.field("pointer_low", &self.pointer_low)
.field("handler_addr", &format_args!("{:#x}", self.handler_addr()))
.field("gdt_selector", &self.gdt_selector)
.field("options", &self.options)
.field("pointer_middle", &self.pointer_middle)
.field("pointer_high", &self.pointer_high)
.field("reserved", &self.reserved)
.finish()
}
}
Expand Down Expand Up @@ -645,6 +641,13 @@ impl<F> Entry<F> {
self.options.set_present(true);
&mut self.options
}

#[inline]
fn handler_addr(&self) -> u64 {
self.pointer_low as u64
| (self.pointer_middle as u64) << 16
| (self.pointer_high as u64) << 32
}
}

macro_rules! impl_set_handler_fn {
Expand Down Expand Up @@ -674,9 +677,17 @@ impl_set_handler_fn!(DivergingHandlerFuncWithErrCode);

/// Represents the options field of an IDT entry.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq)]
pub struct EntryOptions(u16);

impl fmt::Debug for EntryOptions {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("EntryOptions")
.field(&format_args!("{:#06x}", self.0))
.finish()
}
}

impl EntryOptions {
/// Creates a minimal options field with all the must-be-one bits set.
#[inline]
Expand Down Expand Up @@ -757,7 +768,6 @@ impl InterruptStackFrame {
///
/// Also, it is not fully clear yet whether modifications of the interrupt stack frame are
/// officially supported by LLVM's x86 interrupt calling convention.
#[allow(clippy::should_implement_trait)]
#[inline]
pub unsafe fn as_mut(&mut self) -> Volatile<&mut InterruptStackFrameValue> {
Volatile::new(&mut self.value)
Expand Down