Begin work for exceptions post

This commit is contained in:
Philipp Oppermann
2016-05-13 15:54:19 +02:00
parent 7c565abba8
commit 431bb39fdb
4 changed files with 96 additions and 0 deletions

26
src/interrupts/idt.rs Normal file
View File

@@ -0,0 +1,26 @@
use x86::irq::IdtEntry;
pub struct Idt([IdtEntry; 16]);
impl Idt {
pub fn new() -> Idt {
Idt([IdtEntry::missing(); 16])
}
pub fn set_handler(&mut self, entry: usize, handler: extern fn()->!) {
let ptr = handler as usize;
self.0[entry] = IdtEntry::interrupt_gate(0x8, ptr as *const _);
}
pub unsafe fn load(&self) {
use x86::dtables::{DescriptorTablePointer, lidt};
use core::mem::size_of;
let ptr = DescriptorTablePointer{
base: self as *const _ as u64,
limit: (size_of::<Self>() - 1) as u16,
};
lidt(&ptr);
}
}