summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authornatrixaeria <upezu@student.kit.edu>2019-11-15 21:53:15 +0100
committernatrixaeria <upezu@student.kit.edu>2019-11-15 21:53:15 +0100
commitbd2e2835d5507f6df908640a151aa1093206f075 (patch)
tree6cac9499eb87ea59bbbb2f15c4434c1905bb184d /kernel
parent5e849967177a2ea639e783e847974db00cce2fff (diff)
Repare broken code
Diffstat (limited to 'kernel')
-rw-r--r--kernel/src/interrupts/apic.rs18
-rw-r--r--kernel/src/interrupts/idt.rs2
-rw-r--r--kernel/src/interrupts/interrupt_handlers.rs4
-rw-r--r--kernel/src/main.rs4
4 files changed, 15 insertions, 13 deletions
diff --git a/kernel/src/interrupts/apic.rs b/kernel/src/interrupts/apic.rs
index 5c236ea..14f6169 100644
--- a/kernel/src/interrupts/apic.rs
+++ b/kernel/src/interrupts/apic.rs
@@ -83,12 +83,12 @@ pub enum TimerDivideConfig {
static mut LOCAL_APIC: Option<Apic> = None;
-pub fn set_local_apic(apic: Apic) -> &mut Apic {
+pub unsafe fn set_local_apic(apic: Apic) -> &'static mut Apic {
LOCAL_APIC.get_or_insert(apic)
}
-pub fn get_local_apic() -> Option<Apic> {
- LOCAL_APIC
+pub unsafe fn get_local_apic() -> Option<&'static mut Apic> {
+ LOCAL_APIC.as_mut()
}
pub struct Apic {
@@ -103,7 +103,7 @@ impl Apic {
if !is_apic() { return None; }
let mut base_apic = unsafe { Msr::new(APIC_BASE_MSR).read() };
- let apic = Self::from_base_apic(base_apic);
+ let mut apic = Self::from_base_apic(base_apic);
let spurious = apic.get(ApicRegister::SpuriousInterruptVec) | 0x1ff;
@@ -116,11 +116,11 @@ impl Apic {
apic.set(ApicRegister::LvtLint0, 0);
apic.set(ApicRegister::LvtLint1, 0);
- apic
+ Some(apic)
}
fn from_base_apic(base_apic: u64) -> Self {
- Self { reg32:
+ Self { regs:
((base_apic >> 12) & 0xfffffffff) as *mut [u32; 1024]
}
}
@@ -148,8 +148,8 @@ impl Apic {
}
pub fn set_timer_interrupt_handler(&mut self, divide: TimerDivideConfig, intr: super::InterruptType) {
- apic.set(ApicRegister::LvtTimer, intr.into());
- apic.set(ApicRegister::TimerDivideConfig, divide);
- apic.set(ApicRegister::TimerInitialCount, 0xFFFFFFFF)
+ self.set(ApicRegister::LvtTimer, intr.as_u8().into());
+ self.set(ApicRegister::TimerDivideConfig, divide as u32);
+ self.set(ApicRegister::TimerInitialCount, 0xFFFFFFFF)
}
}
diff --git a/kernel/src/interrupts/idt.rs b/kernel/src/interrupts/idt.rs
index eb72fb0..8cd01d0 100644
--- a/kernel/src/interrupts/idt.rs
+++ b/kernel/src/interrupts/idt.rs
@@ -19,7 +19,7 @@ lazy_static! {
.set_handler_fn(exception_handlers::page_fault_handler)
.set_stack_index(gdt::PAGE_FAULT_IST_INDEX);
}
- idt[Interrupts::Timer.as_usize()].set_handler_fn(interrupt_handlers::timer_handler);
+ idt[InterruptType::Timer.as_usize()].set_handler_fn(interrupt_handlers::timer_handler);
idt
};
diff --git a/kernel/src/interrupts/interrupt_handlers.rs b/kernel/src/interrupts/interrupt_handlers.rs
index f05e2dc..4624723 100644
--- a/kernel/src/interrupts/interrupt_handlers.rs
+++ b/kernel/src/interrupts/interrupt_handlers.rs
@@ -5,5 +5,7 @@ use x86_64::structures::idt::{InterruptStackFrame, PageFaultErrorCode};
pub extern "x86-interrupt" fn timer_handler(stack_frame: &mut InterruptStackFrame) {
panic!("Timer interrupt recieved\n\n");
- super::apic::get_local_apic().map(|apic| apic.end_of_interrupt())
+ if let Some(apic) = unsafe { super::apic::get_local_apic() } {
+ apic.end_of_interrupt()
+ }
}
diff --git a/kernel/src/main.rs b/kernel/src/main.rs
index 08778f2..7cfbbe3 100644
--- a/kernel/src/main.rs
+++ b/kernel/src/main.rs
@@ -21,8 +21,8 @@ extern "C" fn _start() -> ! {
kernel::init();
x86_64::instructions::interrupts::enable();
- let apic = interrupts::apic::Apic::new();
- let apic = interrupts::apic::set_local_apic(apic);
+ let apic = interrupts::apic::Apic::new().expect("no APIC support");
+ let mut apic = unsafe { interrupts::apic::set_local_apic(apic) };
apic.set_timer_interrupt_handler(interrupts::apic::TimerDivideConfig::Div32, interrupts::InterruptType::Timer);
if cfg!(test) {