From 585e55e8b7d2607df70b9fe9fadc2ff31a3ae441 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 14 Oct 2020 10:04:36 +0800 Subject: [PATCH] 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 --- kernel/src/arch/hosted/process.rs | 4 ++++ kernel/src/arch/riscv/process.rs | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/kernel/src/arch/hosted/process.rs b/kernel/src/arch/hosted/process.rs index 3ac462e2f..8f381a63e 100644 --- a/kernel/src/arch/hosted/process.rs +++ b/kernel/src/arch/hosted/process.rs @@ -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) diff --git a/kernel/src/arch/riscv/process.rs b/kernel/src/arch/riscv/process.rs index 5a5d8e04c..c4f439809 100644 --- a/kernel/src/arch/riscv/process.rs +++ b/kernel/src/arch/riscv/process.rs @@ -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> {