Some code?
This commit is contained in:
parent
084945688b
commit
92533cb5d2
33
src/gdt.rs
Normal file
33
src/gdt.rs
Normal 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();
|
||||||
|
}
|
@ -9,6 +9,7 @@
|
|||||||
mod vga_buffer;
|
mod vga_buffer;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod serial;
|
mod serial;
|
||||||
|
mod gdt;
|
||||||
mod interrupts;
|
mod interrupts;
|
||||||
mod test_utils;
|
mod test_utils;
|
||||||
|
|
||||||
@ -31,9 +32,6 @@ pub extern "C" fn _start() -> ! {
|
|||||||
x86_64::instructions::interrupts::int3();
|
x86_64::instructions::interrupts::int3();
|
||||||
|
|
||||||
println!("We're here now");
|
println!("We're here now");
|
||||||
unsafe {
|
|
||||||
*(0xff00ff00 as *mut u64) = 44;
|
|
||||||
}
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,5 +46,6 @@ fn basic_test2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
|
gdt::init();
|
||||||
interrupts::init_idt();
|
interrupts::init_idt();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user