| #![no_std] |
| |
| mod dprintf; |
| mod mailbox_client; |
| |
| use crate::mailbox_client::MailboxClient; |
| 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(); |
| |
| unsafe { |
| loop { |
| dprintf!("SEC: Waiting for request\r\n"); |
| let message_size = MailboxClient::wait_message_async(&mut MESSAGE_BUF).await; |
| dprintf!("SEC: Request arrived, {} bytes\r\n", message_size); |
| |
| let dst: *mut u32 = core::mem::transmute(MESSAGE_BUF.as_ptr()); |
| |
| // We don't actually have any message handling set up, so we just |
| // tweak the first and last dword of the message so the sender can |
| // tell we were able to modify it. |
| let last = (message_size / 4) - 1; |
| dprintf!("request[0] = {:X}\r\n", dst.offset(0).read()); |
| dprintf!( |
| "request[{}] = {:X}\r\n", |
| last, |
| dst.offset(last as isize).read() |
| ); |
| |
| dst.offset(0).write(0x12345678); |
| dst.offset(last as isize).write(0x87654321); |
| |
| dprintf!("SEC: Sending response\r\n"); |
| MailboxClient::send_message_sync(message_size, &MESSAGE_BUF); |
| |
| dprintf!("SEC: Response sent\r\n"); |
| } |
| } |
| // Unreachable |
| } |