From 098d222fc1aad13f4d37994e05912df6689c7e5a Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 19 Mar 2018 15:24:26 +0100 Subject: [PATCH] int --- kernel-rs/Cargo.toml | 4 ++++ kernel-rs/src/interrupts/mod.rs | 21 +++++++++++++++++++++ kernel-rs/src/lib.rs | 21 ++++++++++++++++----- kernel-rs/src/memory/paging/table.rs | 2 +- kernel-rs/x86 | 2 +- 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 kernel-rs/src/interrupts/mod.rs diff --git a/kernel-rs/Cargo.toml b/kernel-rs/Cargo.toml index 558231c0..90aada02 100644 --- a/kernel-rs/Cargo.toml +++ b/kernel-rs/Cargo.toml @@ -11,3 +11,7 @@ rlibc = "1.0" bitflags = "1.0.1" multiboot2 = { path = "multiboot2-elf64" } x86 = { path = "x86" } + +[dependencies.lazy_static] +version = "1.0.0" +features = ["spin_no_std"] diff --git a/kernel-rs/src/interrupts/mod.rs b/kernel-rs/src/interrupts/mod.rs new file mode 100644 index 00000000..29734748 --- /dev/null +++ b/kernel-rs/src/interrupts/mod.rs @@ -0,0 +1,21 @@ +use x86::structures::idt::*; + +lazy_static! { + static ref IDT: Idt = { + let mut idt = Idt::new(); + idt.breakpoint.set_handler_fn(breakpoint_handler); + idt + }; +} + +pub fn init() { + IDT.load(); +} + +extern "x86-interrupt" fn breakpoint_handler( + stack_frame: &mut ExceptionStackFrame) +{ + println!("EXCEPTION: BREAKPOINT\n"); + flush!(); + loop{} +} diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index c92dfc7c..ba3c49f6 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -5,13 +5,16 @@ #![feature(const_fn)] #![feature(ptr_internals)] #![feature(asm)] + #![feature(alloc)] #![feature(allocator_api)] #![feature(global_allocator)] +#![feature(abi_x86_interrupt)] + extern crate rlibc; extern crate multiboot2; -// #[macro_use] extern crate bitflags; +#[macro_use] extern crate lazy_static; #[macro_use] extern crate alloc; extern crate x86; @@ -27,22 +30,28 @@ pub mod cpuio; pub mod acpi; /// physical frame allocator + paging module + heap allocator pub mod memory; -// x86 interruptions -// pub mod interrupts; +/// x86 interruptions +pub mod interrupts; fn init_kernel(multiboot_info_addr: usize) -> Result <(), &'static str> { + let boot_info = unsafe { multiboot2::load(multiboot_info_addr)}; + if let Some(rsdp) = boot_info.rsdp_v2_tag() { acpi::load(rsdp)?; } else if let Some(rsdp) = boot_info.rsdp_tag() { acpi::load(rsdp)?; - } - else { + } else { acpi::init()?; } + enable_paging(); + enable_write_protect_bit(); + memory::init(&boot_info); + interrupts::init(); vga::init(); + Ok(()) } @@ -53,6 +62,8 @@ pub extern fn kmain(multiboot_info_addr: usize) -> ! { cpuio::halt(); } + x86::instructions::interrupts::int3(); + loop { keyboard::kbd_callback(); } } diff --git a/kernel-rs/src/memory/paging/table.rs b/kernel-rs/src/memory/paging/table.rs index b390b99a..70a9731e 100644 --- a/kernel-rs/src/memory/paging/table.rs +++ b/kernel-rs/src/memory/paging/table.rs @@ -1,6 +1,6 @@ use memory::*; use x86::structures::paging::*; -use x86::ux::*; +// use x86::ux::*; pub trait RecTable { diff --git a/kernel-rs/x86 b/kernel-rs/x86 index 7b8227e3..da544c83 160000 --- a/kernel-rs/x86 +++ b/kernel-rs/x86 @@ -1 +1 @@ -Subproject commit 7b8227e36afe68ed2d518a2c7cede0466878ca9d +Subproject commit da544c834b3f3d8b53f456c48b3aafa58d09198a