Some code?

This commit is contained in:
Greg Shuflin 2023-11-09 17:32:46 -08:00
parent 084945688b
commit 92533cb5d2
2 changed files with 35 additions and 3 deletions

33
src/gdt.rs Normal file
View File

@ -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();
}

View File

@ -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();
}