Skip to content

Commit 1b8a8e2

Browse files
authored
Merge pull request #92 from nolandda/noland_dev
IoApic convenience function to get a Range of IVs
2 parents fbc8b1f + 49ca72a commit 1b8a8e2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ A rust-based hypervisor currently requiring multiboot2 boot (e.g. grub), and VT-
44

55
## Building and Testing
66

7+
Don't forget to clone using `--recurse-submodules` or if you've
8+
already cloned `git submodule update --init --recursive` to get the
9+
dependencies.
10+
711
`mythril` should be built and tested using the provided docker image
812
`adamschwalm/hypervisor-build`. There are convenience `make` rules for
913
using this image. For example, to build the multiboot application, run:
@@ -58,4 +62,4 @@ Breakpoint 1, kmain (multiboot_info_addr=10993664) at mythril_multiboot2/src/mai
5862
151 unsafe { interrupt::idt::init() };
5963
```
6064

61-
You can then use `step` and other debugging functions as usual.
65+
You can then use `step` and other debugging functions as usual.

mythril/src/ioapic.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::acpi::madt::{Ics, MADT};
1616
use crate::error::{Error, Result};
1717
use crate::lock::ro_after_init::RoAfterInit;
1818
use core::convert::TryFrom;
19+
use core::ops::Range;
1920
use core::fmt;
2021
use core::ptr;
2122

@@ -49,10 +50,8 @@ static IOAPICS: RoAfterInit<ArrayVec<[IoApic; MAX_IOAPIC_COUNT]>> =
4950
// TODO(alschwalm): Support InterruptSourceOverride
5051
fn ioapic_for_gsi(gsi: u32) -> Option<(&'static IoApic, u8)> {
5152
for ioapic in IOAPICS.iter() {
52-
let entries = ioapic.max_redirection_entry() as u32;
53-
let base = ioapic.gsi_base;
54-
if gsi > base && gsi < base + entries {
55-
return Some((ioapic, (gsi - base) as u8));
53+
if ioapic.get_ivec_range().contains(&gsi) {
54+
return Some((ioapic, (gsi - ioapic.gsi_base) as u8));
5655
}
5756
}
5857
None
@@ -285,6 +284,13 @@ impl IoApic {
285284
Ok(())
286285
}
287286
}
287+
288+
/// convenience function to get a Range of the interrupt vectors
289+
/// that should be associated with this IoApic.
290+
pub fn get_ivec_range(&self) -> Range<u32> {
291+
return Range{ start: self.gsi_base, end: self.gsi_base +
292+
(self.max_redirection_entry() as u32) };
293+
}
288294
}
289295

290296
impl TryFrom<Ics> for IoApic {

0 commit comments

Comments
 (0)