kernel: implement retry_instruction()

This function is used to decrement the program counter to re-run a given
instruction. This can be used as a cheap way to implement blocking
calls.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-10-14 10:04:36 +08:00
parent a0a90cc3ab
commit 585e55e8b7
2 changed files with 13 additions and 0 deletions

View file

@ -179,6 +179,10 @@ impl Process {
process.threads[thread - 1].allocated = true;
}
pub fn retry_instruction(&mut self, _tid: TID) -> Result<(), xous_kernel::Error> {
Ok(())
}
pub fn setup_process(pid: PID, setup: ThreadInit) -> Result<(), xous_kernel::Error> {
let mut tmp = Process { pid };
tmp.setup_thread(INITIAL_TID, setup)

View file

@ -235,6 +235,15 @@ impl Process {
}
}
pub fn retry_instruction(&mut self, tid: TID) -> Result<(), xous_kernel::Error> {
let process = unsafe { &mut *PROCESS };
let mut thread = &mut process.threads[tid];
if thread.sepc >= 4 {
thread.sepc -= 4;
}
Ok(())
}
/// Initialize this process thread with the given entrypoint and stack
/// addresses.
pub fn setup_process(pid: PID, thread_init: ThreadInit) -> Result<(), xous_kernel::Error> {