Skip to content

Commit 465df1d

Browse files
authored
Add sidt support (#246)
1 parent 75f3a58 commit 465df1d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/asm/asm.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ _x86_64_asm_lidt:
119119
lidt (%rdi)
120120
retq
121121

122+
.global _x86_64_asm_sidt
123+
.p2align 4
124+
_x86_64_asm_sidt:
125+
sidt (%rdi)
126+
retq
127+
122128
.global _x86_64_asm_write_rflags
123129
.p2align 4
124130
_x86_64_asm_write_rflags:

src/asm/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ extern "C" {
132132
)]
133133
pub(crate) fn x86_64_asm_lidt(idt: *const crate::instructions::tables::DescriptorTablePointer);
134134

135+
#[cfg_attr(
136+
any(target_env = "gnu", target_env = "musl"),
137+
link_name = "_x86_64_asm_sidt"
138+
)]
139+
pub(crate) fn x86_64_asm_sidt(idt: *mut crate::instructions::tables::DescriptorTablePointer);
140+
135141
#[cfg_attr(
136142
any(target_env = "gnu", target_env = "musl"),
137143
link_name = "_x86_64_asm_ltr"

src/instructions/tables.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Functions to load GDT, IDT, and TSS structures.
22
33
use crate::structures::gdt::SegmentSelector;
4+
use crate::VirtAddr;
45

56
pub use crate::structures::DescriptorTablePointer;
67

@@ -44,6 +45,25 @@ pub unsafe fn lidt(idt: &DescriptorTablePointer) {
4445
crate::asm::x86_64_asm_lidt(idt as *const _);
4546
}
4647

48+
/// Get the address of the current IDT.
49+
#[inline]
50+
pub fn sidt() -> DescriptorTablePointer {
51+
let mut idt: DescriptorTablePointer = DescriptorTablePointer {
52+
limit: 0,
53+
base: VirtAddr::new(0),
54+
};
55+
#[cfg(feature = "inline_asm")]
56+
unsafe {
57+
asm!("sidt [{}]", in(reg) &mut idt, options(nostack));
58+
}
59+
#[cfg(not(feature = "inline_asm"))]
60+
unsafe {
61+
crate::asm::x86_64_asm_sidt(&mut idt as *mut _);
62+
}
63+
64+
idt
65+
}
66+
4767
/// Load the task state register using the `ltr` instruction.
4868
///
4969
/// ## Safety

0 commit comments

Comments
 (0)