Skip to content

Commit 3761494

Browse files
committed
Use GSI constants
1 parent 7b921f6 commit 3761494

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

mythril/src/interrupt/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
pub mod idt;
22

3-
pub const UART_VECTOR: u8 = 36;
4-
pub const TIMER_VECTOR: u8 = 48;
5-
pub const IPC_VECTOR: u8 = 49;
3+
pub mod vector {
4+
pub const UART: u8 = 36;
5+
pub const TIMER: u8 = 48;
6+
pub const IPC: u8 = 49;
7+
}
8+
9+
pub mod gsi {
10+
pub const PIT: u32 = 0;
11+
pub const UART: u32 = 4;
12+
}
613

714
pub unsafe fn enable_interrupts() {
815
llvm_asm!("sti" :::: "volatile");

mythril/src/kmain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ unsafe fn kmain(mut boot_info: BootInfo) -> ! {
250250
apic::LocalApic::init().expect("Failed to initialize local APIC");
251251

252252
ioapic::init_ioapics(&madt).expect("Failed to initialize IOAPICs");
253-
ioapic::map_gsi_vector(4, interrupt::UART_VECTOR, 0)
253+
ioapic::map_gsi_vector(interrupt::gsi::UART, interrupt::vector::UART, 0)
254254
.expect("Failed to map com0 gsi");
255255

256256
let mut builder = vm::VirtualMachineBuilder::new();

mythril/src/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl TimerWheel {
333333
if let Some((when, _)) = soonest {
334334
unsafe {
335335
apic::get_local_apic_mut()
336-
.schedule_interrupt(when, interrupt::TIMER_VECTOR);
336+
.schedule_interrupt(when, interrupt::vector::TIMER);
337337
}
338338
}
339339
}

mythril/src/vcpu.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,10 @@ impl VCpu {
626626
vmexit::ExitInformation::InterruptWindow => {}
627627
vmexit::ExitInformation::ExternalInterrupt(info) => unsafe {
628628
match info.vector {
629-
interrupt::UART_VECTOR => {
629+
interrupt::vector::UART => {
630630
self.handle_uart_keypress(&mut responses)?
631631
}
632-
interrupt::IPC_VECTOR => {
632+
interrupt::vector::IPC => {
633633
let msg =
634634
vm::recv_msg().ok_or_else(|| Error::NotFound)?;
635635
match msg {
@@ -698,8 +698,8 @@ impl VCpu {
698698

699699
//FIXME(alschwalm): this should be the APIC id of the bsp, not the core id
700700
ioapic::map_gsi_vector(
701-
4,
702-
interrupt::UART_VECTOR,
701+
interrupt::gsi::UART,
702+
interrupt::vector::UART,
703703
next_bsp.raw as u8,
704704
)
705705
.map_err(|_| {

mythril/src/virtdev/com.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::error::Result;
2+
use crate::interrupt;
23
use crate::physdev::com::*;
3-
use crate::vcpu;
44
use crate::virtdev::{
55
DeviceEvent, DeviceEventResponse, DeviceRegion, EmulatedDevice, Event, Port,
66
};
@@ -61,7 +61,9 @@ impl EmulatedDevice for Uart8250 {
6161
fn on_event(&mut self, event: Event) -> Result<()> {
6262
match event.kind {
6363
DeviceEvent::HostUartReceived(key) => {
64-
event.responses.push(DeviceEventResponse::GSI(4));
64+
event
65+
.responses
66+
.push(DeviceEventResponse::GSI(interrupt::gsi::UART));
6567
if key == 0x01 {
6668
// ctrl+a
6769
self.ctrl_a_count += 1;
@@ -130,7 +132,9 @@ impl EmulatedDevice for Uart8250 {
130132
.interrupt_enable_register
131133
.contains(IerFlags::THR_EMPTY_INTERRUPT)
132134
{
133-
event.responses.push(DeviceEventResponse::GSI(4));
135+
event.responses.push(DeviceEventResponse::GSI(
136+
interrupt::gsi::UART,
137+
));
134138
}
135139
self.interrupt_identification_register = 0b10;
136140
}

mythril/src/virtdev/pit.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::error::{Error, Result};
2+
use crate::interrupt;
23
use crate::physdev::pit::*;
34
use crate::time;
45
use crate::virtdev::{
@@ -227,7 +228,9 @@ impl Pit8254 {
227228
if port == PIT_COUNTER_0 {
228229
*timer = Some(time::set_oneshot_timer(
229230
duration,
230-
time::TimerInterruptType::GSI(0),
231+
time::TimerInterruptType::GSI(
232+
interrupt::gsi::PIT,
233+
),
231234
));
232235
}
233236
}
@@ -243,7 +246,9 @@ impl Pit8254 {
243246
if port == PIT_COUNTER_0 {
244247
*timer = Some(time::set_periodic_timer(
245248
duration,
246-
time::TimerInterruptType::GSI(0),
249+
time::TimerInterruptType::GSI(
250+
interrupt::gsi::PIT,
251+
),
247252
));
248253
}
249254
}

mythril/src/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl VirtualMachines {
178178
apic::Level::Assert,
179179
apic::DstMode::Physical,
180180
apic::DeliveryMode::Fixed,
181-
interrupt::IPC_VECTOR,
181+
interrupt::vector::IPC,
182182
);
183183
}
184184

@@ -435,7 +435,7 @@ impl VirtualMachine {
435435
// guest IO APICs. For now just blindly translate GSI to vector based
436436
// on this basic formula.
437437
let vector = (gsi + 48) as u8;
438-
if gsi == 4 {
438+
if gsi == interrupt::gsi::UART {
439439
Ok((
440440
self.config.bsp_id(),
441441
vector,

0 commit comments

Comments
 (0)