Skip to content

Commit

Permalink
[hal] E: Refactoring IDT
Browse files Browse the repository at this point in the history
  • Loading branch information
ppenna committed Aug 11, 2024
1 parent c9c8611 commit 9d39aca
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/hal/arch/x86/cpu/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,25 @@ pub const EXCP_OFF: u8 = 0;
///
pub const INT_OFF: u8 = 32;

///
/// # Description
///
/// Length of the IDT.
///
pub const IDT_LEN: usize = 256;

///
/// # Description
///
/// Size of the IDT.
///
pub const IDT_SIZE: usize = IDT_LEN * mem::size_of::<Idte>();

//==================================================================================================
// Global Variables
//==================================================================================================

static mut IDT: [Idte; 256] = unsafe { mem::zeroed() };
static mut IDT: [Idte; IDT_LEN] = unsafe { mem::zeroed() };

static mut IDTR: Idtr = unsafe { mem::zeroed() };

Expand Down Expand Up @@ -204,7 +218,10 @@ pub unsafe fn init() {
IDT[128] = idt_entry!(_do_kcall, DescriptorPrivilegeLevel::Ring3, GateType::Int32);

// Load IDT.
info!("loading idt (base={:p}, size={})", IDT.as_ptr(), mem::size_of_val(&IDT));
IDTR.init(IDT.as_ptr() as u32, (mem::size_of_val(&IDT)) as u16);
info!("loading idt (base={:p}, size={})", IDT.as_ptr(), IDT_SIZE);
IDTR.init(
IDT.as_ptr() as u32,
u16::try_from(IDT_SIZE).expect("wrong idt size, is it corrupted?"),
);
IDTR.load();
}

0 comments on commit 9d39aca

Please sign in to comment.