mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Use new x86::segmentation::cs function and merge set_handler and options
We avoid inline assembly and increase safety (it is no longer possible to set the non-present initilization entries to present).
This commit is contained in:
@@ -18,7 +18,7 @@ git = "https://github.com/phil-opp/multiboot2-elf64"
|
|||||||
|
|
||||||
[dependencies.x86]
|
[dependencies.x86]
|
||||||
default-features = false
|
default-features = false
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use x86::segmentation::{self, SegmentSelector};
|
||||||
|
|
||||||
pub struct Idt([Entry; 16]);
|
pub struct Idt([Entry; 16]);
|
||||||
|
|
||||||
@@ -6,14 +7,8 @@ impl Idt {
|
|||||||
Idt([Entry::missing(); 16])
|
Idt([Entry::missing(); 16])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_handler(&mut self, entry: u8, handler: extern "C" fn() -> !) {
|
pub fn set_handler(&mut self, entry: u8, handler: extern "C" fn() -> !) -> &mut EntryOptions {
|
||||||
let segment: u16;
|
self.0[entry as usize] = Entry::new(segmentation::cs(), handler);
|
||||||
unsafe { asm!("mov %cs, $0" : "=r" (segment) ) };
|
|
||||||
let code_segment = SegmentSelector::from_raw(segment);
|
|
||||||
self.0[entry as usize] = Entry::new(code_segment, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn options(&mut self, entry: u8) -> &mut EntryOptions {
|
|
||||||
&mut self.0[entry as usize].options
|
&mut self.0[entry as usize].options
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +26,6 @@ impl Idt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use bit_field::BitField;
|
use bit_field::BitField;
|
||||||
use x86::segmentation::SegmentSelector;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
@@ -56,7 +50,7 @@ impl Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(gdt_selector: SegmentSelector, handler: extern "C" fn() -> !) -> Self {
|
fn new(gdt_selector: SegmentSelector, handler: extern "C" fn() -> !) -> Self {
|
||||||
let pointer = handler as u64;
|
let pointer = handler as u64;
|
||||||
Entry {
|
Entry {
|
||||||
gdt_selector: gdt_selector,
|
gdt_selector: gdt_selector,
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ lazy_static! {
|
|||||||
let mut idt = idt::Idt::new();
|
let mut idt = idt::Idt::new();
|
||||||
|
|
||||||
idt.set_handler(0, divide_by_zero_handler);
|
idt.set_handler(0, divide_by_zero_handler);
|
||||||
idt.set_handler(8, double_fault_handler);
|
idt.set_handler(8, double_fault_handler).set_stack_index(1);
|
||||||
idt.set_handler(13, general_protection_fault_handler);
|
idt.set_handler(13, general_protection_fault_handler);
|
||||||
idt.set_handler(14, page_fault_handler);
|
idt.set_handler(14, page_fault_handler);
|
||||||
|
|
||||||
idt.options(8).set_stack_index(1);
|
|
||||||
|
|
||||||
idt
|
idt
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user