Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit 11278a2

Browse files
authored
Merge pull request #97 from nabeelomer/master
Added docs to the interrupts crate
2 parents e2b0883 + aebc9f4 commit 11278a2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

interrupts/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This module contains methods and macros to create and register interrupt descriptors and
2+
//! interrupt handlers
3+
14
#![feature(asm)]
25
#![feature(naked_functions)]
36
#![feature(const_fn)]
@@ -12,6 +15,9 @@ use x86::shared::dtables;
1215
use x86::shared::dtables::DescriptorTablePointer;
1316
use x86::bits64::irq::IdtEntry;
1417

18+
/// Creates an IDT entry.
19+
///
20+
/// Creates an IDT entry that executes the expression in `body`.
1521
#[macro_export]
1622
macro_rules! make_idt_entry {
1723
($name:ident, $body:expr) => {{
@@ -75,8 +81,12 @@ macro_rules! make_idt_entry {
7581
}};
7682
}
7783

84+
/// The Interrupt Descriptor Table
85+
///
86+
/// The CPU will look at this table to find the appropriate interrupt handler.
7887
static IDT: Mutex<[IdtEntry; 256]> = Mutex::new([IdtEntry::MISSING; 256]);
7988

89+
/// Pointer to the Interrupt Descriptor Table
8090
pub struct IdtRef {
8191
ptr: DescriptorTablePointer<IdtEntry>,
8292
idt: &'static Mutex<[IdtEntry; 256]>,
@@ -85,6 +95,7 @@ pub struct IdtRef {
8595
unsafe impl Sync for IdtRef {}
8696

8797
impl IdtRef {
98+
/// Creates a new pointer struct to the IDT.
8899
pub fn new() -> IdtRef {
89100
let r = IdtRef {
90101
ptr: DescriptorTablePointer::new_idtp(&IDT.lock()[..]),
@@ -93,17 +104,17 @@ impl IdtRef {
93104

94105
// This block is safe because by referencing IDT above, we know that we've constructed an
95106
// IDT.
96-
unsafe {
97-
dtables::lidt(&r.ptr)
98-
};
107+
unsafe { dtables::lidt(&r.ptr) };
99108

100109
r
101110
}
102111

112+
/// Sets an IdtEntry as a handler for interrupt specified by `index`.
103113
pub fn set_handler(&self, index: usize, entry: IdtEntry) {
104114
self.idt.lock()[index] = entry;
105115
}
106116

117+
/// Enables interrupts.
107118
pub fn enable_interrupts(&self) {
108119
// This unsafe fn is okay becuase, by virtue of having an IdtRef, we know that we have a
109120
// valid Idt.

0 commit comments

Comments
 (0)