Skip to content

Commit 801d285

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 e09d7c0 commit 801d285

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/hyperlight_guest/src/idtr.rs

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

src/hyperlight_guest/src/lib.rs

+1
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)