Skip to content

Commit ef5fce8

Browse files
committed
[interrupt-handlers] added IDTR
- made Idtr structure (+ its static mut global var) to house the IDT, and - made load_idt fxn that uses global_asm's lidt to load the IDT. Signed-off-by: danbugs <[email protected]>
1 parent 91b7de6 commit ef5fce8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/hyperlight_guest/src/idtr.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use core::ptr::addr_of;
2+
use crate::idt::{IdtEntry, IDT};
3+
4+
#[repr(C, packed)]
5+
pub struct Idtr {
6+
pub limit: u16,
7+
pub base: u64,
8+
}
9+
10+
static mut IDTR: Idtr = Idtr { limit: 0, base: 0 };
11+
12+
impl Idtr {
13+
pub unsafe fn init(&mut self, base: u64, size: u16) {
14+
self.limit = size - 1;
15+
self.base = base;
16+
}
17+
18+
pub unsafe fn load(&self) {
19+
core::arch::asm!("lidt [{}]", in(reg) self, options(readonly, nostack, preserves_flags));
20+
}
21+
}
22+
23+
pub(crate) unsafe fn load_idt() {
24+
let idt_size = 256 * size_of::<IdtEntry>();
25+
let expected_base = addr_of!(IDT) as *const _ as u64;
26+
27+
IDTR.init(expected_base, idt_size as u16);
28+
IDTR.load();
29+
}

src/hyperlight_guest/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub mod logging;
5454
pub mod interrupt_entry;
5555
pub mod interrupt_handlers;
5656
pub mod idt;
57+
pub mod idtr;
5758

5859
// Unresolved symbols
5960
///cbindgen:ignore

0 commit comments

Comments
 (0)