Skip to content

Commit df48ba9

Browse files
committed
Add Debug implementation for InterruptDescriptorTable
This commit also improves the debug implementations for `Entry` and `EntryOptions` so that code like: ```rust println!("{:#?}", InterruptDescriptorTable::new()); ``` doesn't produce complete garbage. Signed-off-by: Joe Richey <[email protected]>
1 parent 9ab2f3f commit df48ba9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/structures/idt.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ use volatile::Volatile;
3333
/// The field descriptions are taken from the
3434
/// [AMD64 manual volume 2](https://support.amd.com/TechDocs/24593.pdf)
3535
/// (with slight modifications).
36-
#[allow(missing_debug_implementations)]
37-
#[derive(Clone)]
36+
#[derive(Clone, Debug)]
3837
#[repr(C)]
3938
#[repr(align(16))]
4039
pub struct InterruptDescriptorTable {
@@ -575,12 +574,9 @@ pub struct Entry<F> {
575574
impl<T> fmt::Debug for Entry<T> {
576575
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
577576
f.debug_struct("Entry")
578-
.field("pointer_low", &self.pointer_low)
577+
.field("handler_addr", &format_args!("{:#x}", self.handler_addr()))
579578
.field("gdt_selector", &self.gdt_selector)
580579
.field("options", &self.options)
581-
.field("pointer_middle", &self.pointer_middle)
582-
.field("pointer_high", &self.pointer_high)
583-
.field("reserved", &self.reserved)
584580
.finish()
585581
}
586582
}
@@ -645,6 +641,13 @@ impl<F> Entry<F> {
645641
self.options.set_present(true);
646642
&mut self.options
647643
}
644+
645+
#[inline]
646+
fn handler_addr(&self) -> u64 {
647+
self.pointer_low as u64
648+
| (self.pointer_middle as u64) << 16
649+
| (self.pointer_high as u64) << 32
650+
}
648651
}
649652

650653
macro_rules! impl_set_handler_fn {
@@ -674,9 +677,17 @@ impl_set_handler_fn!(DivergingHandlerFuncWithErrCode);
674677

675678
/// Represents the options field of an IDT entry.
676679
#[repr(transparent)]
677-
#[derive(Debug, Clone, Copy, PartialEq)]
680+
#[derive(Clone, Copy, PartialEq)]
678681
pub struct EntryOptions(u16);
679682

683+
impl fmt::Debug for EntryOptions {
684+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
685+
f.debug_tuple("EntryOptions")
686+
.field(&format_args!("{:#06x}", self.0))
687+
.finish()
688+
}
689+
}
690+
680691
impl EntryOptions {
681692
/// Creates a minimal options field with all the must-be-one bits set.
682693
#[inline]

0 commit comments

Comments
 (0)