-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handling double faults in a seperate stack segment
- Loading branch information
1 parent
7c57ee0
commit 3318cd9
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use x86_64::VirtAddr; | ||
use x86_64::structures::tss::TaskStateSegment; | ||
use lazy_static::lazy_static; | ||
use x86_64::structures::gdt::{GlobalDescriptorTable, Descriptor, SegmentSelector}; | ||
|
||
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0; | ||
|
||
pub fn init() { | ||
use x86_64::instructions::tables::load_tss; | ||
use x86_64::instructions::segmentation::{CS, Segment}; | ||
|
||
GDT.0.load(); | ||
unsafe { | ||
CS::set_reg(GDT.1.code_selector); | ||
load_tss(GDT.1.tss_selector); | ||
} | ||
} | ||
|
||
struct Selectors { | ||
code_selector: SegmentSelector, | ||
tss_selector: SegmentSelector, | ||
} | ||
|
||
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 }) | ||
}; | ||
} | ||
|
||
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 | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters