Skip to content

Commit

Permalink
Add InterruptDescriptorTable::load_unsafe (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored Apr 18, 2020
1 parent 2b9df60 commit d73f3e0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/structures/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,22 @@ impl InterruptDescriptorTable {
#[cfg(target_arch = "x86_64")]
#[inline]
pub fn load(&'static self) {
unsafe { self.load_unsafe() }
}

/// Loads the IDT in the CPU using the `lidt` command.
///
/// # Safety
///
/// As long as it is the active IDT, you must ensure that:
///
/// - `self` is never destroyed.
/// - `self` always stays at the same memory location. It is recommended to wrap it in
/// a `Box`.
///
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn load_unsafe(&self) {
use crate::instructions::tables::{lidt, DescriptorTablePointer};
use core::mem::size_of;

Expand All @@ -422,7 +438,7 @@ impl InterruptDescriptorTable {
limit: (size_of::<Self>() - 1) as u16,
};

unsafe { lidt(&ptr) };
lidt(&ptr);
}

/// Returns a normalized and ranged check slice range from a RangeBounds trait object
Expand Down

0 comments on commit d73f3e0

Please sign in to comment.