diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/long_mode.rs | 12 | ||||
-rw-r--r-- | examples/real_mode.rs | 12 |
2 files changed, 22 insertions, 2 deletions
diff --git a/examples/long_mode.rs b/examples/long_mode.rs index 67c014a..668364f 100644 --- a/examples/long_mode.rs +++ b/examples/long_mode.rs @@ -126,7 +126,7 @@ fn setup_long_mode(sregs: &mut kvm_sys::kvm_sregs, mem: &mut UserMem) { fn main() -> std::io::Result<()> { // Create VM & VCPU. let vm = Kvm::new()?.create_vm()?; - let vcpu = vm.create_vpcu(0)?; + let mut vcpu = vm.create_vpcu(0)?; // Map memory for guest VM. let mut mem = UserMem::new(0x8000)?; @@ -155,10 +155,20 @@ fn main() -> std::io::Result<()> { while let Ok(exit) = vcpu.run() { match exit { KvmExit::Halt => break, + KvmExit::IoIn(port, data) => { + println!("IO_IN: port={} len={}", port, data.len()); + // Provide some input data. + data.fill(0xaa); + } KvmExit::IoOut(_port, data) => { let s = std::str::from_utf8(data).unwrap(); print!("{}", s); } + KvmExit::MmioRead(addr, data) => { + println!("MMIO_READ: addr={:#x} len={}", addr, data.len()); + // Provide some read data. + data.fill(0xbb); + } KvmExit::MmioWrite(addr, data) => { println!( "MMIO_WRITE: addr={:#x} len={} data={:#x?}", diff --git a/examples/real_mode.rs b/examples/real_mode.rs index 70f3e1d..f37d45c 100644 --- a/examples/real_mode.rs +++ b/examples/real_mode.rs @@ -5,7 +5,7 @@ use kvm_rs::{PhysAddr, UserMem}; fn main() -> std::io::Result<()> { // Create VM & VCPU. let vm = Kvm::new()?.create_vm()?; - let vcpu = vm.create_vpcu(0)?; + let mut vcpu = vm.create_vpcu(0)?; // Map memory for guest VM and initialize with guest image. let mem = UserMem::with_init(0x1000, include_bytes!("../guest/guest16"))?; @@ -29,10 +29,20 @@ fn main() -> std::io::Result<()> { while let Ok(exit) = vcpu.run() { match exit { KvmExit::Halt => break, + KvmExit::IoIn(port, data) => { + println!("IO_IN: port={} len={}", port, data.len()); + // Provide some input data. + data.fill(0xaa); + } KvmExit::IoOut(_port, data) => { let s = std::str::from_utf8(data).unwrap(); print!("{}", s); } + KvmExit::MmioRead(addr, data) => { + println!("MMIO_READ: addr={:#x} len={}", addr, data.len()); + // Provide some read data. + data.fill(0xbb); + } KvmExit::MmioWrite(addr, data) => { println!( "MMIO_WRITE: addr={:#x} len={} data={:#x?}", |