Ehyve now returns with the first byte written to the shutdown port, if any....

Ehyve now returns with the first byte written to the shutdown port, if any. Useful for CI of ehyve VMs
parent 9f2e7ffb
......@@ -204,7 +204,7 @@ impl VirtualCPU for EhyveCPU {
Ok(())
}
fn run(&mut self) -> Result<()> {
fn run(&mut self) -> Result<u8> {
//self.print_registers();
loop {
......@@ -221,7 +221,9 @@ impl VirtualCPU for EhyveCPU {
}
VcpuExit::IoOut(port, addr) => match port {
SHUTDOWN_PORT => {
return Ok(());
// Return the first byte written to the port as
// return value
return Ok(addr[0]);
}
_ => {
self.io_exit(port, std::str::from_utf8(addr).unwrap().to_string())?;
......@@ -236,7 +238,7 @@ impl VirtualCPU for EhyveCPU {
}
}
Ok(())
Ok(0)
}
fn print_registers(&self) {
......
......@@ -328,7 +328,7 @@ impl VirtualCPU for EhyveCPU {
Ok(())
}
fn run(&mut self) -> Result<()> {
fn run(&mut self) -> Result<u8> {
//self.print_registers();
debug!("Run vCPU {}", self.id);
......@@ -404,7 +404,10 @@ impl VirtualCPU for EhyveCPU {
match port {
SHUTDOWN_PORT => {
return Ok(());
// Read the return value from the shutdown
// port
let ret_val = (self.vcpu.read_register(&x86Reg::RAX)? & 0xFF) as u8;
return Ok(ret_val);
}
COM_PORT => {
let al = (self.vcpu.read_register(&x86Reg::RAX)? & 0xFF) as u8;
......@@ -427,6 +430,7 @@ impl VirtualCPU for EhyveCPU {
}
}
}
Ok(0)
}
fn print_registers(&self) {
......
......@@ -120,9 +120,14 @@ fn main() {
let result = cpu.run();
match result {
Ok(()) => {}
Ok(ret_code) => {
if ret_code != 0 {
std::process::exit(ret_code as i32);
}
}
Err(x) => {
error!("CPU {} crashes! {}", tid, x);
std::process::exit(255);
}
}
})
......
......@@ -54,7 +54,7 @@ impl VmParameter {
pub trait VirtualCPU {
fn init(&mut self, entry_point: u64) -> Result<()>;
fn run(&mut self) -> Result<()>;
fn run(&mut self) -> Result<u8>;
fn print_registers(&self);
fn io_exit(&self, port: u16, message: String) -> Result<()> {
......
......@@ -126,7 +126,7 @@ impl VirtualCPU for EhyveCPU {
Ok(())
}
fn run(&mut self) -> Result<()> {
fn run(&mut self) -> Result<u8> {
debug!("Run vCPU {}", self.id);
loop {
let exit_context = self.vcpu.run().unwrap();
......@@ -137,7 +137,9 @@ impl VirtualCPU for EhyveCPU {
let io_port_access_ctx = unsafe { &exit_context.anon_union.IoPortAccess };
if io_port_access_ctx.PortNumber == SHUTDOWN_PORT {
return Ok(());
panic!("io_port_access_ctx: {:?}", io_port_access_ctx);
// TODO: get return value
return Ok(42);
}
let _status = e
......@@ -313,7 +315,7 @@ impl EmulatorCallbacks for EhyveCPU {
_context: *mut VOID,
io_access: &mut WHV_EMULATOR_IO_ACCESS_INFO,
) -> HRESULT {
if io_access.Port == 0x3f8 {
if io_access.Port == COM_PORT {
let cstr = unsafe {
std::str::from_utf8(std::slice::from_raw_parts(
&io_access.Data as *const _ as *const u8,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment