mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
6 Commits
first_edit
...
first_edit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93aff8cfa8 | ||
|
|
fab320271a | ||
|
|
7becaf5f30 | ||
|
|
3bbc2a0bdc | ||
|
|
c2d22af1c7 | ||
|
|
0ddd214a1b |
@@ -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"]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Blog OS (Kernel Heap)
|
||||
[](https://travis-ci.org/phil-opp/blog_os/branches)
|
||||
# Blog OS (Handling Exceptions)
|
||||
[](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
19
src/interrupts.rs
Normal 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);
|
||||
}
|
||||
12
src/lib.rs
12
src/lib.rs
@@ -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 {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user