Add IST entries for NMI and double fault

This commit is contained in:
Mathieu Strypsteen 2024-07-12 14:00:48 +02:00
parent 36488ea49e
commit 0512033ddd
2 changed files with 11 additions and 2 deletions

View file

@ -1,6 +1,6 @@
use core::{arch::asm, mem::size_of}; use core::{alloc::Layout, arch::asm, mem::size_of};
use alloc::boxed::Box; use alloc::{alloc::alloc, boxed::Box};
#[repr(C)] #[repr(C)]
struct GDTEntry { struct GDTEntry {
@ -43,7 +43,10 @@ struct GDTDescriptor {
base: u64, base: u64,
} }
const IST_STACK_SIZE: usize = 128 * 1024;
pub fn setup_gdt() { pub fn setup_gdt() {
let layout = Layout::from_size_align(IST_STACK_SIZE, 16).unwrap();
let tss = Box::leak(Box::new(TSS { let tss = Box::leak(Box::new(TSS {
reserved1: 0, reserved1: 0,
rsp: [0; 3], rsp: [0; 3],
@ -53,6 +56,10 @@ pub fn setup_gdt() {
reserved4: 0, reserved4: 0,
iopb_offset: size_of::<TSS>() as u16, iopb_offset: size_of::<TSS>() as u16,
})); }));
unsafe {
tss.ist[0] = alloc(layout) as u64 + IST_STACK_SIZE as u64;
tss.ist[1] = alloc(layout) as u64 + IST_STACK_SIZE as u64;
}
let gdt = Box::leak(Box::new(GDT { let gdt = Box::leak(Box::new(GDT {
entries: [ entries: [
GDTEntry { GDTEntry {

View file

@ -310,12 +310,14 @@ pub fn setup_idt() {
set_address(&mut idt.entries[0], isr0); set_address(&mut idt.entries[0], isr0);
set_address(&mut idt.entries[1], isr1); set_address(&mut idt.entries[1], isr1);
set_address(&mut idt.entries[2], isr2); set_address(&mut idt.entries[2], isr2);
idt.entries[2].ist = 1; // NMI
set_address(&mut idt.entries[3], isr3); set_address(&mut idt.entries[3], isr3);
set_address(&mut idt.entries[4], isr4); set_address(&mut idt.entries[4], isr4);
set_address(&mut idt.entries[5], isr5); set_address(&mut idt.entries[5], isr5);
set_address(&mut idt.entries[6], isr6); set_address(&mut idt.entries[6], isr6);
set_address(&mut idt.entries[7], isr7); set_address(&mut idt.entries[7], isr7);
set_address(&mut idt.entries[8], isr8); set_address(&mut idt.entries[8], isr8);
idt.entries[8].ist = 2; // Double fault
set_address(&mut idt.entries[9], isr9); set_address(&mut idt.entries[9], isr9);
set_address(&mut idt.entries[10], isr10); set_address(&mut idt.entries[10], isr10);
set_address(&mut idt.entries[11], isr11); set_address(&mut idt.entries[11], isr11);