mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-08 04:56:43 +00:00
xous: add Message type
This type actually contains the message contents, and will be used to return data to the caller. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
d463f9563f
commit
64c88f9942
3 changed files with 52 additions and 9 deletions
|
|
@ -463,6 +463,9 @@ pub enum Result {
|
|||
/// 20: A scalar with five values
|
||||
Scalar5(usize, usize, usize, usize, usize),
|
||||
|
||||
// 21: A message is returned as part of `send_message()` when the result is blocking
|
||||
Message(Message),
|
||||
|
||||
UnknownResult(usize, usize, usize, usize, usize, usize, usize),
|
||||
}
|
||||
|
||||
|
|
@ -526,7 +529,13 @@ impl Result {
|
|||
0,
|
||||
],
|
||||
Result::NewProcess(p) => Self::add_opcode(19, p.into()),
|
||||
Result::Scalar5(a, b, c, d, e) => [15, *a, *b, *c, *d, *e, 0, 0],
|
||||
Result::Scalar5(a, b, c, d, e) => [20, *a, *b, *c, *d, *e, 0, 0],
|
||||
Result::Message(message) => {
|
||||
let encoded = message.to_usize();
|
||||
[
|
||||
21, encoded[0], encoded[1], encoded[2], encoded[3], encoded[4], encoded[5], 0,
|
||||
]
|
||||
}
|
||||
Result::UnknownResult(arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {
|
||||
[usize::MAX, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7]
|
||||
}
|
||||
|
|
@ -605,19 +614,36 @@ impl Result {
|
|||
18 => Result::MemoryReturned(MemorySize::new(src[1]), MemorySize::new(src[2])),
|
||||
19 => Result::NewProcess(src.into()),
|
||||
20 => Result::Scalar5(src[1], src[2], src[3], src[4], src[5]),
|
||||
21 => Result::Message(match src[1] {
|
||||
0 => match MemoryMessage::from_usize(src[2], src[3], src[4], src[5], src[6]) {
|
||||
None => return Result::Error(Error::InternalError),
|
||||
Some(s) => Message::MutableBorrow(s),
|
||||
},
|
||||
1 => match MemoryMessage::from_usize(src[2], src[3], src[4], src[5], src[6]) {
|
||||
None => return Result::Error(Error::InternalError),
|
||||
Some(s) => Message::Borrow(s),
|
||||
},
|
||||
2 => match MemoryMessage::from_usize(src[2], src[3], src[4], src[5], src[6]) {
|
||||
None => return Result::Error(Error::InternalError),
|
||||
Some(s) => Message::Move(s),
|
||||
},
|
||||
3 => Message::Scalar(ScalarMessage::from_usize(
|
||||
src[2], src[3], src[4], src[5], src[6],
|
||||
)),
|
||||
4 => Message::BlockingScalar(ScalarMessage::from_usize(
|
||||
src[2], src[3], src[4], src[5], src[6],
|
||||
)),
|
||||
_ => return Result::Error(Error::InternalError),
|
||||
}),
|
||||
_ => Result::UnknownResult(src[0], src[1], src[2], src[3], src[4], src[5], src[6]),
|
||||
}
|
||||
}
|
||||
|
||||
/// If the Result has memory attached to it, return the memory
|
||||
pub fn memory(&self) -> Option<MemoryRange> {
|
||||
pub fn memory(&self) -> Option<&MemoryRange> {
|
||||
match self {
|
||||
Result::Message(msg) => match &msg.body {
|
||||
Message::Move(memory_message)
|
||||
| Message::Borrow(memory_message)
|
||||
| Message::MutableBorrow(memory_message) => Some(memory_message.buf),
|
||||
_ => None,
|
||||
},
|
||||
Result::MessageEnvelope(msg) => msg.body.memory(),
|
||||
Result::Message(msg) => msg.memory(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,6 +264,19 @@ impl Message {
|
|||
Message::Scalar(s) | Message::BlockingScalar(s) => s.id = id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_usize(&self) -> [usize; 6] {
|
||||
let ret = match &*self {
|
||||
Message::MutableBorrow(m) => (0, m.to_usize()),
|
||||
Message::Borrow(m) => (1, m.to_usize()),
|
||||
Message::Move(m) => (2, m.to_usize()),
|
||||
Message::Scalar(m) => (3, m.to_usize()),
|
||||
Message::BlockingScalar(m) => (4, m.to_usize()),
|
||||
};
|
||||
[
|
||||
ret.0, ret.1[0], ret.1[1], ret.1[2], ret.1[3], ret.1[4],
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<(usize, usize, usize, usize, usize, usize)> for Message {
|
||||
|
|
|
|||
|
|
@ -324,11 +324,14 @@ pub enum SysCall {
|
|||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * **Ok**: The Scalar / Send message was successfully sent, or the Borrow has finished
|
||||
/// * **Ok**: The Scalar / Send message was successfully sent
|
||||
/// * **Scalar1**: The Server returned a `Scalar1` value
|
||||
/// * **Scalar2**: The Server returned a `Scalar2` value
|
||||
/// * **Scalar5**: The Server returned a `Scalar5` value
|
||||
/// * **BlockedProcess**: In Hosted mode, the target process is now blocked
|
||||
/// * **Message**: For Scalar messages, this includes the args as returned
|
||||
/// by the server. For MemoryMessages, this will include
|
||||
/// the Opcode, Offset, and Valid fields.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
|
@ -511,6 +514,7 @@ pub enum SysCall {
|
|||
usize, /* arg2 (BlockingScalar) or the memory length (MemoryMesage) */
|
||||
usize, /* arg3 (BlockingScalar) or the memory offset (MemoryMesage) */
|
||||
usize, /* arg4 (BlockingScalar) or the memory valid (MemoryMesage) */
|
||||
usize, /* for BlockingScalars, indicates how many args are valid */
|
||||
),
|
||||
|
||||
/// This syscall does not exist. It captures all possible
|
||||
|
|
|
|||
Loading…
Reference in a new issue