Skip to content

Commit

Permalink
Add struct to represent UART port syscall data
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhyte authored and jounathaen committed Jun 2, 2023
1 parent dc7da20 commit 3c332ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ pub trait VirtualCPU {
Hypercall::Cmdval(syscmdval)
}
HypercallAddress::Uart => Hypercall::SerialWriteByte(data as u8),
HypercallAddress::SerialWriteBuffer => {
let syscmdval = unsafe { &*(self.host_address(data) as *const SerialWriteBufferParams) };
Hypercall::SerialWriteBuffer(syscmdval)
}
_ => unimplemented!(),
})
} else {
Expand Down
5 changes: 5 additions & 0 deletions uhyve-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub enum HypercallAddress {
Uart = 0x800,
/// Port address = `0x840`
FileUnlink = 0x840,
/// Port address = `0x880`
SerialBufferWrite = 0x880,
}
impl From<Hypercall<'_>> for HypercallAddress {
fn from(value: Hypercall) -> Self {
Expand All @@ -71,6 +73,7 @@ impl From<Hypercall<'_>> for HypercallAddress {
Hypercall::FileWrite(_) => Self::FileWrite,
Hypercall::FileUnlink(_) => Self::FileUnlink,
Hypercall::SerialWriteByte(_) => Self::Uart,
Hypercall::SerialWriteBuffer(_) => Self::SerialBufferWrite,
}
}
}
Expand All @@ -95,6 +98,8 @@ pub enum Hypercall<'a> {
FileUnlink(&'a mut UnlinkParams),
/// Write a char to the terminal.
SerialWriteByte(u8),
/// Write a buffer to the terminal.
SerialWriteBuffer(&'a SerialWriteBufferParams),
}
impl<'a> Hypercall<'a> {
/// Get a hypercall's port address.
Expand Down
8 changes: 8 additions & 0 deletions uhyve-interface/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ pub struct LseekParams {
/// `whence` value of the lseek call.
pub whence: i32,
}

/// Parameters for a [`SerialWriteBuffer`](crate::Hypercall::SerialWriteBuffer) hypercall.
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct SerialWriteBufferParams {
buf: PhysAddr,
len: usize,
}

0 comments on commit 3c332ea

Please sign in to comment.