Skip to content

Commit

Permalink
refactor(uhyve): unify uhyve_send
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed Sep 21, 2024
1 parent b3ca333 commit 7187617
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/syscalls/interfaces/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use alloc::boxed::Box;
use alloc::vec::Vec;
use core::{mem, ptr};

#[cfg(target_arch = "x86_64")]
use x86::io::*;

use crate::arch;
use crate::arch::mm::{paging, PhysAddr, VirtAddr};
use crate::syscalls::interfaces::SyscallInterface;
Expand All @@ -16,40 +13,27 @@ const UHYVE_PORT_CMDVAL: u16 = 0x780;

/// forward a request to the hypervisor uhyve
#[inline]
#[cfg(target_arch = "x86_64")]
fn uhyve_send<T>(port: u16, data: &mut T) {
let ptr = VirtAddr(ptr::from_mut(data).addr() as u64);
let physical_address = paging::virtual_to_physical(ptr).unwrap();

#[cfg(target_arch = "x86_64")]
unsafe {
outl(port, physical_address.as_u64() as u32);
x86::io::outl(port, physical_address.as_u64() as u32);
}
}

/// forward a request to the hypervisor uhyve
#[inline]
#[cfg(target_arch = "aarch64")]
fn uhyve_send<T>(port: u16, data: &mut T) {
use core::arch::asm;

let ptr = VirtAddr(ptr::from_mut(data).addr() as u64);
let physical_address = paging::virtual_to_physical(ptr).unwrap();

#[cfg(target_arch = "aarch64")]
unsafe {
asm!(
core::arch::asm!(
"str x8, [{port}]",
port = in(reg) u64::from(port),
in("x8") physical_address.as_u64(),
options(nostack),
);
}
}

/// forward a request to the hypervisor uhyve
#[inline]
#[cfg(target_arch = "riscv64")]
fn uhyve_send<T>(_port: u16, _data: &mut T) {
todo!()
#[cfg(target_arch = "riscv64")]
todo!("uhyve_send(port = {port}, physical_address = {physical_address})");
}

const MAX_ARGC_ENVC: usize = 128;
Expand Down

0 comments on commit 7187617

Please sign in to comment.