blob: 9ca6a24f4c6d875b617403ee1c46a2d74da400a9 [file] [log] [blame]
#![no_std]
use core::cell::Cell;
mod dprintf;
mod mailbox_client;
use mailbox_client::MailboxClient;
use mailbox_client::WaitResult;
use libtock::result::TockResult;
use libtock::syscalls;
use matcha_config::*;
libtock_core::stack_size! {0x1000}
// Global static message buffer. The mailbox driver will copy incoming messages
// here when they arrive.
static mut MESSAGE_BUF: [u8; 4096] = [0; 4096];
//------------------------------------------------------------------------------
#[libtock::main]
async fn main() -> TockResult<()> {
dprintf!("SEC: Booting seL4 from TockOS app!\r\n");
let _result = syscalls::command(CAPSULE_ELFLOADER, CMD_ELFLOADER_BOOT_SEL4, 0, 0);
dprintf!("SEC: Booting seL4 from TockOS app done!\r\n");
MailboxClient::init();
let wait_result = Cell::new(WaitResult::default());
MailboxClient::wait_message_setup(&wait_result, unsafe { &mut MESSAGE_BUF });
unsafe {
loop {
MailboxClient::wait_message_async(&wait_result).await;
// Status, message size (bytes), Option<attached page>
let (_, request_size, opt_page) = wait_result.take();
let (request_slice, reply_slice) = MESSAGE_BUF.split_at_mut(request_size);
let reply_size = MailboxClient::dispatch(request_slice, opt_page, reply_slice)
.await
.unwrap_or(0); // XXX send error code
MailboxClient::send_message_sync(reply_size, reply_slice);
}
}
// Unreachable
}