Skip to content

Commit fbc8b1f

Browse files
authored
Merge pull request #84 from mythril-hypervisor/adam-dev
General interrupt and IO implementation
2 parents c2f90fc + 11647e8 commit fbc8b1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2418
-1214
lines changed

mythril/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mythril/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ description = "A intel-focused hypervisor using VT-x/EPT"
1111
test = []
1212

1313
[dependencies]
14+
arraydeque = { version = "0.4.5", default-features = false }
1415
arrayvec = { version = "0.5.1", default-features = false }
1516
bitflags = "1.2.0"
1617
byteorder = { version = "1", default-features = false }
@@ -25,7 +26,7 @@ spin = "0.5"
2526
ux = { version = "0.1.3", default-features = false }
2627

2728
[dependencies.iced-x86]
28-
version = "1.1.0"
29+
version = "1.8.0"
2930
default-features = false
3031
features = ["no_std", "decoder"]
3132

mythril/src/apic.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{declare_per_core, get_per_core, get_per_core_mut};
66
use raw_cpuid::CpuId;
77
use x86::msr;
88

9+
use core::fmt;
10+
911
/// APIC base physical address mask.
1012
const IA32_APIC_BASE_MASK: u64 = 0xffff_f000;
1113
/// xAPIC global enable mask
@@ -103,6 +105,33 @@ pub unsafe fn get_local_apic_mut() -> &'static mut LocalApic {
103105
.expect("Attempt to get local APIC before initialization")
104106
}
105107

108+
/// A representation of a APIC ID
109+
#[derive(Copy, Clone, Debug, Ord, PartialEq, PartialOrd, Eq)]
110+
pub struct ApicId {
111+
/// The raw ID as an integer
112+
pub raw: u32,
113+
}
114+
115+
impl ApicId {
116+
/// Returns whether this is the BSP core
117+
pub fn is_bsp(&self) -> bool {
118+
//TODO(alschwalm): This is not correct for multi socket systems
119+
self.raw == 0
120+
}
121+
}
122+
123+
impl From<u32> for ApicId {
124+
fn from(value: u32) -> Self {
125+
ApicId { raw: value }
126+
}
127+
}
128+
129+
impl fmt::Display for ApicId {
130+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
131+
write!(f, "0x{:x}", self.raw)
132+
}
133+
}
134+
106135
/// Structure defining the interface for a local x2APIC
107136
#[derive(Debug)]
108137
pub struct LocalApic {
@@ -188,8 +217,10 @@ impl LocalApic {
188217
}
189218

190219
/// The APIC ID
191-
pub fn id(&self) -> usize {
192-
unsafe { msr::rdmsr(msr::IA32_X2APIC_APICID) as usize }
220+
pub fn id(&self) -> ApicId {
221+
ApicId {
222+
raw: unsafe { msr::rdmsr(msr::IA32_X2APIC_APICID) as u32 },
223+
}
193224
}
194225

195226
/// The Logical APIC ID
@@ -249,15 +280,15 @@ impl LocalApic {
249280
/// Set the Interrupt Command Register
250281
pub fn send_ipi(
251282
&mut self,
252-
dst: u32,
283+
dst: ApicId,
253284
dst_short: DstShorthand,
254285
trigger: TriggerMode,
255286
level: Level,
256287
dst_mode: DstMode,
257288
delivery_mode: DeliveryMode,
258289
vector: u8,
259290
) {
260-
let mut icr: u64 = (dst as u64) << 32;
291+
let mut icr: u64 = (dst.raw as u64) << 32;
261292
icr |= (dst_short as u64) << 18;
262293
icr |= (trigger as u64) << 15;
263294
icr |= (level as u64) << 14;

mythril/src/boot.S

+29-3
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,36 @@ _start:
148148
call map_page_directory
149149
pop edi
150150

151-
; Disable IRQs (probably not necessary)
152-
mov al, 0xFF ; Out 0xFF to 0xA1 and 0x21 to disable all IRQs.
153-
out 0xA1, al
151+
; Setup PIC
152+
mov al, 0x11
153+
out 0x20, al
154+
out 0xa0, al
155+
156+
; Setup offsets
157+
mov al, 0x20
158+
out 0x21, al
159+
mov al, 0x28
160+
out 0xa1, al
161+
162+
mov al, 0x4
163+
out 0x21, al
164+
mov al, 0x2
165+
out 0xa1, al
166+
167+
mov al, 0x1
168+
out 0x21, al
169+
out 0xa1, al
170+
171+
;; Mask everything so the I/O APIC will work
172+
mov al, 0xff
154173
out 0x21, al
174+
mov al, 0xff
175+
out 0xA1, al
176+
177+
;; ACK any pending interrupts
178+
mov al, 0x20
179+
out 0x20, al
180+
out 0xa0, al
155181

156182
; Enter long mode.
157183
mov eax, 10100000b ; Set the PAE and PGE bit.

mythril/src/device/com.rs

-125
This file was deleted.

mythril/src/device/debug.rs

-60
This file was deleted.

mythril/src/device/keyboard.rs

-48
This file was deleted.

0 commit comments

Comments
 (0)