From 6b729d9ebcb6f077be5f5eabfa74be4ee138ba08 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Fri, 27 Mar 2020 16:58:04 +0800 Subject: [PATCH] kernel: services: resume correct context after interrupt We were resuming the wrong context after returning from an interrupt. This resulted in us resuming context 3 more often than not. This now properly banks the current process context prior to the switch. Signed-off-by: Sean Cross --- kernel/src/services.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/src/services.rs b/kernel/src/services.rs index 96088d50c..a6ab6796e 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -328,6 +328,7 @@ impl SystemServices { ProcessState::Running(x) => ProcessState::Ready(x), y => panic!("current process was {:?}, not 'Running(_)'", y), }; + current.current_context = current.previous_context; } // Get the new process, and ensure that it is in a state where it's fit @@ -393,6 +394,7 @@ impl SystemServices { ProcessState::Setup(_, _, _) => panic!("process hasn't been set up yet"), }; process.state = ProcessState::Running(available_threads); + process.previous_context = process.current_context; process.current_context = IRQ_CONTEXT as u8; process.mapping.activate(); } @@ -593,8 +595,6 @@ impl SystemServices { // Restore the previous context, if one exists. process.set_context_nr(new_context); - self.processes[self.pid as usize - 1].previous_context = - self.processes[self.pid as usize - 1].current_context; self.processes[self.pid as usize - 1].current_context = new_context as u8; let ctx = process.current_context(); println!(