xous: add reply_and_receive_next_legacy call

This call is used to return values while simultaneously listening for
new messages.

The -legacy suffix is used to disambiguate scalar values, so we know
whether to send Scalar1, Scalar2, or Scalar5 messages.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2022-12-29 21:00:35 +08:00
parent 64c88f9942
commit d88254b1b1
2 changed files with 39 additions and 6 deletions

View file

@ -92,7 +92,7 @@ impl MemoryMessage {
}
#[repr(C)]
#[derive(Debug, PartialEq, Clone, Copy)]
#[derive(Debug, PartialEq, Clone, Copy, Default)]
/// A simple scalar message. This is similar to a `move` message.
pub struct ScalarMessage {
pub id: MessageId,
@ -239,6 +239,15 @@ impl Message {
}
}
pub fn scalar_message_mut(&mut self) -> Option<&mut ScalarMessage> {
match self {
Message::MutableBorrow(_)
| Message::Borrow(_)
| Message::Move(_)
| Message::Scalar(_) => None,
Message::BlockingScalar(scalar) => Some(scalar),
}
}
pub(crate) fn message_type(&self) -> usize {
match *self {
Message::MutableBorrow(_) => 1,

View file

@ -850,15 +850,15 @@ impl SysCall {
0,
0,
],
SysCall::ReplyAndReceiveNext(sender, result, arg1, arg2, arg3, arg4) => [
SysCallNumber::ReturnMemory as usize,
SysCall::ReplyAndReceiveNext(sender, arg0, arg1, arg2, arg3, arg4, return_type) => [
SysCallNumber::ReplyAndReceiveNext as usize,
sender.to_usize(),
*result,
*arg0,
*arg1,
*arg2,
*arg3,
*arg4,
0,
*return_type,
],
SysCall::CreateThread(init) => {
@ -1086,7 +1086,7 @@ impl SysCall {
MemorySize::new(a5),
),
SysCallNumber::ReplyAndReceiveNext => {
SysCall::ReplyAndReceiveNext(MessageSender::from_usize(a1), a2, a3, a4, a5, a6)
SysCall::ReplyAndReceiveNext(MessageSender::from_usize(a1), a2, a3, a4, a5, a6, a7)
}
SysCallNumber::CreateThread => {
SysCall::CreateThread(crate::arch::args_to_thread(a1, a2, a3, a4, a5, a6, a7)?)
@ -1936,6 +1936,30 @@ pub fn reply_and_receive_next(
server: SID,
msg: &mut Option<MessageEnvelope>,
) -> core::result::Result<(), crate::Error> {
reply_and_receive_next_legacy(server, msg, &mut 0)
}
/// Reply to the message, if one exists, and receive the next one.
/// If no message exists, delegate the call to `receive_syscall()`.
/// Allow specifying the scalar return type.
///
/// This is named `_legacy` because it is meant to work with calls that
/// expect both `Scalar1` and `Scalar2` values, in addition to `Scalar5`.
///
/// ## Arguments
///
/// * **server**: The SID of the server to receive messages from
/// * **msg**: An Option<MessageEnvelope> specifying the message to return.
/// * **return_type**: If 1 or 2, responds to a BlockingScalarMessage
/// with a Scalar1 or a Scalar2. Otherwise, will respond
/// as normal.
pub fn reply_and_receive_next_legacy(
server: SID,
msg: &mut Option<MessageEnvelope>,
return_type: &mut usize,
) -> core::result::Result<(), crate::Error> {
let rt = *return_type;
*return_type = 0;
if let Some(envelope) = msg.take() {
// If the message inside is nonblocking, then there's nothing to return.
// Delegate reception to the `receive_message()` call