Compare commits

..

6 Commits

Author SHA1 Message Date
Philipp Oppermann
93aff8cfa8 Test our exception handler by invoking a breakpoint exception 2017-11-19 14:22:24 +01:00
Philipp Oppermann
fab320271a Create and load an IDT 2017-11-19 14:21:51 +01:00
Philipp Oppermann
7becaf5f30 Add a dependency on lazy_static 2017-11-19 14:21:51 +01:00
Philipp Oppermann
3bbc2a0bdc Add a simple handler function for the breakpoint exception 2017-11-19 14:21:36 +01:00
Philipp Oppermann
c2d22af1c7 Create a new interrupts module 2017-11-19 14:21:12 +01:00
Philipp Oppermann
0ddd214a1b Update Readme for “Handling Exceptions” post 2017-11-19 14:21:00 +01:00
4 changed files with 36 additions and 5 deletions

View File

@@ -15,3 +15,7 @@ bitflags = "0.7.0"
x86_64 = "0.1.2"
once = "0.3.3"
linked_list_allocator = "0.4.2"
[dependencies.lazy_static]
version = "0.2.4"
features = ["spin_no_std"]

View File

@@ -1,7 +1,7 @@
# Blog OS (Kernel Heap)
[![Build Status](https://travis-ci.org/phil-opp/blog_os.svg?branch=post_8)](https://travis-ci.org/phil-opp/blog_os/branches)
# Blog OS (Handling Exceptions)
[![Build Status](https://travis-ci.org/phil-opp/blog_os.svg?branch=post_9)](https://travis-ci.org/phil-opp/blog_os/branches)
This repository contains the source code for the [Kernel Heap](http://os.phil-opp.com/kernel-heap.html) post of the [Writing an OS in Rust](http://os.phil-opp.com) series.
This repository contains the source code for the [Handling Exceptions](http://os.phil-opp.com/handling-exceptions.html) post of the [Writing an OS in Rust](http://os.phil-opp.com) series.
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**

19
src/interrupts.rs Normal file
View File

@@ -0,0 +1,19 @@
use x86_64::structures::idt::{Idt, ExceptionStackFrame};
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{:#?}", stack_frame);
}

View File

@@ -5,6 +5,7 @@
#![feature(unique)]
#![feature(allocator_api)]
#![feature(global_allocator)]
#![feature(abi_x86_interrupt)]
#![no_std]
@@ -21,10 +22,12 @@ extern crate x86_64;
#[macro_use]
extern crate once;
extern crate linked_list_allocator;
#[macro_use]
extern crate lazy_static;
#[macro_use]
mod vga_buffer;
mod memory;
mod interrupts;
#[no_mangle]
pub extern "C" fn rust_main(multiboot_information_address: usize) {
@@ -45,12 +48,17 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
HEAP_ALLOCATOR.lock().init(HEAP_START, HEAP_START + HEAP_SIZE);
}
// initialize our IDT
interrupts::init();
for i in 0..10000 {
format!("Some String");
}
println!("It did not crash!");
// invoke a breakpoint exception
x86_64::instructions::interrupts::int3();
println!("It did not crash!");
loop {}
}