mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
43 Commits
returning_
...
better_exc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87d95dbf0d | ||
|
|
91672e3cac | ||
|
|
a91322017e | ||
|
|
f0df9fb937 | ||
|
|
135d8891f3 | ||
|
|
58de55a2d4 | ||
|
|
94d4f8df8e | ||
|
|
d5c84a860a | ||
|
|
ce6b43cc9b | ||
|
|
090e0785ff | ||
|
|
5ce6655aa1 | ||
|
|
e8d1f96b76 | ||
|
|
e09df45b9b | ||
|
|
7f80db6fb4 | ||
|
|
c764e6bb43 | ||
|
|
0ec126fc7d | ||
|
|
258a7d1aba | ||
|
|
6e20fe17db | ||
|
|
2aeeaecf86 | ||
|
|
e63dda6953 | ||
|
|
af8578ec78 | ||
|
|
4c9f7cfbee | ||
|
|
c26fb53547 | ||
|
|
7871e4008a | ||
|
|
e1a90fe3ab | ||
|
|
e17fd2d0de | ||
|
|
2df8517816 | ||
|
|
550a99cfd4 | ||
|
|
86a757cb61 | ||
|
|
bf72618647 | ||
|
|
308b033ea9 | ||
|
|
07bef978ad | ||
|
|
ee48ec5e29 | ||
|
|
6590531a41 | ||
|
|
df99382cda | ||
|
|
979663acda | ||
|
|
8bb46c6b62 | ||
|
|
4eda7993a2 | ||
|
|
b949fba62f | ||
|
|
83978e8417 | ||
|
|
9113a63f5e | ||
|
|
9e45cf65bc | ||
|
|
06fb4d6596 |
@@ -3,15 +3,6 @@ language: rust
|
||||
rust:
|
||||
- nightly
|
||||
|
||||
cache: cargo
|
||||
|
||||
before_script:
|
||||
- curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=$TRAVIS_RUST_VERSION -y
|
||||
- source ~/.cargo/env
|
||||
- rustup component add rust-src
|
||||
- (test -x $HOME/.cargo/bin/rustfmt || cargo install rustfmt)
|
||||
- (test -x $HOME/.cargo/bin/xargo || cargo install xargo)
|
||||
|
||||
sudo: false
|
||||
|
||||
notifications:
|
||||
|
||||
@@ -7,7 +7,7 @@ version = "0.1.0"
|
||||
bit_field = "0.7.0"
|
||||
bitflags = "0.7.0"
|
||||
multiboot2 = "0.1.0"
|
||||
once = "0.3.2"
|
||||
once = "0.2.1"
|
||||
rlibc = "0.1.4"
|
||||
spin = "0.3.4"
|
||||
volatile = "0.1.0"
|
||||
@@ -19,10 +19,6 @@ path = "libs/hole_list_allocator"
|
||||
default-features = false
|
||||
version = "0.8.0"
|
||||
|
||||
[dependencies.lazy_static]
|
||||
version = "0.2.1"
|
||||
features = ["spin_no_std"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
|
||||
4
Makefile
4
Makefile
@@ -8,7 +8,7 @@
|
||||
# except according to those terms.
|
||||
|
||||
arch ?= x86_64
|
||||
target ?= $(arch)-blog_os
|
||||
target ?= $(arch)-unknown-linux-gnu
|
||||
kernel := build/kernel-$(arch).bin
|
||||
iso := build/os-$(arch).iso
|
||||
|
||||
@@ -49,7 +49,7 @@ $(kernel): cargo $(rust_os) $(assembly_object_files) $(linker_script)
|
||||
@ld -n --gc-sections -T $(linker_script) -o $(kernel) $(assembly_object_files) $(rust_os)
|
||||
|
||||
cargo:
|
||||
@xargo build --target $(target)
|
||||
@cargo build --target $(target)
|
||||
|
||||
# compile assembly files
|
||||
build/arch/$(arch)/%.o: src/arch/$(arch)/%.asm
|
||||
|
||||
10
README.md
10
README.md
@@ -1,14 +1,12 @@
|
||||
# Blog OS (Returning from Exceptions)
|
||||
[](https://travis-ci.org/phil-opp/blog_os/branches)
|
||||
# Blog OS (Better Exception Messages)
|
||||
[](https://travis-ci.org/phil-opp/blog_os/branches)
|
||||
|
||||
This repository contains the source code for the [Returning from Exceptions](http://os.phil-opp.com/returning-from-exceptions.html) post of the [Writing an OS in Rust](http://os.phil-opp.com) series.
|
||||
This repository contains the source code for the [Better Exception Messages](http://os.phil-opp.com/better-exception-messages.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.**
|
||||
|
||||
## Building
|
||||
You need to have `nasm`, `grub-mkrescue`, `xorriso`, `qemu`, a nightly Rust compiler, and [xargo] installed. Then you can run it using `make run`.
|
||||
|
||||
[xargo]: https://github.com/japaric/xargo
|
||||
You need to have `nasm`, `grub-mkrescue`, `xorriso`, `qemu`, and a nightly Rust compiler installed. Then you can run it using `make run`.
|
||||
|
||||
Please file an issue if you have any problems.
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
[target.x86_64-blog_os.dependencies]
|
||||
collections = {}
|
||||
@@ -9,51 +9,17 @@
|
||||
|
||||
mod idt;
|
||||
|
||||
macro_rules! save_scratch_registers {
|
||||
() => {
|
||||
asm!("push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rsi
|
||||
push rdi
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
" :::: "intel", "volatile");
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! restore_scratch_registers {
|
||||
() => {
|
||||
asm!("pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rax
|
||||
" :::: "intel", "volatile");
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! handler {
|
||||
($name: ident) => {{
|
||||
#[naked]
|
||||
extern "C" fn wrapper() -> ! {
|
||||
unsafe {
|
||||
save_scratch_registers!();
|
||||
asm!("mov rdi, rsp
|
||||
add rdi, 9*8 // calculate exception stack frame pointer
|
||||
sub rsp, 8 // align the stack pointer
|
||||
call $0"
|
||||
:: "i"($name as extern "C" fn(
|
||||
&ExceptionStackFrame))
|
||||
&ExceptionStackFrame) -> !)
|
||||
: "rdi" : "intel");
|
||||
|
||||
restore_scratch_registers!();
|
||||
asm!("iretq" :::: "intel", "volatile");
|
||||
::core::intrinsics::unreachable();
|
||||
}
|
||||
}
|
||||
@@ -66,19 +32,13 @@ macro_rules! handler_with_error_code {
|
||||
#[naked]
|
||||
extern "C" fn wrapper() -> ! {
|
||||
unsafe {
|
||||
save_scratch_registers!();
|
||||
asm!("mov rsi, [rsp + 9*8] // load error code into rsi
|
||||
asm!("pop rsi // pop error code into rsi
|
||||
mov rdi, rsp
|
||||
add rdi, 10*8 // calculate exception stack frame pointer
|
||||
sub rsp, 8 // align the stack pointer
|
||||
call $0
|
||||
add rsp, 8 // undo stack pointer alignment
|
||||
" :: "i"($name as extern "C" fn(
|
||||
&ExceptionStackFrame, u64))
|
||||
call $0"
|
||||
:: "i"($name as extern "C" fn(
|
||||
&ExceptionStackFrame, u64) -> !)
|
||||
: "rdi","rsi" : "intel");
|
||||
restore_scratch_registers!();
|
||||
asm!("add rsp, 8 // pop error code
|
||||
iretq" :::: "intel", "volatile");
|
||||
::core::intrinsics::unreachable();
|
||||
}
|
||||
}
|
||||
@@ -91,7 +51,6 @@ lazy_static! {
|
||||
let mut idt = idt::Idt::new();
|
||||
|
||||
idt.set_handler(0, handler!(divide_by_zero_handler));
|
||||
idt.set_handler(3, handler!(breakpoint_handler));
|
||||
idt.set_handler(6, handler!(invalid_opcode_handler));
|
||||
idt.set_handler(14, handler_with_error_code!(page_fault_handler));
|
||||
|
||||
@@ -113,18 +72,12 @@ struct ExceptionStackFrame {
|
||||
stack_segment: u64,
|
||||
}
|
||||
|
||||
extern "C" fn divide_by_zero_handler(stack_frame: &ExceptionStackFrame) {
|
||||
extern "C" fn divide_by_zero_handler(stack_frame: &ExceptionStackFrame) -> ! {
|
||||
println!("\nEXCEPTION: DIVIDE BY ZERO\n{:#?}", stack_frame);
|
||||
loop {}
|
||||
}
|
||||
|
||||
extern "C" fn breakpoint_handler(stack_frame: &ExceptionStackFrame) {
|
||||
println!("\nEXCEPTION: BREAKPOINT at {:#x}\n{:#?}",
|
||||
stack_frame.instruction_pointer,
|
||||
stack_frame);
|
||||
}
|
||||
|
||||
extern "C" fn invalid_opcode_handler(stack_frame: &ExceptionStackFrame) {
|
||||
extern "C" fn invalid_opcode_handler(stack_frame: &ExceptionStackFrame) -> ! {
|
||||
println!("\nEXCEPTION: INVALID OPCODE at {:#x}\n{:#?}",
|
||||
stack_frame.instruction_pointer,
|
||||
stack_frame);
|
||||
@@ -141,7 +94,7 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn page_fault_handler(stack_frame: &ExceptionStackFrame, error_code: u64) {
|
||||
extern "C" fn page_fault_handler(stack_frame: &ExceptionStackFrame, error_code: u64) -> ! {
|
||||
use x86::shared::control_regs;
|
||||
println!("\nEXCEPTION: PAGE FAULT while accessing {:#x}\nerror code: \
|
||||
{:?}\n{:#?}",
|
||||
|
||||
@@ -21,13 +21,10 @@ extern crate spin;
|
||||
extern crate multiboot2;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[macro_use]
|
||||
extern crate x86;
|
||||
#[macro_use]
|
||||
extern crate once;
|
||||
extern crate bit_field;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
extern crate hole_list_allocator;
|
||||
extern crate alloc;
|
||||
@@ -56,8 +53,9 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
||||
// initialize our IDT
|
||||
interrupts::init();
|
||||
|
||||
// trigger a breakpoint exception
|
||||
unsafe { int!(3) };
|
||||
// provoke a page fault
|
||||
unsafe { *(0xdeadbeaf as *mut u64) = 42 };
|
||||
|
||||
|
||||
println!("It did not crash!");
|
||||
loop {}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"llvm-target": "x86_64-unknown-linux-gnu",
|
||||
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
|
||||
"target-endian": "little",
|
||||
"target-pointer-width": "64",
|
||||
"arch": "x86_64",
|
||||
"os": "none",
|
||||
"features": "-mmx,-sse,+soft-float",
|
||||
"disable-redzone": true
|
||||
}
|
||||
Reference in New Issue
Block a user