From 92533cb5d20fc1ab975f3bd2caccb43c1f3034d2 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 9 Nov 2023 17:32:46 -0800 Subject: [PATCH] Some code? --- src/gdt.rs | 33 +++++++++++++++++++++++++++++++++ src/main.rs | 5 ++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/gdt.rs diff --git a/src/gdt.rs b/src/gdt.rs new file mode 100644 index 0000000..1df968d --- /dev/null +++ b/src/gdt.rs @@ -0,0 +1,33 @@ +use lazy_static::lazy_static; +use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector}; +use x86_64::structures::tss::TaskStateSegment; +use x86_64::VirtAddr; + +pub const DOUBLE_FAULT_IST_INDEX: u16 = 0; + +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 = { + let mut gdt = GlobalDescriptorTable::new(); + gdt.add_entry(Descriptor::kernel_code_segment()); + gdt.add_entry(Descriptor::tss_segment(&TSS)); + gdt + }; +} + +pub fn init() { + GDT.load(); +} diff --git a/src/main.rs b/src/main.rs index 87c4092..b04071f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod vga_buffer; #[macro_use] mod serial; +mod gdt; mod interrupts; mod test_utils; @@ -31,9 +32,6 @@ pub extern "C" fn _start() -> ! { x86_64::instructions::interrupts::int3(); println!("We're here now"); - unsafe { - *(0xff00ff00 as *mut u64) = 44; - } loop {} } @@ -48,5 +46,6 @@ fn basic_test2() { } pub fn init() { + gdt::init(); interrupts::init_idt(); }