mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Begin work for exceptions post
This commit is contained in:
26
src/interrupts/idt.rs
Normal file
26
src/interrupts/idt.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
41
src/interrupts/mod.rs
Normal file
41
src/interrupts/mod.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
mod idt;
|
||||
|
||||
lazy_static! {
|
||||
static ref IDT: idt::Idt = {
|
||||
let mut idt = idt::Idt::new();
|
||||
|
||||
idt.set_handler(0, divide_by_zero_handler);
|
||||
idt.set_handler(8, double_fault_handler);
|
||||
idt.set_handler(13, general_protection_fault_handler);
|
||||
idt.set_handler(14, page_fault_handler);
|
||||
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
assert_has_not_been_called!();
|
||||
|
||||
unsafe { IDT.load() }
|
||||
}
|
||||
|
||||
|
||||
pub extern fn divide_by_zero_handler() -> ! {
|
||||
println!("EXCEPTION: DIVIDE BY ZERO");
|
||||
loop {}
|
||||
}
|
||||
|
||||
pub extern fn double_fault_handler() -> ! {
|
||||
println!("EXCEPTION: DOUBLE FAULT");
|
||||
loop {}
|
||||
}
|
||||
|
||||
pub extern fn general_protection_fault_handler() -> ! {
|
||||
println!("EXCEPTION: GENERAL PROTECTION FAULT");
|
||||
loop {}
|
||||
}
|
||||
|
||||
pub extern fn page_fault_handler() -> ! {
|
||||
println!("EXCEPTION: PAGE FAULT");
|
||||
loop {}
|
||||
}
|
||||
Reference in New Issue
Block a user