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