mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 23:07:50 +00:00
Begin porting the double faults post
This commit is contained in:
@@ -15,6 +15,7 @@ extern crate std;
|
||||
|
||||
pub mod serial;
|
||||
pub mod vga_buffer;
|
||||
pub mod tss;
|
||||
|
||||
pub unsafe fn exit_qemu() {
|
||||
use x86_64::instructions::port::Port;
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -21,8 +21,12 @@ pub extern "C" fn _start() -> ! {
|
||||
|
||||
init_idt();
|
||||
|
||||
// invoke a breakpoint exception
|
||||
x86_64::instructions::int3();
|
||||
fn stack_overflow() {
|
||||
stack_overflow(); // for each recursion, the return address is pushed
|
||||
}
|
||||
|
||||
// trigger a stack overflow
|
||||
stack_overflow();
|
||||
|
||||
println!("It did not crash!");
|
||||
loop {}
|
||||
@@ -43,6 +47,7 @@ lazy_static! {
|
||||
static ref IDT: Idt = {
|
||||
let mut idt = Idt::new();
|
||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||
idt.double_fault.set_handler_fn(double_fault_handler);
|
||||
idt
|
||||
};
|
||||
}
|
||||
@@ -54,3 +59,10 @@ pub fn init_idt() {
|
||||
extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut ExceptionStackFrame) {
|
||||
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn double_fault_handler(
|
||||
stack_frame: &mut ExceptionStackFrame, _error_code: u64)
|
||||
{
|
||||
println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
||||
loop {}
|
||||
}
|
||||
|
||||
14
src/tss.rs
Normal file
14
src/tss.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use x86_64::structures::tss::TaskStateSegment;
|
||||
|
||||
static DOUBLE_FAULT_STACK: [u8; 4096] = [0; 4096];
|
||||
const DOUBLE_FAULT_IST_INDEX: usize = 0;
|
||||
|
||||
pub fn init() {
|
||||
let mut tss = TaskStateSegment::new();
|
||||
tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX] = {
|
||||
let stack_start = &DOUBLE_FAULT_STACK as *const [u8; _] as usize;
|
||||
let stack_size = DOUBLE_FAULT_STACK.len();
|
||||
let stack_end = stack_start + stack_size;
|
||||
stack_end
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user