~kameliya/syso

bffd41fe2792776713f93bd38d461d8c4a882417 — Yuki Izumi 4 years ago eeb5de2 master
ugly idt
2 files changed, 22 insertions(+), 2 deletions(-)

M src/desc.rs
M src/lib.rs
M src/desc.rs => src/desc.rs +20 -2
@@ 1,6 1,24 @@
use core::mem::size_of;
use x86::bits64::irq::IdtEntry;
use x86::shared::dtables::DescriptorTablePointer;
use x86::shared::dtables::{DescriptorTablePointer, lidt};
use x86::shared::{PrivilegeLevel, segmentation};
use x86::shared::paging::VAddr;

static mut IDT_ENTRIES: [IdtEntry; 256] = [IdtEntry::MISSING; 256];

pub fn init() {
    let entries: [IdtEntry; 256] = [IdtEntry::MISSING; 256];
    unsafe { IDT_ENTRIES[0] = IdtEntry::new(VAddr::from_usize(div_zero as usize), segmentation::cs().bits(), PrivilegeLevel::Ring0, false) }

    let ptr = DescriptorTablePointer {
        base: unsafe { &IDT_ENTRIES as *const _ },
        limit: (size_of::<[IdtEntry; 256]>() - 1) as u16,
    };
    unsafe { lidt(&ptr) }
}

extern "C" fn div_zero() {
    use debug::DEBUG;
    use core::fmt::Write;
    unsafe { write!(DEBUG, "div_zero\n").unwrap() }
    loop {}
}

M src/lib.rs => src/lib.rs +2 -0
@@ 34,6 34,8 @@ pub extern fn rust_entry(multiboot_addr: usize) {
    mem::init(&multiboot);
    desc::init();

//     unsafe { asm!("mov dx, 0; div dx" ::: "ax", "dx" : "volatile", "intel") }

    write!(console, "> ").unwrap();

    unsafe { asm!("hlt") }