kernel: services: keep track of current pid

Currently we use the ASID inside the MMU to figure out the current PID.
We should also keep track of what we think it is, for consistency.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-03-14 21:28:01 +08:00
parent 845cef3771
commit 9a10f50ce1

View file

@ -142,6 +142,9 @@ pub struct InitialProcess {
/// A big unifying struct containing all of the system state. /// A big unifying struct containing all of the system state.
/// This is inherited from the stage 1 bootloader. /// This is inherited from the stage 1 bootloader.
pub struct SystemServices { pub struct SystemServices {
/// Current PID
pid: PID,
/// A table of all processes in the system /// A table of all processes in the system
pub processes: [Process; MAX_PROCESS_COUNT], pub processes: [Process; MAX_PROCESS_COUNT],
@ -150,6 +153,7 @@ pub struct SystemServices {
} }
static mut SYSTEM_SERVICES: SystemServices = SystemServices { static mut SYSTEM_SERVICES: SystemServices = SystemServices {
pid: 1 as PID,
processes: [Process { processes: [Process {
state: ProcessState::Free, state: ProcessState::Free,
ppid: 0, ppid: 0,
@ -264,6 +268,11 @@ impl SystemServices {
"process memory map doesn't match -- current_pid: {}", "process memory map doesn't match -- current_pid: {}",
pid pid
); );
assert_eq!(
pid, self.pid,
"current pid {} doesn't match arch pid: {}",
self.pid, pid
);
pid as PID pid as PID
} }
@ -315,6 +324,7 @@ impl SystemServices {
// Switch to new process memory space, allowing us to save the context // Switch to new process memory space, allowing us to save the context
// if necessary. // if necessary.
process.mapping.activate(); process.mapping.activate();
self.pid = pid;
let context = ProcessContext::current(); let context = ProcessContext::current();
@ -347,6 +357,7 @@ impl SystemServices {
// Save state if the PID has changed // Save state if the PID has changed
let context = if pid != previous_pid { let context = if pid != previous_pid {
let context = { let context = {
self.pid = pid;
let new = self.get_process_mut(pid)?; let new = self.get_process_mut(pid)?;
match new.state { match new.state {
ProcessState::Free => return Err(xous::Error::ProcessNotFound), ProcessState::Free => return Err(xous::Error::ProcessNotFound),