1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use core::mem::size_of;
use irq::IdtEntry;
use VirtualAddress;
#[derive(Debug)]
#[repr(C, packed)]
pub struct DescriptorTablePointer {
pub limit: u16,
pub base: VirtualAddress,
}
impl DescriptorTablePointer {
fn new<T>(slice: &[T]) -> Self {
let len = slice.len() * size_of::<T>();
assert!(len < 0x10000);
DescriptorTablePointer {
base: VirtualAddress::from(slice.as_ptr() as usize),
limit: len as u16,
}
}
}
impl DescriptorTablePointer {
pub fn new_idtp(idt: &[IdtEntry]) -> Self {
Self::new(idt)
}
}
pub unsafe fn lgdt(gdt: &DescriptorTablePointer) {
asm!("lgdt ($0)" :: "r" (gdt) : "memory");
}
pub unsafe fn lldt(ldt: &DescriptorTablePointer) {
asm!("lldt ($0)" :: "r" (ldt) : "memory");
}
pub unsafe fn lidt(idt: &DescriptorTablePointer) {
asm!("lidt ($0)" :: "r" (idt) : "memory");
}