From 7161da589e7e938742246068d09413b5f690543e Mon Sep 17 00:00:00 2001 From: Andrew Bresticker Date: Fri, 23 Dec 2022 12:28:05 -0500 Subject: [PATCH] Vm: Forward legacy put_char() to host Like the debug console, this should get forwarded to the VM's host rather than having Salus print directly to the console. Signed-off-by: Andrew Bresticker --- src/host_vm.rs | 3 +++ src/vm.rs | 11 +++-------- test-workloads/src/bin/tellus.rs | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/host_vm.rs b/src/host_vm.rs index 37914dbb..c47b7636 100644 --- a/src/host_vm.rs +++ b/src/host_vm.rs @@ -431,6 +431,9 @@ impl HostVmRunner { // Can't do anything about errors right now. let _ = self.handle_put_string(&vm, addr, len); } + Ok(PutChar(c)) => { + print!("{}", c as u8 as char); + } _ => { println!("Unhandled ECALL from host"); return ControlFlow::Break(()); diff --git a/src/vm.rs b/src/vm.rs index fd56514c..7e4ebb4e 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -193,7 +193,6 @@ impl From for EcallError { #[derive(Clone, Copy, Debug)] enum EcallAction { - LegacyOk, Unhandled, Continue(SbiReturn), Break(VmExitCause, SbiReturn), @@ -489,9 +488,6 @@ impl<'a, T: GuestStagePagingMode> FinalizedVm<'a, T> { match exit { VmCpuTrap::Ecall(Some(sbi_msg)) => { match self.handle_ecall(sbi_msg, &mut active_vcpu) { - EcallAction::LegacyOk => { - active_vcpu.set_ecall_result(Legacy(0)); - } EcallAction::Unhandled => { active_vcpu.set_ecall_result(Standard(SbiReturn::from( SbiError::NotSupported, @@ -705,10 +701,9 @@ impl<'a, T: GuestStagePagingMode> FinalizedVm<'a, T> { /// Handles ecalls from the guest. fn handle_ecall(&self, msg: SbiMessage, active_vcpu: &mut ActiveVmCpu) -> EcallAction { match msg { - SbiMessage::PutChar(c) => { - // put char - legacy command - print!("{}", c as u8 as char); - EcallAction::LegacyOk + SbiMessage::PutChar(_) => { + // TODO: Let the host set the return value and forward it to the guest. + EcallAction::Break(VmExitCause::ResumableEcall(msg), SbiReturn::success(0)) } SbiMessage::Reset(ResetFunction::Reset { .. }) => { EcallAction::Break(VmExitCause::FatalEcall(msg), SbiReturn::success(0)) diff --git a/test-workloads/src/bin/tellus.rs b/test-workloads/src/bin/tellus.rs index 21db5435..727fda21 100644 --- a/test-workloads/src/bin/tellus.rs +++ b/test-workloads/src/bin/tellus.rs @@ -643,6 +643,9 @@ extern "C" fn kernel_init(hart_id: u64, fdt_addr: u64) { len, ); } + Ok(PutChar(c)) => { + print!("{}", c as u8 as char); + } _ => { println!("Unexpected ECALL from guest"); break;