Typing in terminal is now supported in rust teton.
This commit is contained in:
parent
18e512cf1f
commit
f04e720811
15 changed files with 489 additions and 13 deletions
|
|
@ -10,6 +10,7 @@ pub mod macros;
|
|||
|
||||
pub mod init;
|
||||
pub mod mem;
|
||||
pub mod port;
|
||||
pub mod syscall;
|
||||
pub mod thread;
|
||||
pub mod zion;
|
||||
|
|
|
|||
42
rust/lib/mammoth/src/port.rs
Normal file
42
rust/lib/mammoth/src/port.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use crate::syscall::{cap_duplicate, cap_release, port_create, port_recv};
|
||||
use crate::zion::{kZionPerm_Read, z_cap_t, ZError};
|
||||
|
||||
pub struct PortServer {
|
||||
port_cap: z_cap_t,
|
||||
}
|
||||
|
||||
impl PortServer {
|
||||
pub fn new() -> Result<Self, ZError> {
|
||||
Ok(Self {
|
||||
port_cap: port_create()?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_client_cap(&self) -> Result<z_cap_t, ZError> {
|
||||
cap_duplicate(self.port_cap, !kZionPerm_Read)
|
||||
}
|
||||
|
||||
pub fn recv_byte(&self) -> Result<u8, ZError> {
|
||||
let mut caps: [z_cap_t; 0] = [];
|
||||
let mut bytes: [u8; 1] = [0];
|
||||
|
||||
port_recv(self.port_cap, &mut bytes, &mut caps)?;
|
||||
|
||||
Ok(bytes[0])
|
||||
}
|
||||
|
||||
pub fn recv_u16(&self) -> Result<u16, ZError> {
|
||||
let mut caps: [z_cap_t; 0] = [];
|
||||
let mut bytes: [u8; 2] = [0; 2];
|
||||
|
||||
port_recv(self.port_cap, &mut bytes, &mut caps)?;
|
||||
|
||||
Ok(u16::from_le_bytes(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PortServer {
|
||||
fn drop(&mut self) {
|
||||
cap_release(self.port_cap).expect("Failed to release port cap");
|
||||
}
|
||||
}
|
||||
|
|
@ -140,6 +140,37 @@ pub fn address_space_unmap(lower_addr: u64, upper_addr: u64) -> Result<(), ZErro
|
|||
)
|
||||
}
|
||||
|
||||
pub fn port_create() -> Result<z_cap_t, ZError> {
|
||||
let mut port_cap = 0;
|
||||
syscall(
|
||||
zion::kZionPortCreate,
|
||||
&zion::ZPortCreateReq {
|
||||
port_cap: &mut port_cap,
|
||||
},
|
||||
)?;
|
||||
Ok(port_cap)
|
||||
}
|
||||
|
||||
pub fn port_recv(
|
||||
port_cap: z_cap_t,
|
||||
bytes: &mut [u8],
|
||||
caps: &mut [u64],
|
||||
) -> Result<(u64, u64), ZError> {
|
||||
let mut num_bytes = bytes.len() as u64;
|
||||
let mut num_caps = caps.len() as u64;
|
||||
syscall(
|
||||
zion::kZionPortRecv,
|
||||
&zion::ZPortRecvReq {
|
||||
port_cap,
|
||||
data: bytes.as_mut_ptr() as *mut c_void,
|
||||
num_bytes: &mut num_bytes as *mut u64,
|
||||
caps: caps.as_mut_ptr(),
|
||||
num_caps: &mut num_caps as *mut u64,
|
||||
},
|
||||
)?;
|
||||
Ok((num_bytes, num_caps))
|
||||
}
|
||||
|
||||
pub fn port_poll(
|
||||
port_cap: z_cap_t,
|
||||
bytes: &mut [u8],
|
||||
|
|
@ -248,6 +279,19 @@ pub fn reply_port_recv(
|
|||
Ok((num_bytes, num_caps))
|
||||
}
|
||||
|
||||
pub fn cap_duplicate(cap: z_cap_t, perm_mask: u64) -> Result<z_cap_t, ZError> {
|
||||
let mut new_cap = 0;
|
||||
syscall(
|
||||
zion::kZionCapDuplicate,
|
||||
&zion::ZCapDuplicateReq {
|
||||
cap_in: cap,
|
||||
perm_mask,
|
||||
cap_out: &mut new_cap,
|
||||
},
|
||||
)?;
|
||||
Ok(new_cap)
|
||||
}
|
||||
|
||||
pub fn cap_release(cap: z_cap_t) -> Result<(), ZError> {
|
||||
syscall(zion::kZionCapRelease, &zion::ZCapReleaseReq { cap })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue