diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-09-10 21:19:02 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-09-10 21:19:02 +0800 |
| commit | f07ff5fad29c63fc4e332afcb08f99fff3df3e0c (patch) | |
| tree | 74b4a28d962a5d52926c21dba99bdf78245593eb /kernel/src/init/cpu | |
| parent | 047a997e3d6e06f6d0a95c473c6f497a88af6b89 (diff) | |
refactor: move init cpu specific into cpu/
Diffstat (limited to 'kernel/src/init/cpu')
| -rw-r--r-- | kernel/src/init/cpu/int.rs | 7 | ||||
| -rw-r--r-- | kernel/src/init/cpu/int/idt.rs | 24 |
2 files changed, 31 insertions, 0 deletions
diff --git a/kernel/src/init/cpu/int.rs b/kernel/src/init/cpu/int.rs new file mode 100644 index 0000000..e2b1c9f --- /dev/null +++ b/kernel/src/init/cpu/int.rs @@ -0,0 +1,7 @@ +use crate::init::cpu::int::idt::IDT; + +pub mod idt; + +pub fn init() { + IDT.load(); +} diff --git a/kernel/src/init/cpu/int/idt.rs b/kernel/src/init/cpu/int/idt.rs new file mode 100644 index 0000000..80d42f8 --- /dev/null +++ b/kernel/src/init/cpu/int/idt.rs @@ -0,0 +1,24 @@ +use spin::LazyLock; +use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; + +use crate::init::earlyprintk::printlnk; + +pub static IDT: LazyLock<InterruptDescriptorTable> = LazyLock::new( + || { + let mut idt = InterruptDescriptorTable::new(); + idt.breakpoint.set_handler_fn(breakpoint_handler); + idt.double_fault.set_handler_fn(double_fault_handler); + idt + }, +); + +extern "x86-interrupt" fn double_fault_handler( + stack_frame: InterruptStackFrame, + error_code: u64, +) -> ! { + panic!("EXCEPTION: DOUBLE FAULT\n{stack_frame:#?}\nERROR CODE:{error_code}"); +} + +extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) { + _ = printlnk!("EXCEPTION: BREAKPOINT\n{stack_frame:#?}"); +} |
