summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2019-11-07 18:32:47 +0100
committerDennis Kobert <dennis@kobert.dev>2019-11-07 18:32:47 +0100
commita9d39fdb56526c4146d92e6af68cc175ec4da7c2 (patch)
treec3e6c67681852718dcacc6f1166e4e2bbd1a90a0
parente19c8879eb7732d3bcb62194065c9cb2892cf1ab (diff)
Add interupt descriptor table
-rw-r--r--kernel/Cargo.toml4
-rw-r--r--kernel/src/boot.asm2
-rw-r--r--kernel/src/interrupts/exceptions.rs7
-rw-r--r--kernel/src/interrupts/mod.rs2
-rw-r--r--kernel/src/interrupts/table.rs16
-rw-r--r--kernel/src/lib.rs6
6 files changed, 34 insertions, 3 deletions
diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml
index 660cb80..9ac2848 100644
--- a/kernel/Cargo.toml
+++ b/kernel/Cargo.toml
@@ -16,6 +16,10 @@ x86_64 = "0.7.5"
uart_16550 = "0.2.1"
spin = "0.5"
+[dependencies.lazy_static]
+version = "1.4.0"
+features = ["spin_no_std"]
+
[dependencies.compiler_builtins]
version = "0.1.19"
git = "https://github.com/rust-lang/compiler-builtins"
diff --git a/kernel/src/boot.asm b/kernel/src/boot.asm
index 451e455..95b699a 100644
--- a/kernel/src/boot.asm
+++ b/kernel/src/boot.asm
@@ -160,5 +160,5 @@ p3_table:
p2_table:
resb 4096
stack_bottom:
- resb 4096
+ resb 4096 * 8
stack_top:
diff --git a/kernel/src/interrupts/exceptions.rs b/kernel/src/interrupts/exceptions.rs
new file mode 100644
index 0000000..5ec7588
--- /dev/null
+++ b/kernel/src/interrupts/exceptions.rs
@@ -0,0 +1,7 @@
+use crate::io::vga_text::OStream;
+use x86_64::structures::idt::InterruptStackFrame;
+
+pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) {
+ let mut stdout = OStream::new();
+ stdout.print(b"EXCEPTION: BREAKPOINT\n");
+}
diff --git a/kernel/src/interrupts/mod.rs b/kernel/src/interrupts/mod.rs
new file mode 100644
index 0000000..ae21761
--- /dev/null
+++ b/kernel/src/interrupts/mod.rs
@@ -0,0 +1,2 @@
+mod exceptions;
+pub mod table;
diff --git a/kernel/src/interrupts/table.rs b/kernel/src/interrupts/table.rs
new file mode 100644
index 0000000..47d6ead
--- /dev/null
+++ b/kernel/src/interrupts/table.rs
@@ -0,0 +1,16 @@
+use crate::io::vga_text::OStream;
+use lazy_static::lazy_static;
+use x86_64::structures::idt::InterruptDescriptorTable;
+
+lazy_static! {
+ static ref IDT: InterruptDescriptorTable = {
+ let mut idt = InterruptDescriptorTable::new();
+ idt.breakpoint
+ .set_handler_fn(super::exceptions::breakpoint_handler);
+ idt
+ };
+}
+
+pub fn init() {
+ IDT.load()
+}
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index d5a3e9e..45ba8e1 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -1,12 +1,12 @@
#![no_main]
#![feature(compiler_builtins_lib)]
#![feature(custom_test_frameworks)]
+#![feature(abi_x86_interrupt)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#![no_std]
-extern crate compiler_builtins;
-
+mod interrupts;
mod io;
use core::fmt::Write;
@@ -25,6 +25,7 @@ pub fn test_runner(tests: &[&dyn Fn(&mut OStream)]) {
#[no_mangle]
pub extern "C" fn _start() -> ! {
+ interrupts::table::init();
if cfg!(test) {
#[cfg(test)]
test_main();
@@ -71,5 +72,6 @@ pub extern "C" fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
write!(serial::SerialStream::new(), "Testing failed\n").unwrap();
qemu::exit_qemu(qemu::QemuExitCode::Failed);
}
+ x86_64::instructions::interrupts::int3();
loop {}
}