mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
wip
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
651844ba20
commit
fb839f3217
8 changed files with 220 additions and 129 deletions
|
|
@ -7,24 +7,28 @@ cpu: CPU.VexRiscv @ sysbus
|
||||||
// Platform Peripherals
|
// Platform Peripherals
|
||||||
// Unrecognized peripheral: reboot
|
// Unrecognized peripheral: reboot
|
||||||
|
|
||||||
|
timer0: Timers.LiteX_Timer_32 @ sysbus 0xf0001000
|
||||||
|
frequency: 100000000
|
||||||
|
-> cpu @ 1000
|
||||||
|
|
||||||
// Unrecognized peripheral: crg
|
// Unrecognized peripheral: crg
|
||||||
|
|
||||||
// Unrecognized peripheral: gpio
|
// Unrecognized peripheral: gpio
|
||||||
|
|
||||||
uart: UART.LiteX_UART @ sysbus 0xf0004000
|
uart: UART.LiteX_UART @ sysbus 0xf0005000
|
||||||
-> cpu @ 1002
|
-> cpu @ 1002
|
||||||
|
|
||||||
console: UART.LiteX_UART @ sysbus 0xf0006000
|
console: UART.LiteX_UART @ sysbus 0xf0007000
|
||||||
-> cpu @ 1003
|
-> cpu @ 1003
|
||||||
|
|
||||||
app_uart: UART.LiteX_UART @ sysbus 0xf0008000
|
app_uart: UART.LiteX_UART @ sysbus 0xf0009000
|
||||||
-> cpu @ 1004
|
-> cpu @ 1004
|
||||||
|
|
||||||
// Unrecognized peripheral: info
|
// Unrecognized peripheral: info
|
||||||
|
|
||||||
// Unrecognized peripheral: sram_ext
|
// Unrecognized peripheral: sram_ext
|
||||||
|
|
||||||
memlcd: Video.BetrustedLCD @ sysbus 0xf000b000
|
memlcd: Video.BetrustedLCD @ sysbus 0xf000c000
|
||||||
|
|
||||||
// Unrecognized peripheral: com
|
// Unrecognized peripheral: com
|
||||||
|
|
||||||
|
|
@ -36,7 +40,7 @@ memlcd: Video.BetrustedLCD @ sysbus 0xf000b000
|
||||||
|
|
||||||
// Unrecognized peripheral: messible2
|
// Unrecognized peripheral: messible2
|
||||||
|
|
||||||
ticktimer: Timers.TickTimer @ sysbus 0xf0011000
|
ticktimer: Timers.TickTimer @ sysbus 0xf0012000
|
||||||
-> cpu @ 1008
|
-> cpu @ 1008
|
||||||
|
|
||||||
// Unrecognized peripheral: susres
|
// Unrecognized peripheral: susres
|
||||||
|
|
@ -45,7 +49,7 @@ ticktimer: Timers.TickTimer @ sysbus 0xf0011000
|
||||||
|
|
||||||
// Unrecognized peripheral: spinor
|
// Unrecognized peripheral: spinor
|
||||||
|
|
||||||
keyboard: Input.BetrustedKbd @ sysbus 0xf0015000
|
keyboard: Input.BetrustedKbd @ sysbus 0xf0016000
|
||||||
-> cpu @ 1011
|
-> cpu @ 1011
|
||||||
|
|
||||||
// Unrecognized peripheral: keyinject
|
// Unrecognized peripheral: keyinject
|
||||||
|
|
@ -56,10 +60,10 @@ keyboard: Input.BetrustedKbd @ sysbus 0xf0015000
|
||||||
|
|
||||||
// Unrecognized peripheral: audio
|
// Unrecognized peripheral: audio
|
||||||
|
|
||||||
trng_kernel: Miscellaneous.BetrustedRNGKernel @ sysbus 0xf001a000
|
trng_kernel: Miscellaneous.BetrustedRNGKernel @ sysbus 0xf001b000
|
||||||
-> cpu @ 1013
|
-> cpu @ 1013
|
||||||
|
|
||||||
trng_server: Miscellaneous.BetrustedRNGServer @ sysbus 0xf001b000
|
trng_server: Miscellaneous.BetrustedRNGServer @ sysbus 0xf001c000
|
||||||
-> cpu @ 1014
|
-> cpu @ 1014
|
||||||
|
|
||||||
// Unrecognized peripheral: trng
|
// Unrecognized peripheral: trng
|
||||||
|
|
@ -74,11 +78,9 @@ trng_server: Miscellaneous.BetrustedRNGServer @ sysbus 0xf001b000
|
||||||
|
|
||||||
// Unrecognized peripheral: d11ctime
|
// Unrecognized peripheral: d11ctime
|
||||||
|
|
||||||
// Unrecognized peripheral: identifier_mem
|
// Unrecognized peripheral: wfi
|
||||||
|
|
||||||
timer0: Timers.LiteX_Timer_32 @ sysbus 0xf0023000
|
// Unrecognized peripheral: identifier_mem
|
||||||
frequency: 100000000
|
|
||||||
-> cpu @ 1000
|
|
||||||
|
|
||||||
|
|
||||||
// Physical base addresses of memory regions
|
// Physical base addresses of memory regions
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,6 @@ showAnalyzer memlcd
|
||||||
|
|
||||||
sysbus Tag <0xB0000000, 0xB0006000> "Framebuffer"
|
sysbus Tag <0xB0000000, 0xB0006000> "Framebuffer"
|
||||||
|
|
||||||
# Silence COM messages
|
|
||||||
sysbus SilenceRange <0xF000C000, 0xF000CFFF>
|
|
||||||
|
|
||||||
# Silence WDT
|
# Silence WDT
|
||||||
sysbus SilenceRange <0xF001F000, 0xF001FFFF>
|
sysbus SilenceRange <0xF001F000, 0xF001FFFF>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,4 @@ rustflags = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
target = "riscv32imac-unknown-none-elf"
|
#target = "riscv32imac-unknown-none-elf"
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ print-panics = []
|
||||||
report-memory = ["stats_alloc"]
|
report-memory = ["stats_alloc"]
|
||||||
wrap-print = []
|
wrap-print = []
|
||||||
# default = ["print-panics", "debug-print", "wrap-print"]
|
# default = ["print-panics", "debug-print", "wrap-print"]
|
||||||
default = ["print-panics", "gdbserver"]
|
default = ["print-panics", "gdbserver", "debug-print", "wrap-print"]
|
||||||
|
|
||||||
[target.'cfg(any(windows, unix))'.dependencies]
|
[target.'cfg(any(windows, unix))'.dependencies]
|
||||||
crossbeam-channel = "0.5"
|
crossbeam-channel = "0.5"
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,9 @@ pub unsafe fn set_isr_return_pair(pid: PID, tid: TID) {
|
||||||
PREVIOUS_PAIR = Some((pid, tid));
|
PREVIOUS_PAIR = Some((pid, tid));
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[allow(dead_code)]
|
pub unsafe fn take_isr_return_pair() -> Option<(PID, TID)> {
|
||||||
// pub unsafe fn take_isr_return_pair() -> Option<(PID, TID)> {
|
PREVIOUS_PAIR.take()
|
||||||
// PREVIOUS_PAIR.take()
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
/// Trap entry point rust (_start_trap_rust)
|
/// Trap entry point rust (_start_trap_rust)
|
||||||
///
|
///
|
||||||
|
|
@ -104,7 +103,15 @@ pub extern "C" fn trap_handler(
|
||||||
// println!("Syscall Result: {:?}", response);
|
// println!("Syscall Result: {:?}", response);
|
||||||
ArchProcess::with_current_mut(|p| {
|
ArchProcess::with_current_mut(|p| {
|
||||||
let thread = p.current_thread();
|
let thread = p.current_thread();
|
||||||
unsafe { _xous_syscall_return_result(&response, thread) };
|
// If we're resuming a process that was previously sleeping, restore the
|
||||||
|
// thread context. Otherwise, keep the thread context the same and pass
|
||||||
|
// the return values in 8 argument registers.
|
||||||
|
if response == xous_kernel::Result::ResumeProcess {
|
||||||
|
crate::arch::syscall::resume(current_pid().get() == 1, thread);
|
||||||
|
} else {
|
||||||
|
// println!("Returning to address {:08x}", thread.sepc);
|
||||||
|
unsafe { _xous_syscall_return_result(&response, thread) };
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ pub fn irq(_irq_number: usize, _arg: *mut usize) {
|
||||||
|
|
||||||
#[cfg(feature = "gdbserver")]
|
#[cfg(feature = "gdbserver")]
|
||||||
unsafe {
|
unsafe {
|
||||||
use crate::debug::gdb_server::{GDB_STATE, XousDebugState};
|
use crate::debug::gdb_server::{XousDebugState, GDB_STATE};
|
||||||
use gdbstub::state_machine::GdbStubStateMachine;
|
use gdbstub::state_machine::GdbStubStateMachine;
|
||||||
use gdbstub::{DisconnectReason, GdbStubError};
|
use gdbstub::{DisconnectReason, GdbStubError};
|
||||||
if let Some(XousDebugState {
|
if let Some(XousDebugState {
|
||||||
|
|
@ -438,6 +438,22 @@ pub fn irq(_irq_number: usize, _arg: *mut usize) {
|
||||||
Err(e) => println!("Unable to start GDB server: {}", e),
|
Err(e) => println!("Unable to start GDB server: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b's' => {
|
||||||
|
println!(">>>>>>>>>>>>>>>>>>>>>>>>>>>> Suspenidng PID 3");
|
||||||
|
crate::services::SystemServices::with_mut(|system_services| {
|
||||||
|
system_services
|
||||||
|
.suspend_process(xous_kernel::PID::new(3).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
b'c' => {
|
||||||
|
println!(">>>>>>>>>>>>>>>>>>>>>>>>>>>> Continuing (Resuming) PID 3");
|
||||||
|
crate::services::SystemServices::with_mut(|system_services| {
|
||||||
|
system_services
|
||||||
|
.continue_process(xous_kernel::PID::new(3).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
b'h' => {
|
b'h' => {
|
||||||
println!("Xous Kernel Debug");
|
println!("Xous Kernel Debug");
|
||||||
println!("key | command");
|
println!("key | command");
|
||||||
|
|
@ -447,6 +463,8 @@ pub fn irq(_irq_number: usize, _arg: *mut usize) {
|
||||||
println!(" m | print MMU page tables of all processes");
|
println!(" m | print MMU page tables of all processes");
|
||||||
println!(" p | print all processes and threads");
|
println!(" p | print all processes and threads");
|
||||||
println!(" r | report RAM usage of all processes");
|
println!(" r | report RAM usage of all processes");
|
||||||
|
println!(" s | Suspend PID 3");
|
||||||
|
println!(" c | Continue PID 3");
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -559,6 +559,23 @@ impl SystemServices {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn runnable(&self, pid: PID, tid: Option<TID>) -> Result<bool, xous_kernel::Error> {
|
||||||
|
let process = self.get_process(pid)?;
|
||||||
|
if let Some(tid) = tid {
|
||||||
|
Ok(match process.state {
|
||||||
|
ProcessState::Running(x) if x & (1 << tid) == 0 => true,
|
||||||
|
ProcessState::Ready(x) if x & (1 << tid) == 0 => true,
|
||||||
|
ProcessState::Sleeping => true,
|
||||||
|
_ => false,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Ok(match process.state {
|
||||||
|
ProcessState::Running(_) | ProcessState::Ready(_) | ProcessState::Sleeping => true,
|
||||||
|
_ => false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Mark the specified context as ready to run. If the thread is Sleeping, mark
|
/// Mark the specified context as ready to run. If the thread is Sleeping, mark
|
||||||
/// it as Ready.
|
/// it as Ready.
|
||||||
pub fn ready_thread(&mut self, pid: PID, tid: TID) -> Result<(), xous_kernel::Error> {
|
pub fn ready_thread(&mut self, pid: PID, tid: TID) -> Result<(), xous_kernel::Error> {
|
||||||
|
|
@ -572,6 +589,7 @@ impl SystemServices {
|
||||||
}
|
}
|
||||||
ProcessState::Ready(x) if x & (1 << tid) == 0 => ProcessState::Ready(x | (1 << tid)),
|
ProcessState::Ready(x) if x & (1 << tid) == 0 => ProcessState::Ready(x | (1 << tid)),
|
||||||
ProcessState::Sleeping => ProcessState::Ready(1 << tid),
|
ProcessState::Sleeping => ProcessState::Ready(1 << tid),
|
||||||
|
ProcessState::Debug(x) if x & (1 << tid) == 0 => ProcessState::Debug(x | (1 << tid)),
|
||||||
other => panic!(
|
other => panic!(
|
||||||
"PID {} was not in a state to wake thread {}: {:?}",
|
"PID {} was not in a state to wake thread {}: {:?}",
|
||||||
pid, tid, other
|
pid, tid, other
|
||||||
|
|
@ -1954,6 +1972,54 @@ impl SystemServices {
|
||||||
Ok(parent_pid)
|
Ok(parent_pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn suspend_process(&mut self, pid: PID) -> Result<(), xous_kernel::Error> {
|
||||||
|
let (process_state, parent_pid) = {
|
||||||
|
let process = self.get_process_mut(pid)?;
|
||||||
|
(process.state, process.ppid)
|
||||||
|
};
|
||||||
|
let new_process_state = match process_state {
|
||||||
|
ProcessState::Allocated => ProcessState::Allocated,
|
||||||
|
ProcessState::Free => ProcessState::Free,
|
||||||
|
ProcessState::Setup(thread_init) => ProcessState::Setup(thread_init),
|
||||||
|
ProcessState::Ready(tids) => ProcessState::Debug(tids),
|
||||||
|
ProcessState::Sleeping => ProcessState::Debug(0),
|
||||||
|
ProcessState::Debug(tids) => ProcessState::Debug(tids),
|
||||||
|
ProcessState::Running(tids) => {
|
||||||
|
// Switch to the parent process when we return.
|
||||||
|
let current_tid = arch::process::current_tid();
|
||||||
|
|
||||||
|
let parent_process = self.get_process_mut(parent_pid).unwrap();
|
||||||
|
parent_process.activate().unwrap();
|
||||||
|
let mut p = crate::arch::process::Process::current();
|
||||||
|
// FIXME: What happens if this fails? We're currently in the new process
|
||||||
|
// but without a context to switch to.
|
||||||
|
p.set_thread(parent_process.previous_thread).unwrap();
|
||||||
|
parent_process.current_thread = parent_process.previous_thread;
|
||||||
|
|
||||||
|
// Ensure we don't switch back to the same process.
|
||||||
|
unsafe { crate::arch::irq::take_isr_return_pair() };
|
||||||
|
ProcessState::Ready(tids | 1 << current_tid)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
self.get_process_mut(pid).unwrap().state = new_process_state;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn continue_process(&mut self, pid: PID) -> Result<(), xous_kernel::Error> {
|
||||||
|
let process = self.get_process_mut(pid)?;
|
||||||
|
process.state = match process.state {
|
||||||
|
ProcessState::Allocated => ProcessState::Allocated,
|
||||||
|
ProcessState::Free => ProcessState::Free,
|
||||||
|
ProcessState::Setup(thread_init) => ProcessState::Setup(thread_init),
|
||||||
|
ProcessState::Ready(tids) => ProcessState::Ready(tids),
|
||||||
|
ProcessState::Sleeping => ProcessState::Sleeping,
|
||||||
|
ProcessState::Debug(0) => ProcessState::Sleeping,
|
||||||
|
ProcessState::Debug(tids) => ProcessState::Ready(tids),
|
||||||
|
ProcessState::Running(tids) => ProcessState::Running(tids),
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls the provided function with the current inner process state.
|
/// Calls the provided function with the current inner process state.
|
||||||
pub fn shutdown(&mut self) -> Result<(), xous_kernel::Error> {
|
pub fn shutdown(&mut self) -> Result<(), xous_kernel::Error> {
|
||||||
// Destroy all servers. This will cause all queued messages to be lost.
|
// Destroy all servers. This will cause all queued messages to be lost.
|
||||||
|
|
|
||||||
|
|
@ -145,116 +145,117 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
|
||||||
|
|
||||||
// If the server has an available thread to receive the message,
|
// If the server has an available thread to receive the message,
|
||||||
// transfer it right away.
|
// transfer it right away.
|
||||||
if let Some(server_tid) = ss
|
if ss.runnable(server_pid, None).unwrap() {
|
||||||
.server_from_sidx_mut(sidx)
|
let server = ss
|
||||||
.expect("server couldn't be located")
|
.server_from_sidx_mut(sidx)
|
||||||
.take_available_thread()
|
.expect("server couldn't be located");
|
||||||
{
|
if let Some(server_tid) = server.take_available_thread() {
|
||||||
// klog!(
|
// klog!(
|
||||||
// "there are threads available in PID {} to handle this message -- marking as Ready",
|
// "there are threads available in PID {} to handle this message -- marking as Ready",
|
||||||
// server_pid
|
// server_pid
|
||||||
// );
|
// );
|
||||||
let sender_idx = if message.is_blocking() {
|
let sender_idx = if message.is_blocking() {
|
||||||
ss.remember_server_message(sidx, pid, thread, &message, client_address)
|
ss.remember_server_message(sidx, pid, thread, &message, client_address)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
klog!("error remembering server message: {:?}", e);
|
klog!("error remembering server message: {:?}", e);
|
||||||
ss.server_from_sidx_mut(sidx)
|
ss.server_from_sidx_mut(sidx)
|
||||||
.expect("server couldn't be located")
|
.expect("server couldn't be located")
|
||||||
.return_available_thread(server_tid);
|
.return_available_thread(server_tid);
|
||||||
e
|
e
|
||||||
})?
|
})?
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
let sender = SenderID::new(sidx, sender_idx, Some(pid));
|
let sender = SenderID::new(sidx, sender_idx, Some(pid));
|
||||||
klog!(
|
|
||||||
"server connection data: sidx: {}, idx: {}, server pid: {}",
|
|
||||||
sidx,
|
|
||||||
sender_idx,
|
|
||||||
server_pid
|
|
||||||
);
|
|
||||||
let envelope = MessageEnvelope {
|
|
||||||
sender: sender.into(),
|
|
||||||
body: message,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mark the server's context as "Ready". If this fails, return the context
|
|
||||||
// to the blocking list.
|
|
||||||
ss.ready_thread(server_pid, server_tid).map_err(|e| {
|
|
||||||
ss.server_from_sidx_mut(sidx)
|
|
||||||
.expect("server couldn't be located")
|
|
||||||
.return_available_thread(server_tid);
|
|
||||||
e
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if blocking && cfg!(baremetal) {
|
|
||||||
klog!("Activating Server context and switching away from Client");
|
|
||||||
ss.activate_process_thread(thread, server_pid, server_tid, false)
|
|
||||||
.map(|_| Ok(xous_kernel::Result::Message(envelope)))
|
|
||||||
.unwrap_or(Err(xous_kernel::Error::ProcessNotFound))
|
|
||||||
} else if blocking && !cfg!(baremetal) {
|
|
||||||
klog!("Blocking client, since it sent a blocking message");
|
|
||||||
ss.switch_from_thread(pid, thread)?;
|
|
||||||
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
|
||||||
ss.set_thread_result(
|
|
||||||
server_pid,
|
|
||||||
server_tid,
|
|
||||||
xous_kernel::Result::Message(envelope),
|
|
||||||
)
|
|
||||||
.map(|_| xous_kernel::Result::BlockedProcess)
|
|
||||||
} else if cfg!(baremetal) {
|
|
||||||
klog!("Setting the return value of the Server ({}:{}) to {:?} and returning to Client",
|
|
||||||
server_pid, server_tid, envelope);
|
|
||||||
ss.set_thread_result(
|
|
||||||
server_pid,
|
|
||||||
server_tid,
|
|
||||||
xous_kernel::Result::Message(envelope),
|
|
||||||
)
|
|
||||||
.map(|_| xous_kernel::Result::Ok)
|
|
||||||
} else {
|
|
||||||
klog!(
|
klog!(
|
||||||
"setting the return value of the Server to {:?} and returning to Client",
|
"server connection data: sidx: {}, idx: {}, server pid: {}",
|
||||||
envelope
|
sidx,
|
||||||
|
sender_idx,
|
||||||
|
server_pid
|
||||||
);
|
);
|
||||||
// "Switch to" the server PID when not running on bare metal. This ensures
|
let envelope = MessageEnvelope {
|
||||||
// that it's "Running".
|
sender: sender.into(),
|
||||||
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
body: message,
|
||||||
ss.set_thread_result(
|
};
|
||||||
server_pid,
|
|
||||||
server_tid,
|
// Mark the server's context as "Ready". If this fails, return the context
|
||||||
xous_kernel::Result::Message(envelope),
|
// to the blocking list.
|
||||||
)
|
ss.ready_thread(server_pid, server_tid).map_err(|e| {
|
||||||
.map(|_| xous_kernel::Result::Ok)
|
ss.server_from_sidx_mut(sidx)
|
||||||
|
.expect("server couldn't be located")
|
||||||
|
.return_available_thread(server_tid);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// --- NOTE: Returning this value //
|
||||||
|
return if blocking && cfg!(baremetal) {
|
||||||
|
klog!("Activating Server context and switching away from Client");
|
||||||
|
ss.activate_process_thread(thread, server_pid, server_tid, false)
|
||||||
|
.map(|_| Ok(xous_kernel::Result::Message(envelope)))
|
||||||
|
.unwrap_or(Err(xous_kernel::Error::ProcessNotFound))
|
||||||
|
} else if blocking && !cfg!(baremetal) {
|
||||||
|
klog!("Blocking client, since it sent a blocking message");
|
||||||
|
ss.switch_from_thread(pid, thread)?;
|
||||||
|
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
||||||
|
ss.set_thread_result(
|
||||||
|
server_pid,
|
||||||
|
server_tid,
|
||||||
|
xous_kernel::Result::Message(envelope),
|
||||||
|
)
|
||||||
|
.map(|_| xous_kernel::Result::BlockedProcess)
|
||||||
|
} else if cfg!(baremetal) {
|
||||||
|
klog!("Setting the return value of the Server ({}:{}) to {:?} and returning to Client",
|
||||||
|
server_pid, server_tid, envelope);
|
||||||
|
ss.set_thread_result(
|
||||||
|
server_pid,
|
||||||
|
server_tid,
|
||||||
|
xous_kernel::Result::Message(envelope),
|
||||||
|
)
|
||||||
|
.map(|_| xous_kernel::Result::Ok)
|
||||||
|
} else {
|
||||||
|
klog!(
|
||||||
|
"setting the return value of the Server to {:?} and returning to Client",
|
||||||
|
envelope
|
||||||
|
);
|
||||||
|
// "Switch to" the server PID when not running on bare metal. This ensures
|
||||||
|
// that it's "Running".
|
||||||
|
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
||||||
|
ss.set_thread_result(
|
||||||
|
server_pid,
|
||||||
|
server_tid,
|
||||||
|
xous_kernel::Result::Message(envelope),
|
||||||
|
)
|
||||||
|
.map(|_| xous_kernel::Result::Ok)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
klog!(
|
||||||
|
"no threads available in PID {} to handle this message, so queueing",
|
||||||
|
server_pid
|
||||||
|
);
|
||||||
|
// Add this message to the queue. If the queue is full, this
|
||||||
|
// returns an error.
|
||||||
|
let _queue_idx = ss.queue_server_message(sidx, pid, thread, message, client_address)?;
|
||||||
|
klog!("queued into index {:x}", _queue_idx);
|
||||||
|
|
||||||
|
// Park this context if it's blocking. This is roughly
|
||||||
|
// equivalent to a "Yield".
|
||||||
|
if blocking {
|
||||||
|
if cfg!(baremetal) {
|
||||||
|
// println!("Returning to parent");
|
||||||
|
let process = ss.get_process(pid).expect("Can't get current process");
|
||||||
|
let ppid = process.ppid;
|
||||||
|
unsafe { SWITCHTO_CALLER = None };
|
||||||
|
ss.activate_process_thread(thread, ppid, 0, false)
|
||||||
|
.map(|_| Ok(xous_kernel::Result::ResumeProcess))
|
||||||
|
.unwrap_or(Err(xous_kernel::Error::ProcessNotFound))
|
||||||
|
} else {
|
||||||
|
ss.switch_from_thread(pid, thread)?;
|
||||||
|
Ok(xous_kernel::Result::BlockedProcess)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
klog!(
|
// println!("Returning to Client with Ok result");
|
||||||
"no threads available in PID {} to handle this message, so queueing",
|
Ok(xous_kernel::Result::Ok)
|
||||||
server_pid
|
|
||||||
);
|
|
||||||
// Add this message to the queue. If the queue is full, this
|
|
||||||
// returns an error.
|
|
||||||
let _queue_idx = ss.queue_server_message(sidx, pid, thread, message, client_address)?;
|
|
||||||
klog!("queued into index {:x}", _queue_idx);
|
|
||||||
|
|
||||||
// Park this context if it's blocking. This is roughly
|
|
||||||
// equivalent to a "Yield".
|
|
||||||
if blocking {
|
|
||||||
if cfg!(baremetal) {
|
|
||||||
// println!("Returning to parent");
|
|
||||||
let process = ss.get_process(pid).expect("Can't get current process");
|
|
||||||
let ppid = process.ppid;
|
|
||||||
unsafe { SWITCHTO_CALLER = None };
|
|
||||||
ss.activate_process_thread(thread, ppid, 0, false)
|
|
||||||
.map(|_| Ok(xous_kernel::Result::ResumeProcess))
|
|
||||||
.unwrap_or(Err(xous_kernel::Error::ProcessNotFound))
|
|
||||||
} else {
|
|
||||||
ss.switch_from_thread(pid, thread)?;
|
|
||||||
Ok(xous_kernel::Result::BlockedProcess)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// println!("Returning to Client with Ok result");
|
|
||||||
Ok(xous_kernel::Result::Ok)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue