blob: 568d6ad979898606f077598533e75aa1015d4b89 [file] [log] [blame]
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![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 _ = MailboxClient::output_select_async(47, 56).await;
let _ = MailboxClient::output_select_async(48, 57).await;
let _ = MailboxClient::input_select_async(64, 51).await;
let _ = MailboxClient::output_select_async(50, 58).await;
let _ = MailboxClient::output_select_async(51, 59).await;
let _ = MailboxClient::output_select_async(52, 60).await;
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
}