Compare commits
2 Commits
5705f8d2ab
...
d4f60f4942
Author | SHA1 | Date |
---|---|---|
Drew Galbraith | d4f60f4942 | |
Drew Galbraith | c2f9f5388b |
|
@ -50,18 +50,13 @@ macro_rules! debug {
|
|||
macro_rules! define_entry {
|
||||
() => {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start(init_port: mammoth::zion::z_cap_t) -> ! {
|
||||
extern "C" {
|
||||
fn main() -> z_err_t;
|
||||
}
|
||||
mammoth::init::parse_init_port(init_port);
|
||||
mammoth::mem::init_heap();
|
||||
unsafe {
|
||||
let err = main();
|
||||
let req = mammoth::zion::ZProcessExitReq { code: err };
|
||||
let _ = mammoth::syscall::syscall(mammoth::zion::kZionProcessExit, &req);
|
||||
}
|
||||
unreachable!()
|
||||
pub extern "C" fn _start(init_port: $crate::zion::z_cap_t) -> ! {
|
||||
$crate::init::parse_init_port(init_port);
|
||||
$crate::mem::init_heap();
|
||||
|
||||
let resp = main();
|
||||
|
||||
$crate::syscall::process_exit(resp);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use core::ffi::c_void;
|
|||
use core::panic::PanicInfo;
|
||||
|
||||
#[must_use]
|
||||
pub fn syscall<T>(id: u64, req: &T) -> Result<(), ZError> {
|
||||
fn syscall<T>(id: u64, req: &T) -> Result<(), ZError> {
|
||||
unsafe {
|
||||
let resp = zion::SysCall1(id, req as *const T as *const c_void);
|
||||
if resp != 0 {
|
||||
|
@ -40,6 +40,12 @@ pub fn debug(msg: &str) {
|
|||
syscall(zion::kZionDebug, &req).expect("Failed to write");
|
||||
}
|
||||
|
||||
pub fn process_exit(code: u64) -> ! {
|
||||
let _ = syscall(zion::kZionProcessExit, &zion::ZProcessExitReq { code });
|
||||
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
pub fn thread_create(proc_cap: z_cap_t) -> Result<z_cap_t, ZError> {
|
||||
let mut cap = 0;
|
||||
syscall(
|
||||
|
@ -115,3 +121,43 @@ pub fn port_poll(
|
|||
syscall(zion::kZionPortPoll, &req)?;
|
||||
Ok((num_bytes, num_caps))
|
||||
}
|
||||
|
||||
pub fn endpoint_send(
|
||||
endpoint_cap: z_cap_t,
|
||||
bytes: &[u8],
|
||||
caps: &[z_cap_t],
|
||||
) -> Result<z_cap_t, ZError> {
|
||||
let mut reply_port_cap: u64 = 0;
|
||||
let send_req = zion::ZEndpointSendReq {
|
||||
caps: caps.as_ptr(),
|
||||
num_caps: caps.len() as u64,
|
||||
endpoint_cap,
|
||||
data: bytes.as_ptr() as *const c_void,
|
||||
num_bytes: bytes.len() as u64,
|
||||
reply_port_cap: &mut reply_port_cap as *mut z_cap_t,
|
||||
};
|
||||
|
||||
syscall(zion::kZionEndpointSend, &send_req)?;
|
||||
|
||||
Ok(reply_port_cap)
|
||||
}
|
||||
|
||||
pub fn reply_port_recv(
|
||||
reply_port_cap: z_cap_t,
|
||||
bytes: &mut [u8],
|
||||
caps: &mut [z_cap_t],
|
||||
) -> Result<(u64, u64), ZError> {
|
||||
let mut num_bytes = bytes.len() as u64;
|
||||
let mut num_caps = caps.len() as u64;
|
||||
let recv_req = zion::ZReplyPortRecvReq {
|
||||
reply_port_cap,
|
||||
caps: caps.as_mut_ptr(),
|
||||
num_caps: &mut num_caps as *mut u64,
|
||||
data: bytes.as_mut_ptr() as *mut c_void,
|
||||
num_bytes: &mut num_bytes as *mut u64,
|
||||
};
|
||||
|
||||
syscall(zion::kZionReplyPortRecv, &recv_req)?;
|
||||
|
||||
Ok((num_bytes, num_caps))
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ impl<const N: usize> ByteBuffer<N> {
|
|||
N as u64
|
||||
}
|
||||
|
||||
pub fn raw_ptr(&self) -> *const u8 {
|
||||
self.buffer.as_ptr()
|
||||
pub fn slice(&self, len: usize) -> &[u8] {
|
||||
&self.buffer[..len]
|
||||
}
|
||||
|
||||
pub fn mut_ptr(&mut self) -> *mut u8 {
|
||||
self.buffer.as_mut_ptr()
|
||||
pub fn mut_slice(&mut self) -> &mut [u8] {
|
||||
&mut self.buffer[..]
|
||||
}
|
||||
|
||||
pub fn write_at<T>(&mut self, offset: usize, obj: T) -> Result<(), ZError> {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::buffer::ByteBuffer;
|
||||
use crate::message::YunqMessage;
|
||||
use alloc::vec::Vec;
|
||||
use core::ffi::c_void;
|
||||
use mammoth::zion::z_cap_t;
|
||||
use mammoth::zion::ZError;
|
||||
|
||||
|
@ -21,31 +20,20 @@ pub fn call_endpoint<Req: YunqMessage, Resp: YunqMessage, const N: usize>(
|
|||
|
||||
byte_buffer.write_at(4, (16 + length) as u32)?;
|
||||
|
||||
let mut reply_port_cap: u64 = 0;
|
||||
let send_req = mammoth::zion::ZEndpointSendReq {
|
||||
caps: cap_buffer.as_ptr(),
|
||||
num_caps: cap_buffer.len() as u64,
|
||||
let reply_port_cap = mammoth::syscall::endpoint_send(
|
||||
endpoint_cap,
|
||||
data: byte_buffer.raw_ptr() as *const c_void,
|
||||
num_bytes: 16 + length as u64,
|
||||
reply_port_cap: &mut reply_port_cap as *mut z_cap_t,
|
||||
};
|
||||
byte_buffer.slice(16 + length),
|
||||
cap_buffer.as_slice(),
|
||||
)?;
|
||||
|
||||
mammoth::syscall::syscall(mammoth::zion::kZionEndpointSend, &send_req)?;
|
||||
// FIXME: Add a way to zero out the byte buffer.
|
||||
|
||||
let mut buffer_size = byte_buffer.size();
|
||||
let mut num_caps: u64 = 10;
|
||||
cap_buffer = vec![0; num_caps as usize];
|
||||
let recv_req = mammoth::zion::ZReplyPortRecvReq {
|
||||
cap_buffer = vec![0; 10];
|
||||
mammoth::syscall::reply_port_recv(
|
||||
reply_port_cap,
|
||||
caps: cap_buffer.as_mut_ptr(),
|
||||
num_caps: &mut num_caps as *mut u64,
|
||||
data: byte_buffer.mut_ptr() as *mut c_void,
|
||||
num_bytes: &mut buffer_size as *mut u64,
|
||||
};
|
||||
|
||||
mammoth::syscall::syscall(mammoth::zion::kZionReplyPortRecv, &recv_req)?;
|
||||
byte_buffer.mut_slice(),
|
||||
cap_buffer.as_mut_slice(),
|
||||
)?;
|
||||
|
||||
if byte_buffer.at::<u32>(0)? != SENTINEL {
|
||||
return Err(ZError::INVALID_RESPONSE);
|
||||
|
|
Loading…
Reference in New Issue