Merge branch 'master' of github.com:betrusted-io/xous-core

This commit is contained in:
bunnie 2020-10-14 23:02:14 +08:00
commit 6ff8c8518c
4 changed files with 47 additions and 24 deletions

View file

@ -10,6 +10,15 @@ use xous_kernel::*;
/// This is the context that called SwitchTo
static mut SWITCHTO_CALLER: Option<(PID, TID)> = None;
fn retry_syscall(pid: PID, tid: TID) -> SysCallResult {
if cfg!(baremetal) {
arch::process::Process::with_current_mut(|p| p.retry_instruction(tid))?;
do_yield(pid, tid)
} else {
Ok(xous_kernel::Result::WouldBlock)
}
}
fn do_yield(_pid: PID, tid: TID) -> SysCallResult {
// If we're not running on bare metal, treat this as a no-op.
if !cfg!(baremetal) {
@ -708,7 +717,6 @@ pub fn handle_inner(pid: PID, tid: TID, call: SysCall) -> SysCallResult {
SysCall::ReturnMemory(sender, buf) => return_memory(pid, tid, sender, buf),
SysCall::ReturnScalar1(sender, arg) => return_scalar(pid, tid, sender, arg),
SysCall::ReturnScalar2(sender, arg1, arg2) => return_scalar2(pid, tid, sender, arg1, arg2),
// SysCall::ReturnScalar2(sender, arg, arg2) => return_memory(pid, tid, sender, arg, arg2),
SysCall::TrySendMessage(cid, message) => send_message(pid, tid, cid, message),
SysCall::TerminateProcess => SystemServices::with_mut(|ss| {
ss.switch_from_thread(pid, tid)?;
@ -724,17 +732,22 @@ pub fn handle_inner(pid: PID, tid: TID, call: SysCall) -> SysCallResult {
SystemServices::with_mut(|ss| ss.shutdown().map(|_| xous_kernel::Result::Ok))
}
// SysCall::Connect(sid) => {
// SystemServices::with_mut(|ss| ss.connect_to_server(sid).map(xous_kernel::Result::ConnectionID))
// }
SysCall::Connect(sid) => {
let result = SystemServices::with_mut(|ss| {
ss.connect_to_server(sid)
.map(xous_kernel::Result::ConnectionID)
});
match result {
Ok(o) => Ok(o),
Err(xous_kernel::Error::ServerNotFound) => retry_syscall(pid, tid),
Err(e) => Err(e),
}
}
SysCall::SendMessage(cid, message) => {
let result = send_message(pid, tid, cid, message);
match result {
Ok(o) => Ok(o),
Err(xous_kernel::Error::ServerQueueFull) => {
arch::process::Process::with_current_mut(|p| p.retry_instruction(tid))?;
do_yield(pid, tid)
}
Err(xous_kernel::Error::ServerQueueFull) => retry_syscall(pid, tid),
Err(e) => Err(e),
}
}

View file

@ -377,7 +377,7 @@ fn send_borrow_message() {
// Perform a connection to the server
// println!("CLIENT: Connecting to server...");
let conn = xous_kernel::try_connect(sid).expect("couldn't connect to server");
let conn = xous_kernel::connect(sid).expect("couldn't connect to server");
// Convert the message into a "Carton" that can be shipped as a message
// println!("CLIENT: Creating carton...");
@ -443,7 +443,7 @@ fn send_mutableborrow_message() {
let sid = server_addr_recv.recv().unwrap();
// Perform a connection to the server
let conn = xous_kernel::try_connect(sid).expect("couldn't connect to server");
let conn = xous_kernel::connect(sid).expect("couldn't connect to server");
// Convert the message into a "Carton" that can be shipped as a message
let mut carton = xous_kernel::carton::Carton::from_bytes(&test_bytes);
@ -516,7 +516,7 @@ fn send_mutableborrow_message_repeat() {
let sid = server_addr_recv.recv().unwrap();
// Perform a connection to the server
let conn = xous_kernel::try_connect(sid).expect("couldn't connect to server");
let conn = xous_kernel::connect(sid).expect("couldn't connect to server");
// Convert the message into a "Carton" that can be shipped as a message
for iteration in 0..loops {

View file

@ -428,19 +428,24 @@ pub fn _xous_syscall(
let mut xsc_borrowed = xsc.borrow_mut();
let xsc_asmut = xsc_borrowed.as_mut().expect("not connected to server!");
_xous_syscall_to(
nr,
a1,
a2,
a3,
a4,
a5,
a6,
a7,
&call,
&mut xsc_asmut.send.lock().unwrap(),
);
_xous_syscall_result(&call, ret, *tid.borrow(), xsc_asmut);
loop {
_xous_syscall_to(
nr,
a1,
a2,
a3,
a4,
a5,
a6,
a7,
&call,
&mut xsc_asmut.send.lock().unwrap(),
);
_xous_syscall_result(&call, ret, *tid.borrow(), xsc_asmut);
if *ret != Result::WouldBlock {
return;
}
}
})
});
}

View file

@ -459,6 +459,9 @@ pub enum Result {
/// A scalar with two values
Scalar2(usize, usize),
/// The syscall should be attempted again
WouldBlock,
UnknownResult(usize, usize, usize, usize, usize, usize, usize),
}
@ -494,6 +497,7 @@ impl Result {
let s = sid.to_u32();
[15, s.0 as _, s.1 as _, s.2 as _, s.3 as _, *cid, 0, 0]
}
Result::WouldBlock => [16, 0, 0, 0, 0, 0, 0, 0],
Result::UnknownResult(arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {
[usize::MAX, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7]
}
@ -567,6 +571,7 @@ impl Result {
SID::from_u32(src[1] as _, src[2] as _, src[3] as _, src[4] as _),
src[5] as _,
),
16 => Result::WouldBlock,
_ => Result::UnknownResult(src[0], src[1], src[2], src[3], src[4], src[5], src[6]),
}
}