Skip to content

Commit

Permalink
Page table are now indexed with u8 instead of usize
Browse files Browse the repository at this point in the history
Since #319
  • Loading branch information
phil-opp committed Feb 3, 2022
1 parent ea00bfd commit 5efea6a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/structures/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,15 +1394,15 @@ macro_rules! set_general_handler_entry {
extern "x86-interrupt" fn handler(frame: $crate::structures::idt::InterruptStackFrame) {
$handler(frame, $idx.into(), None);
}
$idt[$idx as usize].set_handler_fn(handler);
$idt[$idx].set_handler_fn(handler);
}};
}

#[cfg(test)]
mod test {
use super::*;

fn entry_present(idt: &InterruptDescriptorTable, index: usize) -> bool {
fn entry_present(idt: &InterruptDescriptorTable, index: u8) -> bool {
let options = match index {
8 => &idt.double_fault.options,
10 => &idt.invalid_tss.options,
Expand All @@ -1413,13 +1413,13 @@ mod test {
15 => &idt.reserved_1.options,
17 => &idt.alignment_check.options,
18 => &idt.machine_check.options,
i @ 21..=28 => &idt.reserved_2[i - 21].options,
i @ 21..=28 => &idt.reserved_2[usize::from(i) - 21].options,
29 => &idt.vmm_communication_exception.options,
30 => &idt.security_exception.options,
31 => &idt.reserved_3.options,
other => &idt[other].options,
};
options.0.get_bit(15)
options.bits.get_bit(15)
}

#[test]
Expand All @@ -1446,31 +1446,31 @@ mod test {

let mut idt = InterruptDescriptorTable::new();
set_general_handler!(&mut idt, general_handler, 0);
for i in 0..256 {
for i in 0..=255 {
if i == 0 {
assert!(entry_present(&idt, i));
} else {
assert!(!entry_present(&idt, i));
}
}
set_general_handler!(&mut idt, general_handler, 14);
for i in 0..256 {
for i in 0..=255 {
if i == 0 || i == 14 {
assert!(entry_present(&idt, i));
} else {
assert!(!entry_present(&idt, i));
}
}
set_general_handler!(&mut idt, general_handler, 32..64);
for i in 1..256 {
for i in 1..=255 {
if i == 0 || i == 14 || (32..64).contains(&i) {
assert!(entry_present(&idt, i), "{}", i);
} else {
assert!(!entry_present(&idt, i));
}
}
set_general_handler!(&mut idt, general_handler);
for i in 0..256 {
for i in 0..=255 {
if i == 15 || i == 31 || (21..=28).contains(&i) {
// reserved entries should not be set
assert!(!entry_present(&idt, i));
Expand Down

0 comments on commit 5efea6a

Please sign in to comment.