mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
syscalls: begin adding message-passing syscalls
These are still not connected, however their existence is starting to solidify the API. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
17efc950c8
commit
d10bc2e894
5 changed files with 48 additions and 7 deletions
|
|
@ -45,6 +45,13 @@ sram: Memory.MappedMemory @ {
|
|||
}
|
||||
size: 16777216
|
||||
|
||||
fbmem: Memory.MappedMemory @ sysbus 0xB0000000
|
||||
size: 0x6000
|
||||
|
||||
memlcd: Video.BetrustedLCD @ sysbus 0xF0005000
|
||||
|
||||
kbd: Input.BetrustedKbd @ sysbus 0xF0006000
|
||||
|
||||
cpu_timer: Timers.LiteX_CPUTimer @ sysbus 0xf0000800
|
||||
frequency: 66000000
|
||||
// IRQ #100 is Machine Timer Interrupt
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ mach create
|
|||
# Add peripherals that are defined in C#. You must restart Renode
|
||||
# if you modify these files.
|
||||
i @peripherals/LiteX_Timer_32.cs
|
||||
i @peripherals/memlcd.cs
|
||||
i @peripherals/keyboard.cs
|
||||
|
||||
# Load the Betrusted Renode Platform file
|
||||
machine LoadPlatformDescription @betrusted.repl
|
||||
|
|
@ -18,6 +20,7 @@ machine StartGdbServer 3333 true
|
|||
showAnalyzer uartkernel
|
||||
showAnalyzer uart
|
||||
showAnalyzer uartlog
|
||||
#showAnalyzer memlcd
|
||||
|
||||
# The macro `reset` gets called implicitly when running `machine Reset`
|
||||
macro reset
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub type SID = (usize, usize, usize, usize);
|
|||
/// Equivalent to a RISC-V Hart ID
|
||||
pub type CpuID = usize;
|
||||
|
||||
#[repr(C)]
|
||||
#[repr(usize)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
NoError = 0,
|
||||
|
|
@ -60,14 +60,14 @@ pub struct ScalarMessage {
|
|||
arg4: usize,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(usize)]
|
||||
pub enum Message {
|
||||
Memory(MemoryMessage),
|
||||
Scalar(ScalarMessage),
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct MessageReceived {
|
||||
#[repr(C)]
|
||||
pub struct MessageEnvelope {
|
||||
sender: MessageSender,
|
||||
message: Message,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ macro_rules! make_name {
|
|||
($fcc:expr) => {{
|
||||
let mut c: [u8; 4] = Default::default();
|
||||
c.copy_from_slice($fcc.as_bytes());
|
||||
usize::from_le_bytes(c)
|
||||
u32::from_le_bytes(c) as usize
|
||||
}};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{CpuID, Error, MemoryAddress, PID, SID};
|
||||
use crate::{CpuID, Error, MemoryAddress, PID, SID, MessageEnvelope};
|
||||
use num_derive::FromPrimitive;
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
|
|
@ -140,6 +140,9 @@ pub enum SysCall {
|
|||
/// This process will now wait for an event such as an IRQ or Message.
|
||||
WaitEvent,
|
||||
|
||||
/// This context will now wait for a message with the given server ID
|
||||
WaitMessage(SID),
|
||||
|
||||
/// Stop running the given process.
|
||||
Suspend(PID, CpuID),
|
||||
|
||||
|
|
@ -255,6 +258,7 @@ enum SysCallNumber {
|
|||
UpdateMemoryFlags = 12,
|
||||
SetMemRegion = 13,
|
||||
CreateServer = 14,
|
||||
WaitMessage = 15,
|
||||
Invalid,
|
||||
}
|
||||
|
||||
|
|
@ -281,6 +285,7 @@ impl SysCall {
|
|||
],
|
||||
SysCall::Yield => [SysCallNumber::Yield as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||
SysCall::WaitEvent => [SysCallNumber::WaitEvent as usize, 0, 0, 0, 0, 0, 0, 0],
|
||||
SysCall::WaitMessage(sid) => [SysCallNumber::WaitMessage as usize, sid.0, sid.1, sid.2, sid.3, 0, 0, 0],
|
||||
SysCall::Suspend(a1, a2) => [
|
||||
SysCallNumber::Suspend as usize,
|
||||
a1 as usize,
|
||||
|
|
@ -380,6 +385,7 @@ impl SysCall {
|
|||
),
|
||||
Some(SysCallNumber::Yield) => SysCall::Yield,
|
||||
Some(SysCallNumber::WaitEvent) => SysCall::WaitEvent,
|
||||
Some(SysCallNumber::WaitMessage) => SysCall::WaitMessage((a1, a2, a3, a4)),
|
||||
Some(SysCallNumber::Suspend) => SysCall::Suspend(a1 as PID, a2),
|
||||
Some(SysCallNumber::ClaimInterrupt) => {
|
||||
SysCall::ClaimInterrupt(a1, a2 as *mut usize, a3 as *mut usize)
|
||||
|
|
@ -495,7 +501,16 @@ pub fn claim_interrupt(
|
|||
Err(Error::InternalError)
|
||||
}
|
||||
|
||||
/// Create a new server. Returns the new server address.
|
||||
/// Create a new server with the given name. This enables other processes to
|
||||
/// connect to this server to send messages. The name is a UTF-8 token that
|
||||
/// will be mixed with other random data that is unique to each process.
|
||||
/// That way, if a process crashes and is restarted, it can keep the same
|
||||
/// name. However, other processes cannot spoof this process.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * **ServerExists**: A server has already registered with that name
|
||||
/// * **InvalidString**: The name was not a valid UTF-8 string
|
||||
pub fn create_server(name: usize) -> core::result::Result<SID, Error> {
|
||||
let result = rsyscall(SysCall::CreateServer(name))?;
|
||||
if let Result::ServerID(sid) = result {
|
||||
|
|
@ -504,6 +519,22 @@ pub fn create_server(name: usize) -> core::result::Result<SID, Error> {
|
|||
Err(Error::InternalError)
|
||||
}
|
||||
|
||||
/// Suspend the current process until a message is received. This thread will
|
||||
/// block until a message is received.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
pub fn receive_message(sid: SID) -> core::result::Result<MessageEnvelope, Error> {
|
||||
rsyscall(SysCall::WaitMessage(sid)).expect("Couldn't call watimessage");
|
||||
Err(Error::UnhandledSyscall)
|
||||
}
|
||||
|
||||
/// Return execution to the kernel.
|
||||
/// This function may return at any time, including immediately
|
||||
pub fn yield_slice() {
|
||||
rsyscall(SysCall::Yield).expect("yield returned an error");
|
||||
}
|
||||
|
||||
pub fn rsyscall(call: SysCall) -> SyscallResult {
|
||||
use core::mem::MaybeUninit;
|
||||
let mut ret = unsafe { MaybeUninit::uninit().assume_init() };
|
||||
|
|
|
|||
Loading…
Reference in a new issue