Handle more double faults
This commit is contained in:
parent
4cc21fdee8
commit
d8df82cdad
46
src/gdt.rs
Normal file
46
src/gdt.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use x86_64::VirtAddr;
|
||||
use x86_64::structures::tss::TaskStateSegment;
|
||||
use x86_64::structures::gdt::{GlobalDescriptorTable, Descriptor, SegmentSelector};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
|
||||
|
||||
struct Selectors {
|
||||
code_selector: SegmentSelector,
|
||||
tss_selector: SegmentSelector
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref TSS: TaskStateSegment = {
|
||||
let mut tss = TaskStateSegment::new();
|
||||
tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = {
|
||||
const STACK_SIZE: usize = 4096 * 5;
|
||||
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
|
||||
|
||||
let stack_start = VirtAddr::from_ptr(unsafe { &STACK });
|
||||
let stack_end = stack_start + STACK_SIZE;
|
||||
stack_end
|
||||
};
|
||||
tss
|
||||
};
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref GDT: (GlobalDescriptorTable, Selectors) = {
|
||||
let mut gdt = GlobalDescriptorTable::new();
|
||||
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
|
||||
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
|
||||
(gdt, Selectors { code_selector, tss_selector })
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_gdt() {
|
||||
use x86_64::instructions::segmentation::set_cs;
|
||||
use x86_64::instructions::tables::load_tss;
|
||||
|
||||
GDT.0.load();
|
||||
unsafe {
|
||||
set_cs(GDT.1.code_selector);
|
||||
load_tss(GDT.1.tss_selector);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
use crate::println;
|
||||
use lazy_static::lazy_static;
|
||||
use crate::gdt;
|
||||
|
||||
lazy_static! {
|
||||
static ref IDT: InterruptDescriptorTable = {
|
||||
let mut idt = InterruptDescriptorTable::new();
|
||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||
idt.double_fault.set_handler_fn(double_fault_handler);
|
||||
unsafe {
|
||||
idt.double_fault.set_handler_fn(double_fault_handler)
|
||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
||||
}
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
mod vga_buffer;
|
||||
mod interrupts;
|
||||
mod gdt;
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
|
||||
|
@ -19,6 +20,7 @@ fn panic(info: &PanicInfo) -> ! {
|
|||
}
|
||||
|
||||
fn init() {
|
||||
gdt::init_gdt();
|
||||
interrupts::init_idt();
|
||||
}
|
||||
|
||||
|
@ -30,10 +32,12 @@ pub extern "C" fn _start() {
|
|||
|
||||
x86_64::instructions::interrupts::int3();
|
||||
|
||||
unsafe {
|
||||
*(0xdeadbeef as *mut u64) = 42;
|
||||
fn stack_overflow() {
|
||||
stack_overflow();
|
||||
}
|
||||
|
||||
stack_overflow();
|
||||
|
||||
#[cfg(test)]
|
||||
test_main();
|
||||
|
||||
|
|
Loading…
Reference in a new issue