update source to match draft

This commit is contained in:
acheronfail
2018-10-15 23:32:22 +10:00
committed by Philipp Oppermann
parent 87f6e734a9
commit 7ad0ed9254
5 changed files with 65 additions and 21 deletions

10
src/interrupts.rs Normal file
View File

@@ -0,0 +1,10 @@
use pic8259_simple::ChainedPics;
use spin;
pub const PIC_1_OFFSET: u8 = 32;
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
pub static PICS: spin::Mutex<ChainedPics> =
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
pub const TIMER_INTERRUPT_ID: u8 = PIC_1_OFFSET;

View File

@@ -5,6 +5,7 @@ extern crate spin;
extern crate volatile;
#[macro_use]
extern crate lazy_static;
extern crate pic8259_simple;
extern crate uart_16550;
extern crate x86_64;
@@ -14,6 +15,7 @@ extern crate array_init;
extern crate std;
pub mod gdt;
pub mod interrupts;
pub mod serial;
pub mod vga_buffer;

View File

@@ -11,6 +11,7 @@ extern crate x86_64;
extern crate lazy_static;
use core::panic::PanicInfo;
use blog_os::interrupts::{self, PICS};
/// This function is the entry point, since the linker looks for a function
/// named `_start` by default.
@@ -22,12 +23,8 @@ pub extern "C" fn _start() -> ! {
blog_os::gdt::init();
init_idt();
fn stack_overflow() {
stack_overflow(); // for each recursion, the return address is pushed
}
// trigger a stack overflow
stack_overflow();
unsafe { PICS.lock().initialize() };
x86_64::instructions::interrupts::enable();
println!("It did not crash!");
loop {}
@@ -54,6 +51,9 @@ lazy_static! {
.set_stack_index(blog_os::gdt::DOUBLE_FAULT_IST_INDEX);
}
let timer_interrupt_id = usize::from(interrupts::TIMER_INTERRUPT_ID);
idt[timer_interrupt_id].set_handler_fn(timer_interrupt_handler);
idt
};
}
@@ -73,3 +73,11 @@ extern "x86-interrupt" fn double_fault_handler(
println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
loop {}
}
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut ExceptionStackFrame) {
print!(".");
unsafe {
PICS.lock()
.notify_end_of_interrupt(interrupts::TIMER_INTERRUPT_ID)
}
}