Compare commits
No commits in common. "beb2227d7e4c1d95854dddba6b55bfbe9c9068a8" and "af973e8c8e9b1dbf9f659a39fff9f82aae86f99b" have entirely different histories.
beb2227d7e
...
af973e8c8e
4 changed files with 4 additions and 78 deletions
47
src/gdt.rs
47
src/gdt.rs
|
@ -1,47 +0,0 @@
|
||||||
use x86_64::VirtAddr;
|
|
||||||
use x86_64::structures::tss::TaskStateSegment;
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use x86_64::structures::gdt::{GlobalDescriptorTable, Descriptor};
|
|
||||||
use x86_64::structures::gdt::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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 })
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Selectors {
|
|
||||||
code_selector: SegmentSelector,
|
|
||||||
tss_selector: SegmentSelector,
|
|
||||||
}
|
|
|
@ -1,17 +1,10 @@
|
||||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||||
use crate::println;
|
use crate::println;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use crate::gdt;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref IDT: InterruptDescriptorTable = {
|
static ref IDT: InterruptDescriptorTable = {
|
||||||
let mut idt = InterruptDescriptorTable::new();
|
let mut idt = InterruptDescriptorTable::new();
|
||||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||||
unsafe {
|
|
||||||
idt.double_fault.set_handler_fn(double_fault_handler)
|
|
||||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); // new
|
|
||||||
}
|
|
||||||
|
|
||||||
idt
|
idt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -25,15 +18,3 @@ extern "x86-interrupt" fn breakpoint_handler(
|
||||||
{
|
{
|
||||||
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
|
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn double_fault_handler(
|
|
||||||
stack_frame: InterruptStackFrame, _error_code: u64) -> !
|
|
||||||
{
|
|
||||||
panic!("EXCEPTION: DLB FAULT\n{:#?}", stack_frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test_case]
|
|
||||||
fn test_breakpoint_exception() {
|
|
||||||
// invoke a breakpoint exception
|
|
||||||
x86_64::instructions::interrupts::int3();
|
|
||||||
}
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -6,16 +6,13 @@
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(abi_x86_interrupt)]
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
interrupts::init_idt();
|
||||||
|
}
|
||||||
|
|
||||||
pub mod serial;
|
pub mod serial;
|
||||||
pub mod vga_buffer;
|
pub mod vga_buffer;
|
||||||
pub mod interrupts;
|
pub mod interrupts;
|
||||||
pub mod gdt;
|
|
||||||
|
|
||||||
pub fn init() {
|
|
||||||
gdt::init();
|
|
||||||
interrupts::init_idt();
|
|
||||||
}
|
|
||||||
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
@ -53,7 +50,6 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
init();
|
|
||||||
test_main();
|
test_main();
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,7 @@ pub extern "C" fn _start() -> ! {
|
||||||
|
|
||||||
donald::init();
|
donald::init();
|
||||||
|
|
||||||
fn stack_overflow() {
|
x86_64::instructions::interrupts::int3();
|
||||||
stack_overflow();
|
|
||||||
}
|
|
||||||
|
|
||||||
stack_overflow();
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
test_main();
|
test_main();
|
||||||
|
|
Loading…
Reference in a new issue