Skip to content

Commit

Permalink
Vm: Forward legacy put_char() to host
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
abrestic-rivos committed Jan 3, 2023
1 parent 6b6e72d commit 7161da5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/host_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down
11 changes: 3 additions & 8 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ impl From<SbiError> for EcallError {

#[derive(Clone, Copy, Debug)]
enum EcallAction {
LegacyOk,
Unhandled,
Continue(SbiReturn),
Break(VmExitCause, SbiReturn),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<T>) -> 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))
Expand Down
3 changes: 3 additions & 0 deletions test-workloads/src/bin/tellus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7161da5

Please sign in to comment.